Search in sources :

Example 16 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.

the class InterstitialAdManager method showAd.

@ReactMethod
public void showAd(String placementId, Promise p) {
    if (mPromise != null) {
        p.reject("E_FAILED_TO_SHOW", "Only one `showAd` can be called at once");
        return;
    }
    ReactApplicationContext reactContext = this.getReactApplicationContext();
    mPromise = p;
    mInterstitial = new InterstitialAd(reactContext, placementId);
    mInterstitial.setAdListener(this);
    mInterstitial.loadAd();
}
Also used : InterstitialAd(com.facebook.ads.InterstitialAd) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 17 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.

the class InterstitialAdManager method loadAd.

@ReactMethod
public void loadAd(String placementId, Promise p) {
    ReactApplicationContext reactContext = this.getReactApplicationContext();
    mViewAtOnce = true;
    mPromise = p;
    mInterstitial = new InterstitialAd(reactContext, placementId);
    mInterstitial.loadAd();
}
Also used : InterstitialAd(com.facebook.ads.InterstitialAd) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 18 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.

the class NativeAdManager method init.

/**
 * Initialises native ad manager for a given placement id and ads to request.
 * This method is run on the UI thread
 *
 * @param placementId
 * @param adsToRequest
 */
@ReactMethod
public void init(final String placementId, final int adsToRequest) {
    final ReactApplicationContext reactContext = this.getReactApplicationContext();
    UiThreadUtil.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final NativeAdsManager adsManager = new NativeAdsManager(reactContext, placementId, adsToRequest);
            adsManager.setListener(NativeAdManager.this);
            mAdsManagers.put(placementId, adsManager);
            adsManager.loadAds();
        }
    });
}
Also used : ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeAdsManager(com.facebook.ads.NativeAdsManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 19 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-twilio-programmable-voice by hoxfon.

the class VoiceFirebaseMessagingService method onMessageReceived.

/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Bundle data: " + remoteMessage.getData());
    }
    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Map<String, String> data = remoteMessage.getData();
        // If notification ID is not provided by the user for push notification, generate one at random
        Random randomNumberGenerator = new Random(System.currentTimeMillis());
        final int notificationId = randomNumberGenerator.nextInt();
        Voice.handleMessage(this, data, new MessageListener() {

            @Override
            public void onCallInvite(final CallInvite callInvite) {
                // We need to run this on the main thread, as the React code assumes that is true.
                // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
                // "Can't create handler inside thread that has not called Looper.prepare()"
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    public void run() {
                        // Construct and load our normal React JS code bundle
                        ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                        ReactContext context = mReactInstanceManager.getCurrentReactContext();
                        // If it's constructed, send a notification
                        if (context != null) {
                            int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext) context);
                            if (BuildConfig.DEBUG) {
                                Log.d(TAG, "CONTEXT present appImportance = " + appImportance);
                            }
                            Intent launchIntent = callNotificationManager.getLaunchIntent((ReactApplicationContext) context, notificationId, callInvite, false, appImportance);
                            // app is not in foreground
                            if (appImportance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                                context.startActivity(launchIntent);
                            }
                            VoiceFirebaseMessagingService.this.handleIncomingCall((ReactApplicationContext) context, notificationId, callInvite, launchIntent);
                        } else {
                            // Otherwise wait for construction, then handle the incoming call
                            mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                                public void onReactContextInitialized(ReactContext context) {
                                    int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext) context);
                                    if (BuildConfig.DEBUG) {
                                        Log.d(TAG, "CONTEXT not present appImportance = " + appImportance);
                                    }
                                    Intent launchIntent = callNotificationManager.getLaunchIntent((ReactApplicationContext) context, notificationId, callInvite, true, appImportance);
                                    context.startActivity(launchIntent);
                                    VoiceFirebaseMessagingService.this.handleIncomingCall((ReactApplicationContext) context, notificationId, callInvite, launchIntent);
                                }
                            });
                            if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                                // Construct it in the background
                                mReactInstanceManager.createReactContextInBackground();
                            }
                        }
                    }
                });
            }

            @Override
            public void onError(MessageException messageException) {
                Log.e(TAG, "Error handling FCM message" + messageException.toString());
            }
        });
    }
    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.e(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }
}
Also used : ReactInstanceManager(com.facebook.react.ReactInstanceManager) MessageListener(com.twilio.voice.MessageListener) Handler(android.os.Handler) Intent(android.content.Intent) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) Random(java.util.Random) ReactContext(com.facebook.react.bridge.ReactContext) MessageException(com.twilio.voice.MessageException) CallInvite(com.twilio.voice.CallInvite)

Example 20 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-push-notification by zo0r.

the class RNPushNotificationListenerService method onNewToken.

@Override
public void onNewToken(String token) {
    final String deviceToken = token;
    final FirebaseMessagingService serviceRef = (this.mFirebaseServiceDelegate == null) ? this : this.mFirebaseServiceDelegate;
    Log.d(LOG_TAG, "Refreshed token: " + deviceToken);
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            final ReactInstanceManager mReactInstanceManager = ((ReactApplication) serviceRef.getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                handleNewToken((ReactApplicationContext) context, deviceToken);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        handleNewToken((ReactApplicationContext) context, deviceToken);
                        mReactInstanceManager.removeReactInstanceEventListener(this);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : FirebaseMessagingService(com.google.firebase.messaging.FirebaseMessagingService) ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Handler(android.os.Handler) ReactApplication(com.facebook.react.ReactApplication) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

Aggregations

ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)21 ReactMethod (com.facebook.react.bridge.ReactMethod)10 ReactInstanceManager (com.facebook.react.ReactInstanceManager)5 Intent (android.content.Intent)4 Handler (android.os.Handler)4 InterstitialAd (com.facebook.ads.InterstitialAd)4 ReactContext (com.facebook.react.bridge.ReactContext)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 ReactApplication (com.facebook.react.ReactApplication)3 WritableMap (com.facebook.react.bridge.WritableMap)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 NativeAdsManager (com.facebook.ads.NativeAdsManager)2 RCTNativeAppEventEmitter (com.facebook.react.modules.core.RCTNativeAppEventEmitter)2 File (java.io.File)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1