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

Commit 472a340b authored by Chun-Ku Lin's avatar Chun-Ku Lin Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Allow update the max lines on the title"" into main

parents 95d75da0 2b11b4d2
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ android_library {
    static_libs: [
    static_libs: [
        "androidx.preference_preference",
        "androidx.preference_preference",
        "SettingsLibSettingsTheme",
        "SettingsLibSettingsTheme",
        "settingslib_selectorwithwidgetpreference_flags_lib",
    ],
    ],


    sdk_version: "system_current",
    sdk_version: "system_current",
@@ -30,3 +31,25 @@ android_library {
        "com.android.mediaprovider",
        "com.android.mediaprovider",
    ],
    ],
}
}

aconfig_declarations {
    name: "settingslib_selectorwithwidgetpreference_flags",
    package: "com.android.settingslib.widget.selectorwithwidgetpreference.flags",
    container: "system",
    srcs: [
        "aconfig/selectorwithwidgetpreference.aconfig",
    ],
}

java_aconfig_library {
    name: "settingslib_selectorwithwidgetpreference_flags_lib",
    aconfig_declarations: "settingslib_selectorwithwidgetpreference_flags",

    min_sdk_version: "30",
    sdk_version: "system_current",
    apex_available: [
        "//apex_available:platform",
        "com.android.permission",
        "com.android.mediaprovider",
    ],
}
+13 −0
Original line number Original line Diff line number Diff line
package: "com.android.settingslib.widget.selectorwithwidgetpreference.flags"
container: "system"

flag {
    name: "allow_set_title_max_lines"
    namespace: "accessibility"
    description: "Allow changes to the title max lines so it's not always fixed to 2"
    bug: "356726764"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+22 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2024 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.
  -->

<resources>
    <declare-styleable name="SelectorWithWidgetPreference">
        <!-- The maximum number of lines for rendering the title. -->
        <attr name="titleMaxLines" format="integer" />
    </declare-styleable>
</resources>
 No newline at end of file
+33 −5
Original line number Original line Diff line number Diff line
@@ -17,15 +17,21 @@
package com.android.settingslib.widget;
package com.android.settingslib.widget;


import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.View;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.CheckBoxPreference;
import androidx.preference.CheckBoxPreference;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.PreferenceViewHolder;


import com.android.settingslib.widget.preference.selector.R;
import com.android.settingslib.widget.preference.selector.R;
import com.android.settingslib.widget.selectorwithwidgetpreference.flags.Flags;


/**
/**
 * Selector preference (checkbox or radio button) with an optional additional widget.
 * Selector preference (checkbox or radio button) with an optional additional widget.
@@ -41,6 +47,8 @@ import com.android.settingslib.widget.preference.selector.R;
 * on the right side that can open another page.
 * on the right side that can open another page.
 */
 */
public class SelectorWithWidgetPreference extends CheckBoxPreference {
public class SelectorWithWidgetPreference extends CheckBoxPreference {
    @VisibleForTesting
    static final int DEFAULT_MAX_LINES = 2;


    /**
    /**
     * Interface definition for a callback to be invoked when the preference is clicked.
     * Interface definition for a callback to be invoked when the preference is clicked.
@@ -63,6 +71,8 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
    private boolean mIsCheckBox = false;  // whether to display this button as a checkbox
    private boolean mIsCheckBox = false;  // whether to display this button as a checkbox


    private View.OnClickListener mExtraWidgetOnClickListener;
    private View.OnClickListener mExtraWidgetOnClickListener;
    private int mTitleMaxLines;



    /**
    /**
     * Perform inflation from XML and apply a class-specific base style.
     * Perform inflation from XML and apply a class-specific base style.
@@ -74,9 +84,10 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
     *                 resource that supplies default values for the view. Can be 0 to not
     *                 resource that supplies default values for the view. Can be 0 to not
     *                 look for defaults.
     *                 look for defaults.
     */
     */
    public SelectorWithWidgetPreference(Context context, AttributeSet attrs, int defStyle) {
    public SelectorWithWidgetPreference(@NonNull Context context, @Nullable AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
        super(context, attrs, defStyle);
        init();
        init(context, attrs, defStyle, /* defStyleRes= */ 0);
    }
    }


    /**
    /**
@@ -88,7 +99,7 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
     */
     */
    public SelectorWithWidgetPreference(Context context, AttributeSet attrs) {
    public SelectorWithWidgetPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);
        init();
        init(context, attrs, /* defStyleAttr= */ 0, /* defStyleRes= */ 0);
    }
    }


    /**
    /**
@@ -100,7 +111,7 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
    public SelectorWithWidgetPreference(Context context, boolean isCheckbox) {
    public SelectorWithWidgetPreference(Context context, boolean isCheckbox) {
        super(context, null);
        super(context, null);
        mIsCheckBox = isCheckbox;
        mIsCheckBox = isCheckbox;
        init();
        init(context, /* attrs= */ null, /* defStyleAttr= */ 0, /* defStyleRes= */ 0);
    }
    }


    /**
    /**
@@ -161,6 +172,11 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
        mExtraWidgetContainer = holder.findViewById(R.id.selector_extra_widget_container);
        mExtraWidgetContainer = holder.findViewById(R.id.selector_extra_widget_container);


        setExtraWidgetOnClickListener(mExtraWidgetOnClickListener);
        setExtraWidgetOnClickListener(mExtraWidgetOnClickListener);

        if (Flags.allowSetTitleMaxLines()) {
            TextView title = (TextView) holder.findViewById(android.R.id.title);
            title.setMaxLines(mTitleMaxLines);
        }
    }
    }


    /**
    /**
@@ -200,7 +216,8 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
        return mIsCheckBox;
        return mIsCheckBox;
    }
    }


    private void init() {
    private void init(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        if (mIsCheckBox) {
        if (mIsCheckBox) {
            setWidgetLayoutResource(R.layout.preference_widget_checkbox);
            setWidgetLayoutResource(R.layout.preference_widget_checkbox);
        } else {
        } else {
@@ -208,5 +225,16 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
        }
        }
        setLayoutResource(R.layout.preference_selector_with_widget);
        setLayoutResource(R.layout.preference_selector_with_widget);
        setIconSpaceReserved(false);
        setIconSpaceReserved(false);

        if (Flags.allowSetTitleMaxLines()) {
            final TypedArray a =
                    context.obtainStyledAttributes(
                            attrs, R.styleable.SelectorWithWidgetPreference, defStyleAttr,
                            defStyleRes);
            mTitleMaxLines =
                    a.getInt(R.styleable.SelectorWithWidgetPreference_titleMaxLines,
                            DEFAULT_MAX_LINES);
            a.recycle();
        }
    }
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ android_robolectric_test {
        "flag-junit",
        "flag-junit",
        "settingslib_media_flags_lib",
        "settingslib_media_flags_lib",
        "settingslib_illustrationpreference_flags_lib",
        "settingslib_illustrationpreference_flags_lib",
        "settingslib_selectorwithwidgetpreference_flags_lib",
        "testng", // TODO: remove once JUnit on Android provides assertThrows
        "testng", // TODO: remove once JUnit on Android provides assertThrows
    ],
    ],
    java_resource_dirs: ["config"],
    java_resource_dirs: ["config"],
Loading