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

Commit 791b37e0 authored by Alan Viverette's avatar Alan Viverette
Browse files

Allow recycling of Preferences in com.android.* packages

Refactors hasSpecifiedLayout to canRecycleLayout for readability's
sake. All boolean references to the method have been inverted.

BUG: 10079104
Change-Id: Ie6beda9f0b837f889a6cc6a80377349e98cc4883
parent b6c38e9d
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    
    private int mLayoutResId = com.android.internal.R.layout.preference;
    private int mWidgetLayoutResId;
    private boolean mHasSpecifiedLayout = false;
    private boolean mCanRecycleLayout = true;
    
    private OnPreferenceChangeInternalListener mListener;
    
@@ -274,9 +274,10 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
        }
        a.recycle();

        if (!getClass().getName().startsWith("android.preference")) {
            // For subclasses not in this package, assume the worst and don't cache views
            mHasSpecifiedLayout = true;
        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;
        }
    }
    
@@ -398,7 +399,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    public void setLayoutResource(int layoutResId) {
        if (layoutResId != mLayoutResId) {
            // Layout changed
            mHasSpecifiedLayout = true;
            mCanRecycleLayout = false;
        }

        mLayoutResId = layoutResId;
@@ -414,7 +415,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    }
    
    /**
     * Sets The layout for the controllable widget portion of this Preference. This
     * Sets the layout for the controllable widget portion of this Preference. This
     * is inflated into the main layout. For example, a {@link CheckBoxPreference}
     * would specify a custom layout (consisting of just the CheckBox) here,
     * instead of creating its own main layout.
@@ -426,7 +427,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    public void setWidgetLayoutResource(int widgetLayoutResId) {
        if (widgetLayoutResId != mWidgetLayoutResId) {
            // Layout changed
            mHasSpecifiedLayout = true;
            mCanRecycleLayout = false;
        }
        mWidgetLayoutResId = widgetLayoutResId;
    }
@@ -1641,8 +1642,8 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
        return mPreferenceManager.getSharedPreferences().getBoolean(mKey, defaultReturnValue);
    }
    
    boolean hasSpecifiedLayout() {
        return mHasSpecifiedLayout;
    boolean canRecycleLayout() {
        return mCanRecycleLayout;
    }
    
    @Override
+2 −2
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
            
            preferences.add(preference);
            
            if (!mHasReturnedViewTypeCount && !preference.hasSpecifiedLayout()) {
            if (!mHasReturnedViewTypeCount && preference.canRecycleLayout()) {
                addPreferenceClassName(preference);
            }
            
@@ -255,7 +255,7 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
        }
        
        final Preference preference = this.getItem(position);
        if (preference.hasSpecifiedLayout()) {
        if (!preference.canRecycleLayout()) {
            return IGNORE_ITEM_VIEW_TYPE;
        }