android.support.v4.app.RemoteInput Java Examples

The following examples show how to use android.support.v4.app.RemoteInput. 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: RemoteInputUtils.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Nullable
public static RemoteInput[] toCompat(@Nullable android.app.RemoteInput[] srcArray) {
    if (srcArray == null) return null;
    RemoteInput[] result = new RemoteInput[srcArray.length];
    try {
        Constructor constructor = RemoteInput.class.getDeclaredConstructor(
                String.class, CharSequence.class, CharSequence[].class,
                boolean.class, Bundle.class);
        constructor.setAccessible(true);
        for (int i = 0; i < srcArray.length; i++) {
            android.app.RemoteInput src = srcArray[i];
            result[i] = (RemoteInput) constructor.newInstance(
                    src.getResultKey(), src.getLabel(), src.getChoices(),
                    src.getAllowFreeFormInput(), src.getExtras());
        }
    } catch (NoSuchMethodException
            | InvocationTargetException
            | InstantiationException
            | IllegalAccessException e) {
        Log.e(TAG, "Failed to create the remote inputs!");
        return null;
    }
    return result;
}
 
Example #2
Source File: VoiceNotiActivity.java    From wearable with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_voice_noti);
	
	//note android developer page, shows this in a separate method, but not necessary.
	
	Bundle remoteInput = RemoteInput.getResultsFromIntent( getIntent());
    if (remoteInput != null) {
        info = remoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString();
    } else {
		info = "No voice reponse.";
	} 
	logger = (TextView) findViewById(R.id.logger);
	logger.setText(info);
}
 
Example #3
Source File: NotificationUtils.java    From wear with MIT License 6 votes vote down vote up
public static void showNotificationWithInputForSecondaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    "Action", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setContentTitle(context.getString(R.string.action_title))
                    .extend(new WearableExtender().addAction(action))
                    .build());
}
 
Example #4
Source File: NotificationUtils.java    From wear with MIT License 6 votes vote down vote up
public static void showNotificationWithInputForPrimaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .setChoices(context.getResources().getStringArray(R.array.input_choices))
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    "Action", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(context.getString(R.string.action_title))
                    .setContentText(context.getString(R.string.action_text))
                    .setContentIntent(pendingIntent)
                    .extend(new WearableExtender().addAction(action))
                    .build());
}
 
Example #5
Source File: Action.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Action[] makeFor(@NonNull Notification notification) {
    Notification.Action[] src = notification.actions;

    if (src == null) {
        return null;
    }

    final int length = src.length;
    final Action[] dst = new Action[src.length];
    for (int i = 0; i < length; i++) {
        RemoteInput[] remoteInputs = getRemoteInputs(src[i]);
        dst[i] = new Action(src[i].icon, src[i].title, src[i].actionIntent, remoteInputs);
    }

    return dst;
}
 
Example #6
Source File: RemoteInputUtils.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Nullable
public static RemoteInput[] toCompat(@Nullable android.app.RemoteInput[] srcArray) {
    if (srcArray == null) return null;
    RemoteInput[] result = new RemoteInput[srcArray.length];
    try {
        Constructor constructor = RemoteInput.class.getDeclaredConstructor(
                String.class, CharSequence.class, CharSequence[].class,
                boolean.class, Bundle.class);
        constructor.setAccessible(true);
        for (int i = 0; i < srcArray.length; i++) {
            android.app.RemoteInput src = srcArray[i];
            result[i] = (RemoteInput) constructor.newInstance(
                    src.getResultKey(), src.getLabel(), src.getChoices(),
                    src.getAllowFreeFormInput(), src.getExtras());
        }
    } catch (NoSuchMethodException
            | InvocationTargetException
            | InstantiationException
            | IllegalAccessException e) {
        Log.e(TAG, "Failed to create the remote inputs!");
        return null;
    }
    return result;
}
 
Example #7
Source File: AutoMessageReplyReceiver.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    int currentAccount = intent.getIntExtra("currentAccount", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true);
}
 
Example #8
Source File: WearReplyReceiver.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    int currentAccount = intent.getIntExtra("currentAccount", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true);
}
 
Example #9
Source File: NotificationListenerService.java    From wear-notify-for-reddit with Apache License 2.0 6 votes vote down vote up
@Override public int onStartCommand(Intent intent, int flags, int startId) {
    if (null == intent || null == intent.getAction()) {
        return Service.START_STICKY;
    }
    String action = intent.getAction();
    if (action.equals(ACTION_RESPONSE)) {
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        CharSequence replyMessage = "";
        if (remoteInputResults != null) {
            replyMessage = remoteInputResults.getCharSequence(EXTRA_VOICE_REPLY);
        }
        String subject = intent.getStringExtra(Constants.PATH_KEY_MESSAGE_SUBJECT);
        String toUser = intent.getStringExtra(Constants.PATH_KEY_MESSAGE_TO_USER);
        String fullname = intent.getStringExtra(Constants.PATH_KEY_POST_FULLNAME);
        boolean isDirectMessage = intent.getBooleanExtra(Constants.PATH_KEY_IS_DIRECT_MESSAGE,
                false);
        sendReplyToPhone(replyMessage.toString(), fullname, toUser, subject, isDirectMessage);
    }
    return Service.START_STICKY;
}
 
Example #10
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
public void onClickSend(View view){
    Intent activityIntent = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(this,0,activityIntent,0);

    RemoteInput remoteInput = new RemoteInput.Builder(KEY_REPLY_TEXT)
            .setLabel("Reply")
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_revert,
                    "Reply", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this,getChannelId())
                    .setSmallIcon(android.R.drawable.ic_dialog_email)
                    .setContentTitle("Reply")
                    .setContentText("Content")
                    .addAction(action);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(0, notificationBuilder.build());
}
 
Example #11
Source File: AutoMessageReplyReceiver.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    int currentAccount = intent.getIntExtra("currentAccount", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true);
}
 
Example #12
Source File: WearReplyReceiver.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    int currentAccount = intent.getIntExtra("currentAccount", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true);
}
 
Example #13
Source File: WearableReplayActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wearable_replay);

    CharSequence replayString;

    //get the voice replays from the remote input.
    Bundle bundle = RemoteInput.getResultsFromIntent(getIntent());
    if (bundle != null) {
        replayString = bundle.getCharSequence(WearableNotification.REMOTE_INPUT_LABEL);
    } else {
        replayString = "No replay from the response.";
    }

    Toast.makeText(this, replayString, Toast.LENGTH_LONG).show();

    finish();
}
 
Example #14
Source File: SingleRecipientNotificationBuilder.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
public void addAndroidAutoAction(@NonNull PendingIntent androidAutoReplyIntent,
                                 @NonNull PendingIntent androidAutoHeardIntent, long timestamp)
{

  if (contentTitle == null || contentText == 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(contentTitle.toString())
              .addMessage(contentText.toString())
              .setLatestTimestamp(timestamp)
              .setReadPendingIntent(androidAutoHeardIntent)
              .setReplyAction(androidAutoReplyIntent, remoteInput);

  extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConversationBuilder.build()));
}
 
Example #15
Source File: Wear.java    From ZadakNotification with MIT License 6 votes vote down vote up
@SuppressLint("ResourceType")
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(ZadakNotification.mSingleton.mContext.getString(R.string.key_voice_reply))
            .setLabel(ZadakNotification.mSingleton.mContext.getString(R.string.label_voice_reply))
            .setChoices(ZadakNotification.mSingleton.mContext.getResources().getStringArray(R.array.reply_choices))
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
 
Example #16
Source File: NotifyWidget.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onActionClick(@NonNull NotificationActions na,
                          @NonNull View view, final @NonNull Action action,
                          @NonNull RemoteInput remoteInput,
                          @NonNull CharSequence text) {
    final Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putCharSequence(remoteInput.getResultKey(), text);
    RemoteInput.addResultsToIntent(action.remoteInputs, intent, bundle);
    mFragment.unlock(
            new Runnable() {
                @Override
                public void run() {
                    // TODO: Cancel pending finish if sending pending intent
                    // has failed.
                    PendingIntent pi = action.intent;
                    Activity activity = mFragment.getActivity();
                    PendingIntentUtils.sendPendingIntent(pi, activity, intent);
                }
            }, false);
}
 
Example #17
Source File: Action.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Action[] makeFor(@NonNull Notification notification) {
    Notification.Action[] src = notification.actions;

    if (src == null) {
        return null;
    }

    final int length = src.length;
    final Action[] dst = new Action[src.length];
    for (int i = 0; i < length; i++) {
        RemoteInput[] remoteInputs = getRemoteInputs(src[i]);
        dst[i] = new Action(src[i].icon, src[i].title, src[i].actionIntent, remoteInputs);
    }

    return dst;
}
 
Example #18
Source File: ResponderService.java    From android-ElizaChat with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (null == intent || null == intent.getAction()) {
        return Service.START_STICKY;
    }
    String action = intent.getAction();
    if (action.equals(ACTION_RESPONSE)) {
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        CharSequence replyMessage = "";
        if (remoteInputResults != null) {
            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
        }
        processIncoming(replyMessage.toString());
    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
        broadcastMessage(mCompleteConversation.toString());
    }
    return Service.START_STICKY;
}
 
Example #19
Source File: ResponderService.java    From android-ElizaChat with Apache License 2.0 6 votes vote down vote up
private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza))
            .setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder
            .extend(new NotificationCompat.WearableExtender()
                    .addAction(new NotificationCompat.Action.Builder(
                            R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
                            .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
                                    .setLabel(getString(R.string.reply))
                                    .build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}
 
Example #20
Source File: ActionsPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(action);
}
 
Example #21
Source File: ActionsPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_action,
            context.getString(R.string.phone_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.phone_action_clicked))
            .build();
    builder.addAction(phoneAction);

    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_label))
            .build();

    NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.wearable_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.wearable_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(wearableAction);
}
 
Example #22
Source File: NotificationIntentReceiver.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_EXAMPLE)) {
        if (mEnableMessages) {
            String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
            Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
            CharSequence replyMessage = null;
            if (remoteInputResults != null) {
                replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
            }
            if (replyMessage != null) {
                message = message + ": \"" + replyMessage + "\"";
            }
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
        mEnableMessages = true;
    } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
        mEnableMessages = false;
    }
}
 
Example #23
Source File: ResponderService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (null == intent || null == intent.getAction()) {
        return Service.START_STICKY;
    }
    String action = intent.getAction();
    if (action.equals(ACTION_RESPONSE)) {
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        CharSequence replyMessage = "";
        if (remoteInputResults != null) {
            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
        }
        processIncoming(replyMessage.toString());
    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
        broadcastMessage(mCompleteConversation.toString());
    }
    return Service.START_STICKY;
}
 
Example #24
Source File: ResponderService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza))
            .setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza)
            .setPriority(NotificationCompat.PRIORITY_MIN);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder
            .extend(new NotificationCompat.WearableExtender()
                    .addAction(new NotificationCompat.Action.Builder(
                            R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
                            .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
                                    .setLabel(getString(R.string.reply))
                                    .build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}
 
Example #25
Source File: Wear.java    From Pugnotification with Apache License 2.0 6 votes vote down vote up
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_key_voice_reply))
            .setLabel(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_label_voice_reply))
            .setChoices(PugNotification.mSingleton.mContext.getResources().getStringArray(R.array.pugnotification_reply_choices))
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
 
Example #26
Source File: InteractiveNotificationHandler.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
@NonNull
private NotificationCompat.Action createAndroidNotificationAction(NotificationAction notificationAction, PendingIntent pendingIntent) {
    NotificationCompat.Action.Builder builder = new NotificationCompat.Action.Builder(
            notificationAction.getIcon(),
            notificationActionTitle(context, notificationAction),
            pendingIntent);

    if (notificationAction.hasInput()) {
        RemoteInput.Builder inputBuilder = new RemoteInput.Builder(notificationAction.getId());
        String inputPlaceholderText = notificationActionInputPlaceholder(context, notificationAction);
        if (inputPlaceholderText != null) {
            inputBuilder.setLabel(inputPlaceholderText);
        }
        builder.addRemoteInput(inputBuilder.build());
    }

    return builder.build();
}
 
Example #27
Source File: Wear.java    From ZadakNotification with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent, String replyLabel, String[] replyChoices) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (replyChoices == null) {
        throw new IllegalArgumentException("Reply Choices Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }
    if (replyLabel == null) {
        throw new IllegalArgumentException("Reply Label Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(ZadakNotification.mSingleton.mContext.getString(R.string.key_voice_reply))
            .setLabel(replyLabel)
            .setChoices(replyChoices)
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
 
Example #28
Source File: NotificationActions.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public Textable(@NonNull NotificationActions container,
                @NonNull RemoteInput remoteInput,
                @NonNull OnTextChangedListener listener) {
    mContainer = container;
    mRemoteInput = remoteInput;
    mListener = listener;
    mContext = container.getContext();
}
 
Example #29
Source File: NotificationActions.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public TextableFreeForm(@NonNull NotificationActions container,
                        @NonNull RemoteInput remoteInput,
                        @NonNull OnTextChangedListener listener) {
    super(container, remoteInput, listener);
    mEditText = onCreateEditText();
    mEditText.setHint(remoteInput.getLabel());
    mEditText.addTextChangedListener(mTextWatcher);
}
 
Example #30
Source File: NotificationActions.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public TextableRestrictedForm(@NonNull NotificationActions container,
                              @NonNull RemoteInput remoteInput,
                              @NonNull OnTextChangedListener listener) {
    super(container, remoteInput, listener);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(
            mContext, android.R.layout.simple_spinner_dropdown_item,
            remoteInput.getChoices());
    mSpinner = onCreateSpinner();
    mSpinner.setAdapter(adapter);
}