Java Code Examples for com.facebook.react.bridge.ReactApplicationContext#getResources()

The following examples show how to use com.facebook.react.bridge.ReactApplicationContext#getResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlurTask.java    From react-native-blur-overlay with MIT License 5 votes vote down vote up
static private Drawable screenShot(
        ReactApplicationContext reactContext,
        RenderScript rs,
        Bitmap b1,
        int radius,
        float factor,
        float brightness) {
    try {
        b1 = blur(rs,b1,radius, brightness,factor);
        return new BitmapDrawable(reactContext.getResources(),b1);
    } catch (Exception e) {
        e.printStackTrace();
        return  null;
    }
}
 
Example 2
Source File: RNBatchModule.java    From react-native-batch-push with MIT License 5 votes vote down vote up
public RNBatchModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
    this.reactContext.addLifecycleEventListener(this);

    try {
        Resources resources = reactContext.getResources();
        String packageName = reactContext.getApplicationContext().getPackageName();
        String batchAPIKey = resources.getString(resources.getIdentifier("BATCH_API_KEY", "string", packageName));

        Batch.setConfig(new Config(batchAPIKey));
    } catch (Exception e) {
        Log.e("RNBatchPush", e.getMessage());
    }
}
 
Example 3
Source File: MusicControlNotification.java    From react-native-music-control with MIT License 5 votes vote down vote up
public MusicControlNotification(MusicControlModule module, ReactApplicationContext context) {
    this.context = context;
    this.module = module;

    Resources r = context.getResources();
    String packageName = context.getPackageName();

    // Optional custom icon with fallback to the play icon
    smallIcon = r.getIdentifier("music_control_icon", "drawable", packageName);
    if (smallIcon == 0) smallIcon = r.getIdentifier("play", "drawable", packageName);
}
 
Example 4
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void createIncomingCallNotification(ReactApplicationContext context,
                                           CallInvite callInvite,
                                           int notificationId,
                                           Intent launchIntent)
{
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "createIncomingCallNotification intent "+launchIntent.getFlags());
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    /*
     * Pass the notification id and call sid to use as an identifier to cancel the
     * notification later
     */
    Bundle extras = new Bundle();
    extras.putInt(INCOMING_CALL_NOTIFICATION_ID, notificationId);
    extras.putString(CALL_SID_KEY, callInvite.getCallSid());
    extras.putString(NOTIFICATION_TYPE, ACTION_INCOMING_CALL);
    /*
     * Create the notification shown in the notification drawer
     */
    initCallNotificationsChannel(notificationManager);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(context, VOICE_CHANNEL)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setSmallIcon(R.drawable.ic_call_white_24dp)
                    .setContentTitle("Incoming call")
                    .setContentText(callInvite.getFrom() + " is calling")
                    .setOngoing(true)
                    .setAutoCancel(true)
                    .setExtras(extras)
                    .setFullScreenIntent(pendingIntent, true);

    // build notification large icon
    Resources res = context.getResources();
    int largeIconResId = res.getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (largeIconResId != 0) {
            notificationBuilder.setLargeIcon(largeIconBitmap);
        }
    }

    // Reject action
    Intent rejectIntent = new Intent(ACTION_REJECT_CALL)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingRejectIntent = PendingIntent.getBroadcast(context, 1, rejectIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(0, "DISMISS", pendingRejectIntent);

    // Answer action
    Intent answerIntent = new Intent(ACTION_ANSWER_CALL);
    answerIntent
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAnswerIntent = PendingIntent.getBroadcast(context, 0, answerIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(R.drawable.ic_call_white_24dp, "ANSWER", pendingAnswerIntent);

    notificationManager.notify(notificationId, notificationBuilder.build());
    TwilioVoiceModule.callNotificationMap.put(INCOMING_NOTIFICATION_PREFIX+callInvite.getCallSid(), notificationId);
}
 
Example 5
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void createMissedCallNotification(ReactApplicationContext context, CallInvite callInvite) {
    SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCE_KEY, Context.MODE_PRIVATE);
    SharedPreferences.Editor sharedPrefEditor = sharedPref.edit();

    /*
     * Create a PendingIntent to specify the action when the notification is
     * selected in the notification drawer
     */
    Intent intent = new Intent(context, getMainActivityClass(context));
    intent.setAction(ACTION_MISSED_CALL)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, MISSED_CALLS_NOTIFICATION_ID)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent clearMissedCallsCountIntent = new Intent(ACTION_CLEAR_MISSED_CALLS_COUNT)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, CLEAR_MISSED_CALLS_NOTIFICATION_ID);
    PendingIntent clearMissedCallsCountPendingIntent = PendingIntent.getBroadcast(context, 0, clearMissedCallsCountIntent, 0);
    /*
     * Pass the notification id and call sid to use as an identifier to open the notification
     */
    Bundle extras = new Bundle();
    extras.putInt(INCOMING_CALL_NOTIFICATION_ID, MISSED_CALLS_NOTIFICATION_ID);
    extras.putString(CALL_SID_KEY, callInvite.getCallSid());
    extras.putString(NOTIFICATION_TYPE, ACTION_MISSED_CALL);

    /*
     * Create the notification shown in the notification drawer
     */
    NotificationCompat.Builder notification =
            new NotificationCompat.Builder(context, VOICE_CHANNEL)
                    .setGroup(MISSED_CALLS_GROUP)
                    .setGroupSummary(true)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setSmallIcon(R.drawable.ic_call_missed_white_24dp)
                    .setContentTitle("Missed call")
                    .setContentText(callInvite.getFrom() + " called")
                    .setAutoCancel(true)
                    .setShowWhen(true)
                    .setExtras(extras)
                    .setDeleteIntent(clearMissedCallsCountPendingIntent)
                    .setContentIntent(pendingIntent);

    int missedCalls = sharedPref.getInt(MISSED_CALLS_GROUP, 0);
    missedCalls++;
    if (missedCalls == 1) {
        inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle("Missed call");
    } else {
        inboxStyle.setBigContentTitle(String.valueOf(missedCalls) + " missed calls");
    }
    inboxStyle.addLine("from: " +callInvite.getFrom());
    sharedPrefEditor.putInt(MISSED_CALLS_GROUP, missedCalls);
    sharedPrefEditor.commit();

    notification.setStyle(inboxStyle);

    // build notification large icon
    Resources res = context.getResources();
    int largeIconResId = res.getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && largeIconResId != 0) {
        notification.setLargeIcon(largeIconBitmap);
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(MISSED_CALLS_NOTIFICATION_ID, notification.build());
}