OSDN Git Service

Zen mode settings update.
authorJohn Spurlock <jspurlock@google.com>
Mon, 31 Mar 2014 16:02:35 +0000 (12:02 -0400)
committerJohn Spurlock <jspurlock@google.com>
Mon, 31 Mar 2014 16:07:52 +0000 (12:07 -0400)
 - 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

src/com/android/settings/NotificationSettings.java
src/com/android/settings/ZenModeSettings.java

index 3deb85b..d0b64a6 100644 (file)
@@ -58,7 +58,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
             = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_NOTIFICATION_PREFERENCES);
 
     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_LOCK_SCREEN_NOTIFICATIONS = "toggle_lock_screen_notifications";
     private static final String KEY_HEADS_UP = "heads_up";
index 3dae7f2..897df7e 100644 (file)
@@ -20,9 +20,6 @@ import android.app.ActionBar;
 import android.app.Activity;
 import android.content.Context;
 import android.database.ContentObserver;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
@@ -34,21 +31,18 @@ import android.util.Log;
 import android.util.TypedValue;
 import android.view.Gravity;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.ImageView;
 import android.widget.LinearLayout;
-import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.ScrollView;
-import android.widget.Spinner;
 import android.widget.Switch;
 import android.widget.TextView;
-import android.widget.Toast;
 
 public class ZenModeSettings extends SettingsPreferenceFragment {
     private static final String TAG = "ZenModeSettings";
@@ -59,24 +53,24 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
 
     private ZenModeConfigView mConfig;
     private Switch mSwitch;
+    private Activity mActivity;
+    private MenuItem mSearch;
 
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        final Activity activity = getActivity();
-        mSwitch = new Switch(activity);
-        activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
-                ActionBar.DISPLAY_SHOW_CUSTOM);
-        activity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(
-                ActionBar.LayoutParams.WRAP_CONTENT,
-                ActionBar.LayoutParams.WRAP_CONTENT,
-                Gravity.CENTER_VERTICAL | Gravity.END));
+        mActivity = getActivity();
+        mSwitch = new Switch(mActivity);
+        final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
+        mSwitch.setPadding(0, 0, p, 0);
+        setHasOptionsMenu(true);
     }
 
     @Override
-    public void onPause() {
-        super.onPause();
-        mSettingsObserver.unregister();
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
+        mSearch = menu.findItem(R.id.search);
+        if (mSearch != null) mSearch.setVisible(false);
     }
 
     @Override
@@ -84,6 +78,21 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
         super.onResume();
         updateState();
         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 {
@@ -156,7 +165,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
         private final Context mContext;
 
         private Drawable mOldBackground;
-        private Toast mToast;
 
         public ZenModeConfigView(Context context) {
             super(context);
@@ -200,138 +208,55 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
         }
 
         private void addTriggers() {
-            addView(new TriggerView("While driving"));
-            addView(new TriggerView("While in meetings"));
-            addView(new TriggerView("During a set time period"));
+            addView(new TriggerView("Never"));
         }
 
         private void addBuckets() {
             LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
                     LayoutParams.WRAP_CONTENT);
-            BucketView callView = new BucketView(android.R.drawable.ic_menu_call, "Phone Calls", 0,
-                    "Block all", "Block all except...");
+            BucketView callView = new BucketView("Phone calls", 0,
+                    "Block all", "Block all except...", "Allow all");
             addView(callView, lp);
             lp.topMargin = 4;
-            BucketView msgView = new BucketView(android.R.drawable.ic_menu_myplaces,
-                    "Texts, SMS, & Other Calls", 0,
-                    "Block all", "Block all except...");
+            BucketView msgView = new BucketView("Texts, SMS, & other calls", 0,
+                    "Block all", "Block all except...", "Allow all");
             addView(msgView, lp);
-            BucketView alarmView = new BucketView(android.R.drawable.ic_menu_agenda,
-                    "Alarms & Timers", 1,
-                    "Block all", "Allow all");
+            BucketView alarmView = new BucketView("Alarms & timers", 2,
+                    "Block all", "Block all except...", "Allow all");
             addView(alarmView, lp);
-            BucketView otherView = new BucketView(android.R.drawable.ic_menu_info_details,
-                    "Other Interruptions", 0,
-                    "Block all", "Block all except...");
+            BucketView otherView = new BucketView("Other interruptions", 0,
+                    "Block all", "Block all except...", "Allow all");
             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 final BucketSpinner mSpinner;
-
-            public BucketView(int icon, String category, int defaultValue, String... values) {
+            public BucketView(String category, int defaultValue, String... values) {
                 super(ZenModeConfigView.this.mContext);
 
                 setBackgroundColor(0xffffffff);
                 final int p = getResources().getDimensionPixelSize(R.dimen.content_margin_left);
-
-                final ImageView iv = new ImageView(mContext);
-                iv.setId(android.R.id.icon);
-                iv.setImageResource(icon);
-                iv.setAlpha(.5f);
-
-                final int size = mContext.getResources()
-                        .getDimensionPixelSize(R.dimen.app_icon_size);
-                LayoutParams lp = new LayoutParams(size, size);
-                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());
+                final int lm = p * 3 / 4;
+                TextView title = new TextView(mContext);
+                title.setId(android.R.id.title);
+                title.setTextColor(0xff000000);
+                title.setTypeface(LIGHT);
+                title.setText(category);
+                title.setTextSize(TypedValue.COMPLEX_UNIT_PX, title.getTextSize() * 1.5f);
+                LayoutParams lp =
+                        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                 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.addRule(RIGHT_OF, iv.getId());
-                lp.addRule(BELOW, tv.getId());
-                addView(mSpinner, 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();
-                }
+                lp.addRule(BELOW, title.getId());
+                lp.leftMargin = lm;
+                lp.bottomMargin = p / 2;
+                addView(subtitle, lp);
             }
         }
 
@@ -341,35 +266,18 @@ public class ZenModeSettings extends SettingsPreferenceFragment {
 
                 setBackgroundColor(0xffffffff);
                 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);
                 tv.setText(text);
                 tv.setTypeface(LIGHT);
                 tv.setTextColor(0xff000000);
                 tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize() * 1.5f);
-                final int p3 = p / 2;
-                tv.setPadding(p3, 0, p3, 0);
-                lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
-                lp.addRule(LEFT_OF, cb.getId());
+                LayoutParams lp =
+                        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                 lp.addRule(CENTER_VERTICAL);
+                lp.bottomMargin = p / 2;
+                lp.topMargin = p / 2;
+                lp.leftMargin = p * 3 / 4;
                 addView(tv, lp);
             }
         }