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