[Catalyst] Refactor some Text Reading items

Test: atest TextReadingPreferenceFragment
Bug: 372776688
Flag: com.android.settings.flags.catalyst_text_reading_screen
Change-Id: I49aa91ca6f441814d6aaeb86826291a155a306f1
This commit is contained in:
Sunny Shao
2024-12-06 21:13:05 +08:00
parent dc1a52a2ee
commit a02483adc9
3 changed files with 55 additions and 14 deletions

View File

@@ -66,7 +66,6 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
static final String RESET_KEY = "reset";
static final String PREVIEW_KEY = "preview";
private static final String NEED_RESET_SETTINGS = "need_reset_settings";
private static final String LAST_PREVIEW_INDEX = "last_preview_index";
private static final int UNKNOWN_INDEX = -1;
private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
@@ -111,13 +110,6 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
if (savedInstanceState.getBoolean(NEED_RESET_SETTINGS)) {
mResetStateListeners.forEach(ResetStateListener::resetState);
}
if (savedInstanceState.containsKey(LAST_PREVIEW_INDEX)) {
final int lastPreviewIndex = savedInstanceState.getInt(LAST_PREVIEW_INDEX);
if (lastPreviewIndex != UNKNOWN_INDEX) {
mPreviewController.setCurrentItem(lastPreviewIndex);
}
}
}
}
@@ -252,8 +244,6 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
if (mNeedResetSettings) {
outState.putBoolean(NEED_RESET_SETTINGS, true);
}
outState.putInt(LAST_PREVIEW_INDEX, mPreviewController.getCurrentItem());
}
@Override

View File

@@ -17,6 +17,8 @@
package com.android.settings.accessibility;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
@@ -36,6 +38,7 @@ import com.android.settings.widget.DotsPageIndicator;
* A {@link Preference} that could show the preview related to the text and reading options.
*/
public class TextReadingPreviewPreference extends Preference {
private static final String KEY_LAST_INDEX = "last_preview_index";
private int mCurrentItem;
private int mLastLayerIndex;
private PreviewPagerAdapter mPreviewAdapter;
@@ -98,6 +101,22 @@ public class TextReadingPreviewPreference extends Preference {
updatePagerAndIndicator(viewPager, pageIndicator);
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle state = new Bundle();
state.putParcelable(null, super.onSaveInstanceState());
state.putInt(KEY_LAST_INDEX, getCurrentItem());
return state;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
Bundle bundle = (Bundle) state;
super.onRestoreInstanceState(bundle.getParcelable(null));
setCurrentItem(bundle.getInt(KEY_LAST_INDEX));
}
/**
* Set the minimum preview layout horizontal inner padding.
*/

View File

@@ -56,10 +56,10 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
private final int mTextStartId;
private final int mTextEndId;
private final int mTickMarkId;
private final int mIconStartId;
private final int mIconEndId;
private final int mIconStartContentDescriptionId;
private final int mIconEndContentDescriptionId;
private int mIconStartId;
private int mIconEndId;
private int mIconStartContentDescriptionId;
private int mIconEndContentDescriptionId;
private OnPreferenceChangeListener mStopListener;
private SeekBar.OnSeekBarChangeListener mSeekBarChangeListener;
@@ -110,6 +110,38 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
return mSeekBar;
}
/** Set the start icon of the Seekbar. */
public void setIconStart(int iconStartId) {
if (mIconStartId != iconStartId) {
mIconStartId = iconStartId;
notifyChanged();
}
}
/** Set the description resource id of the start icon. */
public void setIconStartContentDescription(int iconStartContentDescriptionId) {
if (mIconStartContentDescriptionId != iconStartContentDescriptionId) {
mIconStartContentDescriptionId = iconStartContentDescriptionId;
notifyChanged();
}
}
/** Set the end icon of the Seekbar. */
public void setIconEnd(int iconEndId) {
if (mIconEndId != iconEndId) {
mIconEndId = iconEndId;
notifyChanged();
}
}
/** Set the description resource id of the end icon. */
public void setIconEndContentDescription(int iconEndContentDescriptionId) {
if (mIconEndContentDescriptionId != iconEndContentDescriptionId) {
mIconEndContentDescriptionId = iconEndContentDescriptionId;
notifyChanged();
}
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);