Android Open Source - AndroidWearable-Samples Actions Presets






From Project

Back to project page AndroidWearable-Samples.

License

The source code is released under:

Apache License

If you think the Android project AndroidWearable-Samples listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.android.support.wearable.notifications;
//from   ww  w.java2 s.  c om
import android.content.Context;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.RemoteInput;

/**
 * Collection of notification actions presets.
 */
public class ActionsPresets {
    public static final ActionsPreset NO_ACTIONS_PRESET = new NoActionsPreset();
    public static final ActionsPreset SINGLE_ACTION_PRESET = new SingleActionPreset();

    public static final ActionsPreset[] PRESETS = new ActionsPreset[] {
            NO_ACTIONS_PRESET,
            SINGLE_ACTION_PRESET,
            new ReplyActionPreset(),
            new ReplyWithChoicesActionPreset(),
            new DifferentActionsOnPhoneAndWearable(),
            new LongTitleActionPreset()
    };

    private static class NoActionsPreset extends ActionsPreset {
        public NoActionsPreset() {
            super(R.string.no_actions);
        }

        @Override
        public void apply(Context context, NotificationCompat.Builder builder,
                NotificationCompat.WearableExtender wearableOptions) {
        }
    }

    private static class SingleActionPreset extends ActionsPreset {
        public SingleActionPreset() {
            super(R.string.single_action);
        }

        @Override
        public void apply(Context context, NotificationCompat.Builder builder,
                NotificationCompat.WearableExtender wearableOptions) {
            builder.addAction(R.drawable.ic_full_action,
                    context.getString(R.string.example_action),
                    NotificationUtil.getExamplePendingIntent(context,
                            R.string.example_action_clicked))
                    .build();
        }
    }

    private static class LongTitleActionPreset extends ActionsPreset {
        public LongTitleActionPreset() {
            super(R.string.long_title_action);
        }

        @Override
        public void apply(Context context, NotificationCompat.Builder builder,
                NotificationCompat.WearableExtender wearableOptions) {
            builder.addAction(R.drawable.ic_full_action,
                    context.getString(R.string.example_action_long_title),
                    NotificationUtil.getExamplePendingIntent(context,
                            R.string.example_action_clicked))
                    .build();
        }
    }

    private static class ReplyActionPreset extends ActionsPreset {
        public ReplyActionPreset() {
            super(R.string.reply_action);
        }

        @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_label))
                    .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();
            builder.addAction(action);
        }
    }

    private static class ReplyWithChoicesActionPreset extends ActionsPreset {
        public ReplyWithChoicesActionPreset() {
            super(R.string.reply_action_with_choices);
        }

        @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);
        }
    }

    private static class DifferentActionsOnPhoneAndWearable extends ActionsPreset {
        public DifferentActionsOnPhoneAndWearable() {
            super(R.string.different_actions_on_phone_and_wearable);
        }

        @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);
        }
    }
}




Java Source Code List

com.example.android.google.wearable.app.GridExampleActivity.java
com.example.android.google.wearable.app.MainActivity.java
com.example.android.google.wearable.watchviewstub.MainActivity.java
com.example.android.support.wearable.notifications.ActionsPreset.java
com.example.android.support.wearable.notifications.ActionsPresets.java
com.example.android.support.wearable.notifications.AnimatedNotificationDisplayActivity.java
com.example.android.support.wearable.notifications.BackgroundPickers.java
com.example.android.support.wearable.notifications.BasicNotificationDisplayActivity.java
com.example.android.support.wearable.notifications.MainActivity.java
com.example.android.support.wearable.notifications.MainActivity.java
com.example.android.support.wearable.notifications.NamedPreset.java
com.example.android.support.wearable.notifications.NotificationIntentReceiver.java
com.example.android.support.wearable.notifications.NotificationPreset.java
com.example.android.support.wearable.notifications.NotificationPreset.java
com.example.android.support.wearable.notifications.NotificationPresets.java
com.example.android.support.wearable.notifications.NotificationPresets.java
com.example.android.support.wearable.notifications.NotificationUtil.java
com.example.android.support.wearable.notifications.PriorityPreset.java
com.example.android.support.wearable.notifications.PriorityPresets.java
com.example.android.support.wearable.notifications.WearableListItemLayout.java
com.example.android.wearable.agendadata.CalendarQueryService.java
com.example.android.wearable.agendadata.Constants.java
com.example.android.wearable.agendadata.Constants.java
com.example.android.wearable.agendadata.DeleteService.java
com.example.android.wearable.agendadata.HomeListenerService.java
com.example.android.wearable.agendadata.MainActivity.java
com.example.android.wearable.datalayer.DataLayerListenerService.java
com.example.android.wearable.datalayer.MainActivity.java
com.example.android.wearable.datalayer.MainActivity.java
com.example.android.wearable.delayedconfirmation.MainActivity.java
com.example.android.wearable.delayedconfirmation.MainActivity.java
com.example.android.wearable.delayedconfirmation.WearableMessageListenerService.java
com.example.android.wearable.elizachat.ElizaResponder.java
com.example.android.wearable.elizachat.MainActivity.java
com.example.android.wearable.elizachat.ResponderService.java
com.example.android.wearable.embeddedapp.PhoneActivity.java
com.example.android.wearable.embeddedapp.WearableActivity.java
com.example.android.wearable.findphone.DisconnectListenerService.java
com.example.android.wearable.findphone.FindPhoneActivity.java
com.example.android.wearable.findphone.FindPhoneService.java
com.example.android.wearable.findphone.SoundAlarmListenerService.java
com.example.android.wearable.flashlight.MainActivity.java
com.example.android.wearable.flashlight.PartyLightView.java
com.example.android.wearable.geofencing.CheckInAndDeleteDataItemsService.java
com.example.android.wearable.geofencing.Constants.java
com.example.android.wearable.geofencing.Constants.java
com.example.android.wearable.geofencing.GeofenceTransitionsIntentService.java
com.example.android.wearable.geofencing.HomeListenerService.java
com.example.android.wearable.geofencing.MainActivity.java
com.example.android.wearable.geofencing.SimpleGeofenceStore.java
com.example.android.wearable.geofencing.SimpleGeofence.java
com.example.android.wearable.gridviewpager.MainActivity.java
com.example.android.wearable.gridviewpager.SampleGridPagerAdapter.java
com.example.android.wearable.jumpingjack.MainActivity.java
com.example.android.wearable.jumpingjack.PagerAdapter.java
com.example.android.wearable.jumpingjack.Utils.java
com.example.android.wearable.jumpingjack.fragments.CounterFragment.java
com.example.android.wearable.jumpingjack.fragments.SettingsFragment.java
com.example.android.wearable.quiz.Constants.java
com.example.android.wearable.quiz.Constants.java
com.example.android.wearable.quiz.DeleteQuestionService.java
com.example.android.wearable.quiz.JsonUtils.java
com.example.android.wearable.quiz.MainActivity.java
com.example.android.wearable.quiz.QuizListenerService.java
com.example.android.wearable.quiz.QuizReportActionService.java
com.example.android.wearable.quiz.UpdateQuestionService.java
com.example.android.wearable.recipeassistant.AssetUtils.java
com.example.android.wearable.recipeassistant.Constants.java
com.example.android.wearable.recipeassistant.MainActivity.java
com.example.android.wearable.recipeassistant.RecipeActivity.java
com.example.android.wearable.recipeassistant.RecipeListAdapter.java
com.example.android.wearable.recipeassistant.RecipeService.java
com.example.android.wearable.recipeassistant.Recipe.java
com.example.android.wearable.synchronizednotifications.DismissListener.java
com.example.android.wearable.synchronizednotifications.NotificationUpdateService.java
com.example.android.wearable.synchronizednotifications.PhoneActivity.java
com.example.android.wearable.synchronizednotifications.WearableActivity.java
com.example.android.wearable.synchronizednotifications.common.Constants.java
com.example.android.wearable.timer.SetTimerActivity.java
com.example.android.wearable.timer.TimerNotificationService.java
com.example.android.wearable.timer.util.Constants.java
com.example.android.wearable.timer.util.TimerFormat.java
com.example.android.wearable.timer.util.TimerObj.java