Files
app_Settings/src/com/android/settings/notification/ImportancePreference.java
Julia Reynolds 090e67d938 Importance preference updates
- Use show on lockscreen setting
- Match design to notification shade guts

Test: robotests
Bug: 131290247
Bug: 128445911
Change-Id: I645b35191c8f22e751c264fd8ca13560f50b7582
2019-05-01 10:14:05 -04:00

172 lines
6.2 KiB
Java

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.transition.AutoTransition;
import android.transition.TransitionManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.android.settingslib.R;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
public class ImportancePreference extends Preference {
private boolean mIsConfigurable = true;
private int mImportance;
private boolean mDisplayInStatusBar;
private boolean mDisplayOnLockscreen;
private View mSilenceButton;
private View mAlertButton;
private Context mContext;
Drawable selectedBackground;
Drawable unselectedBackground;
private static final int BUTTON_ANIM_TIME_MS = 100;
public ImportancePreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
public ImportancePreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public ImportancePreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ImportancePreference(Context context) {
super(context);
init(context);
}
private void init(Context context) {
mContext = context;
selectedBackground = mContext.getDrawable(R.drawable.button_border_selected);
unselectedBackground = mContext.getDrawable(R.drawable.button_border_unselected);
setLayoutResource(R.layout.notif_importance_preference);
}
public void setImportance(int importance) {
mImportance = importance;
}
public void setConfigurable(boolean configurable) {
mIsConfigurable = configurable;
}
public void setDisplayInStatusBar(boolean display) {
mDisplayInStatusBar = display;
}
public void setDisplayOnLockscreen(boolean display) {
mDisplayOnLockscreen = display;
}
@Override
public void onBindViewHolder(final PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.itemView.setClickable(false);
mSilenceButton = holder.findViewById(R.id.silence);
mAlertButton = holder.findViewById(R.id.alert);
if (!mIsConfigurable) {
mSilenceButton.setEnabled(false);
mAlertButton.setEnabled(false);
}
switch (mImportance) {
case IMPORTANCE_MIN:
case IMPORTANCE_LOW:
mAlertButton.setBackground(unselectedBackground);
mSilenceButton.setBackground(selectedBackground);
break;
case IMPORTANCE_HIGH:
default:
mSilenceButton.setBackground(unselectedBackground);
mAlertButton.setBackground(selectedBackground);
break;
}
setImportanceSummary((ViewGroup) holder.itemView, mImportance, false);
mSilenceButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_LOW);
mAlertButton.setBackground(unselectedBackground);
mAlertButton.setSelected(false);
mSilenceButton.setBackground(selectedBackground);
mSilenceButton.setSelected(true);
setImportanceSummary((ViewGroup) holder.itemView, IMPORTANCE_LOW, true);
});
mAlertButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_DEFAULT);
mSilenceButton.setBackground(unselectedBackground);
mSilenceButton.setSelected(false);
mAlertButton.setBackground(selectedBackground);
mAlertButton.setSelected(true);
setImportanceSummary((ViewGroup) holder.itemView, IMPORTANCE_DEFAULT, true);
});
}
void setImportanceSummary(ViewGroup parent, int importance, boolean fromUser) {
if (fromUser) {
AutoTransition transition = new AutoTransition();
transition.setDuration(BUTTON_ANIM_TIME_MS);
TransitionManager.beginDelayedTransition(parent, transition);
}
if (importance >= IMPORTANCE_DEFAULT) {
parent.findViewById(R.id.silence_summary).setVisibility(GONE);
TextView view = parent.findViewById(R.id.alert_summary);
view.setText(R.string.notification_channel_summary_default);
view.setVisibility(VISIBLE);
} else {
parent.findViewById(R.id.alert_summary).setVisibility(GONE);
TextView view = parent.findViewById(R.id.silence_summary);
view.setVisibility(VISIBLE);
if (mDisplayInStatusBar) {
if (mDisplayOnLockscreen) {
view.setText(R.string.notification_channel_summary_low_status_lock);
} else {
view.setText(R.string.notification_channel_summary_low_status);
}
} else if (mDisplayOnLockscreen) {
view.setText(R.string.notification_channel_summary_low_lock);
} else {
view.setText(R.string.notification_channel_summary_low);
}
}
}
}