Clean up user preset dialog

Change-Id: Idefafe3a877e8a0cf25ca955f689818e193fde72
diff --git a/res/layout/filtershow_presets_management_dialog.xml b/res/layout/filtershow_presets_management_dialog.xml
index f6c6fb7..68754e2 100644
--- a/res/layout/filtershow_presets_management_dialog.xml
+++ b/res/layout/filtershow_presets_management_dialog.xml
@@ -22,14 +22,30 @@
               android:divider="?android:dividerVertical"
               android:showDividers="middle">
 
-    <ListView
-            android:id="@+id/listItems"
-            android:orientation="vertical"
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:layout_margin="8dip">
+
+        <TextView
+                android:layout_height="wrap_content"
+                android:layout_width="wrap_content"
+                android:text="@string/filtershow_preset_name"
+                android:layout_margin="8dp"
+                />
+
+        <EditText
+            android:id="@+id/editView"
+            android:gravity="center"
+            android:textSize="18sp"
+            android:layout_weight="1"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_margin="8dip"
-            android:divider="@android:color/transparent"
-            android:dividerHeight="8dip"/>
+            android:focusable="true"
+            android:imeOptions="actionDone"
+            android:singleLine="true"/>
+    </LinearLayout>
 
     <LinearLayout
             android:orientation="horizontal"
@@ -46,14 +62,6 @@
                 style="?android:attr/buttonBarButtonStyle" />
 
         <Button
-                android:id="@+id/addpreset"
-                android:layout_width="0dp"
-                android:layout_height="match_parent"
-                android:layout_weight="1"
-                android:text="@string/filtershow_save_preset"
-                style="?android:attr/buttonBarButtonStyle"/>
-
-        <Button
                 android:id="@+id/ok"
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
diff --git a/res/layout/filtershow_presets_management_row.xml b/res/layout/filtershow_presets_management_row.xml
index 648e874..bd3e479 100644
--- a/res/layout/filtershow_presets_management_row.xml
+++ b/res/layout/filtershow_presets_management_row.xml
@@ -47,5 +47,6 @@
             android:background="@android:color/transparent"
             android:layout_weight=".1"
             android:gravity="center"
-            android:src="@drawable/ic_menu_trash_holo_light"/>
+            android:src="@drawable/ic_menu_trash_holo_light"
+            android:visibility="gone"/>
 </LinearLayout>
\ No newline at end of file
diff --git a/res/values/filtershow_strings.xml b/res/values/filtershow_strings.xml
index 4d84007..6c8bbc2 100644
--- a/res/values/filtershow_strings.xml
+++ b/res/values/filtershow_strings.xml
@@ -257,6 +257,8 @@
     <string name="filtershow_manage_preset">Manage user presets</string>
     <!-- Label for newly created user preset [CHAR LIMIT=30] -->
     <string name="filtershow_new_preset">New Preset</string>
+    <!-- Label for preset name [CHAR LIMIT=30] -->
+    <string name="filtershow_preset_name">Preset Name</string>
 
     <!-- Label for showing the image information panel [CHAR LIMIT=50] -->
     <string name="filtershow_show_info_panel">Information</string>
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 5cd780f..f386b1b 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -428,6 +428,14 @@
         updateVersions();
     }
 
+    public void removeLook(Action action) {
+        FilterUserPresetRepresentation rep = (FilterUserPresetRepresentation) action.getRepresentation();
+        if (rep == null) {
+            return;
+        }
+        mUserPresetsManager.delete(rep.getId());
+    }
+
     private void fillEffects() {
         FiltersManager filtersManager = FiltersManager.getManager();
         ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getEffects();
@@ -1002,7 +1010,7 @@
         for (int i = 0; i < presets.size(); i++) {
             FilterUserPresetRepresentation representation = presets.get(i);
             mCategoryLooksAdapter.add(
-                    new Action(this, representation, Action.FULL_VIEW));
+                    new Action(this, representation, Action.FULL_VIEW, true));
             mUserPresetsAdapter.add(new Action(this, representation, Action.FULL_VIEW));
         }
         if (presets.size() > 0) {
@@ -1011,8 +1019,8 @@
         mCategoryLooksAdapter.notifyDataSetInvalidated();
     }
 
-    public void saveCurrentImagePreset() {
-        mUserPresetsManager.save(MasterImage.getImage().getPreset());
+    public void saveCurrentImagePreset(String name) {
+        mUserPresetsManager.save(MasterImage.getImage().getPreset(), name);
     }
 
     private void deletePreset(int id) {
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
index 5c273e0..54aca54 100644
--- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
+++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
@@ -159,12 +159,17 @@
 
     @Override
     public void remove(Action action) {
-        if (mCategory != MainPanel.VERSIONS) {
+        if (!(mCategory == MainPanel.VERSIONS
+                || mCategory == MainPanel.LOOKS)) {
             return;
         }
         super.remove(action);
         FilterShowActivity activity = (FilterShowActivity) getContext();
-        activity.removeVersion(action);
+        if (mCategory == MainPanel.LOOKS) {
+            activity.removeLook(action);
+        } else if (mCategory == MainPanel.VERSIONS) {
+            activity.removeVersion(action);
+        }
     }
 
     public void setOrientation(int orientation) {
diff --git a/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java b/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
index 114cd3e..f36509d 100644
--- a/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
+++ b/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
@@ -86,11 +86,11 @@
         String name;
     }
 
-    public void save(ImagePreset preset) {
+    public void save(ImagePreset preset, String name) {
         Message msg = mProcessingHandler.obtainMessage(SAVE);
         SaveOperation op = new SaveOperation();
         op.json = preset.getJsonString(mActivity.getString(R.string.saved));
-        op.name= mActivity.getString(R.string.filtershow_new_preset);
+        op.name = name;
         msg.obj = op;
         mProcessingHandler.sendMessage(msg);
     }
diff --git a/src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java b/src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java
index 7ab61fc..63a6165 100644
--- a/src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java
+++ b/src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java
@@ -21,12 +21,15 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.ImageView;
 import android.widget.ListView;
 import com.android.gallery3d.R;
 import com.android.gallery3d.filtershow.FilterShowActivity;
 
 public class PresetManagementDialog extends DialogFragment implements View.OnClickListener {
     private UserPresetsAdapter mAdapter;
+    private EditText mEditText;
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -35,13 +38,10 @@
 
         FilterShowActivity activity = (FilterShowActivity) getActivity();
         mAdapter = activity.getUserPresetsAdapter();
-        ListView panel = (ListView) view.findViewById(R.id.listItems);
-        panel.setAdapter(mAdapter);
-
+        mEditText = (EditText) view.findViewById(R.id.editView);
         view.findViewById(R.id.cancel).setOnClickListener(this);
-        view.findViewById(R.id.addpreset).setOnClickListener(this);
         view.findViewById(R.id.ok).setOnClickListener(this);
-        getDialog().setTitle(getString(R.string.filtershow_manage_preset));
+        getDialog().setTitle(getString(R.string.filtershow_save_preset));
         return view;
     }
 
@@ -55,11 +55,9 @@
                 activity.updateUserPresetsFromAdapter(mAdapter);
                 dismiss();
                 break;
-            case R.id.addpreset:
-                activity.saveCurrentImagePreset();
-                dismiss();
-                break;
             case R.id.ok:
+                String text = String.valueOf(mEditText.getText());
+                activity.saveCurrentImagePreset(text);
                 mAdapter.updateCurrent();
                 activity.updateUserPresetsFromAdapter(mAdapter);
                 dismiss();