1 /* 2 * Copyright (C) 2020 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 17 package com.android.settings.gestures; 18 19 import android.content.Context; 20 import android.net.Uri; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.core.BasePreferenceController; 27 import com.android.settingslib.core.lifecycle.LifecycleObserver; 28 import com.android.settingslib.core.lifecycle.events.OnStart; 29 import com.android.settingslib.core.lifecycle.events.OnStop; 30 31 /** 32 * Preference controller for One-handed mode shortcut settings 33 */ 34 public class OneHandedEnablePreferenceController extends BasePreferenceController 35 implements OneHandedSettingsUtils.TogglesCallback, LifecycleObserver, OnStart, OnStop { 36 37 private final OneHandedSettingsUtils mUtils; 38 private Preference mPreference; 39 OneHandedEnablePreferenceController(Context context, String preferenceKey)40 public OneHandedEnablePreferenceController(Context context, String preferenceKey) { 41 super(context, preferenceKey); 42 mUtils = new OneHandedSettingsUtils(context); 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 48 } 49 50 @Override getSummary()51 public CharSequence getSummary() { 52 return mContext.getText( 53 OneHandedSettingsUtils.isOneHandedModeEnabled(mContext) 54 ? R.string.gesture_setting_on : R.string.gesture_setting_off); 55 } 56 57 @Override displayPreference(PreferenceScreen screen)58 public void displayPreference(PreferenceScreen screen) { 59 super.displayPreference(screen); 60 mPreference = screen.findPreference(getPreferenceKey()); 61 } 62 63 @Override onStart()64 public void onStart() { 65 mUtils.registerToggleAwareObserver(this); 66 } 67 68 @Override onStop()69 public void onStop() { 70 mUtils.unregisterToggleAwareObserver(); 71 } 72 73 @Override onChange(Uri uri)74 public void onChange(Uri uri) { 75 if (mPreference == null) { 76 return; 77 } 78 if (uri.equals(OneHandedSettingsUtils.ONE_HANDED_MODE_ENABLED_URI)) { 79 refreshSummary(mPreference); 80 } 81 } 82 } 83