Fix disable/force stop app button incorrect state.

The LayoutPreference calls super.onBindPreview, which enables all
children views. This is usually fine because a Preference object has
just one click target. But the LayoutPreference can hold multiple click
targets so we should not force enable everything during every single
bind.

To fix this, we don't call super.onBind, and manually wire up
onClickListener and selectable/focusable state. Everything else from
super.onBind is useless to this preference type.

Change-Id: Ibb89f1be399311b9ee053733a050f04be6aa85e8
Fix: 37452204
Fix: 37538936
Fix: 35633637
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-04-20 15:10:46 -07:00
parent dcc0af50c6
commit b61f945e8e
2 changed files with 104 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.applications;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
@@ -31,7 +32,10 @@ import com.android.settings.Utils;
public class LayoutPreference extends Preference {
private View mRootView;
private final View.OnClickListener mClickListener = v -> performClick(v);
@VisibleForTesting
View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -59,7 +63,7 @@ public class LayoutPreference extends Preference {
private void setView(View view) {
setLayoutResource(R.layout.layout_preference_frame);
final ViewGroup allDetails = (ViewGroup) view.findViewById(R.id.all_details);
final ViewGroup allDetails = view.findViewById(R.id.all_details);
if (allDetails != null) {
Utils.forceCustomPadding(allDetails, true /* additive padding */);
}
@@ -68,9 +72,14 @@ public class LayoutPreference extends Preference {
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
FrameLayout layout = (FrameLayout) view.itemView;
public void onBindViewHolder(PreferenceViewHolder holder) {
holder.itemView.setOnClickListener(mClickListener);
final boolean selectable = isSelectable();
holder.itemView.setFocusable(selectable);
holder.itemView.setClickable(selectable);
FrameLayout layout = (FrameLayout) holder.itemView;
layout.removeAllViews();
ViewGroup parent = (ViewGroup) mRootView.getParent();
if (parent != null) {