From 879ba7b0cd6d9fa61bd412ecb32fc8f156eda843 Mon Sep 17 00:00:00 2001 From: Bobby Georgescu Date: Tue, 11 Sep 2012 17:02:03 -0700 Subject: Launch next-gen editor if present and show FX button Bug: 7050303 Shows editor button on the photo page and launches the next-gen photo editor if it is present on the device. Change-Id: I4058cffaec3fc4b446bd90dbecb809681d3255ea --- src/com/android/gallery3d/app/PhotoPage.java | 77 ++++++++++++++++++++-- .../android/gallery3d/data/FilterDeleteSet.java | 5 ++ 2 files changed, 77 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 6b7459c8d..0f927df64 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -22,13 +22,18 @@ import android.content.ActivityNotFoundException; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Rect; import android.net.Uri; import android.nfc.NfcAdapter; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.view.View; +import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; +import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.Toast; import com.actionbarsherlock.app.ActionBar.OnMenuVisibilityListener; @@ -85,6 +90,7 @@ public class PhotoPage extends ActivityState implements private static final int MSG_UNFREEZE_GLROOT = 6; private static final int MSG_WANT_BARS = 7; private static final int MSG_REFRESH_GRID_BUTTON = 8; + private static final int MSG_REFRESH_EDIT_BUTTON = 9; private static final int HIDE_BARS_TIMEOUT = 3500; private static final int UNFREEZE_GLROOT_TIMEOUT = 250; @@ -111,6 +117,8 @@ public class PhotoPage extends ActivityState implements public static final int MSG_ALBUMPAGE_RESUMED = 2; public static final int MSG_ALBUMPAGE_PICKED = 4; + public static final String ACTION_NEXTGEN_EDIT = "action_nextgen_edit"; + private GalleryApp mApplication; private SelectionManager mSelectionManager; @@ -361,6 +369,10 @@ public class PhotoPage extends ActivityState implements setGridButtonVisibility(mPhotoView.getFilmMode()); break; } + case MSG_REFRESH_EDIT_BUTTON: { + refreshEditButton(); + break; + } case MSG_LOCK_ORIENTATION: { mOrientationManager.lockOrientation(); break; @@ -391,6 +403,46 @@ public class PhotoPage extends ActivityState implements }; mPhotoView.setFilmMode(mStartInFilmstrip); + setupEditButton(); + } + + private ImageView mEditButton; + private void setupEditButton() { + RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity) + .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root); + if (galleryRoot == null) return; + + mEditButton = new ImageView(mActivity); + mEditButton.setImageResource(R.drawable.photoeditor_artistic); + mEditButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + launchPhotoEditor(); + } + }); + RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( + RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT); + lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + galleryRoot.addView(mEditButton, lp); + refreshEditButton(); + } + + private void cleanupEditButton() { + RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity) + .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root); + if (galleryRoot == null) return; + galleryRoot.removeView(mEditButton); + mEditButton = null; + } + + private void refreshEditButton() { + if (mEditButton == null) return; + if(mShowBars) { + mEditButton.setVisibility(View.VISIBLE); + } else { + mEditButton.setVisibility(View.GONE); + } } @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) @@ -411,6 +463,21 @@ public class PhotoPage extends ActivityState implements } + private void launchPhotoEditor() { + MediaItem current = mModel.getMediaItem(0); + if (current == null) return; + + Intent intent = new Intent(ACTION_NEXTGEN_EDIT); + intent.setData(mActivity.getDataManager().getContentUri(current.getPath())).setFlags( + Intent.FLAG_GRANT_READ_URI_PERMISSION); + if (mActivity.getPackageManager() + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) { + intent.setAction(Intent.ACTION_EDIT); + } + ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), + REQUEST_EDIT); + } + private void updateShareURI(Path path) { DataManager manager = mActivity.getDataManager(); Uri uri = manager.getContentUri(path); @@ -489,6 +556,7 @@ public class PhotoPage extends ActivityState implements mActionBar.show(); mActivity.getGLRoot().setLightsOutMode(false); refreshHidingMessage(); + refreshEditButton(); } private void hideBars() { @@ -497,6 +565,7 @@ public class PhotoPage extends ActivityState implements mActionBar.hide(); mActivity.getGLRoot().setLightsOutMode(true); mHandler.removeMessages(MSG_HIDE_BARS); + refreshEditButton(); } private void refreshHidingMessage() { @@ -718,11 +787,7 @@ public class PhotoPage extends ActivityState implements return true; } case R.id.action_edit: { - Intent intent = new Intent(Intent.ACTION_EDIT) - .setData(manager.getContentUri(path)) - .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), - REQUEST_EDIT); + launchPhotoEditor(); return true; } case R.id.action_details: { @@ -1010,6 +1075,7 @@ public class PhotoPage extends ActivityState implements public void onFilmModeChanged(boolean enabled) { mHandler.sendEmptyMessage(MSG_REFRESH_GRID_BUTTON); + mHandler.sendEmptyMessage(MSG_REFRESH_EDIT_BUTTON); if (enabled) { mHandler.removeMessages(MSG_HIDE_BARS); } else { @@ -1083,6 +1149,7 @@ public class PhotoPage extends ActivityState implements } mOrientationManager.removeListener(this); mActivity.getGLRoot().setOrientationSource(null); + cleanupEditButton(); // Remove all pending messages. mHandler.removeCallbacksAndMessages(null); diff --git a/src/com/android/gallery3d/data/FilterDeleteSet.java b/src/com/android/gallery3d/data/FilterDeleteSet.java index 2738387a6..b2b84e86f 100644 --- a/src/com/android/gallery3d/data/FilterDeleteSet.java +++ b/src/com/android/gallery3d/data/FilterDeleteSet.java @@ -71,6 +71,11 @@ public class FilterDeleteSet extends MediaSet implements ContentListener { mBaseSet.addContentListener(this); } + @Override + public boolean isCameraRoll() { + return mBaseSet.isCameraRoll(); + } + @Override public String getName() { return mBaseSet.getName(); -- cgit v1.2.3