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.content.Intent; 20 import android.os.Bundle; 21 import android.support.wearable.complications.ComplicationProviderInfo; 22 import android.support.wearable.complications.ProviderChooserIntent; 23 import android.util.Log; 24 25 import androidx.recyclerview.widget.LinearLayoutManager; 26 import androidx.wear.widget.WearableRecyclerView; 27 28 import com.example.android.wearable.watchface.R; 29 import com.example.android.wearable.watchface.model.AnalogComplicationConfigData; 30 import com.example.android.wearable.watchface.watchface.AnalogComplicationWatchFaceService; 31 32 /** 33 * The watch-side config activity for {@link AnalogComplicationWatchFaceService}, which 34 * allows for setting the left and right complications of watch face along with the second's marker 35 * color, background color, unread notifications toggle, and background complication image. 36 */ 37 public class AnalogComplicationConfigActivity extends Activity { 38 39 private static final String TAG = AnalogComplicationConfigActivity.class.getSimpleName(); 40 41 static final int COMPLICATION_CONFIG_REQUEST_CODE = 1001; 42 static final int UPDATE_COLORS_CONFIG_REQUEST_CODE = 1002; 43 44 private WearableRecyclerView mWearableRecyclerView; 45 private AnalogComplicationConfigRecyclerViewAdapter mAdapter; 46 47 @Override onCreate(Bundle savedInstanceState)48 protected void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 51 setContentView(R.layout.activity_analog_complication_config); 52 53 mAdapter = new AnalogComplicationConfigRecyclerViewAdapter( 54 getApplicationContext(), 55 AnalogComplicationConfigData.getWatchFaceServiceClass(), 56 AnalogComplicationConfigData.getDataToPopulateAdapter(this)); 57 58 mWearableRecyclerView = 59 (WearableRecyclerView) findViewById(R.id.wearable_recycler_view); 60 61 // Aligns the first and last items on the list vertically centered on the screen. 62 mWearableRecyclerView.setEdgeItemsCenteringEnabled(true); 63 64 mWearableRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 65 66 // Improves performance because we know changes in content do not change the layout size of 67 // the RecyclerView. 68 mWearableRecyclerView.setHasFixedSize(true); 69 70 mWearableRecyclerView.setAdapter(mAdapter); 71 } 72 73 @Override onActivityResult(int requestCode, int resultCode, Intent data)74 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 75 76 if (requestCode == COMPLICATION_CONFIG_REQUEST_CODE 77 && resultCode == RESULT_OK) { 78 79 // Retrieves information for selected Complication provider. 80 ComplicationProviderInfo complicationProviderInfo = 81 data.getParcelableExtra(ProviderChooserIntent.EXTRA_PROVIDER_INFO); 82 Log.d(TAG, "Provider: " + complicationProviderInfo); 83 84 // Updates preview with new complication information for selected complication id. 85 // Note: complication id is saved and tracked in the adapter class. 86 mAdapter.updateSelectedComplication(complicationProviderInfo); 87 88 } else if (requestCode == UPDATE_COLORS_CONFIG_REQUEST_CODE 89 && resultCode == RESULT_OK) { 90 91 // Updates highlight and background colors based on the user preference. 92 mAdapter.updatePreviewColors(); 93 } 94 } 95 }