1 /* 2 * Copyright (C) 2022 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.accessibility; 18 19 import android.content.Context; 20 import android.view.View; 21 22 import androidx.annotation.Nullable; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint; 26 import com.android.settings.core.BasePreferenceController; 27 import com.android.settings.core.instrumentation.SettingsStatsLog; 28 29 /** 30 * The controller of the reset button in the text and reading options page. 31 */ 32 class TextReadingResetController extends BasePreferenceController { 33 private boolean mIsVisible; 34 private final View.OnClickListener mOnResetClickListener; 35 36 @EntryPoint 37 private int mEntryPoint; 38 TextReadingResetController(Context context, String preferenceKey, @Nullable View.OnClickListener listener)39 TextReadingResetController(Context context, String preferenceKey, 40 @Nullable View.OnClickListener listener) { 41 super(context, preferenceKey); 42 mOnResetClickListener = listener; 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 return AVAILABLE; 48 } 49 50 @Override displayPreference(PreferenceScreen screen)51 public void displayPreference(PreferenceScreen screen) { 52 super.displayPreference(screen); 53 54 final TextReadingResetPreference resetPreference = 55 (TextReadingResetPreference) screen.findPreference(getPreferenceKey()); 56 resetPreference.setOnResetClickListener(v -> { 57 if (mOnResetClickListener != null) { 58 mOnResetClickListener.onClick(v); 59 60 SettingsStatsLog.write( 61 SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED, 62 AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()), 63 /* reset */ -1, 64 AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint)); 65 } 66 }); 67 68 setVisible(screen, getPreferenceKey(), mIsVisible); 69 } 70 setVisible(boolean isVisible)71 void setVisible(boolean isVisible) { 72 mIsVisible = isVisible; 73 } 74 75 /** 76 * The entry point is used for logging. 77 * 78 * @param entryPoint from which settings page 79 */ setEntryPoint(@ntryPoint int entryPoint)80 void setEntryPoint(@EntryPoint int entryPoint) { 81 mEntryPoint = entryPoint; 82 } 83 84 /** 85 * Interface for resetting to default state. 86 */ 87 interface ResetStateListener { 88 /** 89 * Called when the reset button was clicked. 90 */ resetState()91 void resetState(); 92 } 93 } 94