Merge "Disabled state UI of Flash Notifications preview button" into udc-dev

This commit is contained in:
Angela Wang
2023-05-11 01:41:47 +00:00
committed by Android (Google) Code Review
8 changed files with 185 additions and 33 deletions

View File

@@ -17,16 +17,26 @@
package com.android.settings.accessibility;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settingslib.Utils;
/**
* Preference for Flash notifications preview.
*/
public class FlashNotificationsPreviewPreference extends Preference {
private Drawable mBackgroundEnabled;
private Drawable mBackgroundDisabled;
@ColorInt
private int mTextColorDisabled;
public FlashNotificationsPreviewPreference(Context context) {
super(context);
@@ -52,5 +62,32 @@ public class FlashNotificationsPreviewPreference extends Preference {
private void init() {
setLayoutResource(R.layout.flash_notification_preview_preference);
mBackgroundEnabled = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_on);
mBackgroundDisabled = getContext().getDrawable(R.drawable.switch_bar_bg_disabled);
mTextColorDisabled = Utils.getColorAttrDefaultColor(getContext(),
android.R.attr.textColorPrimary);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final boolean enabled = isEnabled();
final View frame = holder.findViewById(R.id.frame);
if (frame != null) {
frame.setBackground(enabled ? mBackgroundEnabled : mBackgroundDisabled);
}
final TextView title = (TextView) holder.findViewById(android.R.id.title);
if (title != null) {
@ColorInt final int textColorEnabled = title.getCurrentTextColor();
title.setAlpha(enabled ? 1f : 0.38f);
title.setTextColor(enabled ? textColorEnabled : mTextColorDisabled);
}
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
notifyChanged();
}
}

View File

@@ -55,7 +55,7 @@ public class FlashNotificationsPreviewPreferenceController extends
new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
onSettingChanged();
updateState(mPreference);
}
};
@@ -73,7 +73,7 @@ public class FlashNotificationsPreviewPreferenceController extends
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
onSettingChanged();
updateState(mPreference);
}
@Override
@@ -103,10 +103,13 @@ public class FlashNotificationsPreviewPreferenceController extends
}
}
private void onSettingChanged() {
if (mPreference == null) return;
mPreference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (preference == null) {
return;
}
preference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
!= FlashNotificationsUtil.State.OFF);
}
}