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.config;
17 
18 import android.app.Activity;
19 import android.os.Bundle;
20 
21 import androidx.recyclerview.widget.LinearLayoutManager;
22 import androidx.wear.widget.WearableRecyclerView;
23 
24 import com.example.android.wearable.watchface.R;
25 import com.example.android.wearable.watchface.model.AnalogComplicationConfigData;
26 
27 /**
28  * Allows user to select color for something on the watch face (background, highlight,etc.) and
29  * saves it to {@link android.content.SharedPreferences} in RecyclerView.Adapter.
30  */
31 public class ColorSelectionActivity extends Activity {
32 
33     private static final String TAG = ColorSelectionActivity.class.getSimpleName();
34 
35     static final String EXTRA_SHARED_PREF =
36             "com.example.android.wearable.watchface.config.extra.EXTRA_SHARED_PREF";
37 
38     private WearableRecyclerView mConfigAppearanceWearableRecyclerView;
39 
40     private ColorSelectionRecyclerViewAdapter mColorSelectionRecyclerViewAdapter;
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         setContentView(R.layout.activity_color_selection_config);
46 
47         // Assigns SharedPreference String used to save color selected.
48         String sharedPrefString = getIntent().getStringExtra(EXTRA_SHARED_PREF);
49 
50         mColorSelectionRecyclerViewAdapter = new ColorSelectionRecyclerViewAdapter(
51                 sharedPrefString,
52                 AnalogComplicationConfigData.getColorOptionsDataSet());
53 
54         mConfigAppearanceWearableRecyclerView =
55                 (WearableRecyclerView) findViewById(R.id.wearable_recycler_view);
56 
57         // Aligns the first and last items on the list vertically centered on the screen.
58         mConfigAppearanceWearableRecyclerView.setEdgeItemsCenteringEnabled(true);
59 
60         mConfigAppearanceWearableRecyclerView.setLayoutManager(new LinearLayoutManager(this));
61 
62         // Improves performance because we know changes in content do not change the layout size of
63         // the RecyclerView.
64         mConfigAppearanceWearableRecyclerView.setHasFixedSize(true);
65 
66         mConfigAppearanceWearableRecyclerView.setAdapter(mColorSelectionRecyclerViewAdapter);
67     }
68 }