diff options
| author | Chao Zhang <chaoz@codeaurora.org> | 2016-05-23 14:31:39 +0800 |
|---|---|---|
| committer | Likai Ding <likaid@codeaurora.org> | 2016-06-28 10:31:30 +0800 |
| commit | 7362c026871e6ce0bb2a6e9a3de6b55c9a917e96 (patch) | |
| tree | df2243cbd9dc9650d198dcb39568f6803d3ea970 | |
| parent | 391b17fca58392701b4a601c2390220a48145530 (diff) | |
| download | android_packages_apps_Gallery2-7362c026871e6ce0bb2a6e9a3de6b55c9a917e96.tar.gz android_packages_apps_Gallery2-7362c026871e6ce0bb2a6e9a3de6b55c9a917e96.tar.bz2 android_packages_apps_Gallery2-7362c026871e6ce0bb2a6e9a3de6b55c9a917e96.zip | |
Gallery2: improve apply filter operation performance in Photo Editor.
1. modify HazeBuster, SeeStraight and TrueScanner editor interface.
2. open filter directly if has only one category.
3. modify logic of compare button.
Change-Id: Ifa6e77d87548024bea67441c5d87fd12eaaf6f7c
CRs-Fixed: 1018892
9 files changed, 133 insertions, 146 deletions
diff --git a/res/layout/filtershow_category_geometry_panel.xml b/res/layout/filtershow_category_geometry_panel.xml index 92dc359d6..e66aa12a4 100644 --- a/res/layout/filtershow_category_geometry_panel.xml +++ b/res/layout/filtershow_category_geometry_panel.xml @@ -140,7 +140,7 @@ android:id="@+id/cancel" android:layout_width="@dimen/category_actionbar_panel_height" android:layout_height="@dimen/category_actionbar_panel_height" - android:background="@color/edit_actionbar_background" + android:background="?android:attr/actionBarItemBackground" android:src="@drawable/cancel" /> <TextView @@ -155,7 +155,7 @@ android:id="@+id/done" android:layout_width="@dimen/category_actionbar_panel_height" android:layout_height="@dimen/category_actionbar_panel_height" - android:background="@color/edit_actionbar_background" + android:background="?android:attr/actionBarItemBackground" android:layout_gravity="right" android:src="@drawable/done" /> </FrameLayout> diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 7445abf31..b5c4b4a91 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -98,7 +98,10 @@ import com.android.gallery3d.filtershow.editors.EditorDualCamFusion; import com.android.gallery3d.filtershow.editors.EditorManager; import com.android.gallery3d.filtershow.editors.EditorPanel; import com.android.gallery3d.filtershow.editors.EditorStraighten; +import com.android.gallery3d.filtershow.editors.HazeBusterEditor; import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; +import com.android.gallery3d.filtershow.editors.SeeStraightEditor; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; @@ -357,7 +360,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL transaction.commitAllowingStateLoss(); } - public void loadEditorPanel(FilterRepresentation representation, + public void loadEditorPanel(final FilterRepresentation representation, final Editor currentEditor) { if (currentEditor.showsActionBar()) { setActionBar(); @@ -387,11 +390,15 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL }.run(); return; } - if (currentId == EditorStraighten.ID) { + if (useStraightenPanel(currentId)) { new Runnable() { @Override public void run() { StraightenPanel panel = new StraightenPanel(); + Bundle bundle = new Bundle(); + bundle.putInt(StraightenPanel.EDITOR_ID, currentId); + bundle.putString(StraightenPanel.EDITOR_NAME, representation.getName()); + panel.setArguments(bundle); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(getSupportFragmentManager().findFragmentByTag( @@ -436,6 +443,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } } + private boolean useStraightenPanel(int EditorID) { + return (EditorID == EditorStraighten.ID || EditorID == TrueScannerEditor.ID + || EditorID == HazeBusterEditor.ID || EditorID == SeeStraightEditor.ID); + } + public void leaveSeekBarPanel() { removeSeekBarPanel(); showDefaultImageView(); @@ -488,22 +500,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_DOWN) { - - HistoryManager adapter = mMasterImage.getHistory(); - int position = adapter.backToOriginal();// adapter.undo(); - mMasterImage.onHistoryItemClick(position, false); + MasterImage.getImage().setShowsOriginal(true); v.setPressed(true); - invalidateViews(); } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { v.setPressed(false); - HistoryManager adapter = mMasterImage.getHistory(); - int position = adapter.backToCurrent(); - mMasterImage.onHistoryItemClick(position, false); - invalidateViews(); - + MasterImage.getImage().setShowsOriginal(false); } return false; diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java index 762978744..bfa6b4fa4 100644 --- a/src/com/android/gallery3d/filtershow/category/MainPanel.java +++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java @@ -101,12 +101,21 @@ public class MainPanel extends Fragment implements BottomPanel.BottomPanelDelega break; } case TRUESCANNER: { + if (trueScannerButton != null) { + trueScannerButton.setSelected(value); + } break; } case HAZEBUSTER: { + if (hazeBusterButton != null) { + hazeBusterButton.setSelected(value); + } break; } case SEESTRAIGHT: { + if (seeStraightButton != null) { + seeStraightButton.setSelected(value); + } break; } } @@ -337,33 +346,51 @@ public class MainPanel extends Fragment implements BottomPanel.BottomPanelDelega } public void loadCategoryTrueScannerPanel() { - boolean fromRight = isRightAnimation(TRUESCANNER); - selection(mCurrentSelected, false); - CategoryPanel categoryPanel = new CategoryPanel(); - categoryPanel.setAdapter(TRUESCANNER); - setCategoryFragment(categoryPanel, fromRight); - mCurrentSelected = TRUESCANNER; - selection(mCurrentSelected, true); + final FilterShowActivity activity = (FilterShowActivity) getActivity(); + CategoryAdapter adapter = activity.getCategoryTrueScannerAdapter(); + if (adapter.getCount() == 1) { + activity.showRepresentation(adapter.getItem(0).getRepresentation()); + } else { + boolean fromRight = isRightAnimation(TRUESCANNER); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(TRUESCANNER); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = TRUESCANNER; + selection(mCurrentSelected, true); + } } public void loadCategoryHazeBusterPanel() { - boolean fromRight = isRightAnimation(HAZEBUSTER); - selection(mCurrentSelected, false); - CategoryPanel categoryPanel = new CategoryPanel(); - categoryPanel.setAdapter(HAZEBUSTER); - setCategoryFragment(categoryPanel, fromRight); - mCurrentSelected = HAZEBUSTER; - selection(mCurrentSelected, true); + final FilterShowActivity activity = (FilterShowActivity) getActivity(); + CategoryAdapter adapter = activity.getCategoryHazeBusterAdapter(); + if (adapter.getCount() == 1) { + activity.showRepresentation(adapter.getItem(0).getRepresentation()); + } else { + boolean fromRight = isRightAnimation(HAZEBUSTER); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(HAZEBUSTER); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = HAZEBUSTER; + selection(mCurrentSelected, true); + } } public void loadCategorySeeStraightPanel() { - boolean fromRight = isRightAnimation(SEESTRAIGHT); - selection(mCurrentSelected, false); - CategoryPanel categoryPanel = new CategoryPanel(); - categoryPanel.setAdapter(SEESTRAIGHT); - setCategoryFragment(categoryPanel, fromRight); - mCurrentSelected = SEESTRAIGHT; - selection(mCurrentSelected, true); + final FilterShowActivity activity = (FilterShowActivity) getActivity(); + CategoryAdapter adapter = activity.getCategorySeeStraightAdapter(); + if (adapter.getCount() == 1) { + activity.showRepresentation(adapter.getItem(0).getRepresentation()); + } else { + boolean fromRight = isRightAnimation(SEESTRAIGHT); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(SEESTRAIGHT); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = SEESTRAIGHT; + selection(mCurrentSelected, true); + } } public void loadCategoryFiltersPanel() { diff --git a/src/com/android/gallery3d/filtershow/category/StraightenPanel.java b/src/com/android/gallery3d/filtershow/category/StraightenPanel.java index e9eb03e7f..1ac5dc489 100644 --- a/src/com/android/gallery3d/filtershow/category/StraightenPanel.java +++ b/src/com/android/gallery3d/filtershow/category/StraightenPanel.java @@ -34,24 +34,50 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.view.View; -import org.codeaurora.gallery.R; import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.editors.EditorStraighten; +import com.android.gallery3d.filtershow.editors.Editor; + +import org.codeaurora.gallery.R; public class StraightenPanel extends BasicGeometryPanel { - private EditorStraighten mEditorStraighten; + public static final String EDITOR_ID = "editor_id"; + public static final String EDITOR_NAME = "editor_name"; + public static final int NO_EDITOR = -1; + private Editor mEditor; + private int mEditorID = NO_EDITOR; + private String mName; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + private void initArguments(Bundle arguments) { + if (arguments != null) { + mEditorID = arguments.getInt(EDITOR_ID); + mName = arguments.getString(EDITOR_NAME); + } + } @Override public void onAttach(Activity activity) { super.onAttach(activity); - FilterShowActivity filterShowActivity = (FilterShowActivity) activity; - mEditorStraighten = (EditorStraighten) filterShowActivity.getEditor(EditorStraighten.ID); + initArguments(getArguments()); + if (mEditorID != NO_EDITOR) { + FilterShowActivity filterShowActivity = (FilterShowActivity) activity; + mEditor = filterShowActivity.getEditor(mEditorID); + if (mEditor != null) { + mEditor.attach(); + } + } } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - mEditorName.setText(R.string.straighten); + if (mName != null) { + mEditorName.setText(mName); + } mBottomPanel.setVisibility(View.VISIBLE); @@ -67,7 +93,9 @@ public class StraightenPanel extends BasicGeometryPanel { mApplyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - mEditorStraighten.finalApplyCalled(); + if (mEditor != null) { + mEditor.finalApplyCalled(); + } activity.backToMain(); activity.setActionBar(); } @@ -77,17 +105,15 @@ public class StraightenPanel extends BasicGeometryPanel { @Override protected void initPanels() { super.initPanels(); - int size = mPanels.length; - for (int i = 0; i < size; i++) { - View view = mPanels[i]; + for (View view : mPanels) { view.setVisibility(View.GONE); } } @Override public void onDetach() { - if (mEditorStraighten != null) { - mEditorStraighten.detach(); + if (mEditor != null) { + mEditor.detach(); } super.onDetach(); } diff --git a/src/com/android/gallery3d/filtershow/editors/HazeBusterEditor.java b/src/com/android/gallery3d/filtershow/editors/HazeBusterEditor.java index c9ee3c8fe..8b7f4b8b9 100644 --- a/src/com/android/gallery3d/filtershow/editors/HazeBusterEditor.java +++ b/src/com/android/gallery3d/filtershow/editors/HazeBusterEditor.java @@ -67,6 +67,11 @@ public class HazeBusterEditor extends Editor { } @Override + public boolean showsActionBar() { + return false; + } + + @Override public boolean showsSeekBar() { return false; } diff --git a/src/com/android/gallery3d/filtershow/editors/SeeStraightEditor.java b/src/com/android/gallery3d/filtershow/editors/SeeStraightEditor.java index d8dff10ee..f320b4bfa 100644 --- a/src/com/android/gallery3d/filtershow/editors/SeeStraightEditor.java +++ b/src/com/android/gallery3d/filtershow/editors/SeeStraightEditor.java @@ -64,6 +64,11 @@ public class SeeStraightEditor extends Editor { } @Override + public boolean showsActionBar() { + return false; + } + + @Override public boolean showsSeekBar() { return false; } diff --git a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java index 816e0b59a..5ecee6997 100644 --- a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java +++ b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java @@ -72,6 +72,11 @@ public class TrueScannerEditor extends Editor { } @Override + public boolean showsActionBar() { + return false; + } + + @Override public boolean showsSeekBar() { return false; } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java index 7d5f57a7a..c3a7b7f38 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java @@ -27,7 +27,6 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapShader; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; @@ -44,7 +43,6 @@ import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; -import android.widget.ImageButton; import android.widget.LinearLayout; import org.codeaurora.gallery.R; @@ -73,13 +71,7 @@ public class ImageShow extends View implements OnGestureListener, private RectF mFusionBounds = new RectF(); protected Rect mImageBounds = new Rect(); - private boolean mOriginalDisabled = false; private boolean mTouchShowOriginal = false; - private long mTouchShowOriginalDate = 0; - private final long mTouchShowOriginalDelayMin = 200; // 200ms - private int mShowOriginalDirection = 0; - private static final int UNVEIL_HORIZONTAL = 1; - private static final int UNVEIL_VERTICAL = 2; private NinePatchDrawable mShadow = null; private Rect mShadowBounds = new Rect(); @@ -90,9 +82,6 @@ public class ImageShow extends View implements OnGestureListener, private Point mTouch = new Point(); private boolean mFinishedScalingOperation = false; - private int mOriginalTextMargin; - private int mOriginalTextSize; - private String mOriginalText; private boolean mZoomIn = false; Point mOriginalTranslation = new Point(); float mOriginalScale; @@ -125,7 +114,6 @@ public class ImageShow extends View implements OnGestureListener, private Paint mMaskPaint = new Paint(); private Matrix mShaderMatrix = new Matrix(); private boolean mDidStartAnimation = false; - private boolean isScalingUpAllowed = true; private static Bitmap convertToAlphaMask(Bitmap b) { Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8); @@ -180,10 +168,7 @@ public class ImageShow extends View implements OnGestureListener, Resources res = context.getResources(); mTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_text_size); mTextPadding = res.getDimensionPixelSize(R.dimen.photoeditor_text_padding); - mOriginalTextMargin = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_margin); - mOriginalTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_size); mBackgroundColor = res.getColor(R.color.background_screen); - mOriginalText = res.getString(R.string.original_picture_text); mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow); setupGestureDetector(context); mActivity = (FilterShowActivity) context; @@ -312,20 +297,19 @@ public class ImageShow extends View implements OnGestureListener, mShadowDrawn = false; - Bitmap highresPreview = MasterImage.getImage().getHighresImage(); - Bitmap fullHighres = MasterImage.getImage().getPartialImage(); + if (!drawCompareImage(canvas, MasterImage.getImage().getOriginalBitmapLarge())) { + Bitmap highresPreview = MasterImage.getImage().getHighresImage(); + Bitmap fullHighres = MasterImage.getImage().getPartialImage(); - boolean isDoingNewLookAnimation = MasterImage.getImage().onGoingNewLookAnimation(); + boolean isDoingNewLookAnimation = MasterImage.getImage().onGoingNewLookAnimation(); - if (highresPreview == null || isDoingNewLookAnimation) { - drawImageAndAnimate(canvas, getFilteredImage()); - } else { - drawImageAndAnimate(canvas, highresPreview); + if (highresPreview == null || isDoingNewLookAnimation) { + drawImageAndAnimate(canvas, getFilteredImage()); + } else { + drawImageAndAnimate(canvas, highresPreview); + } } -// drawHighresImage(canvas, fullHighres); - //drawCompareImage(canvas, getGeometryOnlyImage()); - canvas.restore(); if (!mEdgeEffect.isFinished()) { @@ -384,8 +368,7 @@ public class ImageShow extends View implements OnGestureListener, return MasterImage.getImage().getFilteredImage(); } - public void drawImageAndAnimate(Canvas canvas, - Bitmap image) { + public void drawImageAndAnimate(Canvas canvas, Bitmap image) { if (image == null) { return; } @@ -558,78 +541,18 @@ public class ImageShow extends View implements OnGestureListener, } } - public void drawCompareImage(Canvas canvas, Bitmap image) { + public boolean drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) - return; + return false; canvas.save(); if (image != null) { - if (mShowOriginalDirection == 0) { - if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { - mShowOriginalDirection = UNVEIL_VERTICAL; - } else { - mShowOriginalDirection = UNVEIL_HORIZONTAL; - } - } - - int px = 0; - int py = 0; - if (mShowOriginalDirection == UNVEIL_VERTICAL) { - px = mImageBounds.width(); - py = mTouch.y - mImageBounds.top; - } else { - px = mTouch.x - mImageBounds.left; - py = mImageBounds.height(); - if (showsOriginal) { - px = mImageBounds.width(); - } - } - - Rect d = new Rect(mImageBounds.left, mImageBounds.top, - mImageBounds.left + px, mImageBounds.top + py); - if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { - if (mTouchDown.x - mTouch.x > 0) { - d.set(mImageBounds.left + px, mImageBounds.top, - mImageBounds.right, mImageBounds.top + py); - } - } else { - if (mTouchDown.y - mTouch.y > 0) { - d.set(mImageBounds.left, mImageBounds.top + py, - mImageBounds.left + px, mImageBounds.bottom); - } - } - canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); - Paint paint = new Paint(); - paint.setColor(Color.BLACK); - paint.setStrokeWidth(3); - - if (mShowOriginalDirection == UNVEIL_VERTICAL) { - canvas.drawLine(mImageBounds.left, mTouch.y, - mImageBounds.right, mTouch.y, paint); - } else { - canvas.drawLine(mTouch.x, mImageBounds.top, - mTouch.x, mImageBounds.bottom, paint); - } - - Rect bounds = new Rect(); - paint.setAntiAlias(true); - paint.setTextSize(mOriginalTextSize); - paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); - paint.setColor(Color.BLACK); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(3); - canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, - mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); - paint.setStyle(Paint.Style.FILL); - paint.setStrokeWidth(1); - paint.setColor(Color.WHITE); - canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, - mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); + return true; } public void bindAsImageLoadListener() { @@ -680,8 +603,6 @@ public class ImageShow extends View implements OnGestureListener, mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; - mTouchShowOriginalDate = System.currentTimeMillis(); - mShowOriginalDirection = 0; MasterImage.getImage().setOriginalTranslation(MasterImage.getImage().getTranslation()); } @@ -699,12 +620,6 @@ public class ImageShow extends View implements OnGestureListener, translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); - mTouchShowOriginal = false; - } else if (enableComparison() && !mOriginalDisabled - && (System.currentTimeMillis() - mTouchShowOriginalDate - > mTouchShowOriginalDelayMin) - && event.getPointerCount() == 1) { - mTouchShowOriginal = true; } } @@ -712,7 +627,6 @@ public class ImageShow extends View implements OnGestureListener, || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; - mTouchShowOriginal = false; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java index c11729ae8..de077afed 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java @@ -219,6 +219,7 @@ public class ImageTrueScanner extends ImageShow { public void onDraw(Canvas canvas) { if(mBitmap == null) return; + toggleComparisonButtonVisibility(); if(mDisplayMatrix == null) { mDisplayMatrix = GeometryMathUtils.getFullGeometryToScreenMatrix(mGeometry, |
