OSDN Git Service

Fix for user presets
authornicolasroard <nicolasroard@google.com>
Wed, 14 Aug 2013 00:36:00 +0000 (17:36 -0700)
committernicolasroard <nicolasroard@google.com>
Wed, 14 Aug 2013 02:44:30 +0000 (19:44 -0700)
remove menu item
add spacer

Change-Id: I8a83aed6da00c6692f2204fefd17dfff3a599b8d

res/menu/filtershow_activity_menu.xml
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/category/Action.java
src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
src/com/android/gallery3d/filtershow/category/CategoryView.java
src/com/android/gallery3d/filtershow/category/IconView.java

index d7e0714..11e9890 100644 (file)
@@ -32,7 +32,7 @@
     <item
         android:id="@+id/manageUserPresets"
         android:showAsAction="never"
-        android:visible="true"
+        android:visible="false"
         android:title="@string/filtershow_manage_preset" />
     <item
         android:id="@+id/exportFlattenButton"
index 7330849..5cd780f 100644 (file)
@@ -404,9 +404,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 getString(R.string.filtershow_version_current), current, -1);
         mCategoryVersionsAdapter.add(
                 new Action(this, currentRep, Action.FULL_VIEW));
+        if (mVersions.size() > 0) {
+            mCategoryVersionsAdapter.add(new Action(this, Action.SPACER));
+        }
         for (FilterUserPresetRepresentation rep : mVersions) {
             mCategoryVersionsAdapter.add(
-                    new Action(this, rep, Action.FULL_VIEW));
+                    new Action(this, rep, Action.FULL_VIEW, true));
         }
         mCategoryVersionsAdapter.notifyDataSetInvalidated();
     }
@@ -949,6 +952,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         return false;
     }
 
+    public void addNewPreset() {
+        DialogFragment dialog = new PresetManagementDialog();
+        dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
+    }
+
     private void manageUserPresets() {
         DialogFragment dialog = new PresetManagementDialog();
         dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
@@ -987,6 +995,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         if (mCategoryLooksAdapter != null) {
             fillLooks();
         }
+        if (presets.size() > 0) {
+            mCategoryLooksAdapter.add(new Action(this, Action.SPACER));
+        }
         mUserPresetsAdapter.clear();
         for (int i = 0; i < presets.size(); i++) {
             FilterUserPresetRepresentation representation = presets.get(i);
@@ -994,8 +1005,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                     new Action(this, representation, Action.FULL_VIEW));
             mUserPresetsAdapter.add(new Action(this, representation, Action.FULL_VIEW));
         }
+        if (presets.size() > 0) {
+            mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION));
+        }
         mCategoryLooksAdapter.notifyDataSetInvalidated();
-
     }
 
     public void saveCurrentImagePreset() {
@@ -1026,6 +1039,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         for (FilterRepresentation representation : filtersRepresentations) {
             mCategoryLooksAdapter.add(new Action(this, representation, Action.FULL_VIEW));
         }
+        if (mUserPresetsManager.getRepresentations() == null
+            || mUserPresetsManager.getRepresentations().size() == 0) {
+            mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION));
+        }
     }
 
     public void setDefaultPreset() {
index d0cfffd..7bdc8ec 100644 (file)
@@ -43,14 +43,27 @@ public class Action implements RenderingRequestCaller {
     private ArrayAdapter mAdapter;
     public static final int FULL_VIEW = 0;
     public static final int CROP_VIEW = 1;
+    public static final int ADD_ACTION = 2;
+    public static final int SPACER = 3;
     private int mType = CROP_VIEW;
     private Bitmap mPortraitImage;
     private Bitmap mOverlayBitmap;
     private Context mContext;
+    private boolean mCanBeRemoved = false;
+
+    public Action(Context context, FilterRepresentation representation, int type,
+                  boolean canBeRemoved) {
+        this(context, representation, type);
+        mCanBeRemoved = canBeRemoved;
+    }
 
     public Action(Context context, FilterRepresentation representation, int type) {
-        mContext = context;
+        this(context, type);
         setRepresentation(representation);
+    }
+
+    public Action(Context context, int type) {
+        mContext = context;
         setType(type);
     }
 
@@ -58,6 +71,10 @@ public class Action implements RenderingRequestCaller {
         this(context, representation, CROP_VIEW);
     }
 
+    public boolean canBeRemoved() {
+        return mCanBeRemoved;
+    }
+
     public int getType() {
         return mType;
     }
index ad86010..5c273e0 100644 (file)
@@ -85,9 +85,14 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
         }
         CategoryView view = (CategoryView) convertView;
         view.setOrientation(mOrientation);
-        view.setAction(getItem(position), this);
+        Action action = getItem(position);
+        view.setAction(action, this);
+        int width = mItemWidth;
+        if (action.getType() == Action.SPACER) {
+            width = width / 2;
+        }
         view.setLayoutParams(
-                new ListView.LayoutParams(mItemWidth, mItemHeight));
+                new ListView.LayoutParams(width, mItemHeight));
         view.setTag(position);
         view.invalidate();
         return view;
@@ -185,8 +190,12 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
         }
         if (rep != null) {
             for (int i = 0; i < getCount(); i++) {
+                FilterRepresentation itemRep = getItem(i).getRepresentation();
+                if (itemRep == null) {
+                    continue;
+                }
                 if (rep.getName().equalsIgnoreCase(
-                        getItem(i).getRepresentation().getName())) {
+                        itemRep.getName())) {
                     selected = i;
                     break;
                 }
index cb72bc8..18079f5 100644 (file)
@@ -19,6 +19,7 @@ package com.android.gallery3d.filtershow.category;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
@@ -44,6 +45,9 @@ public class CategoryView extends IconView
     private int mBorderStroke;
     private float mStartTouchY = 0;
     private float mDeleteSlope = 20;
+    private int mSelectionColor = Color.WHITE;
+    private int mSpacerColor = Color.WHITE;
+    private boolean mCanBeRemoved = false;
 
     public CategoryView(Context context) {
         super(context);
@@ -52,7 +56,10 @@ public class CategoryView extends IconView
         mSelectionStroke = res.getDimensionPixelSize(R.dimen.thumbnail_margin);
         mSelectPaint = new Paint();
         mSelectPaint.setStyle(Paint.Style.FILL);
-        mSelectPaint.setColor(res.getColor(R.color.filtershow_category_selection));
+        mSelectionColor = res.getColor(R.color.filtershow_category_selection);
+        mSpacerColor = res.getColor(R.color.filtershow_categoryview_text);
+
+        mSelectPaint.setColor(mSelectionColor);
         mBorderPaint = new Paint(mSelectPaint);
         mBorderPaint.setColor(Color.BLACK);
         mBorderStroke = mSelectionStroke / 3;
@@ -69,8 +76,23 @@ public class CategoryView extends IconView
         return false;
     }
 
+    private boolean canBeRemoved() {
+        return mCanBeRemoved;
+    }
+
+    private void drawSpacer(Canvas canvas) {
+        mPaint.reset();
+        mPaint.setAntiAlias(true);
+        mPaint.setColor(mSpacerColor);
+        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 5, mPaint);
+    }
+
     public void onDraw(Canvas canvas) {
         if (mAction != null) {
+            if (mAction.getType() == Action.SPACER) {
+                drawSpacer(canvas);
+                return;
+            }
             if (mAction.getImage() == null) {
                 mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), getOrientation());
             } else {
@@ -89,19 +111,33 @@ public class CategoryView extends IconView
         mAction = action;
         setText(mAction.getName());
         mAdapter = adapter;
+        mCanBeRemoved = action.canBeRemoved();
         invalidate();
+        if (mAction.getType() == Action.ADD_ACTION) {
+            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.filtershow_add);
+            setBitmap(bitmap);
+            setUseOnlyDrawable(true);
+            setText(getResources().getString(R.string.filtershow_add_button_looks));
+        }
     }
 
     @Override
     public void onClick(View view) {
         FilterShowActivity activity = (FilterShowActivity) getContext();
-        activity.showRepresentation(mAction.getRepresentation());
-        mAdapter.setSelected(this);
+        if (mAction.getType() == Action.ADD_ACTION) {
+            activity.addNewPreset();
+        } else if (mAction.getType() != Action.SPACER) {
+            activity.showRepresentation(mAction.getRepresentation());
+            mAdapter.setSelected(this);
+        }
     }
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        super.onTouchEvent(event);
+        boolean ret = super.onTouchEvent(event);
+        if (!canBeRemoved()) {
+            return ret;
+        }
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
             mStartTouchY = event.getY();
         }
index 5d2aacf..0d9f6da 100644 (file)
@@ -57,8 +57,8 @@ public class IconView extends View {
                 "http://schemas.android.com/apk/res/android", "src", 0);
         Resources res = context.getResources();
         Bitmap bitmap = BitmapFactory.decodeStream(res.openRawResource(bitmapRsc));
-        mUseOnlyDrawable = true;
         setBitmap(bitmap);
+        setUseOnlyDrawable(true);
     }
 
     public IconView(Context context) {
@@ -152,6 +152,10 @@ public class IconView extends View {
         mBitmap = bitmap;
     }
 
+    public void setUseOnlyDrawable(boolean value) {
+        mUseOnlyDrawable = value;
+    }
+
     public Rect getBitmapBounds() {
         return mBitmapBounds;
     }