Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c7997be authored by PETER LIANG's avatar PETER LIANG Committed by Android (Google) Code Review
Browse files

Merge "Refine the UI of the text reading page across SuW."

parents 76c59eb0 5e931b2c
Loading
Loading
Loading
Loading
+0 −37
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2022 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart">

    <Button
        android:id="@+id/reset_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:paddingVertical="14dp"
        android:background="?android:attr/selectableItemBackground"
        android:textColor="?android:attr/colorAccent"
        android:textSize="16sp"
        android:text="@string/accessibility_text_reading_reset_button_title"
        android:fontFamily="@*android:string/config_bodyFontFamilyMedium" />
</FrameLayout>
+11 −15
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ package com.android.settings.accessibility;

import static com.android.settings.accessibility.TextReadingResetController.ResetStateListener;

import android.app.Activity;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
@@ -44,7 +44,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
@@ -55,8 +54,7 @@ import java.util.stream.Collectors;
public class TextReadingPreferenceFragment extends DashboardFragment {
    public static final String EXTRA_LAUNCHED_FROM = "launched_from";
    private static final String TAG = "TextReadingPreferenceFragment";
    private static final String CATEGORY_FOR_ANYTHING_ELSE =
            "com.android.settings.suggested.category.DISPLAY_SETTINGS";
    private static final String SETUP_WIZARD_PACKAGE = "setupwizard";
    static final String FONT_SIZE_KEY = "font_size";
    static final String DISPLAY_SIZE_KEY = "display_size";
    static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
@@ -179,10 +177,8 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
                new TextReadingResetController(context, RESET_KEY,
                        v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS));
        resetController.setEntryPoint(mEntryPoint);
        resetController.setVisible(!WizardManagerHelper.isAnySetupWizard(getIntent()));
        controllers.add(resetController);
        if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
            resetController.setSetupWizardStyle();
        }

        return controllers;
    }
@@ -230,6 +226,13 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
        }
    }

    protected boolean isCallingFromAnythingElseEntryPoint() {
        final Activity activity = getActivity();
        final String callingPackage = activity != null ? activity.getCallingPackage() : null;

        return callingPackage != null && callingPackage.contains(SETUP_WIZARD_PACKAGE);
    }

    @VisibleForTesting
    DisplaySizeData createDisplaySizeData(Context context) {
        return new DisplaySizeData(context);
@@ -242,14 +245,7 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
            return;
        }

        final Intent intent = getIntent();
        if (intent == null) {
            mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
            return;
        }

        final Set<String> categories = intent.getCategories();
        mEntryPoint = categories != null && categories.contains(CATEGORY_FOR_ANYTHING_ELSE)
        mEntryPoint = isCallingFromAnythingElseEntryPoint()
                ? EntryPoint.SUW_ANYTHING_ELSE : EntryPoint.UNKNOWN_ENTRY;
    }

+28 −1
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.settings.accessibility;

import static android.app.Activity.RESULT_CANCELED;

import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums.DIALOG_RESET_SETTINGS;

import android.app.settings.SettingsEnums;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -28,9 +32,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settingslib.Utils;

import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.GlifPreferenceLayout;


/**
 * A {@link androidx.preference.PreferenceFragmentCompat} that displays the settings page related
 * to the text and reading option in the SetupWizard.
@@ -48,6 +53,28 @@ public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPref
        icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
        AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
                /* description= */ null, icon);

        final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
        mixin.setSecondaryButton(
                new FooterButton.Builder(getContext())
                        .setText(R.string.accessibility_text_reading_reset_button_title)
                        .setListener(l -> showDialog(DIALOG_RESET_SETTINGS))
                        .setButtonType(FooterButton.ButtonType.CLEAR)
                        .setTheme(R.style.SudGlifButton_Secondary)
                        .build());

        if (isCallingFromAnythingElseEntryPoint()) {
            mixin.setPrimaryButton(
                    new FooterButton.Builder(getContext())
                            .setText(R.string.done)
                            .setListener(l -> {
                                setResult(RESULT_CANCELED);
                                finish();
                            })
                            .setButtonType(FooterButton.ButtonType.DONE)
                            .setTheme(R.style.SudGlifButton_Primary)
                            .build());
        }
    }

    @Override
+4 −6
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import androidx.annotation.Nullable;
import androidx.preference.PreferenceScreen;

import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.accessibility.TextReadingResetPreference.ButtonStyle;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;

@@ -31,8 +30,7 @@ import com.android.settings.core.instrumentation.SettingsStatsLog;
 * The controller of the reset button in the text and reading options page.
 */
class TextReadingResetController extends BasePreferenceController {
    @ButtonStyle
    private int mButtonStyle;
    private boolean mIsVisible;
    private final View.OnClickListener mOnResetClickListener;

    @EntryPoint
@@ -67,11 +65,11 @@ class TextReadingResetController extends BasePreferenceController {
            }
        });

        resetPreference.setSetupWizardStyle(mButtonStyle);
        setVisible(screen, getPreferenceKey(), mIsVisible);
    }

    void setSetupWizardStyle() {
        mButtonStyle = ButtonStyle.SUW;
    void setVisible(boolean isVisible) {
        mIsVisible = isVisible;
    }

    /**
+1 −22
Original line number Diff line number Diff line
@@ -20,15 +20,11 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.IntDef;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * The preference which is used for resetting the status of all preferences in the display size
 * and text page.
@@ -36,20 +32,10 @@ import java.lang.annotation.RetentionPolicy;
public class TextReadingResetPreference extends Preference {
    private View.OnClickListener mOnResetClickListener;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            ButtonStyle.DEFAULT,
            ButtonStyle.SUW,
    })
    @interface ButtonStyle {
        int DEFAULT = 0;
        int SUW = 1;
    }

    public TextReadingResetPreference(Context context, AttributeSet attrs) {
        super(context, attrs);

        setSetupWizardStyle(ButtonStyle.DEFAULT);
        setLayoutResource(R.layout.accessibility_text_reading_reset_button);
    }

    @Override
@@ -60,13 +46,6 @@ public class TextReadingResetPreference extends Preference {
        view.setOnClickListener(mOnResetClickListener);
    }

    void setSetupWizardStyle(@ButtonStyle int style) {
        final int layoutResId = (style == ButtonStyle.SUW)
                ? R.layout.accessibility_text_reading_reset_button_suw
                : R.layout.accessibility_text_reading_reset_button;
        setLayoutResource(layoutResId);
    }

    void setOnResetClickListener(View.OnClickListener resetClickListener) {
        mOnResetClickListener = resetClickListener;
    }
Loading