summaryrefslogtreecommitdiff
path: root/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/ActionsPresets.java
blob: ff639dcb92e8493c3bbbf289533e5b06a1fb2904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.support.wearable.notifications;

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