Making the whole preference entry a single tap target when notification access

is not available

Bug: 64232287
Change-Id: I93dadfb88ee5d008dee7582c5f37ea3d354330cd
This commit is contained in:
Sunny Goyal 2017-08-01 11:04:15 -07:00
parent ec99420fe7
commit b65e13ca83
3 changed files with 11 additions and 16 deletions

View File

@ -17,8 +17,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackgroundBorderless" android:importantForAccessibility="no"
android:contentDescription="@string/title_missing_notification_access"
android:scaleType="center" android:scaleType="center"
android:src="@drawable/ic_warning" android:src="@drawable/ic_warning"
android:tint="?android:attr/textColorSecondary" /> android:tint="?android:attr/textColorSecondary" />

View File

@ -34,7 +34,6 @@ import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.System; import android.provider.Settings.System;
import android.view.View;
import com.android.launcher3.graphics.IconShapeOverride; import com.android.launcher3.graphics.IconShapeOverride;
import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.notification.NotificationListener;
@ -172,7 +171,7 @@ public class SettingsActivity extends Activity {
* and updates the launcher badging setting subtext accordingly. * and updates the launcher badging setting subtext accordingly.
*/ */
private static class IconBadgingObserver extends ContentObserver private static class IconBadgingObserver extends ContentObserver
implements View.OnClickListener { implements Preference.OnPreferenceClickListener {
private final ButtonPreference mBadgingPref; private final ButtonPreference mBadgingPref;
private final ContentResolver mResolver; private final ContentResolver mResolver;
@ -205,14 +204,16 @@ public class SettingsActivity extends Activity {
summary = R.string.title_missing_notification_access; summary = R.string.title_missing_notification_access;
} }
} }
mBadgingPref.setButtonOnClickListener(serviceEnabled ? null : this); mBadgingPref.setWidgetFrameVisible(!serviceEnabled);
mBadgingPref.setOnPreferenceClickListener(serviceEnabled ? null : this);
mBadgingPref.setSummary(summary); mBadgingPref.setSummary(summary);
} }
@Override @Override
public void onClick(View view) { public boolean onPreferenceClick(Preference preference) {
new NotificationAccessConfirmation().show(mFragmentManager, "notification_access"); new NotificationAccessConfirmation().show(mFragmentManager, "notification_access");
return true;
} }
} }

View File

@ -28,7 +28,7 @@ import android.view.ViewGroup;
*/ */
public class ButtonPreference extends Preference { public class ButtonPreference extends Preference {
private View.OnClickListener mClickListener; private boolean mWidgetFrameVisible = false;
public ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
@ -46,9 +46,9 @@ public class ButtonPreference extends Preference {
super(context); super(context);
} }
public void setButtonOnClickListener(View.OnClickListener clickListener) { public void setWidgetFrameVisible(boolean isVisible) {
if (mClickListener != clickListener) { if (mWidgetFrameVisible != isVisible) {
mClickListener = clickListener; mWidgetFrameVisible = isVisible;
notifyChanged(); notifyChanged();
} }
} }
@ -59,12 +59,7 @@ public class ButtonPreference extends Preference {
ViewGroup widgetFrame = view.findViewById(android.R.id.widget_frame); ViewGroup widgetFrame = view.findViewById(android.R.id.widget_frame);
if (widgetFrame != null) { if (widgetFrame != null) {
View button = widgetFrame.getChildAt(0); widgetFrame.setVisibility(mWidgetFrameVisible ? View.VISIBLE : View.GONE);
if (button != null) {
button.setOnClickListener(mClickListener);
}
widgetFrame.setVisibility(
(mClickListener == null || button == null) ? View.GONE : View.VISIBLE);
} }
} }
} }