Search in sources :

Example 1 with RemoteInput

use of android.support.v4.app.RemoteInput in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent i = new Intent(this, VoiceReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(VoiceReceiver.EXTRA_SPEECH).setLabel(getString(R.string.talk)).setChoices(getResources().getStringArray(R.array.replies)).build();
    NotificationCompat.Action wearAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
    NotificationCompat.WearableExtender wearExtender = new NotificationCompat.WearableExtender().addAction(wearAction);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(getString(R.string.title)).setContentText(getString(R.string.talk)).extend(wearExtender);
    NotificationManagerCompat.from(this).notify(NOTIFY_ID, builder.build());
    finish();
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 2 with RemoteInput

use of android.support.v4.app.RemoteInput in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent i = new Intent(this, RemoteInputReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT).setLabel(getString(R.string.talk)).build();
    NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
    NotificationCompat.Builder builder = RemoteInputReceiver.buildNotificationBase(this).addAction(remoteAction);
    NotificationManagerCompat.from(this).notify(RemoteInputReceiver.NOTIFY_ID, builder.build());
    finish();
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 3 with RemoteInput

use of android.support.v4.app.RemoteInput in project Signal-Android by WhisperSystems.

the class SingleRecipientNotificationBuilder method addAndroidAutoAction.

public void addAndroidAutoAction(@NonNull PendingIntent androidAutoReplyIntent, @NonNull PendingIntent androidAutoHeardIntent, long timestamp) {
    if (mContentTitle == null || mContentText == null)
        return;
    RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY).setLabel(context.getString(R.string.MessageNotifier_reply)).build();
    NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(mContentTitle.toString()).addMessage(mContentText.toString()).setLatestTimestamp(timestamp).setReadPendingIntent(androidAutoHeardIntent).setReplyAction(androidAutoReplyIntent, remoteInput);
    extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConversationBuilder.build()));
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) SpannableStringBuilder(android.text.SpannableStringBuilder) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 4 with RemoteInput

use of android.support.v4.app.RemoteInput in project Talon-for-Twitter by klinker24.

the class NotificationUtils method sendTestNotification.

public static void sendTestNotification(Context context) {
    if (!TEST_NOTIFICATION) {
        return;
    }
    AppSettings settings = AppSettings.getInstance(context);
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
    String shortText = "Test Talon";
    String longText = "Here is a test for Talon's notifications";
    Intent resultIntent = new Intent(context, RedirectToMentions.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    NotificationCompat.Builder mBuilder;
    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);
    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)).setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }
    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    Intent reply = new Intent(context, NotificationCompose.class);
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ").build();
    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);
    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());
    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());
    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 5 with RemoteInput

use of android.support.v4.app.RemoteInput in project phonegap-plugin-push by phonegap.

the class GCMIntentService method createActions.

private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId) {
    Log.d(LOG_TAG, "create actions: with in-line");
    String actions = extras.getString(ACTIONS);
    if (actions != null) {
        try {
            JSONArray actionsArray = new JSONArray(actions);
            ArrayList<NotificationCompat.Action> wActions = new ArrayList<NotificationCompat.Action>();
            for (int i = 0; i < actionsArray.length(); i++) {
                int min = 1;
                int max = 2000000000;
                Random random = new Random();
                int uniquePendingIntentRequestCode = random.nextInt((max - min) + 1) + min;
                Log.d(LOG_TAG, "adding action");
                JSONObject action = actionsArray.getJSONObject(i);
                Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK));
                boolean foreground = action.optBoolean(FOREGROUND, true);
                boolean inline = action.optBoolean("inline", false);
                Intent intent = null;
                PendingIntent pIntent = null;
                if (inline) {
                    Log.d(LOG_TAG, "Version: " + android.os.Build.VERSION.SDK_INT + " = " + android.os.Build.VERSION_CODES.M);
                    if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
                        Log.d(LOG_TAG, "push activity");
                        intent = new Intent(this, PushHandlerActivity.class);
                    } else {
                        Log.d(LOG_TAG, "push receiver");
                        intent = new Intent(this, BackgroundActionButtonHandler.class);
                    }
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
                        Log.d(LOG_TAG, "push activity for notId " + notId);
                        pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
                    } else {
                        Log.d(LOG_TAG, "push receiver for notId " + notId);
                        pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
                    }
                } else if (foreground) {
                    intent = new Intent(this, PushHandlerActivity.class);
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                } else {
                    intent = new Intent(this, BackgroundActionButtonHandler.class);
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                }
                NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
                RemoteInput remoteInput = null;
                if (inline) {
                    Log.d(LOG_TAG, "create remote input");
                    String replyLabel = "Enter your reply here";
                    remoteInput = new RemoteInput.Builder(INLINE_REPLY).setLabel(replyLabel).build();
                    actionBuilder.addRemoteInput(remoteInput);
                }
                NotificationCompat.Action wAction = actionBuilder.build();
                wActions.add(actionBuilder.build());
                if (inline) {
                    mBuilder.addAction(wAction);
                } else {
                    mBuilder.addAction(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
                }
                wAction = null;
                pIntent = null;
            }
            mBuilder.extend(new WearableExtender().addActions(wActions));
            wActions.clear();
        } catch (JSONException e) {
        // nope
        }
    }
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) WearableExtender(android.support.v4.app.NotificationCompat.WearableExtender) Random(java.util.Random) JSONObject(org.json.JSONObject) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)13 RemoteInput (android.support.v4.app.RemoteInput)13 PendingIntent (android.app.PendingIntent)11 Intent (android.content.Intent)11 SharedPreferences (android.content.SharedPreferences)5 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)4 PowerManager (android.os.PowerManager)3 AppSettings (com.klinker.android.twitter.settings.AppSettings)3 ArrayList (java.util.ArrayList)3 Bitmap (android.graphics.Bitmap)2 Random (java.util.Random)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 NotificationManager (android.app.NotificationManager)1 ComponentName (android.content.ComponentName)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1