1 /*
2  * Copyright (C) 2017 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 package com.example.android.wearable.watchface.model;
17 
18 import android.content.Context;
19 import android.graphics.Color;
20 
21 import androidx.recyclerview.widget.RecyclerView;
22 import androidx.recyclerview.widget.RecyclerView.ViewHolder;
23 
24 import com.example.android.wearable.watchface.R;
25 import com.example.android.wearable.watchface.config.AnalogComplicationConfigActivity;
26 import com.example.android.wearable.watchface.config.AnalogComplicationConfigRecyclerViewAdapter;
27 import com.example.android.wearable.watchface.config.ColorSelectionActivity;
28 import com.example.android.wearable.watchface.watchface.AnalogComplicationWatchFaceService;
29 
30 import java.util.ArrayList;
31 
32 /**
33  * Data represents different views for configuring the
34  * {@link AnalogComplicationWatchFaceService} watch face's appearance and complications
35  * via {@link AnalogComplicationConfigActivity}.
36  */
37 public class AnalogComplicationConfigData {
38 
39 
40     /**
41      * Interface all ConfigItems must implement so the {@link RecyclerView}'s Adapter associated
42      * with the configuration activity knows what type of ViewHolder to inflate.
43      */
44     public interface ConfigItemType {
getConfigType()45         int getConfigType();
46     }
47 
48     /**
49      * Returns Watch Face Service class associated with configuration Activity.
50      */
getWatchFaceServiceClass()51     public static Class getWatchFaceServiceClass() {
52         return AnalogComplicationWatchFaceService.class;
53     }
54 
55     /**
56      * Returns Material Design color options.
57      */
getColorOptionsDataSet()58     public static ArrayList<Integer> getColorOptionsDataSet() {
59         ArrayList<Integer> colorOptionsDataSet = new ArrayList<>();
60         colorOptionsDataSet.add(Color.parseColor("#FFFFFF")); // White
61 
62         colorOptionsDataSet.add(Color.parseColor("#FFEB3B")); // Yellow
63         colorOptionsDataSet.add(Color.parseColor("#FFC107")); // Amber
64         colorOptionsDataSet.add(Color.parseColor("#FF9800")); // Orange
65         colorOptionsDataSet.add(Color.parseColor("#FF5722")); // Deep Orange
66 
67         colorOptionsDataSet.add(Color.parseColor("#F44336")); // Red
68         colorOptionsDataSet.add(Color.parseColor("#E91E63")); // Pink
69 
70         colorOptionsDataSet.add(Color.parseColor("#9C27B0")); // Purple
71         colorOptionsDataSet.add(Color.parseColor("#673AB7")); // Deep Purple
72         colorOptionsDataSet.add(Color.parseColor("#3F51B5")); // Indigo
73         colorOptionsDataSet.add(Color.parseColor("#2196F3")); // Blue
74         colorOptionsDataSet.add(Color.parseColor("#03A9F4")); // Light Blue
75 
76         colorOptionsDataSet.add(Color.parseColor("#00BCD4")); // Cyan
77         colorOptionsDataSet.add(Color.parseColor("#009688")); // Teal
78         colorOptionsDataSet.add(Color.parseColor("#4CAF50")); // Green
79         colorOptionsDataSet.add(Color.parseColor("#8BC34A")); // Lime Green
80         colorOptionsDataSet.add(Color.parseColor("#CDDC39")); // Lime
81 
82         colorOptionsDataSet.add(Color.parseColor("#607D8B")); // Blue Grey
83         colorOptionsDataSet.add(Color.parseColor("#9E9E9E")); // Grey
84         colorOptionsDataSet.add(Color.parseColor("#795548")); // Brown
85         colorOptionsDataSet.add(Color.parseColor("#000000")); // Black
86 
87         return colorOptionsDataSet;
88     }
89 
90     /**
91      * Includes all data to populate each of the 5 different custom
92      * {@link ViewHolder} types in {@link AnalogComplicationConfigRecyclerViewAdapter}.
93      */
getDataToPopulateAdapter(Context context)94     public static ArrayList<ConfigItemType> getDataToPopulateAdapter(Context context) {
95 
96         ArrayList<ConfigItemType> settingsConfigData = new ArrayList<>();
97 
98         // Data for watch face preview and complications UX in settings Activity.
99         ConfigItemType complicationConfigItem =
100                 new PreviewAndComplicationsConfigItem(R.drawable.add_complication);
101         settingsConfigData.add(complicationConfigItem);
102 
103         // Data for "more options" UX in settings Activity.
104         ConfigItemType moreOptionsConfigItem =
105                 new MoreOptionsConfigItem(R.drawable.ic_expand_more_white_18dp);
106         settingsConfigData.add(moreOptionsConfigItem);
107 
108         // Data for highlight/marker (second hand) color UX in settings Activity.
109         ConfigItemType markerColorConfigItem =
110                 new ColorConfigItem(
111                         context.getString(R.string.config_marker_color_label),
112                         R.drawable.icn_styles,
113                         context.getString(R.string.saved_marker_color),
114                         ColorSelectionActivity.class);
115         settingsConfigData.add(markerColorConfigItem);
116 
117         // Data for Background color UX in settings Activity.
118         ConfigItemType backgroundColorConfigItem =
119                 new ColorConfigItem(
120                         context.getString(R.string.config_background_color_label),
121                         R.drawable.icn_styles,
122                         context.getString(R.string.saved_background_color),
123                         ColorSelectionActivity.class);
124         settingsConfigData.add(backgroundColorConfigItem);
125 
126         // Data for 'Unread Notifications' UX (toggle) in settings Activity.
127         ConfigItemType unreadNotificationsConfigItem =
128                 new UnreadNotificationConfigItem(
129                         context.getString(R.string.config_unread_notifications_label),
130                         R.drawable.ic_notifications_white_24dp,
131                         R.drawable.ic_notifications_off_white_24dp,
132                         R.string.saved_unread_notifications_pref);
133         settingsConfigData.add(unreadNotificationsConfigItem);
134 
135         // Data for background complications UX in settings Activity.
136         ConfigItemType backgroundImageComplicationConfigItem =
137                 // TODO (jewalker): Revised in another CL to support background complication.
138                 new BackgroundComplicationConfigItem(
139                         context.getString(R.string.config_background_image_complication_label),
140                         R.drawable.ic_landscape_white);
141         settingsConfigData.add(backgroundImageComplicationConfigItem);
142 
143         return settingsConfigData;
144     }
145 
146     /**
147      * Data for Watch Face Preview with Complications Preview item in RecyclerView.
148      */
149     public static class PreviewAndComplicationsConfigItem implements ConfigItemType {
150 
151         private int defaultComplicationResourceId;
152 
PreviewAndComplicationsConfigItem(int defaultComplicationResourceId)153         PreviewAndComplicationsConfigItem(int defaultComplicationResourceId) {
154             this.defaultComplicationResourceId = defaultComplicationResourceId;
155         }
156 
getDefaultComplicationResourceId()157         public int getDefaultComplicationResourceId() {
158             return defaultComplicationResourceId;
159         }
160 
161         @Override
getConfigType()162         public int getConfigType() {
163             return AnalogComplicationConfigRecyclerViewAdapter.TYPE_PREVIEW_AND_COMPLICATIONS_CONFIG;
164         }
165     }
166 
167     /**
168      * Data for "more options" item in RecyclerView.
169      */
170     public static class MoreOptionsConfigItem implements ConfigItemType {
171 
172         private int iconResourceId;
173 
MoreOptionsConfigItem(int iconResourceId)174         MoreOptionsConfigItem(int iconResourceId) {
175             this.iconResourceId = iconResourceId;
176         }
177 
getIconResourceId()178         public int getIconResourceId() {
179             return iconResourceId;
180         }
181 
182         @Override
getConfigType()183         public int getConfigType() {
184             return AnalogComplicationConfigRecyclerViewAdapter.TYPE_MORE_OPTIONS;
185         }
186     }
187 
188     /**
189      * Data for color picker item in RecyclerView.
190      */
191     public static class ColorConfigItem  implements ConfigItemType {
192 
193         private String name;
194         private int iconResourceId;
195         private String sharedPrefString;
196         private Class<ColorSelectionActivity> activityToChoosePreference;
197 
ColorConfigItem( String name, int iconResourceId, String sharedPrefString, Class<ColorSelectionActivity> activity)198         ColorConfigItem(
199                 String name,
200                 int iconResourceId,
201                 String sharedPrefString,
202                 Class<ColorSelectionActivity> activity) {
203             this.name = name;
204             this.iconResourceId = iconResourceId;
205             this.sharedPrefString = sharedPrefString;
206             this.activityToChoosePreference = activity;
207         }
208 
getName()209         public String getName() {
210             return name;
211         }
212 
getIconResourceId()213         public int getIconResourceId() {
214             return iconResourceId;
215         }
216 
getSharedPrefString()217         public String getSharedPrefString() {
218             return sharedPrefString;
219         }
220 
getActivityToChoosePreference()221         public Class<ColorSelectionActivity> getActivityToChoosePreference() {
222             return activityToChoosePreference;
223         }
224 
225         @Override
getConfigType()226         public int getConfigType() {
227             return AnalogComplicationConfigRecyclerViewAdapter.TYPE_COLOR_CONFIG;
228         }
229     }
230 
231     /**
232      * Data for Unread Notification preference picker item in RecyclerView.
233      */
234     public static class UnreadNotificationConfigItem  implements ConfigItemType {
235 
236         private String name;
237         private int iconEnabledResourceId;
238         private int iconDisabledResourceId;
239         private int sharedPrefId;
240 
UnreadNotificationConfigItem( String name, int iconEnabledResourceId, int iconDisabledResourceId, int sharedPrefId)241         UnreadNotificationConfigItem(
242                 String name,
243                 int iconEnabledResourceId,
244                 int iconDisabledResourceId,
245                 int sharedPrefId) {
246             this.name = name;
247             this.iconEnabledResourceId = iconEnabledResourceId;
248             this.iconDisabledResourceId = iconDisabledResourceId;
249             this.sharedPrefId = sharedPrefId;
250         }
251 
getName()252         public String getName() {
253             return name;
254         }
255 
getIconEnabledResourceId()256         public int getIconEnabledResourceId() {
257             return iconEnabledResourceId;
258         }
259 
getIconDisabledResourceId()260         public int getIconDisabledResourceId() {
261             return iconDisabledResourceId;
262         }
263 
getSharedPrefId()264         public int getSharedPrefId() {
265             return sharedPrefId;
266         }
267 
268         @Override
getConfigType()269         public int getConfigType() {
270             return AnalogComplicationConfigRecyclerViewAdapter.TYPE_UNREAD_NOTIFICATION_CONFIG;
271         }
272     }
273 
274     /**
275      * Data for background image complication picker item in RecyclerView.
276      */
277     public static class BackgroundComplicationConfigItem  implements ConfigItemType {
278 
279         private String name;
280         private int iconResourceId;
281 
BackgroundComplicationConfigItem( String name, int iconResourceId)282         BackgroundComplicationConfigItem(
283                 String name,
284                 int iconResourceId) {
285 
286             this.name = name;
287             this.iconResourceId = iconResourceId;
288         }
289 
getName()290         public String getName() {
291             return name;
292         }
293 
getIconResourceId()294         public int getIconResourceId() {
295             return iconResourceId;
296         }
297 
298         @Override
getConfigType()299         public int getConfigType() {
300             return AnalogComplicationConfigRecyclerViewAdapter.TYPE_BACKGROUND_COMPLICATION_IMAGE_CONFIG;
301         }
302     }
303 }