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

Commit b3d2e110 authored by Filip Pavlis's avatar Filip Pavlis Committed by Android (Google) Code Review
Browse files

Merge "Enable recycling of third party preference widgets"

parents 22892f45 4186b344
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -1052,6 +1052,7 @@ package android {
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recycleEnabled = 16844124; // 0x101055c
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
@@ -31916,6 +31917,7 @@ package android.preference {
    method public boolean hasKey();
    method public boolean hasKey();
    method public boolean isEnabled();
    method public boolean isEnabled();
    method public boolean isPersistent();
    method public boolean isPersistent();
    method public boolean isRecycleEnabled();
    method public boolean isSelectable();
    method public boolean isSelectable();
    method protected void notifyChanged();
    method protected void notifyChanged();
    method public void notifyDependencyChange(boolean);
    method public void notifyDependencyChange(boolean);
@@ -31955,6 +31957,7 @@ package android.preference {
    method public void setOrder(int);
    method public void setOrder(int);
    method public void setPersistent(boolean);
    method public void setPersistent(boolean);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setRecycleEnabled(boolean);
    method public void setSelectable(boolean);
    method public void setSelectable(boolean);
    method public void setShouldDisableView(boolean);
    method public void setShouldDisableView(boolean);
    method public void setSummary(java.lang.CharSequence);
    method public void setSummary(java.lang.CharSequence);
+3 −0
Original line number Original line Diff line number Diff line
@@ -1165,6 +1165,7 @@ package android {
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recycleEnabled = 16844124; // 0x101055c
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
@@ -34764,6 +34765,7 @@ package android.preference {
    method public boolean hasKey();
    method public boolean hasKey();
    method public boolean isEnabled();
    method public boolean isEnabled();
    method public boolean isPersistent();
    method public boolean isPersistent();
    method public boolean isRecycleEnabled();
    method public boolean isSelectable();
    method public boolean isSelectable();
    method protected void notifyChanged();
    method protected void notifyChanged();
    method public void notifyDependencyChange(boolean);
    method public void notifyDependencyChange(boolean);
@@ -34803,6 +34805,7 @@ package android.preference {
    method public void setOrder(int);
    method public void setOrder(int);
    method public void setPersistent(boolean);
    method public void setPersistent(boolean);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setRecycleEnabled(boolean);
    method public void setSelectable(boolean);
    method public void setSelectable(boolean);
    method public void setShouldDisableView(boolean);
    method public void setShouldDisableView(boolean);
    method public void setSummary(java.lang.CharSequence);
    method public void setSummary(java.lang.CharSequence);
+3 −0
Original line number Original line Diff line number Diff line
@@ -1052,6 +1052,7 @@ package android {
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int ratingBarStyleSmall = 16842877; // 0x101007d
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int readPermission = 16842759; // 0x1010007
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recognitionService = 16843932; // 0x101049c
    field public static final int recycleEnabled = 16844124; // 0x101055c
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int relinquishTaskIdentity = 16843894; // 0x1010476
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparent = 16843964; // 0x10104bc
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
    field public static final int reparentWithOverlay = 16843965; // 0x10104bd
@@ -32040,6 +32041,7 @@ package android.preference {
    method public boolean hasKey();
    method public boolean hasKey();
    method public boolean isEnabled();
    method public boolean isEnabled();
    method public boolean isPersistent();
    method public boolean isPersistent();
    method public boolean isRecycleEnabled();
    method public boolean isSelectable();
    method public boolean isSelectable();
    method protected void notifyChanged();
    method protected void notifyChanged();
    method public void notifyDependencyChange(boolean);
    method public void notifyDependencyChange(boolean);
@@ -32079,6 +32081,7 @@ package android.preference {
    method public void setOrder(int);
    method public void setOrder(int);
    method public void setPersistent(boolean);
    method public void setPersistent(boolean);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setPreferenceDataStore(android.preference.PreferenceDataStore);
    method public void setRecycleEnabled(boolean);
    method public void setSelectable(boolean);
    method public void setSelectable(boolean);
    method public void setShouldDisableView(boolean);
    method public void setShouldDisableView(boolean);
    method public void setSummary(java.lang.CharSequence);
    method public void setSummary(java.lang.CharSequence);
+80 −62
Original line number Original line Diff line number Diff line
@@ -81,6 +81,7 @@ import java.util.Set;
 * @attr ref android.R.styleable#Preference_persistent
 * @attr ref android.R.styleable#Preference_persistent
 * @attr ref android.R.styleable#Preference_defaultValue
 * @attr ref android.R.styleable#Preference_defaultValue
 * @attr ref android.R.styleable#Preference_shouldDisableView
 * @attr ref android.R.styleable#Preference_shouldDisableView
 * @attr ref android.R.styleable#Preference_recycleEnabled
 */
 */
public class Preference implements Comparable<Preference> {
public class Preference implements Comparable<Preference> {
    /**
    /**
@@ -131,6 +132,7 @@ public class Preference implements Comparable<Preference> {
    private Object mDefaultValue;
    private Object mDefaultValue;
    private boolean mDependencyMet = true;
    private boolean mDependencyMet = true;
    private boolean mParentDependencyMet = true;
    private boolean mParentDependencyMet = true;
    private boolean mRecycleEnabled = true;


    /**
    /**
     * @see #setShouldDisableView(boolean)
     * @see #setShouldDisableView(boolean)
@@ -139,7 +141,6 @@ public class Preference implements Comparable<Preference> {


    private int mLayoutResId = com.android.internal.R.layout.preference;
    private int mLayoutResId = com.android.internal.R.layout.preference;
    private int mWidgetLayoutResId;
    private int mWidgetLayoutResId;
    private boolean mCanRecycleLayout = true;


    private OnPreferenceChangeInternalListener mListener;
    private OnPreferenceChangeInternalListener mListener;


@@ -291,15 +292,13 @@ public class Preference implements Comparable<Preference> {
                case com.android.internal.R.styleable.Preference_shouldDisableView:
                case com.android.internal.R.styleable.Preference_shouldDisableView:
                    mShouldDisableView = a.getBoolean(attr, mShouldDisableView);
                    mShouldDisableView = a.getBoolean(attr, mShouldDisableView);
                    break;
                    break;

                case com.android.internal.R.styleable.Preference_recycleEnabled:
                    mRecycleEnabled = a.getBoolean(attr, mRecycleEnabled);
                    break;
            }
            }
        }
        }
        a.recycle();
        a.recycle();

        if (!getClass().getName().startsWith("android.preference")
                && !getClass().getName().startsWith("com.android")) {
            // For non-framework subclasses, assume the worst and don't cache views.
            mCanRecycleLayout = false;
        }
    }
    }


    /**
    /**
@@ -482,7 +481,7 @@ public class Preference implements Comparable<Preference> {
    public void setLayoutResource(@LayoutRes int layoutResId) {
    public void setLayoutResource(@LayoutRes int layoutResId) {
        if (layoutResId != mLayoutResId) {
        if (layoutResId != mLayoutResId) {
            // Layout changed
            // Layout changed
            mCanRecycleLayout = false;
            mRecycleEnabled = false;
        }
        }


        mLayoutResId = layoutResId;
        mLayoutResId = layoutResId;
@@ -511,7 +510,7 @@ public class Preference implements Comparable<Preference> {
    public void setWidgetLayoutResource(@LayoutRes int widgetLayoutResId) {
    public void setWidgetLayoutResource(@LayoutRes int widgetLayoutResId) {
        if (widgetLayoutResId != mWidgetLayoutResId) {
        if (widgetLayoutResId != mWidgetLayoutResId) {
            // Layout changed
            // Layout changed
            mCanRecycleLayout = false;
            mRecycleEnabled = false;
        }
        }
        mWidgetLayoutResId = widgetLayoutResId;
        mWidgetLayoutResId = widgetLayoutResId;
    }
    }
@@ -653,15 +652,13 @@ public class Preference implements Comparable<Preference> {
    }
    }


    /**
    /**
     * Sets the order of this Preference with respect to other
     * Sets the order of this Preference with respect to other Preference objects on the same level.
     * Preference objects on the same level. If this is not specified, the
     * If this is not specified, the default behavior is to sort alphabetically. The
     * default behavior is to sort alphabetically. The
     * {@link PreferenceGroup#setOrderingAsAdded(boolean)} can be used to order Preference objects
     * {@link PreferenceGroup#setOrderingAsAdded(boolean)} can be used to order
     * based on the order they appear in the XML.
     * Preference objects based on the order they appear in the XML.
     *
     *
     * @param order The order for this Preference. A lower value will be shown
     * @param order the order for this Preference. A lower value will be shown first. Use
     *            first. Use {@link #DEFAULT_ORDER} to sort alphabetically or
     *              {@link #DEFAULT_ORDER} to sort alphabetically or allow ordering from XML
     *            allow ordering from XML.
     * @see PreferenceGroup#setOrderingAsAdded(boolean)
     * @see PreferenceGroup#setOrderingAsAdded(boolean)
     * @see #DEFAULT_ORDER
     * @see #DEFAULT_ORDER
     */
     */
@@ -675,10 +672,9 @@ public class Preference implements Comparable<Preference> {
    }
    }


    /**
    /**
     * Gets the order of this Preference with respect to other Preference objects
     * Gets the order of this Preference with respect to other Preference objects on the same level.
     * on the same level.
     *
     *
     * @return The order of this Preference.
     * @return the order of this Preference
     * @see #setOrder(int)
     * @see #setOrder(int)
     */
     */
    public int getOrder() {
    public int getOrder() {
@@ -686,12 +682,10 @@ public class Preference implements Comparable<Preference> {
    }
    }


    /**
    /**
     * Sets the title for this Preference with a CharSequence. 
     * Sets the title for this Preference with a CharSequence. This title will be placed into the ID
     * This title will be placed into the ID
     * {@link android.R.id#title} within the View created by {@link #onCreateView(ViewGroup)}.
     * {@link android.R.id#title} within the View created by
     * {@link #onCreateView(ViewGroup)}.
     *
     *
     * @param title The title for this Preference.
     * @param title the title for this Preference
     */
     */
    public void setTitle(CharSequence title) {
    public void setTitle(CharSequence title) {
        if (title == null && mTitle != null || title != null && !title.equals(mTitle)) {
        if (title == null && mTitle != null || title != null && !title.equals(mTitle)) {
@@ -705,7 +699,7 @@ public class Preference implements Comparable<Preference> {
     * Sets the title for this Preference with a resource ID.
     * Sets the title for this Preference with a resource ID.
     *
     *
     * @see #setTitle(CharSequence)
     * @see #setTitle(CharSequence)
     * @param titleResId The title as a resource ID.
     * @param titleResId the title as a resource ID
     */
     */
    public void setTitle(@StringRes int titleResId) {
    public void setTitle(@StringRes int titleResId) {
        setTitle(mContext.getString(titleResId));
        setTitle(mContext.getString(titleResId));
@@ -713,10 +707,10 @@ public class Preference implements Comparable<Preference> {
    }
    }


    /**
    /**
     * Returns the title resource ID of this Preference.  If the title did
     * Returns the title resource ID of this Preference. If the title did not come from a resource,
     * not come from a resource, 0 is returned.
     * {@code 0} is returned.
     *
     *
     * @return The title resource.
     * @return the title resource
     * @see #setTitle(int)
     * @see #setTitle(int)
     */
     */
    @StringRes
    @StringRes
@@ -727,7 +721,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Returns the title of this Preference.
     * Returns the title of this Preference.
     *
     *
     * @return The title.
     * @return the title
     * @see #setTitle(CharSequence)
     * @see #setTitle(CharSequence)
     */
     */
    public CharSequence getTitle() {
    public CharSequence getTitle() {
@@ -735,12 +729,10 @@ public class Preference implements Comparable<Preference> {
    }
    }


    /**
    /**
     * Sets the icon for this Preference with a Drawable. 
     * Sets the icon for this Preference with a Drawable. This icon will be placed into the ID
     * This icon will be placed into the ID
     * {@link android.R.id#icon} within the View created by {@link #onCreateView(ViewGroup)}.
     * {@link android.R.id#icon} within the View created by
     * {@link #onCreateView(ViewGroup)}.
     *
     *
     * @param icon The optional icon for this Preference.
     * @param icon the optional icon for this Preference
     */
     */
    public void setIcon(Drawable icon) {
    public void setIcon(Drawable icon) {
        if ((icon == null && mIcon != null) || (icon != null && mIcon != icon)) {
        if ((icon == null && mIcon != null) || (icon != null && mIcon != icon)) {
@@ -754,7 +746,7 @@ public class Preference implements Comparable<Preference> {
     * Sets the icon for this Preference with a resource ID.
     * Sets the icon for this Preference with a resource ID.
     *
     *
     * @see #setIcon(Drawable)
     * @see #setIcon(Drawable)
     * @param iconResId The icon as a resource ID.
     * @param iconResId the icon as a resource ID
     */
     */
    public void setIcon(@DrawableRes int iconResId) {
    public void setIcon(@DrawableRes int iconResId) {
        if (mIconResId != iconResId) {
        if (mIconResId != iconResId) {
@@ -766,7 +758,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Returns the icon of this Preference.
     * Returns the icon of this Preference.
     *
     *
     * @return The icon.
     * @return the icon
     * @see #setIcon(Drawable)
     * @see #setIcon(Drawable)
     */
     */
    public Drawable getIcon() {
    public Drawable getIcon() {
@@ -779,7 +771,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Returns the summary of this Preference.
     * Returns the summary of this Preference.
     *
     *
     * @return The summary.
     * @return the summary
     * @see #setSummary(CharSequence)
     * @see #setSummary(CharSequence)
     */
     */
    public CharSequence getSummary() {
    public CharSequence getSummary() {
@@ -789,7 +781,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Sets the summary for this Preference with a CharSequence.
     * Sets the summary for this Preference with a CharSequence.
     *
     *
     * @param summary The summary for the preference.
     * @param summary the summary for the preference
     */
     */
    public void setSummary(CharSequence summary) {
    public void setSummary(CharSequence summary) {
        if (summary == null && mSummary != null || summary != null && !summary.equals(mSummary)) {
        if (summary == null && mSummary != null || summary != null && !summary.equals(mSummary)) {
@@ -802,7 +794,7 @@ public class Preference implements Comparable<Preference> {
     * Sets the summary for this Preference with a resource ID.
     * Sets the summary for this Preference with a resource ID.
     *
     *
     * @see #setSummary(CharSequence)
     * @see #setSummary(CharSequence)
     * @param summaryResId The summary as a resource.
     * @param summaryResId the summary as a resource
     */
     */
    public void setSummary(@StringRes int summaryResId) {
    public void setSummary(@StringRes int summaryResId) {
        setSummary(mContext.getString(summaryResId));
        setSummary(mContext.getString(summaryResId));
@@ -812,7 +804,7 @@ public class Preference implements Comparable<Preference> {
     * Sets whether this Preference is enabled. If disabled, it will
     * Sets whether this Preference is enabled. If disabled, it will
     * not handle clicks.
     * not handle clicks.
     *
     *
     * @param enabled Set true to enable it.
     * @param enabled set {@code true} to enable it
     */
     */
    public void setEnabled(boolean enabled) {
    public void setEnabled(boolean enabled) {
        if (mEnabled != enabled) {
        if (mEnabled != enabled) {
@@ -828,7 +820,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Checks whether this Preference should be enabled in the list.
     * Checks whether this Preference should be enabled in the list.
     *
     *
     * @return True if this Preference is enabled, false otherwise.
     * @return {@code true} if this Preference is enabled, false otherwise
     */
     */
    public boolean isEnabled() {
    public boolean isEnabled() {
        return mEnabled && mDependencyMet && mParentDependencyMet;
        return mEnabled && mDependencyMet && mParentDependencyMet;
@@ -837,7 +829,7 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Sets whether this Preference is selectable.
     * Sets whether this Preference is selectable.
     *
     *
     * @param selectable Set true to make it selectable.
     * @param selectable set {@code true} to make it selectable
     */
     */
    public void setSelectable(boolean selectable) {
    public void setSelectable(boolean selectable) {
        if (mSelectable != selectable) {
        if (mSelectable != selectable) {
@@ -849,22 +841,21 @@ public class Preference implements Comparable<Preference> {
    /**
    /**
     * Checks whether this Preference should be selectable in the list.
     * Checks whether this Preference should be selectable in the list.
     *
     *
     * @return True if it is selectable, false otherwise.
     * @return {@code true} if it is selectable, {@code false} otherwise
     */
     */
    public boolean isSelectable() {
    public boolean isSelectable() {
        return mSelectable;
        return mSelectable;
    }
    }


    /**
    /**
     * Sets whether this Preference should disable its view when it gets
     * Sets whether this Preference should disable its view when it gets disabled.
     * disabled.
     * <p>
     * For example, set this and {@link #setEnabled(boolean)} to false for
     * preferences that are only displaying information and 1) should not be
     * clickable 2) should not have the view set to the disabled state.
     *
     *
     * @param shouldDisableView Set true if this preference should disable its view
     * <p>For example, set this and {@link #setEnabled(boolean)} to false for preferences that are
     *            when the preference is disabled.
     * only displaying information and 1) should not be clickable 2) should not have the view set to
     * the disabled state.
     *
     * @param shouldDisableView set {@code true} if this preference should disable its view when
     *                          the preference is disabled
     */
     */
    public void setShouldDisableView(boolean shouldDisableView) {
    public void setShouldDisableView(boolean shouldDisableView) {
        mShouldDisableView = shouldDisableView;
        mShouldDisableView = shouldDisableView;
@@ -873,13 +864,44 @@ public class Preference implements Comparable<Preference> {


    /**
    /**
     * Checks whether this Preference should disable its view when it's action is disabled.
     * Checks whether this Preference should disable its view when it's action is disabled.
     *
     * @see #setShouldDisableView(boolean)
     * @see #setShouldDisableView(boolean)
     * @return True if it should disable the view. 
     * @return {@code true} if it should disable the view
     */
     */
    public boolean getShouldDisableView() {
    public boolean getShouldDisableView() {
        return mShouldDisableView;
        return mShouldDisableView;
    }
    }


    /**
     * Sets whether this Preference has enabled to have its view recycled when used in the list
     * view. By default the recycling is enabled.
     *
     * <p>The value can be changed only before this preference is added to the preference hierarchy.
     *
     * <p>If view recycling is not allowed then each time the list view populates this preference
     * the {@link #getView(View, ViewGroup)} method receives a {@code null} convert view and needs
     * to recreate the view. Otherwise view gets recycled and only {@link #onBindView(View)} gets
     * called.
     *
     * @param enabled set {@code true} if this preference view should be recycled
     */
    @CallSuper
    public void setRecycleEnabled(boolean enabled) {
        mRecycleEnabled = enabled;
        notifyChanged();
    }

    /**
     * Checks whether this Preference has enabled to have its view recycled when used in the list
     * view.
     *
     * @see #setRecycleEnabled(boolean)
     * @return {@code true} if this preference view should be recycled
     */
    public boolean isRecycleEnabled() {
        return mRecycleEnabled;
    }

    /**
    /**
     * Returns a unique ID for this Preference.  This ID should be unique across all
     * Returns a unique ID for this Preference.  This ID should be unique across all
     * Preference objects in a hierarchy.
     * Preference objects in a hierarchy.
@@ -1831,10 +1853,6 @@ public class Preference implements Comparable<Preference> {
        return mPreferenceManager.getSharedPreferences().getBoolean(mKey, defaultReturnValue);
        return mPreferenceManager.getSharedPreferences().getBoolean(mKey, defaultReturnValue);
    }
    }


    boolean canRecycleLayout() {
        return mCanRecycleLayout;
    }

    @Override
    @Override
    public String toString() {
    public String toString() {
        return getFilterableStringBuilder().toString();
        return getFilterableStringBuilder().toString();
+2 −2
Original line number Original line Diff line number Diff line
@@ -164,7 +164,7 @@ public class PreferenceGroupAdapter extends BaseAdapter
            
            
            preferences.add(preference);
            preferences.add(preference);
            
            
            if (!mHasReturnedViewTypeCount && preference.canRecycleLayout()) {
            if (!mHasReturnedViewTypeCount && preference.isRecycleEnabled()) {
                addPreferenceClassName(preference);
                addPreferenceClassName(preference);
            }
            }
            
            
@@ -296,7 +296,7 @@ public class PreferenceGroupAdapter extends BaseAdapter
        }
        }
        
        
        final Preference preference = this.getItem(position);
        final Preference preference = this.getItem(position);
        if (!preference.canRecycleLayout()) {
        if (!preference.isRecycleEnabled()) {
            return IGNORE_ITEM_VIEW_TYPE;
            return IGNORE_ITEM_VIEW_TYPE;
        }
        }


Loading