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