OSDN Git Service

Clean up user preset dialog
authornicolasroard <nicolasroard@google.com>
Wed, 14 Aug 2013 17:04:37 +0000 (10:04 -0700)
committernicolasroard <nicolasroard@google.com>
Wed, 14 Aug 2013 17:04:37 +0000 (10:04 -0700)
Change-Id: Idefafe3a877e8a0cf25ca955f689818e193fde72

res/layout/filtershow_presets_management_dialog.xml
res/layout/filtershow_presets_management_row.xml
res/values/filtershow_strings.xml
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java

index f6c6fb7..68754e2 100644 (file)
               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"
                 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"
index 648e874..bd3e479 100644 (file)
@@ -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
index 4d84007..6c8bbc2 100644 (file)
     <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>
index 5cd780f..f386b1b 100644 (file)
@@ -428,6 +428,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         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 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         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 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         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) {
index 5c273e0..54aca54 100644 (file)
@@ -159,12 +159,17 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
 
     @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) {
index 114cd3e..f36509d 100644 (file)
@@ -86,11 +86,11 @@ public class UserPresetsManager implements Handler.Callback {
         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);
     }
index 7ab61fc..63a6165 100644 (file)
@@ -21,12 +21,15 @@ import android.support.v4.app.DialogFragment;
 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 @@ public class PresetManagementDialog extends DialogFragment implements View.OnCli
 
         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 @@ public class PresetManagementDialog extends DialogFragment implements View.OnCli
                 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();