summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/FilterShowActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/FilterShowActivity.java')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java260
1 files changed, 189 insertions, 71 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index f46a0b781..3807e1d75 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -29,7 +29,9 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.Color;
import android.graphics.Matrix;
+import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
@@ -44,6 +46,7 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.print.PrintHelper;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
@@ -57,8 +60,10 @@ import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
+import android.widget.PopupMenu;
import android.widget.ShareActionProvider;
import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
+import android.widget.Spinner;
import android.widget.Toast;
import com.android.gallery3d.R;
@@ -87,9 +92,11 @@ import com.android.gallery3d.filtershow.editors.EditorRotate;
import com.android.gallery3d.filtershow.editors.EditorStraighten;
import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
+import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilter;
@@ -112,8 +119,6 @@ import com.android.gallery3d.filtershow.tools.XmpPresets.XMresults;
import com.android.gallery3d.filtershow.ui.ExportDialog;
import com.android.gallery3d.filtershow.ui.FramedTextButton;
import com.android.gallery3d.util.GalleryUtils;
-import com.android.gallery3d.util.PrintJob;
-import com.android.gallery3d.util.UsageStatistics;
import com.android.photos.data.GalleryBitmapPool;
import java.io.File;
@@ -124,7 +129,8 @@ import java.util.ArrayList;
import java.util.Vector;
public class FilterShowActivity extends FragmentActivity implements OnItemClickListener,
- OnShareTargetSelectedListener {
+ OnShareTargetSelectedListener, DialogInterface.OnShowListener,
+ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
private String mAction = "";
MasterImage mMasterImage = null;
@@ -133,6 +139,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
public static final String TINY_PLANET_ACTION = "com.android.camera.action.TINY_PLANET";
public static final String LAUNCH_FULLSCREEN = "launch-fullscreen";
+ public static final boolean RESET_TO_LOADED = false;
private ImageShow mImageShow = null;
private View mSaveButton = null;
@@ -146,7 +153,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private boolean mShowingTinyPlanet = false;
private boolean mShowingImageStatePanel = false;
private boolean mShowingVersionsPanel = false;
- private boolean mShowingInformationPanel = false;
private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
@@ -164,6 +170,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private Uri mSelectedImageUri = null;
+ private ArrayList<Action> mActions = new ArrayList<Action>();
private UserPresetsManager mUserPresetsManager = null;
private UserPresetsAdapter mUserPresetsAdapter = null;
private CategoryAdapter mCategoryLooksAdapter = null;
@@ -184,6 +191,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private ProcessingService mBoundService;
private boolean mIsBound = false;
+ private Menu mMenu;
+ private DialogInterface mCurrentDialog = null;
+ private PopupMenu mCurrentMenu = null;
+ private boolean mLoadingVisible = true;
public ProcessingService getProcessingService() {
return mBoundService;
@@ -240,17 +251,21 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
- private void setupPipeline() {
- doBindService();
+ public void updateUIAfterServiceStarted() {
+ MasterImage.setMaster(mMasterImage);
ImageFilter.setActivityForMemoryToasts(this);
mUserPresetsManager = new UserPresetsManager(this);
mUserPresetsAdapter = new UserPresetsAdapter(this);
- }
- public void updateUIAfterServiceStarted() {
+ setupMasterImage();
+ setupMenu();
+ setDefaultValues();
+ fillEditors();
+ getWindow().setBackgroundDrawable(new ColorDrawable(0));
+ loadXML();
+
fillCategories();
loadMainPanel();
- setDefaultPreset();
extractXMPData();
processIntent();
}
@@ -263,19 +278,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
if (onlyUsePortrait) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
- MasterImage.setMaster(mMasterImage);
clearGalleryBitmapPool();
- setupPipeline();
-
- setupMasterImage();
- setDefaultValues();
- fillEditors();
-
- loadXML();
- UsageStatistics.onContentViewChanged(UsageStatistics.COMPONENT_EDITOR, "Main");
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_LIFECYCLE, UsageStatistics.LIFECYCLE_START);
+ doBindService();
+ getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY));
+ setContentView(R.layout.filtershow_splashscreen);
}
public boolean isShowingImageStatePanel() {
@@ -330,35 +337,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
- public void hideInformationPanel() {
- FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
- infoLayout.setVisibility(View.GONE);
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(InfoPanel.FRAGMENT_TAG);
- if (fragment != null) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.remove(fragment);
- transaction.commit();
- }
- mShowingInformationPanel = false;
- }
-
public void toggleInformationPanel() {
- mShowingInformationPanel = !mShowingInformationPanel;
- if (!mShowingInformationPanel) {
- hideInformationPanel();
- showDefaultImageView();
- return;
- }
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
- FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
- infoLayout.setVisibility(View.VISIBLE);
- mEditorPlaceHolder.hide();
- mImageShow.setVisibility(View.GONE);
InfoPanel panel = new InfoPanel();
- transaction.replace(R.id.central_panel_container, panel, InfoPanel.FRAGMENT_TAG);
- transaction.commit();
+ panel.show(transaction, InfoPanel.FRAGMENT_TAG);
}
private void loadXML() {
@@ -384,7 +368,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
setupEditors();
mEditorPlaceHolder.hide();
- mImageShow.bindAsImageLoadListener();
+ mImageShow.attach();
setupStatePanel();
}
@@ -403,10 +387,27 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
private void fillVersions() {
+ if (mCategoryVersionsAdapter != null) {
+ mCategoryVersionsAdapter.clear();
+ }
mCategoryVersionsAdapter = new CategoryAdapter(this);
mCategoryVersionsAdapter.setShowAddButton(true);
}
+ public void registerAction(Action action) {
+ if (mActions.contains(action)) {
+ return;
+ }
+ mActions.add(action);
+ }
+
+ private void loadActions() {
+ for (int i = 0; i < mActions.size(); i++) {
+ Action action = mActions.get(i);
+ action.setImageFrame(new Rect(0, 0, 96, 96), 0);
+ }
+ }
+
public void updateVersions() {
mCategoryVersionsAdapter.clear();
FilterUserPresetRepresentation originalRep = new FilterUserPresetRepresentation(
@@ -455,6 +456,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private void fillEffects() {
FiltersManager filtersManager = FiltersManager.getManager();
ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getEffects();
+ if (mCategoryFiltersAdapter != null) {
+ mCategoryFiltersAdapter.clear();
+ }
mCategoryFiltersAdapter = new CategoryAdapter(this);
for (FilterRepresentation representation : filtersRepresentations) {
if (representation.getTextId() != 0) {
@@ -467,9 +471,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private void fillTools() {
FiltersManager filtersManager = FiltersManager.getManager();
ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools();
+ if (mCategoryGeometryAdapter != null) {
+ mCategoryGeometryAdapter.clear();
+ }
mCategoryGeometryAdapter = new CategoryAdapter(this);
+ boolean found = false;
for (FilterRepresentation representation : filtersRepresentations) {
mCategoryGeometryAdapter.add(new Action(this, representation));
+ if (representation instanceof FilterDrawRepresentation) {
+ found = true;
+ }
+ }
+ if (!found) {
+ FilterRepresentation representation = new FilterDrawRepresentation();
+ Action action = new Action(this, representation);
+ action.setIsDoubleAction(true);
+ mCategoryGeometryAdapter.add(action);
}
}
@@ -525,13 +542,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size);
Spline.setCurveHandle(curveHandle, curveHandleSize);
Spline.setCurveWidth((int) getPixelsFromDip(3));
+
+ mOriginalImageUri = null;
}
private void startLoadBitmap(Uri uri) {
- final View loading = findViewById(R.id.loading);
final View imageShow = findViewById(R.id.imageShow);
imageShow.setVisibility(View.INVISIBLE);
- loading.setVisibility(View.VISIBLE);
+ startLoadingIndicator();
mShowingTinyPlanet = false;
mLoadBitmapTask = new LoadBitmapTask();
mLoadBitmapTask.execute(uri);
@@ -549,6 +567,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
+ if (mCategoryBordersAdapter != null) {
+ mCategoryBordersAdapter.clear();
+ }
mCategoryBordersAdapter = new CategoryAdapter(this);
for (FilterRepresentation representation : borders) {
if (representation.getTextId() != 0) {
@@ -646,6 +667,18 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
FilterMirrorRepresentation r = (FilterMirrorRepresentation) representation;
r.cycle();
}
+ if (representation.isBooleanFilter()) {
+ ImagePreset preset = MasterImage.getImage().getPreset();
+ if (preset.getRepresentation(representation) != null) {
+ // remove
+ ImagePreset copy = new ImagePreset(preset);
+ copy.removeFilter(representation);
+ FilterRepresentation filterRepresentation = representation.copy();
+ MasterImage.getImage().setPreset(copy, filterRepresentation, true);
+ MasterImage.getImage().setCurrentFilterRepresentation(null);
+ return;
+ }
+ }
useFilterRepresentation(representation);
// show representation
@@ -654,7 +687,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
loadEditorPanel(representation, mCurrentEditor);
- hideInformationPanel();
}
public Editor getEditor(int editorID) {
@@ -670,6 +702,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
public void updateCategories() {
+ if (mMasterImage == null) {
+ return;
+ }
ImagePreset preset = mMasterImage.getPreset();
mCategoryLooksAdapter.reflectImagePreset(preset);
mCategoryBordersAdapter.reflectImagePreset(preset);
@@ -679,6 +714,30 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
return findViewById(id);
}
+ public void onShowMenu(PopupMenu menu) {
+ mCurrentMenu = menu;
+ menu.setOnDismissListener(this);
+ }
+
+ @Override
+ public void onDismiss(PopupMenu popupMenu){
+ if (mCurrentMenu == null) {
+ return;
+ }
+ mCurrentMenu.setOnDismissListener(null);
+ mCurrentMenu = null;
+ }
+
+ @Override
+ public void onShow(DialogInterface dialog) {
+ mCurrentDialog = dialog;
+ }
+
+ @Override
+ public void onDismiss(DialogInterface dialogInterface) {
+ mCurrentDialog = null;
+ }
+
private class LoadHighresBitmapTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
@@ -713,6 +772,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
+ public boolean isLoadingVisible() {
+ return mLoadingVisible;
+ }
+
+ public void startLoadingIndicator() {
+ final View loading = findViewById(R.id.loading);
+ mLoadingVisible = true;
+ loading.setVisibility(View.VISIBLE);
+ }
+
+ public void stopLoadingIndicator() {
+ final View loading = findViewById(R.id.loading);
+ loading.setVisibility(View.GONE);
+ mLoadingVisible = false;
+ }
+
private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
int mBitmapSize;
@@ -748,7 +823,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
if (!result) {
- if (!mOriginalImageUri.equals(mSelectedImageUri)) {
+ if (mOriginalImageUri != null
+ && !mOriginalImageUri.equals(mSelectedImageUri)) {
mOriginalImageUri = mSelectedImageUri;
mOriginalPreset = null;
Toast.makeText(FilterShowActivity.this,
@@ -764,14 +840,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
Log.v(LOGTAG,"RenderScript context destroyed during load");
return;
}
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.GONE);
final View imageShow = findViewById(R.id.imageShow);
imageShow.setVisibility(View.VISIBLE);
+
Bitmap largeBitmap = MasterImage.getImage().getOriginalBitmapLarge();
mBoundService.setOriginalBitmap(largeBitmap);
- MasterImage.getImage().resetGeometryImages(true);
float previewScale = (float) largeBitmap.getWidth()
/ (float) MasterImage.getImage().getOriginalBounds().width();
@@ -785,13 +859,20 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mCategoryFiltersAdapter.imageLoaded();
mLoadBitmapTask = null;
+ MasterImage.getImage().warnListeners();
+ loadActions();
+
if (mOriginalPreset != null) {
MasterImage.getImage().setLoadedPreset(mOriginalPreset);
MasterImage.getImage().setPreset(mOriginalPreset,
mOriginalPreset.getLastRepresentation(), true);
mOriginalPreset = null;
+ } else {
+ setDefaultPreset();
}
+ MasterImage.getImage().resetGeometryImages(true);
+
if (mAction == TINY_PLANET_ACTION) {
showRepresentation(mCategoryFiltersAdapter.getTinyPlanet());
}
@@ -916,12 +997,23 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
.getActionProvider();
mShareActionProvider.setShareIntent(getDefaultShareIntent());
mShareActionProvider.setOnShareTargetSelectedListener(this);
+ mMenu = menu;
+ setupMenu();
+ return true;
+ }
- MenuItem undoItem = menu.findItem(R.id.undoButton);
- MenuItem redoItem = menu.findItem(R.id.redoButton);
- MenuItem resetItem = menu.findItem(R.id.resetHistoryButton);
+ private void setupMenu(){
+ if (mMenu == null || mMasterImage == null) {
+ return;
+ }
+ MenuItem undoItem = mMenu.findItem(R.id.undoButton);
+ MenuItem redoItem = mMenu.findItem(R.id.redoButton);
+ MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton);
+ MenuItem printItem = mMenu.findItem(R.id.printButton);
+ if (!PrintHelper.systemSupportsPrint()) {
+ printItem.setVisible(false);
+ }
mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem);
- return true;
}
@Override
@@ -949,8 +1041,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mMasterImage.onHistoryItemClick(position);
backToMain();
invalidateViews();
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_BUTTON_PRESS, "Undo");
return true;
}
case R.id.redoButton: {
@@ -958,21 +1048,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
int position = adapter.redo();
mMasterImage.onHistoryItemClick(position);
invalidateViews();
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_BUTTON_PRESS, "Redo");
return true;
}
case R.id.resetHistoryButton: {
resetHistory();
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_BUTTON_PRESS, "ResetHistory");
return true;
}
case R.id.showImageStateButton: {
toggleImageStatePanel();
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_BUTTON_PRESS,
- mShowingImageStatePanel ? "ShowPanel" : "HidePanel");
return true;
}
case R.id.exportFlattenButton: {
@@ -1001,7 +1084,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
public void print() {
Bitmap bitmap = MasterImage.getImage().getHighresImage();
- PrintJob.printBitmap(this, "ImagePrint", bitmap);
+ PrintHelper printer = new PrintHelper(this);
+ printer.printBitmap("ImagePrint", bitmap);
}
public void addNewPreset() {
@@ -1087,6 +1171,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
FiltersManager filtersManager = FiltersManager.getManager();
ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getLooks();
+ if (mCategoryLooksAdapter != null) {
+ mCategoryLooksAdapter.clear();
+ }
mCategoryLooksAdapter = new CategoryAdapter(this);
int verticalItemHeight = (int) getResources().getDimension(R.dimen.action_item_height);
mCategoryLooksAdapter.setItemHeight(verticalItemHeight);
@@ -1161,17 +1248,28 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
+
setDefaultValues();
+ if (mMasterImage == null) {
+ return;
+ }
loadXML();
fillCategories();
loadMainPanel();
+ if (mCurrentMenu != null) {
+ mCurrentMenu.dismiss();
+ mCurrentMenu = null;
+ }
+ if (mCurrentDialog != null) {
+ mCurrentDialog.dismiss();
+ mCurrentDialog = null;
+ }
// mLoadBitmapTask==null implies you have looked at the intent
if (!mShowingTinyPlanet && (mLoadBitmapTask == null)) {
mCategoryFiltersAdapter.removeTinyPlanet();
}
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.GONE);
+ stopLoadingIndicator();
}
public void setupMasterImage() {
@@ -1195,14 +1293,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
HistoryManager adapter = mMasterImage.getHistory();
adapter.reset();
HistoryItem historyItem = adapter.getItem(0);
- ImagePreset original = new ImagePreset(historyItem.getImagePreset());
- mMasterImage.setPreset(original, historyItem.getFilterRepresentation(), true);
+ ImagePreset original = null;
+ if (RESET_TO_LOADED) {
+ original = new ImagePreset(historyItem.getImagePreset());
+ } else {
+ original = new ImagePreset();
+ }
+ FilterRepresentation rep = null;
+ if (historyItem != null) {
+ rep = historyItem.getFilterRepresentation();
+ }
+ mMasterImage.setPreset(original, rep, true);
invalidateViews();
backToMain();
}
public void showDefaultImageView() {
- hideInformationPanel();
mEditorPlaceHolder.hide();
mImageShow.setVisibility(View.VISIBLE);
MasterImage.getImage().setCurrentFilter(null);
@@ -1374,11 +1480,23 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
return super.dispatchTouchEvent(ev);
}
+ public Point mHintTouchPoint = new Point();
+
+ public Point hintTouchPoint(View view) {
+ int location[] = new int[2];
+ view.getLocationOnScreen(location);
+ int x = mHintTouchPoint.x - location[0];
+ int y = mHintTouchPoint.y - location[1];
+ return new Point(x, y);
+ }
+
public void startTouchAnimation(View target, float x, float y) {
final CategorySelected hint =
(CategorySelected) findViewById(R.id.categorySelectedIndicator);
int location[] = new int[2];
target.getLocationOnScreen(location);
+ mHintTouchPoint.x = (int) (location[0] + x);
+ mHintTouchPoint.y = (int) (location[1] + y);
int locationHint[] = new int[2];
((View)hint.getParent()).getLocationOnScreen(locationHint);
int dx = (int) (x - (hint.getWidth())/2);