OSDN Git Service

Fix UI
authornicolasroard <nicolasroard@google.com>
Wed, 1 May 2013 03:50:03 +0000 (20:50 -0700)
committernicolasroard <nicolasroard@google.com>
Thu, 2 May 2013 02:02:55 +0000 (19:02 -0700)
bug:8664728
Change-Id: I90b903e8935b2b6c0dbd6590cff36865644c49b4

src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/category/Action.java
src/com/android/gallery3d/filtershow/category/CategoryView.java
src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
src/com/android/gallery3d/filtershow/presets/ImagePreset.java
src/com/android/gallery3d/filtershow/state/State.java
src/com/android/gallery3d/filtershow/state/StateAdapter.java
src/com/android/gallery3d/filtershow/state/StatePanelTrack.java
src/com/android/gallery3d/filtershow/state/StateView.java

index d26a58a..9e1d0be 100644 (file)
@@ -165,18 +165,39 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     }
 
     public void loadEditorPanel(FilterRepresentation representation,
-                                Editor currentEditor) {
+                                final Editor currentEditor) {
         if (representation.getEditorId() == ImageOnlyEditor.ID) {
             currentEditor.getImageShow().select();
             currentEditor.reflectCurrentFilter();
             return;
         }
-        EditorPanel panel = new EditorPanel();
-        panel.setEditor(currentEditor.getID());
-        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-        transaction.remove(getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG));
-        transaction.replace(R.id.main_panel_container, panel, MainPanel.FRAGMENT_TAG);
-        transaction.commit();
+        final int currentId = currentEditor.getID();
+        Runnable showEditor = new Runnable() {
+            @Override
+            public void run() {
+                EditorPanel panel = new EditorPanel();
+                panel.setEditor(currentId);
+                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+                transaction.remove(getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG));
+                transaction.replace(R.id.main_panel_container, panel, MainPanel.FRAGMENT_TAG);
+                transaction.commit();
+            }
+        };
+        Fragment main = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
+        boolean doAnimation = false;
+        if (mShowingImageStatePanel
+                && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
+            doAnimation = true;
+        }
+        if (doAnimation && main != null && main instanceof MainPanel) {
+            MainPanel mainPanel = (MainPanel) main;
+            View container = mainPanel.getView().findViewById(R.id.category_panel_container);
+            View bottom = mainPanel.getView().findViewById(R.id.bottom_panel);
+            int panelHeight = container.getHeight() + bottom.getHeight();
+            mainPanel.getView().animate().translationY(panelHeight).withEndAction(showEditor).start();
+        } else {
+            showEditor.run();
+        }
     }
 
     private void loadXML() {
@@ -353,7 +374,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             if (representation.getTextId() != 0) {
                 representation.setName(getString(representation.getTextId()));
             }
-            mCategoryBordersAdapter.add(new Action(this, representation));
+            mCategoryBordersAdapter.add(new Action(this, representation, Action.FULL_VIEW));
         }
     }
 
@@ -738,7 +759,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         mCategoryLooksAdapter = new CategoryAdapter(this);
         int verticalItemHeight = (int) getResources().getDimension(R.dimen.action_item_height);
         mCategoryLooksAdapter.setItemHeight(verticalItemHeight);
-        mCategoryLooksAdapter.add(new Action(this, nullFx, Action.CROP_VIEW));
+        mCategoryLooksAdapter.add(new Action(this, nullFx, Action.FULL_VIEW));
         for (FilterRepresentation representation : filtersRepresentations) {
             mCategoryLooksAdapter.add(new Action(this, representation, Action.FULL_VIEW));
         }
index 667a897..4f2c128 100644 (file)
@@ -149,7 +149,15 @@ public class Action implements RenderingRequestCaller {
                     mRepresentation.getOverlayId());
         }
         if (mOverlayBitmap != null) {
-            drawCenteredImage(mOverlayBitmap, mImage, false);
+            if (getRepresentation().getPriority() == FilterRepresentation.TYPE_BORDER) {
+                Canvas canvas = new Canvas(mImage);
+                canvas.drawBitmap(mOverlayBitmap, new Rect(0, 0, mOverlayBitmap.getWidth(), mOverlayBitmap.getHeight()),
+                        new Rect(0, 0, mImage.getWidth(), mImage.getHeight()), new Paint());
+            } else {
+                Canvas canvas = new Canvas(mImage);
+                canvas.drawARGB(128, 0, 0, 0);
+                drawCenteredImage(mOverlayBitmap, mImage, false);
+            }
         }
         if (mAdapter != null) {
             mAdapter.notifyDataSetChanged();
index 5467841..c101f98 100644 (file)
@@ -62,11 +62,8 @@ public class CategoryView extends View implements View.OnClickListener {
             return;
         }
         text = text.toUpperCase();
-        mPaint.reset();
-        mPaint.setColor(mTextColor);
         mPaint.setTextSize(sTextSize);
         mPaint.setTypeface(Typeface.DEFAULT_BOLD);
-        mPaint.setAntiAlias(true);
         float textWidth = mPaint.measureText(text);
         mPaint.getTextBounds(text, 0, text.length(), mTextBounds);
         int x = (int) (canvas.getWidth() - textWidth - sMargin);
@@ -77,13 +74,22 @@ public class CategoryView extends View implements View.OnClickListener {
     public void onDraw(Canvas canvas) {
         canvas.drawColor(mBackgroundColor);
         if (mAction != null) {
-            drawText(canvas, mAction.getName());
+            mPaint.reset();
+            mPaint.setAntiAlias(true);
             if (mAction.getImage() == null) {
                 mAction.setImageFrame(new Rect(0, 0, canvas.getWidth(), canvas.getHeight()));
             } else {
                 Bitmap bitmap = mAction.getImage();
                 canvas.drawBitmap(bitmap, 0, 0, mPaint);
             }
+            mPaint.setColor(mBackgroundColor);
+            mPaint.setStyle(Paint.Style.STROKE);
+            mPaint.setStrokeWidth(3);
+            drawText(canvas, mAction.getName());
+            mPaint.setColor(mTextColor);
+            mPaint.setStyle(Paint.Style.FILL);
+            mPaint.setStrokeWidth(1);
+            drawText(canvas, mAction.getName());
         }
     }
 
index c23b90b..9ec858c 100644 (file)
@@ -181,8 +181,6 @@ public class ParametricEditor extends Editor {
                 mControl = (Control) c.newInstance();
                 p.setController(mControl);
                 mControl.setUp((ViewGroup) editControl, p, this);
-
-
             } catch (Exception e) {
                 Log.e(LOGTAG, "Error in loading Control ", e);
             }
index 5bb0e57..82012b9 100644 (file)
@@ -117,7 +117,7 @@ public class FilterRepresentation implements Cloneable {
     }
 
     public boolean supportsPartialRendering() {
-        return mSupportsPartialRendering;
+        return false && mSupportsPartialRendering; // disable for now
     }
 
     public void setSupportsPartialRendering(boolean value) {
index 3530935..ed0a72a 100644 (file)
@@ -554,20 +554,24 @@ public class ImagePreset {
         if (imageStateAdapter == null) {
             return;
         }
-        imageStateAdapter.clear();
-        imageStateAdapter.addOriginal();
+        Vector<State> states = new Vector<State>();
         // TODO: supports Geometry representations in the state panel.
         if (false && mGeoData != null && mGeoData.hasModifications()) {
             State geo = new State("Geometry");
             geo.setFilterRepresentation(mGeoData);
-            imageStateAdapter.add(geo);
+            states.add(geo);
+        }
+        for (FilterRepresentation filter : mFilters) {
+            State state = new State(filter.getName());
+            state.setFilterRepresentation(filter);
+            states.add(state);
         }
-        imageStateAdapter.addAll(mFilters);
         if (mBorder != null) {
             State border = new State(mBorder.getName());
             border.setFilterRepresentation(mBorder);
-            imageStateAdapter.add(border);
+            states.add(border);
         }
+        imageStateAdapter.fill(states);
     }
 
     public void setPartialRendering(boolean partialRendering, Rect bounds) {
index a853371..29bbf91 100644 (file)
@@ -31,11 +31,19 @@ public class State {
        this(text, StateView.DEFAULT);
     }
 
-    State(String text, int type) {
+    public State(String text, int type) {
         mText = text;
         mType = type;
     }
 
+    public boolean equals(State state) {
+        if (mFilterRepresentation.getFilterClass()
+                != state.mFilterRepresentation.getFilterClass()) {
+            return false;
+        }
+        return true;
+    }
+
     public boolean isDraggable() {
         return mFilterRepresentation != null;
     }
index 58f9a7f..5225852 100644 (file)
@@ -17,6 +17,7 @@
 package com.android.gallery3d.filtershow.state;
 
 import android.content.Context;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
@@ -30,8 +31,8 @@ import java.util.Vector;
 
 public class StateAdapter extends ArrayAdapter<State> {
 
+    private static final String LOGTAG = "StateAdapter";
     private int mOrientation;
-    private PanelTrack mListener;
     private String mOriginalText;
     private String mResultText;
 
@@ -76,28 +77,32 @@ public class StateAdapter extends ArrayAdapter<State> {
         mOrientation = orientation;
     }
 
-    @Override
-    public void notifyDataSetChanged() {
-        if (mListener != null) {
-            mListener.fillContent(false);
-        }
-    }
-
     public void addOriginal() {
         add(new State(mOriginalText));
     }
 
-    public void addAll(Vector<FilterRepresentation> filters) {
-        for (FilterRepresentation filter : filters) {
-            State state = new State(filter.getName());
-            state.setFilterRepresentation(filter);
-            add(state);
+    public boolean same(Vector<State> states) {
+        // we have the original state in addition
+        if (states.size() + 1 != getCount()) {
+            return false;
         }
-        notifyDataSetChanged();
+        for (int i = 1; i < getCount(); i++) {
+            State state = getItem(i);
+            if (!state.equals(states.elementAt(i-1))) {
+                return false;
+            }
+        }
+        return true;
     }
 
-    void setListener(PanelTrack listener) {
-        mListener = listener;
+    public void fill(Vector<State> states) {
+        if (same(states)) {
+            return;
+        }
+        clear();
+        addOriginal();
+        addAll(states);
+        notifyDataSetChanged();
     }
 
     @Override
index 4fb1b11..fff7e7f 100644 (file)
@@ -19,6 +19,8 @@ package com.android.gallery3d.filtershow.state;
 import android.animation.LayoutTransition;
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.database.DataSetObserver;
+import android.graphics.Canvas;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.util.AttributeSet;
@@ -56,6 +58,19 @@ public class StatePanelTrack extends LinearLayout implements PanelTrack {
     private long mTouchTime;
     private int mMaxTouchDelay = 300; // 300ms delay for touch
     private static final boolean ALLOWS_DRAG = false;
+    private DataSetObserver mObserver = new DataSetObserver() {
+        @Override
+        public void onChanged() {
+            super.onChanged();
+            fillContent(false);
+        }
+
+        @Override
+        public void onInvalidated() {
+            super.onInvalidated();
+            fillContent(false);
+        }
+    };
 
     public StatePanelTrack(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -112,7 +127,7 @@ public class StatePanelTrack extends LinearLayout implements PanelTrack {
 
     public void setAdapter(StateAdapter adapter) {
         mAdapter = adapter;
-        mAdapter.setListener(this);
+        mAdapter.registerDataSetObserver(mObserver);
         mAdapter.setOrientation(getOrientation());
         fillContent(false);
         requestLayout();
@@ -236,17 +251,22 @@ public class StatePanelTrack extends LinearLayout implements PanelTrack {
                 && event.getActionMasked() == MotionEvent.ACTION_UP
                 && System.currentTimeMillis() - mTouchTime < mMaxTouchDelay) {
             FilterRepresentation representation = mCurrentView.getState().getFilterRepresentation();
+            mCurrentView.setSelected(true);
             if (representation != MasterImage.getImage().getCurrentFilterRepresentation()) {
                 FilterShowActivity activity = (FilterShowActivity) getContext();
                 activity.showRepresentation(representation);
-            }
-            if (representation.getEditorId() != ImageOnlyEditor.ID) {
-                mCurrentView.setSelected(true);
+                mCurrentView.setSelected(false);
             }
         }
         if (event.getActionMasked() == MotionEvent.ACTION_UP
                 || (!mStartedDrag && event.getActionMasked() == MotionEvent.ACTION_CANCEL)) {
             checkEndState();
+            if (mCurrentView != null) {
+                FilterRepresentation representation = mCurrentView.getState().getFilterRepresentation();
+                if (representation.getEditorId() == ImageOnlyEditor.ID) {
+                    mCurrentView.setSelected(false);
+                }
+            }
         }
         return true;
     }
index 45ca382..9353a43 100644 (file)
@@ -145,6 +145,7 @@ public class StateView extends View {
 
     public void onDraw(Canvas canvas) {
         canvas.drawARGB(0, 0, 0, 0);
+        mPaint.reset();
         mPath.reset();
 
         float w = canvas.getWidth();