Home | History | Annotate | Download | only in com.example.android.support.wearable.notifications
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.support.wearable.notifications;
     18 
     19 import android.content.Context;
     20 import android.support.v4.app.NotificationCompat;
     21 import android.support.v4.app.RemoteInput;
     22 
     23 /**
     24  * Collection of notification actions presets.
     25  */
     26 public class ActionsPresets {
     27     public static final ActionsPreset NO_ACTIONS_PRESET = new NoActionsPreset();
     28     public static final ActionsPreset SINGLE_ACTION_PRESET = new SingleActionPreset();
     29 
     30     public static final ActionsPreset[] PRESETS = new ActionsPreset[] {
     31             NO_ACTIONS_PRESET,
     32             SINGLE_ACTION_PRESET,
     33             new ReplyActionPreset(),
     34             new ReplyWithChoicesActionPreset(),
     35             new DifferentActionsOnPhoneAndWearable(),
     36             new LongTitleActionPreset()
     37     };
     38 
     39     private static class NoActionsPreset extends ActionsPreset {
     40         public NoActionsPreset() {
     41             super(R.string.no_actions);
     42         }
     43 
     44         @Override
     45         public void apply(Context context, NotificationCompat.Builder builder,
     46                 NotificationCompat.WearableExtender wearableOptions) {
     47         }
     48     }
     49 
     50     private static class SingleActionPreset extends ActionsPreset {
     51         public SingleActionPreset() {
     52             super(R.string.single_action);
     53         }
     54 
     55         @Override
     56         public void apply(Context context, NotificationCompat.Builder builder,
     57                 NotificationCompat.WearableExtender wearableOptions) {
     58             builder.addAction(R.drawable.ic_full_action,
     59                     context.getString(R.string.example_action),
     60                     NotificationUtil.getExamplePendingIntent(context,
     61                             R.string.example_action_clicked))
     62                     .build();
     63         }
     64     }
     65 
     66     private static class LongTitleActionPreset extends ActionsPreset {
     67         public LongTitleActionPreset() {
     68             super(R.string.long_title_action);
     69         }
     70 
     71         @Override
     72         public void apply(Context context, NotificationCompat.Builder builder,
     73                 NotificationCompat.WearableExtender wearableOptions) {
     74             builder.addAction(R.drawable.ic_full_action,
     75                     context.getString(R.string.example_action_long_title),
     76                     NotificationUtil.getExamplePendingIntent(context,
     77                             R.string.example_action_clicked))
     78                     .build();
     79         }
     80     }
     81 
     82     private static class ReplyActionPreset extends ActionsPreset {
     83         public ReplyActionPreset() {
     84             super(R.string.reply_action);
     85         }
     86 
     87         @Override
     88         public void apply(Context context, NotificationCompat.Builder builder,
     89                 NotificationCompat.WearableExtender wearableOptions) {
     90             RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
     91                     .setLabel(context.getString(R.string.example_reply_label))
     92                     .build();
     93             NotificationCompat.Action action = new NotificationCompat.Action.Builder(
     94                     R.drawable.ic_full_reply,
     95                     context.getString(R.string.example_reply_action),
     96                     NotificationUtil.getExamplePendingIntent(context,
     97                             R.string.example_reply_action_clicked))
     98                     .addRemoteInput(remoteInput)
     99                     .build();
    100             builder.addAction(action);
    101         }
    102     }
    103 
    104     private static class ReplyWithChoicesActionPreset extends ActionsPreset {
    105         public ReplyWithChoicesActionPreset() {
    106             super(R.string.reply_action_with_choices);
    107         }
    108 
    109         @Override
    110         public void apply(Context context, NotificationCompat.Builder builder,
    111                 NotificationCompat.WearableExtender wearableOptions) {
    112             RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
    113                     .setLabel(context.getString(R.string.example_reply_answer_label))
    114                     .setChoices(new String[] { context.getString(R.string.yes),
    115                             context.getString(R.string.no), context.getString(R.string.maybe) })
    116                     .build();
    117             NotificationCompat.Action action = new NotificationCompat.Action.Builder(
    118                     R.drawable.ic_full_reply,
    119                     context.getString(R.string.example_reply_action),
    120                     NotificationUtil.getExamplePendingIntent(context,
    121                             R.string.example_reply_action_clicked))
    122                     .addRemoteInput(remoteInput)
    123                     .build();
    124             wearableOptions.addAction(action);
    125         }
    126     }
    127 
    128     private static class DifferentActionsOnPhoneAndWearable extends ActionsPreset {
    129         public DifferentActionsOnPhoneAndWearable() {
    130             super(R.string.different_actions_on_phone_and_wearable);
    131         }
    132 
    133         @Override
    134         public void apply(Context context, NotificationCompat.Builder builder,
    135                 NotificationCompat.WearableExtender wearableOptions) {
    136             NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
    137                     R.drawable.ic_full_action,
    138                     context.getString(R.string.phone_action),
    139                     NotificationUtil.getExamplePendingIntent(context,
    140                             R.string.phone_action_clicked))
    141                     .build();
    142             builder.addAction(phoneAction);
    143 
    144             RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
    145                     .setLabel(context.getString(R.string.example_reply_label))
    146                     .build();
    147 
    148             NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
    149                     R.drawable.ic_full_reply,
    150                     context.getString(R.string.wearable_action),
    151                     NotificationUtil.getExamplePendingIntent(context,
    152                             R.string.wearable_action_clicked))
    153                     .addRemoteInput(remoteInput)
    154                     .build();
    155             wearableOptions.addAction(wearableAction);
    156         }
    157     }
    158 }
    159