summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow')
-rw-r--r--src/com/android/gallery3d/filtershow/CenteredLinearLayout.java51
-rw-r--r--src/com/android/gallery3d/filtershow/EditorPlaceHolder.java82
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java1121
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java502
-rw-r--r--src/com/android/gallery3d/filtershow/category/Action.java186
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryAdapter.java182
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryPanel.java108
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryTrack.java77
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryView.java176
-rw-r--r--src/com/android/gallery3d/filtershow/category/MainPanel.java239
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorGridDialog.java100
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorListener.java21
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorOpacityView.java197
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorPickerDialog.java123
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorRectView.java225
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java180
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/RGBListener.java21
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ActionSlider.java71
-rw-r--r--src/com/android/gallery3d/filtershow/controller/BasicParameterInt.java113
-rw-r--r--src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java111
-rw-r--r--src/com/android/gallery3d/filtershow/controller/BasicSlider.java87
-rw-r--r--src/com/android/gallery3d/filtershow/controller/Control.java32
-rw-r--r--src/com/android/gallery3d/filtershow/controller/FilterView.java25
-rw-r--r--src/com/android/gallery3d/filtershow/controller/Parameter.java33
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java29
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterInteger.java31
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterSet.java23
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterStyles.java37
-rw-r--r--src/com/android/gallery3d/filtershow/controller/StyleChooser.java88
-rw-r--r--src/com/android/gallery3d/filtershow/controller/TitledSlider.java106
-rw-r--r--src/com/android/gallery3d/filtershow/crop/BoundedRect.java368
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropActivity.java697
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java168
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropExtras.java121
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropMath.java260
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropObject.java330
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropView.java378
-rw-r--r--src/com/android/gallery3d/filtershow/data/FilterStackDBHelper.java101
-rw-r--r--src/com/android/gallery3d/filtershow/data/FilterStackSource.java197
-rw-r--r--src/com/android/gallery3d/filtershow/data/UserPresetsManager.java149
-rw-r--r--src/com/android/gallery3d/filtershow/editors/BasicEditor.java138
-rw-r--r--src/com/android/gallery3d/filtershow/editors/Editor.java330
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorChanSat.java227
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorCrop.java168
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorCurves.java56
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorDraw.java158
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorGrad.java315
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorInfo.java23
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorMirror.java109
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorPanel.java143
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorRedEye.java65
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorRotate.java112
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorStraighten.java103
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java58
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorVignette.java53
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorZoom.java27
-rw-r--r--src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java50
-rw-r--r--src/com/android/gallery3d/filtershow/editors/ParametricEditor.java206
-rw-r--r--src/com/android/gallery3d/filtershow/editors/SwapButton.java111
-rw-r--r--src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java296
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ColorSpaceMatrix.java225
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java196
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java211
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java113
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java179
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java170
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java38
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java171
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java112
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java497
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java91
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java190
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterPoint.java21
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java88
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java67
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java262
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java190
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java154
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java101
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterUserPresetRepresentation.java53
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java173
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FiltersManagerInterface.java21
-rw-r--r--src/com/android/gallery3d/filtershow/filters/IconUtilities.java75
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilter.java109
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java92
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java64
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java161
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java58
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java112
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java83
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java278
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java53
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java56
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java111
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java190
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterHighlights.java74
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java64
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java95
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java39
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java69
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java260
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java79
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java58
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java58
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java107
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java158
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java57
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java98
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java59
-rw-r--r--src/com/android/gallery3d/filtershow/filters/RedEyeCandidate.java50
-rw-r--r--src/com/android/gallery3d/filtershow/filters/SimpleImageFilter.java37
-rw-r--r--src/com/android/gallery3d/filtershow/filters/SplineMath.java166
-rw-r--r--src/com/android/gallery3d/filtershow/filters/convolve3x3.rs67
-rw-r--r--src/com/android/gallery3d/filtershow/filters/grad.rs121
-rw-r--r--src/com/android/gallery3d/filtershow/filters/grey.rs22
-rw-r--r--src/com/android/gallery3d/filtershow/filters/saturation.rs161
-rw-r--r--src/com/android/gallery3d/filtershow/history/HistoryItem.java53
-rw-r--r--src/com/android/gallery3d/filtershow/history/HistoryManager.java172
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java64
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/EclipseControl.java302
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java416
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/GradControl.java274
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java307
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageCurves.java445
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java139
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageGrad.java215
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageMirror.java78
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImagePoint.java89
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageRedEye.java137
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java81
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageShow.java578
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java260
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageTinyPlanet.java174
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageVignette.java165
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/Line.java26
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/MasterImage.java581
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/Oval.java29
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/Spline.java450
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/Buffer.java74
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java193
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java469
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java178
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/HighresRenderingRequestTask.java90
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java694
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java125
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/PipelineInterface.java31
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java283
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ProcessingTask.java88
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ProcessingTaskController.java97
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/RenderingRequest.java174
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/RenderingRequestCaller.java21
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/RenderingRequestTask.java81
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java77
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/SharedPreset.java42
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/UpdatePreviewTask.java79
-rw-r--r--src/com/android/gallery3d/filtershow/presets/PresetManagementDialog.java69
-rw-r--r--src/com/android/gallery3d/filtershow/presets/UserPresetsAdapter.java171
-rw-r--r--src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java137
-rw-r--r--src/com/android/gallery3d/filtershow/state/DragListener.java110
-rw-r--r--src/com/android/gallery3d/filtershow/state/PanelTrack.java37
-rw-r--r--src/com/android/gallery3d/filtershow/state/State.java78
-rw-r--r--src/com/android/gallery3d/filtershow/state/StateAdapter.java115
-rw-r--r--src/com/android/gallery3d/filtershow/state/StatePanel.java44
-rw-r--r--src/com/android/gallery3d/filtershow/state/StatePanelTrack.java351
-rw-r--r--src/com/android/gallery3d/filtershow/state/StateView.java291
-rw-r--r--src/com/android/gallery3d/filtershow/tools/IconFactory.java108
-rw-r--r--src/com/android/gallery3d/filtershow/tools/MatrixFit.java200
-rw-r--r--src/com/android/gallery3d/filtershow/tools/SaveImage.java632
-rw-r--r--src/com/android/gallery3d/filtershow/tools/XmpPresets.java133
-rw-r--r--src/com/android/gallery3d/filtershow/ui/ExportDialog.java90
-rw-r--r--src/com/android/gallery3d/filtershow/ui/FramedTextButton.java137
-rw-r--r--src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java48
172 files changed, 0 insertions, 27140 deletions
diff --git a/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java b/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java
deleted file mode 100644
index bc9342d6f..000000000
--- a/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.widget.LinearLayout;
-
-import com.android.gallery3d.R;
-
-public class CenteredLinearLayout extends LinearLayout {
- private final int mMaxWidth;
-
- public CenteredLinearLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CenteredLinearLayout);
- mMaxWidth = a.getDimensionPixelSize(R.styleable.CenteredLinearLayout_max_width, 0);
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
- int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
- Resources r = getContext().getResources();
- float value = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, parentWidth,
- r.getDisplayMetrics());
- if (mMaxWidth > 0 && parentWidth > mMaxWidth) {
- int measureMode = MeasureSpec.getMode(widthMeasureSpec);
- widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode);
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java b/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java
deleted file mode 100644
index 95abce114..000000000
--- a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.android.gallery3d.filtershow;
-
-import android.view.View;
-import android.view.ViewParent;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.filtershow.cache.ImageLoader;
-import com.android.gallery3d.filtershow.editors.Editor;
-import com.android.gallery3d.filtershow.imageshow.ImageShow;
-
-import java.util.HashMap;
-import java.util.Vector;
-
-public class EditorPlaceHolder {
- private static final String LOGTAG = "EditorPlaceHolder";
-
- private FilterShowActivity mActivity = null;
- private FrameLayout mContainer = null;
- private HashMap<Integer, Editor> mEditors = new HashMap<Integer, Editor>();
- private Vector<ImageShow> mOldViews = new Vector<ImageShow>();
-
- public EditorPlaceHolder(FilterShowActivity activity) {
- mActivity = activity;
- }
-
- public void setContainer(FrameLayout container) {
- mContainer = container;
- }
-
- public void addEditor(Editor c) {
- mEditors.put(c.getID(), c);
- }
-
- public boolean contains(int type) {
- if (mEditors.get(type) != null) {
- return true;
- }
- return false;
- }
-
- public Editor showEditor(int type) {
- Editor editor = mEditors.get(type);
- if (editor == null) {
- return null;
- }
-
- editor.createEditor(mActivity, mContainer);
- editor.getImageShow().bindAsImageLoadListener();
- mContainer.setVisibility(View.VISIBLE);
- mContainer.removeAllViews();
- View eview = editor.getTopLevelView();
- ViewParent parent = eview.getParent();
-
- if (parent != null && parent instanceof FrameLayout) {
- ((FrameLayout) parent).removeAllViews();
- }
-
- mContainer.addView(eview);
- hideOldViews();
- editor.setVisibility(View.VISIBLE);
- return editor;
- }
-
- public void setOldViews(Vector<ImageShow> views) {
- mOldViews = views;
- }
-
- public void hide() {
- mContainer.setVisibility(View.GONE);
- }
-
- public void hideOldViews() {
- for (View view : mOldViews) {
- view.setVisibility(View.GONE);
- }
- }
-
- public Editor getEditor(int editorId) {
- return mEditors.get(editorId);
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
deleted file mode 100644
index 4700fccfe..000000000
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ /dev/null
@@ -1,1121 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow;
-
-import android.app.ActionBar;
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.ComponentName;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.content.pm.ActivityInfo;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-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.util.DisplayMetrics;
-import android.util.Log;
-import android.util.TypedValue;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewPropertyAnimator;
-import android.view.WindowManager;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.FrameLayout;
-import android.widget.ShareActionProvider;
-import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
-import android.widget.Toast;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.app.PhotoPage;
-import com.android.gallery3d.data.LocalAlbum;
-import com.android.gallery3d.filtershow.cache.ImageLoader;
-import com.android.gallery3d.filtershow.category.Action;
-import com.android.gallery3d.filtershow.category.CategoryAdapter;
-import com.android.gallery3d.filtershow.category.MainPanel;
-import com.android.gallery3d.filtershow.data.UserPresetsManager;
-import com.android.gallery3d.filtershow.editors.BasicEditor;
-import com.android.gallery3d.filtershow.editors.Editor;
-import com.android.gallery3d.filtershow.editors.EditorChanSat;
-import com.android.gallery3d.filtershow.editors.EditorCrop;
-import com.android.gallery3d.filtershow.editors.EditorDraw;
-import com.android.gallery3d.filtershow.editors.EditorGrad;
-import com.android.gallery3d.filtershow.editors.EditorManager;
-import com.android.gallery3d.filtershow.editors.EditorMirror;
-import com.android.gallery3d.filtershow.editors.EditorPanel;
-import com.android.gallery3d.filtershow.editors.EditorRedEye;
-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.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
-import com.android.gallery3d.filtershow.filters.FiltersManager;
-import com.android.gallery3d.filtershow.filters.ImageFilter;
-import com.android.gallery3d.filtershow.history.HistoryItem;
-import com.android.gallery3d.filtershow.history.HistoryManager;
-import com.android.gallery3d.filtershow.imageshow.ImageShow;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.imageshow.Spline;
-import com.android.gallery3d.filtershow.pipeline.CachingPipeline;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-import com.android.gallery3d.filtershow.pipeline.ProcessingService;
-import com.android.gallery3d.filtershow.presets.PresetManagementDialog;
-import com.android.gallery3d.filtershow.presets.UserPresetsAdapter;
-import com.android.gallery3d.filtershow.provider.SharedImageProvider;
-import com.android.gallery3d.filtershow.state.StateAdapter;
-import com.android.gallery3d.filtershow.tools.SaveImage;
-import com.android.gallery3d.filtershow.tools.XmpPresets;
-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.UsageStatistics;
-import com.android.photos.data.GalleryBitmapPool;
-
-import java.io.File;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Vector;
-
-public class FilterShowActivity extends FragmentActivity implements OnItemClickListener,
- OnShareTargetSelectedListener {
-
- private String mAction = "";
- MasterImage mMasterImage = null;
-
- private static final long LIMIT_SUPPORTS_HIGHRES = 134217728; // 128Mb
-
- public static final String TINY_PLANET_ACTION = "com.android.camera.action.TINY_PLANET";
- public static final String LAUNCH_FULLSCREEN = "launch-fullscreen";
- private ImageShow mImageShow = null;
-
- private View mSaveButton = null;
-
- private EditorPlaceHolder mEditorPlaceHolder = new EditorPlaceHolder(this);
-
- private static final int SELECT_PICTURE = 1;
- private static final String LOGTAG = "FilterShowActivity";
-
- private boolean mShowingTinyPlanet = false;
- private boolean mShowingImageStatePanel = false;
-
- private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
-
- private ShareActionProvider mShareActionProvider;
- private File mSharedOutputFile = null;
-
- private boolean mSharingImage = false;
-
- private WeakReference<ProgressDialog> mSavingProgressDialog;
-
- private LoadBitmapTask mLoadBitmapTask;
-
- private Uri mOriginalImageUri = null;
- private ImagePreset mOriginalPreset = null;
-
- private Uri mSelectedImageUri = null;
-
- private UserPresetsManager mUserPresetsManager = null;
- private UserPresetsAdapter mUserPresetsAdapter = null;
- private CategoryAdapter mCategoryLooksAdapter = null;
- private CategoryAdapter mCategoryBordersAdapter = null;
- private CategoryAdapter mCategoryGeometryAdapter = null;
- private CategoryAdapter mCategoryFiltersAdapter = null;
- private int mCurrentPanel = MainPanel.LOOKS;
-
- private ProcessingService mBoundService;
- private boolean mIsBound = false;
-
- public ProcessingService getProcessingService() {
- return mBoundService;
- }
-
- public boolean isSimpleEditAction() {
- return !PhotoPage.ACTION_NEXTGEN_EDIT.equalsIgnoreCase(mAction);
- }
-
- private ServiceConnection mConnection = new ServiceConnection() {
- public void onServiceConnected(ComponentName className, IBinder service) {
- /*
- * This is called when the connection with the service has been
- * established, giving us the service object we can use to
- * interact with the service. Because we have bound to a explicit
- * service that we know is running in our own process, we can
- * cast its IBinder to a concrete class and directly access it.
- */
- mBoundService = ((ProcessingService.LocalBinder)service).getService();
- mBoundService.setFiltershowActivity(FilterShowActivity.this);
- mBoundService.onStart();
- }
-
- public void onServiceDisconnected(ComponentName className) {
- /*
- * This is called when the connection with the service has been
- * unexpectedly disconnected -- that is, its process crashed.
- * Because it is running in our same process, we should never
- * see this happen.
- */
- mBoundService = null;
- }
- };
-
- void doBindService() {
- /*
- * Establish a connection with the service. We use an explicit
- * class name because we want a specific service implementation that
- * we know will be running in our own process (and thus won't be
- * supporting component replacement by other applications).
- */
- bindService(new Intent(FilterShowActivity.this, ProcessingService.class),
- mConnection, Context.BIND_AUTO_CREATE);
- mIsBound = true;
- }
-
- void doUnbindService() {
- if (mIsBound) {
- // Detach our existing connection.
- unbindService(mConnection);
- mIsBound = false;
- }
- }
-
- private void setupPipeline() {
- doBindService();
- ImageFilter.setActivityForMemoryToasts(this);
- mUserPresetsManager = new UserPresetsManager(this);
- mUserPresetsAdapter = new UserPresetsAdapter(this);
- mCategoryLooksAdapter = new CategoryAdapter(this);
- }
-
- public void updateUIAfterServiceStarted() {
- fillCategories();
- loadMainPanel();
- setDefaultPreset();
- extractXMPData();
- processIntent();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- boolean onlyUsePortrait = getResources().getBoolean(R.bool.only_use_portrait);
- 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);
- }
-
- public boolean isShowingImageStatePanel() {
- return mShowingImageStatePanel;
- }
-
- public void loadMainPanel() {
- if (findViewById(R.id.main_panel_container) == null) {
- return;
- }
- MainPanel panel = new MainPanel();
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.main_panel_container, panel, MainPanel.FRAGMENT_TAG);
- transaction.commit();
- }
-
- public void loadEditorPanel(FilterRepresentation representation,
- final Editor currentEditor) {
- if (representation.getEditorId() == ImageOnlyEditor.ID) {
- currentEditor.reflectCurrentFilter();
- return;
- }
- 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();
- ViewPropertyAnimator anim = mainPanel.getView().animate();
- anim.translationY(panelHeight).start();
- final Handler handler = new Handler();
- handler.postDelayed(showEditor, anim.getDuration());
- } else {
- showEditor.run();
- }
- }
-
- private void loadXML() {
- setContentView(R.layout.filtershow_activity);
-
- ActionBar actionBar = getActionBar();
- actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
- actionBar.setCustomView(R.layout.filtershow_actionbar);
-
- mSaveButton = actionBar.getCustomView();
- mSaveButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- saveImage();
- }
- });
-
- mImageShow = (ImageShow) findViewById(R.id.imageShow);
- mImageViews.add(mImageShow);
-
- setupEditors();
-
- mEditorPlaceHolder.hide();
- mImageShow.bindAsImageLoadListener();
-
- setupStatePanel();
- }
-
- public void fillCategories() {
- fillLooks();
- loadUserPresets();
- fillBorders();
- fillTools();
- fillEffects();
- }
-
- public void setupStatePanel() {
- MasterImage.getImage().setHistoryManager(mMasterImage.getHistory());
- }
-
- private void fillEffects() {
- FiltersManager filtersManager = FiltersManager.getManager();
- ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getEffects();
- mCategoryFiltersAdapter = new CategoryAdapter(this);
- for (FilterRepresentation representation : filtersRepresentations) {
- if (representation.getTextId() != 0) {
- representation.setName(getString(representation.getTextId()));
- }
- mCategoryFiltersAdapter.add(new Action(this, representation));
- }
- }
-
- private void fillTools() {
- FiltersManager filtersManager = FiltersManager.getManager();
- ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools();
- mCategoryGeometryAdapter = new CategoryAdapter(this);
- for (FilterRepresentation representation : filtersRepresentations) {
- mCategoryGeometryAdapter.add(new Action(this, representation));
- }
- }
-
- private void processIntent() {
- Intent intent = getIntent();
- if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) {
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- }
-
- mAction = intent.getAction();
- mSelectedImageUri = intent.getData();
- Uri loadUri = mSelectedImageUri;
- if (mOriginalImageUri != null) {
- loadUri = mOriginalImageUri;
- }
- if (loadUri != null) {
- startLoadBitmap(loadUri);
- } else {
- pickImage();
- }
- }
-
- private void setupEditors() {
- mEditorPlaceHolder.setContainer((FrameLayout) findViewById(R.id.editorContainer));
- EditorManager.addEditors(mEditorPlaceHolder);
- mEditorPlaceHolder.setOldViews(mImageViews);
- }
-
- private void fillEditors() {
- mEditorPlaceHolder.addEditor(new EditorChanSat());
- mEditorPlaceHolder.addEditor(new EditorGrad());
- mEditorPlaceHolder.addEditor(new EditorDraw());
- mEditorPlaceHolder.addEditor(new BasicEditor());
- mEditorPlaceHolder.addEditor(new ImageOnlyEditor());
- mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
- mEditorPlaceHolder.addEditor(new EditorRedEye());
- mEditorPlaceHolder.addEditor(new EditorCrop());
- mEditorPlaceHolder.addEditor(new EditorMirror());
- mEditorPlaceHolder.addEditor(new EditorRotate());
- mEditorPlaceHolder.addEditor(new EditorStraighten());
- }
-
- private void setDefaultValues() {
- Resources res = getResources();
-
- // TODO: get those values from XML.
- FramedTextButton.setTextSize((int) getPixelsFromDip(14));
- FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4));
- FramedTextButton.setTriangleSize((int) getPixelsFromDip(10));
-
- Drawable curveHandle = res.getDrawable(R.drawable.camera_crop);
- int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size);
- Spline.setCurveHandle(curveHandle, curveHandleSize);
- Spline.setCurveWidth((int) getPixelsFromDip(3));
- }
-
- 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);
- mShowingTinyPlanet = false;
- mLoadBitmapTask = new LoadBitmapTask();
- mLoadBitmapTask.execute(uri);
- }
-
- private void fillBorders() {
- FiltersManager filtersManager = FiltersManager.getManager();
- ArrayList<FilterRepresentation> borders = filtersManager.getBorders();
-
- for (int i = 0; i < borders.size(); i++) {
- FilterRepresentation filter = borders.get(i);
- filter.setName(getString(R.string.borders));
- if (i == 0) {
- filter.setName(getString(R.string.none));
- }
- }
-
- mCategoryBordersAdapter = new CategoryAdapter(this);
- for (FilterRepresentation representation : borders) {
- if (representation.getTextId() != 0) {
- representation.setName(getString(representation.getTextId()));
- }
- mCategoryBordersAdapter.add(new Action(this, representation, Action.FULL_VIEW));
- }
- }
-
- public UserPresetsAdapter getUserPresetsAdapter() {
- return mUserPresetsAdapter;
- }
-
- public CategoryAdapter getCategoryLooksAdapter() {
- return mCategoryLooksAdapter;
- }
-
- public CategoryAdapter getCategoryBordersAdapter() {
- return mCategoryBordersAdapter;
- }
-
- public CategoryAdapter getCategoryGeometryAdapter() {
- return mCategoryGeometryAdapter;
- }
-
- public CategoryAdapter getCategoryFiltersAdapter() {
- return mCategoryFiltersAdapter;
- }
-
- public void removeFilterRepresentation(FilterRepresentation filterRepresentation) {
- if (filterRepresentation == null) {
- return;
- }
- ImagePreset oldPreset = MasterImage.getImage().getPreset();
- ImagePreset copy = new ImagePreset(oldPreset);
- copy.removeFilter(filterRepresentation);
- MasterImage.getImage().setPreset(copy, copy.getLastRepresentation(), true);
- if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
- FilterRepresentation lastRepresentation = copy.getLastRepresentation();
- MasterImage.getImage().setCurrentFilterRepresentation(lastRepresentation);
- }
- }
-
- public void useFilterRepresentation(FilterRepresentation filterRepresentation) {
- if (filterRepresentation == null) {
- return;
- }
- if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
- return;
- }
- ImagePreset oldPreset = MasterImage.getImage().getPreset();
- ImagePreset copy = new ImagePreset(oldPreset);
- FilterRepresentation representation = copy.getRepresentation(filterRepresentation);
- if (representation == null) {
- copy.addFilter(filterRepresentation);
- } else if (filterRepresentation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
- filterRepresentation = representation;
- } else {
- if (filterRepresentation.allowsSingleInstanceOnly()) {
- // Don't just update the filter representation. Centralize the
- // logic in the addFilter(), such that we can keep "None" as
- // null.
- copy.removeFilter(representation);
- copy.addFilter(filterRepresentation);
- }
- }
- MasterImage.getImage().setPreset(copy, filterRepresentation, true);
- MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation);
- }
-
- public void showRepresentation(FilterRepresentation representation) {
- if (representation == null) {
- return;
- }
-
- useFilterRepresentation(representation);
-
- // show representation
- Editor mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
- loadEditorPanel(representation, mCurrentEditor);
- }
-
- public Editor getEditor(int editorID) {
- return mEditorPlaceHolder.getEditor(editorID);
- }
-
- public void setCurrentPanel(int currentPanel) {
- mCurrentPanel = currentPanel;
- }
-
- public int getCurrentPanel() {
- return mCurrentPanel;
- }
-
- public void updateCategories() {
- ImagePreset preset = mMasterImage.getPreset();
- mCategoryLooksAdapter.reflectImagePreset(preset);
- mCategoryBordersAdapter.reflectImagePreset(preset);
- }
-
- private class LoadHighresBitmapTask extends AsyncTask<Void, Void, Boolean> {
- @Override
- protected Boolean doInBackground(Void... params) {
- MasterImage master = MasterImage.getImage();
- Rect originalBounds = master.getOriginalBounds();
- if (master.supportsHighRes()) {
- int highresPreviewSize = master.getOriginalBitmapLarge().getWidth() * 2;
- if (highresPreviewSize > originalBounds.width()) {
- highresPreviewSize = originalBounds.width();
- }
- Rect bounds = new Rect();
- Bitmap originalHires = ImageLoader.loadOrientedConstrainedBitmap(master.getUri(),
- master.getActivity(), highresPreviewSize,
- master.getOrientation(), bounds);
- master.setOriginalBounds(bounds);
- master.setOriginalBitmapHighres(originalHires);
- mBoundService.setOriginalBitmapHighres(originalHires);
- master.warnListeners();
- }
- return true;
- }
-
- @Override
- protected void onPostExecute(Boolean result) {
- Bitmap highresBitmap = MasterImage.getImage().getOriginalBitmapHighres();
- if (highresBitmap != null) {
- float highResPreviewScale = (float) highresBitmap.getWidth()
- / (float) MasterImage.getImage().getOriginalBounds().width();
- mBoundService.setHighresPreviewScaleFactor(highResPreviewScale);
- }
- }
- }
-
- private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
- int mBitmapSize;
-
- public LoadBitmapTask() {
- mBitmapSize = getScreenImageSize();
- }
-
- @Override
- protected Boolean doInBackground(Uri... params) {
- if (!MasterImage.getImage().loadBitmap(params[0], mBitmapSize)) {
- return false;
- }
- publishProgress(ImageLoader.queryLightCycle360(MasterImage.getImage().getActivity()));
- return true;
- }
-
- @Override
- protected void onProgressUpdate(Boolean... values) {
- super.onProgressUpdate(values);
- if (isCancelled()) {
- return;
- }
- if (values[0]) {
- mShowingTinyPlanet = true;
- }
- }
-
- @Override
- protected void onPostExecute(Boolean result) {
- MasterImage.setMaster(mMasterImage);
- if (isCancelled()) {
- return;
- }
-
- if (!result) {
- cannotLoadImage();
- }
-
- if (null == CachingPipeline.getRenderScriptContext()){
- 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);
-
- float previewScale = (float) largeBitmap.getWidth()
- / (float) MasterImage.getImage().getOriginalBounds().width();
- mBoundService.setPreviewScaleFactor(previewScale);
- if (!mShowingTinyPlanet) {
- mCategoryFiltersAdapter.removeTinyPlanet();
- }
- mCategoryLooksAdapter.imageLoaded();
- mCategoryBordersAdapter.imageLoaded();
- mCategoryGeometryAdapter.imageLoaded();
- mCategoryFiltersAdapter.imageLoaded();
- mLoadBitmapTask = null;
-
- if (mOriginalPreset != null) {
- MasterImage.getImage().setLoadedPreset(mOriginalPreset);
- MasterImage.getImage().setPreset(mOriginalPreset,
- mOriginalPreset.getLastRepresentation(), true);
- mOriginalPreset = null;
- }
-
- if (mAction == TINY_PLANET_ACTION) {
- showRepresentation(mCategoryFiltersAdapter.getTinyPlanet());
- }
- LoadHighresBitmapTask highresLoad = new LoadHighresBitmapTask();
- highresLoad.execute();
- super.onPostExecute(result);
- }
-
- }
-
- private void clearGalleryBitmapPool() {
- (new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- // Free memory held in Gallery's Bitmap pool. May be O(n) for n bitmaps.
- GalleryBitmapPool.getInstance().clear();
- return null;
- }
- }).execute();
- }
-
- @Override
- protected void onDestroy() {
- if (mLoadBitmapTask != null) {
- mLoadBitmapTask.cancel(false);
- }
- mUserPresetsManager.close();
- doUnbindService();
- super.onDestroy();
- }
-
- // TODO: find a more robust way of handling image size selection
- // for high screen densities.
- private int getScreenImageSize() {
- DisplayMetrics outMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
- return (int) Math.max(outMetrics.heightPixels, outMetrics.widthPixels);
- }
-
- private void showSavingProgress(String albumName) {
- ProgressDialog progress;
- if (mSavingProgressDialog != null) {
- progress = mSavingProgressDialog.get();
- if (progress != null) {
- progress.show();
- return;
- }
- }
- // TODO: Allow cancellation of the saving process
- String progressText;
- if (albumName == null) {
- progressText = getString(R.string.saving_image);
- } else {
- progressText = getString(R.string.filtershow_saving_image, albumName);
- }
- progress = ProgressDialog.show(this, "", progressText, true, false);
- mSavingProgressDialog = new WeakReference<ProgressDialog>(progress);
- }
-
- private void hideSavingProgress() {
- if (mSavingProgressDialog != null) {
- ProgressDialog progress = mSavingProgressDialog.get();
- if (progress != null)
- progress.dismiss();
- }
- }
-
- public void completeSaveImage(Uri saveUri) {
- if (mSharingImage && mSharedOutputFile != null) {
- // Image saved, we unblock the content provider
- Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
- Uri.encode(mSharedOutputFile.getAbsolutePath()));
- ContentValues values = new ContentValues();
- values.put(SharedImageProvider.PREPARE, false);
- getContentResolver().insert(uri, values);
- }
- setResult(RESULT_OK, new Intent().setData(saveUri));
- hideSavingProgress();
- finish();
- }
-
- @Override
- public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) {
- // First, let's tell the SharedImageProvider that it will need to wait
- // for the image
- Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
- Uri.encode(mSharedOutputFile.getAbsolutePath()));
- ContentValues values = new ContentValues();
- values.put(SharedImageProvider.PREPARE, true);
- getContentResolver().insert(uri, values);
- mSharingImage = true;
-
- // Process and save the image in the background.
- showSavingProgress(null);
- mImageShow.saveImage(this, mSharedOutputFile);
- return true;
- }
-
- private Intent getDefaultShareIntent() {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.setType(SharedImageProvider.MIME_TYPE);
- mSharedOutputFile = SaveImage.getNewFile(this, MasterImage.getImage().getUri());
- Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
- Uri.encode(mSharedOutputFile.getAbsolutePath()));
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- return intent;
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
- MenuItem showState = menu.findItem(R.id.showImageStateButton);
- if (mShowingImageStatePanel) {
- showState.setTitle(R.string.hide_imagestate_panel);
- } else {
- showState.setTitle(R.string.show_imagestate_panel);
- }
- mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
- .getActionProvider();
- mShareActionProvider.setShareIntent(getDefaultShareIntent());
- mShareActionProvider.setOnShareTargetSelectedListener(this);
-
- MenuItem undoItem = menu.findItem(R.id.undoButton);
- MenuItem redoItem = menu.findItem(R.id.redoButton);
- MenuItem resetItem = menu.findItem(R.id.resetHistoryButton);
- mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem);
- return true;
- }
-
- @Override
- public void onPause() {
- super.onPause();
- if (mShareActionProvider != null) {
- mShareActionProvider.setOnShareTargetSelectedListener(null);
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mShareActionProvider != null) {
- mShareActionProvider.setOnShareTargetSelectedListener(this);
- }
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.undoButton: {
- HistoryManager adapter = mMasterImage.getHistory();
- int position = adapter.undo();
- mMasterImage.onHistoryItemClick(position);
- backToMain();
- invalidateViews();
- UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
- UsageStatistics.CATEGORY_BUTTON_PRESS, "Undo");
- return true;
- }
- case R.id.redoButton: {
- HistoryManager adapter = mMasterImage.getHistory();
- 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: {
- showExportOptionsDialog();
- return true;
- }
- case android.R.id.home: {
- saveImage();
- return true;
- }
- case R.id.manageUserPresets: {
- manageUserPresets();
- return true;
- }
- }
- return false;
- }
-
- private void manageUserPresets() {
- DialogFragment dialog = new PresetManagementDialog();
- dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
- }
-
- private void showExportOptionsDialog() {
- DialogFragment dialog = new ExportDialog();
- dialog.show(getSupportFragmentManager(), "ExportDialogFragment");
- }
-
- public void updateUserPresetsFromAdapter(UserPresetsAdapter adapter) {
- ArrayList<FilterUserPresetRepresentation> representations =
- adapter.getDeletedRepresentations();
- for (FilterUserPresetRepresentation representation : representations) {
- deletePreset(representation.getId());
- }
- ArrayList<FilterUserPresetRepresentation> changedRepresentations =
- adapter.getChangedRepresentations();
- for (FilterUserPresetRepresentation representation : changedRepresentations) {
- updatePreset(representation);
- }
- adapter.clearDeletedRepresentations();
- adapter.clearChangedRepresentations();
- loadUserPresets();
- }
-
- public void loadUserPresets() {
- mUserPresetsManager.load();
- }
-
- public void updateUserPresetsFromManager() {
- ArrayList<FilterUserPresetRepresentation> presets = mUserPresetsManager.getRepresentations();
- if (presets == null) {
- return;
- }
- if (mCategoryLooksAdapter != null) {
- fillLooks();
- }
- mUserPresetsAdapter.clear();
- for (int i = 0; i < presets.size(); i++) {
- FilterUserPresetRepresentation representation = presets.get(i);
- mCategoryLooksAdapter.add(
- new Action(this, representation, Action.FULL_VIEW));
- mUserPresetsAdapter.add(new Action(this, representation, Action.FULL_VIEW));
- }
- mCategoryLooksAdapter.notifyDataSetInvalidated();
-
- }
-
- public void saveCurrentImagePreset() {
- mUserPresetsManager.save(MasterImage.getImage().getPreset());
- }
-
- private void deletePreset(int id) {
- mUserPresetsManager.delete(id);
- }
-
- private void updatePreset(FilterUserPresetRepresentation representation) {
- mUserPresetsManager.update(representation);
- }
-
- public void enableSave(boolean enable) {
- if (mSaveButton != null) {
- mSaveButton.setEnabled(enable);
- }
- }
-
- private void fillLooks() {
- FiltersManager filtersManager = FiltersManager.getManager();
- ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getLooks();
-
- mCategoryLooksAdapter.clear();
- int verticalItemHeight = (int) getResources().getDimension(R.dimen.action_item_height);
- mCategoryLooksAdapter.setItemHeight(verticalItemHeight);
- for (FilterRepresentation representation : filtersRepresentations) {
- mCategoryLooksAdapter.add(new Action(this, representation, Action.FULL_VIEW));
- }
- }
-
- public void setDefaultPreset() {
- // Default preset (original)
- ImagePreset preset = new ImagePreset(); // empty
- mMasterImage.setPreset(preset, preset.getLastRepresentation(), true);
- }
-
- // //////////////////////////////////////////////////////////////////////////////
- // Some utility functions
- // TODO: finish the cleanup.
-
- public void invalidateViews() {
- for (ImageShow views : mImageViews) {
- views.updateImage();
- }
- }
-
- public void hideImageViews() {
- for (View view : mImageViews) {
- view.setVisibility(View.GONE);
- }
- mEditorPlaceHolder.hide();
- }
-
- // //////////////////////////////////////////////////////////////////////////////
- // imageState panel...
-
- public void toggleImageStatePanel() {
- invalidateOptionsMenu();
- mShowingImageStatePanel = !mShowingImageStatePanel;
- Fragment panel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
- if (panel != null) {
- if (panel instanceof EditorPanel) {
- EditorPanel editorPanel = (EditorPanel) panel;
- editorPanel.showImageStatePanel(mShowingImageStatePanel);
- } else if (panel instanceof MainPanel) {
- MainPanel mainPanel = (MainPanel) panel;
- mainPanel.showImageStatePanel(mShowingImageStatePanel);
- }
- }
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig)
- {
- super.onConfigurationChanged(newConfig);
- setDefaultValues();
- loadXML();
- fillCategories();
- loadMainPanel();
-
- // 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);
- }
-
- public void setupMasterImage() {
-
- HistoryManager historyManager = new HistoryManager();
- StateAdapter imageStateAdapter = new StateAdapter(this, 0);
- MasterImage.reset();
- mMasterImage = MasterImage.getImage();
- mMasterImage.setHistoryManager(historyManager);
- mMasterImage.setStateAdapter(imageStateAdapter);
- mMasterImage.setActivity(this);
-
- if (Runtime.getRuntime().maxMemory() > LIMIT_SUPPORTS_HIGHRES) {
- mMasterImage.setSupportsHighRes(true);
- } else {
- mMasterImage.setSupportsHighRes(false);
- }
- }
-
- void resetHistory() {
- HistoryManager adapter = mMasterImage.getHistory();
- adapter.reset();
- HistoryItem historyItem = adapter.getItem(0);
- ImagePreset original = new ImagePreset(historyItem.getImagePreset());
- mMasterImage.setPreset(original, historyItem.getFilterRepresentation(), true);
- invalidateViews();
- backToMain();
- }
-
- public void showDefaultImageView() {
- mEditorPlaceHolder.hide();
- mImageShow.setVisibility(View.VISIBLE);
- MasterImage.getImage().setCurrentFilter(null);
- MasterImage.getImage().setCurrentFilterRepresentation(null);
- }
-
- public void backToMain() {
- Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
- if (currentPanel instanceof MainPanel) {
- return;
- }
- loadMainPanel();
- showDefaultImageView();
- }
-
- @Override
- public void onBackPressed() {
- Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
- if (currentPanel instanceof MainPanel) {
- if (!mImageShow.hasModifications()) {
- done();
- } else {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(R.string.unsaved).setTitle(R.string.save_before_exit);
- builder.setPositiveButton(R.string.save_and_exit, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- saveImage();
- }
- });
- builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- done();
- }
- });
- builder.show();
- }
- } else {
- backToMain();
- }
- }
-
- public void cannotLoadImage() {
- Toast.makeText(this, R.string.cannot_load_image, Toast.LENGTH_SHORT).show();
- finish();
- }
-
- // //////////////////////////////////////////////////////////////////////////////
-
- public float getPixelsFromDip(float value) {
- Resources r = getResources();
- return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
- r.getDisplayMetrics());
- }
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position,
- long id) {
- mMasterImage.onHistoryItemClick(position);
- invalidateViews();
- }
-
- public void pickImage() {
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);
- startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
- SELECT_PICTURE);
- }
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK) {
- if (requestCode == SELECT_PICTURE) {
- Uri selectedImageUri = data.getData();
- startLoadBitmap(selectedImageUri);
- }
- }
- }
-
-
- public void saveImage() {
- if (mImageShow.hasModifications()) {
- // Get the name of the album, to which the image will be saved
- File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri);
- int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
- String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
- showSavingProgress(albumName);
- mImageShow.saveImage(this, null);
- } else {
- done();
- }
- }
-
-
- public void done() {
- hideSavingProgress();
- if (mLoadBitmapTask != null) {
- mLoadBitmapTask.cancel(false);
- }
- finish();
- }
-
- private void extractXMPData() {
- XMresults res = XmpPresets.extractXMPData(
- getBaseContext(), mMasterImage, getIntent().getData());
- if (res == null)
- return;
-
- mOriginalImageUri = res.originalimage;
- mOriginalPreset = res.preset;
- }
-
- public Uri getSelectedImageUri() {
- return mSelectedImageUri;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
deleted file mode 100644
index b6c72fd9d..000000000
--- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.cache;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteException;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.BitmapRegionDecoder;
-import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.net.Uri;
-import android.provider.MediaStore;
-import android.util.Log;
-import android.webkit.MimeTypeMap;
-
-import com.adobe.xmp.XMPException;
-import com.adobe.xmp.XMPMeta;
-import com.android.gallery3d.R;
-import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.exif.ExifInterface;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.util.XmpUtilHelper;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-public final class ImageLoader {
-
- private static final String LOGTAG = "ImageLoader";
-
- public static final String JPEG_MIME_TYPE = "image/jpeg";
- public static final int DEFAULT_COMPRESS_QUALITY = 95;
-
- public static final int ORI_NORMAL = ExifInterface.Orientation.TOP_LEFT;
- public static final int ORI_ROTATE_90 = ExifInterface.Orientation.RIGHT_TOP;
- public static final int ORI_ROTATE_180 = ExifInterface.Orientation.BOTTOM_LEFT;
- public static final int ORI_ROTATE_270 = ExifInterface.Orientation.RIGHT_BOTTOM;
- public static final int ORI_FLIP_HOR = ExifInterface.Orientation.TOP_RIGHT;
- public static final int ORI_FLIP_VERT = ExifInterface.Orientation.BOTTOM_RIGHT;
- public static final int ORI_TRANSPOSE = ExifInterface.Orientation.LEFT_TOP;
- public static final int ORI_TRANSVERSE = ExifInterface.Orientation.LEFT_BOTTOM;
-
- private static final int BITMAP_LOAD_BACKOUT_ATTEMPTS = 5;
-
- private ImageLoader() {}
-
- /**
- * Returns the Mime type for a Url. Safe to use with Urls that do not
- * come from Gallery's content provider.
- */
- public static String getMimeType(Uri src) {
- String postfix = MimeTypeMap.getFileExtensionFromUrl(src.toString());
- String ret = null;
- if (postfix != null) {
- ret = MimeTypeMap.getSingleton().getMimeTypeFromExtension(postfix);
- }
- return ret;
- }
-
- /**
- * Returns the image's orientation flag. Defaults to ORI_NORMAL if no valid
- * orientation was found.
- */
- public static int getMetadataOrientation(Context context, Uri uri) {
- if (uri == null || context == null) {
- throw new IllegalArgumentException("bad argument to getOrientation");
- }
-
- // First try to find orientation data in Gallery's ContentProvider.
- Cursor cursor = null;
- try {
- cursor = context.getContentResolver().query(uri,
- new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
- null, null, null);
- if (cursor != null && cursor.moveToNext()) {
- int ori = cursor.getInt(0);
- switch (ori) {
- case 90:
- return ORI_ROTATE_90;
- case 270:
- return ORI_ROTATE_270;
- case 180:
- return ORI_ROTATE_180;
- default:
- return ORI_NORMAL;
- }
- }
- } catch (SQLiteException e) {
- // Do nothing
- } catch (IllegalArgumentException e) {
- // Do nothing
- } finally {
- Utils.closeSilently(cursor);
- }
-
- // Fall back to checking EXIF tags in file.
- if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
- String mimeType = getMimeType(uri);
- if (!JPEG_MIME_TYPE.equals(mimeType)) {
- return ORI_NORMAL;
- }
- String path = uri.getPath();
- ExifInterface exif = new ExifInterface();
- try {
- exif.readExif(path);
- Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
- if (tagval != null) {
- int orientation = tagval;
- switch(orientation) {
- case ORI_NORMAL:
- case ORI_ROTATE_90:
- case ORI_ROTATE_180:
- case ORI_ROTATE_270:
- case ORI_FLIP_HOR:
- case ORI_FLIP_VERT:
- case ORI_TRANSPOSE:
- case ORI_TRANSVERSE:
- return orientation;
- default:
- return ORI_NORMAL;
- }
- }
- } catch (IOException e) {
- Log.w(LOGTAG, "Failed to read EXIF orientation", e);
- }
- }
- return ORI_NORMAL;
- }
-
- /**
- * Returns the rotation of image at the given URI as one of 0, 90, 180,
- * 270. Defaults to 0.
- */
- public static int getMetadataRotation(Context context, Uri uri) {
- int orientation = getMetadataOrientation(context, uri);
- switch(orientation) {
- case ORI_ROTATE_90:
- return 90;
- case ORI_ROTATE_180:
- return 180;
- case ORI_ROTATE_270:
- return 270;
- default:
- return 0;
- }
- }
-
- /**
- * Takes an orientation and a bitmap, and returns the bitmap transformed
- * to that orientation.
- */
- public static Bitmap orientBitmap(Bitmap bitmap, int ori) {
- Matrix matrix = new Matrix();
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- if (ori == ORI_ROTATE_90 ||
- ori == ORI_ROTATE_270 ||
- ori == ORI_TRANSPOSE ||
- ori == ORI_TRANSVERSE) {
- int tmp = w;
- w = h;
- h = tmp;
- }
- switch (ori) {
- case ORI_ROTATE_90:
- matrix.setRotate(90, w / 2f, h / 2f);
- break;
- case ORI_ROTATE_180:
- matrix.setRotate(180, w / 2f, h / 2f);
- break;
- case ORI_ROTATE_270:
- matrix.setRotate(270, w / 2f, h / 2f);
- break;
- case ORI_FLIP_HOR:
- matrix.preScale(-1, 1);
- break;
- case ORI_FLIP_VERT:
- matrix.preScale(1, -1);
- break;
- case ORI_TRANSPOSE:
- matrix.setRotate(90, w / 2f, h / 2f);
- matrix.preScale(1, -1);
- break;
- case ORI_TRANSVERSE:
- matrix.setRotate(270, w / 2f, h / 2f);
- matrix.preScale(1, -1);
- break;
- case ORI_NORMAL:
- default:
- return bitmap;
- }
- return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
- bitmap.getHeight(), matrix, true);
- }
-
- /**
- * Returns the bitmap for the rectangular region given by "bounds"
- * if it is a subset of the bitmap stored at uri. Otherwise returns
- * null.
- */
- public static Bitmap loadRegionBitmap(Context context, Uri uri, BitmapFactory.Options options,
- Rect bounds) {
- InputStream is = null;
- try {
- is = context.getContentResolver().openInputStream(uri);
- BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
- Rect r = new Rect(0, 0, decoder.getWidth(), decoder.getHeight());
- // return null if bounds are not entirely within the bitmap
- if (!r.contains(bounds)) {
- return null;
- }
- return decoder.decodeRegion(bounds, options);
- } catch (FileNotFoundException e) {
- Log.e(LOGTAG, "FileNotFoundException for " + uri, e);
- } catch (IOException e) {
- Log.e(LOGTAG, "FileNotFoundException for " + uri, e);
- } finally {
- Utils.closeSilently(is);
- }
- return null;
- }
-
- /**
- * Returns the bounds of the bitmap stored at a given Url.
- */
- public static Rect loadBitmapBounds(Context context, Uri uri) {
- BitmapFactory.Options o = new BitmapFactory.Options();
- loadBitmap(context, uri, o);
- return new Rect(0, 0, o.outWidth, o.outHeight);
- }
-
- /**
- * Loads a bitmap that has been downsampled using sampleSize from a given url.
- */
- public static Bitmap loadDownsampledBitmap(Context context, Uri uri, int sampleSize) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inMutable = true;
- options.inSampleSize = sampleSize;
- return loadBitmap(context, uri, options);
- }
-
-
- /**
- * Returns the bitmap from the given uri loaded using the given options.
- * Returns null on failure.
- */
- public static Bitmap loadBitmap(Context context, Uri uri, BitmapFactory.Options o) {
- if (uri == null || context == null) {
- throw new IllegalArgumentException("bad argument to loadBitmap");
- }
- InputStream is = null;
- try {
- is = context.getContentResolver().openInputStream(uri);
- return BitmapFactory.decodeStream(is, null, o);
- } catch (FileNotFoundException e) {
- Log.e(LOGTAG, "FileNotFoundException for " + uri, e);
- } finally {
- Utils.closeSilently(is);
- }
- return null;
- }
-
- /**
- * Loads a bitmap at a given URI that is downsampled so that both sides are
- * smaller than maxSideLength. The Bitmap's original dimensions are stored
- * in the rect originalBounds.
- *
- * @param uri URI of image to open.
- * @param context context whose ContentResolver to use.
- * @param maxSideLength max side length of returned bitmap.
- * @param originalBounds If not null, set to the actual bounds of the stored bitmap.
- * @param useMin use min or max side of the original image
- * @return downsampled bitmap or null if this operation failed.
- */
- public static Bitmap loadConstrainedBitmap(Uri uri, Context context, int maxSideLength,
- Rect originalBounds, boolean useMin) {
- if (maxSideLength <= 0 || uri == null || context == null) {
- throw new IllegalArgumentException("bad argument to getScaledBitmap");
- }
- // Get width and height of stored bitmap
- Rect storedBounds = loadBitmapBounds(context, uri);
- if (originalBounds != null) {
- originalBounds.set(storedBounds);
- }
- int w = storedBounds.width();
- int h = storedBounds.height();
-
- // If bitmap cannot be decoded, return null
- if (w <= 0 || h <= 0) {
- return null;
- }
-
- // Find best downsampling size
- int imageSide = 0;
- if (useMin) {
- imageSide = Math.min(w, h);
- } else {
- imageSide = Math.max(w, h);
- }
- int sampleSize = 1;
- while (imageSide > maxSideLength) {
- imageSide >>>= 1;
- sampleSize <<= 1;
- }
-
- // Make sure sample size is reasonable
- if (sampleSize <= 0 ||
- 0 >= (int) (Math.min(w, h) / sampleSize)) {
- return null;
- }
- return loadDownsampledBitmap(context, uri, sampleSize);
- }
-
- /**
- * Loads a bitmap at a given URI that is downsampled so that both sides are
- * smaller than maxSideLength. The Bitmap's original dimensions are stored
- * in the rect originalBounds. The output is also transformed to the given
- * orientation.
- *
- * @param uri URI of image to open.
- * @param context context whose ContentResolver to use.
- * @param maxSideLength max side length of returned bitmap.
- * @param orientation the orientation to transform the bitmap to.
- * @param originalBounds set to the actual bounds of the stored bitmap.
- * @return downsampled bitmap or null if this operation failed.
- */
- public static Bitmap loadOrientedConstrainedBitmap(Uri uri, Context context, int maxSideLength,
- int orientation, Rect originalBounds) {
- Bitmap bmap = loadConstrainedBitmap(uri, context, maxSideLength, originalBounds, false);
- if (bmap != null) {
- bmap = orientBitmap(bmap, orientation);
- }
- return bmap;
- }
-
- public static Bitmap getScaleOneImageForPreset(Context context, Uri uri, Rect bounds,
- Rect destination) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inMutable = true;
- if (destination != null) {
- if (bounds.width() > destination.width()) {
- int sampleSize = 1;
- int w = bounds.width();
- while (w > destination.width()) {
- sampleSize *= 2;
- w /= sampleSize;
- }
- options.inSampleSize = sampleSize;
- }
- }
- Bitmap bmp = loadRegionBitmap(context, uri, options, bounds);
- return bmp;
- }
-
- /**
- * Loads a bitmap that is downsampled by at least the input sample size. In
- * low-memory situations, the bitmap may be downsampled further.
- */
- public static Bitmap loadBitmapWithBackouts(Context context, Uri sourceUri, int sampleSize) {
- boolean noBitmap = true;
- int num_tries = 0;
- if (sampleSize <= 0) {
- sampleSize = 1;
- }
- Bitmap bmap = null;
- while (noBitmap) {
- try {
- // Try to decode, downsample if low-memory.
- bmap = loadDownsampledBitmap(context, sourceUri, sampleSize);
- noBitmap = false;
- } catch (java.lang.OutOfMemoryError e) {
- // Try with more downsampling before failing for good.
- if (++num_tries >= BITMAP_LOAD_BACKOUT_ATTEMPTS) {
- throw e;
- }
- bmap = null;
- System.gc();
- sampleSize *= 2;
- }
- }
- return bmap;
- }
-
- /**
- * Loads an oriented bitmap that is downsampled by at least the input sample
- * size. In low-memory situations, the bitmap may be downsampled further.
- */
- public static Bitmap loadOrientedBitmapWithBackouts(Context context, Uri sourceUri,
- int sampleSize) {
- Bitmap bitmap = loadBitmapWithBackouts(context, sourceUri, sampleSize);
- if (bitmap == null) {
- return null;
- }
- int orientation = getMetadataOrientation(context, sourceUri);
- bitmap = orientBitmap(bitmap, orientation);
- return bitmap;
- }
-
- /**
- * Loads bitmap from a resource that may be downsampled in low-memory situations.
- */
- public static Bitmap decodeResourceWithBackouts(Resources res, BitmapFactory.Options options,
- int id) {
- boolean noBitmap = true;
- int num_tries = 0;
- if (options.inSampleSize < 1) {
- options.inSampleSize = 1;
- }
- // Stopgap fix for low-memory devices.
- Bitmap bmap = null;
- while (noBitmap) {
- try {
- // Try to decode, downsample if low-memory.
- bmap = BitmapFactory.decodeResource(
- res, id, options);
- noBitmap = false;
- } catch (java.lang.OutOfMemoryError e) {
- // Retry before failing for good.
- if (++num_tries >= BITMAP_LOAD_BACKOUT_ATTEMPTS) {
- throw e;
- }
- bmap = null;
- System.gc();
- options.inSampleSize *= 2;
- }
- }
- return bmap;
- }
-
- public static XMPMeta getXmpObject(Context context) {
- try {
- InputStream is = context.getContentResolver().openInputStream(
- MasterImage.getImage().getUri());
- return XmpUtilHelper.extractXMPMeta(is);
- } catch (FileNotFoundException e) {
- return null;
- }
- }
-
- /**
- * Determine if this is a light cycle 360 image
- *
- * @return true if it is a light Cycle image that is full 360
- */
- public static boolean queryLightCycle360(Context context) {
- InputStream is = null;
- try {
- is = context.getContentResolver().openInputStream(MasterImage.getImage().getUri());
- XMPMeta meta = XmpUtilHelper.extractXMPMeta(is);
- if (meta == null) {
- return false;
- }
- String namespace = "http://ns.google.com/photos/1.0/panorama/";
- String cropWidthName = "GPano:CroppedAreaImageWidthPixels";
- String fullWidthName = "GPano:FullPanoWidthPixels";
-
- if (!meta.doesPropertyExist(namespace, cropWidthName)) {
- return false;
- }
- if (!meta.doesPropertyExist(namespace, fullWidthName)) {
- return false;
- }
-
- Integer cropValue = meta.getPropertyInteger(namespace, cropWidthName);
- Integer fullValue = meta.getPropertyInteger(namespace, fullWidthName);
-
- // Definition of a 360:
- // GFullPanoWidthPixels == CroppedAreaImageWidthPixels
- if (cropValue != null && fullValue != null) {
- return cropValue.equals(fullValue);
- }
-
- return false;
- } catch (FileNotFoundException e) {
- return false;
- } catch (XMPException e) {
- return false;
- } finally {
- Utils.closeSilently(is);
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/category/Action.java b/src/com/android/gallery3d/filtershow/category/Action.java
deleted file mode 100644
index 332ca18b0..000000000
--- a/src/com/android/gallery3d/filtershow/category/Action.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.widget.ArrayAdapter;
-import android.widget.ListAdapter;
-import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequest;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-public class Action implements RenderingRequestCaller {
-
- private static final String LOGTAG = "Action";
- private FilterRepresentation mRepresentation;
- private String mName;
- private Rect mImageFrame;
- private Bitmap mImage;
- private ArrayAdapter mAdapter;
- public static final int FULL_VIEW = 0;
- public static final int CROP_VIEW = 1;
- private int mType = CROP_VIEW;
- private Bitmap mPortraitImage;
- private Bitmap mOverlayBitmap;
- private Context mContext;
-
- public Action(Context context, FilterRepresentation representation, int type) {
- mContext = context;
- setRepresentation(representation);
- setType(type);
- }
-
- public Action(Context context, FilterRepresentation representation) {
- this(context, representation, CROP_VIEW);
- }
-
- public FilterRepresentation getRepresentation() {
- return mRepresentation;
- }
-
- public void setRepresentation(FilterRepresentation representation) {
- mRepresentation = representation;
- mName = representation.getName();
- }
-
- public String getName() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
- public void setImageFrame(Rect imageFrame, int orientation) {
- if (mImageFrame != null && mImageFrame.equals(imageFrame)) {
- return;
- }
- Bitmap bitmap = MasterImage.getImage().getLargeThumbnailBitmap();
- if (bitmap != null) {
- mImageFrame = imageFrame;
- int w = mImageFrame.width();
- int h = mImageFrame.height();
- if (orientation == CategoryView.VERTICAL
- && mType == CROP_VIEW) {
- w /= 2;
- }
- Bitmap bitmapCrop = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- drawCenteredImage(bitmap, bitmapCrop, true);
-
- postNewIconRenderRequest(bitmapCrop);
- }
- }
-
- public Bitmap getImage() {
- return mImage;
- }
-
- public void setImage(Bitmap image) {
- mImage = image;
- }
-
- public void setAdapter(ArrayAdapter adapter) {
- mAdapter = adapter;
- }
-
- public void setType(int type) {
- mType = type;
- }
-
- private void postNewIconRenderRequest(Bitmap bitmap) {
- if (bitmap != null && mRepresentation != null) {
- ImagePreset preset = new ImagePreset();
- preset.addFilter(mRepresentation);
- RenderingRequest.post(mContext, bitmap,
- preset, RenderingRequest.ICON_RENDERING, this);
- }
- }
-
- private void drawCenteredImage(Bitmap source, Bitmap destination, boolean scale) {
- RectF image = new RectF(0, 0, source.getWidth(), source.getHeight());
- int border = 0;
- if (!scale) {
- border = destination.getWidth() - destination.getHeight();
- if (border < 0) {
- border = 0;
- }
- }
- RectF frame = new RectF(border, 0,
- destination.getWidth() - border,
- destination.getHeight());
- Matrix m = new Matrix();
- m.setRectToRect(frame, image, Matrix.ScaleToFit.CENTER);
- image.set(frame);
- m.mapRect(image);
- m.setRectToRect(image, frame, Matrix.ScaleToFit.FILL);
- Canvas canvas = new Canvas(destination);
- canvas.drawBitmap(source, m, new Paint(Paint.FILTER_BITMAP_FLAG));
- }
-
- @Override
- public void available(RenderingRequest request) {
- mImage = request.getBitmap();
- if (mImage == null) {
- return;
- }
- if (mRepresentation.getOverlayId() != 0 && mOverlayBitmap == null) {
- mOverlayBitmap = BitmapFactory.decodeResource(
- mContext.getResources(),
- mRepresentation.getOverlayId());
- }
- if (mOverlayBitmap != null) {
- if (getRepresentation().getFilterType() == 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();
- }
- }
-
- public void setPortraitImage(Bitmap portraitImage) {
- mPortraitImage = portraitImage;
- }
-
- public Bitmap getPortraitImage() {
- return mPortraitImage;
- }
-
- public Bitmap getOverlayBitmap() {
- return mOverlayBitmap;
- }
-
- public void setOverlayBitmap(Bitmap overlayBitmap) {
- mOverlayBitmap = overlayBitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
deleted file mode 100644
index 6451c39df..000000000
--- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.content.Context;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-public class CategoryAdapter extends ArrayAdapter<Action> {
-
- private static final String LOGTAG = "CategoryAdapter";
- private int mItemHeight;
- private View mContainer;
- private int mItemWidth = ListView.LayoutParams.MATCH_PARENT;
- private int mSelectedPosition;
- int mCategory;
- private int mOrientation;
-
- public CategoryAdapter(Context context, int textViewResourceId) {
- super(context, textViewResourceId);
- mItemHeight = (int) (context.getResources().getDisplayMetrics().density * 100);
- }
-
- public CategoryAdapter(Context context) {
- this(context, 0);
- }
-
- public void setItemHeight(int height) {
- mItemHeight = height;
- }
-
- public void setItemWidth(int width) {
- mItemWidth = width;
- }
-
- @Override
- public void add(Action action) {
- super.add(action);
- action.setAdapter(this);
- }
-
- public void initializeSelection(int category) {
- mCategory = category;
- mSelectedPosition = -1;
- if (category == MainPanel.LOOKS) {
- mSelectedPosition = 0;
- }
- if (category == MainPanel.BORDERS) {
- mSelectedPosition = 0;
- }
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = new CategoryView(getContext());
- }
- CategoryView view = (CategoryView) convertView;
- view.setOrientation(mOrientation);
- view.setAction(getItem(position), this);
- view.setLayoutParams(
- new ListView.LayoutParams(mItemWidth, mItemHeight));
- view.setTag(position);
- view.invalidate();
- return view;
- }
-
- public void setSelected(View v) {
- int old = mSelectedPosition;
- mSelectedPosition = (Integer) v.getTag();
- if (old != -1) {
- invalidateView(old);
- }
- invalidateView(mSelectedPosition);
- }
-
- public boolean isSelected(View v) {
- return (Integer) v.getTag() == mSelectedPosition;
- }
-
- private void invalidateView(int position) {
- View child = null;
- if (mContainer instanceof ListView) {
- ListView lv = (ListView) mContainer;
- child = lv.getChildAt(position - lv.getFirstVisiblePosition());
- } else {
- CategoryTrack ct = (CategoryTrack) mContainer;
- child = ct.getChildAt(position);
- }
- if (child != null) {
- child.invalidate();
- }
- }
-
- public void setContainer(View container) {
- mContainer = container;
- }
-
- public void imageLoaded() {
- notifyDataSetChanged();
- }
-
- public FilterRepresentation getTinyPlanet() {
- for (int i = 0; i < getCount(); i++) {
- Action action = getItem(i);
- if (action.getRepresentation() != null
- && action.getRepresentation()
- instanceof FilterTinyPlanetRepresentation) {
- return action.getRepresentation();
- }
- }
- return null;
- }
-
- public void removeTinyPlanet() {
- for (int i = 0; i < getCount(); i++) {
- Action action = getItem(i);
- if (action.getRepresentation() != null
- && action.getRepresentation()
- instanceof FilterTinyPlanetRepresentation) {
- remove(action);
- return;
- }
- }
- }
-
- public void setOrientation(int orientation) {
- mOrientation = orientation;
- }
-
- public void reflectImagePreset(ImagePreset preset) {
- if (preset == null) {
- return;
- }
- int selected = 0; // if nothing found, select "none" (first element)
- FilterRepresentation rep = null;
- if (mCategory == MainPanel.LOOKS) {
- int pos = preset.getPositionForType(FilterRepresentation.TYPE_FX);
- if (pos != -1) {
- rep = preset.getFilterRepresentation(pos);
- }
- } else if (mCategory == MainPanel.BORDERS) {
- int pos = preset.getPositionForType(FilterRepresentation.TYPE_BORDER);
- if (pos != -1) {
- rep = preset.getFilterRepresentation(pos);
- }
- }
- if (rep != null) {
- for (int i = 0; i < getCount(); i++) {
- if (rep.getName().equalsIgnoreCase(
- getItem(i).getRepresentation().getName())) {
- selected = i;
- break;
- }
- }
- }
- if (mSelectedPosition != selected) {
- mSelectedPosition = selected;
- this.notifyDataSetChanged();
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java
deleted file mode 100644
index de2481f3f..000000000
--- a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-import android.widget.ListView;
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-
-public class CategoryPanel extends Fragment {
-
- public static final String FRAGMENT_TAG = "CategoryPanel";
- private static final String PARAMETER_TAG = "currentPanel";
-
- private int mCurrentAdapter = MainPanel.LOOKS;
- private CategoryAdapter mAdapter;
-
- public void setAdapter(int value) {
- mCurrentAdapter = value;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- loadAdapter(mCurrentAdapter);
- }
-
- private void loadAdapter(int adapter) {
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- switch (adapter) {
- case MainPanel.LOOKS: {
- mAdapter = activity.getCategoryLooksAdapter();
- mAdapter.initializeSelection(MainPanel.LOOKS);
- activity.updateCategories();
- break;
- }
- case MainPanel.BORDERS: {
- mAdapter = activity.getCategoryBordersAdapter();
- mAdapter.initializeSelection(MainPanel.BORDERS);
- activity.updateCategories();
- break;
- }
- case MainPanel.GEOMETRY: {
- mAdapter = activity.getCategoryGeometryAdapter();
- mAdapter.initializeSelection(MainPanel.GEOMETRY);
- break;
- }
- case MainPanel.FILTERS: {
- mAdapter = activity.getCategoryFiltersAdapter();
- mAdapter.initializeSelection(MainPanel.FILTERS);
- break;
- }
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle state) {
- super.onSaveInstanceState(state);
- state.putInt(PARAMETER_TAG, mCurrentAdapter);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- LinearLayout main = (LinearLayout) inflater.inflate(
- R.layout.filtershow_category_panel_new, container,
- false);
-
- if (savedInstanceState != null) {
- int selectedPanel = savedInstanceState.getInt(PARAMETER_TAG);
- loadAdapter(selectedPanel);
- }
-
- View panelView = main.findViewById(R.id.listItems);
- if (panelView instanceof CategoryTrack) {
- CategoryTrack panel = (CategoryTrack) panelView;
- mAdapter.setOrientation(CategoryView.HORIZONTAL);
- panel.setAdapter(mAdapter);
- mAdapter.setContainer(panel);
- } else {
- ListView panel = (ListView) main.findViewById(R.id.listItems);
- panel.setAdapter(mAdapter);
- mAdapter.setContainer(panel);
- }
- return main;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryTrack.java b/src/com/android/gallery3d/filtershow/category/CategoryTrack.java
deleted file mode 100644
index ac8245a3b..000000000
--- a/src/com/android/gallery3d/filtershow/category/CategoryTrack.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.database.DataSetObserver;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.widget.LinearLayout;
-import com.android.gallery3d.R;
-
-public class CategoryTrack extends LinearLayout {
-
- private CategoryAdapter mAdapter;
- private int mElemSize;
- private DataSetObserver mDataSetObserver = new DataSetObserver() {
- @Override
- public void onChanged() {
- super.onChanged();
- invalidate();
- }
- @Override
- public void onInvalidated() {
- super.onInvalidated();
- fillContent();
- }
- };
-
- public CategoryTrack(Context context, AttributeSet attrs) {
- super(context, attrs);
- TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CategoryTrack);
- mElemSize = a.getDimensionPixelSize(R.styleable.CategoryTrack_iconSize, 0);
- }
-
- public void setAdapter(CategoryAdapter adapter) {
- mAdapter = adapter;
- mAdapter.registerDataSetObserver(mDataSetObserver);
- fillContent();
- }
-
- public void fillContent() {
- removeAllViews();
- mAdapter.setItemWidth(mElemSize);
- mAdapter.setItemHeight(LayoutParams.MATCH_PARENT);
- int n = mAdapter.getCount();
- for (int i = 0; i < n; i++) {
- View view = mAdapter.getView(i, null, this);
- addView(view, i);
- }
- requestLayout();
- }
-
- @Override
- public void invalidate() {
- for (int i = 0; i < this.getChildCount(); i++) {
- View child = getChildAt(i);
- child.invalidate();
- }
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java
deleted file mode 100644
index c456dc207..000000000
--- a/src/com/android/gallery3d/filtershow/category/CategoryView.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.Typeface;
-import android.view.View;
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.ui.SelectionRenderer;
-
-public class CategoryView extends View implements View.OnClickListener {
-
- private static final String LOGTAG = "CategoryView";
- public static final int VERTICAL = 0;
- public static final int HORIZONTAL = 1;
- private Paint mPaint = new Paint();
- private Action mAction;
- private Rect mTextBounds = new Rect();
- private int mMargin = 16;
- private int mTextSize = 32;
- private int mTextColor;
- private int mBackgroundColor;
- private Paint mSelectPaint;
- CategoryAdapter mAdapter;
- private int mSelectionStroke;
- private Paint mBorderPaint;
- private int mBorderStroke;
- private int mOrientation = VERTICAL;
-
- public CategoryView(Context context) {
- super(context);
- setOnClickListener(this);
- Resources res = getResources();
- mBackgroundColor = res.getColor(R.color.filtershow_categoryview_background);
- mTextColor = res.getColor(R.color.filtershow_categoryview_text);
- mSelectionStroke = res.getDimensionPixelSize(R.dimen.thumbnail_margin);
- mTextSize = res.getDimensionPixelSize(R.dimen.category_panel_text_size);
- mMargin = res.getDimensionPixelOffset(R.dimen.category_panel_margin);
- mSelectPaint = new Paint();
- mSelectPaint.setStyle(Paint.Style.FILL);
- mSelectPaint.setColor(res.getColor(R.color.filtershow_category_selection));
- mBorderPaint = new Paint(mSelectPaint);
- mBorderPaint.setColor(Color.BLACK);
- mBorderStroke = mSelectionStroke / 3;
- }
-
- private void computeTextPosition(String text) {
- if (text == null) {
- return;
- }
- mPaint.setTextSize(mTextSize);
- if (mOrientation == VERTICAL) {
- text = text.toUpperCase();
- // TODO: set this in xml
- mPaint.setTypeface(Typeface.DEFAULT_BOLD);
- }
- mPaint.getTextBounds(text, 0, text.length(), mTextBounds);
- }
-
- public void drawText(Canvas canvas, String text) {
- if (text == null) {
- return;
- }
- float textWidth = mPaint.measureText(text);
- int x = (int) (canvas.getWidth() - textWidth - mMargin);
- if (mOrientation == HORIZONTAL) {
- x = (int) ((canvas.getWidth() - textWidth) / 2.0f);
- }
- if (x < 0) {
- // If the text takes more than the view width,
- // justify to the left.
- x = mMargin;
- }
- int y = canvas.getHeight() - mMargin;
- canvas.drawText(text, x, y, mPaint);
- }
-
- @Override
- public CharSequence getContentDescription () {
- if (mAction != null) {
- return mAction.getName();
- }
- return null;
- }
-
- @Override
- public void onDraw(Canvas canvas) {
- canvas.drawColor(mBackgroundColor);
- if (mAction != null) {
- mPaint.reset();
- mPaint.setAntiAlias(true);
- computeTextPosition(mAction.getName());
- if (mAction.getImage() == null) {
- mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), mOrientation);
- } else {
- Bitmap bitmap = mAction.getImage();
- canvas.save();
- Rect clipRect = new Rect(mSelectionStroke, mSelectionStroke,
- getWidth() - mSelectionStroke,
- getHeight() - 2* mMargin - mTextSize);
- int offsetx = 0;
- int offsety = 0;
- if (mOrientation == HORIZONTAL) {
- canvas.clipRect(clipRect);
- offsetx = - (bitmap.getWidth() - clipRect.width()) / 2;
- offsety = - (bitmap.getHeight() - clipRect.height()) / 2;
- }
- canvas.drawBitmap(bitmap, offsetx, offsety, mPaint);
- canvas.restore();
- if (mAdapter.isSelected(this)) {
- if (mOrientation == HORIZONTAL) {
- SelectionRenderer.drawSelection(canvas, 0, 0,
- getWidth(), getHeight() - mMargin - mTextSize,
- mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint);
- } else {
- SelectionRenderer.drawSelection(canvas, 0, 0,
- Math.min(bitmap.getWidth(), getWidth()),
- Math.min(bitmap.getHeight(), getHeight()),
- mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint);
- }
- }
- }
- 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());
- }
- }
-
- public void setAction(Action action, CategoryAdapter adapter) {
- mAction = action;
- mAdapter = adapter;
- invalidate();
- }
-
- public FilterRepresentation getRepresentation() {
- return mAction.getRepresentation();
- }
-
- @Override
- public void onClick(View view) {
- FilterShowActivity activity = (FilterShowActivity) getContext();
- activity.showRepresentation(mAction.getRepresentation());
- mAdapter.setSelected(this);
- }
-
- public void setOrientation(int orientation) {
- mOrientation = orientation;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java
deleted file mode 100644
index 9a64ffbf3..000000000
--- a/src/com/android/gallery3d/filtershow/category/MainPanel.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.category;
-
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageButton;
-import android.widget.LinearLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.state.StatePanel;
-
-public class MainPanel extends Fragment {
-
- private static final String LOGTAG = "MainPanel";
-
- private LinearLayout mMainView;
- private ImageButton looksButton;
- private ImageButton bordersButton;
- private ImageButton geometryButton;
- private ImageButton filtersButton;
-
- public static final String FRAGMENT_TAG = "MainPanel";
- public static final int LOOKS = 0;
- public static final int BORDERS = 1;
- public static final int GEOMETRY = 2;
- public static final int FILTERS = 3;
-
- private int mCurrentSelected = -1;
-
- private void selection(int position, boolean value) {
- if (value) {
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- activity.setCurrentPanel(position);
- }
- switch (position) {
- case LOOKS: {
- looksButton.setSelected(value);
- break;
- }
- case BORDERS: {
- bordersButton.setSelected(value);
- break;
- }
- case GEOMETRY: {
- geometryButton.setSelected(value);
- break;
- }
- case FILTERS: {
- filtersButton.setSelected(value);
- break;
- }
- }
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- if (mMainView != null) {
- if (mMainView.getParent() != null) {
- ViewGroup parent = (ViewGroup) mMainView.getParent();
- parent.removeView(mMainView);
- }
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
-
- mMainView = (LinearLayout) inflater.inflate(
- R.layout.filtershow_main_panel, null, false);
-
- looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton);
- bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton);
- geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton);
- filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton);
-
- looksButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showPanel(LOOKS);
- }
- });
- bordersButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showPanel(BORDERS);
- }
- });
- geometryButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showPanel(GEOMETRY);
- }
- });
- filtersButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showPanel(FILTERS);
- }
- });
-
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- showImageStatePanel(activity.isShowingImageStatePanel());
- showPanel(activity.getCurrentPanel());
- return mMainView;
- }
-
- private boolean isRightAnimation(int newPos) {
- if (newPos < mCurrentSelected) {
- return false;
- }
- return true;
- }
-
- private void setCategoryFragment(CategoryPanel category, boolean fromRight) {
- FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
- if (fromRight) {
- transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right);
- } else {
- transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
- }
- transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG);
- transaction.commit();
- }
-
- public void loadCategoryLookPanel() {
- if (mCurrentSelected == LOOKS) {
- return;
- }
- boolean fromRight = isRightAnimation(LOOKS);
- selection(mCurrentSelected, false);
- CategoryPanel categoryPanel = new CategoryPanel();
- categoryPanel.setAdapter(LOOKS);
- setCategoryFragment(categoryPanel, fromRight);
- mCurrentSelected = LOOKS;
- selection(mCurrentSelected, true);
- }
-
- public void loadCategoryBorderPanel() {
- if (mCurrentSelected == BORDERS) {
- return;
- }
- boolean fromRight = isRightAnimation(BORDERS);
- selection(mCurrentSelected, false);
- CategoryPanel categoryPanel = new CategoryPanel();
- categoryPanel.setAdapter(BORDERS);
- setCategoryFragment(categoryPanel, fromRight);
- mCurrentSelected = BORDERS;
- selection(mCurrentSelected, true);
- }
-
- public void loadCategoryGeometryPanel() {
- if (mCurrentSelected == GEOMETRY) {
- return;
- }
- boolean fromRight = isRightAnimation(GEOMETRY);
- selection(mCurrentSelected, false);
- CategoryPanel categoryPanel = new CategoryPanel();
- categoryPanel.setAdapter(GEOMETRY);
- setCategoryFragment(categoryPanel, fromRight);
- mCurrentSelected = GEOMETRY;
- selection(mCurrentSelected, true);
- }
-
- public void loadCategoryFiltersPanel() {
- if (mCurrentSelected == FILTERS) {
- return;
- }
- boolean fromRight = isRightAnimation(FILTERS);
- selection(mCurrentSelected, false);
- CategoryPanel categoryPanel = new CategoryPanel();
- categoryPanel.setAdapter(FILTERS);
- setCategoryFragment(categoryPanel, fromRight);
- mCurrentSelected = FILTERS;
- selection(mCurrentSelected, true);
- }
-
- public void showPanel(int currentPanel) {
- switch (currentPanel) {
- case LOOKS: {
- loadCategoryLookPanel();
- break;
- }
- case BORDERS: {
- loadCategoryBorderPanel();
- break;
- }
- case GEOMETRY: {
- loadCategoryGeometryPanel();
- break;
- }
- case FILTERS: {
- loadCategoryFiltersPanel();
- break;
- }
- }
- }
-
- public void showImageStatePanel(boolean show) {
- if (mMainView.findViewById(R.id.state_panel_container) == null) {
- return;
- }
- FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
- final View container = mMainView.findViewById(R.id.state_panel_container);
- if (show) {
- container.setVisibility(View.VISIBLE);
- StatePanel statePanel = new StatePanel();
- transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
- } else {
- container.setVisibility(View.GONE);
- Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
- if (statePanel != null) {
- transaction.remove(statePanel);
- }
- }
- transaction.commit();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorGridDialog.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorGridDialog.java
deleted file mode 100644
index dd4df7dc8..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorGridDialog.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.graphics.Color;
-import android.graphics.drawable.GradientDrawable;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-
-import com.android.gallery3d.R;
-
-import java.util.ArrayList;
-
-public class ColorGridDialog extends Dialog {
- RGBListener mCallback;
- private static final String LOGTAG = "ColorGridDialog";
-
- public ColorGridDialog(Context context, final RGBListener cl) {
- super(context);
- mCallback = cl;
- setTitle(R.string.color_pick_title);
- setContentView(R.layout.filtershow_color_gird);
- Button sel = (Button) findViewById(R.id.filtershow_cp_custom);
- ArrayList<Button> b = getButtons((ViewGroup) getWindow().getDecorView());
- int k = 0;
- float[] hsv = new float[3];
-
- for (Button button : b) {
- if (!button.equals(sel)){
- hsv[0] = (k % 5) * 360 / 5;
- hsv[1] = (k / 5) / 3.0f;
- hsv[2] = (k < 5) ? (k / 4f) : 1;
- final int c = (Color.HSVToColor(hsv) & 0x00FFFFFF) | 0xAA000000;
- GradientDrawable sd = ((GradientDrawable) button.getBackground());
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mCallback.setColor(c);
- dismiss();
- }
- });
- sd.setColor(c);
- k++;
- }
-
- }
- sel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showColorPicker();
- ColorGridDialog.this.dismiss();
- }
- });
- }
-
- private ArrayList<Button> getButtons(ViewGroup vg) {
- ArrayList<Button> list = new ArrayList<Button>();
- for (int i = 0; i < vg.getChildCount(); i++) {
- View v = vg.getChildAt(i);
- if (v instanceof Button) {
- list.add((Button) v);
- } else if (v instanceof ViewGroup) {
- list.addAll(getButtons((ViewGroup) v));
- }
- }
- return list;
- }
-
- public void showColorPicker() {
- ColorListener cl = new ColorListener() {
- @Override
- public void setColor(float[] hsvo) {
- int c = Color.HSVToColor(hsvo) & 0xFFFFFF;
- int alpha = (int) (hsvo[3] * 255);
- c |= alpha << 24;
- mCallback.setColor(c);
- }
- };
- ColorPickerDialog cpd = new ColorPickerDialog(this.getContext(), cl);
- cpd.show();
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorListener.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorListener.java
deleted file mode 100644
index 5127dad26..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorListener.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-public interface ColorListener {
- void setColor(float[] hsvo);
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorOpacityView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorOpacityView.java
deleted file mode 100644
index 2bff501f7..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorOpacityView.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapShader;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.LinearGradient;
-import android.graphics.Paint;
-import android.graphics.RadialGradient;
-import android.graphics.Shader;
-import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.view.MotionEvent;
-import android.view.View;
-
-import com.android.gallery3d.R;
-
-import java.util.ArrayList;
-
-public class ColorOpacityView extends View implements ColorListener {
-
- private float mRadius;
- private float mWidth;
- private Paint mBarPaint1;
- private Paint mLinePaint1;
- private Paint mLinePaint2;
- private Paint mCheckPaint;
-
- private float mHeight;
- private Paint mDotPaint;
- private int mBgcolor = 0;
-
- private float mDotRadius;
- private float mBorder;
-
- private float[] mHSVO = new float[4];
- private int mSliderColor;
- private float mDotX = mBorder;
- private float mDotY = mBorder;
- private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
- public final static float BORDER_SIZE = 20;;
-
- public ColorOpacityView(Context ctx, AttributeSet attrs) {
- super(ctx, attrs);
- DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
- float mDpToPix = metrics.density;
- mDotRadius = DOT_SIZE * mDpToPix;
- mBorder = BORDER_SIZE * mDpToPix;
- mBarPaint1 = new Paint();
-
- mDotPaint = new Paint();
-
- mDotPaint.setStyle(Paint.Style.FILL);
- mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
- mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
-
- mBarPaint1.setStyle(Paint.Style.FILL);
-
- mLinePaint1 = new Paint();
- mLinePaint1.setColor(Color.GRAY);
- mLinePaint2 = new Paint();
- mLinePaint2.setColor(mSliderColor);
- mLinePaint2.setStrokeWidth(4);
-
- int[] colors = new int[16 * 16];
- for (int i = 0; i < colors.length; i++) {
- int y = i / (16 * 8);
- int x = (i / 8) % 2;
- colors[i] = (x == y) ? 0xFFAAAAAA : 0xFF444444;
- }
- Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888);
- BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
- mCheckPaint = new Paint();
- mCheckPaint.setShader(bs);
- }
-
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- float ox = mDotX;
- float oy = mDotY;
-
- float x = event.getX();
- float y = event.getY();
-
- mDotX = x;
-
- if (mDotX < mBorder) {
- mDotX = mBorder;
- }
-
- if (mDotX > mWidth - mBorder) {
- mDotX = mWidth - mBorder;
- }
- mHSVO[3] = (mDotX - mBorder) / (mWidth - mBorder * 2);
- notifyColorListeners(mHSVO);
- setupButton();
- invalidate((int) (ox - mDotRadius), (int) (oy - mDotRadius), (int) (ox + mDotRadius),
- (int) (oy + mDotRadius));
- invalidate(
- (int) (mDotX - mDotRadius), (int) (mDotY - mDotRadius), (int) (mDotX + mDotRadius),
- (int) (mDotY + mDotRadius));
-
- return true;
- }
-
- private void setupButton() {
- float pos = mHSVO[3] * (mWidth - mBorder * 2);
- mDotX = pos + mBorder;
-
- int[] colors3 = new int[] {
- mSliderColor, mSliderColor, 0x66000000, 0 };
- RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadius, colors3, new float[] {
- 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
- mDotPaint.setShader(g);
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- mWidth = w;
- mHeight = h;
- mDotY = mHeight / 2;
- updatePaint();
- setupButton();
- }
-
- private void updatePaint() {
-
- int color2 = Color.HSVToColor(mHSVO);
- int color1 = color2 & 0xFFFFFF;
-
- Shader sg = new LinearGradient(
- mBorder, mBorder, mWidth - mBorder, mBorder, color1, color2, Shader.TileMode.CLAMP);
- mBarPaint1.setShader(sg);
-
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawColor(mBgcolor);
- canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mCheckPaint);
- canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mBarPaint1);
- canvas.drawLine(mDotX, mDotY, mWidth - mBorder, mDotY, mLinePaint1);
- canvas.drawLine(mBorder, mDotY, mDotX, mDotY, mLinePaint2);
- if (mDotX != Float.NaN) {
- canvas.drawCircle(mDotX, mDotY, mDotRadius, mDotPaint);
- }
- }
-
- @Override
- public void setColor(float[] hsv) {
- System.arraycopy(hsv, 0, mHSVO, 0, mHSVO.length);
-
- float oy = mDotY;
-
- updatePaint();
- setupButton();
- invalidate();
- }
-
- ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
-
- public void notifyColorListeners(float[] hsvo) {
- for (ColorListener l : mColorListeners) {
- l.setColor(hsvo);
- }
- }
-
- public void addColorListener(ColorListener l) {
- mColorListeners.add(l);
- }
-
- public void removeColorListener(ColorListener l) {
- mColorListeners.remove(l);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorPickerDialog.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorPickerDialog.java
deleted file mode 100644
index 73a5c907c..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorPickerDialog.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.graphics.Color;
-import android.graphics.drawable.GradientDrawable;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ToggleButton;
-
-import com.android.gallery3d.R;
-
-public class ColorPickerDialog extends Dialog implements ColorListener {
- ToggleButton mSelectedButton;
- GradientDrawable mSelectRect;
-
- float[] mHSVO = new float[4];
-
- public ColorPickerDialog(Context context, final ColorListener cl) {
- super(context);
-
- setContentView(R.layout.filtershow_color_picker);
- ColorValueView csv = (ColorValueView) findViewById(R.id.colorValueView);
- ColorRectView cwv = (ColorRectView) findViewById(R.id.colorRectView);
- ColorOpacityView cvv = (ColorOpacityView) findViewById(R.id.colorOpacityView);
- float[] hsvo = new float[] {
- 123, .9f, 1, 1 };
-
- mSelectRect = (GradientDrawable) getContext()
- .getResources().getDrawable(R.drawable.filtershow_color_picker_roundrect);
- Button selButton = (Button) findViewById(R.id.btnSelect);
- selButton.setCompoundDrawablesWithIntrinsicBounds(null, null, mSelectRect, null);
- Button sel = (Button) findViewById(R.id.btnSelect);
-
- sel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ColorPickerDialog.this.dismiss();
- if (cl != null) {
- cl.setColor(mHSVO);
- }
- }
- });
-
- cwv.setColor(hsvo);
- cvv.setColor(hsvo);
- csv.setColor(hsvo);
- csv.addColorListener(cwv);
- cwv.addColorListener(csv);
- csv.addColorListener(cvv);
- cwv.addColorListener(cvv);
- cvv.addColorListener(cwv);
- cvv.addColorListener(csv);
- cvv.addColorListener(this);
- csv.addColorListener(this);
- cwv.addColorListener(this);
-
- }
-
- void toggleClick(ToggleButton v, int[] buttons, boolean isChecked) {
- int id = v.getId();
- if (!isChecked) {
- mSelectedButton = null;
- return;
- }
- for (int i = 0; i < buttons.length; i++) {
- if (id != buttons[i]) {
- ToggleButton b = (ToggleButton) findViewById(buttons[i]);
- b.setChecked(false);
- }
- }
- mSelectedButton = v;
-
- float[] hsv = (float[]) v.getTag();
-
- ColorValueView csv = (ColorValueView) findViewById(R.id.colorValueView);
- ColorRectView cwv = (ColorRectView) findViewById(R.id.colorRectView);
- ColorOpacityView cvv = (ColorOpacityView) findViewById(R.id.colorOpacityView);
- cwv.setColor(hsv);
- cvv.setColor(hsv);
- csv.setColor(hsv);
- }
-
- @Override
- public void setColor(float[] hsvo) {
- System.arraycopy(hsvo, 0, mHSVO, 0, mHSVO.length);
- int color = Color.HSVToColor(hsvo);
- mSelectRect.setColor(color);
- setButtonColor(mSelectedButton, hsvo);
- }
-
- private void setButtonColor(ToggleButton button, float[] hsv) {
- if (button == null) {
- return;
- }
- int color = Color.HSVToColor(hsv);
- button.setBackgroundColor(color);
- float[] fg = new float[] {
- (hsv[0] + 180) % 360,
- hsv[1],
- (hsv[2] > .5f) ? .1f : .9f
- };
- button.setTextColor(Color.HSVToColor(fg));
- button.setTag(hsv);
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorRectView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorRectView.java
deleted file mode 100644
index 07d7c7126..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorRectView.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.LinearGradient;
-import android.graphics.Paint;
-import android.graphics.RadialGradient;
-import android.graphics.RectF;
-import android.graphics.Shader;
-import android.graphics.SweepGradient;
-import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.view.MotionEvent;
-import android.view.View;
-
-import com.android.gallery3d.R;
-
-import java.util.ArrayList;
-
-public class ColorRectView extends View implements ColorListener {
- private float mDpToPix;
- private float mRadius = 80;
- private float mCtrY = 100;
- private Paint mWheelPaint1;
- private Paint mWheelPaint2;
- private Paint mWheelPaint3;
- private float mCtrX = 100;
- private Paint mDotPaint;
- private float mDotRadus;
- private float mBorder;
- private int mBgcolor = 0;
- private float mDotX = Float.NaN;
- private float mDotY;
- private int mSliderColor = 0xFF33B5E5;
- private float[] mHSVO = new float[4];
- private int[] mColors = new int[] {
- 0xFFFF0000,// red
- 0xFFFFFF00,// yellow
- 0xFF00FF00,// green
- 0xFF00FFFF,// cyan
- 0xFF0000FF,// blue
- 0xFFFF00FF,// magenta
- 0xFFFF0000,// red
- };
- private int mWidth;
- private int mHeight;
- public final static float DOT_SIZE = 20;
- public final static float BORDER_SIZE = 10;
-
- public ColorRectView(Context ctx, AttributeSet attrs) {
- super(ctx, attrs);
-
- DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
- mDpToPix = metrics.density;
- mDotRadus = DOT_SIZE * mDpToPix;
- mBorder = BORDER_SIZE * mDpToPix;
-
- mWheelPaint1 = new Paint();
- mWheelPaint2 = new Paint();
- mWheelPaint3 = new Paint();
- mDotPaint = new Paint();
-
- mDotPaint.setStyle(Paint.Style.FILL);
- mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
- mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
- mWheelPaint1.setStyle(Paint.Style.FILL);
- mWheelPaint2.setStyle(Paint.Style.FILL);
- mWheelPaint3.setStyle(Paint.Style.FILL);
- }
-
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
-
- invalidate((int) (mDotX - mDotRadus), (int) (mDotY - mDotRadus), (int) (mDotX + mDotRadus),
- (int) (mDotY + mDotRadus));
- float x = event.getX();
- float y = event.getY();
-
- x = Math.max(Math.min(x, mWidth - mBorder), mBorder);
- y = Math.max(Math.min(y, mHeight - mBorder), mBorder);
- mDotX = x;
- mDotY = y;
- float sat = 1 - (mDotY - mBorder) / (mHeight - 2 * mBorder);
- if (sat > 1) {
- sat = 1;
- }
-
- double hue = Math.PI * 2 * (mDotX - mBorder) / (mHeight - 2 * mBorder);
- mHSVO[0] = ((float) Math.toDegrees(hue) + 360) % 360;
- mHSVO[1] = sat;
- notifyColorListeners(mHSVO);
- updateDotPaint();
- invalidate((int) (mDotX - mDotRadus), (int) (mDotY - mDotRadus), (int) (mDotX + mDotRadus),
- (int) (mDotY + mDotRadus));
-
- return true;
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- mWidth = w;
- mHeight = h;
- mCtrY = h / 2f;
- mCtrX = w / 2f;
- mRadius = Math.min(mCtrY, mCtrX) - 2 * mBorder;
- setUpColorPanel();
- }
-
- private void setUpColorPanel() {
- float val = mHSVO[2];
- int v = 0xFF000000 | 0x10101 * (int) (val * 0xFF);
- int[] colors = new int[] {
- 0x0000000, v };
- int[] colors2 = new int[] {
- 0x0000000, 0xFF000000 };
- int[] wheelColor = new int[mColors.length];
- float[] hsv = new float[3];
- for (int i = 0; i < wheelColor.length; i++) {
- Color.colorToHSV(mColors[i], hsv);
- hsv[2] = mHSVO[2];
- wheelColor[i] = Color.HSVToColor(hsv);
- }
- updateDot();
- updateDotPaint();
- SweepGradient sg = new SweepGradient(mCtrX, mCtrY, wheelColor, null);
- LinearGradient lg = new LinearGradient(
- mBorder, 0, mWidth - mBorder, 0, wheelColor, null, Shader.TileMode.CLAMP);
-
- mWheelPaint1.setShader(lg);
- LinearGradient rg = new LinearGradient(
- 0, mBorder, 0, mHeight - mBorder, colors, null, Shader.TileMode.CLAMP);
- mWheelPaint2.setShader(rg);
- LinearGradient rg2 = new LinearGradient(
- 0, mBorder, 0, mHeight - mBorder, colors2, null, Shader.TileMode.CLAMP);
- mWheelPaint3.setShader(rg2);
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawColor(mBgcolor);
- RectF rect = new RectF();
- rect.left = mBorder;
- rect.right = mWidth - mBorder;
- rect.top = mBorder;
- rect.bottom = mHeight - mBorder;
-
- canvas.drawRect(rect, mWheelPaint1);
- canvas.drawRect(rect, mWheelPaint3);
- canvas.drawRect(rect, mWheelPaint2);
-
- if (mDotX != Float.NaN) {
-
- canvas.drawCircle(mDotX, mDotY, mDotRadus, mDotPaint);
- }
- }
-
- private void updateDot() {
-
- double hue = mHSVO[0];
- double sat = mHSVO[1];
-
- mDotX = (float) (mBorder + (mHeight - 2 * mBorder) * Math.toRadians(hue) / (Math.PI * 2));
- mDotY = (float) ((1 - sat) * (mHeight - 2 * mBorder) + mBorder);
-
- }
-
- private void updateDotPaint() {
- int[] colors3 = new int[] {
- mSliderColor, mSliderColor, 0x66000000, 0 };
- RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadus, colors3, new float[] {
- 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
- mDotPaint.setShader(g);
-
- }
-
- @Override
- public void setColor(float[] hsvo) {
- System.arraycopy(hsvo, 0, mHSVO, 0, mHSVO.length);
-
- setUpColorPanel();
- invalidate();
-
- updateDot();
- updateDotPaint();
-
- }
-
- ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
-
- public void notifyColorListeners(float[] hsv) {
- for (ColorListener l : mColorListeners) {
- l.setColor(hsv);
- }
- }
-
- public void addColorListener(ColorListener l) {
- mColorListeners.add(l);
- }
-
- public void removeColorListener(ColorListener l) {
- mColorListeners.remove(l);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java
deleted file mode 100644
index 13cb44bad..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.LinearGradient;
-import android.graphics.Paint;
-import android.graphics.RadialGradient;
-import android.graphics.Shader;
-import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.view.MotionEvent;
-import android.view.View;
-
-import com.android.gallery3d.R;
-
-import java.util.ArrayList;
-
-public class ColorValueView extends View implements ColorListener {
-
- private float mRadius;
- private float mWidth;
- private Paint mBarPaint1;
- private Paint mLinePaint1;
- private Paint mLinePaint2;
- private float mHeight;
- private int mBgcolor = 0;
- private Paint mDotPaint;
- private float dotRadus;
- private float mBorder;
-
- private float[] mHSVO = new float[4];
- private int mSliderColor;
- private float mDotX;
- private float mDotY = mBorder;
- private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
- private final static float BORDER_SIZE = ColorRectView.DOT_SIZE;
-
- public ColorValueView(Context ctx, AttributeSet attrs) {
- super(ctx, attrs);
- DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
- float mDpToPix = metrics.density;
- dotRadus = DOT_SIZE * mDpToPix;
- mBorder = BORDER_SIZE * mDpToPix;
-
- mBarPaint1 = new Paint();
-
- mDotPaint = new Paint();
-
- mDotPaint.setStyle(Paint.Style.FILL);
- mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
-
- mBarPaint1.setStyle(Paint.Style.FILL);
-
- mLinePaint1 = new Paint();
- mLinePaint1.setColor(Color.GRAY);
- mLinePaint2 = new Paint();
- mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
- mLinePaint2.setColor(mSliderColor);
- mLinePaint2.setStrokeWidth(4);
- }
-
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- public boolean onTouchEvent(MotionEvent event) {
- float ox = mDotX;
- float oy = mDotY;
-
- float x = event.getX();
- float y = event.getY();
-
- mDotY = y;
-
- if (mDotY < mBorder) {
- mDotY = mBorder;
- }
-
- if (mDotY > mHeight - mBorder) {
- mDotY = mHeight - mBorder;
- }
- mHSVO[2] = (mDotY - mBorder) / (mHeight - mBorder * 2);
- notifyColorListeners(mHSVO);
- setupButton();
- invalidate((int) (ox - dotRadus), (int) (oy - dotRadus), (int) (ox + dotRadus),
- (int) (oy + dotRadus));
- invalidate((int) (mDotX - dotRadus), (int) (mDotY - dotRadus), (int) (mDotX + dotRadus),
- (int) (mDotY + dotRadus));
-
- return true;
- }
-
- private void setupButton() {
- float pos = mHSVO[2] * (mHeight - mBorder * 2);
- mDotY = pos + mBorder;
-
- int[] colors3 = new int[] {
- mSliderColor, mSliderColor, 0x66000000, 0 };
- RadialGradient g = new RadialGradient(mDotX, mDotY, dotRadus, colors3, new float[] {
- 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
- mDotPaint.setShader(g);
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- mWidth = w;
- mHeight = h;
- mDotX = mWidth / 2;
- updatePaint();
- setupButton();
- }
-
- private void updatePaint() {
- float[] hsv = new float[] {
- mHSVO[0], mHSVO[1], 0f };
- int color1 = Color.HSVToColor(hsv);
- hsv[2] = 1;
- int color2 = Color.HSVToColor(hsv);
-
- Shader sg = new LinearGradient(mBorder, mBorder, mBorder, mHeight - mBorder, color1, color2,
- Shader.TileMode.CLAMP);
- mBarPaint1.setShader(sg);
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawColor(mBgcolor);
- canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mBarPaint1);
- canvas.drawLine(mDotX, mDotY, mDotX, mHeight - mBorder, mLinePaint2);
- canvas.drawLine(mDotX, mBorder, mDotX, mDotY, mLinePaint1);
- if (mDotX != Float.NaN) {
- canvas.drawCircle(mDotX, mDotY, dotRadus, mDotPaint);
- }
- }
-
- @Override
- public void setColor(float[] hsvo) {
- System.arraycopy(hsvo, 0, mHSVO, 0, mHSVO.length);
-
- float oy = mDotY;
- updatePaint();
- setupButton();
- invalidate();
-
- }
-
- ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
-
- public void notifyColorListeners(float[] hsv) {
- for (ColorListener l : mColorListeners) {
- l.setColor(hsv);
- }
- }
-
- public void addColorListener(ColorListener l) {
- mColorListeners.add(l);
- }
-
- public void removeColorListener(ColorListener l) {
- mColorListeners.remove(l);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/RGBListener.java b/src/com/android/gallery3d/filtershow/colorpicker/RGBListener.java
deleted file mode 100644
index 147fb91a4..000000000
--- a/src/com/android/gallery3d/filtershow/colorpicker/RGBListener.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.colorpicker;
-
-public interface RGBListener {
- void setColor(int hsv);
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/ActionSlider.java b/src/com/android/gallery3d/filtershow/controller/ActionSlider.java
deleted file mode 100644
index f80a1cacb..000000000
--- a/src/com/android/gallery3d/filtershow/controller/ActionSlider.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.ImageButton;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.Editor;
-
-public class ActionSlider extends TitledSlider {
- private static final String LOGTAG = "ActionSlider";
- ImageButton mLeftButton;
- ImageButton mRightButton;
- public ActionSlider() {
- mLayoutID = R.layout.filtershow_control_action_slider;
- }
-
- @Override
- public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
- super.setUp(container, parameter, editor);
- mLeftButton = (ImageButton) mTopView.findViewById(R.id.leftActionButton);
- mLeftButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- ((ParameterActionAndInt) mParameter).fireLeftAction();
- }
- });
-
- mRightButton = (ImageButton) mTopView.findViewById(R.id.rightActionButton);
- mRightButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- ((ParameterActionAndInt) mParameter).fireRightAction();
- }
- });
- updateUI();
- }
-
- @Override
- public void updateUI() {
- super.updateUI();
- if (mLeftButton != null) {
- int iconId = ((ParameterActionAndInt) mParameter).getLeftIcon();
- mLeftButton.setImageResource(iconId);
- }
- if (mRightButton != null) {
- int iconId = ((ParameterActionAndInt) mParameter).getRightIcon();
- mRightButton.setImageResource(iconId);
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicParameterInt.java b/src/com/android/gallery3d/filtershow/controller/BasicParameterInt.java
deleted file mode 100644
index 92145e9be..000000000
--- a/src/com/android/gallery3d/filtershow/controller/BasicParameterInt.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.util.Log;
-
-public class BasicParameterInt implements ParameterInteger {
- protected String mParameterName;
- protected Control mControl;
- protected int mMaximum = 100;
- protected int mMinimum = 0;
- protected int mDefaultValue;
- protected int mValue;
- public final int ID;
- protected FilterView mEditor;
- private final String LOGTAG = "BasicParameterInt";
-
- @Override
- public void copyFrom(Parameter src) {
- if (!(src instanceof BasicParameterInt)) {
- throw new IllegalArgumentException(src.getClass().getName());
- }
- BasicParameterInt p = (BasicParameterInt) src;
- mMaximum = p.mMaximum;
- mMinimum = p.mMinimum;
- mDefaultValue = p.mDefaultValue;
- mValue = p.mValue;
- }
-
- public BasicParameterInt(int id, int value) {
- ID = id;
- mValue = value;
- }
-
- public BasicParameterInt(int id, int value, int min, int max) {
- ID = id;
- mValue = value;
- mMinimum = min;
- mMaximum = max;
- }
-
- @Override
- public String getParameterName() {
- return mParameterName;
- }
-
- @Override
- public String getParameterType() {
- return sParameterType;
- }
-
- @Override
- public String getValueString() {
- return mParameterName + mValue;
- }
-
- @Override
- public void setController(Control control) {
- mControl = control;
- }
-
- @Override
- public int getMaximum() {
- return mMaximum;
- }
-
- @Override
- public int getMinimum() {
- return mMinimum;
- }
-
- @Override
- public int getDefaultValue() {
- return mDefaultValue;
- }
-
- @Override
- public int getValue() {
- return mValue;
- }
-
- @Override
- public void setValue(int value) {
- mValue = value;
- if (mEditor != null) {
- mEditor.commitLocalRepresentation();
- }
- }
-
- @Override
- public String toString() {
- return getValueString();
- }
-
- @Override
- public void setFilterView(FilterView editor) {
- mEditor = editor;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java b/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java
deleted file mode 100644
index fb9f95e97..000000000
--- a/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.content.Context;
-
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-
-public class BasicParameterStyle implements ParameterStyles {
- protected String mParameterName;
- protected int mSelectedStyle;
- protected int mNumberOfStyles;
- protected int mDefaultStyle = 0;
- protected Control mControl;
- protected FilterView mEditor;
- public final int ID;
- private final String LOGTAG = "BasicParameterStyle";
-
- @Override
- public void copyFrom(Parameter src) {
- if (!(src instanceof BasicParameterStyle)) {
- throw new IllegalArgumentException(src.getClass().getName());
- }
- BasicParameterStyle p = (BasicParameterStyle) src;
- mNumberOfStyles = p.mNumberOfStyles;
- mSelectedStyle = p.mSelectedStyle;
- mDefaultStyle = p.mDefaultStyle;
- }
-
- public BasicParameterStyle(int id, int numberOfStyles) {
- ID = id;
- mNumberOfStyles = numberOfStyles;
- }
-
- @Override
- public String getParameterName() {
- return mParameterName;
- }
-
- @Override
- public String getParameterType() {
- return sParameterType;
- }
-
- @Override
- public String getValueString() {
- return mParameterName + mSelectedStyle;
- }
-
- @Override
- public void setController(Control control) {
- mControl = control;
- }
-
- @Override
- public int getNumberOfStyles() {
- return mNumberOfStyles;
- }
-
- @Override
- public int getDefaultSelected() {
- return mDefaultStyle;
- }
-
- @Override
- public int getSelected() {
- return mSelectedStyle;
- }
-
- @Override
- public void setSelected(int selectedStyle) {
- mSelectedStyle = selectedStyle;
- if (mEditor != null) {
- mEditor.commitLocalRepresentation();
- }
- }
-
- @Override
- public void getIcon(int index, RenderingRequestCaller caller) {
- mEditor.computeIcon(index, caller);
- }
-
- @Override
- public String getStyleTitle(int index, Context context) {
- return "";
- }
-
- @Override
- public String toString() {
- return getValueString();
- }
-
- @Override
- public void setFilterView(FilterView editor) {
- mEditor = editor;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicSlider.java b/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
deleted file mode 100644
index 9d8278d52..000000000
--- a/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.Editor;
-
-public class BasicSlider implements Control {
- private SeekBar mSeekBar;
- private ParameterInteger mParameter;
- Editor mEditor;
-
- @Override
- public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
- container.removeAllViews();
- mEditor = editor;
- Context context = container.getContext();
- mParameter = (ParameterInteger) parameter;
- LayoutInflater inflater =
- (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- LinearLayout lp = (LinearLayout) inflater.inflate(
- R.layout.filtershow_seekbar, container, true);
- mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar);
-
- updateUI();
- mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- if (mParameter != null) {
- mParameter.setValue(progress + mParameter.getMinimum());
- mEditor.commitLocalRepresentation();
-
- }
- }
- });
- }
-
- @Override
- public View getTopView() {
- return mSeekBar;
- }
-
- @Override
- public void setPrameter(Parameter parameter) {
- mParameter = (ParameterInteger) parameter;
- if (mSeekBar != null) {
- updateUI();
- }
- }
-
- @Override
- public void updateUI() {
- mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum());
- mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum());
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/Control.java b/src/com/android/gallery3d/filtershow/controller/Control.java
deleted file mode 100644
index 43422904c..000000000
--- a/src/com/android/gallery3d/filtershow/controller/Control.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.gallery3d.filtershow.editors.Editor;
-
-public interface Control {
- public void setUp(ViewGroup container, Parameter parameter, Editor editor);
-
- public View getTopView();
-
- public void setPrameter(Parameter parameter);
-
- public void updateUI();
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/FilterView.java b/src/com/android/gallery3d/filtershow/controller/FilterView.java
deleted file mode 100644
index 9ca81dc35..000000000
--- a/src/com/android/gallery3d/filtershow/controller/FilterView.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-
-public interface FilterView {
- public void computeIcon(int index, RenderingRequestCaller caller);
-
- public void commitLocalRepresentation();
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/Parameter.java b/src/com/android/gallery3d/filtershow/controller/Parameter.java
deleted file mode 100644
index 8f4d5c0a5..000000000
--- a/src/com/android/gallery3d/filtershow/controller/Parameter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import com.android.gallery3d.filtershow.editors.Editor;
-
-public interface Parameter {
- String getParameterName();
-
- String getParameterType();
-
- String getValueString();
-
- public void setController(Control c);
-
- public void setFilterView(FilterView editor);
-
- public void copyFrom(Parameter src);
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java b/src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java
deleted file mode 100644
index 8a05c3aa6..000000000
--- a/src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-public interface ParameterActionAndInt extends ParameterInteger {
- static String sParameterType = "ParameterActionAndInt";
-
- public void fireLeftAction();
-
- public int getLeftIcon();
-
- public void fireRightAction();
-
- public int getRightIcon();
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterInteger.java b/src/com/android/gallery3d/filtershow/controller/ParameterInteger.java
deleted file mode 100644
index 0bfd20135..000000000
--- a/src/com/android/gallery3d/filtershow/controller/ParameterInteger.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-public interface ParameterInteger extends Parameter {
- static String sParameterType = "ParameterInteger";
-
- int getMaximum();
-
- int getMinimum();
-
- int getDefaultValue();
-
- int getValue();
-
- void setValue(int value);
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterSet.java b/src/com/android/gallery3d/filtershow/controller/ParameterSet.java
deleted file mode 100644
index 6b50a4d0b..000000000
--- a/src/com/android/gallery3d/filtershow/controller/ParameterSet.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-public interface ParameterSet {
- int getNumberOfParameters();
-
- Parameter getFilterParameter(int index);
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java b/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
deleted file mode 100644
index 7d250a0bf..000000000
--- a/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.content.Context;
-
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-
-public interface ParameterStyles extends Parameter {
- public static String sParameterType = "ParameterStyles";
-
- int getNumberOfStyles();
-
- int getDefaultSelected();
-
- int getSelected();
-
- void setSelected(int value);
-
- void getIcon(int index, RenderingRequestCaller caller);
-
- String getStyleTitle(int index, Context context);
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
deleted file mode 100644
index fb613abc7..000000000
--- a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.android.gallery3d.filtershow.controller;
-
-import android.app.ActionBar.LayoutParams;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageButton;
-import android.widget.ImageView.ScaleType;
-import android.widget.LinearLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequest;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-import com.android.gallery3d.filtershow.editors.Editor;
-
-import java.util.Vector;
-
-public class StyleChooser implements Control {
- private final String LOGTAG = "StyleChooser";
- protected ParameterStyles mParameter;
- protected LinearLayout mLinearLayout;
- protected Editor mEditor;
- private View mTopView;
- private Vector<ImageButton> mIconButton = new Vector<ImageButton>();
- protected int mLayoutID = R.layout.filtershow_control_style_chooser;
-
- @Override
- public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
- container.removeAllViews();
- mEditor = editor;
- Context context = container.getContext();
- mParameter = (ParameterStyles) parameter;
- LayoutInflater inflater =
- (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mTopView = inflater.inflate(mLayoutID, container, true);
- mLinearLayout = (LinearLayout) mTopView.findViewById(R.id.listStyles);
- mTopView.setVisibility(View.VISIBLE);
- int n = mParameter.getNumberOfStyles();
- mIconButton.clear();
- LayoutParams lp = new LayoutParams(120, 120);
- for (int i = 0; i < n; i++) {
- final ImageButton button = new ImageButton(context);
- button.setScaleType(ScaleType.CENTER_CROP);
- button.setLayoutParams(lp);
- button.setBackgroundResource(android.R.color.transparent);
- mIconButton.add(button);
- final int buttonNo = i;
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- mParameter.setSelected(buttonNo);
- }
- });
- mLinearLayout.addView(button);
- mParameter.getIcon(i, new RenderingRequestCaller() {
- @Override
- public void available(RenderingRequest request) {
- Bitmap bmap = request.getBitmap();
- if (bmap == null) {
- return;
- }
- button.setImageBitmap(bmap);
- }
- });
- }
- }
-
- @Override
- public View getTopView() {
- return mTopView;
- }
-
- @Override
- public void setPrameter(Parameter parameter) {
- mParameter = (ParameterStyles) parameter;
- updateUI();
- }
-
- @Override
- public void updateUI() {
- if (mParameter == null) {
- return;
- }
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/controller/TitledSlider.java b/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
deleted file mode 100644
index f29442bb9..000000000
--- a/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.controller;
-
-import android.content.Context;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.Editor;
-
-public class TitledSlider implements Control {
- private final String LOGTAG = "ParametricEditor";
- private SeekBar mSeekBar;
- private TextView mControlName;
- private TextView mControlValue;
- protected ParameterInteger mParameter;
- Editor mEditor;
- View mTopView;
- protected int mLayoutID = R.layout.filtershow_control_title_slider;
-
- @Override
- public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
- container.removeAllViews();
- mEditor = editor;
- Context context = container.getContext();
- mParameter = (ParameterInteger) parameter;
- LayoutInflater inflater =
- (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mTopView = inflater.inflate(mLayoutID, container, true);
- mTopView.setVisibility(View.VISIBLE);
- mSeekBar = (SeekBar) mTopView.findViewById(R.id.controlValueSeekBar);
- mControlName = (TextView) mTopView.findViewById(R.id.controlName);
- mControlValue = (TextView) mTopView.findViewById(R.id.controlValue);
- updateUI();
- mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- if (mParameter != null) {
- mParameter.setValue(progress + mParameter.getMinimum());
- if (mControlName != null) {
- mControlName.setText(mParameter.getParameterName());
- }
- if (mControlValue != null) {
- mControlValue.setText(Integer.toString(mParameter.getValue()));
- }
- mEditor.commitLocalRepresentation();
- }
- }
- });
- }
-
- @Override
- public void setPrameter(Parameter parameter) {
- mParameter = (ParameterInteger) parameter;
- if (mSeekBar != null)
- updateUI();
- }
-
- @Override
- public void updateUI() {
- if (mControlName != null && mParameter.getParameterName() != null) {
- mControlName.setText(mParameter.getParameterName().toUpperCase());
- }
- if (mControlValue != null) {
- mControlValue.setText(
- Integer.toString(mParameter.getValue()));
- }
- mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum());
- mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum());
- mEditor.commitLocalRepresentation();
- }
-
- @Override
- public View getTopView() {
- return mTopView;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/BoundedRect.java b/src/com/android/gallery3d/filtershow/crop/BoundedRect.java
deleted file mode 100644
index 13b8d6de1..000000000
--- a/src/com/android/gallery3d/filtershow/crop/BoundedRect.java
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.crop;
-
-import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.graphics.RectF;
-
-import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
-
-import java.util.Arrays;
-
-/**
- * Maintains invariant that inner rectangle is constrained to be within the
- * outer, rotated rectangle.
- */
-public class BoundedRect {
- private float rot;
- private RectF outer;
- private RectF inner;
- private float[] innerRotated;
-
- public BoundedRect(float rotation, Rect outerRect, Rect innerRect) {
- rot = rotation;
- outer = new RectF(outerRect);
- inner = new RectF(innerRect);
- innerRotated = CropMath.getCornersFromRect(inner);
- rotateInner();
- if (!isConstrained())
- reconstrain();
- }
-
- public BoundedRect(float rotation, RectF outerRect, RectF innerRect) {
- rot = rotation;
- outer = new RectF(outerRect);
- inner = new RectF(innerRect);
- innerRotated = CropMath.getCornersFromRect(inner);
- rotateInner();
- if (!isConstrained())
- reconstrain();
- }
-
- public void resetTo(float rotation, RectF outerRect, RectF innerRect) {
- rot = rotation;
- outer.set(outerRect);
- inner.set(innerRect);
- innerRotated = CropMath.getCornersFromRect(inner);
- rotateInner();
- if (!isConstrained())
- reconstrain();
- }
-
- /**
- * Sets inner, and re-constrains it to fit within the rotated bounding rect.
- */
- public void setInner(RectF newInner) {
- if (inner.equals(newInner))
- return;
- inner = newInner;
- innerRotated = CropMath.getCornersFromRect(inner);
- rotateInner();
- if (!isConstrained())
- reconstrain();
- }
-
- /**
- * Sets rotation, and re-constrains inner to fit within the rotated bounding rect.
- */
- public void setRotation(float rotation) {
- if (rotation == rot)
- return;
- rot = rotation;
- innerRotated = CropMath.getCornersFromRect(inner);
- rotateInner();
- if (!isConstrained())
- reconstrain();
- }
-
- public void setToInner(RectF r) {
- r.set(inner);
- }
-
- public void setToOuter(RectF r) {
- r.set(outer);
- }
-
- public RectF getInner() {
- return new RectF(inner);
- }
-
- public RectF getOuter() {
- return new RectF(outer);
- }
-
- /**
- * Tries to move the inner rectangle by (dx, dy). If this would cause it to leave
- * the bounding rectangle, snaps the inner rectangle to the edge of the bounding
- * rectangle.
- */
- public void moveInner(float dx, float dy) {
- Matrix m0 = getInverseRotMatrix();
-
- RectF translatedInner = new RectF(inner);
- translatedInner.offset(dx, dy);
-
- float[] translatedInnerCorners = CropMath.getCornersFromRect(translatedInner);
- float[] outerCorners = CropMath.getCornersFromRect(outer);
-
- m0.mapPoints(translatedInnerCorners);
- float[] correction = {
- 0, 0
- };
-
- // find correction vectors for corners that have moved out of bounds
- for (int i = 0; i < translatedInnerCorners.length; i += 2) {
- float correctedInnerX = translatedInnerCorners[i] + correction[0];
- float correctedInnerY = translatedInnerCorners[i + 1] + correction[1];
- if (!CropMath.inclusiveContains(outer, correctedInnerX, correctedInnerY)) {
- float[] badCorner = {
- correctedInnerX, correctedInnerY
- };
- float[] nearestSide = CropMath.closestSide(badCorner, outerCorners);
- float[] correctionVec =
- GeometryMathUtils.shortestVectorFromPointToLine(badCorner, nearestSide);
- correction[0] += correctionVec[0];
- correction[1] += correctionVec[1];
- }
- }
-
- for (int i = 0; i < translatedInnerCorners.length; i += 2) {
- float correctedInnerX = translatedInnerCorners[i] + correction[0];
- float correctedInnerY = translatedInnerCorners[i + 1] + correction[1];
- if (!CropMath.inclusiveContains(outer, correctedInnerX, correctedInnerY)) {
- float[] correctionVec = {
- correctedInnerX, correctedInnerY
- };
- CropMath.getEdgePoints(outer, correctionVec);
- correctionVec[0] -= correctedInnerX;
- correctionVec[1] -= correctedInnerY;
- correction[0] += correctionVec[0];
- correction[1] += correctionVec[1];
- }
- }
-
- // Set correction
- for (int i = 0; i < translatedInnerCorners.length; i += 2) {
- float correctedInnerX = translatedInnerCorners[i] + correction[0];
- float correctedInnerY = translatedInnerCorners[i + 1] + correction[1];
- // update translated corners with correction vectors
- translatedInnerCorners[i] = correctedInnerX;
- translatedInnerCorners[i + 1] = correctedInnerY;
- }
-
- innerRotated = translatedInnerCorners;
- // reconstrain to update inner
- reconstrain();
- }
-
- /**
- * Attempts to resize the inner rectangle. If this would cause it to leave
- * the bounding rect, clips the inner rectangle to fit.
- */
- public void resizeInner(RectF newInner) {
- Matrix m = getRotMatrix();
- Matrix m0 = getInverseRotMatrix();
-
- float[] outerCorners = CropMath.getCornersFromRect(outer);
- m.mapPoints(outerCorners);
- float[] oldInnerCorners = CropMath.getCornersFromRect(inner);
- float[] newInnerCorners = CropMath.getCornersFromRect(newInner);
- RectF ret = new RectF(newInner);
-
- for (int i = 0; i < newInnerCorners.length; i += 2) {
- float[] c = {
- newInnerCorners[i], newInnerCorners[i + 1]
- };
- float[] c0 = Arrays.copyOf(c, 2);
- m0.mapPoints(c0);
- if (!CropMath.inclusiveContains(outer, c0[0], c0[1])) {
- float[] outerSide = CropMath.closestSide(c, outerCorners);
- float[] pathOfCorner = {
- newInnerCorners[i], newInnerCorners[i + 1],
- oldInnerCorners[i], oldInnerCorners[i + 1]
- };
- float[] p = GeometryMathUtils.lineIntersect(pathOfCorner, outerSide);
- if (p == null) {
- // lines are parallel or not well defined, so don't resize
- p = new float[2];
- p[0] = oldInnerCorners[i];
- p[1] = oldInnerCorners[i + 1];
- }
- // relies on corners being in same order as method
- // getCornersFromRect
- switch (i) {
- case 0:
- case 1:
- ret.left = (p[0] > ret.left) ? p[0] : ret.left;
- ret.top = (p[1] > ret.top) ? p[1] : ret.top;
- break;
- case 2:
- case 3:
- ret.right = (p[0] < ret.right) ? p[0] : ret.right;
- ret.top = (p[1] > ret.top) ? p[1] : ret.top;
- break;
- case 4:
- case 5:
- ret.right = (p[0] < ret.right) ? p[0] : ret.right;
- ret.bottom = (p[1] < ret.bottom) ? p[1] : ret.bottom;
- break;
- case 6:
- case 7:
- ret.left = (p[0] > ret.left) ? p[0] : ret.left;
- ret.bottom = (p[1] < ret.bottom) ? p[1] : ret.bottom;
- break;
- default:
- break;
- }
- }
- }
- float[] retCorners = CropMath.getCornersFromRect(ret);
- m0.mapPoints(retCorners);
- innerRotated = retCorners;
- // reconstrain to update inner
- reconstrain();
- }
-
- /**
- * Attempts to resize the inner rectangle. If this would cause it to leave
- * the bounding rect, clips the inner rectangle to fit while maintaining
- * aspect ratio.
- */
- public void fixedAspectResizeInner(RectF newInner) {
- Matrix m = getRotMatrix();
- Matrix m0 = getInverseRotMatrix();
-
- float aspectW = inner.width();
- float aspectH = inner.height();
- float aspRatio = aspectW / aspectH;
- float[] corners = CropMath.getCornersFromRect(outer);
-
- m.mapPoints(corners);
- float[] oldInnerCorners = CropMath.getCornersFromRect(inner);
- float[] newInnerCorners = CropMath.getCornersFromRect(newInner);
-
- // find fixed corner
- int fixed = -1;
- if (inner.top == newInner.top) {
- if (inner.left == newInner.left)
- fixed = 0; // top left
- else if (inner.right == newInner.right)
- fixed = 2; // top right
- } else if (inner.bottom == newInner.bottom) {
- if (inner.right == newInner.right)
- fixed = 4; // bottom right
- else if (inner.left == newInner.left)
- fixed = 6; // bottom left
- }
- // no fixed corner, return without update
- if (fixed == -1)
- return;
- float widthSoFar = newInner.width();
- int moved = -1;
- for (int i = 0; i < newInnerCorners.length; i += 2) {
- float[] c = {
- newInnerCorners[i], newInnerCorners[i + 1]
- };
- float[] c0 = Arrays.copyOf(c, 2);
- m0.mapPoints(c0);
- if (!CropMath.inclusiveContains(outer, c0[0], c0[1])) {
- moved = i;
- if (moved == fixed)
- continue;
- float[] l2 = CropMath.closestSide(c, corners);
- float[] l1 = {
- newInnerCorners[i], newInnerCorners[i + 1],
- oldInnerCorners[i], oldInnerCorners[i + 1]
- };
- float[] p = GeometryMathUtils.lineIntersect(l1, l2);
- if (p == null) {
- // lines are parallel or not well defined, so set to old
- // corner
- p = new float[2];
- p[0] = oldInnerCorners[i];
- p[1] = oldInnerCorners[i + 1];
- }
- // relies on corners being in same order as method
- // getCornersFromRect
- float fixed_x = oldInnerCorners[fixed];
- float fixed_y = oldInnerCorners[fixed + 1];
- float newWidth = Math.abs(fixed_x - p[0]);
- float newHeight = Math.abs(fixed_y - p[1]);
- newWidth = Math.max(newWidth, aspRatio * newHeight);
- if (newWidth < widthSoFar)
- widthSoFar = newWidth;
- }
- }
-
- float heightSoFar = widthSoFar / aspRatio;
- RectF ret = new RectF(inner);
- if (fixed == 0) {
- ret.right = ret.left + widthSoFar;
- ret.bottom = ret.top + heightSoFar;
- } else if (fixed == 2) {
- ret.left = ret.right - widthSoFar;
- ret.bottom = ret.top + heightSoFar;
- } else if (fixed == 4) {
- ret.left = ret.right - widthSoFar;
- ret.top = ret.bottom - heightSoFar;
- } else if (fixed == 6) {
- ret.right = ret.left + widthSoFar;
- ret.top = ret.bottom - heightSoFar;
- }
- float[] retCorners = CropMath.getCornersFromRect(ret);
- m0.mapPoints(retCorners);
- innerRotated = retCorners;
- // reconstrain to update inner
- reconstrain();
- }
-
- // internal methods
-
- private boolean isConstrained() {
- for (int i = 0; i < 8; i += 2) {
- if (!CropMath.inclusiveContains(outer, innerRotated[i], innerRotated[i + 1]))
- return false;
- }
- return true;
- }
-
- private void reconstrain() {
- // innerRotated has been changed to have incorrect values
- CropMath.getEdgePoints(outer, innerRotated);
- Matrix m = getRotMatrix();
- float[] unrotated = Arrays.copyOf(innerRotated, 8);
- m.mapPoints(unrotated);
- inner = CropMath.trapToRect(unrotated);
- }
-
- private void rotateInner() {
- Matrix m = getInverseRotMatrix();
- m.mapPoints(innerRotated);
- }
-
- private Matrix getRotMatrix() {
- Matrix m = new Matrix();
- m.setRotate(rot, outer.centerX(), outer.centerY());
- return m;
- }
-
- private Matrix getInverseRotMatrix() {
- Matrix m = new Matrix();
- m.setRotate(-rot, outer.centerX(), outer.centerY());
- return m;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropActivity.java b/src/com/android/gallery3d/filtershow/crop/CropActivity.java
deleted file mode 100644
index 0a0c36703..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropActivity.java
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.app.ActionBar;
-import android.app.Activity;
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.CompressFormat;
-import android.graphics.BitmapFactory;
-import android.graphics.BitmapRegionDecoder;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.provider.MediaStore;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.WindowManager;
-import android.widget.Toast;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.filtershow.cache.ImageLoader;
-import com.android.gallery3d.filtershow.tools.SaveImage;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Activity for cropping an image.
- */
-public class CropActivity extends Activity {
- private static final String LOGTAG = "CropActivity";
- public static final String CROP_ACTION = "com.android.camera.action.CROP";
- private CropExtras mCropExtras = null;
- private LoadBitmapTask mLoadBitmapTask = null;
-
- private int mOutputX = 0;
- private int mOutputY = 0;
- private Bitmap mOriginalBitmap = null;
- private RectF mOriginalBounds = null;
- private int mOriginalRotation = 0;
- private Uri mSourceUri = null;
- private CropView mCropView = null;
- private View mSaveButton = null;
- private boolean finalIOGuard = false;
-
- private static final int SELECT_PICTURE = 1; // request code for picker
-
- private static final int DEFAULT_COMPRESS_QUALITY = 90;
- /**
- * The maximum bitmap size we allow to be returned through the intent.
- * Intents have a maximum of 1MB in total size. However, the Bitmap seems to
- * have some overhead to hit so that we go way below the limit here to make
- * sure the intent stays below 1MB.We should consider just returning a byte
- * array instead of a Bitmap instance to avoid overhead.
- */
- public static final int MAX_BMAP_IN_INTENT = 750000;
-
- // Flags
- private static final int DO_SET_WALLPAPER = 1;
- private static final int DO_RETURN_DATA = 1 << 1;
- private static final int DO_EXTRA_OUTPUT = 1 << 2;
-
- private static final int FLAG_CHECK = DO_SET_WALLPAPER | DO_RETURN_DATA | DO_EXTRA_OUTPUT;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent intent = getIntent();
- setResult(RESULT_CANCELED, new Intent());
- mCropExtras = getExtrasFromIntent(intent);
- if (mCropExtras != null && mCropExtras.getShowWhenLocked()) {
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
- }
-
- setContentView(R.layout.crop_activity);
- mCropView = (CropView) findViewById(R.id.cropView);
-
- ActionBar actionBar = getActionBar();
- actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
- actionBar.setCustomView(R.layout.filtershow_actionbar);
-
- View mSaveButton = actionBar.getCustomView();
- mSaveButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- startFinishOutput();
- }
- });
-
- if (intent.getData() != null) {
- mSourceUri = intent.getData();
- startLoadBitmap(mSourceUri);
- } else {
- pickImage();
- }
- }
-
- private void enableSave(boolean enable) {
- if (mSaveButton != null) {
- mSaveButton.setEnabled(enable);
- }
- }
-
- @Override
- protected void onDestroy() {
- if (mLoadBitmapTask != null) {
- mLoadBitmapTask.cancel(false);
- }
- super.onDestroy();
- }
-
- @Override
- public void onConfigurationChanged (Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- mCropView.configChanged();
- }
-
- /**
- * Opens a selector in Gallery to chose an image for use when none was given
- * in the CROP intent.
- */
- private void pickImage() {
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);
- startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
- SELECT_PICTURE);
- }
-
- /**
- * Callback for pickImage().
- */
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK && requestCode == SELECT_PICTURE) {
- mSourceUri = data.getData();
- startLoadBitmap(mSourceUri);
- }
- }
-
- /**
- * Gets screen size metric.
- */
- private int getScreenImageSize() {
- DisplayMetrics outMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
- return (int) Math.max(outMetrics.heightPixels, outMetrics.widthPixels);
- }
-
- /**
- * Method that loads a bitmap in an async task.
- */
- private void startLoadBitmap(Uri uri) {
- if (uri != null) {
- enableSave(false);
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.VISIBLE);
- mLoadBitmapTask = new LoadBitmapTask();
- mLoadBitmapTask.execute(uri);
- } else {
- cannotLoadImage();
- done();
- }
- }
-
- /**
- * Method called on UI thread with loaded bitmap.
- */
- private void doneLoadBitmap(Bitmap bitmap, RectF bounds, int orientation) {
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.GONE);
- mOriginalBitmap = bitmap;
- mOriginalBounds = bounds;
- mOriginalRotation = orientation;
- if (bitmap != null && bitmap.getWidth() != 0 && bitmap.getHeight() != 0) {
- RectF imgBounds = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
- mCropView.initialize(bitmap, imgBounds, imgBounds, orientation);
- if (mCropExtras != null) {
- int aspectX = mCropExtras.getAspectX();
- int aspectY = mCropExtras.getAspectY();
- mOutputX = mCropExtras.getOutputX();
- mOutputY = mCropExtras.getOutputY();
- if (mOutputX > 0 && mOutputY > 0) {
- mCropView.applyAspect(mOutputX, mOutputY);
-
- }
- float spotX = mCropExtras.getSpotlightX();
- float spotY = mCropExtras.getSpotlightY();
- if (spotX > 0 && spotY > 0) {
- mCropView.setWallpaperSpotlight(spotX, spotY);
- }
- if (aspectX > 0 && aspectY > 0) {
- mCropView.applyAspect(aspectX, aspectY);
- }
- }
- enableSave(true);
- } else {
- Log.w(LOGTAG, "could not load image for cropping");
- cannotLoadImage();
- setResult(RESULT_CANCELED, new Intent());
- done();
- }
- }
-
- /**
- * Display toast for image loading failure.
- */
- private void cannotLoadImage() {
- CharSequence text = getString(R.string.cannot_load_image);
- Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
- toast.show();
- }
-
- /**
- * AsyncTask for loading a bitmap into memory.
- *
- * @see #startLoadBitmap(Uri)
- * @see #doneLoadBitmap(Bitmap)
- */
- private class LoadBitmapTask extends AsyncTask<Uri, Void, Bitmap> {
- int mBitmapSize;
- Context mContext;
- Rect mOriginalBounds;
- int mOrientation;
-
- public LoadBitmapTask() {
- mBitmapSize = getScreenImageSize();
- mContext = getApplicationContext();
- mOriginalBounds = new Rect();
- mOrientation = 0;
- }
-
- @Override
- protected Bitmap doInBackground(Uri... params) {
- Uri uri = params[0];
- Bitmap bmap = ImageLoader.loadConstrainedBitmap(uri, mContext, mBitmapSize,
- mOriginalBounds, false);
- mOrientation = ImageLoader.getMetadataRotation(mContext, uri);
- return bmap;
- }
-
- @Override
- protected void onPostExecute(Bitmap result) {
- doneLoadBitmap(result, new RectF(mOriginalBounds), mOrientation);
- }
- }
-
- private void startFinishOutput() {
- if (finalIOGuard) {
- return;
- } else {
- finalIOGuard = true;
- }
- enableSave(false);
- Uri destinationUri = null;
- int flags = 0;
- if (mOriginalBitmap != null && mCropExtras != null) {
- if (mCropExtras.getExtraOutput() != null) {
- destinationUri = mCropExtras.getExtraOutput();
- if (destinationUri != null) {
- flags |= DO_EXTRA_OUTPUT;
- }
- }
- if (mCropExtras.getSetAsWallpaper()) {
- flags |= DO_SET_WALLPAPER;
- }
- if (mCropExtras.getReturnData()) {
- flags |= DO_RETURN_DATA;
- }
- }
- if (flags == 0) {
- destinationUri = SaveImage.makeAndInsertUri(this, mSourceUri);
- if (destinationUri != null) {
- flags |= DO_EXTRA_OUTPUT;
- }
- }
- if ((flags & FLAG_CHECK) != 0 && mOriginalBitmap != null) {
- RectF photo = new RectF(0, 0, mOriginalBitmap.getWidth(), mOriginalBitmap.getHeight());
- RectF crop = getBitmapCrop(photo);
- startBitmapIO(flags, mOriginalBitmap, mSourceUri, destinationUri, crop,
- photo, mOriginalBounds,
- (mCropExtras == null) ? null : mCropExtras.getOutputFormat(), mOriginalRotation);
- return;
- }
- setResult(RESULT_CANCELED, new Intent());
- done();
- return;
- }
-
- private void startBitmapIO(int flags, Bitmap currentBitmap, Uri sourceUri, Uri destUri,
- RectF cropBounds, RectF photoBounds, RectF currentBitmapBounds, String format,
- int rotation) {
- if (cropBounds == null || photoBounds == null || currentBitmap == null
- || currentBitmap.getWidth() == 0 || currentBitmap.getHeight() == 0
- || cropBounds.width() == 0 || cropBounds.height() == 0 || photoBounds.width() == 0
- || photoBounds.height() == 0) {
- return; // fail fast
- }
- if ((flags & FLAG_CHECK) == 0) {
- return; // no output options
- }
- if ((flags & DO_SET_WALLPAPER) != 0) {
- Toast.makeText(this, R.string.setting_wallpaper, Toast.LENGTH_LONG).show();
- }
-
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.VISIBLE);
- BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds,
- photoBounds, currentBitmapBounds, rotation, mOutputX, mOutputY);
- ioTask.execute(currentBitmap);
- }
-
- private void doneBitmapIO(boolean success, Intent intent) {
- final View loading = findViewById(R.id.loading);
- loading.setVisibility(View.GONE);
- if (success) {
- setResult(RESULT_OK, intent);
- } else {
- setResult(RESULT_CANCELED, intent);
- }
- done();
- }
-
- private class BitmapIOTask extends AsyncTask<Bitmap, Void, Boolean> {
-
- private final WallpaperManager mWPManager;
- InputStream mInStream = null;
- OutputStream mOutStream = null;
- String mOutputFormat = null;
- Uri mOutUri = null;
- Uri mInUri = null;
- int mFlags = 0;
- RectF mCrop = null;
- RectF mPhoto = null;
- RectF mOrig = null;
- Intent mResultIntent = null;
- int mRotation = 0;
-
- // Helper to setup input stream
- private void regenerateInputStream() {
- if (mInUri == null) {
- Log.w(LOGTAG, "cannot read original file, no input URI given");
- } else {
- Utils.closeSilently(mInStream);
- try {
- mInStream = getContentResolver().openInputStream(mInUri);
- } catch (FileNotFoundException e) {
- Log.w(LOGTAG, "cannot read file: " + mInUri.toString(), e);
- }
- }
- }
-
- public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags,
- RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds, int rotation,
- int outputX, int outputY) {
- mOutputFormat = outputFormat;
- mOutStream = null;
- mOutUri = destUri;
- mInUri = sourceUri;
- mFlags = flags;
- mCrop = cropBounds;
- mPhoto = photoBounds;
- mOrig = originalBitmapBounds;
- mWPManager = WallpaperManager.getInstance(getApplicationContext());
- mResultIntent = new Intent();
- mRotation = (rotation < 0) ? -rotation : rotation;
- mRotation %= 360;
- mRotation = 90 * (int) (mRotation / 90); // now mRotation is a multiple of 90
- mOutputX = outputX;
- mOutputY = outputY;
-
- if ((flags & DO_EXTRA_OUTPUT) != 0) {
- if (mOutUri == null) {
- Log.w(LOGTAG, "cannot write file, no output URI given");
- } else {
- try {
- mOutStream = getContentResolver().openOutputStream(mOutUri);
- } catch (FileNotFoundException e) {
- Log.w(LOGTAG, "cannot write file: " + mOutUri.toString(), e);
- }
- }
- }
-
- if ((flags & (DO_EXTRA_OUTPUT | DO_SET_WALLPAPER)) != 0) {
- regenerateInputStream();
- }
- }
-
- @Override
- protected Boolean doInBackground(Bitmap... params) {
- boolean failure = false;
- Bitmap img = params[0];
-
- // Set extra for crop bounds
- if (mCrop != null && mPhoto != null && mOrig != null) {
- RectF trueCrop = CropMath.getScaledCropBounds(mCrop, mPhoto, mOrig);
- Matrix m = new Matrix();
- m.setRotate(mRotation);
- m.mapRect(trueCrop);
- if (trueCrop != null) {
- Rect rounded = new Rect();
- trueCrop.roundOut(rounded);
- mResultIntent.putExtra(CropExtras.KEY_CROPPED_RECT, rounded);
- }
- }
-
- // Find the small cropped bitmap that is returned in the intent
- if ((mFlags & DO_RETURN_DATA) != 0) {
- assert (img != null);
- Bitmap ret = getCroppedImage(img, mCrop, mPhoto);
- if (ret != null) {
- ret = getDownsampledBitmap(ret, MAX_BMAP_IN_INTENT);
- }
- if (ret == null) {
- Log.w(LOGTAG, "could not downsample bitmap to return in data");
- failure = true;
- } else {
- if (mRotation > 0) {
- Matrix m = new Matrix();
- m.setRotate(mRotation);
- Bitmap tmp = Bitmap.createBitmap(ret, 0, 0, ret.getWidth(),
- ret.getHeight(), m, true);
- if (tmp != null) {
- ret = tmp;
- }
- }
- mResultIntent.putExtra(CropExtras.KEY_DATA, ret);
- }
- }
-
- // Do the large cropped bitmap and/or set the wallpaper
- if ((mFlags & (DO_EXTRA_OUTPUT | DO_SET_WALLPAPER)) != 0 && mInStream != null) {
- // Find crop bounds (scaled to original image size)
- RectF trueCrop = CropMath.getScaledCropBounds(mCrop, mPhoto, mOrig);
- if (trueCrop == null) {
- Log.w(LOGTAG, "cannot find crop for full size image");
- failure = true;
- return false;
- }
- Rect roundedTrueCrop = new Rect();
- trueCrop.roundOut(roundedTrueCrop);
-
- if (roundedTrueCrop.width() <= 0 || roundedTrueCrop.height() <= 0) {
- Log.w(LOGTAG, "crop has bad values for full size image");
- failure = true;
- return false;
- }
-
- // Attempt to open a region decoder
- BitmapRegionDecoder decoder = null;
- try {
- decoder = BitmapRegionDecoder.newInstance(mInStream, true);
- } catch (IOException e) {
- Log.w(LOGTAG, "cannot open region decoder for file: " + mInUri.toString(), e);
- }
-
- Bitmap crop = null;
- if (decoder != null) {
- // Do region decoding to get crop bitmap
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inMutable = true;
- crop = decoder.decodeRegion(roundedTrueCrop, options);
- decoder.recycle();
- }
-
- if (crop == null) {
- // BitmapRegionDecoder has failed, try to crop in-memory
- regenerateInputStream();
- Bitmap fullSize = null;
- if (mInStream != null) {
- fullSize = BitmapFactory.decodeStream(mInStream);
- }
- if (fullSize != null) {
- crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left,
- roundedTrueCrop.top, roundedTrueCrop.width(),
- roundedTrueCrop.height());
- }
- }
-
- if (crop == null) {
- Log.w(LOGTAG, "cannot decode file: " + mInUri.toString());
- failure = true;
- return false;
- }
- if (mOutputX > 0 && mOutputY > 0) {
- Matrix m = new Matrix();
- RectF cropRect = new RectF(0, 0, crop.getWidth(), crop.getHeight());
- if (mRotation > 0) {
- m.setRotate(mRotation);
- m.mapRect(cropRect);
- }
- RectF returnRect = new RectF(0, 0, mOutputX, mOutputY);
- m.setRectToRect(cropRect, returnRect, Matrix.ScaleToFit.FILL);
- m.preRotate(mRotation);
- Bitmap tmp = Bitmap.createBitmap((int) returnRect.width(),
- (int) returnRect.height(), Bitmap.Config.ARGB_8888);
- if (tmp != null) {
- Canvas c = new Canvas(tmp);
- c.drawBitmap(crop, m, new Paint());
- crop = tmp;
- }
- } else if (mRotation > 0) {
- Matrix m = new Matrix();
- m.setRotate(mRotation);
- Bitmap tmp = Bitmap.createBitmap(crop, 0, 0, crop.getWidth(),
- crop.getHeight(), m, true);
- if (tmp != null) {
- crop = tmp;
- }
- }
- // Get output compression format
- CompressFormat cf =
- convertExtensionToCompressFormat(getFileExtension(mOutputFormat));
-
- // If we only need to output to a URI, compress straight to file
- if (mFlags == DO_EXTRA_OUTPUT) {
- if (mOutStream == null
- || !crop.compress(cf, DEFAULT_COMPRESS_QUALITY, mOutStream)) {
- Log.w(LOGTAG, "failed to compress bitmap to file: " + mOutUri.toString());
- failure = true;
- } else {
- mResultIntent.setData(mOutUri);
- }
- } else {
- // Compress to byte array
- ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
- if (crop.compress(cf, DEFAULT_COMPRESS_QUALITY, tmpOut)) {
-
- // If we need to output to a Uri, write compressed
- // bitmap out
- if ((mFlags & DO_EXTRA_OUTPUT) != 0) {
- if (mOutStream == null) {
- Log.w(LOGTAG,
- "failed to compress bitmap to file: " + mOutUri.toString());
- failure = true;
- } else {
- try {
- mOutStream.write(tmpOut.toByteArray());
- mResultIntent.setData(mOutUri);
- } catch (IOException e) {
- Log.w(LOGTAG,
- "failed to compress bitmap to file: "
- + mOutUri.toString(), e);
- failure = true;
- }
- }
- }
-
- // If we need to set to the wallpaper, set it
- if ((mFlags & DO_SET_WALLPAPER) != 0 && mWPManager != null) {
- if (mWPManager == null) {
- Log.w(LOGTAG, "no wallpaper manager");
- failure = true;
- } else {
- try {
- mWPManager.setStream(new ByteArrayInputStream(tmpOut
- .toByteArray()));
- } catch (IOException e) {
- Log.w(LOGTAG, "cannot write stream to wallpaper", e);
- failure = true;
- }
- }
- }
- } else {
- Log.w(LOGTAG, "cannot compress bitmap");
- failure = true;
- }
- }
- }
- return !failure; // True if any of the operations failed
- }
-
- @Override
- protected void onPostExecute(Boolean result) {
- Utils.closeSilently(mOutStream);
- Utils.closeSilently(mInStream);
- doneBitmapIO(result.booleanValue(), mResultIntent);
- }
-
- }
-
- private void done() {
- finish();
- }
-
- protected static Bitmap getCroppedImage(Bitmap image, RectF cropBounds, RectF photoBounds) {
- RectF imageBounds = new RectF(0, 0, image.getWidth(), image.getHeight());
- RectF crop = CropMath.getScaledCropBounds(cropBounds, photoBounds, imageBounds);
- if (crop == null) {
- return null;
- }
- Rect intCrop = new Rect();
- crop.roundOut(intCrop);
- return Bitmap.createBitmap(image, intCrop.left, intCrop.top, intCrop.width(),
- intCrop.height());
- }
-
- protected static Bitmap getDownsampledBitmap(Bitmap image, int max_size) {
- if (image == null || image.getWidth() == 0 || image.getHeight() == 0 || max_size < 16) {
- throw new IllegalArgumentException("Bad argument to getDownsampledBitmap()");
- }
- int shifts = 0;
- int size = CropMath.getBitmapSize(image);
- while (size > max_size) {
- shifts++;
- size /= 4;
- }
- Bitmap ret = Bitmap.createScaledBitmap(image, image.getWidth() >> shifts,
- image.getHeight() >> shifts, true);
- if (ret == null) {
- return null;
- }
- // Handle edge case for rounding.
- if (CropMath.getBitmapSize(ret) > max_size) {
- return Bitmap.createScaledBitmap(ret, ret.getWidth() >> 1, ret.getHeight() >> 1, true);
- }
- return ret;
- }
-
- /**
- * Gets the crop extras from the intent, or null if none exist.
- */
- protected static CropExtras getExtrasFromIntent(Intent intent) {
- Bundle extras = intent.getExtras();
- if (extras != null) {
- return new CropExtras(extras.getInt(CropExtras.KEY_OUTPUT_X, 0),
- extras.getInt(CropExtras.KEY_OUTPUT_Y, 0),
- extras.getBoolean(CropExtras.KEY_SCALE, true) &&
- extras.getBoolean(CropExtras.KEY_SCALE_UP_IF_NEEDED, false),
- extras.getInt(CropExtras.KEY_ASPECT_X, 0),
- extras.getInt(CropExtras.KEY_ASPECT_Y, 0),
- extras.getBoolean(CropExtras.KEY_SET_AS_WALLPAPER, false),
- extras.getBoolean(CropExtras.KEY_RETURN_DATA, false),
- (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT),
- extras.getString(CropExtras.KEY_OUTPUT_FORMAT),
- extras.getBoolean(CropExtras.KEY_SHOW_WHEN_LOCKED, false),
- extras.getFloat(CropExtras.KEY_SPOTLIGHT_X),
- extras.getFloat(CropExtras.KEY_SPOTLIGHT_Y));
- }
- return null;
- }
-
- protected static CompressFormat convertExtensionToCompressFormat(String extension) {
- return extension.equals("png") ? CompressFormat.PNG : CompressFormat.JPEG;
- }
-
- protected static String getFileExtension(String requestFormat) {
- String outputFormat = (requestFormat == null)
- ? "jpg"
- : requestFormat;
- outputFormat = outputFormat.toLowerCase();
- return (outputFormat.equals("png") || outputFormat.equals("gif"))
- ? "png" // We don't support gif compression.
- : "jpg";
- }
-
- private RectF getBitmapCrop(RectF imageBounds) {
- RectF crop = mCropView.getCrop();
- RectF photo = mCropView.getPhoto();
- if (crop == null || photo == null) {
- Log.w(LOGTAG, "could not get crop");
- return null;
- }
- RectF scaledCrop = CropMath.getScaledCropBounds(crop, photo, imageBounds);
- return scaledCrop;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java b/src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java
deleted file mode 100644
index b0d324cbb..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Path;
-import android.graphics.RectF;
-import android.graphics.Region;
-import android.graphics.drawable.Drawable;
-
-public abstract class CropDrawingUtils {
-
- public static void drawRuleOfThird(Canvas canvas, RectF bounds) {
- Paint p = new Paint();
- p.setStyle(Paint.Style.STROKE);
- p.setColor(Color.argb(128, 255, 255, 255));
- p.setStrokeWidth(2);
- float stepX = bounds.width() / 3.0f;
- float stepY = bounds.height() / 3.0f;
- float x = bounds.left + stepX;
- float y = bounds.top + stepY;
- for (int i = 0; i < 2; i++) {
- canvas.drawLine(x, bounds.top, x, bounds.bottom, p);
- x += stepX;
- }
- for (int j = 0; j < 2; j++) {
- canvas.drawLine(bounds.left, y, bounds.right, y, p);
- y += stepY;
- }
- }
-
- public static void drawCropRect(Canvas canvas, RectF bounds) {
- Paint p = new Paint();
- p.setStyle(Paint.Style.STROKE);
- p.setColor(Color.WHITE);
- p.setStrokeWidth(3);
- canvas.drawRect(bounds, p);
- }
-
- public static void drawIndicator(Canvas canvas, Drawable indicator, int indicatorSize,
- float centerX, float centerY) {
- int left = (int) centerX - indicatorSize / 2;
- int top = (int) centerY - indicatorSize / 2;
- indicator.setBounds(left, top, left + indicatorSize, top + indicatorSize);
- indicator.draw(canvas);
- }
-
- public static void drawIndicators(Canvas canvas, Drawable cropIndicator, int indicatorSize,
- RectF bounds, boolean fixedAspect, int selection) {
- boolean notMoving = (selection == CropObject.MOVE_NONE);
- if (fixedAspect) {
- if ((selection == CropObject.TOP_LEFT) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.left, bounds.top);
- }
- if ((selection == CropObject.TOP_RIGHT) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.right, bounds.top);
- }
- if ((selection == CropObject.BOTTOM_LEFT) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.left, bounds.bottom);
- }
- if ((selection == CropObject.BOTTOM_RIGHT) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.right, bounds.bottom);
- }
- } else {
- if (((selection & CropObject.MOVE_TOP) != 0) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.centerX(), bounds.top);
- }
- if (((selection & CropObject.MOVE_BOTTOM) != 0) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.centerX(), bounds.bottom);
- }
- if (((selection & CropObject.MOVE_LEFT) != 0) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.left, bounds.centerY());
- }
- if (((selection & CropObject.MOVE_RIGHT) != 0) || notMoving) {
- drawIndicator(canvas, cropIndicator, indicatorSize, bounds.right, bounds.centerY());
- }
- }
- }
-
- public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX,
- float spotY, Paint p, Paint shadowPaint) {
- float sx = cropBounds.width() * spotX;
- float sy = cropBounds.height() * spotY;
- float cx = cropBounds.centerX();
- float cy = cropBounds.centerY();
- RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
- float temp = sx;
- sx = sy;
- sy = temp;
- RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
- canvas.save();
- canvas.clipRect(cropBounds);
- canvas.clipRect(r1, Region.Op.DIFFERENCE);
- canvas.clipRect(r2, Region.Op.DIFFERENCE);
- canvas.drawPaint(shadowPaint);
- canvas.restore();
- Path path = new Path();
- path.moveTo(r1.left, r1.top);
- path.lineTo(r1.right, r1.top);
- path.moveTo(r1.left, r1.top);
- path.lineTo(r1.left, r1.bottom);
- path.moveTo(r1.left, r1.bottom);
- path.lineTo(r1.right, r1.bottom);
- path.moveTo(r1.right, r1.top);
- path.lineTo(r1.right, r1.bottom);
- path.moveTo(r2.left, r2.top);
- path.lineTo(r2.right, r2.top);
- path.moveTo(r2.right, r2.top);
- path.lineTo(r2.right, r2.bottom);
- path.moveTo(r2.left, r2.bottom);
- path.lineTo(r2.right, r2.bottom);
- path.moveTo(r2.left, r2.top);
- path.lineTo(r2.left, r2.bottom);
- canvas.drawPath(path, p);
- }
-
- public static void drawShadows(Canvas canvas, Paint p, RectF innerBounds, RectF outerBounds) {
- canvas.drawRect(outerBounds.left, outerBounds.top, innerBounds.right, innerBounds.top, p);
- canvas.drawRect(innerBounds.right, outerBounds.top, outerBounds.right, innerBounds.bottom,
- p);
- canvas.drawRect(innerBounds.left, innerBounds.bottom, outerBounds.right,
- outerBounds.bottom, p);
- canvas.drawRect(outerBounds.left, innerBounds.top, innerBounds.left, outerBounds.bottom, p);
- }
-
- public static Matrix getBitmapToDisplayMatrix(RectF imageBounds, RectF displayBounds) {
- Matrix m = new Matrix();
- CropDrawingUtils.setBitmapToDisplayMatrix(m, imageBounds, displayBounds);
- return m;
- }
-
- public static boolean setBitmapToDisplayMatrix(Matrix m, RectF imageBounds,
- RectF displayBounds) {
- m.reset();
- return m.setRectToRect(imageBounds, displayBounds, Matrix.ScaleToFit.CENTER);
- }
-
- public static boolean setImageToScreenMatrix(Matrix dst, RectF image,
- RectF screen, int rotation) {
- RectF rotatedImage = new RectF();
- dst.setRotate(rotation, image.centerX(), image.centerY());
- if (!dst.mapRect(rotatedImage, image)) {
- return false; // fails for rotations that are not multiples of 90
- // degrees
- }
- boolean rToR = dst.setRectToRect(rotatedImage, screen, Matrix.ScaleToFit.CENTER);
- boolean rot = dst.preRotate(rotation, image.centerX(), image.centerY());
- return rToR && rot;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropExtras.java b/src/com/android/gallery3d/filtershow/crop/CropExtras.java
deleted file mode 100644
index 60fe9af53..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropExtras.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.net.Uri;
-
-public class CropExtras {
-
- public static final String KEY_CROPPED_RECT = "cropped-rect";
- public static final String KEY_OUTPUT_X = "outputX";
- public static final String KEY_OUTPUT_Y = "outputY";
- public static final String KEY_SCALE = "scale";
- public static final String KEY_SCALE_UP_IF_NEEDED = "scaleUpIfNeeded";
- public static final String KEY_ASPECT_X = "aspectX";
- public static final String KEY_ASPECT_Y = "aspectY";
- public static final String KEY_SET_AS_WALLPAPER = "set-as-wallpaper";
- public static final String KEY_RETURN_DATA = "return-data";
- public static final String KEY_DATA = "data";
- public static final String KEY_SPOTLIGHT_X = "spotlightX";
- public static final String KEY_SPOTLIGHT_Y = "spotlightY";
- public static final String KEY_SHOW_WHEN_LOCKED = "showWhenLocked";
- public static final String KEY_OUTPUT_FORMAT = "outputFormat";
-
- private int mOutputX = 0;
- private int mOutputY = 0;
- private boolean mScaleUp = true;
- private int mAspectX = 0;
- private int mAspectY = 0;
- private boolean mSetAsWallpaper = false;
- private boolean mReturnData = false;
- private Uri mExtraOutput = null;
- private String mOutputFormat = null;
- private boolean mShowWhenLocked = false;
- private float mSpotlightX = 0;
- private float mSpotlightY = 0;
-
- public CropExtras(int outputX, int outputY, boolean scaleUp, int aspectX, int aspectY,
- boolean setAsWallpaper, boolean returnData, Uri extraOutput, String outputFormat,
- boolean showWhenLocked, float spotlightX, float spotlightY) {
- mOutputX = outputX;
- mOutputY = outputY;
- mScaleUp = scaleUp;
- mAspectX = aspectX;
- mAspectY = aspectY;
- mSetAsWallpaper = setAsWallpaper;
- mReturnData = returnData;
- mExtraOutput = extraOutput;
- mOutputFormat = outputFormat;
- mShowWhenLocked = showWhenLocked;
- mSpotlightX = spotlightX;
- mSpotlightY = spotlightY;
- }
-
- public CropExtras(CropExtras c) {
- this(c.mOutputX, c.mOutputY, c.mScaleUp, c.mAspectX, c.mAspectY, c.mSetAsWallpaper,
- c.mReturnData, c.mExtraOutput, c.mOutputFormat, c.mShowWhenLocked,
- c.mSpotlightX, c.mSpotlightY);
- }
-
- public int getOutputX() {
- return mOutputX;
- }
-
- public int getOutputY() {
- return mOutputY;
- }
-
- public boolean getScaleUp() {
- return mScaleUp;
- }
-
- public int getAspectX() {
- return mAspectX;
- }
-
- public int getAspectY() {
- return mAspectY;
- }
-
- public boolean getSetAsWallpaper() {
- return mSetAsWallpaper;
- }
-
- public boolean getReturnData() {
- return mReturnData;
- }
-
- public Uri getExtraOutput() {
- return mExtraOutput;
- }
-
- public String getOutputFormat() {
- return mOutputFormat;
- }
-
- public boolean getShowWhenLocked() {
- return mShowWhenLocked;
- }
-
- public float getSpotlightX() {
- return mSpotlightX;
- }
-
- public float getSpotlightY() {
- return mSpotlightY;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropMath.java b/src/com/android/gallery3d/filtershow/crop/CropMath.java
deleted file mode 100644
index 02c65310e..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropMath.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.graphics.Bitmap;
-import android.graphics.Matrix;
-import android.graphics.RectF;
-
-import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
-
-import java.util.Arrays;
-
-public class CropMath {
-
- /**
- * Gets a float array of the 2D coordinates representing a rectangles
- * corners.
- * The order of the corners in the float array is:
- * 0------->1
- * ^ |
- * | v
- * 3<-------2
- *
- * @param r the rectangle to get the corners of
- * @return the float array of corners (8 floats)
- */
-
- public static float[] getCornersFromRect(RectF r) {
- float[] corners = {
- r.left, r.top,
- r.right, r.top,
- r.right, r.bottom,
- r.left, r.bottom
- };
- return corners;
- }
-
- /**
- * Returns true iff point (x, y) is within or on the rectangle's bounds.
- * RectF's "contains" function treats points on the bottom and right bound
- * as not being contained.
- *
- * @param r the rectangle
- * @param x the x value of the point
- * @param y the y value of the point
- * @return
- */
- public static boolean inclusiveContains(RectF r, float x, float y) {
- return !(x > r.right || x < r.left || y > r.bottom || y < r.top);
- }
-
- /**
- * Takes an array of 2D coordinates representing corners and returns the
- * smallest rectangle containing those coordinates.
- *
- * @param array array of 2D coordinates
- * @return smallest rectangle containing coordinates
- */
- public static RectF trapToRect(float[] array) {
- RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
- Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
- for (int i = 1; i < array.length; i += 2) {
- float x = array[i - 1];
- float y = array[i];
- r.left = (x < r.left) ? x : r.left;
- r.top = (y < r.top) ? y : r.top;
- r.right = (x > r.right) ? x : r.right;
- r.bottom = (y > r.bottom) ? y : r.bottom;
- }
- r.sort();
- return r;
- }
-
- /**
- * If edge point [x, y] in array [x0, y0, x1, y1, ...] is outside of the
- * image bound rectangle, clamps it to the edge of the rectangle.
- *
- * @param imageBound the rectangle to clamp edge points to.
- * @param array an array of points to clamp to the rectangle, gets set to
- * the clamped values.
- */
- public static void getEdgePoints(RectF imageBound, float[] array) {
- if (array.length < 2)
- return;
- for (int x = 0; x < array.length; x += 2) {
- array[x] = GeometryMathUtils.clamp(array[x], imageBound.left, imageBound.right);
- array[x + 1] = GeometryMathUtils.clamp(array[x + 1], imageBound.top, imageBound.bottom);
- }
- }
-
- /**
- * Takes a point and the corners of a rectangle and returns the two corners
- * representing the side of the rectangle closest to the point.
- *
- * @param point the point which is being checked
- * @param corners the corners of the rectangle
- * @return two corners representing the side of the rectangle
- */
- public static float[] closestSide(float[] point, float[] corners) {
- int len = corners.length;
- float oldMag = Float.POSITIVE_INFINITY;
- float[] bestLine = null;
- for (int i = 0; i < len; i += 2) {
- float[] line = {
- corners[i], corners[(i + 1) % len],
- corners[(i + 2) % len], corners[(i + 3) % len]
- };
- float mag = GeometryMathUtils.vectorLength(
- GeometryMathUtils.shortestVectorFromPointToLine(point, line));
- if (mag < oldMag) {
- oldMag = mag;
- bestLine = line;
- }
- }
- return bestLine;
- }
-
- /**
- * Checks if a given point is within a rotated rectangle.
- *
- * @param point 2D point to check
- * @param bound rectangle to rotate
- * @param rot angle of rotation about rectangle center
- * @return true if point is within rotated rectangle
- */
- public static boolean pointInRotatedRect(float[] point, RectF bound, float rot) {
- Matrix m = new Matrix();
- float[] p = Arrays.copyOf(point, 2);
- m.setRotate(rot, bound.centerX(), bound.centerY());
- Matrix m0 = new Matrix();
- if (!m.invert(m0))
- return false;
- m0.mapPoints(p);
- return inclusiveContains(bound, p[0], p[1]);
- }
-
- /**
- * Checks if a given point is within a rotated rectangle.
- *
- * @param point 2D point to check
- * @param rotatedRect corners of a rotated rectangle
- * @param center center of the rotated rectangle
- * @return true if point is within rotated rectangle
- */
- public static boolean pointInRotatedRect(float[] point, float[] rotatedRect, float[] center) {
- RectF unrotated = new RectF();
- float angle = getUnrotated(rotatedRect, center, unrotated);
- return pointInRotatedRect(point, unrotated, angle);
- }
-
- /**
- * Resizes rectangle to have a certain aspect ratio (center remains
- * stationary).
- *
- * @param r rectangle to resize
- * @param w new width aspect
- * @param h new height aspect
- */
- public static void fixAspectRatio(RectF r, float w, float h) {
- float scale = Math.min(r.width() / w, r.height() / h);
- float centX = r.centerX();
- float centY = r.centerY();
- float hw = scale * w / 2;
- float hh = scale * h / 2;
- r.set(centX - hw, centY - hh, centX + hw, centY + hh);
- }
-
- /**
- * Resizes rectangle to have a certain aspect ratio (center remains
- * stationary) while constraining it to remain within the original rect.
- *
- * @param r rectangle to resize
- * @param w new width aspect
- * @param h new height aspect
- */
- public static void fixAspectRatioContained(RectF r, float w, float h) {
- float origW = r.width();
- float origH = r.height();
- float origA = origW / origH;
- float a = w / h;
- float finalW = origW;
- float finalH = origH;
- if (origA < a) {
- finalH = origW / a;
- r.top = r.centerY() - finalH / 2;
- r.bottom = r.top + finalH;
- } else {
- finalW = origH * a;
- r.left = r.centerX() - finalW / 2;
- r.right = r.left + finalW;
- }
- }
-
- /**
- * Stretches/Scales/Translates photoBounds to match displayBounds, and
- * and returns an equivalent stretched/scaled/translated cropBounds or null
- * if the mapping is invalid.
- * @param cropBounds cropBounds to transform
- * @param photoBounds original bounds containing crop bounds
- * @param displayBounds final bounds for crop
- * @return the stretched/scaled/translated crop bounds that fit within displayBounds
- */
- public static RectF getScaledCropBounds(RectF cropBounds, RectF photoBounds,
- RectF displayBounds) {
- Matrix m = new Matrix();
- m.setRectToRect(photoBounds, displayBounds, Matrix.ScaleToFit.FILL);
- RectF trueCrop = new RectF(cropBounds);
- if (!m.mapRect(trueCrop)) {
- return null;
- }
- return trueCrop;
- }
-
- /**
- * Returns the size of a bitmap in bytes.
- * @param bmap bitmap whose size to check
- * @return bitmap size in bytes
- */
- public static int getBitmapSize(Bitmap bmap) {
- return bmap.getRowBytes() * bmap.getHeight();
- }
-
- /**
- * Constrains rotation to be in [0, 90, 180, 270] rounding down.
- * @param rotation any rotation value, in degrees
- * @return integer rotation in [0, 90, 180, 270]
- */
- public static int constrainedRotation(float rotation) {
- int r = (int) ((rotation % 360) / 90);
- r = (r < 0) ? (r + 4) : r;
- return r * 90;
- }
-
- private static float getUnrotated(float[] rotatedRect, float[] center, RectF unrotated) {
- float dy = rotatedRect[1] - rotatedRect[3];
- float dx = rotatedRect[0] - rotatedRect[2];
- float angle = (float) (Math.atan(dy / dx) * 180 / Math.PI);
- Matrix m = new Matrix();
- m.setRotate(-angle, center[0], center[1]);
- float[] unrotatedRect = new float[rotatedRect.length];
- m.mapPoints(unrotatedRect, rotatedRect);
- unrotated.set(trapToRect(unrotatedRect));
- return angle;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropObject.java b/src/com/android/gallery3d/filtershow/crop/CropObject.java
deleted file mode 100644
index b98ed1bfd..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropObject.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.graphics.Rect;
-import android.graphics.RectF;
-
-import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
-
-public class CropObject {
- private BoundedRect mBoundedRect;
- private float mAspectWidth = 1;
- private float mAspectHeight = 1;
- private boolean mFixAspectRatio = false;
- private float mRotation = 0;
- private float mTouchTolerance = 45;
- private float mMinSideSize = 20;
-
- public static final int MOVE_NONE = 0;
- // Sides
- public static final int MOVE_LEFT = 1;
- public static final int MOVE_TOP = 2;
- public static final int MOVE_RIGHT = 4;
- public static final int MOVE_BOTTOM = 8;
- public static final int MOVE_BLOCK = 16;
-
- // Corners
- public static final int TOP_LEFT = MOVE_TOP | MOVE_LEFT;
- public static final int TOP_RIGHT = MOVE_TOP | MOVE_RIGHT;
- public static final int BOTTOM_RIGHT = MOVE_BOTTOM | MOVE_RIGHT;
- public static final int BOTTOM_LEFT = MOVE_BOTTOM | MOVE_LEFT;
-
- private int mMovingEdges = MOVE_NONE;
-
- public CropObject(Rect outerBound, Rect innerBound, int outerAngle) {
- mBoundedRect = new BoundedRect(outerAngle % 360, outerBound, innerBound);
- }
-
- public CropObject(RectF outerBound, RectF innerBound, int outerAngle) {
- mBoundedRect = new BoundedRect(outerAngle % 360, outerBound, innerBound);
- }
-
- public void resetBoundsTo(RectF inner, RectF outer) {
- mBoundedRect.resetTo(0, outer, inner);
- }
-
- public void getInnerBounds(RectF r) {
- mBoundedRect.setToInner(r);
- }
-
- public void getOuterBounds(RectF r) {
- mBoundedRect.setToOuter(r);
- }
-
- public RectF getInnerBounds() {
- return mBoundedRect.getInner();
- }
-
- public RectF getOuterBounds() {
- return mBoundedRect.getOuter();
- }
-
- public int getSelectState() {
- return mMovingEdges;
- }
-
- public boolean isFixedAspect() {
- return mFixAspectRatio;
- }
-
- public void rotateOuter(int angle) {
- mRotation = angle % 360;
- mBoundedRect.setRotation(mRotation);
- clearSelectState();
- }
-
- public boolean setInnerAspectRatio(float width, float height) {
- if (width <= 0 || height <= 0) {
- throw new IllegalArgumentException("Width and Height must be greater than zero");
- }
- RectF inner = mBoundedRect.getInner();
- CropMath.fixAspectRatioContained(inner, width, height);
- if (inner.width() < mMinSideSize || inner.height() < mMinSideSize) {
- return false;
- }
- mAspectWidth = width;
- mAspectHeight = height;
- mFixAspectRatio = true;
- mBoundedRect.setInner(inner);
- clearSelectState();
- return true;
- }
-
- public void setTouchTolerance(float tolerance) {
- if (tolerance <= 0) {
- throw new IllegalArgumentException("Tolerance must be greater than zero");
- }
- mTouchTolerance = tolerance;
- }
-
- public void setMinInnerSideSize(float minSide) {
- if (minSide <= 0) {
- throw new IllegalArgumentException("Min dide must be greater than zero");
- }
- mMinSideSize = minSide;
- }
-
- public void unsetAspectRatio() {
- mFixAspectRatio = false;
- clearSelectState();
- }
-
- public boolean hasSelectedEdge() {
- return mMovingEdges != MOVE_NONE;
- }
-
- public static boolean checkCorner(int selected) {
- return selected == TOP_LEFT || selected == TOP_RIGHT || selected == BOTTOM_RIGHT
- || selected == BOTTOM_LEFT;
- }
-
- public static boolean checkEdge(int selected) {
- return selected == MOVE_LEFT || selected == MOVE_TOP || selected == MOVE_RIGHT
- || selected == MOVE_BOTTOM;
- }
-
- public static boolean checkBlock(int selected) {
- return selected == MOVE_BLOCK;
- }
-
- public static boolean checkValid(int selected) {
- return selected == MOVE_NONE || checkBlock(selected) || checkEdge(selected)
- || checkCorner(selected);
- }
-
- public void clearSelectState() {
- mMovingEdges = MOVE_NONE;
- }
-
- public int wouldSelectEdge(float x, float y) {
- int edgeSelected = calculateSelectedEdge(x, y);
- if (edgeSelected != MOVE_NONE && edgeSelected != MOVE_BLOCK) {
- return edgeSelected;
- }
- return MOVE_NONE;
- }
-
- public boolean selectEdge(int edge) {
- if (!checkValid(edge)) {
- // temporary
- throw new IllegalArgumentException("bad edge selected");
- // return false;
- }
- if ((mFixAspectRatio && !checkCorner(edge)) && !checkBlock(edge) && edge != MOVE_NONE) {
- // temporary
- throw new IllegalArgumentException("bad corner selected");
- // return false;
- }
- mMovingEdges = edge;
- return true;
- }
-
- public boolean selectEdge(float x, float y) {
- int edgeSelected = calculateSelectedEdge(x, y);
- if (mFixAspectRatio) {
- edgeSelected = fixEdgeToCorner(edgeSelected);
- }
- if (edgeSelected == MOVE_NONE) {
- return false;
- }
- return selectEdge(edgeSelected);
- }
-
- public boolean moveCurrentSelection(float dX, float dY) {
- if (mMovingEdges == MOVE_NONE) {
- return false;
- }
- RectF crop = mBoundedRect.getInner();
-
- float minWidthHeight = mMinSideSize;
-
- int movingEdges = mMovingEdges;
- if (movingEdges == MOVE_BLOCK) {
- mBoundedRect.moveInner(dX, dY);
- return true;
- } else {
- float dx = 0;
- float dy = 0;
-
- if ((movingEdges & MOVE_LEFT) != 0) {
- dx = Math.min(crop.left + dX, crop.right - minWidthHeight) - crop.left;
- }
- if ((movingEdges & MOVE_TOP) != 0) {
- dy = Math.min(crop.top + dY, crop.bottom - minWidthHeight) - crop.top;
- }
- if ((movingEdges & MOVE_RIGHT) != 0) {
- dx = Math.max(crop.right + dX, crop.left + minWidthHeight)
- - crop.right;
- }
- if ((movingEdges & MOVE_BOTTOM) != 0) {
- dy = Math.max(crop.bottom + dY, crop.top + minWidthHeight)
- - crop.bottom;
- }
-
- if (mFixAspectRatio) {
- float[] l1 = {
- crop.left, crop.bottom
- };
- float[] l2 = {
- crop.right, crop.top
- };
- if (movingEdges == TOP_LEFT || movingEdges == BOTTOM_RIGHT) {
- l1[1] = crop.top;
- l2[1] = crop.bottom;
- }
- float[] b = {
- l1[0] - l2[0], l1[1] - l2[1]
- };
- float[] disp = {
- dx, dy
- };
- float[] bUnit = GeometryMathUtils.normalize(b);
- float sp = GeometryMathUtils.scalarProjection(disp, bUnit);
- dx = sp * bUnit[0];
- dy = sp * bUnit[1];
- RectF newCrop = fixedCornerResize(crop, movingEdges, dx, dy);
-
- mBoundedRect.fixedAspectResizeInner(newCrop);
- } else {
- if ((movingEdges & MOVE_LEFT) != 0) {
- crop.left += dx;
- }
- if ((movingEdges & MOVE_TOP) != 0) {
- crop.top += dy;
- }
- if ((movingEdges & MOVE_RIGHT) != 0) {
- crop.right += dx;
- }
- if ((movingEdges & MOVE_BOTTOM) != 0) {
- crop.bottom += dy;
- }
- mBoundedRect.resizeInner(crop);
- }
- }
- return true;
- }
-
- // Helper methods
-
- private int calculateSelectedEdge(float x, float y) {
- RectF cropped = mBoundedRect.getInner();
-
- float left = Math.abs(x - cropped.left);
- float right = Math.abs(x - cropped.right);
- float top = Math.abs(y - cropped.top);
- float bottom = Math.abs(y - cropped.bottom);
-
- int edgeSelected = MOVE_NONE;
- // Check left or right.
- if ((left <= mTouchTolerance) && ((y + mTouchTolerance) >= cropped.top)
- && ((y - mTouchTolerance) <= cropped.bottom) && (left < right)) {
- edgeSelected |= MOVE_LEFT;
- }
- else if ((right <= mTouchTolerance) && ((y + mTouchTolerance) >= cropped.top)
- && ((y - mTouchTolerance) <= cropped.bottom)) {
- edgeSelected |= MOVE_RIGHT;
- }
-
- // Check top or bottom.
- if ((top <= mTouchTolerance) && ((x + mTouchTolerance) >= cropped.left)
- && ((x - mTouchTolerance) <= cropped.right) && (top < bottom)) {
- edgeSelected |= MOVE_TOP;
- }
- else if ((bottom <= mTouchTolerance) && ((x + mTouchTolerance) >= cropped.left)
- && ((x - mTouchTolerance) <= cropped.right)) {
- edgeSelected |= MOVE_BOTTOM;
- }
- return edgeSelected;
- }
-
- private static RectF fixedCornerResize(RectF r, int moving_corner, float dx, float dy) {
- RectF newCrop = null;
- // Fix opposite corner in place and move sides
- if (moving_corner == BOTTOM_RIGHT) {
- newCrop = new RectF(r.left, r.top, r.left + r.width() + dx, r.top + r.height()
- + dy);
- } else if (moving_corner == BOTTOM_LEFT) {
- newCrop = new RectF(r.right - r.width() + dx, r.top, r.right, r.top + r.height()
- + dy);
- } else if (moving_corner == TOP_LEFT) {
- newCrop = new RectF(r.right - r.width() + dx, r.bottom - r.height() + dy,
- r.right, r.bottom);
- } else if (moving_corner == TOP_RIGHT) {
- newCrop = new RectF(r.left, r.bottom - r.height() + dy, r.left
- + r.width() + dx, r.bottom);
- }
- return newCrop;
- }
-
- private static int fixEdgeToCorner(int moving_edges) {
- if (moving_edges == MOVE_LEFT) {
- moving_edges |= MOVE_TOP;
- }
- if (moving_edges == MOVE_TOP) {
- moving_edges |= MOVE_LEFT;
- }
- if (moving_edges == MOVE_RIGHT) {
- moving_edges |= MOVE_BOTTOM;
- }
- if (moving_edges == MOVE_BOTTOM) {
- moving_edges |= MOVE_RIGHT;
- }
- return moving_edges;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/crop/CropView.java b/src/com/android/gallery3d/filtershow/crop/CropView.java
deleted file mode 100644
index bbb7cfd4c..000000000
--- a/src/com/android/gallery3d/filtershow/crop/CropView.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.crop;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.DashPathEffect;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.NinePatchDrawable;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.View;
-
-import com.android.gallery3d.R;
-
-
-public class CropView extends View {
- private static final String LOGTAG = "CropView";
-
- private RectF mImageBounds = new RectF();
- private RectF mScreenBounds = new RectF();
- private RectF mScreenImageBounds = new RectF();
- private RectF mScreenCropBounds = new RectF();
- private Rect mShadowBounds = new Rect();
-
- private Bitmap mBitmap;
- private Paint mPaint = new Paint();
-
- private NinePatchDrawable mShadow;
- private CropObject mCropObj = null;
- private Drawable mCropIndicator;
- private int mIndicatorSize;
- private int mRotation = 0;
- private boolean mMovingBlock = false;
- private Matrix mDisplayMatrix = null;
- private Matrix mDisplayMatrixInverse = null;
- private boolean mDirty = false;
-
- private float mPrevX = 0;
- private float mPrevY = 0;
- private float mSpotX = 0;
- private float mSpotY = 0;
- private boolean mDoSpot = false;
-
- private int mShadowMargin = 15;
- private int mMargin = 32;
- private int mOverlayShadowColor = 0xCF000000;
- private int mOverlayWPShadowColor = 0x5F000000;
- private int mWPMarkerColor = 0x7FFFFFFF;
- private int mMinSideSize = 90;
- private int mTouchTolerance = 40;
- private float mDashOnLength = 20;
- private float mDashOffLength = 10;
-
- private enum Mode {
- NONE, MOVE
- }
-
- private Mode mState = Mode.NONE;
-
- public CropView(Context context) {
- super(context);
- setup(context);
- }
-
- public CropView(Context context, AttributeSet attrs) {
- super(context, attrs);
- setup(context);
- }
-
- public CropView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- setup(context);
- }
-
- private void setup(Context context) {
- Resources rsc = context.getResources();
- mShadow = (NinePatchDrawable) rsc.getDrawable(R.drawable.geometry_shadow);
- mCropIndicator = rsc.getDrawable(R.drawable.camera_crop);
- mIndicatorSize = (int) rsc.getDimension(R.dimen.crop_indicator_size);
- mShadowMargin = (int) rsc.getDimension(R.dimen.shadow_margin);
- mMargin = (int) rsc.getDimension(R.dimen.preview_margin);
- mMinSideSize = (int) rsc.getDimension(R.dimen.crop_min_side);
- mTouchTolerance = (int) rsc.getDimension(R.dimen.crop_touch_tolerance);
- mOverlayShadowColor = (int) rsc.getColor(R.color.crop_shadow_color);
- mOverlayWPShadowColor = (int) rsc.getColor(R.color.crop_shadow_wp_color);
- mWPMarkerColor = (int) rsc.getColor(R.color.crop_wp_markers);
- mDashOnLength = rsc.getDimension(R.dimen.wp_selector_dash_length);
- mDashOffLength = rsc.getDimension(R.dimen.wp_selector_off_length);
- }
-
- public void initialize(Bitmap image, RectF newCropBounds, RectF newPhotoBounds, int rotation) {
- mBitmap = image;
- if (mCropObj != null) {
- RectF crop = mCropObj.getInnerBounds();
- RectF containing = mCropObj.getOuterBounds();
- if (crop != newCropBounds || containing != newPhotoBounds
- || mRotation != rotation) {
- mRotation = rotation;
- mCropObj.resetBoundsTo(newCropBounds, newPhotoBounds);
- clearDisplay();
- }
- } else {
- mRotation = rotation;
- mCropObj = new CropObject(newPhotoBounds, newCropBounds, 0);
- clearDisplay();
- }
- }
-
- public RectF getCrop() {
- return mCropObj.getInnerBounds();
- }
-
- public RectF getPhoto() {
- return mCropObj.getOuterBounds();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- float x = event.getX();
- float y = event.getY();
- if (mDisplayMatrix == null || mDisplayMatrixInverse == null) {
- return true;
- }
- float[] touchPoint = {
- x, y
- };
- mDisplayMatrixInverse.mapPoints(touchPoint);
- x = touchPoint[0];
- y = touchPoint[1];
- switch (event.getActionMasked()) {
- case (MotionEvent.ACTION_DOWN):
- if (mState == Mode.NONE) {
- if (!mCropObj.selectEdge(x, y)) {
- mMovingBlock = mCropObj.selectEdge(CropObject.MOVE_BLOCK);
- }
- mPrevX = x;
- mPrevY = y;
- mState = Mode.MOVE;
- }
- break;
- case (MotionEvent.ACTION_UP):
- if (mState == Mode.MOVE) {
- mCropObj.selectEdge(CropObject.MOVE_NONE);
- mMovingBlock = false;
- mPrevX = x;
- mPrevY = y;
- mState = Mode.NONE;
- }
- break;
- case (MotionEvent.ACTION_MOVE):
- if (mState == Mode.MOVE) {
- float dx = x - mPrevX;
- float dy = y - mPrevY;
- mCropObj.moveCurrentSelection(dx, dy);
- mPrevX = x;
- mPrevY = y;
- }
- break;
- default:
- break;
- }
- invalidate();
- return true;
- }
-
- private void reset() {
- Log.w(LOGTAG, "crop reset called");
- mState = Mode.NONE;
- mCropObj = null;
- mRotation = 0;
- mMovingBlock = false;
- clearDisplay();
- }
-
- private void clearDisplay() {
- mDisplayMatrix = null;
- mDisplayMatrixInverse = null;
- invalidate();
- }
-
- protected void configChanged() {
- mDirty = true;
- }
-
- public void applyFreeAspect() {
- mCropObj.unsetAspectRatio();
- invalidate();
- }
-
- public void applyOriginalAspect() {
- RectF outer = mCropObj.getOuterBounds();
- float w = outer.width();
- float h = outer.height();
- if (w > 0 && h > 0) {
- applyAspect(w, h);
- mCropObj.resetBoundsTo(outer, outer);
- } else {
- Log.w(LOGTAG, "failed to set aspect ratio original");
- }
- }
-
- public void applySquareAspect() {
- applyAspect(1, 1);
- }
-
- public void applyAspect(float x, float y) {
- if (x <= 0 || y <= 0) {
- throw new IllegalArgumentException("Bad arguments to applyAspect");
- }
- // If we are rotated by 90 degrees from horizontal, swap x and y
- if (((mRotation < 0) ? -mRotation : mRotation) % 180 == 90) {
- float tmp = x;
- x = y;
- y = tmp;
- }
- if (!mCropObj.setInnerAspectRatio(x, y)) {
- Log.w(LOGTAG, "failed to set aspect ratio");
- }
- invalidate();
- }
-
- public void setWallpaperSpotlight(float spotlightX, float spotlightY) {
- mSpotX = spotlightX;
- mSpotY = spotlightY;
- if (mSpotX > 0 && mSpotY > 0) {
- mDoSpot = true;
- }
- }
-
- public void unsetWallpaperSpotlight() {
- mDoSpot = false;
- }
-
- /**
- * Rotates first d bits in integer x to the left some number of times.
- */
- private int bitCycleLeft(int x, int times, int d) {
- int mask = (1 << d) - 1;
- int mout = x & mask;
- times %= d;
- int hi = mout >> (d - times);
- int low = (mout << times) & mask;
- int ret = x & ~mask;
- ret |= low;
- ret |= hi;
- return ret;
- }
-
- /**
- * Find the selected edge or corner in screen coordinates.
- */
- private int decode(int movingEdges, float rotation) {
- int rot = CropMath.constrainedRotation(rotation);
- switch (rot) {
- case 90:
- return bitCycleLeft(movingEdges, 1, 4);
- case 180:
- return bitCycleLeft(movingEdges, 2, 4);
- case 270:
- return bitCycleLeft(movingEdges, 3, 4);
- default:
- return movingEdges;
- }
- }
-
- @Override
- public void onDraw(Canvas canvas) {
- if (mBitmap == null) {
- return;
- }
- if (mDirty) {
- mDirty = false;
- clearDisplay();
- }
-
- mImageBounds = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
- mScreenBounds = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
- mScreenBounds.inset(mMargin, mMargin);
-
- // If crop object doesn't exist, create it and update it from master
- // state
- if (mCropObj == null) {
- reset();
- mCropObj = new CropObject(mImageBounds, mImageBounds, 0);
- }
-
- // If display matrix doesn't exist, create it and its dependencies
- if (mDisplayMatrix == null || mDisplayMatrixInverse == null) {
- mDisplayMatrix = new Matrix();
- mDisplayMatrix.reset();
- if (!CropDrawingUtils.setImageToScreenMatrix(mDisplayMatrix, mImageBounds, mScreenBounds,
- mRotation)) {
- Log.w(LOGTAG, "failed to get screen matrix");
- mDisplayMatrix = null;
- return;
- }
- mDisplayMatrixInverse = new Matrix();
- mDisplayMatrixInverse.reset();
- if (!mDisplayMatrix.invert(mDisplayMatrixInverse)) {
- Log.w(LOGTAG, "could not invert display matrix");
- mDisplayMatrixInverse = null;
- return;
- }
- // Scale min side and tolerance by display matrix scale factor
- mCropObj.setMinInnerSideSize(mDisplayMatrixInverse.mapRadius(mMinSideSize));
- mCropObj.setTouchTolerance(mDisplayMatrixInverse.mapRadius(mTouchTolerance));
- }
-
- mScreenImageBounds.set(mImageBounds);
-
- // Draw background shadow
- if (mDisplayMatrix.mapRect(mScreenImageBounds)) {
- int margin = (int) mDisplayMatrix.mapRadius(mShadowMargin);
- mScreenImageBounds.roundOut(mShadowBounds);
- mShadowBounds.set(mShadowBounds.left - margin, mShadowBounds.top -
- margin, mShadowBounds.right + margin, mShadowBounds.bottom + margin);
- mShadow.setBounds(mShadowBounds);
- mShadow.draw(canvas);
- }
-
- mPaint.setAntiAlias(true);
- mPaint.setFilterBitmap(true);
- // Draw actual bitmap
- canvas.drawBitmap(mBitmap, mDisplayMatrix, mPaint);
-
- mCropObj.getInnerBounds(mScreenCropBounds);
-
- if (mDisplayMatrix.mapRect(mScreenCropBounds)) {
-
- // Draw overlay shadows
- Paint p = new Paint();
- p.setColor(mOverlayShadowColor);
- p.setStyle(Paint.Style.FILL);
- CropDrawingUtils.drawShadows(canvas, p, mScreenCropBounds, mScreenImageBounds);
-
- // Draw crop rect and markers
- CropDrawingUtils.drawCropRect(canvas, mScreenCropBounds);
- if (!mDoSpot) {
- CropDrawingUtils.drawRuleOfThird(canvas, mScreenCropBounds);
- } else {
- Paint wpPaint = new Paint();
- wpPaint.setColor(mWPMarkerColor);
- wpPaint.setStrokeWidth(3);
- wpPaint.setStyle(Paint.Style.STROKE);
- wpPaint.setPathEffect(new DashPathEffect(new float[]
- {mDashOnLength, mDashOnLength + mDashOffLength}, 0));
- p.setColor(mOverlayWPShadowColor);
- CropDrawingUtils.drawWallpaperSelectionFrame(canvas, mScreenCropBounds,
- mSpotX, mSpotY, wpPaint, p);
- }
- CropDrawingUtils.drawIndicators(canvas, mCropIndicator, mIndicatorSize,
- mScreenCropBounds, mCropObj.isFixedAspect(), decode(mCropObj.getSelectState(), mRotation));
- }
-
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/data/FilterStackDBHelper.java b/src/com/android/gallery3d/filtershow/data/FilterStackDBHelper.java
deleted file mode 100644
index e18d3104f..000000000
--- a/src/com/android/gallery3d/filtershow/data/FilterStackDBHelper.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.data;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-
-public class FilterStackDBHelper extends SQLiteOpenHelper {
-
- public static final int DATABASE_VERSION = 1;
- public static final String DATABASE_NAME = "filterstacks.db";
- private static final String SQL_CREATE_TABLE = "CREATE TABLE ";
-
- public static interface FilterStack {
- /** The row uid */
- public static final String _ID = "_id";
- /** The table name */
- public static final String TABLE = "filterstack";
- /** The stack name */
- public static final String STACK_ID = "stack_id";
- /** A serialized stack of filters. */
- public static final String FILTER_STACK= "stack";
- }
-
- private static final String[][] CREATE_FILTER_STACK = {
- { FilterStack._ID, "INTEGER PRIMARY KEY AUTOINCREMENT" },
- { FilterStack.STACK_ID, "TEXT" },
- { FilterStack.FILTER_STACK, "BLOB" },
- };
-
- public FilterStackDBHelper(Context context, String name, int version) {
- super(context, name, null, version);
- }
-
- public FilterStackDBHelper(Context context, String name) {
- this(context, name, DATABASE_VERSION);
- }
-
- public FilterStackDBHelper(Context context) {
- this(context, DATABASE_NAME);
- }
-
- @Override
- public void onCreate(SQLiteDatabase db) {
- createTable(db, FilterStack.TABLE, CREATE_FILTER_STACK);
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- dropTable(db, FilterStack.TABLE);
- onCreate(db);
- }
-
- protected static void createTable(SQLiteDatabase db, String table, String[][] columns) {
- StringBuilder create = new StringBuilder(SQL_CREATE_TABLE);
- create.append(table).append('(');
- boolean first = true;
- for (String[] column : columns) {
- if (!first) {
- create.append(',');
- }
- first = false;
- for (String val : column) {
- create.append(val).append(' ');
- }
- }
- create.append(')');
- db.beginTransaction();
- try {
- db.execSQL(create.toString());
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
- }
-
- protected static void dropTable(SQLiteDatabase db, String table) {
- db.beginTransaction();
- try {
- db.execSQL("drop table if exists " + table);
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/data/FilterStackSource.java b/src/com/android/gallery3d/filtershow/data/FilterStackSource.java
deleted file mode 100644
index d283771b4..000000000
--- a/src/com/android/gallery3d/filtershow/data/FilterStackSource.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.data;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
-import android.util.Log;
-import android.util.Pair;
-
-import com.android.gallery3d.filtershow.data.FilterStackDBHelper.FilterStack;
-import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class FilterStackSource {
- private static final String LOGTAG = "FilterStackSource";
-
- private SQLiteDatabase database = null;
- private final FilterStackDBHelper dbHelper;
-
- public FilterStackSource(Context context) {
- dbHelper = new FilterStackDBHelper(context);
- }
-
- public void open() {
- try {
- database = dbHelper.getWritableDatabase();
- } catch (SQLiteException e) {
- Log.w(LOGTAG, "could not open database", e);
- }
- }
-
- public void close() {
- database = null;
- dbHelper.close();
- }
-
- public boolean insertStack(String stackName, byte[] stackBlob) {
- boolean ret = true;
- ContentValues val = new ContentValues();
- val.put(FilterStack.STACK_ID, stackName);
- val.put(FilterStack.FILTER_STACK, stackBlob);
- database.beginTransaction();
- try {
- ret = (-1 != database.insert(FilterStack.TABLE, null, val));
- database.setTransactionSuccessful();
- } finally {
- database.endTransaction();
- }
- return ret;
- }
-
- public void updateStackName(int id, String stackName) {
- ContentValues val = new ContentValues();
- val.put(FilterStack.STACK_ID, stackName);
- database.beginTransaction();
- try {
- database.update(FilterStack.TABLE, val, FilterStack._ID + " = ?",
- new String[] { "" + id});
- database.setTransactionSuccessful();
- } finally {
- database.endTransaction();
- }
- }
-
- public boolean removeStack(int id) {
- boolean ret = true;
- database.beginTransaction();
- try {
- ret = (0 != database.delete(FilterStack.TABLE, FilterStack._ID + " = ?",
- new String[] { "" + id }));
- database.setTransactionSuccessful();
- } finally {
- database.endTransaction();
- }
- return ret;
- }
-
- public void removeAllStacks() {
- database.beginTransaction();
- try {
- database.delete(FilterStack.TABLE, null, null);
- database.setTransactionSuccessful();
- } finally {
- database.endTransaction();
- }
- }
-
- public byte[] getStack(String stackName) {
- byte[] ret = null;
- Cursor c = null;
- database.beginTransaction();
- try {
- c = database.query(FilterStack.TABLE,
- new String[] { FilterStack.FILTER_STACK },
- FilterStack.STACK_ID + " = ?",
- new String[] { stackName }, null, null, null, null);
- if (c != null && c.moveToFirst() && !c.isNull(0)) {
- ret = c.getBlob(0);
- }
- database.setTransactionSuccessful();
- } finally {
- if (c != null) {
- c.close();
- }
- database.endTransaction();
- }
- return ret;
- }
-
- public ArrayList<FilterUserPresetRepresentation> getAllUserPresets() {
- ArrayList<FilterUserPresetRepresentation> ret =
- new ArrayList<FilterUserPresetRepresentation>();
-
- Cursor c = null;
- database.beginTransaction();
- try {
- c = database.query(FilterStack.TABLE,
- new String[] { FilterStack._ID,
- FilterStack.STACK_ID,
- FilterStack.FILTER_STACK },
- null, null, null, null, null, null);
- if (c != null) {
- boolean loopCheck = c.moveToFirst();
- while (loopCheck) {
- int id = c.getInt(0);
- String name = (c.isNull(1)) ? null : c.getString(1);
- byte[] b = (c.isNull(2)) ? null : c.getBlob(2);
- String json = new String(b);
-
- ImagePreset preset = new ImagePreset();
- preset.readJsonFromString(json);
- FilterUserPresetRepresentation representation =
- new FilterUserPresetRepresentation(name, preset, id);
- ret.add(representation);
- loopCheck = c.moveToNext();
- }
- }
- database.setTransactionSuccessful();
- } finally {
- if (c != null) {
- c.close();
- }
- database.endTransaction();
- }
-
- return ret;
- }
-
- public List<Pair<String, byte[]>> getAllStacks() {
- List<Pair<String, byte[]>> ret = new ArrayList<Pair<String, byte[]>>();
- Cursor c = null;
- database.beginTransaction();
- try {
- c = database.query(FilterStack.TABLE,
- new String[] { FilterStack.STACK_ID, FilterStack.FILTER_STACK },
- null, null, null, null, null, null);
- if (c != null) {
- boolean loopCheck = c.moveToFirst();
- while (loopCheck) {
- String name = (c.isNull(0)) ? null : c.getString(0);
- byte[] b = (c.isNull(1)) ? null : c.getBlob(1);
- ret.add(new Pair<String, byte[]>(name, b));
- loopCheck = c.moveToNext();
- }
- }
- database.setTransactionSuccessful();
- } finally {
- if (c != null) {
- c.close();
- }
- database.endTransaction();
- }
- if (ret.size() <= 0) {
- return null;
- }
- return ret;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java b/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
deleted file mode 100644
index 114cd3ebc..000000000
--- a/src/com/android/gallery3d/filtershow/data/UserPresetsManager.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package com.android.gallery3d.filtershow.data;
-
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Message;
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-import java.util.ArrayList;
-
-public class UserPresetsManager implements Handler.Callback {
-
- private static final String LOGTAG = "UserPresetsManager";
-
- private FilterShowActivity mActivity;
- private HandlerThread mHandlerThread = null;
- private Handler mProcessingHandler = null;
- private FilterStackSource mUserPresets;
-
- private static final int LOAD = 1;
- private static final int LOAD_RESULT = 2;
- private static final int SAVE = 3;
- private static final int DELETE = 4;
- private static final int UPDATE = 5;
-
- private ArrayList<FilterUserPresetRepresentation> mRepresentations;
-
- private final Handler mResultHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case LOAD_RESULT:
- resultLoad(msg);
- break;
- }
- }
- };
-
- @Override
- public boolean handleMessage(Message msg) {
- switch (msg.what) {
- case LOAD:
- processLoad();
- return true;
- case SAVE:
- processSave(msg);
- return true;
- case DELETE:
- processDelete(msg);
- return true;
- case UPDATE:
- processUpdate(msg);
- return true;
- }
- return false;
- }
-
- public UserPresetsManager(FilterShowActivity context) {
- mActivity = context;
- mHandlerThread = new HandlerThread(LOGTAG,
- android.os.Process.THREAD_PRIORITY_BACKGROUND);
- mHandlerThread.start();
- mProcessingHandler = new Handler(mHandlerThread.getLooper(), this);
- mUserPresets = new FilterStackSource(mActivity);
- mUserPresets.open();
- }
-
- public ArrayList<FilterUserPresetRepresentation> getRepresentations() {
- return mRepresentations;
- }
-
- public void load() {
- Message msg = mProcessingHandler.obtainMessage(LOAD);
- mProcessingHandler.sendMessage(msg);
- }
-
- public void close() {
- mUserPresets.close();
- mHandlerThread.quit();
- }
-
- static class SaveOperation {
- String json;
- String name;
- }
-
- public void save(ImagePreset preset) {
- Message msg = mProcessingHandler.obtainMessage(SAVE);
- SaveOperation op = new SaveOperation();
- op.json = preset.getJsonString(mActivity.getString(R.string.saved));
- op.name= mActivity.getString(R.string.filtershow_new_preset);
- msg.obj = op;
- mProcessingHandler.sendMessage(msg);
- }
-
- public void delete(int id) {
- Message msg = mProcessingHandler.obtainMessage(DELETE);
- msg.arg1 = id;
- mProcessingHandler.sendMessage(msg);
- }
-
- static class UpdateOperation {
- int id;
- String name;
- }
-
- public void update(FilterUserPresetRepresentation representation) {
- Message msg = mProcessingHandler.obtainMessage(UPDATE);
- UpdateOperation op = new UpdateOperation();
- op.id = representation.getId();
- op.name = representation.getName();
- msg.obj = op;
- mProcessingHandler.sendMessage(msg);
- }
-
- private void processLoad() {
- ArrayList<FilterUserPresetRepresentation> list = mUserPresets.getAllUserPresets();
- Message msg = mResultHandler.obtainMessage(LOAD_RESULT);
- msg.obj = list;
- mResultHandler.sendMessage(msg);
- }
-
- private void resultLoad(Message msg) {
- mRepresentations =
- (ArrayList<FilterUserPresetRepresentation>) msg.obj;
- mActivity.updateUserPresetsFromManager();
- }
-
- private void processSave(Message msg) {
- SaveOperation op = (SaveOperation) msg.obj;
- mUserPresets.insertStack(op.name, op.json.getBytes());
- processLoad();
- }
-
- private void processDelete(Message msg) {
- int id = msg.arg1;
- mUserPresets.removeStack(id);
- processLoad();
- }
-
- private void processUpdate(Message msg) {
- UpdateOperation op = (UpdateOperation) msg.obj;
- mUserPresets.updateStackName(op.id, op.name);
- processLoad();
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/BasicEditor.java b/src/com/android/gallery3d/filtershow/editors/BasicEditor.java
deleted file mode 100644
index af694d811..000000000
--- a/src/com/android/gallery3d/filtershow/editors/BasicEditor.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.Control;
-import com.android.gallery3d.filtershow.controller.FilterView;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.controller.ParameterInteger;
-import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-
-
-/**
- * The basic editor that all the one parameter filters
- */
-public class BasicEditor extends ParametricEditor implements ParameterInteger {
- public static int ID = R.id.basicEditor;
- private final String LOGTAG = "BasicEditor";
-
- public BasicEditor() {
- super(ID, R.layout.filtershow_default_editor, R.id.basicEditor);
- }
-
- protected BasicEditor(int id) {
- super(id, R.layout.filtershow_default_editor, R.id.basicEditor);
- }
-
- protected BasicEditor(int id, int layoutID, int viewID) {
- super(id, layoutID, viewID);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
- updateText();
- }
- }
-
- private FilterBasicRepresentation getBasicRepresentation() {
- FilterRepresentation tmpRep = getLocalRepresentation();
- if (tmpRep != null && tmpRep instanceof FilterBasicRepresentation) {
- return (FilterBasicRepresentation) tmpRep;
-
- }
- return null;
- }
-
- @Override
- public int getMaximum() {
- FilterBasicRepresentation rep = getBasicRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getMaximum();
- }
-
- @Override
- public int getMinimum() {
- FilterBasicRepresentation rep = getBasicRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getMinimum();
- }
-
- @Override
- public int getDefaultValue() {
- return 0;
- }
-
- @Override
- public int getValue() {
- FilterBasicRepresentation rep = getBasicRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getValue();
- }
-
- @Override
- public String getValueString() {
- return null;
- }
-
- @Override
- public void setValue(int value) {
- FilterBasicRepresentation rep = getBasicRepresentation();
- if (rep == null) {
- return;
- }
- rep.setValue(value);
- commitLocalRepresentation();
- }
-
- @Override
- public String getParameterName() {
- FilterBasicRepresentation rep = getBasicRepresentation();
- return mContext.getString(rep.getTextId());
- }
-
- @Override
- public String getParameterType() {
- return sParameterType;
- }
-
- @Override
- public void setController(Control c) {
- }
-
- @Override
- public void setFilterView(FilterView editor) {
-
- }
-
- @Override
- public void copyFrom(Parameter src) {
-
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/Editor.java b/src/com/android/gallery3d/filtershow/editors/Editor.java
deleted file mode 100644
index a9e56e0c1..000000000
--- a/src/com/android/gallery3d/filtershow/editors/Editor.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.PopupMenu;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.Control;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageShow;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * Base class for Editors Must contain a mImageShow and a top level view
- */
-public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonListener {
- protected Context mContext;
- protected View mView;
- protected ImageShow mImageShow;
- protected FrameLayout mFrameLayout;
- protected SeekBar mSeekBar;
- Button mEditTitle;
- protected Button mFilterTitle;
- protected int mID;
- private final String LOGTAG = "Editor";
- protected boolean mChangesGeometry = false;
- protected FilterRepresentation mLocalRepresentation = null;
- protected byte mShowParameter = SHOW_VALUE_UNDEFINED;
- private Button mButton;
- public static byte SHOW_VALUE_UNDEFINED = -1;
- public static byte SHOW_VALUE_OFF = 0;
- public static byte SHOW_VALUE_INT = 1;
-
- public static void hackFixStrings(Menu menu) {
- int count = menu.size();
- for (int i = 0; i < count; i++) {
- MenuItem item = menu.getItem(i);
- item.setTitle(item.getTitle().toString().toUpperCase());
- }
- }
-
- public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
- return effectName.toUpperCase() + " " + parameterValue;
- }
-
- protected Editor(int id) {
- mID = id;
- }
-
- public int getID() {
- return mID;
- }
-
- public byte showParameterValue() {
- return mShowParameter;
- }
-
- public boolean showsSeekBar() {
- return true;
- }
-
- public void setUpEditorUI(View actionButton, View editControl,
- Button editTitle, Button stateButton) {
- mEditTitle = editTitle;
- mFilterTitle = stateButton;
- mButton = editTitle;
- setMenuIcon(true);
- setUtilityPanelUI(actionButton, editControl);
- }
-
- public boolean showsPopupIndicator() {
- return true;
- }
-
- /**
- * @param actionButton the would be the area for menu etc
- * @param editControl this is the black area for sliders etc
- */
- public void setUtilityPanelUI(View actionButton, View editControl) {
-
- AttributeSet aset;
- Context context = editControl.getContext();
- LayoutInflater inflater =
- (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- LinearLayout lp = (LinearLayout) inflater.inflate(
- R.layout.filtershow_seekbar, (ViewGroup) editControl, true);
- mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar);
- mSeekBar.setOnSeekBarChangeListener(this);
-
- if (showsSeekBar()) {
- mSeekBar.setOnSeekBarChangeListener(this);
- mSeekBar.setVisibility(View.VISIBLE);
- } else {
- mSeekBar.setVisibility(View.INVISIBLE);
- }
-
- if (mButton != null) {
- if (showsPopupIndicator()) {
- mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0,
- R.drawable.filtershow_menu_marker, 0);
- } else {
- mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
- }
- }
- }
-
- @Override
- public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
-
- }
-
- public void setPanel() {
-
- }
-
- public void createEditor(Context context,FrameLayout frameLayout) {
- mContext = context;
- mFrameLayout = frameLayout;
- mLocalRepresentation = null;
- }
-
- protected void unpack(int viewid, int layoutid) {
-
- if (mView == null) {
- mView = mFrameLayout.findViewById(viewid);
- if (mView == null) {
- LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
- (Context.LAYOUT_INFLATER_SERVICE);
- mView = inflater.inflate(layoutid, mFrameLayout, false);
- mFrameLayout.addView(mView, mView.getLayoutParams());
- }
- }
- mImageShow = findImageShow(mView);
- }
-
- private ImageShow findImageShow(View view) {
- if (view instanceof ImageShow) {
- return (ImageShow) view;
- }
- if (!(view instanceof ViewGroup)) {
- return null;
- }
- ViewGroup vg = (ViewGroup) view;
- int n = vg.getChildCount();
- for (int i = 0; i < n; i++) {
- View v = vg.getChildAt(i);
- if (v instanceof ImageShow) {
- return (ImageShow) v;
- } else if (v instanceof ViewGroup) {
- return findImageShow(v);
- }
- }
- return null;
- }
-
- public View getTopLevelView() {
- return mView;
- }
-
- public ImageShow getImageShow() {
- return mImageShow;
- }
-
- public void setVisibility(int visible) {
- mView.setVisibility(visible);
- }
-
- public FilterRepresentation getLocalRepresentation() {
- if (mLocalRepresentation == null) {
- ImagePreset preset = MasterImage.getImage().getPreset();
- FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation();
- mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation);
- if (mShowParameter == SHOW_VALUE_UNDEFINED && filterRepresentation != null) {
- boolean show = filterRepresentation.showParameterValue();
- mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF;
- }
-
- }
- return mLocalRepresentation;
- }
-
- /**
- * Call this to update the preset in MasterImage with the current representation
- * returned by getLocalRepresentation. This causes the preview bitmap to be
- * regenerated.
- */
- public void commitLocalRepresentation() {
- commitLocalRepresentation(getLocalRepresentation());
- }
-
- /**
- * Call this to update the preset in MasterImage with a given representation.
- * This causes the preview bitmap to be regenerated.
- */
- public void commitLocalRepresentation(FilterRepresentation rep) {
- ArrayList<FilterRepresentation> filter = new ArrayList<FilterRepresentation>(1);
- filter.add(rep);
- commitLocalRepresentation(filter);
- }
-
- /**
- * Call this to update the preset in MasterImage with a collection of FilterRepresnations.
- * This causes the preview bitmap to be regenerated.
- */
- public void commitLocalRepresentation(Collection<FilterRepresentation> reps) {
- ImagePreset preset = MasterImage.getImage().getPreset();
- preset.updateFilterRepresentations(reps);
- if (mButton != null) {
- updateText();
- }
- if (mChangesGeometry) {
- // Regenerate both the filtered and the geometry-only bitmaps
- MasterImage.getImage().updatePresets(true);
- } else {
- // Regenerate only the filtered bitmap.
- MasterImage.getImage().invalidateFiltersOnly();
- }
- preset.fillImageStateAdapter(MasterImage.getImage().getState());
- }
-
- /**
- * This is called in response to a click to apply and leave the editor.
- */
- public void finalApplyCalled() {
- commitLocalRepresentation();
- }
-
- protected void updateText() {
- String s = "";
- if (mLocalRepresentation != null) {
- s = mContext.getString(mLocalRepresentation.getTextId());
- }
- mButton.setText(calculateUserMessage(mContext, s, ""));
- }
-
- /**
- * called after the filter is set and the select is called
- */
- public void reflectCurrentFilter() {
- mLocalRepresentation = null;
- FilterRepresentation representation = getLocalRepresentation();
- if (representation != null && mFilterTitle != null && representation.getTextId() != 0) {
- String text = mContext.getString(representation.getTextId()).toUpperCase();
- mFilterTitle.setText(text);
- updateText();
- }
- }
-
- public boolean useUtilityPanel() {
- return true;
- }
-
- public void openUtilityPanel(LinearLayout mAccessoryViewList) {
- setMenuIcon(false);
- if (mImageShow != null) {
- mImageShow.openUtilityPanel(mAccessoryViewList);
- }
- }
-
- protected void setMenuIcon(boolean on) {
- mEditTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
- 0, 0, on ? R.drawable.filtershow_menu_marker : 0, 0);
- }
-
- protected void createMenu(int[] strId, View button) {
- PopupMenu pmenu = new PopupMenu(mContext, button);
- Menu menu = pmenu.getMenu();
- for (int i = 0; i < strId.length; i++) {
- menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i]));
- }
- setMenuIcon(true);
-
- }
-
- public Control[] getControls() {
- return null;
- }
- @Override
- public void onStartTrackingTouch(SeekBar arg0) {
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar arg0) {
-
- }
-
- @Override
- public void swapLeft(MenuItem item) {
-
- }
-
- @Override
- public void swapRight(MenuItem item) {
-
- }
-
- public void detach() {
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java
deleted file mode 100644
index 7e31f09ae..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.os.Handler;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.LinearLayout;
-import android.widget.PopupMenu;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.BasicParameterStyle;
-import com.android.gallery3d.filtershow.controller.FilterView;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.filters.FilterChanSatRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequest;
-import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
-
-public class EditorChanSat extends ParametricEditor implements OnSeekBarChangeListener, FilterView {
- public static final int ID = R.id.editorChanSat;
- private final String LOGTAG = "EditorGrunge";
- private SwapButton mButton;
- private final Handler mHandler = new Handler();
-
- int[] mMenuStrings = {
- R.string.editor_chan_sat_main,
- R.string.editor_chan_sat_red,
- R.string.editor_chan_sat_yellow,
- R.string.editor_chan_sat_green,
- R.string.editor_chan_sat_cyan,
- R.string.editor_chan_sat_blue,
- R.string.editor_chan_sat_magenta
- };
-
- String mCurrentlyEditing = null;
-
- public EditorChanSat() {
- super(ID, R.layout.filtershow_default_editor, R.id.basicEditor);
- }
-
- @Override
- public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
- FilterRepresentation rep = getLocalRepresentation();
- if (rep == null || !(rep instanceof FilterChanSatRepresentation)) {
- return "";
- }
- FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep;
- int mode = csrep.getParameterMode();
- String paramString;
-
- paramString = mContext.getString(mMenuStrings[mode]);
-
- int val = csrep.getCurrentParameter();
- return paramString + ((val > 0) ? " +" : " ") + val;
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- mButton = (SwapButton) accessoryViewList.findViewById(R.id.applyEffect);
- mButton.setText(mContext.getString(R.string.editor_chan_sat_main));
-
- final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), mButton);
-
- popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_chan_sat, popupMenu.getMenu());
-
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- selectMenuItem(item);
- return true;
- }
- });
- mButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- popupMenu.show();
- }
- });
- mButton.setListener(this);
-
- FilterChanSatRepresentation csrep = getChanSatRep();
- String menuString = mContext.getString(mMenuStrings[0]);
- switchToMode(csrep, FilterChanSatRepresentation.MODE_MASTER, menuString);
-
- }
-
- public int getParameterIndex(int id) {
- switch (id) {
- case R.id.editor_chan_sat_main:
- return FilterChanSatRepresentation.MODE_MASTER;
- case R.id.editor_chan_sat_red:
- return FilterChanSatRepresentation.MODE_RED;
- case R.id.editor_chan_sat_yellow:
- return FilterChanSatRepresentation.MODE_YELLOW;
- case R.id.editor_chan_sat_green:
- return FilterChanSatRepresentation.MODE_GREEN;
- case R.id.editor_chan_sat_cyan:
- return FilterChanSatRepresentation.MODE_CYAN;
- case R.id.editor_chan_sat_blue:
- return FilterChanSatRepresentation.MODE_BLUE;
- case R.id.editor_chan_sat_magenta:
- return FilterChanSatRepresentation.MODE_MAGENTA;
- }
- return -1;
- }
-
- @Override
- public void detach() {
- mButton.setListener(null);
- mButton.setOnClickListener(null);
- }
-
- private void updateSeekBar(FilterChanSatRepresentation rep) {
- mControl.updateUI();
- }
-
- @Override
- protected Parameter getParameterToEdit(FilterRepresentation rep) {
- if (rep instanceof FilterChanSatRepresentation) {
- FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep;
- Parameter param = csrep.getFilterParameter(csrep.getParameterMode());
- if (param instanceof BasicParameterStyle) {
- param.setFilterView(EditorChanSat.this);
- }
- return param;
- }
- return null;
- }
-
- private FilterChanSatRepresentation getChanSatRep() {
- FilterRepresentation rep = getLocalRepresentation();
- if (rep != null
- && rep instanceof FilterChanSatRepresentation) {
- FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep;
- return csrep;
- }
- return null;
- }
-
- @Override
- public void computeIcon(int n, RenderingRequestCaller caller) {
- FilterChanSatRepresentation rep = getChanSatRep();
- if (rep == null) return;
- rep = (FilterChanSatRepresentation) rep.copy();
- ImagePreset preset = new ImagePreset();
- preset.addFilter(rep);
- Bitmap src = MasterImage.getImage().getThumbnailBitmap();
- RenderingRequest.post(null, src, preset, RenderingRequest.STYLE_ICON_RENDERING,
- caller);
- }
-
- protected void selectMenuItem(MenuItem item) {
- if (getLocalRepresentation() != null
- && getLocalRepresentation() instanceof FilterChanSatRepresentation) {
- FilterChanSatRepresentation csrep =
- (FilterChanSatRepresentation) getLocalRepresentation();
-
- switchToMode(csrep, getParameterIndex(item.getItemId()), item.getTitle().toString());
-
- }
- }
-
- protected void switchToMode(FilterChanSatRepresentation csrep, int mode, String title) {
- csrep.setParameterMode(mode);
- mCurrentlyEditing = title;
- mButton.setText(mCurrentlyEditing);
- {
- Parameter param = getParameterToEdit(csrep);
-
- control(param, mEditControl);
- }
- updateSeekBar(csrep);
- mView.invalidate();
- }
-
- @Override
- public void swapLeft(MenuItem item) {
- super.swapLeft(item);
- mButton.setTranslationX(0);
- mButton.animate().translationX(mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION);
- Runnable updateButton = new Runnable() {
- @Override
- public void run() {
- mButton.animate().cancel();
- mButton.setTranslationX(0);
- }
- };
- mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION);
- selectMenuItem(item);
- }
-
- @Override
- public void swapRight(MenuItem item) {
- super.swapRight(item);
- mButton.setTranslationX(0);
- mButton.animate().translationX(-mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION);
- Runnable updateButton = new Runnable() {
- @Override
- public void run() {
- mButton.animate().cancel();
- mButton.setTranslationX(0);
- }
- };
- mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION);
- selectMenuItem(item);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
deleted file mode 100644
index 511d4ff87..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.Log;
-import android.util.SparseArray;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.PopupMenu;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterCropRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageCrop;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class EditorCrop extends Editor implements EditorInfo {
- public static final String TAG = EditorCrop.class.getSimpleName();
- public static final int ID = R.id.editorCrop;
-
- // Holder for an aspect ratio it's string id
- protected static final class AspectInfo {
- int mAspectX;
- int mAspectY;
- int mStringId;
- AspectInfo(int stringID, int x, int y) {
- mStringId = stringID;
- mAspectX = x;
- mAspectY = y;
- }
- };
-
- // Mapping from menu id to aspect ratio
- protected static final SparseArray<AspectInfo> sAspects;
- static {
- sAspects = new SparseArray<AspectInfo>();
- sAspects.put(R.id.crop_menu_1to1, new AspectInfo(R.string.aspect1to1_effect, 1, 1));
- sAspects.put(R.id.crop_menu_4to3, new AspectInfo(R.string.aspect4to3_effect, 4, 3));
- sAspects.put(R.id.crop_menu_3to4, new AspectInfo(R.string.aspect3to4_effect, 3, 4));
- sAspects.put(R.id.crop_menu_5to7, new AspectInfo(R.string.aspect5to7_effect, 5, 7));
- sAspects.put(R.id.crop_menu_7to5, new AspectInfo(R.string.aspect7to5_effect, 7, 5));
- sAspects.put(R.id.crop_menu_none, new AspectInfo(R.string.aspectNone_effect, 0, 0));
- sAspects.put(R.id.crop_menu_original, new AspectInfo(R.string.aspectOriginal_effect, 0, 0));
- }
-
- protected ImageCrop mImageCrop;
- private String mAspectString = "";
-
- public EditorCrop() {
- super(ID);
- mChangesGeometry = true;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- if (mImageCrop == null) {
- mImageCrop = new ImageCrop(context);
- }
- mView = mImageShow = mImageCrop;
- mImageCrop.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- MasterImage master = MasterImage.getImage();
- master.setCurrentFilterRepresentation(master.getPreset()
- .getFilterWithSerializationName(FilterCropRepresentation.SERIALIZATION_NAME));
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep == null || rep instanceof FilterCropRepresentation) {
- mImageCrop.setFilterCropRepresentation((FilterCropRepresentation) rep);
- } else {
- Log.w(TAG, "Could not reflect current filter, not of type: "
- + FilterCropRepresentation.class.getSimpleName());
- }
- mImageCrop.invalidate();
- }
-
- @Override
- public void finalApplyCalled() {
- commitLocalRepresentation(mImageCrop.getFinalRepresentation());
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- view.setText(mContext.getString(R.string.crop));
- view.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- showPopupMenu(accessoryViewList);
- }
- });
- }
-
- private void changeCropAspect(int itemId) {
- AspectInfo info = sAspects.get(itemId);
- if (info == null) {
- throw new IllegalArgumentException("Invalid resource ID: " + itemId);
- }
- if (itemId == R.id.crop_menu_original) {
- mImageCrop.applyOriginalAspect();
- } else if (itemId == R.id.crop_menu_none) {
- mImageCrop.applyFreeAspect();
- } else {
- mImageCrop.applyAspect(info.mAspectX, info.mAspectY);
- }
- setAspectString(mContext.getString(info.mStringId));
- }
-
- private void showPopupMenu(LinearLayout accessoryViewList) {
- final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
- popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_crop, popupMenu.getMenu());
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- changeCropAspect(item.getItemId());
- return true;
- }
- });
- popupMenu.show();
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-
- @Override
- public int getTextId() {
- return R.string.crop;
- }
-
- @Override
- public int getOverlayId() {
- return R.drawable.filtershow_button_geometry_crop;
- }
-
- @Override
- public boolean getOverlayOnly() {
- return true;
- }
-
- private void setAspectString(String s) {
- mAspectString = s;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCurves.java b/src/com/android/gallery3d/filtershow/editors/EditorCurves.java
deleted file mode 100644
index 83fbced79..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorCurves.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterCurvesRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageCurves;
-
-public class EditorCurves extends Editor {
- public static final int ID = R.id.imageCurves;
- ImageCurves mImageCurves;
-
- public EditorCurves() {
- super(ID);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mView = mImageShow = mImageCurves = new ImageCurves(context);
- mImageCurves.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep != null && getLocalRepresentation() instanceof FilterCurvesRepresentation) {
- FilterCurvesRepresentation drawRep = (FilterCurvesRepresentation) rep;
- mImageCurves.setFilterDrawRepresentation(drawRep);
- }
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
deleted file mode 100644
index 4b09051e2..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.WindowManager.LayoutParams;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.PopupMenu;
-import android.widget.SeekBar;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.colorpicker.ColorGridDialog;
-import com.android.gallery3d.filtershow.colorpicker.RGBListener;
-import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.ImageFilterDraw;
-import com.android.gallery3d.filtershow.imageshow.ImageDraw;
-
-public class EditorDraw extends Editor {
- private static final String LOGTAG = "EditorDraw";
- public static final int ID = R.id.editorDraw;
- public ImageDraw mImageDraw;
-
- public EditorDraw() {
- super(ID);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mView = mImageShow = mImageDraw = new ImageDraw(context);
- mImageDraw.setEditor(this);
-
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
-
- if (rep != null && getLocalRepresentation() instanceof FilterDrawRepresentation) {
- FilterDrawRepresentation drawRep = (FilterDrawRepresentation) getLocalRepresentation();
- mImageDraw.setFilterDrawRepresentation(drawRep);
- }
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- view.setText(mContext.getString(R.string.draw_style));
- view.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- showPopupMenu(accessoryViewList);
- }
- });
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-
- private void showPopupMenu(LinearLayout accessoryViewList) {
- final Button button = (Button) accessoryViewList.findViewById(
- R.id.applyEffect);
- if (button == null) {
- return;
- }
- final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
- popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_draw, popupMenu.getMenu());
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
-
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter();
- if (item.getItemId() == R.id.draw_menu_color) {
- showColorGrid(item);
- } else if (item.getItemId() == R.id.draw_menu_size) {
- showSizeDialog(item);
- } else if (item.getItemId() == R.id.draw_menu_style_brush_marker) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_MARKER);
- } else if (item.getItemId() == R.id.draw_menu_style_brush_spatter) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_SPATTER);
- } else if (item.getItemId() == R.id.draw_menu_style_line) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.SIMPLE_STYLE);
- } else if (item.getItemId() == R.id.draw_menu_clear) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.resetParameter();
- commitLocalRepresentation();
- }
- mView.invalidate();
- return true;
- }
- });
- popupMenu.show();
- }
-
- public void showSizeDialog(final MenuItem item) {
- FilterShowActivity ctx = mImageShow.getActivity();
- final Dialog dialog = new Dialog(ctx);
- dialog.setTitle(R.string.draw_size_title);
- dialog.setContentView(R.layout.filtershow_draw_size);
- final SeekBar bar = (SeekBar) dialog.findViewById(R.id.sizeSeekBar);
- ImageDraw idraw = (ImageDraw) mImageShow;
- bar.setProgress(idraw.getSize());
- Button button = (Button) dialog.findViewById(R.id.sizeAcceptButton);
- button.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- int p = bar.getProgress();
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setSize(p + 1);
- dialog.dismiss();
- }
- });
- dialog.show();
- }
-
- public void showColorGrid(final MenuItem item) {
- RGBListener cl = new RGBListener() {
- @Override
- public void setColor(int rgb) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setColor(rgb);
- }
- };
- ColorGridDialog cpd = new ColorGridDialog(mImageShow.getActivity(), cl);
- cpd.show();
- LayoutParams params = cpd.getWindow().getAttributes();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorGrad.java b/src/com/android/gallery3d/filtershow/editors/EditorGrad.java
deleted file mode 100644
index f427ccbd8..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorGrad.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.PopupMenu;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.ToggleButton;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.Control;
-import com.android.gallery3d.filtershow.controller.FilterView;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.controller.ParameterActionAndInt;
-import com.android.gallery3d.filtershow.filters.FilterGradRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageGrad;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class EditorGrad extends ParametricEditor
- implements OnSeekBarChangeListener, ParameterActionAndInt {
- private static final String LOGTAG = "EditorGrad";
- public static final int ID = R.id.editorGrad;
- PopupMenu mPopupMenu;
- ToggleButton mAddModeButton;
- String mEffectName = "";
- private static final int MODE_BRIGHTNESS = FilterGradRepresentation.PARAM_BRIGHTNESS;
- private static final int MODE_SATURATION = FilterGradRepresentation.PARAM_SATURATION;
- private static final int MODE_CONTRAST = FilterGradRepresentation.PARAM_CONTRAST;
- private static final int ADD_ICON = R.drawable.ic_grad_add;
- private static final int DEL_ICON = R.drawable.ic_grad_del;
- private int mSliderMode = MODE_BRIGHTNESS;
- ImageGrad mImageGrad;
-
- public EditorGrad() {
- super(ID, R.layout.filtershow_grad_editor, R.id.gradEditor);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mImageGrad = (ImageGrad) mImageShow;
- mImageGrad.setEditor(this);
-
- }
-
- public void clearAddMode() {
- mAddModeButton.setChecked(false);
- FilterRepresentation tmpRep = getLocalRepresentation();
- if (tmpRep instanceof FilterGradRepresentation) {
- updateMenuItems((FilterGradRepresentation) tmpRep);
- }
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- FilterRepresentation tmpRep = getLocalRepresentation();
- if (tmpRep instanceof FilterGradRepresentation) {
- FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep;
- boolean f = rep.showParameterValue();
-
- mImageGrad.setRepresentation(rep);
- }
- }
-
- public void updateSeekBar(FilterGradRepresentation rep) {
- mControl.updateUI();
- }
-
- @Override
- public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
- FilterRepresentation tmpRep = getLocalRepresentation();
- if (tmpRep instanceof FilterGradRepresentation) {
- FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep;
- int min = rep.getParameterMin(mSliderMode);
- int value = progress + min;
- rep.setParameter(mSliderMode, value);
- mView.invalidate();
- commitLocalRepresentation();
- }
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- view.setText(mContext.getString(R.string.editor_grad_brightness));
- view.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- showPopupMenu(accessoryViewList);
- }
- });
-
- setUpPopupMenu(view);
- setEffectName();
- }
-
- private void updateMenuItems(FilterGradRepresentation rep) {
- int n = rep.getNumberOfBands();
- }
-
- public void setEffectName() {
- if (mPopupMenu != null) {
- MenuItem item = mPopupMenu.getMenu().findItem(R.id.editor_grad_brightness);
- mEffectName = item.getTitle().toString();
- }
- }
-
- private void showPopupMenu(LinearLayout accessoryViewList) {
- Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- if (button == null) {
- return;
- }
-
- if (mPopupMenu == null) {
- setUpPopupMenu(button);
- }
- mPopupMenu.show();
- }
-
- private void setUpPopupMenu(Button button) {
- mPopupMenu = new PopupMenu(mImageShow.getActivity(), button);
- mPopupMenu.getMenuInflater()
- .inflate(R.menu.filtershow_menu_grad, mPopupMenu.getMenu());
- FilterGradRepresentation rep = (FilterGradRepresentation) getLocalRepresentation();
- if (rep == null) {
- return;
- }
- updateMenuItems(rep);
- hackFixStrings(mPopupMenu.getMenu());
- setEffectName();
- updateText();
-
- mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- FilterRepresentation tmpRep = getLocalRepresentation();
-
- if (tmpRep instanceof FilterGradRepresentation) {
- FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep;
- int cmdID = item.getItemId();
- switch (cmdID) {
- case R.id.editor_grad_brightness:
- mSliderMode = MODE_BRIGHTNESS;
- mEffectName = item.getTitle().toString();
- break;
- case R.id.editor_grad_contrast:
- mSliderMode = MODE_CONTRAST;
- mEffectName = item.getTitle().toString();
- break;
- case R.id.editor_grad_saturation:
- mSliderMode = MODE_SATURATION;
- mEffectName = item.getTitle().toString();
- break;
- }
- updateMenuItems(rep);
- updateSeekBar(rep);
-
- commitLocalRepresentation();
- mView.invalidate();
- }
- return true;
- }
- });
- }
-
- @Override
- public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return mEffectName;
- }
- int val = rep.getParameter(mSliderMode);
- return mEffectName.toUpperCase() + ((val > 0) ? " +" : " ") + val;
- }
-
- private FilterGradRepresentation getGradRepresentation() {
- FilterRepresentation tmpRep = getLocalRepresentation();
- if (tmpRep instanceof FilterGradRepresentation) {
- return (FilterGradRepresentation) tmpRep;
- }
- return null;
- }
-
- @Override
- public int getMaximum() {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getParameterMax(mSliderMode);
- }
-
- @Override
- public int getMinimum() {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getParameterMin(mSliderMode);
- }
-
- @Override
- public int getDefaultValue() {
- return 0;
- }
-
- @Override
- public int getValue() {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return 0;
- }
- return rep.getParameter(mSliderMode);
- }
-
- @Override
- public String getValueString() {
- return null;
- }
-
- @Override
- public void setValue(int value) {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return;
- }
- rep.setParameter(mSliderMode, value);
- }
-
- @Override
- public String getParameterName() {
- return mEffectName;
- }
-
- @Override
- public String getParameterType() {
- return sParameterType;
- }
-
- @Override
- public void setController(Control c) {
-
- }
-
- @Override
- public void fireLeftAction() {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return;
- }
- rep.addBand(MasterImage.getImage().getOriginalBounds());
- updateMenuItems(rep);
- updateSeekBar(rep);
-
- commitLocalRepresentation();
- mView.invalidate();
- }
-
- @Override
- public int getLeftIcon() {
- return ADD_ICON;
- }
-
- @Override
- public void fireRightAction() {
- FilterGradRepresentation rep = getGradRepresentation();
- if (rep == null) {
- return;
- }
- rep.deleteCurrentBand();
-
- updateMenuItems(rep);
- updateSeekBar(rep);
- commitLocalRepresentation();
- mView.invalidate();
- }
-
- @Override
- public int getRightIcon() {
- return DEL_ICON;
- }
-
- @Override
- public void setFilterView(FilterView editor) {
-
- }
-
- @Override
- public void copyFrom(Parameter src) {
-
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorInfo.java b/src/com/android/gallery3d/filtershow/editors/EditorInfo.java
deleted file mode 100644
index 75afe49c2..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorInfo.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-public interface EditorInfo {
- public int getTextId();
- public int getOverlayId();
- public boolean getOverlayOnly();
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorMirror.java b/src/com/android/gallery3d/filtershow/editors/EditorMirror.java
deleted file mode 100644
index d6d9ee75d..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorMirror.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageMirror;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class EditorMirror extends Editor implements EditorInfo {
- public static final String TAG = EditorMirror.class.getSimpleName();
- public static final int ID = R.id.editorFlip;
- ImageMirror mImageMirror;
-
- public EditorMirror() {
- super(ID);
- mChangesGeometry = true;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- if (mImageMirror == null) {
- mImageMirror = new ImageMirror(context);
- }
- mView = mImageShow = mImageMirror;
- mImageMirror.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- MasterImage master = MasterImage.getImage();
- master.setCurrentFilterRepresentation(master.getPreset()
- .getFilterWithSerializationName(FilterMirrorRepresentation.SERIALIZATION_NAME));
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep == null || rep instanceof FilterMirrorRepresentation) {
- mImageMirror.setFilterMirrorRepresentation((FilterMirrorRepresentation) rep);
- } else {
- Log.w(TAG, "Could not reflect current filter, not of type: "
- + FilterMirrorRepresentation.class.getSimpleName());
- }
- mImageMirror.invalidate();
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- mImageMirror.flip();
- }
- });
- }
-
- @Override
- public void finalApplyCalled() {
- commitLocalRepresentation(mImageMirror.getFinalRepresentation());
- }
-
- @Override
- public int getTextId() {
- return R.string.mirror;
- }
-
- @Override
- public int getOverlayId() {
- return R.drawable.filtershow_button_geometry_flip;
- }
-
- @Override
- public boolean getOverlayOnly() {
- return true;
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-
- @Override
- public boolean showsPopupIndicator() {
- return false;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
deleted file mode 100644
index bc4ca6ab6..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.LinearLayout;
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.history.HistoryManager;
-import com.android.gallery3d.filtershow.category.MainPanel;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.state.StatePanel;
-
-public class EditorPanel extends Fragment {
-
- private static final String LOGTAG = "EditorPanel";
-
- private LinearLayout mMainView;
- private Editor mEditor;
- private int mEditorID;
-
- public void setEditor(int editor) {
- mEditorID = editor;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- FilterShowActivity filterShowActivity = (FilterShowActivity) activity;
- mEditor = filterShowActivity.getEditor(mEditorID);
- }
-
- public void cancelCurrentFilter() {
- MasterImage masterImage = MasterImage.getImage();
- HistoryManager adapter = masterImage.getHistory();
-
- int position = adapter.undo();
- masterImage.onHistoryItemClick(position);
- ((FilterShowActivity)getActivity()).invalidateViews();
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- if (mMainView != null) {
- if (mMainView.getParent() != null) {
- ViewGroup parent = (ViewGroup) mMainView.getParent();
- parent.removeView(mMainView);
- }
- showImageStatePanel(activity.isShowingImageStatePanel());
- return mMainView;
- }
- mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_editor_panel, null);
-
- View actionControl = mMainView.findViewById(R.id.panelAccessoryViewList);
- View editControl = mMainView.findViewById(R.id.controlArea);
- ImageButton cancelButton = (ImageButton) mMainView.findViewById(R.id.cancelFilter);
- ImageButton applyButton = (ImageButton) mMainView.findViewById(R.id.applyFilter);
- Button editTitle = (Button) mMainView.findViewById(R.id.applyEffect);
- cancelButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- cancelCurrentFilter();
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- activity.backToMain();
- }
- });
-
- Button toggleState = (Button) mMainView.findViewById(R.id.toggle_state);
- mEditor = activity.getEditor(mEditorID);
- if (mEditor != null) {
- mEditor.setUpEditorUI(actionControl, editControl, editTitle, toggleState);
- mEditor.reflectCurrentFilter();
- if (mEditor.useUtilityPanel()) {
- mEditor.openUtilityPanel((LinearLayout) actionControl);
- }
- }
- applyButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- mEditor.finalApplyCalled();
- activity.backToMain();
- }
- });
-
- showImageStatePanel(activity.isShowingImageStatePanel());
- return mMainView;
- }
-
- @Override
- public void onDetach() {
- if (mEditor != null) {
- mEditor.detach();
- }
- super.onDetach();
- }
-
- public void showImageStatePanel(boolean show) {
- if (mMainView.findViewById(R.id.state_panel_container) == null) {
- return;
- }
- FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
- Fragment panel = getActivity().getSupportFragmentManager().findFragmentByTag(
- MainPanel.FRAGMENT_TAG);
- if (panel == null || panel instanceof MainPanel) {
- transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
- }
- if (show) {
- StatePanel statePanel = new StatePanel();
- transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
- } else {
- Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
- if (statePanel != null) {
- transaction.remove(statePanel);
- }
- }
- transaction.commit();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java b/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java
deleted file mode 100644
index b0e88dd44..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterRedEyeRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageRedEye;
-
-/**
- * The editor with no slider for filters without UI
- */
-public class EditorRedEye extends Editor {
- public static int ID = R.id.editorRedEye;
- private final String LOGTAG = "EditorRedEye";
- ImageRedEye mImageRedEyes;
-
- public EditorRedEye() {
- super(ID);
- }
-
- protected EditorRedEye(int id) {
- super(id);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mView = mImageShow = mImageRedEyes= new ImageRedEye(context);
- mImageRedEyes.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep != null && getLocalRepresentation() instanceof FilterRedEyeRepresentation) {
- FilterRedEyeRepresentation redEyeRep = (FilterRedEyeRepresentation) rep;
-
- mImageRedEyes.setRepresentation(redEyeRep);
- }
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
deleted file mode 100644
index 9452bf0c0..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageRotate;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class EditorRotate extends Editor implements EditorInfo {
- public static final String TAG = EditorRotate.class.getSimpleName();
- public static final int ID = R.id.editorRotate;
- ImageRotate mImageRotate;
-
- public EditorRotate() {
- super(ID);
- mChangesGeometry = true;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- if (mImageRotate == null) {
- mImageRotate = new ImageRotate(context);
- }
- mView = mImageShow = mImageRotate;
- mImageRotate.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- MasterImage master = MasterImage.getImage();
- master.setCurrentFilterRepresentation(master.getPreset()
- .getFilterWithSerializationName(FilterRotateRepresentation.SERIALIZATION_NAME));
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep == null || rep instanceof FilterRotateRepresentation) {
- mImageRotate.setFilterRotateRepresentation((FilterRotateRepresentation) rep);
- } else {
- Log.w(TAG, "Could not reflect current filter, not of type: "
- + FilterRotateRepresentation.class.getSimpleName());
- }
- mImageRotate.invalidate();
- }
-
- @Override
- public void openUtilityPanel(final LinearLayout accessoryViewList) {
- final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
- button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- mImageRotate.rotate();
- String displayVal = mContext.getString(getTextId()) + " "
- + mImageRotate.getLocalValue();
- button.setText(displayVal);
- }
- });
- }
-
- @Override
- public void finalApplyCalled() {
- commitLocalRepresentation(mImageRotate.getFinalRepresentation());
- }
-
- @Override
- public int getTextId() {
- return R.string.rotate;
- }
-
- @Override
- public int getOverlayId() {
- return R.drawable.filtershow_button_geometry_rotate;
- }
-
- @Override
- public boolean getOverlayOnly() {
- return true;
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-
- @Override
- public boolean showsPopupIndicator() {
- return false;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
deleted file mode 100644
index ff84ba8f9..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.Log;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageStraighten;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class EditorStraighten extends Editor implements EditorInfo {
- public static final String TAG = EditorStraighten.class.getSimpleName();
- public static final int ID = R.id.editorStraighten;
- ImageStraighten mImageStraighten;
-
- public EditorStraighten() {
- super(ID);
- mShowParameter = SHOW_VALUE_INT;
- mChangesGeometry = true;
- }
-
- @Override
- public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
- String apply = context.getString(R.string.apply_effect);
- apply += " " + effectName;
- return apply.toUpperCase();
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- if (mImageStraighten == null) {
- mImageStraighten = new ImageStraighten(context);
- }
- mView = mImageShow = mImageStraighten;
- mImageStraighten.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- MasterImage master = MasterImage.getImage();
- master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName(
- FilterStraightenRepresentation.SERIALIZATION_NAME));
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep == null || rep instanceof FilterStraightenRepresentation) {
- mImageStraighten
- .setFilterStraightenRepresentation((FilterStraightenRepresentation) rep);
- } else {
- Log.w(TAG, "Could not reflect current filter, not of type: "
- + FilterStraightenRepresentation.class.getSimpleName());
- }
- mImageStraighten.invalidate();
- }
-
- @Override
- public void finalApplyCalled() {
- commitLocalRepresentation(mImageStraighten.getFinalRepresentation());
- }
-
- @Override
- public int getTextId() {
- return R.string.straighten;
- }
-
- @Override
- public int getOverlayId() {
- return R.drawable.filtershow_button_geometry_straighten;
- }
-
- @Override
- public boolean getOverlayOnly() {
- return true;
- }
-
- @Override
- public boolean showsSeekBar() {
- return false;
- }
-
- @Override
- public boolean showsPopupIndicator() {
- return false;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java b/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java
deleted file mode 100644
index 9376fbef0..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet;
-
-public class EditorTinyPlanet extends BasicEditor {
- public static final int ID = R.id.tinyPlanetEditor;
- private static final String LOGTAG = "EditorTinyPlanet";
- ImageTinyPlanet mImageTinyPlanet;
-
- public EditorTinyPlanet() {
- super(ID, R.layout.filtershow_tiny_planet_editor, R.id.imageTinyPlanet);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mImageTinyPlanet = (ImageTinyPlanet) mImageShow;
- mImageTinyPlanet.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- FilterRepresentation rep = getLocalRepresentation();
- if (rep != null && rep instanceof FilterTinyPlanetRepresentation) {
- FilterTinyPlanetRepresentation drawRep = (FilterTinyPlanetRepresentation) rep;
- mImageTinyPlanet.setRepresentation(drawRep);
- }
- }
-
- public void updateUI() {
- if (mControl != null) {
- mControl.updateUI();
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorVignette.java b/src/com/android/gallery3d/filtershow/editors/EditorVignette.java
deleted file mode 100644
index 7127b2188..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorVignette.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation;
-import com.android.gallery3d.filtershow.imageshow.ImageVignette;
-
-public class EditorVignette extends ParametricEditor {
- public static final int ID = R.id.vignetteEditor;
- private static final String LOGTAG = "EditorVignettePlanet";
- ImageVignette mImageVignette;
-
- public EditorVignette() {
- super(ID, R.layout.filtershow_vignette_editor, R.id.imageVignette);
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mImageVignette = (ImageVignette) mImageShow;
- mImageVignette.setEditor(this);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
-
- FilterRepresentation rep = getLocalRepresentation();
- if (rep != null && getLocalRepresentation() instanceof FilterVignetteRepresentation) {
- FilterVignetteRepresentation drawRep = (FilterVignetteRepresentation) rep;
- mImageVignette.setRepresentation(drawRep);
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorZoom.java b/src/com/android/gallery3d/filtershow/editors/EditorZoom.java
deleted file mode 100644
index ea8e3d140..000000000
--- a/src/com/android/gallery3d/filtershow/editors/EditorZoom.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import com.android.gallery3d.R;
-
-public class EditorZoom extends BasicEditor {
- public static final int ID = R.id.imageZoom;
-
- public EditorZoom() {
- super(ID, R.layout.filtershow_zoom_editor,R.id.imageZoom);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java b/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java
deleted file mode 100644
index d4e66edf8..000000000
--- a/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.widget.FrameLayout;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.imageshow.ImageShow;
-
-/**
- * The editor with no slider for filters without UI
- */
-public class ImageOnlyEditor extends Editor {
- public final static int ID = R.id.imageOnlyEditor;
- private final String LOGTAG = "ImageOnlyEditor";
-
- public ImageOnlyEditor() {
- super(ID);
- }
-
- protected ImageOnlyEditor(int id) {
- super(id);
- }
-
- public boolean useUtilityPanel() {
- return false;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- mView = mImageShow = new ImageShow(context);
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
deleted file mode 100644
index 9ec858ca5..000000000
--- a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
-import android.view.WindowManager;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.SeekBar;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.ActionSlider;
-import com.android.gallery3d.filtershow.controller.BasicSlider;
-import com.android.gallery3d.filtershow.controller.Control;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.controller.ParameterActionAndInt;
-import com.android.gallery3d.filtershow.controller.ParameterInteger;
-import com.android.gallery3d.filtershow.controller.ParameterStyles;
-import com.android.gallery3d.filtershow.controller.StyleChooser;
-import com.android.gallery3d.filtershow.controller.TitledSlider;
-import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
-import com.android.gallery3d.filtershow.filters.FilterRepresentation;
-
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-
-public class ParametricEditor extends Editor {
- private int mLayoutID;
- private int mViewID;
- public static int ID = R.id.editorParametric;
- private final String LOGTAG = "ParametricEditor";
- protected Control mControl;
- public static final int MINIMUM_WIDTH = 600;
- public static final int MINIMUM_HEIGHT = 800;
- View mActionButton;
- View mEditControl;
- static HashMap<String, Class> portraitMap = new HashMap<String, Class>();
- static HashMap<String, Class> landscapeMap = new HashMap<String, Class>();
- static {
- portraitMap.put(ParameterInteger.sParameterType, BasicSlider.class);
- landscapeMap.put(ParameterInteger.sParameterType, TitledSlider.class);
- portraitMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
- landscapeMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
- portraitMap.put(ParameterStyles.sParameterType, StyleChooser.class);
- landscapeMap.put(ParameterStyles.sParameterType, StyleChooser.class);
- }
-
- static Constructor getConstructor(Class cl) {
- try {
- return cl.getConstructor(Context.class, ViewGroup.class);
- } catch (Exception e) {
- return null;
- }
- }
-
- public ParametricEditor() {
- super(ID);
- }
-
- protected ParametricEditor(int id) {
- super(id);
- }
-
- protected ParametricEditor(int id, int layoutID, int viewID) {
- super(id);
- mLayoutID = layoutID;
- mViewID = viewID;
- }
-
- @Override
- public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
- String apply = "";
-
- if (mShowParameter == SHOW_VALUE_INT & useCompact(context)) {
- if (getLocalRepresentation() instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
- apply += " " + effectName.toUpperCase() + " " + interval.getStateRepresentation();
- } else {
- apply += " " + effectName.toUpperCase() + " " + parameterValue;
- }
- } else {
- apply += " " + effectName.toUpperCase();
- }
- return apply;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- unpack(mViewID, mLayoutID);
- }
-
- @Override
- public void reflectCurrentFilter() {
- super.reflectCurrentFilter();
- if (getLocalRepresentation() != null
- && getLocalRepresentation() instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
- mControl.setPrameter(interval);
- }
- }
-
- @Override
- public Control[] getControls() {
- BasicSlider slider = new BasicSlider();
- return new Control[] {
- slider
- };
- }
-
- // TODO: need a better way to decide which representation
- static boolean useCompact(Context context) {
- WindowManager w = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
- Point size = new Point();
- w.getDefaultDisplay().getSize(size);
- if (size.x < size.y) { // if tall than wider
- return true;
- }
- if (size.x < MINIMUM_WIDTH) {
- return true;
- }
- if (size.y < MINIMUM_HEIGHT) {
- return true;
- }
- return false;
- }
-
- protected Parameter getParameterToEdit(FilterRepresentation rep) {
- if (this instanceof Parameter) {
- return (Parameter) this;
- } else if (rep instanceof Parameter) {
- return ((Parameter) rep);
- }
- return null;
- }
-
- @Override
- public void setUtilityPanelUI(View actionButton, View editControl) {
- mActionButton = actionButton;
- mEditControl = editControl;
- FilterRepresentation rep = getLocalRepresentation();
- Parameter param = getParameterToEdit(rep);
- if (param != null) {
- control(param, editControl);
- } else {
- mSeekBar = new SeekBar(editControl.getContext());
- LayoutParams lp = new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- mSeekBar.setLayoutParams(lp);
- ((LinearLayout) editControl).addView(mSeekBar);
- mSeekBar.setOnSeekBarChangeListener(this);
- }
- }
-
- protected void control(Parameter p, View editControl) {
- String pType = p.getParameterType();
- Context context = editControl.getContext();
- Class c = ((useCompact(context)) ? portraitMap : landscapeMap).get(pType);
-
- if (c != null) {
- try {
- mControl = (Control) c.newInstance();
- p.setController(mControl);
- mControl.setUp((ViewGroup) editControl, p, this);
- } catch (Exception e) {
- Log.e(LOGTAG, "Error in loading Control ", e);
- }
- } else {
- Log.e(LOGTAG, "Unable to find class for " + pType);
- for (String string : portraitMap.keySet()) {
- Log.e(LOGTAG, "for " + string + " use " + portraitMap.get(string));
- }
- }
- }
-
- @Override
- public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar arg0) {
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar arg0) {
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/editors/SwapButton.java b/src/com/android/gallery3d/filtershow/editors/SwapButton.java
deleted file mode 100644
index bb4432e28..000000000
--- a/src/com/android/gallery3d/filtershow/editors/SwapButton.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.editors;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.GestureDetector;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.widget.Button;
-
-public class SwapButton extends Button implements GestureDetector.OnGestureListener {
-
- public static int ANIM_DURATION = 200;
-
- public interface SwapButtonListener {
- public void swapLeft(MenuItem item);
- public void swapRight(MenuItem item);
- }
-
- private GestureDetector mDetector;
- private SwapButtonListener mListener;
- private Menu mMenu;
- private int mCurrentMenuIndex;
-
- public SwapButton(Context context, AttributeSet attrs) {
- super(context, attrs);
- mDetector = new GestureDetector(context, this);
- }
-
- public SwapButtonListener getListener() {
- return mListener;
- }
-
- public void setListener(SwapButtonListener listener) {
- mListener = listener;
- }
-
- public boolean onTouchEvent(MotionEvent me) {
- if (!mDetector.onTouchEvent(me)) {
- return super.onTouchEvent(me);
- }
- return true;
- }
-
- @Override
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- @Override
- public void onShowPress(MotionEvent e) {
- }
-
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- callOnClick();
- return true;
- }
-
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- return false;
- }
-
- @Override
- public void onLongPress(MotionEvent e) {
- }
-
- @Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- if (mMenu == null) {
- return false;
- }
- if (e1.getX() - e2.getX() > 0) {
- // right to left
- mCurrentMenuIndex++;
- if (mCurrentMenuIndex == mMenu.size()) {
- mCurrentMenuIndex = 0;
- }
- if (mListener != null) {
- mListener.swapRight(mMenu.getItem(mCurrentMenuIndex));
- }
- } else {
- // left to right
- mCurrentMenuIndex--;
- if (mCurrentMenuIndex < 0) {
- mCurrentMenuIndex = mMenu.size() - 1;
- }
- if (mListener != null) {
- mListener.swapLeft(mMenu.getItem(mCurrentMenuIndex));
- }
- }
- return true;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
deleted file mode 100644
index 3fa91916d..000000000
--- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.filters;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorCrop;
-import com.android.gallery3d.filtershow.editors.EditorMirror;
-import com.android.gallery3d.filtershow.editors.EditorRotate;
-import com.android.gallery3d.filtershow.editors.EditorStraighten;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Vector;
-
-public abstract class BaseFiltersManager implements FiltersManagerInterface {
- protected HashMap<Class, ImageFilter> mFilters = null;
- protected HashMap<String, FilterRepresentation> mRepresentationLookup = null;
- private static final String LOGTAG = "BaseFiltersManager";
-
- protected ArrayList<FilterRepresentation> mLooks = new ArrayList<FilterRepresentation>();
- protected ArrayList<FilterRepresentation> mBorders = new ArrayList<FilterRepresentation>();
- protected ArrayList<FilterRepresentation> mTools = new ArrayList<FilterRepresentation>();
- protected ArrayList<FilterRepresentation> mEffects = new ArrayList<FilterRepresentation>();
-
- protected void init() {
- mFilters = new HashMap<Class, ImageFilter>();
- mRepresentationLookup = new HashMap<String, FilterRepresentation>();
- Vector<Class> filters = new Vector<Class>();
- addFilterClasses(filters);
- for (Class filterClass : filters) {
- try {
- Object filterInstance = filterClass.newInstance();
- if (filterInstance instanceof ImageFilter) {
- mFilters.put(filterClass, (ImageFilter) filterInstance);
-
- FilterRepresentation rep =
- ((ImageFilter) filterInstance).getDefaultRepresentation();
- if (rep != null) {
- addRepresentation(rep);
- }
- }
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
-
- public void addRepresentation(FilterRepresentation rep) {
- mRepresentationLookup.put(rep.getSerializationName(), rep);
- }
-
- public FilterRepresentation createFilterFromName(String name) {
- try {
- return mRepresentationLookup.get(name).copy();
- } catch (Exception e) {
- Log.v(LOGTAG, "unable to generate a filter representation for \"" + name + "\"");
- e.printStackTrace();
- }
- return null;
- }
-
- public ImageFilter getFilter(Class c) {
- return mFilters.get(c);
- }
-
- @Override
- public ImageFilter getFilterForRepresentation(FilterRepresentation representation) {
- return mFilters.get(representation.getFilterClass());
- }
-
- public FilterRepresentation getRepresentation(Class c) {
- ImageFilter filter = mFilters.get(c);
- if (filter != null) {
- return filter.getDefaultRepresentation();
- }
- return null;
- }
-
- public void freeFilterResources(ImagePreset preset) {
- if (preset == null) {
- return;
- }
- Vector<ImageFilter> usedFilters = preset.getUsedFilters(this);
- for (Class c : mFilters.keySet()) {
- ImageFilter filter = mFilters.get(c);
- if (!usedFilters.contains(filter)) {
- filter.freeResources();
- }
- }
- }
-
- public void freeRSFilterScripts() {
- for (Class c : mFilters.keySet()) {
- ImageFilter filter = mFilters.get(c);
- if (filter != null && filter instanceof ImageFilterRS) {
- ((ImageFilterRS) filter).resetScripts();
- }
- }
- }
-
- protected void addFilterClasses(Vector<Class> filters) {
- filters.add(ImageFilterTinyPlanet.class);
- filters.add(ImageFilterRedEye.class);
- filters.add(ImageFilterWBalance.class);
- filters.add(ImageFilterExposure.class);
- filters.add(ImageFilterVignette.class);
- filters.add(ImageFilterGrad.class);
- filters.add(ImageFilterContrast.class);
- filters.add(ImageFilterShadows.class);
- filters.add(ImageFilterHighlights.class);
- filters.add(ImageFilterVibrance.class);
- filters.add(ImageFilterSharpen.class);
- filters.add(ImageFilterCurves.class);
- filters.add(ImageFilterDraw.class);
- filters.add(ImageFilterHue.class);
- filters.add(ImageFilterChanSat.class);
- filters.add(ImageFilterSaturated.class);
- filters.add(ImageFilterBwFilter.class);
- filters.add(ImageFilterNegative.class);
- filters.add(ImageFilterEdge.class);
- filters.add(ImageFilterKMeans.class);
- filters.add(ImageFilterFx.class);
- filters.add(ImageFilterBorder.class);
- filters.add(ImageFilterParametricBorder.class);
- }
-
- public ArrayList<FilterRepresentation> getLooks() {
- return mLooks;
- }
-
- public ArrayList<FilterRepresentation> getBorders() {
- return mBorders;
- }
-
- public ArrayList<FilterRepresentation> getTools() {
- return mTools;
- }
-
- public ArrayList<FilterRepresentation> getEffects() {
- return mEffects;
- }
-
- public void addBorders(Context context) {
-
- }
-
- public void addLooks(Context context) {
- int[] drawid = {
- R.drawable.filtershow_fx_0005_punch,
- R.drawable.filtershow_fx_0000_vintage,
- R.drawable.filtershow_fx_0004_bw_contrast,
- R.drawable.filtershow_fx_0002_bleach,
- R.drawable.filtershow_fx_0001_instant,
- R.drawable.filtershow_fx_0007_washout,
- R.drawable.filtershow_fx_0003_blue_crush,
- R.drawable.filtershow_fx_0008_washout_color,
- R.drawable.filtershow_fx_0006_x_process
- };
-
- int[] fxNameid = {
- R.string.ffx_punch,
- R.string.ffx_vintage,
- R.string.ffx_bw_contrast,
- R.string.ffx_bleach,
- R.string.ffx_instant,
- R.string.ffx_washout,
- R.string.ffx_blue_crush,
- R.string.ffx_washout_color,
- R.string.ffx_x_process
- };
-
- // Do not localize.
- String[] serializationNames = {
- "LUT3D_PUNCH",
- "LUT3D_VINTAGE",
- "LUT3D_BW",
- "LUT3D_BLEACH",
- "LUT3D_INSTANT",
- "LUT3D_WASHOUT",
- "LUT3D_BLUECRUSH",
- "LUT3D_WASHOUT",
- "LUT3D_XPROCESS"
- };
-
- FilterFxRepresentation nullFx =
- new FilterFxRepresentation(context.getString(R.string.none),
- 0, R.string.none);
- mLooks.add(nullFx);
-
- for (int i = 0; i < drawid.length; i++) {
- FilterFxRepresentation fx = new FilterFxRepresentation(
- context.getString(fxNameid[i]), drawid[i], fxNameid[i]);
- fx.setSerializationName(serializationNames[i]);
- ImagePreset preset = new ImagePreset();
- preset.addFilter(fx);
- FilterUserPresetRepresentation rep = new FilterUserPresetRepresentation(
- context.getString(fxNameid[i]), preset, -1);
- mLooks.add(rep);
- addRepresentation(fx);
- }
- }
-
- public void addEffects() {
- mEffects.add(getRepresentation(ImageFilterTinyPlanet.class));
- mEffects.add(getRepresentation(ImageFilterWBalance.class));
- mEffects.add(getRepresentation(ImageFilterExposure.class));
- mEffects.add(getRepresentation(ImageFilterVignette.class));
- mEffects.add(getRepresentation(ImageFilterGrad.class));
- mEffects.add(getRepresentation(ImageFilterContrast.class));
- mEffects.add(getRepresentation(ImageFilterShadows.class));
- mEffects.add(getRepresentation(ImageFilterHighlights.class));
- mEffects.add(getRepresentation(ImageFilterVibrance.class));
- mEffects.add(getRepresentation(ImageFilterSharpen.class));
- mEffects.add(getRepresentation(ImageFilterCurves.class));
- mEffects.add(getRepresentation(ImageFilterHue.class));
- mEffects.add(getRepresentation(ImageFilterChanSat.class));
- mEffects.add(getRepresentation(ImageFilterBwFilter.class));
- mEffects.add(getRepresentation(ImageFilterNegative.class));
- mEffects.add(getRepresentation(ImageFilterEdge.class));
- mEffects.add(getRepresentation(ImageFilterKMeans.class));
- }
-
- public void addTools(Context context) {
-
- int[] editorsId = {
- EditorCrop.ID,
- EditorStraighten.ID,
- EditorRotate.ID,
- EditorMirror.ID
- };
-
- int[] textId = {
- R.string.crop,
- R.string.straighten,
- R.string.rotate,
- R.string.mirror
- };
-
- int[] overlayId = {
- R.drawable.filtershow_button_geometry_crop,
- R.drawable.filtershow_button_geometry_straighten,
- R.drawable.filtershow_button_geometry_rotate,
- R.drawable.filtershow_button_geometry_flip
- };
-
- FilterRepresentation[] geometryFilters = {
- new FilterCropRepresentation(),
- new FilterStraightenRepresentation(),
- new FilterRotateRepresentation(),
- new FilterMirrorRepresentation()
- };
-
- for (int i = 0; i < editorsId.length; i++) {
- int editorId = editorsId[i];
- FilterRepresentation geometry = geometryFilters[i];
- geometry.setEditorId(editorId);
- geometry.setTextId(textId[i]);
- geometry.setOverlayId(overlayId[i]);
- geometry.setOverlayOnly(true);
- if (geometry.getTextId() != 0) {
- geometry.setName(context.getString(geometry.getTextId()));
- }
- mTools.add(geometry);
- }
-
- mTools.add(getRepresentation(ImageFilterRedEye.class));
- mTools.add(getRepresentation(ImageFilterDraw.class));
- }
-
- public void setFilterResources(Resources resources) {
- ImageFilterBorder filterBorder = (ImageFilterBorder) getFilter(ImageFilterBorder.class);
- filterBorder.setResources(resources);
- ImageFilterFx filterFx = (ImageFilterFx) getFilter(ImageFilterFx.class);
- filterFx.setResources(resources);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ColorSpaceMatrix.java b/src/com/android/gallery3d/filtershow/filters/ColorSpaceMatrix.java
deleted file mode 100644
index 7c307a9e7..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ColorSpaceMatrix.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import java.util.Arrays;
-
-public class ColorSpaceMatrix {
- private final float[] mMatrix = new float[16];
- private static final float RLUM = 0.3086f;
- private static final float GLUM = 0.6094f;
- private static final float BLUM = 0.0820f;
-
- public ColorSpaceMatrix() {
- identity();
- }
-
- /**
- * Copy constructor
- *
- * @param matrix
- */
- public ColorSpaceMatrix(ColorSpaceMatrix matrix) {
- System.arraycopy(matrix.mMatrix, 0, mMatrix, 0, matrix.mMatrix.length);
- }
-
- /**
- * get the matrix
- *
- * @return the internal matrix
- */
- public float[] getMatrix() {
- return mMatrix;
- }
-
- /**
- * set matrix to identity
- */
- public void identity() {
- Arrays.fill(mMatrix, 0);
- mMatrix[0] = mMatrix[5] = mMatrix[10] = mMatrix[15] = 1;
- }
-
- public void convertToLuminance() {
- mMatrix[0] = mMatrix[1] = mMatrix[2] = 0.3086f;
- mMatrix[4] = mMatrix[5] = mMatrix[6] = 0.6094f;
- mMatrix[8] = mMatrix[9] = mMatrix[10] = 0.0820f;
- }
-
- private void multiply(float[] a)
- {
- int x, y;
- float[] temp = new float[16];
-
- for (y = 0; y < 4; y++) {
- int y4 = y * 4;
- for (x = 0; x < 4; x++) {
- temp[y4 + x] = mMatrix[y4 + 0] * a[x]
- + mMatrix[y4 + 1] * a[4 + x]
- + mMatrix[y4 + 2] * a[8 + x]
- + mMatrix[y4 + 3] * a[12 + x];
- }
- }
- for (int i = 0; i < 16; i++)
- mMatrix[i] = temp[i];
- }
-
- private void xRotateMatrix(float rs, float rc)
- {
- ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.mMatrix;
-
- tmp[5] = rc;
- tmp[6] = rs;
- tmp[9] = -rs;
- tmp[10] = rc;
-
- multiply(tmp);
- }
-
- private void yRotateMatrix(float rs, float rc)
- {
- ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.mMatrix;
-
- tmp[0] = rc;
- tmp[2] = -rs;
- tmp[8] = rs;
- tmp[10] = rc;
-
- multiply(tmp);
- }
-
- private void zRotateMatrix(float rs, float rc)
- {
- ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.mMatrix;
-
- tmp[0] = rc;
- tmp[1] = rs;
- tmp[4] = -rs;
- tmp[5] = rc;
- multiply(tmp);
- }
-
- private void zShearMatrix(float dx, float dy)
- {
- ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.mMatrix;
-
- tmp[2] = dx;
- tmp[6] = dy;
- multiply(tmp);
- }
-
- /**
- * sets the transform to a shift in Hue
- *
- * @param rot rotation in degrees
- */
- public void setHue(float rot)
- {
- float mag = (float) Math.sqrt(2.0);
- float xrs = 1 / mag;
- float xrc = 1 / mag;
- xRotateMatrix(xrs, xrc);
- mag = (float) Math.sqrt(3.0);
- float yrs = -1 / mag;
- float yrc = (float) Math.sqrt(2.0) / mag;
- yRotateMatrix(yrs, yrc);
-
- float lx = getRedf(RLUM, GLUM, BLUM);
- float ly = getGreenf(RLUM, GLUM, BLUM);
- float lz = getBluef(RLUM, GLUM, BLUM);
- float zsx = lx / lz;
- float zsy = ly / lz;
- zShearMatrix(zsx, zsy);
-
- float zrs = (float) Math.sin(rot * Math.PI / 180.0);
- float zrc = (float) Math.cos(rot * Math.PI / 180.0);
- zRotateMatrix(zrs, zrc);
- zShearMatrix(-zsx, -zsy);
- yRotateMatrix(-yrs, yrc);
- xRotateMatrix(-xrs, xrc);
- }
-
- /**
- * set it to a saturation matrix
- *
- * @param s
- */
- public void changeSaturation(float s) {
- mMatrix[0] = (1 - s) * RLUM + s;
- mMatrix[1] = (1 - s) * RLUM;
- mMatrix[2] = (1 - s) * RLUM;
- mMatrix[4] = (1 - s) * GLUM;
- mMatrix[5] = (1 - s) * GLUM + s;
- mMatrix[6] = (1 - s) * GLUM;
- mMatrix[8] = (1 - s) * BLUM;
- mMatrix[9] = (1 - s) * BLUM;
- mMatrix[10] = (1 - s) * BLUM + s;
- }
-
- /**
- * Transform RGB value
- *
- * @param r red pixel value
- * @param g green pixel value
- * @param b blue pixel value
- * @return computed red pixel value
- */
- public float getRed(int r, int g, int b) {
- return r * mMatrix[0] + g * mMatrix[4] + b * mMatrix[8] + mMatrix[12];
- }
-
- /**
- * Transform RGB value
- *
- * @param r red pixel value
- * @param g green pixel value
- * @param b blue pixel value
- * @return computed green pixel value
- */
- public float getGreen(int r, int g, int b) {
- return r * mMatrix[1] + g * mMatrix[5] + b * mMatrix[9] + mMatrix[13];
- }
-
- /**
- * Transform RGB value
- *
- * @param r red pixel value
- * @param g green pixel value
- * @param b blue pixel value
- * @return computed blue pixel value
- */
- public float getBlue(int r, int g, int b) {
- return r * mMatrix[2] + g * mMatrix[6] + b * mMatrix[10] + mMatrix[14];
- }
-
- private float getRedf(float r, float g, float b) {
- return r * mMatrix[0] + g * mMatrix[4] + b * mMatrix[8] + mMatrix[12];
- }
-
- private float getGreenf(float r, float g, float b) {
- return r * mMatrix[1] + g * mMatrix[5] + b * mMatrix[9] + mMatrix[13];
- }
-
- private float getBluef(float r, float g, float b) {
- return r * mMatrix[2] + g * mMatrix[6] + b * mMatrix[10] + mMatrix[14];
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
deleted file mode 100644
index 1eebdb571..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-
-import android.util.Log;
-
-import com.android.gallery3d.filtershow.controller.Control;
-import com.android.gallery3d.filtershow.controller.FilterView;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.controller.ParameterInteger;
-
-public class FilterBasicRepresentation extends FilterRepresentation implements ParameterInteger {
- private static final String LOGTAG = "FilterBasicRep";
- private int mMinimum;
- private int mValue;
- private int mMaximum;
- private int mDefaultValue;
- private int mPreviewValue;
- public static final String SERIAL_NAME = "Name";
- public static final String SERIAL_VALUE = "Value";
- private boolean mLogVerbose = Log.isLoggable(LOGTAG, Log.VERBOSE);
-
- public FilterBasicRepresentation(String name, int minimum, int value, int maximum) {
- super(name);
- mMinimum = minimum;
- mMaximum = maximum;
- setValue(value);
- }
-
- @Override
- public String toString() {
- return getName() + " : " + mMinimum + " < " + mValue + " < " + mMaximum;
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterBasicRepresentation representation = new FilterBasicRepresentation(getName(),0,0,0);
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation representation = (FilterBasicRepresentation) a;
- setMinimum(representation.getMinimum());
- setMaximum(representation.getMaximum());
- setValue(representation.getValue());
- setDefaultValue(representation.getDefaultValue());
- setPreviewValue(representation.getPreviewValue());
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation basic = (FilterBasicRepresentation) representation;
- if (basic.mMinimum == mMinimum
- && basic.mMaximum == mMaximum
- && basic.mValue == mValue
- && basic.mDefaultValue == mDefaultValue
- && basic.mPreviewValue == mPreviewValue) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int getMinimum() {
- return mMinimum;
- }
-
- public void setMinimum(int minimum) {
- mMinimum = minimum;
- }
-
- @Override
- public int getValue() {
- return mValue;
- }
-
- @Override
- public void setValue(int value) {
- mValue = value;
- if (mValue < mMinimum) {
- mValue = mMinimum;
- }
- if (mValue > mMaximum) {
- mValue = mMaximum;
- }
- }
-
- @Override
- public int getMaximum() {
- return mMaximum;
- }
-
- public void setMaximum(int maximum) {
- mMaximum = maximum;
- }
-
- public void setDefaultValue(int defaultValue) {
- mDefaultValue = defaultValue;
- }
-
- @Override
- public int getDefaultValue() {
- return mDefaultValue;
- }
-
- public int getPreviewValue() {
- return mPreviewValue;
- }
-
- public void setPreviewValue(int previewValue) {
- mPreviewValue = previewValue;
- }
-
- @Override
- public String getStateRepresentation() {
- int val = getValue();
- return ((val > 0) ? "+" : "") + val;
- }
-
- @Override
- public String getParameterType(){
- return sParameterType;
- }
-
- @Override
- public void setController(Control control) {
- }
-
- @Override
- public String getValueString() {
- return getStateRepresentation();
- }
-
- @Override
- public String getParameterName() {
- return getName();
- }
-
- @Override
- public void setFilterView(FilterView editor) {
- }
-
- @Override
- public void copyFrom(Parameter src) {
- useParametersFrom((FilterBasicRepresentation) src);
- }
-
- @Override
- public String[][] serializeRepresentation() {
- String[][] ret = {
- {SERIAL_NAME , getName() },
- {SERIAL_VALUE , Integer.toString(mValue)}};
- return ret;
- }
-
- @Override
- public void deSerializeRepresentation(String[][] rep) {
- super.deSerializeRepresentation(rep);
- for (int i = 0; i < rep.length; i++) {
- if (SERIAL_VALUE.equals(rep[i][0])) {
- mValue = Integer.parseInt(rep[i][1]);
- break;
- }
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java
deleted file mode 100644
index 7ce67dd96..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterChanSatRepresentation.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.controller.BasicParameterInt;
-import com.android.gallery3d.filtershow.controller.Parameter;
-import com.android.gallery3d.filtershow.controller.ParameterSet;
-import com.android.gallery3d.filtershow.editors.EditorChanSat;
-import com.android.gallery3d.filtershow.imageshow.ControlPoint;
-import com.android.gallery3d.filtershow.imageshow.Spline;
-
-import java.io.IOException;
-import java.util.Vector;
-
-/**
- * Representation for a filter that has per channel & Master saturation
- */
-public class FilterChanSatRepresentation extends FilterRepresentation implements ParameterSet {
- private static final String LOGTAG = "FilterChanSatRepresentation";
- private static final String ARGS = "ARGS";
- private static final String SERIALIZATION_NAME = "channelsaturation";
-
- public static final int MODE_MASTER = 0;
- public static final int MODE_RED = 1;
- public static final int MODE_YELLOW = 2;
- public static final int MODE_GREEN = 3;
- public static final int MODE_CYAN = 4;
- public static final int MODE_BLUE = 5;
- public static final int MODE_MAGENTA = 6;
- private int mParameterMode = MODE_MASTER;
-
- private static int MINSAT = -100;
- private static int MAXSAT = 100;
- private BasicParameterInt mParamMaster = new BasicParameterInt(MODE_MASTER, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamRed = new BasicParameterInt(MODE_RED, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamYellow = new BasicParameterInt(MODE_YELLOW, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamGreen = new BasicParameterInt(MODE_GREEN, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamCyan = new BasicParameterInt(MODE_CYAN, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamBlue = new BasicParameterInt(MODE_BLUE, 0, MINSAT, MAXSAT);
- private BasicParameterInt mParamMagenta = new BasicParameterInt(MODE_MAGENTA, 0, MINSAT, MAXSAT);
-
- private BasicParameterInt[] mAllParam = {
- mParamMaster,
- mParamRed,
- mParamYellow,
- mParamGreen,
- mParamCyan,
- mParamBlue,
- mParamMagenta};
-
- public FilterChanSatRepresentation() {
- super("ChannelSaturation");
- setTextId(R.string.saturation);
- setFilterType(FilterRepresentation.TYPE_NORMAL);
- setSerializationName(SERIALIZATION_NAME);
- setFilterClass(ImageFilterChanSat.class);
- setEditorId(EditorChanSat.ID);
- }
-
- public String toString() {
- return getName() + " : " + mParamRed + ", " + mParamCyan + ", " + mParamRed
- + ", " + mParamGreen + ", " + mParamMaster + ", " + mParamYellow;
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterChanSatRepresentation representation = new FilterChanSatRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterChanSatRepresentation) {
- FilterChanSatRepresentation representation = (FilterChanSatRepresentation) a;
-
- for (int i = 0; i < mAllParam.length; i++) {
- mAllParam[i].copyFrom(representation.mAllParam[i]);
- }
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterChanSatRepresentation) {
- FilterChanSatRepresentation rep = (FilterChanSatRepresentation) representation;
- for (int i = 0; i < mAllParam.length; i++) {
- if (rep.getValue(i) != getValue(i))
- return false;
- }
- return true;
- }
- return false;
- }
-
- public int getValue(int mode) {
- return mAllParam[mode].getValue();
- }
-
- public void setValue(int mode, int value) {
- mAllParam[mode].setValue(value);
- }
-
- public int getMinimum() {
- return mParamMaster.getMinimum();
- }
-
- public int getMaximum() {
- return mParamMaster.getMaximum();
- }
-
- public int getParameterMode() {
- return mParameterMode;
- }
-
- public void setParameterMode(int parameterMode) {
- mParameterMode = parameterMode;
- }
-
- public int getCurrentParameter() {
- return getValue(mParameterMode);
- }
-
- public void setCurrentParameter(int value) {
- setValue(mParameterMode, value);
- }
-
- @Override
- public int getNumberOfParameters() {
- return 6;
- }
-
- @Override
- public Parameter getFilterParameter(int index) {
- return mAllParam[index];
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
-
- writer.name(ARGS);
- writer.beginArray();
- writer.value(getValue(MODE_MASTER));
- writer.value(getValue(MODE_RED));
- writer.value(getValue(MODE_YELLOW));
- writer.value(getValue(MODE_GREEN));
- writer.value(getValue(MODE_CYAN));
- writer.value(getValue(MODE_BLUE));
- writer.value(getValue(MODE_MAGENTA));
- writer.endArray();
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader sreader) throws IOException {
- sreader.beginObject();
-
- while (sreader.hasNext()) {
- String name = sreader.nextName();
- if (name.startsWith(ARGS)) {
- sreader.beginArray();
- sreader.hasNext();
- setValue(MODE_MASTER, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_RED, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_YELLOW, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_GREEN, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_CYAN, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_BLUE, sreader.nextInt());
- sreader.hasNext();
- setValue(MODE_MAGENTA, sreader.nextInt());
- sreader.hasNext();
- sreader.endArray();
- } else {
- sreader.skipValue();
- }
- }
- sreader.endObject();
- }
-} \ No newline at end of file
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
deleted file mode 100644
index 94eb20631..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
-
-public class FilterColorBorderRepresentation extends FilterRepresentation {
- private int mColor;
- private int mBorderSize;
- private int mBorderRadius;
-
- public FilterColorBorderRepresentation(int color, int size, int radius) {
- super("ColorBorder");
- mColor = color;
- mBorderSize = size;
- mBorderRadius = radius;
- setFilterType(FilterRepresentation.TYPE_BORDER);
- setTextId(R.string.borders);
- setEditorId(ImageOnlyEditor.ID);
- setShowParameterValue(false);
- }
-
- public String toString() {
- return "FilterBorder: " + getName();
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterColorBorderRepresentation representation = new FilterColorBorderRepresentation(0,0,0);
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterColorBorderRepresentation) {
- FilterColorBorderRepresentation representation = (FilterColorBorderRepresentation) a;
- setName(representation.getName());
- setColor(representation.getColor());
- setBorderSize(representation.getBorderSize());
- setBorderRadius(representation.getBorderRadius());
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterColorBorderRepresentation) {
- FilterColorBorderRepresentation border = (FilterColorBorderRepresentation) representation;
- if (border.mColor == mColor
- && border.mBorderSize == mBorderSize
- && border.mBorderRadius == mBorderRadius) {
- return true;
- }
- }
- return false;
- }
-
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- @Override
- public int getTextId() {
- return R.string.borders;
- }
-
- public int getColor() {
- return mColor;
- }
-
- public void setColor(int color) {
- mColor = color;
- }
-
- public int getBorderSize() {
- return mBorderSize;
- }
-
- public void setBorderSize(int borderSize) {
- mBorderSize = borderSize;
- }
-
- public int getBorderRadius() {
- return mBorderRadius;
- }
-
- public void setBorderRadius(int borderRadius) {
- mBorderRadius = borderRadius;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
deleted file mode 100644
index c1bd7b3bb..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.RectF;
-import android.util.JsonReader;
-import android.util.JsonWriter;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorCrop;
-
-import java.io.IOException;
-
-public class FilterCropRepresentation extends FilterRepresentation {
- public static final String SERIALIZATION_NAME = "CROP";
- public static final String[] BOUNDS = {
- "C0", "C1", "C2", "C3"
- };
- private static final String TAG = FilterCropRepresentation.class.getSimpleName();
-
- RectF mCrop = getNil();
-
- public FilterCropRepresentation(RectF crop) {
- super(FilterCropRepresentation.class.getSimpleName());
- setSerializationName(SERIALIZATION_NAME);
- setShowParameterValue(true);
- setFilterClass(FilterCropRepresentation.class);
- setFilterType(FilterRepresentation.TYPE_GEOMETRY);
- setTextId(R.string.crop);
- setEditorId(EditorCrop.ID);
- setCrop(crop);
- }
-
- public FilterCropRepresentation(FilterCropRepresentation m) {
- this(m.mCrop);
- }
-
- public FilterCropRepresentation() {
- this(sNilRect);
- }
-
- public void set(FilterCropRepresentation r) {
- mCrop.set(r.mCrop);
- }
-
- @Override
- public boolean equals(FilterRepresentation rep) {
- if (!(rep instanceof FilterCropRepresentation)) {
- return false;
- }
- FilterCropRepresentation crop = (FilterCropRepresentation) rep;
- if (mCrop.bottom != crop.mCrop.bottom
- || mCrop.left != crop.mCrop.left
- || mCrop.right != crop.mCrop.right
- || mCrop.top != crop.mCrop.top) {
- return false;
- }
- return true;
- }
-
- public RectF getCrop() {
- return new RectF(mCrop);
- }
-
- public void getCrop(RectF r) {
- r.set(mCrop);
- }
-
- public void setCrop(RectF crop) {
- if (crop == null) {
- throw new IllegalArgumentException("Argument to setCrop is null");
- }
- mCrop.set(crop);
- }
-
- /**
- * Takes a crop rect contained by [0, 0, 1, 1] and scales it by the height
- * and width of the image rect.
- */
- public static void findScaledCrop(RectF crop, int bitmapWidth, int bitmapHeight) {
- crop.left *= bitmapWidth;
- crop.top *= bitmapHeight;
- crop.right *= bitmapWidth;
- crop.bottom *= bitmapHeight;
- }
-
- /**
- * Takes crop rect and normalizes it by scaling down by the height and width
- * of the image rect.
- */
- public static void findNormalizedCrop(RectF crop, int bitmapWidth, int bitmapHeight) {
- crop.left /= bitmapWidth;
- crop.top /= bitmapHeight;
- crop.right /= bitmapWidth;
- crop.bottom /= bitmapHeight;
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- @Override
- public FilterRepresentation copy() {
- return new FilterCropRepresentation(this);
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- if (!(representation instanceof FilterCropRepresentation)) {
- throw new IllegalArgumentException("calling copyAllParameters with incompatible types!");
- }
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (!(a instanceof FilterCropRepresentation)) {
- throw new IllegalArgumentException("calling useParametersFrom with incompatible types!");
- }
- setCrop(((FilterCropRepresentation) a).mCrop);
- }
-
- private static final RectF sNilRect = new RectF(0, 0, 1, 1);
-
- @Override
- public boolean isNil() {
- return mCrop.equals(sNilRect);
- }
-
- public static RectF getNil() {
- return new RectF(sNilRect);
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- writer.name(BOUNDS[0]).value(mCrop.left);
- writer.name(BOUNDS[1]).value(mCrop.top);
- writer.name(BOUNDS[2]).value(mCrop.right);
- writer.name(BOUNDS[3]).value(mCrop.bottom);
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader reader) throws IOException {
- reader.beginObject();
- while (reader.hasNext()) {
- String name = reader.nextName();
- if (BOUNDS[0].equals(name)) {
- mCrop.left = (float) reader.nextDouble();
- } else if (BOUNDS[1].equals(name)) {
- mCrop.top = (float) reader.nextDouble();
- } else if (BOUNDS[2].equals(name)) {
- mCrop.right = (float) reader.nextDouble();
- } else if (BOUNDS[3].equals(name)) {
- mCrop.bottom = (float) reader.nextDouble();
- } else {
- reader.skipValue();
- }
- }
- reader.endObject();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java
deleted file mode 100644
index edab2a08d..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.imageshow.ControlPoint;
-import com.android.gallery3d.filtershow.imageshow.Spline;
-
-import java.io.IOException;
-
-/**
- * TODO: Insert description here. (generated by hoford)
- */
-public class FilterCurvesRepresentation extends FilterRepresentation {
- private static final String LOGTAG = "FilterCurvesRepresentation";
- public static final String SERIALIZATION_NAME = "Curve";
- private static final int MAX_SPLINE_NUMBER = 4;
-
- private Spline[] mSplines = new Spline[MAX_SPLINE_NUMBER];
-
- public FilterCurvesRepresentation() {
- super("Curves");
- setSerializationName("CURVES");
- setFilterClass(ImageFilterCurves.class);
- setTextId(R.string.curvesRGB);
- setOverlayId(R.drawable.filtershow_button_colors_curve);
- setEditorId(R.id.imageCurves);
- setShowParameterValue(false);
- setSupportsPartialRendering(true);
- reset();
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterCurvesRepresentation representation = new FilterCurvesRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (!(a instanceof FilterCurvesRepresentation)) {
- Log.v(LOGTAG, "cannot use parameters from " + a);
- return;
- }
- FilterCurvesRepresentation representation = (FilterCurvesRepresentation) a;
- Spline[] spline = new Spline[MAX_SPLINE_NUMBER];
- for (int i = 0; i < spline.length; i++) {
- Spline sp = representation.mSplines[i];
- if (sp != null) {
- spline[i] = new Spline(sp);
- } else {
- spline[i] = new Spline();
- }
- }
- mSplines = spline;
- }
-
- @Override
- public boolean isNil() {
- for (int i = 0; i < MAX_SPLINE_NUMBER; i++) {
- if (getSpline(i) != null && !getSpline(i).isOriginal()) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
-
- if (!(representation instanceof FilterCurvesRepresentation)) {
- return false;
- } else {
- FilterCurvesRepresentation curve =
- (FilterCurvesRepresentation) representation;
- for (int i = 0; i < MAX_SPLINE_NUMBER; i++) {
- if (!getSpline(i).sameValues(curve.getSpline(i))) {
- return false;
- }
- }
- }
- // Every spline matches, therefore they are the same.
- return true;
- }
-
- public void reset() {
- Spline spline = new Spline();
-
- spline.addPoint(0.0f, 1.0f);
- spline.addPoint(1.0f, 0.0f);
-
- for (int i = 0; i < MAX_SPLINE_NUMBER; i++) {
- mSplines[i] = new Spline(spline);
- }
- }
-
- public void setSpline(int splineIndex, Spline s) {
- mSplines[splineIndex] = s;
- }
-
- public Spline getSpline(int splineIndex) {
- return mSplines[splineIndex];
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- {
- writer.name(NAME_TAG);
- writer.value(getName());
- for (int i = 0; i < mSplines.length; i++) {
- writer.name(SERIALIZATION_NAME + i);
- writer.beginArray();
- int nop = mSplines[i].getNbPoints();
- for (int j = 0; j < nop; j++) {
- ControlPoint p = mSplines[i].getPoint(j);
- writer.beginArray();
- writer.value(p.x);
- writer.value(p.y);
- writer.endArray();
- }
- writer.endArray();
- }
-
- }
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader sreader) throws IOException {
- sreader.beginObject();
- Spline[] spline = new Spline[MAX_SPLINE_NUMBER];
- while (sreader.hasNext()) {
- String name = sreader.nextName();
- if (NAME_TAG.equals(name)) {
- setName(sreader.nextString());
- } else if (name.startsWith(SERIALIZATION_NAME)) {
- int curveNo = Integer.parseInt(name.substring(SERIALIZATION_NAME.length()));
- spline[curveNo] = new Spline();
- sreader.beginArray();
- while (sreader.hasNext()) {
- sreader.beginArray();
- sreader.hasNext();
- float x = (float) sreader.nextDouble();
- sreader.hasNext();
- float y = (float) sreader.nextDouble();
- sreader.endArray();
- spline[curveNo].addPoint(x, y);
- }
- sreader.endArray();
-
- }
- }
- mSplines = spline;
- sreader.endObject();
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
deleted file mode 100644
index ac0cb7492..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-public class FilterDirectRepresentation extends FilterRepresentation {
-
- @Override
- public FilterRepresentation copy() {
- FilterDirectRepresentation representation = new FilterDirectRepresentation(getName());
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public FilterDirectRepresentation(String name) {
- super(name);
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
deleted file mode 100644
index 977dbeac5..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Path;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorDraw;
-
-import java.util.Vector;
-
-public class FilterDrawRepresentation extends FilterRepresentation {
- private static final String LOGTAG = "FilterDrawRepresentation";
-
- public static class StrokeData implements Cloneable {
- public byte mType;
- public Path mPath;
- public float mRadius;
- public int mColor;
- public int noPoints = 0;
- @Override
- public String toString() {
- return "stroke(" + mType + ", path(" + (mPath) + "), " + mRadius + " , "
- + Integer.toHexString(mColor) + ")";
- }
- @Override
- public StrokeData clone() throws CloneNotSupportedException {
- return (StrokeData) super.clone();
- }
- }
-
- private Vector<StrokeData> mDrawing = new Vector<StrokeData>();
- private StrokeData mCurrent; // used in the currently drawing style
-
- public FilterDrawRepresentation() {
- super("Draw");
- setFilterClass(ImageFilterDraw.class);
- setSerializationName("DRAW");
- setFilterType(FilterRepresentation.TYPE_VIGNETTE);
- setTextId(R.string.imageDraw);
- setEditorId(EditorDraw.ID);
- setOverlayId(R.drawable.filtershow_drawing);
- setOverlayOnly(true);
- }
-
- @Override
- public String toString() {
- return getName() + " : strokes=" + mDrawing.size()
- + ((mCurrent == null) ? " no current "
- : ("draw=" + mCurrent.mType + " " + mCurrent.noPoints));
- }
-
- public Vector<StrokeData> getDrawing() {
- return mDrawing;
- }
-
- public StrokeData getCurrentDrawing() {
- return mCurrent;
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterDrawRepresentation representation = new FilterDrawRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public boolean isNil() {
- return getDrawing().isEmpty();
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterDrawRepresentation) {
- FilterDrawRepresentation representation = (FilterDrawRepresentation) a;
- try {
- if (representation.mCurrent != null) {
- mCurrent = (StrokeData) representation.mCurrent.clone();
- } else {
- mCurrent = null;
- }
- if (representation.mDrawing != null) {
- mDrawing = (Vector<StrokeData>) representation.mDrawing.clone();
- } else {
- mDrawing = null;
- }
-
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- } else {
- Log.v(LOGTAG, "cannot use parameters from " + a);
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterDrawRepresentation) {
- FilterDrawRepresentation fdRep = (FilterDrawRepresentation) representation;
- if (fdRep.mDrawing.size() != mDrawing.size())
- return false;
- if (fdRep.mCurrent == null && mCurrent.mPath == null) {
- return true;
- }
- if (fdRep.mCurrent != null && mCurrent.mPath != null) {
- if (fdRep.mCurrent.noPoints == mCurrent.noPoints) {
- return true;
- }
- return false;
- }
- }
- return false;
- }
-
- public void startNewSection(byte type, int color, float size, float x, float y) {
- mCurrent = new StrokeData();
- mCurrent.mColor = color;
- mCurrent.mRadius = size;
- mCurrent.mType = type;
- mCurrent.mPath = new Path();
- mCurrent.mPath.moveTo(x, y);
- mCurrent.noPoints = 0;
- }
-
- public void addPoint(float x, float y) {
- mCurrent.noPoints++;
- mCurrent.mPath.lineTo(x, y);
- }
-
- public void endSection(float x, float y) {
- mCurrent.mPath.lineTo(x, y);
- mCurrent.noPoints++;
- mDrawing.add(mCurrent);
- mCurrent = null;
- }
-
- public void clearCurrentSection() {
- mCurrent = null;
- }
-
- public void clear() {
- mCurrent = null;
- mDrawing.clear();
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java
deleted file mode 100644
index e5a6fdd23..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
-
-public class FilterFxRepresentation extends FilterRepresentation {
- private static final String LOGTAG = "FilterFxRepresentation";
- // TODO: When implementing serialization, we should find a unique way of
- // specifying bitmaps / names (the resource IDs being random)
- private int mBitmapResource = 0;
- private int mNameResource = 0;
-
- public FilterFxRepresentation(String name, int bitmapResource, int nameResource) {
- super(name);
- setFilterClass(ImageFilterFx.class);
- mBitmapResource = bitmapResource;
- mNameResource = nameResource;
- setFilterType(FilterRepresentation.TYPE_FX);
- setTextId(nameResource);
- setEditorId(ImageOnlyEditor.ID);
- setShowParameterValue(false);
- setSupportsPartialRendering(true);
- }
-
- @Override
- public String toString() {
- return "FilterFx: " + hashCode() + " : " + getName() + " bitmap rsc: " + mBitmapResource;
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterFxRepresentation representation = new FilterFxRepresentation(getName(),0,0);
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public synchronized void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterFxRepresentation) {
- FilterFxRepresentation representation = (FilterFxRepresentation) a;
- setName(representation.getName());
- setSerializationName(representation.getSerializationName());
- setBitmapResource(representation.getBitmapResource());
- setNameResource(representation.getNameResource());
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterFxRepresentation) {
- FilterFxRepresentation fx = (FilterFxRepresentation) representation;
- if (fx.mNameResource == mNameResource
- && fx.mBitmapResource == mBitmapResource) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean same(FilterRepresentation representation) {
- if (!super.same(representation)) {
- return false;
- }
- return equals(representation);
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- public int getNameResource() {
- return mNameResource;
- }
-
- public void setNameResource(int nameResource) {
- mNameResource = nameResource;
- }
-
- public int getBitmapResource() {
- return mBitmapResource;
- }
-
- public void setBitmapResource(int bitmapResource) {
- mBitmapResource = bitmapResource;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java
deleted file mode 100644
index 0c272d48a..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Rect;
-import android.util.JsonReader;
-import android.util.JsonWriter;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorGrad;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.imageshow.Line;
-
-import java.io.IOException;
-import java.util.Vector;
-
-public class FilterGradRepresentation extends FilterRepresentation
- implements Line {
- private static final String LOGTAG = "FilterGradRepresentation";
- public static final int MAX_POINTS = 16;
- public static final int PARAM_BRIGHTNESS = 0;
- public static final int PARAM_SATURATION = 1;
- public static final int PARAM_CONTRAST = 2;
- private static final double ADD_MIN_DIST = .05;
- private static String LINE_NAME = "Point";
- private static final String SERIALIZATION_NAME = "grad";
-
- public FilterGradRepresentation() {
- super("Grad");
- setSerializationName(SERIALIZATION_NAME);
- creatExample();
- setOverlayId(R.drawable.filtershow_button_grad);
- setFilterClass(ImageFilterGrad.class);
- setTextId(R.string.grad);
- setEditorId(EditorGrad.ID);
- }
-
- public void trimVector(){
- int n = mBands.size();
- for (int i = n; i < MAX_POINTS; i++) {
- mBands.add(new Band());
- }
- for (int i = MAX_POINTS; i < n; i++) {
- mBands.remove(i);
- }
- }
-
- Vector<Band> mBands = new Vector<Band>();
- Band mCurrentBand;
-
- static class Band {
- private boolean mask = true;
-
- private int xPos1 = -1;
- private int yPos1 = 100;
- private int xPos2 = -1;
- private int yPos2 = 100;
- private int brightness = 40;
- private int contrast = 0;
- private int saturation = 0;
-
-
- public Band() {
- }
-
- public Band(int x, int y) {
- xPos1 = x;
- yPos1 = y+30;
- xPos2 = x;
- yPos2 = y-30;
- }
-
- public Band(Band copy) {
- mask = copy.mask;
- xPos1 = copy.xPos1;
- yPos1 = copy.yPos1;
- xPos2 = copy.xPos2;
- yPos2 = copy.yPos2;
- brightness = copy.brightness;
- contrast = copy.contrast;
- saturation = copy.saturation;
- }
-
- }
-
- @Override
- public String toString() {
- int count = 0;
- for (Band point : mBands) {
- if (!point.mask) {
- count++;
- }
- }
- return "c=" + mBands.indexOf(mBands) + "[" + mBands.size() + "]" + count;
- }
-
- private void creatExample() {
- Band p = new Band();
- p.mask = false;
- p.xPos1 = -1;
- p.yPos1 = 100;
- p.xPos2 = -1;
- p.yPos2 = 100;
- p.brightness = 40;
- p.contrast = 0;
- p.saturation = 0;
- mBands.add(0, p);
- mCurrentBand = p;
- trimVector();
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- FilterGradRepresentation rep = (FilterGradRepresentation) a;
- Vector<Band> tmpBands = new Vector<Band>();
- int n = (rep.mCurrentBand == null) ? 0 : rep.mBands.indexOf(rep.mCurrentBand);
- for (Band band : rep.mBands) {
- tmpBands.add(new Band(band));
- }
- mCurrentBand = null;
- mBands = tmpBands;
- mCurrentBand = mBands.elementAt(n);
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterGradRepresentation representation = new FilterGradRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (representation instanceof FilterGradRepresentation) {
- FilterGradRepresentation rep = (FilterGradRepresentation) representation;
- int n = getNumberOfBands();
- if (rep.getNumberOfBands() != n) {
- return false;
- }
- for (int i = 0; i < mBands.size(); i++) {
- Band b1 = mBands.get(i);
- Band b2 = rep.mBands.get(i);
- if (b1.mask != b2.mask
- || b1.brightness != b2.brightness
- || b1.contrast != b2.contrast
- || b1.saturation != b2.saturation
- || b1.xPos1 != b2.xPos1
- || b1.xPos2 != b2.xPos2
- || b1.yPos1 != b2.yPos1
- || b1.yPos2 != b2.yPos2) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- public int getNumberOfBands() {
- int count = 0;
- for (Band point : mBands) {
- if (!point.mask) {
- count++;
- }
- }
- return count;
- }
-
- public int addBand(Rect rect) {
- mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY()));
- mCurrentBand.mask = false;
- int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2)/2;
- int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2)/2;
- double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height());
- boolean moved = true;
- int count = 0;
- int toMove = mBands.indexOf(mCurrentBand);
-
- while (moved) {
- moved = false;
- count++;
- if (count > 14) {
- break;
- }
-
- for (Band point : mBands) {
- if (point.mask) {
- break;
- }
- }
-
- for (Band point : mBands) {
- if (point.mask) {
- break;
- }
- int index = mBands.indexOf(point);
-
- if (toMove != index) {
- double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y);
- if (dist < addDelta) {
- moved = true;
- mCurrentBand.xPos1 += addDelta;
- mCurrentBand.yPos1 += addDelta;
- mCurrentBand.xPos2 += addDelta;
- mCurrentBand.yPos2 += addDelta;
- x = (mCurrentBand.xPos1 + mCurrentBand.xPos2)/2;
- y = (mCurrentBand.yPos1 + mCurrentBand.yPos2)/2;
-
- if (mCurrentBand.yPos1 > rect.bottom) {
- mCurrentBand.yPos1 = (int) (rect.top + addDelta);
- }
- if (mCurrentBand.xPos1 > rect.right) {
- mCurrentBand.xPos1 = (int) (rect.left + addDelta);
- }
- }
- }
- }
- }
- trimVector();
- return 0;
- }
-
- public void deleteCurrentBand() {
- int index = mBands.indexOf(mCurrentBand);
- mBands.remove(mCurrentBand);
- trimVector();
- if (getNumberOfBands() == 0) {
- addBand(MasterImage.getImage().getOriginalBounds());
- }
- mCurrentBand = mBands.get(0);
- }
-
- public void nextPoint(){
- int index = mBands.indexOf(mCurrentBand);
- int tmp = index;
- Band point;
- int k = 0;
- do {
- index = (index+1)% mBands.size();
- point = mBands.get(index);
- if (k++ >= mBands.size()) {
- break;
- }
- }
- while (point.mask == true);
- mCurrentBand = mBands.get(index);
- }
-
- public void setSelectedPoint(int pos) {
- mCurrentBand = mBands.get(pos);
- }
-
- public int getSelectedPoint() {
- return mBands.indexOf(mCurrentBand);
- }
-
- public boolean[] getMask() {
- boolean[] ret = new boolean[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = !point.mask;
- }
- return ret;
- }
-
- public int[] getXPos1() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.xPos1;
- }
- return ret;
- }
-
- public int[] getYPos1() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.yPos1;
- }
- return ret;
- }
-
- public int[] getXPos2() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.xPos2;
- }
- return ret;
- }
-
- public int[] getYPos2() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.yPos2;
- }
- return ret;
- }
-
- public int[] getBrightness() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.brightness;
- }
- return ret;
- }
-
- public int[] getContrast() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.contrast;
- }
- return ret;
- }
-
- public int[] getSaturation() {
- int[] ret = new int[mBands.size()];
- int i = 0;
- for (Band point : mBands) {
- ret[i++] = point.saturation;
- }
- return ret;
- }
-
- public int getParameter(int type) {
- switch (type){
- case PARAM_BRIGHTNESS:
- return mCurrentBand.brightness;
- case PARAM_SATURATION:
- return mCurrentBand.saturation;
- case PARAM_CONTRAST:
- return mCurrentBand.contrast;
- }
- throw new IllegalArgumentException("no such type " + type);
- }
-
- public int getParameterMax(int type) {
- switch (type) {
- case PARAM_BRIGHTNESS:
- return 100;
- case PARAM_SATURATION:
- return 100;
- case PARAM_CONTRAST:
- return 100;
- }
- throw new IllegalArgumentException("no such type " + type);
- }
-
- public int getParameterMin(int type) {
- switch (type) {
- case PARAM_BRIGHTNESS:
- return -100;
- case PARAM_SATURATION:
- return -100;
- case PARAM_CONTRAST:
- return -100;
- }
- throw new IllegalArgumentException("no such type " + type);
- }
-
- public void setParameter(int type, int value) {
- mCurrentBand.mask = false;
- switch (type) {
- case PARAM_BRIGHTNESS:
- mCurrentBand.brightness = value;
- break;
- case PARAM_SATURATION:
- mCurrentBand.saturation = value;
- break;
- case PARAM_CONTRAST:
- mCurrentBand.contrast = value;
- break;
- default:
- throw new IllegalArgumentException("no such type " + type);
- }
- }
-
- @Override
- public void setPoint1(float x, float y) {
- mCurrentBand.xPos1 = (int)x;
- mCurrentBand.yPos1 = (int)y;
- }
-
- @Override
- public void setPoint2(float x, float y) {
- mCurrentBand.xPos2 = (int)x;
- mCurrentBand.yPos2 = (int)y;
- }
-
- @Override
- public float getPoint1X() {
- return mCurrentBand.xPos1;
- }
-
- @Override
- public float getPoint1Y() {
- return mCurrentBand.yPos1;
- }
- @Override
- public float getPoint2X() {
- return mCurrentBand.xPos2;
- }
-
- @Override
- public float getPoint2Y() {
- return mCurrentBand.yPos2;
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- int len = mBands.size();
- int count = 0;
-
- for (int i = 0; i < len; i++) {
- Band point = mBands.get(i);
- if (point.mask) {
- continue;
- }
- writer.name(LINE_NAME + count);
- count++;
- writer.beginArray();
- writer.value(point.xPos1);
- writer.value(point.yPos1);
- writer.value(point.xPos2);
- writer.value(point.yPos2);
- writer.value(point.brightness);
- writer.value(point.contrast);
- writer.value(point.saturation);
- writer.endArray();
- }
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader sreader) throws IOException {
- sreader.beginObject();
- Vector<Band> points = new Vector<Band>();
-
- while (sreader.hasNext()) {
- String name = sreader.nextName();
- if (name.startsWith(LINE_NAME)) {
- int pointNo = Integer.parseInt(name.substring(LINE_NAME.length()));
- sreader.beginArray();
- Band p = new Band();
- p.mask = false;
- sreader.hasNext();
- p.xPos1 = sreader.nextInt();
- sreader.hasNext();
- p.yPos1 = sreader.nextInt();
- sreader.hasNext();
- p.xPos2 = sreader.nextInt();
- sreader.hasNext();
- p.yPos2 = sreader.nextInt();
- sreader.hasNext();
- p.brightness = sreader.nextInt();
- sreader.hasNext();
- p.contrast = sreader.nextInt();
- sreader.hasNext();
- p.saturation = sreader.nextInt();
- sreader.hasNext();
- sreader.endArray();
- points.add(p);
-
- } else {
- sreader.skipValue();
- }
- }
- mBands = points;
- trimVector();
- mCurrentBand = mBands.get(0);
- sreader.endObject();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
deleted file mode 100644
index f310a2be1..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
-
-public class FilterImageBorderRepresentation extends FilterRepresentation {
- private int mDrawableResource = 0;
-
- public FilterImageBorderRepresentation(int drawableResource) {
- super("ImageBorder");
- setFilterClass(ImageFilterBorder.class);
- mDrawableResource = drawableResource;
- setFilterType(FilterRepresentation.TYPE_BORDER);
- setTextId(R.string.borders);
- setEditorId(ImageOnlyEditor.ID);
- setShowParameterValue(false);
- }
-
- public String toString() {
- return "FilterBorder: " + getName();
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterImageBorderRepresentation representation =
- new FilterImageBorderRepresentation(mDrawableResource);
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterImageBorderRepresentation) {
- FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) a;
- setName(representation.getName());
- setDrawableResource(representation.getDrawableResource());
- }
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterImageBorderRepresentation) {
- FilterImageBorderRepresentation border = (FilterImageBorderRepresentation) representation;
- if (border.mDrawableResource == mDrawableResource) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int getTextId() {
- return R.string.none;
- }
-
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- public int getDrawableResource() {
- return mDrawableResource;
- }
-
- public void setDrawableResource(int drawableResource) {
- mDrawableResource = drawableResource;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
deleted file mode 100644
index 8dcff0d16..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorMirror;
-
-import java.io.IOException;
-
-public class FilterMirrorRepresentation extends FilterRepresentation {
- public static final String SERIALIZATION_NAME = "MIRROR";
- private static final String SERIALIZATION_MIRROR_VALUE = "value";
- private static final String TAG = FilterMirrorRepresentation.class.getSimpleName();
-
- Mirror mMirror;
-
- public enum Mirror {
- NONE('N'), VERTICAL('V'), HORIZONTAL('H'), BOTH('B');
- char mValue;
-
- private Mirror(char value) {
- mValue = value;
- }
-
- public char value() {
- return mValue;
- }
-
- public static Mirror fromValue(char value) {
- switch (value) {
- case 'N':
- return NONE;
- case 'V':
- return VERTICAL;
- case 'H':
- return HORIZONTAL;
- case 'B':
- return BOTH;
- default:
- return null;
- }
- }
- }
-
- public FilterMirrorRepresentation(Mirror mirror) {
- super(FilterMirrorRepresentation.class.getSimpleName());
- setSerializationName(SERIALIZATION_NAME);
- setShowParameterValue(true);
- setFilterClass(FilterMirrorRepresentation.class);
- setFilterType(FilterRepresentation.TYPE_GEOMETRY);
- setTextId(R.string.mirror);
- setEditorId(EditorMirror.ID);
- setMirror(mirror);
- }
-
- public FilterMirrorRepresentation(FilterMirrorRepresentation m) {
- this(m.getMirror());
- }
-
- public FilterMirrorRepresentation() {
- this(getNil());
- }
-
- @Override
- public boolean equals(FilterRepresentation rep) {
- if (!(rep instanceof FilterMirrorRepresentation)) {
- return false;
- }
- FilterMirrorRepresentation mirror = (FilterMirrorRepresentation) rep;
- if (mMirror != mirror.mMirror) {
- return false;
- }
- return true;
- }
-
- public Mirror getMirror() {
- return mMirror;
- }
-
- public void set(FilterMirrorRepresentation r) {
- mMirror = r.mMirror;
- }
-
- public void setMirror(Mirror mirror) {
- if (mirror == null) {
- throw new IllegalArgumentException("Argument to setMirror is null");
- }
- mMirror = mirror;
- }
-
- public void cycle() {
- switch (mMirror) {
- case NONE:
- mMirror = Mirror.HORIZONTAL;
- break;
- case HORIZONTAL:
- mMirror = Mirror.VERTICAL;
- break;
- case VERTICAL:
- mMirror = Mirror.BOTH;
- break;
- case BOTH:
- mMirror = Mirror.NONE;
- break;
- }
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- @Override
- public FilterRepresentation copy() {
- return new FilterMirrorRepresentation(this);
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- if (!(representation instanceof FilterMirrorRepresentation)) {
- throw new IllegalArgumentException("calling copyAllParameters with incompatible types!");
- }
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (!(a instanceof FilterMirrorRepresentation)) {
- throw new IllegalArgumentException("calling useParametersFrom with incompatible types!");
- }
- setMirror(((FilterMirrorRepresentation) a).getMirror());
- }
-
- @Override
- public boolean isNil() {
- return mMirror == getNil();
- }
-
- public static Mirror getNil() {
- return Mirror.NONE;
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- writer.name(SERIALIZATION_MIRROR_VALUE).value(mMirror.value());
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader reader) throws IOException {
- boolean unset = true;
- reader.beginObject();
- while (reader.hasNext()) {
- String name = reader.nextName();
- if (SERIALIZATION_MIRROR_VALUE.equals(name)) {
- Mirror r = Mirror.fromValue((char) reader.nextInt());
- if (r != null) {
- setMirror(r);
- unset = false;
- }
- } else {
- reader.skipValue();
- }
- }
- if (unset) {
- Log.w(TAG, "WARNING: bad value when deserializing " + SERIALIZATION_NAME);
- }
- reader.endObject();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterPoint.java b/src/com/android/gallery3d/filtershow/filters/FilterPoint.java
deleted file mode 100644
index 4520717a1..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterPoint.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-public interface FilterPoint {
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java
deleted file mode 100644
index 9bd1699d9..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import java.util.Vector;
-
-public abstract class FilterPointRepresentation extends FilterRepresentation {
- private static final String LOGTAG = "FilterPointRepresentation";
- private Vector<FilterPoint> mCandidates = new Vector<FilterPoint>();
-
- public FilterPointRepresentation(String type, int textid, int editorID) {
- super(type);
- setFilterClass(ImageFilterRedEye.class);
- setFilterType(FilterRepresentation.TYPE_NORMAL);
- setTextId(textid);
- setEditorId(editorID);
- }
-
- @Override
- public abstract FilterRepresentation copy();
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public boolean hasCandidates() {
- return mCandidates != null;
- }
-
- public Vector<FilterPoint> getCandidates() {
- return mCandidates;
- }
-
- @Override
- public boolean isNil() {
- if (getCandidates() != null && getCandidates().size() > 0) {
- return false;
- }
- return true;
- }
-
- public Object getCandidate(int index) {
- return this.mCandidates.get(index);
- }
-
- public void addCandidate(FilterPoint c) {
- this.mCandidates.add(c);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (a instanceof FilterPointRepresentation) {
- FilterPointRepresentation representation = (FilterPointRepresentation) a;
- mCandidates.clear();
- for (FilterPoint redEyeCandidate : representation.mCandidates) {
- mCandidates.add(redEyeCandidate);
- }
- }
- }
-
- public void removeCandidate(RedEyeCandidate c) {
- this.mCandidates.remove(c);
- }
-
- public void clearCandidates() {
- this.mCandidates.clear();
- }
-
- public int getNumberOfCandidates() {
- return mCandidates.size();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java
deleted file mode 100644
index dd06a9760..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.RectF;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorRedEye;
-
-import java.util.Vector;
-
-public class FilterRedEyeRepresentation extends FilterPointRepresentation {
- private static final String LOGTAG = "FilterRedEyeRepresentation";
-
- public FilterRedEyeRepresentation() {
- super("RedEye",R.string.redeye,EditorRedEye.ID);
- setSerializationName("REDEYE");
- setFilterClass(ImageFilterRedEye.class);
- setOverlayId(R.drawable.photoeditor_effect_redeye);
- setOverlayOnly(true);
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterRedEyeRepresentation representation = new FilterRedEyeRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- public void addRect(RectF rect, RectF bounds) {
- Vector<RedEyeCandidate> intersects = new Vector<RedEyeCandidate>();
- for (int i = 0; i < getCandidates().size(); i++) {
- RedEyeCandidate r = (RedEyeCandidate) getCandidate(i);
- if (r.intersect(rect)) {
- intersects.add(r);
- }
- }
- for (int i = 0; i < intersects.size(); i++) {
- RedEyeCandidate r = intersects.elementAt(i);
- rect.union(r.mRect);
- bounds.union(r.mBounds);
- removeCandidate(r);
- }
- addCandidate(new RedEyeCandidate(rect, bounds));
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
deleted file mode 100644
index 5b33ffba5..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-import android.util.Log;
-
-import com.android.gallery3d.filtershow.editors.BasicEditor;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-public class FilterRepresentation {
- private static final String LOGTAG = "FilterRepresentation";
- private static final boolean DEBUG = false;
- private String mName;
- private int mPriority = TYPE_NORMAL;
- private Class<?> mFilterClass;
- private boolean mSupportsPartialRendering = false;
- private int mTextId = 0;
- private int mEditorId = BasicEditor.ID;
- private int mButtonId = 0;
- private int mOverlayId = 0;
- private boolean mOverlayOnly = false;
- private boolean mShowParameterValue = true;
- private String mSerializationName;
- public static final byte TYPE_BORDER = 1;
- public static final byte TYPE_FX = 2;
- public static final byte TYPE_WBALANCE = 3;
- public static final byte TYPE_VIGNETTE = 4;
- public static final byte TYPE_NORMAL = 5;
- public static final byte TYPE_TINYPLANET = 6;
- public static final byte TYPE_GEOMETRY = 7;
- protected static final String NAME_TAG = "Name";
-
- public FilterRepresentation(String name) {
- mName = name;
- }
-
- public FilterRepresentation copy(){
- FilterRepresentation representation = new FilterRepresentation(mName);
- representation.useParametersFrom(this);
- return representation;
- }
-
- protected void copyAllParameters(FilterRepresentation representation) {
- representation.setName(getName());
- representation.setFilterClass(getFilterClass());
- representation.setFilterType(getFilterType());
- representation.setSupportsPartialRendering(supportsPartialRendering());
- representation.setTextId(getTextId());
- representation.setEditorId(getEditorId());
- representation.setOverlayId(getOverlayId());
- representation.setOverlayOnly(getOverlayOnly());
- representation.setShowParameterValue(showParameterValue());
- representation.mSerializationName = mSerializationName;
-
- }
-
- public boolean equals(FilterRepresentation representation) {
- if (representation == null) {
- return false;
- }
- if (representation.mFilterClass == mFilterClass
- && representation.mName.equalsIgnoreCase(mName)
- && representation.mPriority == mPriority
- // TODO: After we enable partial rendering, we can switch back
- // to use member variable here.
- && representation.supportsPartialRendering() == supportsPartialRendering()
- && representation.mTextId == mTextId
- && representation.mEditorId == mEditorId
- && representation.mButtonId == mButtonId
- && representation.mOverlayId == mOverlayId
- && representation.mOverlayOnly == mOverlayOnly
- && representation.mShowParameterValue == mShowParameterValue) {
- return true;
- }
- return false;
- }
-
- @Override
- public String toString() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
- public String getName() {
- return mName;
- }
-
- public void setSerializationName(String sname) {
- mSerializationName = sname;
- }
-
- public String getSerializationName() {
- return mSerializationName;
- }
-
- public void setFilterType(int priority) {
- mPriority = priority;
- }
-
- public int getFilterType() {
- return mPriority;
- }
-
- public boolean isNil() {
- return false;
- }
-
- public boolean supportsPartialRendering() {
- return false && mSupportsPartialRendering; // disable for now
- }
-
- public void setSupportsPartialRendering(boolean value) {
- mSupportsPartialRendering = value;
- }
-
- public void useParametersFrom(FilterRepresentation a) {
- }
-
- public boolean allowsSingleInstanceOnly() {
- return false;
- }
-
- public Class<?> getFilterClass() {
- return mFilterClass;
- }
-
- public void setFilterClass(Class<?> filterClass) {
- mFilterClass = filterClass;
- }
-
- // This same() function is different from equals(), basically it checks
- // whether 2 FilterRepresentations are the same type. It doesn't care about
- // the values.
- public boolean same(FilterRepresentation b) {
- if (b == null) {
- return false;
- }
- return getFilterClass() == b.getFilterClass();
- }
-
- public int getTextId() {
- return mTextId;
- }
-
- public void setTextId(int textId) {
- mTextId = textId;
- }
-
- public int getOverlayId() {
- return mOverlayId;
- }
-
- public void setOverlayId(int overlayId) {
- mOverlayId = overlayId;
- }
-
- public boolean getOverlayOnly() {
- return mOverlayOnly;
- }
-
- public void setOverlayOnly(boolean value) {
- mOverlayOnly = value;
- }
-
- final public int getEditorId() {
- return mEditorId;
- }
-
- public int[] getEditorIds() {
- return new int[] {
- mEditorId };
- }
-
- public void setEditorId(int editorId) {
- mEditorId = editorId;
- }
-
- public boolean showParameterValue() {
- return mShowParameterValue;
- }
-
- public void setShowParameterValue(boolean showParameterValue) {
- mShowParameterValue = showParameterValue;
- }
-
- public String getStateRepresentation() {
- return "";
- }
-
- /**
- * Method must "beginObject()" add its info and "endObject()"
- * @param writer
- * @throws IOException
- */
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- {
- String[][] rep = serializeRepresentation();
- for (int k = 0; k < rep.length; k++) {
- writer.name(rep[k][0]);
- writer.value(rep[k][1]);
- }
- }
- writer.endObject();
- }
-
- // this is the old way of doing this and will be removed soon
- public String[][] serializeRepresentation() {
- String[][] ret = {{NAME_TAG, getName()}};
- return ret;
- }
-
- public void deSerializeRepresentation(JsonReader reader) throws IOException {
- ArrayList<String[]> al = new ArrayList<String[]>();
- reader.beginObject();
- while (reader.hasNext()) {
- String[] kv = {reader.nextName(), reader.nextString()};
- al.add(kv);
-
- }
- reader.endObject();
- String[][] oldFormat = al.toArray(new String[al.size()][]);
-
- deSerializeRepresentation(oldFormat);
- }
-
- // this is the old way of doing this and will be removed soon
- public void deSerializeRepresentation(String[][] rep) {
- for (int i = 0; i < rep.length; i++) {
- if (NAME_TAG.equals(rep[i][0])) {
- mName = rep[i][1];
- break;
- }
- }
- }
-
- // Override this in subclasses
- public int getStyle() {
- return -1;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
deleted file mode 100644
index eb89de036..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorRotate;
-
-import java.io.IOException;
-
-public class FilterRotateRepresentation extends FilterRepresentation {
- public static final String SERIALIZATION_NAME = "ROTATION";
- public static final String SERIALIZATION_ROTATE_VALUE = "value";
- private static final String TAG = FilterRotateRepresentation.class.getSimpleName();
-
- Rotation mRotation;
-
- public enum Rotation {
- ZERO(0), NINETY(90), ONE_EIGHTY(180), TWO_SEVENTY(270);
- private final int mValue;
-
- private Rotation(int value) {
- mValue = value;
- }
-
- public int value() {
- return mValue;
- }
-
- public static Rotation fromValue(int value) {
- switch (value) {
- case 0:
- return ZERO;
- case 90:
- return NINETY;
- case 180:
- return ONE_EIGHTY;
- case 270:
- return TWO_SEVENTY;
- default:
- return null;
- }
- }
- }
-
- public FilterRotateRepresentation(Rotation rotation) {
- super(FilterRotateRepresentation.class.getSimpleName());
- setSerializationName(SERIALIZATION_NAME);
- setShowParameterValue(true);
- setFilterClass(FilterRotateRepresentation.class);
- setFilterType(FilterRepresentation.TYPE_GEOMETRY);
- setTextId(R.string.rotate);
- setEditorId(EditorRotate.ID);
- setRotation(rotation);
- }
-
- public FilterRotateRepresentation(FilterRotateRepresentation r) {
- this(r.getRotation());
- }
-
- public FilterRotateRepresentation() {
- this(getNil());
- }
-
- public Rotation getRotation() {
- return mRotation;
- }
-
- public void rotateCW() {
- switch(mRotation) {
- case ZERO:
- mRotation = Rotation.NINETY;
- break;
- case NINETY:
- mRotation = Rotation.ONE_EIGHTY;
- break;
- case ONE_EIGHTY:
- mRotation = Rotation.TWO_SEVENTY;
- break;
- case TWO_SEVENTY:
- mRotation = Rotation.ZERO;
- break;
- }
- }
-
- public void set(FilterRotateRepresentation r) {
- mRotation = r.mRotation;
- }
-
- public void setRotation(Rotation rotation) {
- if (rotation == null) {
- throw new IllegalArgumentException("Argument to setRotation is null");
- }
- mRotation = rotation;
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- @Override
- public FilterRepresentation copy() {
- return new FilterRotateRepresentation(this);
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- if (!(representation instanceof FilterRotateRepresentation)) {
- throw new IllegalArgumentException("calling copyAllParameters with incompatible types!");
- }
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (!(a instanceof FilterRotateRepresentation)) {
- throw new IllegalArgumentException("calling useParametersFrom with incompatible types!");
- }
- setRotation(((FilterRotateRepresentation) a).getRotation());
- }
-
- @Override
- public boolean isNil() {
- return mRotation == getNil();
- }
-
- public static Rotation getNil() {
- return Rotation.ZERO;
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- writer.name(SERIALIZATION_ROTATE_VALUE).value(mRotation.value());
- writer.endObject();
- }
-
- @Override
- public boolean equals(FilterRepresentation rep) {
- if (!(rep instanceof FilterRotateRepresentation)) {
- return false;
- }
- FilterRotateRepresentation rotate = (FilterRotateRepresentation) rep;
- if (rotate.mRotation.value() != mRotation.value()) {
- return false;
- }
- return true;
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader reader) throws IOException {
- boolean unset = true;
- reader.beginObject();
- while (reader.hasNext()) {
- String name = reader.nextName();
- if (SERIALIZATION_ROTATE_VALUE.equals(name)) {
- Rotation r = Rotation.fromValue(reader.nextInt());
- if (r != null) {
- setRotation(r);
- unset = false;
- }
- } else {
- reader.skipValue();
- }
- }
- if (unset) {
- Log.w(TAG, "WARNING: bad value when deserializing " + SERIALIZATION_NAME);
- }
- reader.endObject();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
deleted file mode 100644
index 94c9497fc..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.util.JsonReader;
-import android.util.JsonWriter;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorStraighten;
-
-import java.io.IOException;
-
-public class FilterStraightenRepresentation extends FilterRepresentation {
- public static final String SERIALIZATION_NAME = "STRAIGHTEN";
- public static final String SERIALIZATION_STRAIGHTEN_VALUE = "value";
- private static final String TAG = FilterStraightenRepresentation.class.getSimpleName();
- public static final int MAX_STRAIGHTEN_ANGLE = 45;
- public static final int MIN_STRAIGHTEN_ANGLE = -45;
-
- float mStraighten;
-
- public FilterStraightenRepresentation(float straighten) {
- super(FilterStraightenRepresentation.class.getSimpleName());
- setSerializationName(SERIALIZATION_NAME);
- setShowParameterValue(true);
- setFilterClass(FilterStraightenRepresentation.class);
- setFilterType(FilterRepresentation.TYPE_GEOMETRY);
- setTextId(R.string.straighten);
- setEditorId(EditorStraighten.ID);
- setStraighten(straighten);
- }
-
- public FilterStraightenRepresentation(FilterStraightenRepresentation s) {
- this(s.getStraighten());
- }
-
- public FilterStraightenRepresentation() {
- this(getNil());
- }
-
- public void set(FilterStraightenRepresentation r) {
- mStraighten = r.mStraighten;
- }
-
- @Override
- public boolean equals(FilterRepresentation rep) {
- if (!(rep instanceof FilterStraightenRepresentation)) {
- return false;
- }
- FilterStraightenRepresentation straighten = (FilterStraightenRepresentation) rep;
- if (straighten.mStraighten != mStraighten) {
- return false;
- }
- return true;
- }
-
- public float getStraighten() {
- return mStraighten;
- }
-
- public void setStraighten(float straighten) {
- if (!rangeCheck(straighten)) {
- straighten = Math.min(Math.max(straighten, MIN_STRAIGHTEN_ANGLE), MAX_STRAIGHTEN_ANGLE);
- }
- mStraighten = straighten;
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-
- @Override
- public FilterRepresentation copy() {
- return new FilterStraightenRepresentation(this);
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- if (!(representation instanceof FilterStraightenRepresentation)) {
- throw new IllegalArgumentException("calling copyAllParameters with incompatible types!");
- }
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- if (!(a instanceof FilterStraightenRepresentation)) {
- throw new IllegalArgumentException("calling useParametersFrom with incompatible types!");
- }
- setStraighten(((FilterStraightenRepresentation) a).getStraighten());
- }
-
- @Override
- public boolean isNil() {
- return mStraighten == getNil();
- }
-
- public static float getNil() {
- return 0;
- }
-
- @Override
- public void serializeRepresentation(JsonWriter writer) throws IOException {
- writer.beginObject();
- writer.name(SERIALIZATION_STRAIGHTEN_VALUE).value(mStraighten);
- writer.endObject();
- }
-
- @Override
- public void deSerializeRepresentation(JsonReader reader) throws IOException {
- boolean unset = true;
- reader.beginObject();
- while (reader.hasNext()) {
- String name = reader.nextName();
- if (SERIALIZATION_STRAIGHTEN_VALUE.equals(name)) {
- float s = (float) reader.nextDouble();
- if (rangeCheck(s)) {
- setStraighten(s);
- unset = false;
- }
- } else {
- reader.skipValue();
- }
- }
- if (unset) {
- Log.w(TAG, "WARNING: bad value when deserializing " + SERIALIZATION_NAME);
- }
- reader.endObject();
- }
-
- private boolean rangeCheck(double s) {
- if (s < -45 || s > 45) {
- return false;
- }
- return true;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
deleted file mode 100644
index be1812957..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
-
-public class FilterTinyPlanetRepresentation extends FilterBasicRepresentation {
- private static final String SERIALIZATION_NAME = "TINYPLANET";
- private static final String LOGTAG = "FilterTinyPlanetRepresentation";
- private static final String SERIAL_ANGLE = "Angle";
- private float mAngle = 0;
-
- public FilterTinyPlanetRepresentation() {
- super("TinyPlanet", 0, 50, 100);
- setSerializationName(SERIALIZATION_NAME);
- setShowParameterValue(true);
- setFilterClass(ImageFilterTinyPlanet.class);
- setFilterType(FilterRepresentation.TYPE_TINYPLANET);
- setTextId(R.string.tinyplanet);
- setEditorId(EditorTinyPlanet.ID);
- setMinimum(1);
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterTinyPlanetRepresentation representation = new FilterTinyPlanetRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- FilterTinyPlanetRepresentation representation = (FilterTinyPlanetRepresentation) a;
- super.useParametersFrom(a);
- mAngle = representation.mAngle;
- setZoom(representation.getZoom());
- }
-
- public void setAngle(float angle) {
- mAngle = angle;
- }
-
- public float getAngle() {
- return mAngle;
- }
-
- public int getZoom() {
- return getValue();
- }
-
- public void setZoom(int zoom) {
- setValue(zoom);
- }
-
- public boolean isNil() {
- // TinyPlanet always has an effect
- return false;
- }
-
- @Override
- public String[][] serializeRepresentation() {
- String[][] ret = {
- {SERIAL_NAME , getName() },
- {SERIAL_VALUE , Integer.toString(getValue())},
- {SERIAL_ANGLE , Float.toString(mAngle)}};
- return ret;
- }
-
- @Override
- public void deSerializeRepresentation(String[][] rep) {
- super.deSerializeRepresentation(rep);
- for (int i = 0; i < rep.length; i++) {
- if (SERIAL_VALUE.equals(rep[i][0])) {
- setValue(Integer.parseInt(rep[i][1]));
- } else if (SERIAL_ANGLE.equals(rep[i][0])) {
- setAngle(Float.parseFloat(rep[i][1]));
- }
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterUserPresetRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterUserPresetRepresentation.java
deleted file mode 100644
index dfdb6fcf0..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterUserPresetRepresentation.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
-
-public class FilterUserPresetRepresentation extends FilterRepresentation {
-
- private ImagePreset mPreset;
- private int mId;
-
- public FilterUserPresetRepresentation(String name, ImagePreset preset, int id) {
- super(name);
- setEditorId(ImageOnlyEditor.ID);
- setFilterType(FilterRepresentation.TYPE_FX);
- mPreset = preset;
- mId = id;
- }
-
- public ImagePreset getImagePreset() {
- return mPreset;
- }
-
- public int getId() {
- return mId;
- }
-
- public FilterRepresentation copy(){
- FilterRepresentation representation = new FilterUserPresetRepresentation(getName(),
- new ImagePreset(mPreset), mId);
- return representation;
- }
-
- @Override
- public boolean allowsSingleInstanceOnly() {
- return true;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
deleted file mode 100644
index 42a7406bc..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorVignette;
-import com.android.gallery3d.filtershow.imageshow.Oval;
-
-public class FilterVignetteRepresentation extends FilterBasicRepresentation implements Oval {
- private static final String LOGTAG = "FilterVignetteRepresentation";
- private float mCenterX = Float.NaN;
- private float mCenterY;
- private float mRadiusX = Float.NaN;
- private float mRadiusY;
-
- public FilterVignetteRepresentation() {
- super("Vignette", -100, 50, 100);
- setSerializationName("VIGNETTE");
- setShowParameterValue(true);
- setFilterType(FilterRepresentation.TYPE_VIGNETTE);
- setTextId(R.string.vignette);
- setEditorId(EditorVignette.ID);
- setName("Vignette");
- setFilterClass(ImageFilterVignette.class);
- setMinimum(-100);
- setMaximum(100);
- setDefaultValue(0);
- }
-
- @Override
- public void useParametersFrom(FilterRepresentation a) {
- super.useParametersFrom(a);
- mCenterX = ((FilterVignetteRepresentation) a).mCenterX;
- mCenterY = ((FilterVignetteRepresentation) a).mCenterY;
- mRadiusX = ((FilterVignetteRepresentation) a).mRadiusX;
- mRadiusY = ((FilterVignetteRepresentation) a).mRadiusY;
- }
-
- @Override
- public FilterRepresentation copy() {
- FilterVignetteRepresentation representation = new FilterVignetteRepresentation();
- copyAllParameters(representation);
- return representation;
- }
-
- @Override
- protected void copyAllParameters(FilterRepresentation representation) {
- super.copyAllParameters(representation);
- representation.useParametersFrom(this);
- }
-
- @Override
- public void setCenter(float centerX, float centerY) {
- mCenterX = centerX;
- mCenterY = centerY;
- }
-
- @Override
- public float getCenterX() {
- return mCenterX;
- }
-
- @Override
- public float getCenterY() {
- return mCenterY;
- }
-
- @Override
- public void setRadius(float radiusX, float radiusY) {
- mRadiusX = radiusX;
- mRadiusY = radiusY;
- }
-
- @Override
- public void setRadiusX(float radiusX) {
- mRadiusX = radiusX;
- }
-
- @Override
- public void setRadiusY(float radiusY) {
- mRadiusY = radiusY;
- }
-
- @Override
- public float getRadiusX() {
- return mRadiusX;
- }
-
- @Override
- public float getRadiusY() {
- return mRadiusY;
- }
-
- public boolean isCenterSet() {
- return mCenterX != Float.NaN;
- }
-
- @Override
- public boolean isNil() {
- return getValue() == 0;
- }
-
- @Override
- public boolean equals(FilterRepresentation representation) {
- if (!super.equals(representation)) {
- return false;
- }
- if (representation instanceof FilterVignetteRepresentation) {
- FilterVignetteRepresentation rep = (FilterVignetteRepresentation) representation;
- if (rep.getCenterX() == getCenterX()
- && rep.getCenterY() == getCenterY()
- && rep.getRadiusX() == getRadiusX()
- && rep.getRadiusY() == getRadiusY()) {
- return true;
- }
- }
- return false;
- }
-
- private static final String[] sParams = {
- "Name", "value", "mCenterX", "mCenterY", "mRadiusX",
- "mRadiusY"
- };
-
- @Override
- public String[][] serializeRepresentation() {
- String[][] ret = {
- { sParams[0], getName() },
- { sParams[1], Integer.toString(getValue()) },
- { sParams[2], Float.toString(mCenterX) },
- { sParams[3], Float.toString(mCenterY) },
- { sParams[4], Float.toString(mRadiusX) },
- { sParams[5], Float.toString(mRadiusY) }
- };
- return ret;
- }
-
- @Override
- public void deSerializeRepresentation(String[][] rep) {
- super.deSerializeRepresentation(rep);
- for (int i = 0; i < rep.length; i++) {
- String key = rep[i][0];
- String value = rep[i][1];
- if (sParams[0].equals(key)) {
- setName(value);
- } else if (sParams[1].equals(key)) {
- setValue(Integer.parseInt(value));
- } else if (sParams[2].equals(key)) {
- mCenterX = Float.parseFloat(value);
- } else if (sParams[3].equals(key)) {
- mCenterY = Float.parseFloat(value);
- } else if (sParams[4].equals(key)) {
- mRadiusX = Float.parseFloat(value);
- } else if (sParams[5].equals(key)) {
- mRadiusY = Float.parseFloat(value);
- }
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/FiltersManagerInterface.java b/src/com/android/gallery3d/filtershow/filters/FiltersManagerInterface.java
deleted file mode 100644
index 710128f99..000000000
--- a/src/com/android/gallery3d/filtershow/filters/FiltersManagerInterface.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-public interface FiltersManagerInterface {
- ImageFilter getFilterForRepresentation(FilterRepresentation representation);
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/IconUtilities.java b/src/com/android/gallery3d/filtershow/filters/IconUtilities.java
deleted file mode 100644
index e2a01472d..000000000
--- a/src/com/android/gallery3d/filtershow/filters/IconUtilities.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import com.android.gallery3d.R;
-
-public class IconUtilities {
- public static final int PUNCH = R.drawable.filtershow_fx_0005_punch;
- public static final int VINTAGE = R.drawable.filtershow_fx_0000_vintage;
- public static final int BW_CONTRAST = R.drawable.filtershow_fx_0004_bw_contrast;
- public static final int BLEACH = R.drawable.filtershow_fx_0002_bleach;
- public static final int INSTANT = R.drawable.filtershow_fx_0001_instant;
- public static final int WASHOUT = R.drawable.filtershow_fx_0007_washout;
- public static final int BLUECRUSH = R.drawable.filtershow_fx_0003_blue_crush;
- public static final int WASHOUT_COLOR = R.drawable.filtershow_fx_0008_washout_color;
- public static final int X_PROCESS = R.drawable.filtershow_fx_0006_x_process;
-
- public static Bitmap getFXBitmap(Resources res, int id) {
- Bitmap ret;
- BitmapFactory.Options o = new BitmapFactory.Options();
- o.inScaled = false;
-
- if (id != 0) {
- return BitmapFactory.decodeResource(res, id, o);
- }
- return null;
- }
-
- public static Bitmap loadBitmap(Resources res, int resource) {
-
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeResource(
- res,
- resource, options);
-
- return bitmap;
- }
-
- public static Bitmap applyFX(Bitmap bitmap, final Bitmap fxBitmap) {
- ImageFilterFx fx = new ImageFilterFx() {
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
-
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- int fxw = fxBitmap.getWidth();
- int fxh = fxBitmap.getHeight();
- int start = 0;
- int end = w * h * 4;
- nativeApplyFilter(bitmap, w, h, fxBitmap, fxw, fxh, start, end);
- return bitmap;
- }
- };
- return fx.apply(bitmap, 0, 0);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
deleted file mode 100644
index 437137416..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.app.Activity;
-import android.graphics.Bitmap;
-import android.graphics.Matrix;
-import android.support.v8.renderscript.Allocation;
-import android.widget.Toast;
-
-import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-
-public abstract class ImageFilter implements Cloneable {
- private FilterEnvironment mEnvironment = null;
-
- protected String mName = "Original";
- private final String LOGTAG = "ImageFilter";
- protected static final boolean SIMPLE_ICONS = true;
- // TODO: Temporary, for dogfood note memory issues with toasts for better
- // feedback. Remove this when filters actually work in low memory
- // situations.
- private static Activity sActivity = null;
-
- public static void setActivityForMemoryToasts(Activity activity) {
- sActivity = activity;
- }
-
- public static void resetStatics() {
- sActivity = null;
- }
-
- public void freeResources() {}
-
- public void displayLowMemoryToast() {
- if (sActivity != null) {
- sActivity.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(sActivity, "Memory too low for filter " + getName() +
- ", please file a bug report", Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
-
- public void setName(String name) {
- mName = name;
- }
-
- public String getName() {
- return mName;
- }
-
- public boolean supportsAllocationInput() { return false; }
-
- public void apply(Allocation in, Allocation out) {
- setGeneralParameters();
- }
-
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- // do nothing here, subclasses will implement filtering here
- setGeneralParameters();
- return bitmap;
- }
-
- public abstract void useRepresentation(FilterRepresentation representation);
-
- native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
- int[] redGradient, int[] greenGradient, int[] blueGradient);
-
- public FilterRepresentation getDefaultRepresentation() {
- return null;
- }
-
- protected Matrix getOriginalToScreenMatrix(int w, int h) {
- return GeometryMathUtils.getImageToScreenMatrix(getEnvironment().getImagePreset()
- .getGeometryFilters(), true, MasterImage.getImage().getOriginalBounds(), w, h);
- }
-
- public void setEnvironment(FilterEnvironment environment) {
- mEnvironment = environment;
- }
-
- public FilterEnvironment getEnvironment() {
- return mEnvironment;
- }
-
- public void setGeneralParameters() {
- // should implement in subclass which like to transport
- // some information to other filters. (like the style setting from RetroLux
- // and Film to FixedFrame)
- mEnvironment.clearGeneralParameters();
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
deleted file mode 100644
index a7286f0fa..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-
-import java.util.HashMap;
-
-public class ImageFilterBorder extends ImageFilter {
- private static final float NINEPATCH_ICON_SCALING = 10;
- private static final float BITMAP_ICON_SCALING = 1 / 3.0f;
- private FilterImageBorderRepresentation mParameters = null;
- private Resources mResources = null;
-
- private HashMap<Integer, Drawable> mDrawables = new HashMap<Integer, Drawable>();
-
- public ImageFilterBorder() {
- mName = "Border";
- }
-
- public void useRepresentation(FilterRepresentation representation) {
- FilterImageBorderRepresentation parameters = (FilterImageBorderRepresentation) representation;
- mParameters = parameters;
- }
-
- public FilterImageBorderRepresentation getParameters() {
- return mParameters;
- }
-
- public void freeResources() {
- mDrawables.clear();
- }
-
- public Bitmap applyHelper(Bitmap bitmap, float scale1, float scale2 ) {
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- Rect bounds = new Rect(0, 0, (int) (w * scale1), (int) (h * scale1));
- Canvas canvas = new Canvas(bitmap);
- canvas.scale(scale2, scale2);
- Drawable drawable = getDrawable(getParameters().getDrawableResource());
- drawable.setBounds(bounds);
- drawable.draw(canvas);
- return bitmap;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null || getParameters().getDrawableResource() == 0) {
- return bitmap;
- }
- float scale2 = scaleFactor * 2.0f;
- float scale1 = 1 / scale2;
- return applyHelper(bitmap, scale1, scale2);
- }
-
- public void setResources(Resources resources) {
- if (mResources != resources) {
- mResources = resources;
- mDrawables.clear();
- }
- }
-
- public Drawable getDrawable(int rsc) {
- Drawable drawable = mDrawables.get(rsc);
- if (drawable == null && mResources != null && rsc != 0) {
- drawable = new BitmapDrawable(mResources, BitmapFactory.decodeResource(mResources, rsc));
- mDrawables.put(rsc, drawable);
- }
- return drawable;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java
deleted file mode 100644
index 50837ca2f..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-import android.graphics.Bitmap;
-import android.graphics.Color;
-
-
-public class ImageFilterBwFilter extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "BWFILTER";
-
- public ImageFilterBwFilter() {
- mName = "BW Filter";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("BW Filter");
- representation.setSerializationName(SERIALIZATION_NAME);
-
- representation.setFilterClass(ImageFilterBwFilter.class);
- representation.setMaximum(180);
- representation.setMinimum(-180);
- representation.setTextId(R.string.bwfilter);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, int r, int g, int b);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float[] hsv = new float[] {
- 180 + getParameters().getValue(), 1, 1
- };
- int rgb = Color.HSVToColor(hsv);
- int r = 0xFF & (rgb >> 16);
- int g = 0xFF & (rgb >> 8);
- int b = 0xFF & (rgb >> 0);
- nativeApplyFilter(bitmap, w, h, r, g, b);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java
deleted file mode 100644
index 1ea8edfb8..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Matrix;
-import android.support.v8.renderscript.Allocation;
-import android.support.v8.renderscript.Element;
-import android.support.v8.renderscript.RenderScript;
-import android.support.v8.renderscript.Script.LaunchOptions;
-import android.support.v8.renderscript.Type;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-
-public class ImageFilterChanSat extends ImageFilterRS {
- private static final String LOGTAG = "ImageFilterChanSat";
- private ScriptC_saturation mScript;
- private Bitmap mSourceBitmap;
-
- private static final int STRIP_SIZE = 64;
-
- FilterChanSatRepresentation mParameters = new FilterChanSatRepresentation();
- private Bitmap mOverlayBitmap;
-
- public ImageFilterChanSat() {
- mName = "ChannelSat";
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return new FilterChanSatRepresentation();
- }
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- mParameters = (FilterChanSatRepresentation) representation;
- }
-
- @Override
- protected void resetAllocations() {
-
- }
-
- @Override
- public void resetScripts() {
- if (mScript != null) {
- mScript.destroy();
- mScript = null;
- }
- }
- @Override
- protected void createFilter(android.content.res.Resources res, float scaleFactor,
- int quality) {
- createFilter(res, scaleFactor, quality, getInPixelsAllocation());
- }
-
- @Override
- protected void createFilter(android.content.res.Resources res, float scaleFactor,
- int quality, Allocation in) {
- RenderScript rsCtx = getRenderScriptContext();
-
- Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx));
- tb_float.setX(in.getType().getX());
- tb_float.setY(in.getType().getY());
- mScript = new ScriptC_saturation(rsCtx, res, R.raw.saturation);
- }
-
-
- private Bitmap getSourceBitmap() {
- assert (mSourceBitmap != null);
- return mSourceBitmap;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) {
- return bitmap;
- }
-
- mSourceBitmap = bitmap;
- Bitmap ret = super.apply(bitmap, scaleFactor, quality);
- mSourceBitmap = null;
-
- return ret;
- }
-
- @Override
- protected void bindScriptValues() {
- int width = getInPixelsAllocation().getType().getX();
- int height = getInPixelsAllocation().getType().getY();
- }
-
-
-
- @Override
- protected void runFilter() {
- int []sat = new int[7];
- for(int i = 0;i<sat.length ;i ++){
- sat[i] = mParameters.getValue(i);
- }
-
-
- int width = getInPixelsAllocation().getType().getX();
- int height = getInPixelsAllocation().getType().getY();
- Matrix m = getOriginalToScreenMatrix(width, height);
-
-
- mScript.set_saturation(sat);
-
- mScript.invoke_setupGradParams();
- runSelectiveAdjust(
- getInPixelsAllocation(), getOutPixelsAllocation());
-
- }
-
- private void runSelectiveAdjust(Allocation in, Allocation out) {
- int width = in.getType().getX();
- int height = in.getType().getY();
-
- LaunchOptions options = new LaunchOptions();
- int ty;
- options.setX(0, width);
-
- for (ty = 0; ty < height; ty += STRIP_SIZE) {
- int endy = ty + STRIP_SIZE;
- if (endy > height) {
- endy = height;
- }
- options.setY(ty, endy);
- mScript.forEach_selectiveAdjust(in, out, options);
- if (checkStop()) {
- return;
- }
- }
- }
-
- private boolean checkStop() {
- RenderScript rsCtx = getRenderScriptContext();
- rsCtx.finish();
- if (getEnvironment().needsStop()) {
- return true;
- }
- return false;
- }
-}
-
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java
deleted file mode 100644
index 27c0e0877..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-import android.graphics.Bitmap;
-
-public class ImageFilterContrast extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "CONTRAST";
-
- public ImageFilterContrast() {
- mName = "Contrast";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Contrast");
- representation.setSerializationName(SERIALIZATION_NAME);
-
- representation.setFilterClass(ImageFilterContrast.class);
- representation.setTextId(R.string.contrast);
- representation.setMinimum(-100);
- representation.setMaximum(100);
- representation.setDefaultValue(0);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float strength);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float value = getParameters().getValue();
- nativeApplyFilter(bitmap, w, h, value);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
deleted file mode 100644
index 61b60d2e3..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-
-import com.android.gallery3d.filtershow.imageshow.Spline;
-
-public class ImageFilterCurves extends ImageFilter {
-
- private static final String LOGTAG = "ImageFilterCurves";
- FilterCurvesRepresentation mParameters = new FilterCurvesRepresentation();
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return new FilterCurvesRepresentation();
- }
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- FilterCurvesRepresentation parameters = (FilterCurvesRepresentation) representation;
- mParameters = parameters;
- }
-
- public ImageFilterCurves() {
- mName = "Curves";
- reset();
- }
-
- public void populateArray(int[] array, int curveIndex) {
- Spline spline = mParameters.getSpline(curveIndex);
- if (spline == null) {
- return;
- }
- float[] curve = spline.getAppliedCurve();
- for (int i = 0; i < 256; i++) {
- array[i] = (int) (curve[i] * 255);
- }
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (!mParameters.getSpline(Spline.RGB).isOriginal()) {
- int[] rgbGradient = new int[256];
- populateArray(rgbGradient, Spline.RGB);
- nativeApplyGradientFilter(bitmap, bitmap.getWidth(), bitmap.getHeight(),
- rgbGradient, rgbGradient, rgbGradient);
- }
-
- int[] redGradient = null;
- if (!mParameters.getSpline(Spline.RED).isOriginal()) {
- redGradient = new int[256];
- populateArray(redGradient, Spline.RED);
- }
- int[] greenGradient = null;
- if (!mParameters.getSpline(Spline.GREEN).isOriginal()) {
- greenGradient = new int[256];
- populateArray(greenGradient, Spline.GREEN);
- }
- int[] blueGradient = null;
- if (!mParameters.getSpline(Spline.BLUE).isOriginal()) {
- blueGradient = new int[256];
- populateArray(blueGradient, Spline.BLUE);
- }
-
- nativeApplyGradientFilter(bitmap, bitmap.getWidth(), bitmap.getHeight(),
- redGradient, greenGradient, blueGradient);
- return bitmap;
- }
-
- public void setSpline(Spline spline, int splineIndex) {
- mParameters.setSpline(splineIndex, new Spline(spline));
- }
-
- public Spline getSpline(int splineIndex) {
- return mParameters.getSpline(splineIndex);
- }
-
- public void reset() {
- Spline spline = new Spline();
-
- spline.addPoint(0.0f, 1.0f);
- spline.addPoint(1.0f, 0.0f);
-
- for (int i = 0; i < 4; i++) {
- mParameters.setSpline(i, new Spline(spline));
- }
- }
-
- public void useFilter(ImageFilter a) {
- ImageFilterCurves c = (ImageFilterCurves) a;
- for (int i = 0; i < 4; i++) {
- if (c.mParameters.getSpline(i) != null) {
- setSpline(c.mParameters.getSpline(i), i);
- }
- }
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java
deleted file mode 100644
index efb9cde71..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.cache.ImageLoader;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-
-public class ImageFilterDownsample extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "DOWNSAMPLE";
- private static final int ICON_DOWNSAMPLE_FRACTION = 8;
- private ImageLoader mImageLoader;
-
- public ImageFilterDownsample(ImageLoader loader) {
- mName = "Downsample";
- mImageLoader = loader;
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Downsample");
- representation.setSerializationName(SERIALIZATION_NAME);
-
- representation.setFilterClass(ImageFilterDownsample.class);
- representation.setMaximum(100);
- representation.setMinimum(1);
- representation.setValue(50);
- representation.setDefaultValue(50);
- representation.setPreviewValue(3);
- representation.setTextId(R.string.downsample);
- return representation;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- int p = getParameters().getValue();
-
- // size of original precached image
- Rect size = MasterImage.getImage().getOriginalBounds();
- int orig_w = size.width();
- int orig_h = size.height();
-
- if (p > 0 && p < 100) {
- // scale preview to same size as the resulting bitmap from a "save"
- int newWidth = orig_w * p / 100;
- int newHeight = orig_h * p / 100;
-
- // only scale preview if preview isn't already scaled enough
- if (newWidth <= 0 || newHeight <= 0 || newWidth >= w || newHeight >= h) {
- return bitmap;
- }
- Bitmap ret = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
- if (ret != bitmap) {
- bitmap.recycle();
- }
- return ret;
- }
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
deleted file mode 100644
index 7df5ffb64..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Paint.Style;
-import android.graphics.Path;
-import android.graphics.PathMeasure;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.cache.ImageLoader;
-import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation.StrokeData;
-import com.android.gallery3d.filtershow.imageshow.MasterImage;
-import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-
-import java.util.Vector;
-
-public class ImageFilterDraw extends ImageFilter {
- private static final String LOGTAG = "ImageFilterDraw";
- public final static byte SIMPLE_STYLE = 0;
- public final static byte BRUSH_STYLE_SPATTER = 1;
- public final static byte BRUSH_STYLE_MARKER = 2;
- public final static int NUMBER_OF_STYLES = 3;
- Bitmap mOverlayBitmap; // this accelerates interaction
- int mCachedStrokes = -1;
- int mCurrentStyle = 0;
-
- FilterDrawRepresentation mParameters = new FilterDrawRepresentation();
-
- public ImageFilterDraw() {
- mName = "Image Draw";
- }
-
- DrawStyle[] mDrawingsTypes = new DrawStyle[] {
- new SimpleDraw(),
- new Brush(R.drawable.brush_marker),
- new Brush(R.drawable.brush_spatter)
- };
- {
- for (int i = 0; i < mDrawingsTypes.length; i++) {
- mDrawingsTypes[i].setType((byte) i);
- }
-
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return new FilterDrawRepresentation();
- }
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- FilterDrawRepresentation parameters = (FilterDrawRepresentation) representation;
- mParameters = parameters;
- }
-
- public void setStyle(byte style) {
- mCurrentStyle = style % mDrawingsTypes.length;
- }
-
- public int getStyle() {
- return mCurrentStyle;
- }
-
- public static interface DrawStyle {
- public void setType(byte type);
- public void paint(FilterDrawRepresentation.StrokeData sd, Canvas canvas, Matrix toScrMatrix,
- int quality);
- }
-
- class SimpleDraw implements DrawStyle {
- byte mType;
-
- @Override
- public void setType(byte type) {
- mType = type;
- }
-
- @Override
- public void paint(FilterDrawRepresentation.StrokeData sd, Canvas canvas, Matrix toScrMatrix,
- int quality) {
- if (sd == null) {
- return;
- }
- if (sd.mPath == null) {
- return;
- }
- Paint paint = new Paint();
-
- paint.setStyle(Style.STROKE);
- paint.setColor(sd.mColor);
- paint.setStrokeWidth(toScrMatrix.mapRadius(sd.mRadius));
-
- // done this way because of a bug in path.transform(matrix)
- Path mCacheTransPath = new Path();
- mCacheTransPath.addPath(sd.mPath, toScrMatrix);
-
- canvas.drawPath(mCacheTransPath, paint);
- }
- }
-
- class Brush implements DrawStyle {
- int mBrushID;
- Bitmap mBrush;
- byte mType;
-
- public Brush(int brushID) {
- mBrushID = brushID;
- }
-
- public Bitmap getBrush() {
- if (mBrush == null) {
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.inPreferredConfig = Bitmap.Config.ALPHA_8;
- mBrush = BitmapFactory.decodeResource(MasterImage.getImage().getActivity()
- .getResources(), mBrushID, opt);
- mBrush = mBrush.extractAlpha();
- }
- return mBrush;
- }
-
- @Override
- public void paint(FilterDrawRepresentation.StrokeData sd, Canvas canvas,
- Matrix toScrMatrix,
- int quality) {
- if (sd == null || sd.mPath == null) {
- return;
- }
- Paint paint = new Paint();
- paint.setStyle(Style.STROKE);
- paint.setAntiAlias(true);
- Path mCacheTransPath = new Path();
- mCacheTransPath.addPath(sd.mPath, toScrMatrix);
- draw(canvas, paint, sd.mColor, toScrMatrix.mapRadius(sd.mRadius) * 2,
- mCacheTransPath);
- }
-
- public Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
- {
- Matrix m = new Matrix();
- m.setScale(dstWidth / (float) src.getWidth(), dstHeight / (float) src.getHeight());
- Bitmap result = Bitmap.createBitmap(dstWidth, dstHeight, src.getConfig());
- Canvas canvas = new Canvas(result);
-
- Paint paint = new Paint();
- paint.setFilterBitmap(filter);
- canvas.drawBitmap(src, m, paint);
-
- return result;
-
- }
- void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
- PathMeasure mPathMeasure = new PathMeasure();
- float[] mPosition = new float[2];
- float[] mTan = new float[2];
-
- mPathMeasure.setPath(path, false);
-
- paint.setAntiAlias(true);
- paint.setColor(color);
-
- paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
- Bitmap brush;
- // done this way because of a bug in
- // Bitmap.createScaledBitmap(getBrush(),(int) size,(int) size,true);
- brush = createScaledBitmap(getBrush(), (int) size, (int) size, true);
- float len = mPathMeasure.getLength();
- float s2 = size / 2;
- float step = s2 / 8;
- for (float i = 0; i < len; i += step) {
- mPathMeasure.getPosTan(i, mPosition, mTan);
- // canvas.drawCircle(pos[0], pos[1], size, paint);
- canvas.drawBitmap(brush, mPosition[0] - s2, mPosition[1] - s2, paint);
- }
- }
-
- @Override
- public void setType(byte type) {
- mType = type;
- }
- }
-
- void paint(FilterDrawRepresentation.StrokeData sd, Canvas canvas, Matrix toScrMatrix,
- int quality) {
- mDrawingsTypes[sd.mType].paint(sd, canvas, toScrMatrix, quality);
- }
-
- public void drawData(Canvas canvas, Matrix originalRotateToScreen, int quality) {
- Paint paint = new Paint();
- if (quality == FilterEnvironment.QUALITY_FINAL) {
- paint.setAntiAlias(true);
- }
- paint.setStyle(Style.STROKE);
- paint.setColor(Color.RED);
- paint.setStrokeWidth(40);
-
- if (mParameters.getDrawing().isEmpty() && mParameters.getCurrentDrawing() == null) {
- return;
- }
- if (quality == FilterEnvironment.QUALITY_FINAL) {
- for (FilterDrawRepresentation.StrokeData strokeData : mParameters.getDrawing()) {
- paint(strokeData, canvas, originalRotateToScreen, quality);
- }
- return;
- }
-
- if (mOverlayBitmap == null ||
- mOverlayBitmap.getWidth() != canvas.getWidth() ||
- mOverlayBitmap.getHeight() != canvas.getHeight() ||
- mParameters.getDrawing().size() < mCachedStrokes) {
-
- mOverlayBitmap = Bitmap.createBitmap(
- canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
- mCachedStrokes = 0;
- }
-
- if (mCachedStrokes < mParameters.getDrawing().size()) {
- fillBuffer(originalRotateToScreen);
- }
- canvas.drawBitmap(mOverlayBitmap, 0, 0, paint);
-
- StrokeData stroke = mParameters.getCurrentDrawing();
- if (stroke != null) {
- paint(stroke, canvas, originalRotateToScreen, quality);
- }
- }
-
- public void fillBuffer(Matrix originalRotateToScreen) {
- Canvas drawCache = new Canvas(mOverlayBitmap);
- Vector<FilterDrawRepresentation.StrokeData> v = mParameters.getDrawing();
- int n = v.size();
-
- for (int i = mCachedStrokes; i < n; i++) {
- paint(v.get(i), drawCache, originalRotateToScreen, FilterEnvironment.QUALITY_PREVIEW);
- }
- mCachedStrokes = n;
- }
-
- public void draw(Canvas canvas, Matrix originalRotateToScreen) {
- for (FilterDrawRepresentation.StrokeData strokeData : mParameters.getDrawing()) {
- paint(strokeData, canvas, originalRotateToScreen, FilterEnvironment.QUALITY_PREVIEW);
- }
- mDrawingsTypes[mCurrentStyle].paint(
- null, canvas, originalRotateToScreen, FilterEnvironment.QUALITY_PREVIEW);
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
-
- Matrix m = getOriginalToScreenMatrix(w, h);
- drawData(new Canvas(bitmap), m, quality);
- return bitmap;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java
deleted file mode 100644
index 2d0d7653d..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-
-import com.android.gallery3d.R;
-
-public class ImageFilterEdge extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "EDGE";
- public ImageFilterEdge() {
- mName = "Edge";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterRepresentation representation = super.getDefaultRepresentation();
- representation.setName("Edge");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterEdge.class);
- representation.setTextId(R.string.edge);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float p);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float p = getParameters().getValue() + 101;
- p = (float) p / 100;
- nativeApplyFilter(bitmap, w, h, p);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java
deleted file mode 100644
index 69eab7330..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-import android.graphics.Bitmap;
-
-public class ImageFilterExposure extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "EXPOSURE";
- public ImageFilterExposure() {
- mName = "Exposure";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Exposure");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterExposure.class);
- representation.setTextId(R.string.exposure);
- representation.setMinimum(-100);
- representation.setMaximum(100);
- representation.setDefaultValue(0);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float bright);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float value = getParameters().getValue();
- nativeApplyFilter(bitmap, w, h, value);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
deleted file mode 100644
index 19bea593b..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import com.android.gallery3d.app.Log;
-
-public class ImageFilterFx extends ImageFilter {
- private static final String LOGTAG = "ImageFilterFx";
- private FilterFxRepresentation mParameters = null;
- private Bitmap mFxBitmap = null;
- private Resources mResources = null;
- private int mFxBitmapId = 0;
-
- public ImageFilterFx() {
- }
-
- @Override
- public void freeResources() {
- if (mFxBitmap != null) mFxBitmap.recycle();
- mFxBitmap = null;
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return null;
- }
-
- public void useRepresentation(FilterRepresentation representation) {
- FilterFxRepresentation parameters = (FilterFxRepresentation) representation;
- mParameters = parameters;
- }
-
- public FilterFxRepresentation getParameters() {
- return mParameters;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h,
- Bitmap fxBitmap, int fxw, int fxh,
- int start, int end);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null || mResources == null) {
- return bitmap;
- }
-
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
-
- int bitmapResourceId = getParameters().getBitmapResource();
- if (bitmapResourceId == 0) { // null filter fx
- return bitmap;
- }
-
- if (mFxBitmap == null || mFxBitmapId != bitmapResourceId) {
- BitmapFactory.Options o = new BitmapFactory.Options();
- o.inScaled = false;
- mFxBitmapId = bitmapResourceId;
- if (mFxBitmapId != 0) {
- mFxBitmap = BitmapFactory.decodeResource(mResources, mFxBitmapId, o);
- } else {
- Log.w(LOGTAG, "bad resource for filter: " + mName);
- }
- }
-
- if (mFxBitmap == null) {
- return bitmap;
- }
-
- int fxw = mFxBitmap.getWidth();
- int fxh = mFxBitmap.getHeight();
-
- int stride = w * 4;
- int max = stride * h;
- int increment = stride * 256; // 256 lines
- for (int i = 0; i < max; i += increment) {
- int start = i;
- int end = i + increment;
- if (end > max) {
- end = max;
- }
- if (!getEnvironment().needsStop()) {
- nativeApplyFilter(bitmap, w, h, mFxBitmap, fxw, fxh, start, end);
- }
- }
-
- return bitmap;
- }
-
- public void setResources(Resources resources) {
- mResources = resources;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java
deleted file mode 100644
index cbdfaa623..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.graphics.Matrix;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.graphics.Matrix;
-import android.support.v8.renderscript.Allocation;
-import android.support.v8.renderscript.Element;
-import android.support.v8.renderscript.RenderScript;
-import android.support.v8.renderscript.Script.LaunchOptions;
-import android.support.v8.renderscript.Type;
-import android.util.Log;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-
-public class ImageFilterGrad extends ImageFilterRS {
- private static final String LOGTAG = "ImageFilterGrad";
- private ScriptC_grad mScript;
- private Bitmap mSourceBitmap;
- private static final int RADIUS_SCALE_FACTOR = 160;
-
- private static final int STRIP_SIZE = 64;
-
- FilterGradRepresentation mParameters = new FilterGradRepresentation();
- private Bitmap mOverlayBitmap;
-
- public ImageFilterGrad() {
- mName = "grad";
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return new FilterGradRepresentation();
- }
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- mParameters = (FilterGradRepresentation) representation;
- }
-
- @Override
- protected void resetAllocations() {
-
- }
-
- @Override
- public void resetScripts() {
- if (mScript != null) {
- mScript.destroy();
- mScript = null;
- }
- }
- @Override
- protected void createFilter(android.content.res.Resources res, float scaleFactor,
- int quality) {
- createFilter(res, scaleFactor, quality, getInPixelsAllocation());
- }
-
- @Override
- protected void createFilter(android.content.res.Resources res, float scaleFactor,
- int quality, Allocation in) {
- RenderScript rsCtx = getRenderScriptContext();
-
- Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx));
- tb_float.setX(in.getType().getX());
- tb_float.setY(in.getType().getY());
- mScript = new ScriptC_grad(rsCtx, res, R.raw.grad);
- }
-
-
- private Bitmap getSourceBitmap() {
- assert (mSourceBitmap != null);
- return mSourceBitmap;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) {
- return bitmap;
- }
-
- mSourceBitmap = bitmap;
- Bitmap ret = super.apply(bitmap, scaleFactor, quality);
- mSourceBitmap = null;
-
- return ret;
- }
-
- @Override
- protected void bindScriptValues() {
- int width = getInPixelsAllocation().getType().getX();
- int height = getInPixelsAllocation().getType().getY();
- mScript.set_inputWidth(width);
- mScript.set_inputHeight(height);
- }
-
- @Override
- protected void runFilter() {
- int[] x1 = mParameters.getXPos1();
- int[] y1 = mParameters.getYPos1();
- int[] x2 = mParameters.getXPos2();
- int[] y2 = mParameters.getYPos2();
-
- int width = getInPixelsAllocation().getType().getX();
- int height = getInPixelsAllocation().getType().getY();
- Matrix m = getOriginalToScreenMatrix(width, height);
- float[] coord = new float[2];
- for (int i = 0; i < x1.length; i++) {
- coord[0] = x1[i];
- coord[1] = y1[i];
- m.mapPoints(coord);
- x1[i] = (int) coord[0];
- y1[i] = (int) coord[1];
- coord[0] = x2[i];
- coord[1] = y2[i];
- m.mapPoints(coord);
- x2[i] = (int) coord[0];
- y2[i] = (int) coord[1];
- }
-
- mScript.set_mask(mParameters.getMask());
- mScript.set_xPos1(x1);
- mScript.set_yPos1(y1);
- mScript.set_xPos2(x2);
- mScript.set_yPos2(y2);
-
- mScript.set_brightness(mParameters.getBrightness());
- mScript.set_contrast(mParameters.getContrast());
- mScript.set_saturation(mParameters.getSaturation());
-
- mScript.invoke_setupGradParams();
- runSelectiveAdjust(
- getInPixelsAllocation(), getOutPixelsAllocation());
-
- }
-
- private void runSelectiveAdjust(Allocation in, Allocation out) {
- int width = in.getType().getX();
- int height = in.getType().getY();
-
- LaunchOptions options = new LaunchOptions();
- int ty;
- options.setX(0, width);
-
- for (ty = 0; ty < height; ty += STRIP_SIZE) {
- int endy = ty + STRIP_SIZE;
- if (endy > height) {
- endy = height;
- }
- options.setY(ty, endy);
- mScript.forEach_selectiveAdjust(in, out, options);
- if (checkStop()) {
- return;
- }
- }
- }
-
- private boolean checkStop() {
- RenderScript rsCtx = getRenderScriptContext();
- rsCtx.finish();
- if (getEnvironment().needsStop()) {
- return true;
- }
- return false;
- }
-}
-
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterHighlights.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterHighlights.java
deleted file mode 100644
index 4c837e0bf..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterHighlights.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-
-import com.android.gallery3d.R;
-
-public class ImageFilterHighlights extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "HIGHLIGHTS";
- private static final String LOGTAG = "ImageFilterVignette";
-
- public ImageFilterHighlights() {
- mName = "Highlights";
- }
-
- SplineMath mSpline = new SplineMath(5);
- double[] mHighlightCurve = { 0.0, 0.32, 0.418, 0.476, 0.642 };
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Highlights");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterHighlights.class);
- representation.setTextId(R.string.highlight_recovery);
- representation.setMinimum(-100);
- representation.setMaximum(100);
- representation.setDefaultValue(0);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float[] luminanceMap);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- float p = getParameters().getValue();
- double t = p/100.;
- for (int i = 0; i < 5; i++) {
- double x = i / 4.;
- double y = mHighlightCurve[i] *t+x*(1-t);
- mSpline.setPoint(i, x, y);
- }
-
- float[][] curve = mSpline.calculatetCurve(256);
- float[] luminanceMap = new float[curve.length];
- for (int i = 0; i < luminanceMap.length; i++) {
- luminanceMap[i] = curve[i][1];
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
-
- nativeApplyFilter(bitmap, w, h, luminanceMap);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java
deleted file mode 100644
index b87c25490..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.BasicEditor;
-
-import android.graphics.Bitmap;
-
-public class ImageFilterHue extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "HUE";
- private ColorSpaceMatrix cmatrix = null;
-
- public ImageFilterHue() {
- mName = "Hue";
- cmatrix = new ColorSpaceMatrix();
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Hue");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterHue.class);
- representation.setMinimum(-180);
- representation.setMaximum(180);
- representation.setTextId(R.string.hue);
- representation.setEditorId(BasicEditor.ID);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float []matrix);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float value = getParameters().getValue();
- cmatrix.identity();
- cmatrix.setHue(value);
-
- nativeApplyFilter(bitmap, w, h, cmatrix.getMatrix());
-
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java
deleted file mode 100644
index 77cdf47b3..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.text.format.Time;
-
-import com.android.gallery3d.R;
-
-public class ImageFilterKMeans extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "KMEANS";
- private int mSeed = 0;
-
- public ImageFilterKMeans() {
- mName = "KMeans";
-
- // set random seed for session
- Time t = new Time();
- t.setToNow();
- mSeed = (int) t.toMillis(false);
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("KMeans");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterKMeans.class);
- representation.setMaximum(20);
- representation.setMinimum(2);
- representation.setValue(4);
- representation.setDefaultValue(4);
- representation.setPreviewValue(4);
- representation.setTextId(R.string.kmeans);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int width, int height,
- Bitmap large_ds_bm, int lwidth, int lheight, Bitmap small_ds_bm,
- int swidth, int sheight, int p, int seed);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
-
- Bitmap large_bm_ds = bitmap;
- Bitmap small_bm_ds = bitmap;
-
- // find width/height for larger downsampled bitmap
- int lw = w;
- int lh = h;
- while (lw > 256 && lh > 256) {
- lw /= 2;
- lh /= 2;
- }
- if (lw != w) {
- large_bm_ds = Bitmap.createScaledBitmap(bitmap, lw, lh, true);
- }
-
- // find width/height for smaller downsampled bitmap
- int sw = lw;
- int sh = lh;
- while (sw > 64 && sh > 64) {
- sw /= 2;
- sh /= 2;
- }
- if (sw != lw) {
- small_bm_ds = Bitmap.createScaledBitmap(large_bm_ds, sw, sh, true);
- }
-
- if (getParameters() != null) {
- int p = Math.max(getParameters().getValue(), getParameters().getMinimum()) % (getParameters().getMaximum() + 1);
- nativeApplyFilter(bitmap, w, h, large_bm_ds, lw, lh, small_bm_ds, sw, sh, p, mSeed);
- }
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
deleted file mode 100644
index 98497596b..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
-
-public class ImageFilterNegative extends ImageFilter {
- private static final String SERIALIZATION_NAME = "NEGATIVE";
- public ImageFilterNegative() {
- mName = "Negative";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterRepresentation representation = new FilterDirectRepresentation("Negative");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterNegative.class);
- representation.setTextId(R.string.negative);
- representation.setShowParameterValue(false);
- representation.setEditorId(ImageOnlyEditor.ID);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
-
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- nativeApplyFilter(bitmap, w, h);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
deleted file mode 100644
index 25e5d1476..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Path;
-import android.graphics.RectF;
-
-public class ImageFilterParametricBorder extends ImageFilter {
- private FilterColorBorderRepresentation mParameters = null;
-
- public ImageFilterParametricBorder() {
- mName = "Border";
- }
-
- public void useRepresentation(FilterRepresentation representation) {
- FilterColorBorderRepresentation parameters = (FilterColorBorderRepresentation) representation;
- mParameters = parameters;
- }
-
- public FilterColorBorderRepresentation getParameters() {
- return mParameters;
- }
-
- private void applyHelper(Canvas canvas, int w, int h) {
- if (getParameters() == null) {
- return;
- }
- Path border = new Path();
- border.moveTo(0, 0);
- float bs = getParameters().getBorderSize() / 100.0f * w;
- float r = getParameters().getBorderRadius() / 100.0f * w;
- border.lineTo(0, h);
- border.lineTo(w, h);
- border.lineTo(w, 0);
- border.lineTo(0, 0);
- border.addRoundRect(new RectF(bs, bs, w - bs, h - bs),
- r, r, Path.Direction.CW);
-
- Paint paint = new Paint();
- paint.setAntiAlias(true);
- paint.setColor(getParameters().getColor());
- canvas.drawPath(border, paint);
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- Canvas canvas = new Canvas(bitmap);
- applyHelper(canvas, bitmap.getWidth(), bitmap.getHeight());
- return bitmap;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
deleted file mode 100644
index 5695ef53e..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.support.v8.renderscript.*;
-import android.util.Log;
-import android.content.res.Resources;
-import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.pipeline.PipelineInterface;
-
-public abstract class ImageFilterRS extends ImageFilter {
- private static final String LOGTAG = "ImageFilterRS";
- private boolean DEBUG = false;
- private int mLastInputWidth = 0;
- private int mLastInputHeight = 0;
- private long mLastTimeCalled;
-
- public static boolean PERF_LOGGING = false;
-
- private static ScriptC_grey mGreyConvert = null;
- private static RenderScript mRScache = null;
-
- private volatile boolean mResourcesLoaded = false;
-
- protected abstract void createFilter(android.content.res.Resources res,
- float scaleFactor, int quality);
-
- protected void createFilter(android.content.res.Resources res,
- float scaleFactor, int quality, Allocation in) {}
- protected void bindScriptValues(Allocation in) {}
-
- protected abstract void runFilter();
-
- protected void update(Bitmap bitmap) {
- getOutPixelsAllocation().copyTo(bitmap);
- }
-
- protected RenderScript getRenderScriptContext() {
- PipelineInterface pipeline = getEnvironment().getPipeline();
- return pipeline.getRSContext();
- }
-
- protected Allocation getInPixelsAllocation() {
- PipelineInterface pipeline = getEnvironment().getPipeline();
- return pipeline.getInPixelsAllocation();
- }
-
- protected Allocation getOutPixelsAllocation() {
- PipelineInterface pipeline = getEnvironment().getPipeline();
- return pipeline.getOutPixelsAllocation();
- }
-
- @Override
- public void apply(Allocation in, Allocation out) {
- long startOverAll = System.nanoTime();
- if (PERF_LOGGING) {
- long delay = (startOverAll - mLastTimeCalled) / 1000;
- String msg = String.format("%s; image size %dx%d; ", getName(),
- in.getType().getX(), in.getType().getY());
- msg += String.format("called after %.2f ms (%.2f FPS); ",
- delay / 1000.f, 1000000.f / delay);
- Log.i(LOGTAG, msg);
- }
- mLastTimeCalled = startOverAll;
- long startFilter = 0;
- long endFilter = 0;
- if (!mResourcesLoaded) {
- PipelineInterface pipeline = getEnvironment().getPipeline();
- createFilter(pipeline.getResources(), getEnvironment().getScaleFactor(),
- getEnvironment().getQuality(), in);
- mResourcesLoaded = true;
- }
- startFilter = System.nanoTime();
- bindScriptValues(in);
- run(in, out);
- if (PERF_LOGGING) {
- getRenderScriptContext().finish();
- endFilter = System.nanoTime();
- long endOverAll = System.nanoTime();
- String msg = String.format("%s; image size %dx%d; ", getName(),
- in.getType().getX(), in.getType().getY());
- long timeOverAll = (endOverAll - startOverAll) / 1000;
- long timeFilter = (endFilter - startFilter) / 1000;
- msg += String.format("over all %.2f ms (%.2f FPS); ",
- timeOverAll / 1000.f, 1000000.f / timeOverAll);
- msg += String.format("run filter %.2f ms (%.2f FPS)",
- timeFilter / 1000.f, 1000000.f / timeFilter);
- Log.i(LOGTAG, msg);
- }
- }
-
- protected void run(Allocation in, Allocation out) {}
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) {
- return bitmap;
- }
- try {
- PipelineInterface pipeline = getEnvironment().getPipeline();
- if (DEBUG) {
- Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
- }
- Resources rsc = pipeline.getResources();
- boolean sizeChanged = false;
- if (getInPixelsAllocation() != null
- && ((getInPixelsAllocation().getType().getX() != mLastInputWidth)
- || (getInPixelsAllocation().getType().getY() != mLastInputHeight))) {
- sizeChanged = true;
- }
- if (pipeline.prepareRenderscriptAllocations(bitmap)
- || !isResourcesLoaded() || sizeChanged) {
- freeResources();
- createFilter(rsc, scaleFactor, quality);
- setResourcesLoaded(true);
- mLastInputWidth = getInPixelsAllocation().getType().getX();
- mLastInputHeight = getInPixelsAllocation().getType().getY();
- }
- bindScriptValues();
- runFilter();
- update(bitmap);
- if (DEBUG) {
- Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName());
- }
- } catch (android.renderscript.RSIllegalArgumentException e) {
- Log.e(LOGTAG, "Illegal argument? " + e);
- } catch (android.renderscript.RSRuntimeException e) {
- Log.e(LOGTAG, "RS runtime exception ? " + e);
- } catch (java.lang.OutOfMemoryError e) {
- // Many of the renderscript filters allocated large (>16Mb resources) in order to apply.
- System.gc();
- displayLowMemoryToast();
- Log.e(LOGTAG, "not enough memory for filter " + getName(), e);
- }
- return bitmap;
- }
-
- protected static Allocation convertBitmap(RenderScript RS, Bitmap bitmap) {
- return Allocation.createFromBitmap(RS, bitmap,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
- private static Allocation convertRGBAtoA(RenderScript RS, Bitmap bitmap) {
- if (RS != mRScache || mGreyConvert == null) {
- mGreyConvert = new ScriptC_grey(RS, RS.getApplicationContext().getResources(),
- R.raw.grey);
- mRScache = RS;
- }
-
- Type.Builder tb_a8 = new Type.Builder(RS, Element.A_8(RS));
-
- Allocation bitmapTemp = convertBitmap(RS, bitmap);
- if (bitmapTemp.getType().getElement().isCompatible(Element.A_8(RS))) {
- return bitmapTemp;
- }
-
- tb_a8.setX(bitmapTemp.getType().getX());
- tb_a8.setY(bitmapTemp.getType().getY());
- Allocation bitmapAlloc = Allocation.createTyped(RS, tb_a8.create(),
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE);
- mGreyConvert.forEach_RGBAtoA(bitmapTemp, bitmapAlloc);
- bitmapTemp.destroy();
- return bitmapAlloc;
- }
-
- public Allocation loadScaledResourceAlpha(int resource, int inSampleSize) {
- Resources res = getEnvironment().getPipeline().getResources();
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ALPHA_8;
- options.inSampleSize = inSampleSize;
- Bitmap bitmap = BitmapFactory.decodeResource(
- res,
- resource, options);
- Allocation ret = convertRGBAtoA(getRenderScriptContext(), bitmap);
- bitmap.recycle();
- return ret;
- }
-
- public Allocation loadScaledResourceAlpha(int resource, int w, int h, int inSampleSize) {
- Resources res = getEnvironment().getPipeline().getResources();
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ALPHA_8;
- options.inSampleSize = inSampleSize;
- Bitmap bitmap = BitmapFactory.decodeResource(
- res,
- resource, options);
- Bitmap resizeBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
- Allocation ret = convertRGBAtoA(getRenderScriptContext(), resizeBitmap);
- resizeBitmap.recycle();
- bitmap.recycle();
- return ret;
- }
-
- public Allocation loadResourceAlpha(int resource) {
- return loadScaledResourceAlpha(resource, 1);
- }
-
- public Allocation loadResource(int resource) {
- Resources res = getEnvironment().getPipeline().getResources();
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeResource(
- res,
- resource, options);
- Allocation ret = convertBitmap(getRenderScriptContext(), bitmap);
- bitmap.recycle();
- return ret;
- }
-
- private boolean isResourcesLoaded() {
- return mResourcesLoaded;
- }
-
- private void setResourcesLoaded(boolean resourcesLoaded) {
- mResourcesLoaded = resourcesLoaded;
- }
-
- /**
- * Bitmaps and RS Allocations should be cleared here
- */
- abstract protected void resetAllocations();
-
- /**
- * RS Script objects (and all other RS objects) should be cleared here
- */
- public abstract void resetScripts();
-
- /**
- * Scripts values should be bound here
- */
- abstract protected void bindScriptValues();
-
- public void freeResources() {
- if (!isResourcesLoaded()) {
- return;
- }
- resetAllocations();
- mLastInputWidth = 0;
- mLastInputHeight = 0;
- setResourcesLoaded(false);
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
deleted file mode 100644
index 511f9e90f..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Matrix;
-import android.graphics.RectF;
-
-import java.util.Vector;
-
-public class ImageFilterRedEye extends ImageFilter {
- private static final String LOGTAG = "ImageFilterRedEye";
- FilterRedEyeRepresentation mParameters = new FilterRedEyeRepresentation();
-
- public ImageFilterRedEye() {
- mName = "Red Eye";
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- return new FilterRedEyeRepresentation();
- }
-
- public boolean isNil() {
- return mParameters.isNil();
- }
-
- public Vector<FilterPoint> getCandidates() {
- return mParameters.getCandidates();
- }
-
- public void clear() {
- mParameters.clearCandidates();
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, short[] matrix);
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- FilterRedEyeRepresentation parameters = (FilterRedEyeRepresentation) representation;
- mParameters = parameters;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- short[] rect = new short[4];
-
- int size = mParameters.getNumberOfCandidates();
- Matrix originalToScreen = getOriginalToScreenMatrix(w, h);
- for (int i = 0; i < size; i++) {
- RectF r = new RectF(((RedEyeCandidate) (mParameters.getCandidate(i))).mRect);
- originalToScreen.mapRect(r);
- if (r.intersect(0, 0, w, h)) {
- rect[0] = (short) r.left;
- rect[1] = (short) r.top;
- rect[2] = (short) r.width();
- rect[3] = (short) r.height();
- nativeApplyFilter(bitmap, w, h, rect);
- }
- }
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java
deleted file mode 100644
index c3124ff77..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-import android.graphics.Bitmap;
-
-public class ImageFilterSaturated extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "SATURATED";
- public ImageFilterSaturated() {
- mName = "Saturated";
- }
-
- @Override
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Saturated");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterSaturated.class);
- representation.setTextId(R.string.saturation);
- representation.setMinimum(-100);
- representation.setMaximum(100);
- representation.setDefaultValue(0);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float saturation);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- int p = getParameters().getValue();
- float value = 1 + p / 100.0f;
- nativeApplyFilter(bitmap, w, h, value);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
deleted file mode 100644
index bd119bbc9..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-import android.graphics.Bitmap;
-
-public class ImageFilterShadows extends SimpleImageFilter {
- private static final String SERIALIZATION_NAME = "SHADOWS";
- public ImageFilterShadows() {
- mName = "Shadows";
-
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterBasicRepresentation representation =
- (FilterBasicRepresentation) super.getDefaultRepresentation();
- representation.setName("Shadows");
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setFilterClass(ImageFilterShadows.class);
- representation.setTextId(R.string.shadow_recovery);
- representation.setMinimum(-100);
- representation.setMaximum(100);
- representation.setDefaultValue(0);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float factor);
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null) {
- return bitmap;
- }
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- float p = getParameters().getValue();
-
- nativeApplyFilter(bitmap, w, h, p);
- return bitmap;
- }
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
deleted file mode 100644
index 3bd794464..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import com.android.gallery3d.R;
-
-public class ImageFilterSharpen extends ImageFilterRS {
- private static final String SERIALIZATION_NAME = "SHARPEN";
- private static final String LOGTAG = "ImageFilterSharpen";
- private ScriptC_convolve3x3 mScript;
-
- private FilterBasicRepresentation mParameters;
-
- public ImageFilterSharpen() {
- mName = "Sharpen";
- }
-
- public FilterRepresentation getDefaultRepresentation() {
- FilterRepresentation representation = new FilterBasicRepresentation("Sharpen", 0, 0, 100);
- representation.setSerializationName(SERIALIZATION_NAME);
- representation.setShowParameterValue(true);
- representation.setFilterClass(ImageFilterSharpen.class);
- representation.setTextId(R.string.sharpness);
- representation.setOverlayId(R.drawable.filtershow_button_colors_sharpen);
- representation.setEditorId(R.id.imageShow);
- representation.setSupportsPartialRendering(true);
- return representation;
- }
-
- public void useRepresentation(FilterRepresentation representation) {
- FilterBasicRepresentation parameters = (FilterBasicRepresentation) representation;
- mParameters = parameters;
- }
-
- @Override
- protected void resetAllocations() {
- // nothing to do
- }
-
- @Override
- public void resetScripts() {
- if (mScript != null) {
- mScript.destroy();
- mScript = null;
- }
- }
-
- @Override
- protected void createFilter(android.content.res.Resources res, float scaleFactor,
- int quality) {
- if (mScript == null) {
- mScript = new ScriptC_convolve3x3(getRenderScriptContext(), res, R.raw.convolve3x3);
- }
- }
-
- private void computeKernel() {
- float scaleFactor = getEnvironment().getScaleFactor();
- float p1 = mParameters.getValue() * scaleFactor;
- float value = p1 / 100.0f;
- float f[] = new float[9];
- float p = value;
- f[0] = -p;
- f[1] = -p;
- f[2] = -p;
- f[3] = -p;
- f[4] = 8 * p + 1;
- f[5] = -p;
- f[6] = -p;
- f[7] = -p;
- f[8] = -p;
- mScript.set_gCoeffs(f);
- }
-
- @Override
- protected void bindScriptValues() {
- int w = getInPixelsAllocation().getType().getX();
- int h = getInPixelsAllocation().getType().getY();
- mScript.set_gWidth(w);
- mScript.set_gHeight(h);
- }
-
- @Override
- protected void runFilter() {
- if (mParameters == null) {
- return;
- }
- computeKernel();
- mScript.set_gIn(getInPixelsAllocation());
- mScript.bind_gPixels(getInPixelsAllocation());
- mScript.forEach_root