Home | History | Annotate | Download | only in wearaccessibilityapp
      1 /*
      2  * Copyright (C) 2017 Google Inc. All Rights Reserved.
      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.wear.wearaccessibilityapp;
     17 
     18 import android.app.Activity;
     19 import android.os.Bundle;
     20 import android.preference.Preference;
     21 import android.preference.Preference.OnPreferenceChangeListener;
     22 import android.preference.PreferenceFragment;
     23 import android.preference.PreferenceScreen;
     24 import android.preference.SwitchPreference;
     25 import android.support.wear.ambient.AmbientMode;
     26 
     27 public class InLineActivity extends Activity implements AmbientMode.AmbientCallbackProvider {
     28 
     29     @Override
     30     protected void onCreate(Bundle savedInstanceState) {
     31         super.onCreate(savedInstanceState);
     32 
     33         AmbientMode.attachAmbientSupport(this);
     34 
     35         getFragmentManager()
     36                 .beginTransaction()
     37                 .replace(android.R.id.content, new InLinePrefFragment())
     38                 .commit();
     39     }
     40 
     41     public static class InLinePrefFragment extends PreferenceFragment {
     42 
     43         private SwitchPreference mDeterminantSwitchPref;
     44         private CircledImageViewPreference mCircledImageViewPref;
     45         private ProgressBarPreference mProgressBarPreference;
     46         private PreferenceScreen mPreferenceScreen;
     47 
     48         @Override
     49         public void onCreate(Bundle savedInstanceState) {
     50             super.onCreate(savedInstanceState);
     51             // Load the preferences from an XML resource
     52             addPreferencesFromResource(R.xml.prefs_in_line_progress);
     53 
     54             mDeterminantSwitchPref =
     55                     (SwitchPreference)
     56                             findPreference(getString(R.string.key_pref_determinant_switch));
     57             mDeterminantSwitchPref.setChecked(true);
     58 
     59             mCircledImageViewPref =
     60                     (CircledImageViewPreference)
     61                             findPreference(getString(R.string.key_pref_circled_image_view));
     62 
     63             mPreferenceScreen =
     64                     (PreferenceScreen) findPreference(getString(R.string.key_pref_progress_screen));
     65 
     66             mProgressBarPreference = new ProgressBarPreference(getContext());
     67             mProgressBarPreference.setTitle("@string/indeterminant_progress");
     68 
     69             mDeterminantSwitchPref.setOnPreferenceChangeListener(
     70                     new OnPreferenceChangeListener() {
     71                         @Override
     72                         public boolean onPreferenceChange(Preference preference, Object newValue) {
     73                             mDeterminantSwitchPref.setChecked(!mDeterminantSwitchPref.isChecked());
     74                             if (mDeterminantSwitchPref.isChecked()) {
     75                                 mCircledImageViewPref.cancelCountDownTimer();
     76                                 mCircledImageViewPref.setStartCircledImageView();
     77                                 mPreferenceScreen.removePreference(mProgressBarPreference);
     78                                 mPreferenceScreen.addPreference(mCircledImageViewPref);
     79                             } else {
     80                                 mPreferenceScreen.removePreference(mCircledImageViewPref);
     81                                 mPreferenceScreen.addPreference(mProgressBarPreference);
     82                             }
     83                             return true;
     84                         }
     85                     });
     86         }
     87     }
     88 
     89     @Override
     90     public AmbientMode.AmbientCallback getAmbientCallback() {
     91         return new MyAmbientCallback();
     92     }
     93 
     94     private class MyAmbientCallback extends AmbientMode.AmbientCallback {}
     95 }
     96