Bug 1023544 - Add back ability to remove dynamic panels in settings. r=liuche
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 13 Jun 2014 16:25:10 -0700
changeset 188562 2aeaa45be97e1e8c54582083af5dfc1cbf129e23
parent 188561 0137da4202c5520ad6e147acfbdfc9db8940bfea
child 188563 562963c7766b7f5ffc3285574c578a63fb273f55
push id7287
push usermleibovic@mozilla.com
push dateFri, 13 Jun 2014 23:25:19 +0000
treeherderfx-team@2aeaa45be97e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1023544
milestone33.0a1
Bug 1023544 - Add back ability to remove dynamic panels in settings. r=liuche
mobile/android/base/preferences/PanelsPreference.java
mobile/android/base/preferences/PanelsPreferenceCategory.java
--- a/mobile/android/base/preferences/PanelsPreference.java
+++ b/mobile/android/base/preferences/PanelsPreference.java
@@ -25,40 +25,43 @@ public class PanelsPreference extends Cu
     protected String LOGTAG = "PanelsPreference";
 
     // Position state of this Preference in enclosing category.
     private static final int STATE_IS_FIRST = 0;
     private static final int STATE_IS_LAST = 1;
 
     /**
      * Index of the context menu button for controlling display options.
-     * This button toggles showing or hiding the panel.
+     * For (removable) Dynamic panels, this button removes the panel.
+     * For built-in panels, this button toggles showing or hiding the panel.
      */
     private static final int INDEX_DISPLAY_BUTTON = 1;
     private static final int INDEX_REORDER_BUTTON = 2;
 
     // Indices of buttons in context menu for reordering.
     private static final int INDEX_MOVE_UP_BUTTON = 0;
     private static final int INDEX_MOVE_DOWN_BUTTON = 1;
 
     private String LABEL_HIDE;
     private String LABEL_SHOW;
 
     private View preferenceView;
     protected boolean mIsHidden = false;
+    private boolean mIsRemovable;
 
     private boolean mAnimate;
     private static final int ANIMATION_DURATION_MS = 400;
 
     // State for reordering.
     private int mPositionState = -1;
     private final int mIndex;
 
-    public PanelsPreference(Context context, CustomListCategory parentCategory, int index, boolean animate) {
+    public PanelsPreference(Context context, CustomListCategory parentCategory, boolean isRemovable, int index, boolean animate) {
         super(context, parentCategory);
+        mIsRemovable = isRemovable;
         mIndex = index;
         mAnimate = animate;
     }
 
     @Override
     protected int getPreferenceLayoutResource() {
         return R.layout.preference_panels;
     }
@@ -90,16 +93,21 @@ public class PanelsPreference extends Cu
         }
     }
 
     @Override
     protected String[] createDialogItems() {
         final Resources res = getContext().getResources();
         final String labelReorder = res.getString(R.string.pref_panels_reorder);
 
+        if (mIsRemovable) {
+            return new String[] { LABEL_SET_AS_DEFAULT, LABEL_REMOVE, labelReorder };
+        }
+
+        // Built-in panels can't be removed, so use show/hide options.
         LABEL_HIDE = res.getString(R.string.pref_panels_hide);
         LABEL_SHOW = res.getString(R.string.pref_panels_show);
 
         return new String[] { LABEL_SET_AS_DEFAULT, LABEL_HIDE, labelReorder };
     }
 
     @Override
     public void setIsDefault(boolean isDefault) {
@@ -118,18 +126,24 @@ public class PanelsPreference extends Cu
     @Override
     protected void onDialogIndexClicked(int index) {
         switch(index) {
             case INDEX_SET_DEFAULT_BUTTON:
                 mParentCategory.setDefault(this);
                 break;
 
             case INDEX_DISPLAY_BUTTON:
-                // The button toggles between text for showing or hiding the panel.
-                ((PanelsPreferenceCategory) mParentCategory).setHidden(this, !mIsHidden);
+                // Handle display options for the panel.
+                if (mIsRemovable) {
+                    // For removable panels, the button displays text for removing the panel.
+                    mParentCategory.uninstall(this);
+                } else {
+                    // Otherwise, the button toggles between text for showing or hiding the panel.
+                    ((PanelsPreferenceCategory) mParentCategory).setHidden(this, !mIsHidden);
+                }
                 break;
 
             case INDEX_REORDER_BUTTON:
                 // Display dialog for changing preference order.
                 final Dialog orderDialog = makeReorderDialog();
                 orderDialog.show();
                 break;
 
@@ -138,18 +152,20 @@ public class PanelsPreference extends Cu
         }
     }
 
     @Override
     protected void configureShownDialog() {
         super.configureShownDialog();
 
         // Handle Show/Hide buttons.
-        final TextView hideButton = (TextView) mDialog.getListView().getChildAt(INDEX_DISPLAY_BUTTON);
-        hideButton.setText(mIsHidden ? LABEL_SHOW : LABEL_HIDE);
+        if (!mIsRemovable) {
+            final TextView hideButton = (TextView) mDialog.getListView().getChildAt(INDEX_DISPLAY_BUTTON);
+            hideButton.setText(mIsHidden ? LABEL_SHOW : LABEL_HIDE);
+        }
     }
 
 
     private Dialog makeReorderDialog() {
         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
 
         final Resources res = getContext().getResources();
         final String labelUp = res.getString(R.string.pref_panels_move_up);
--- a/mobile/android/base/preferences/PanelsPreferenceCategory.java
+++ b/mobile/android/base/preferences/PanelsPreferenceCategory.java
@@ -93,21 +93,23 @@ public class PanelsPreferenceCategory ex
         } else {
             displayHomeConfig(state, animatePanelId);
         }
     }
 
     private void displayHomeConfig(HomeConfig.State configState, String animatePanelId) {
         int index = 0;
         for (PanelConfig panelConfig : configState) {
+            final boolean isRemovable = panelConfig.isDynamic();
+
             // Create and add the pref.
             final String panelId = panelConfig.getId();
             final boolean animate = TextUtils.equals(animatePanelId, panelId);
 
-            final PanelsPreference pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, index, animate);
+            final PanelsPreference pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, index, animate);
             pref.setTitle(panelConfig.getTitle());
             pref.setKey(panelConfig.getId());
             // XXX: Pull icon from PanelInfo.
             addPreference(pref);
 
             if (panelConfig.isDisabled()) {
                 pref.setHidden(true);
             }