Zen mode settings update.
- Fix master switch placement, hide search option. - New text-based design for bucket configs. - Automatically turn on = Never - Still read-only. Bug:13670014 Change-Id: I33e7614515cc4ce1ca957d922b844d4865e35c9a
This commit is contained in:
@@ -58,7 +58,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
= new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_NOTIFICATION_PREFERENCES);
|
= new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_NOTIFICATION_PREFERENCES);
|
||||||
|
|
||||||
private static final String KEY_NOTIFICATION_SOUND = "notification_sound";
|
private static final String KEY_NOTIFICATION_SOUND = "notification_sound";
|
||||||
private static final String KEY_ZEN_MODE = "zen_mode";
|
|
||||||
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
|
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
|
||||||
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "toggle_lock_screen_notifications";
|
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "toggle_lock_screen_notifications";
|
||||||
private static final String KEY_HEADS_UP = "heads_up";
|
private static final String KEY_HEADS_UP = "heads_up";
|
||||||
|
@@ -20,9 +20,6 @@ import android.app.ActionBar;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -34,21 +31,18 @@ import android.util.Log;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class ZenModeSettings extends SettingsPreferenceFragment {
|
public class ZenModeSettings extends SettingsPreferenceFragment {
|
||||||
private static final String TAG = "ZenModeSettings";
|
private static final String TAG = "ZenModeSettings";
|
||||||
@@ -59,24 +53,24 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
private ZenModeConfigView mConfig;
|
private ZenModeConfigView mConfig;
|
||||||
private Switch mSwitch;
|
private Switch mSwitch;
|
||||||
|
private Activity mActivity;
|
||||||
|
private MenuItem mSearch;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
final Activity activity = getActivity();
|
mActivity = getActivity();
|
||||||
mSwitch = new Switch(activity);
|
mSwitch = new Switch(mActivity);
|
||||||
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
|
||||||
ActionBar.DISPLAY_SHOW_CUSTOM);
|
mSwitch.setPadding(0, 0, p, 0);
|
||||||
activity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(
|
setHasOptionsMenu(true);
|
||||||
ActionBar.LayoutParams.WRAP_CONTENT,
|
|
||||||
ActionBar.LayoutParams.WRAP_CONTENT,
|
|
||||||
Gravity.CENTER_VERTICAL | Gravity.END));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onPause();
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
mSettingsObserver.unregister();
|
mSearch = menu.findItem(R.id.search);
|
||||||
|
if (mSearch != null) mSearch.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,6 +78,21 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
updateState();
|
updateState();
|
||||||
mSettingsObserver.register();
|
mSettingsObserver.register();
|
||||||
|
mActivity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||||
|
ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
mActivity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.CENTER_VERTICAL | Gravity.END));
|
||||||
|
if (mSearch != null) mSearch.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
mSettingsObserver.unregister();
|
||||||
|
mActivity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
if (mSearch != null) mSearch.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class SettingsObserver extends ContentObserver {
|
private final class SettingsObserver extends ContentObserver {
|
||||||
@@ -156,7 +165,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
private Drawable mOldBackground;
|
private Drawable mOldBackground;
|
||||||
private Toast mToast;
|
|
||||||
|
|
||||||
public ZenModeConfigView(Context context) {
|
public ZenModeConfigView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -200,138 +208,55 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addTriggers() {
|
private void addTriggers() {
|
||||||
addView(new TriggerView("While driving"));
|
addView(new TriggerView("Never"));
|
||||||
addView(new TriggerView("While in meetings"));
|
|
||||||
addView(new TriggerView("During a set time period"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBuckets() {
|
private void addBuckets() {
|
||||||
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
|
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
LayoutParams.WRAP_CONTENT);
|
LayoutParams.WRAP_CONTENT);
|
||||||
BucketView callView = new BucketView(android.R.drawable.ic_menu_call, "Phone Calls", 0,
|
BucketView callView = new BucketView("Phone calls", 0,
|
||||||
"Block all", "Block all except...");
|
"Block all", "Block all except...", "Allow all");
|
||||||
addView(callView, lp);
|
addView(callView, lp);
|
||||||
lp.topMargin = 4;
|
lp.topMargin = 4;
|
||||||
BucketView msgView = new BucketView(android.R.drawable.ic_menu_myplaces,
|
BucketView msgView = new BucketView("Texts, SMS, & other calls", 0,
|
||||||
"Texts, SMS, & Other Calls", 0,
|
"Block all", "Block all except...", "Allow all");
|
||||||
"Block all", "Block all except...");
|
|
||||||
addView(msgView, lp);
|
addView(msgView, lp);
|
||||||
BucketView alarmView = new BucketView(android.R.drawable.ic_menu_agenda,
|
BucketView alarmView = new BucketView("Alarms & timers", 2,
|
||||||
"Alarms & Timers", 1,
|
"Block all", "Block all except...", "Allow all");
|
||||||
"Block all", "Allow all");
|
|
||||||
addView(alarmView, lp);
|
addView(alarmView, lp);
|
||||||
BucketView otherView = new BucketView(android.R.drawable.ic_menu_info_details,
|
BucketView otherView = new BucketView("Other interruptions", 0,
|
||||||
"Other Interruptions", 0,
|
"Block all", "Block all except...", "Allow all");
|
||||||
"Block all", "Block all except...");
|
|
||||||
addView(otherView, lp);
|
addView(otherView, lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notImplemented() {
|
|
||||||
if (mToast != null) mToast.cancel();
|
|
||||||
mToast = Toast.makeText(mContext, "Not implemented", Toast.LENGTH_SHORT);
|
|
||||||
mToast.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BucketView extends RelativeLayout {
|
private class BucketView extends RelativeLayout {
|
||||||
private final BucketSpinner mSpinner;
|
public BucketView(String category, int defaultValue, String... values) {
|
||||||
|
|
||||||
public BucketView(int icon, String category, int defaultValue, String... values) {
|
|
||||||
super(ZenModeConfigView.this.mContext);
|
super(ZenModeConfigView.this.mContext);
|
||||||
|
|
||||||
setBackgroundColor(0xffffffff);
|
setBackgroundColor(0xffffffff);
|
||||||
final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
|
final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
|
||||||
|
final int lm = p * 3 / 4;
|
||||||
final ImageView iv = new ImageView(mContext);
|
TextView title = new TextView(mContext);
|
||||||
iv.setId(android.R.id.icon);
|
title.setId(android.R.id.title);
|
||||||
iv.setImageResource(icon);
|
title.setTextColor(0xff000000);
|
||||||
iv.setAlpha(.5f);
|
title.setTypeface(LIGHT);
|
||||||
|
title.setText(category);
|
||||||
final int size = mContext.getResources()
|
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, title.getTextSize() * 1.5f);
|
||||||
.getDimensionPixelSize(R.dimen.app_icon_size);
|
LayoutParams lp =
|
||||||
LayoutParams lp = new LayoutParams(size, size);
|
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||||
lp.addRule(CENTER_VERTICAL);
|
|
||||||
lp.leftMargin = 16;
|
|
||||||
lp.rightMargin = 16;
|
|
||||||
addView(iv, lp);
|
|
||||||
|
|
||||||
TextView tv = new TextView(mContext);
|
|
||||||
tv.setPadding(4, 0, 0, 0);
|
|
||||||
tv.setId(android.R.id.title);
|
|
||||||
tv.setTextColor(0xff000000);
|
|
||||||
tv.setText(category);
|
|
||||||
tv.setAllCaps(true);
|
|
||||||
lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.addRule(RIGHT_OF, iv.getId());
|
|
||||||
lp.topMargin = p / 2;
|
lp.topMargin = p / 2;
|
||||||
addView(tv, lp);
|
lp.leftMargin = lm;
|
||||||
|
addView(title, lp);
|
||||||
|
|
||||||
mSpinner = new BucketSpinner(defaultValue, values);
|
TextView subtitle = new TextView(mContext);
|
||||||
|
subtitle.setTextColor(0xff000000);
|
||||||
|
subtitle.setTypeface(LIGHT);
|
||||||
|
subtitle.setText(values[defaultValue]);
|
||||||
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
lp.addRule(RIGHT_OF, iv.getId());
|
lp.addRule(BELOW, title.getId());
|
||||||
lp.addRule(BELOW, tv.getId());
|
lp.leftMargin = lm;
|
||||||
addView(mSpinner, lp);
|
lp.bottomMargin = p / 2;
|
||||||
}
|
addView(subtitle, lp);
|
||||||
}
|
|
||||||
|
|
||||||
private class BucketSpinner extends Spinner {
|
|
||||||
private final Bitmap mArrow;
|
|
||||||
|
|
||||||
public BucketSpinner(int defaultValue, String... values) {
|
|
||||||
super(ZenModeConfigView.this.mContext);
|
|
||||||
setGravity(Gravity.LEFT);
|
|
||||||
mArrow = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.spinner_default_holo_dark_am_no_underline);
|
|
||||||
setPadding(0, 0, getPaddingRight(), getPaddingBottom());
|
|
||||||
setBackgroundColor(0x00000000);
|
|
||||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, 0) {
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
return getDropDownView(position, convertView, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
|
||||||
final TextView tv = convertView != null ? (TextView) convertView
|
|
||||||
: new TextView(ZenModeConfigView.this.mContext);
|
|
||||||
tv.setText(getItem(position));
|
|
||||||
if (convertView == null) {
|
|
||||||
tv.setTypeface(LIGHT);
|
|
||||||
tv.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
|
||||||
tv.setTextColor(0xff000000);
|
|
||||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize() * 1.5f);
|
|
||||||
final int p = (int) tv.getTextSize() / 2;
|
|
||||||
if (parent instanceof ListView) {
|
|
||||||
final ListView lv = (ListView)parent;
|
|
||||||
lv.setDividerHeight(0);
|
|
||||||
tv.setBackgroundColor(BG_COLOR);
|
|
||||||
tv.setPadding(p, p, p, p);
|
|
||||||
} else {
|
|
||||||
tv.setPadding(0, 0, p, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tv;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
adapter.addAll(values);
|
|
||||||
setAdapter(adapter);
|
|
||||||
setSelection(defaultValue, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
final TextView tv = (TextView)getSelectedView();
|
|
||||||
final int w = (int)tv.getLayout().getLineWidth(0);
|
|
||||||
final int left = w - mArrow.getWidth() / 4;
|
|
||||||
final int top = getHeight() - mArrow.getHeight();
|
|
||||||
canvas.drawBitmap(mArrow, left, top, null);
|
|
||||||
super.onDraw(canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSelection(int position) {
|
|
||||||
if (position != getSelectedItemPosition()) {
|
|
||||||
notImplemented();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,35 +266,18 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
setBackgroundColor(0xffffffff);
|
setBackgroundColor(0xffffffff);
|
||||||
final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
|
final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
|
||||||
final int p2 = p / 4;
|
|
||||||
setPadding(p2, p2, p2, p2);
|
|
||||||
|
|
||||||
final CheckBox cb = new CheckBox(mContext);
|
|
||||||
cb.setId(android.R.id.checkbox);
|
|
||||||
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
if (isChecked) {
|
|
||||||
cb.setChecked(false);
|
|
||||||
notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,
|
|
||||||
LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.addRule(ALIGN_PARENT_RIGHT);
|
|
||||||
addView(cb, lp);
|
|
||||||
|
|
||||||
final TextView tv = new TextView(mContext);
|
final TextView tv = new TextView(mContext);
|
||||||
tv.setText(text);
|
tv.setText(text);
|
||||||
tv.setTypeface(LIGHT);
|
tv.setTypeface(LIGHT);
|
||||||
tv.setTextColor(0xff000000);
|
tv.setTextColor(0xff000000);
|
||||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize() * 1.5f);
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize() * 1.5f);
|
||||||
final int p3 = p / 2;
|
LayoutParams lp =
|
||||||
tv.setPadding(p3, 0, p3, 0);
|
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||||
lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.addRule(LEFT_OF, cb.getId());
|
|
||||||
lp.addRule(CENTER_VERTICAL);
|
lp.addRule(CENTER_VERTICAL);
|
||||||
|
lp.bottomMargin = p / 2;
|
||||||
|
lp.topMargin = p / 2;
|
||||||
|
lp.leftMargin = p * 3 / 4;
|
||||||
addView(tv, lp);
|
addView(tv, lp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user