From d167e2fccc895a59a31afe47233bb1766809ddfb Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Thu, 28 Feb 2013 12:11:35 -0800 Subject: Improves State panel and Refactor FilterShowActivity - handles multiple xml layout - add a portrait layout - improves the state panel (delete, etc.) Change-Id: I29762c99cdd467db8705174c660304c8ed673ce2 --- .../gallery3d/filtershow/FilterShowActivity.java | 323 +++++++++++---------- .../gallery3d/filtershow/ImageStateAdapter.java | 14 +- .../gallery3d/filtershow/MovableLinearLayout.java | 91 ++++++ .../gallery3d/filtershow/PanelController.java | 68 ++++- .../filtershow/imageshow/MasterImage.java | 1 + .../gallery3d/filtershow/presets/ImagePreset.java | 21 ++ .../gallery3d/filtershow/ui/FilterIconButton.java | 3 +- 7 files changed, 360 insertions(+), 161 deletions(-) create mode 100644 src/com/android/gallery3d/filtershow/MovableLinearLayout.java (limited to 'src/com') diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 34c5fe61f..146040274 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -116,11 +116,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, private View mSaveButton = null; - private ImageButton mFxButton = null; - private ImageButton mBorderButton = null; - private ImageButton mGeometryButton = null; - private ImageButton mColorsButton = null; - private EditorPlaceHolder mEditorPlaceHolder = new EditorPlaceHolder(this); private static final int SELECT_PICTURE = 1; @@ -145,35 +140,24 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, private FilterIconButton mNullBorderFilter; private int mIconSeedSize = 140; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ImageFilter.setActivityForMemoryToasts(this); - setResources(); - Resources res = getResources(); setupMasterImage(); - ImageFilterRS.setRenderScriptContext(this); + setDefaultValues(); + fillEditors(); - ImageShow.setDefaultBackgroundColor(res.getColor(R.color.background_screen)); - // TODO: get those values from XML. - ImageZoom.setZoomedSize(getPixelsFromDip(256)); - FramedTextButton.setTextSize((int) getPixelsFromDip(14)); - FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); - FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); - ImageShow.setTextSize((int) getPixelsFromDip(12)); - ImageShow.setTextPadding((int) getPixelsFromDip(10)); - ImageShow.setOriginalTextMargin((int) getPixelsFromDip(4)); - ImageShow.setOriginalTextSize((int) getPixelsFromDip(18)); - ImageShow.setOriginalText(res.getString(R.string.original_picture_text)); - mIconSeedSize = res.getDimensionPixelSize(R.dimen.thumbnail_size); + loadXML(); + setDefaultPreset(); - 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)); + processIntent(); + } + private void loadXML() { setContentView(R.layout.filtershow_activity); + ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.filtershow_actionbar); @@ -186,98 +170,89 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } }); - mImageLoader = new ImageLoader(this, getApplicationContext()); mImageShow = (ImageShow) findViewById(R.id.imageShow); mImageTinyPlanet = (ImageTinyPlanet) findViewById(R.id.imageTinyPlanet); - - ImageCrop.setAspectTextSize((int) getPixelsFromDip(18)); - ImageCrop.setTouchTolerance((int) getPixelsFromDip(25)); - ImageCrop.setMinCropSize((int) getPixelsFromDip(55)); mImageViews.add(mImageShow); mImageViews.add(mImageTinyPlanet); - mEditorPlaceHolder.setContainer((FrameLayout) findViewById(R.id.editorContainer)); - 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 EditorFlip()); - mEditorPlaceHolder.addEditor(new EditorRotate()); - mEditorPlaceHolder.addEditor(new EditorStraighten()); - EditorManager.addEditors(mEditorPlaceHolder); - mEditorPlaceHolder.setOldViews(mImageViews); - mEditorPlaceHolder.setImageLoader(mImageLoader); + setupEditors(); mEditorPlaceHolder.hide(); - mFxButton = (ImageButton) findViewById(R.id.fxButton); - mBorderButton = (ImageButton) findViewById(R.id.borderButton); - mGeometryButton = (ImageButton) findViewById(R.id.geometryButton); - mColorsButton = (ImageButton) findViewById(R.id.colorsButton); - mImageShow.setImageLoader(mImageLoader); mImageTinyPlanet.setImageLoader(mImageLoader); + mPanelController.clear(); mPanelController.setActivity(this); mPanelController.setEditorPlaceHolder(mEditorPlaceHolder); mPanelController.addImageView(findViewById(R.id.imageShow)); mPanelController.addImageView(findViewById(R.id.imageTinyPlanet)); - mPanelController.addPanel(mFxButton, findViewById(R.id.fxList), 0); - mPanelController.addPanel(mBorderButton, findViewById(R.id.bordersList), 1); - mPanelController.addPanel(mGeometryButton, findViewById(R.id.geometryList), 2); + mPanelController.addPanel(R.id.fxButton, R.id.fxList, 0); + mPanelController.addPanel(R.id.borderButton, R.id.bordersList, 1); + mPanelController.addPanel(R.id.geometryButton, R.id.geometryList, 2); + mPanelController.addPanel(R.id.colorsButton, R.id.colorsFxList, 3); - // TODO: move to a separate function. - GeometryMetadata geo = new GeometryMetadata(); - int[] editorsId = geo.getEditorIds(); - for (int i = 0; i < editorsId.length; i++) { - int editorId = editorsId[i]; - GeometryMetadata geometry = new GeometryMetadata(geo); - geometry.setEditorId(editorId); - EditorInfo editorInfo = (EditorInfo) mEditorPlaceHolder.getEditor(editorId); - geometry.setTextId(editorInfo.getTextId()); - geometry.setOverlayId(editorInfo.getOverlayId()); - geometry.setOverlayOnly(editorInfo.getOverlayOnly()); - setupFilterRepresentationButton( - geometry, (LinearLayout) findViewById(R.id.listGeometry), mGeometryButton); - } - - mPanelController.addPanel(mColorsButton, findViewById(R.id.colorsFxList), 3); - - Vector filtersRepresentations = new Vector(); - - FiltersManager filtersManager = FiltersManager.getManager(); - filtersManager.addEffects(filtersRepresentations); - - for (FilterRepresentation representation : filtersRepresentations) { - setupFilterRepresentationButton(representation, - (LinearLayout) findViewById(R.id.listColorsFx), mColorsButton); - } + fillFilters(); + fillGeometry(); + fillFx((LinearLayout) findViewById(R.id.listFilters), R.id.fxButton); + LoadBordersTask loadBorders = new LoadBordersTask((LinearLayout) findViewById(R.id.listBorders)); + loadBorders.execute(); mPanelController.addView(findViewById(R.id.applyEffect)); + findViewById(R.id.resetOperationsButton).setOnClickListener( createOnClickResetOperationsButton()); ListView operationsList = (ListView) findViewById(R.id.operationsList); operationsList.setAdapter(mMasterImage.getHistory()); operationsList.setOnItemClickListener(this); + ListView imageStateList = (ListView) findViewById(R.id.imageStateList); imageStateList.setAdapter(mMasterImage.getState()); mImageLoader.setAdapter(mMasterImage.getHistory()); - fillListImages((LinearLayout) findViewById(R.id.listFilters)); - LoadBordersTask loadBorders = new LoadBordersTask((LinearLayout) findViewById(R.id.listBorders)); - loadBorders.execute(); - mPanelController.setRowPanel(findViewById(R.id.secondRowPanel)); mPanelController.setUtilityPanel(this, findViewById(R.id.filterButtonsList), findViewById(R.id.panelAccessoryViewList), findViewById(R.id.applyEffect)); - mPanelController.setCurrentPanel(mFxButton); + mPanelController.setCurrentPanel(R.id.fxButton); + } + + private void fillFilters() { + Vector filtersRepresentations = new Vector(); + + FiltersManager filtersManager = FiltersManager.getManager(); + filtersManager.addEffects(filtersRepresentations); + + ImageButton colorsButton = (ImageButton) findViewById(R.id.colorsButton); + for (FilterRepresentation representation : filtersRepresentations) { + setupFilterRepresentationButton(representation, + (LinearLayout) findViewById(R.id.listColorsFx), colorsButton); + } + } + + private void fillGeometry() { + // TODO: move to a separate function. + GeometryMetadata geo = new GeometryMetadata(); + int[] editorsId = geo.getEditorIds(); + ImageButton geometryButton = (ImageButton) findViewById(R.id.geometryButton); + for (int i = 0; i < editorsId.length; i++) { + int editorId = editorsId[i]; + GeometryMetadata geometry = new GeometryMetadata(geo); + geometry.setEditorId(editorId); + EditorInfo editorInfo = (EditorInfo) mEditorPlaceHolder.getEditor(editorId); + geometry.setTextId(editorInfo.getTextId()); + geometry.setOverlayId(editorInfo.getOverlayId()); + geometry.setOverlayOnly(editorInfo.getOverlayOnly()); + setupFilterRepresentationButton( + geometry, (LinearLayout) findViewById(R.id.listGeometry), geometryButton); + } + } + + private void processIntent() { Intent intent = getIntent(); if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); @@ -327,6 +302,56 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } } + private void setupEditors() { + mEditorPlaceHolder.setContainer((FrameLayout) findViewById(R.id.editorContainer)); + EditorManager.addEditors(mEditorPlaceHolder); + mEditorPlaceHolder.setOldViews(mImageViews); + mEditorPlaceHolder.setImageLoader(mImageLoader); + } + + private void fillEditors() { + 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 EditorFlip()); + mEditorPlaceHolder.addEditor(new EditorRotate()); + mEditorPlaceHolder.addEditor(new EditorStraighten()); + } + + private void setDefaultValues() { + ImageFilter.setActivityForMemoryToasts(this); + ImageFilterRS.setRenderScriptContext(this); + + Resources res = getResources(); + ImageFilterBorder filterBorder = (ImageFilterBorder) FiltersManager.getManager().getFilter(ImageFilterBorder.class); + filterBorder.setResources(res); + + ImageShow.setDefaultBackgroundColor(res.getColor(R.color.background_screen)); + // TODO: get those values from XML. + ImageZoom.setZoomedSize(getPixelsFromDip(256)); + FramedTextButton.setTextSize((int) getPixelsFromDip(14)); + FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); + FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); + ImageShow.setTextSize((int) getPixelsFromDip(12)); + ImageShow.setTextPadding((int) getPixelsFromDip(10)); + ImageShow.setOriginalTextMargin((int) getPixelsFromDip(4)); + ImageShow.setOriginalTextSize((int) getPixelsFromDip(18)); + ImageShow.setOriginalText(res.getString(R.string.original_picture_text)); + mIconSeedSize = res.getDimensionPixelSize(R.dimen.thumbnail_size); + + 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)); + + ImageCrop.setAspectTextSize((int) getPixelsFromDip(18)); + ImageCrop.setTouchTolerance((int) getPixelsFromDip(25)); + ImageCrop.setMinCropSize((int) getPixelsFromDip(55)); + } + private void startLoadBitmap(Uri uri) { final View filters = findViewById(R.id.filtersPanel); final View loading = findViewById(R.id.loading); @@ -381,7 +406,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, if (i == 0) { filter.setName(getString(R.string.none)); } - FilterIconButton b = setupFilterRepresentationButton(filter, mList, mBorderButton); + ImageButton borderButton = (ImageButton) findViewById(R.id.borderButton); + FilterIconButton b = setupFilterRepresentationButton(filter, mList, borderButton); if (i == 0) { mNullBorderFilter = b; mNullBorderFilter.setSelected(true); @@ -448,42 +474,11 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, float previewScale = (float) largeBitmap.getWidth() / (float) mImageLoader.getOriginalBounds().width(); pipeline.setPreviewScaleFactor(previewScale); - Bitmap bmap = mImageLoader.getOriginalBitmapSmall(); - if (bmap != null && bmap.getWidth() > 0 && bmap.getHeight() > 0) { - float w = bmap.getWidth(); - float h = bmap.getHeight(); - float f = mIconSeedSize / Math.min(w, h); - w = w * f; - h = h * f; - bmap = Bitmap.createScaledBitmap(bmap, (int) w, (int) h, true); - - LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx); - int num_colors_buttons = listColors.getChildCount(); - for (int i = 0; i < num_colors_buttons; i++) { - FilterIconButton b = (FilterIconButton) listColors.getChildAt(i); - b.setIcon(bmap); - } - - LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters); - int num_filters_buttons = listFilters.getChildCount(); - for (int i = 0; i < num_filters_buttons; i++) { - FilterIconButton b = (FilterIconButton) listFilters.getChildAt(i); - b.setIcon(bmap); - } - - LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders); - int num_borders_buttons = listBorders.getChildCount(); - for (int i = 0; i < num_borders_buttons; i++) { - FilterIconButton b = (FilterIconButton) listBorders.getChildAt(i); - b.setIcon(bmap); - } - - } + fillButtonIcons(); MasterImage.getImage().setOriginalGeometry(largeBitmap); mLoadBitmapTask = null; if (mAction == CROP_ACTION) { - mPanelController.showComponent(findViewById(EditorCrop.ID)); } else if (mAction == TINY_PLANET_ACTION) { mPanelController.showComponent(findViewById(EditorTinyPlanet.ID)); @@ -494,6 +489,40 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } + private void fillButtonIcons() { + Bitmap bmap = mImageLoader.getOriginalBitmapSmall(); + if (bmap != null && bmap.getWidth() > 0 && bmap.getHeight() > 0) { + float w = bmap.getWidth(); + float h = bmap.getHeight(); + float f = mIconSeedSize / Math.min(w, h); + w = w * f; + h = h * f; + bmap = Bitmap.createScaledBitmap(bmap, (int) w, (int) h, true); + + LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx); + int num_colors_buttons = listColors.getChildCount(); + for (int i = 0; i < num_colors_buttons; i++) { + FilterIconButton b = (FilterIconButton) listColors.getChildAt(i); + b.setIcon(bmap); + } + + LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters); + int num_filters_buttons = listFilters.getChildCount(); + for (int i = 0; i < num_filters_buttons; i++) { + FilterIconButton b = (FilterIconButton) listFilters.getChildAt(i); + b.setIcon(bmap); + } + + LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders); + int num_borders_buttons = listBorders.getChildCount(); + for (int i = 0; i < num_borders_buttons; i++) { + FilterIconButton b = (FilterIconButton) listBorders.getChildAt(i); + b.setIcon(bmap); + } + + } + } + @Override protected void onDestroy() { if (mLoadBitmapTask != null) { @@ -711,7 +740,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, return icon; } - private void fillListImages(LinearLayout listFilters) { + private void fillFx(LinearLayout listFilters, int buttonId) { // TODO: use listview // TODO: load the filters straight from the filesystem @@ -742,9 +771,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, R.string.ffx_x_process }; - ImagePreset preset = new ImagePreset(getString(R.string.history_original)); // empty - preset.setImageLoader(mImageLoader); - BitmapFactory.Options o = new BitmapFactory.Options(); o.inScaled = false; @@ -755,21 +781,28 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, fxArray[p++] = fx; } + ImageButton button = (ImageButton) findViewById(buttonId); + FilterFxRepresentation nullFx = new FilterFxRepresentation(getString(R.string.none), 0, R.string.none); - mNullFxFilter = setupFilterRepresentationButton(nullFx, listFilters, mFxButton); + mNullFxFilter = setupFilterRepresentationButton(nullFx, listFilters, button); mNullFxFilter.setSelected(true); Vector filtersRepresentations = new Vector(); FiltersManager.getManager().addLooks(filtersRepresentations); for (FilterRepresentation representation : filtersRepresentations) { - setupFilterRepresentationButton(representation, listFilters, mFxButton); + setupFilterRepresentationButton(representation, listFilters, button); } for (int i = 0; i < p; i++) { - setupFilterRepresentationButton(fxArray[i], listFilters, mFxButton); + setupFilterRepresentationButton(fxArray[i], listFilters, button); } + } + public void setDefaultPreset() { // Default preset (original) + ImagePreset preset = new ImagePreset(getString(R.string.history_original)); // empty + preset.setImageLoader(mImageLoader); + mMasterImage.setPreset(preset, true); } @@ -799,7 +832,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } private void toggleImageStatePanel() { - final View view = findViewById(R.id.mainPanel); final View viewList = findViewById(R.id.imageStatePanel); if (mShowingHistoryPanel) { @@ -807,36 +839,12 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mShowingHistoryPanel = false; } - int translate = translateMainPanel(viewList); if (!mShowingImageStatePanel) { mShowingImageStatePanel = true; - if (PanelController.useAnimations()) { - view.animate().setDuration(200).x(translate) - .withLayer().withEndAction(new Runnable() { - @Override - public void run() { - viewList.setAlpha(0); - viewList.setVisibility(View.VISIBLE); - viewList.animate().setDuration(100) - .alpha(1.0f).start(); - } - }).start(); - } else { - view.setX(translate); - viewList.setAlpha(0); - viewList.setVisibility(View.VISIBLE); - viewList.animate().setDuration(100) - .alpha(1.0f).start(); - } + viewList.setVisibility(View.VISIBLE); } else { mShowingImageStatePanel = false; - viewList.setVisibility(View.INVISIBLE); - if (PanelController.useAnimations()) { - view.animate().setDuration(200).x(0).withLayer() - .start(); - } else { - view.setX(0); - } + viewList.setVisibility(View.GONE); } invalidateOptionsMenu(); } @@ -845,13 +853,19 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - setResources(); + setDefaultValues(); + loadXML(); + fillButtonIcons(); if (mShowingHistoryPanel) { toggleHistoryPanel(); } + final View loading = findViewById(R.id.loading); + loading.setVisibility(View.GONE); } public void setupMasterImage() { + mImageLoader = new ImageLoader(this, getApplicationContext()); + HistoryAdapter mHistoryAdapter = new HistoryAdapter( this, R.layout.filtershow_history_operation_row, R.id.rowTextView); @@ -943,6 +957,10 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } } + public PanelController getPanelController() { + return mPanelController; + } + public void cannotLoadImage() { CharSequence text = getString(R.string.cannot_load_image); Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); @@ -1084,11 +1102,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, finish(); } - private void setResources() { - ImageFilterBorder filterBorder = (ImageFilterBorder) FiltersManager.getManager().getFilter(ImageFilterBorder.class); - filterBorder.setResources(getResources()); - } - static { System.loadLibrary("jni_filtershow_filters"); } diff --git a/src/com/android/gallery3d/filtershow/ImageStateAdapter.java b/src/com/android/gallery3d/filtershow/ImageStateAdapter.java index a4a7a78f6..62633e26e 100644 --- a/src/com/android/gallery3d/filtershow/ImageStateAdapter.java +++ b/src/com/android/gallery3d/filtershow/ImageStateAdapter.java @@ -21,10 +21,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.ImageView; import android.widget.TextView; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.ImageFilter; +import com.android.gallery3d.filtershow.imageshow.MasterImage; public class ImageStateAdapter extends ArrayAdapter { private static final String LOGTAG = "ImageStateAdapter"; @@ -35,13 +38,20 @@ public class ImageStateAdapter extends ArrayAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { - View view = convertView; + MovableLinearLayout view = (MovableLinearLayout) convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.filtershow_imagestate_row, null); + view = (MovableLinearLayout) inflater.inflate(R.layout.filtershow_imagestate_row, null); } FilterRepresentation filter = getItem(position); + view.setFilterRepresentation(filter); + ImageView markView = (ImageView) view.findViewById(R.id.selectedMark); + if (filter == MasterImage.getImage().getCurrentFilterRepresentation()) { + markView.setVisibility(View.VISIBLE); + } else { + markView.setVisibility(View.INVISIBLE); + } if (filter != null) { TextView itemLabel = (TextView) view.findViewById(R.id.imagestate_label); itemLabel.setText(filter.getName()); diff --git a/src/com/android/gallery3d/filtershow/MovableLinearLayout.java b/src/com/android/gallery3d/filtershow/MovableLinearLayout.java new file mode 100644 index 000000000..9eddb41f1 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/MovableLinearLayout.java @@ -0,0 +1,91 @@ +/* + * 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; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.Point; +import android.util.AttributeSet; +import android.util.Log; +import android.view.MotionEvent; +import android.widget.LinearLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class MovableLinearLayout extends LinearLayout { + + private Point mTouchDown = new Point(); + private FilterRepresentation mFilterRepresentation; + private int mTouchSlope = 3; + private static final String LOGTAG = "MovableLinearLayout"; + + public MovableLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + private void resetView() { + setTranslationX(0); + mTouchDown.x = 0; + mTouchDown.y = 0; + setAlpha(1.0f); + setBackgroundResource(R.drawable.filtershow_button_background); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + int ex = (int) event.getX(); + int ey = (int) event.getY(); + if (event.getAction() == MotionEvent.ACTION_DOWN) { + mTouchDown.x = ex; + mTouchDown.y = ey; + FilterShowActivity activity = (FilterShowActivity) getContext(); + activity.getPanelController().showComponentWithRepresentation(mFilterRepresentation); + } + if (event.getAction() == MotionEvent.ACTION_MOVE) { + int delta = ex - mTouchDown.x; + if (delta > 0 && (delta - getTranslationX()) > mTouchSlope) { + setTranslationX(delta); + float alpha = (getWidth() - getTranslationX()) / getWidth(); + int backgroundColor = Color.argb((int) (1.0f - alpha * 255), 255, 0, 0); + setBackgroundColor(backgroundColor); + setAlpha(alpha); + } + } + if (event.getAction() == MotionEvent.ACTION_UP + || event.getAction() == MotionEvent.ACTION_CANCEL) { + if (getTranslationX() > getWidth() / 4) { + delete(mFilterRepresentation); + } else { + resetView(); + } + } + return true; + } + + private void delete(FilterRepresentation filterRepresentation) { + FilterShowActivity activity = (FilterShowActivity) getContext(); + activity.getPanelController().removeFilterRepresentation(filterRepresentation); + } + + public void setFilterRepresentation(FilterRepresentation filterRepresentation) { + mFilterRepresentation = filterRepresentation; + resetView(); + } + +} diff --git a/src/com/android/gallery3d/filtershow/PanelController.java b/src/com/android/gallery3d/filtershow/PanelController.java index 58aded671..3c4470ad0 100644 --- a/src/com/android/gallery3d/filtershow/PanelController.java +++ b/src/com/android/gallery3d/filtershow/PanelController.java @@ -24,6 +24,8 @@ import android.view.ViewPropertyAnimator; import android.widget.LinearLayout; import android.widget.TextView; +import android.util.Log; + import com.android.gallery3d.R; import com.android.gallery3d.filtershow.editors.Editor; import com.android.gallery3d.filtershow.editors.EditorTinyPlanet; @@ -36,6 +38,7 @@ import com.android.gallery3d.filtershow.presets.ImagePreset; import com.android.gallery3d.filtershow.ui.FilterIconButton; import java.util.HashMap; +import java.util.Set; import java.util.Vector; public class PanelController implements OnClickListener { @@ -264,6 +267,13 @@ public class PanelController implements OnClickListener { private FilterShowActivity mActivity = null; private EditorPlaceHolder mEditorPlaceHolder = null; + public void clear() { + mPanels.clear(); + mViews.clear(); + mFilters.clear(); + mImageViews.clear(); + } + public void setActivity(FilterShowActivity activity) { mActivity = activity; } @@ -273,7 +283,18 @@ public class PanelController implements OnClickListener { mViews.put(view, new ViewType(view, COMPONENT)); } - public void addPanel(View view, View container, int position) { + public View getViewFromId(int viewId) { + for (View view : mPanels.keySet()) { + if (view.getId() == viewId) { + return view; + } + } + return null; + } + + public void addPanel(int viewId, int containerId, int position) { + View view = mActivity.findViewById(viewId); + View container = mActivity.findViewById(containerId); mPanels.put(view, new Panel(view, container, position)); view.setOnClickListener(this); mViews.put(view, new ViewType(view, PANEL)); @@ -334,8 +355,8 @@ public class PanelController implements OnClickListener { mUtilityPanel.setShowParameter(s); } - public void setCurrentPanel(View panel) { - showPanel(panel); + public void setCurrentPanel(int panelId) { + showPanel(getViewFromId(panelId)); } public void setRowPanel(View rowPanel) { @@ -438,6 +459,30 @@ public class PanelController implements OnClickListener { mUtilityPanel.setEffectName(ename); } + public void removeFilterRepresentation(FilterRepresentation filterRepresentation) { + if (filterRepresentation == null) { + Log.v(LOGTAG, "RemoveFilterRepresentation: " + filterRepresentation); + return; + } + ImagePreset oldPreset = MasterImage.getImage().getPreset(); + ImagePreset copy = new ImagePreset(oldPreset); + copy.removeFilter(filterRepresentation); + MasterImage.getImage().setPreset(copy, true); + if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) { + FilterRepresentation lastRepresentation = copy.getLastRepresentation(); + MasterImage.getImage().setCurrentFilterRepresentation(lastRepresentation); + } + // Now let's reset the panel + if (mUtilityPanel == null || !mUtilityPanel.selected()) { + return; + } + showPanel(mCurrentPanel); + mCurrentImage.select(); + if (mCurrentEditor != null) { + mCurrentEditor.reflectCurrentFilter(); + } + } + public void useFilterRepresentation(FilterRepresentation filterRepresentation) { if (filterRepresentation == null) { return; @@ -461,6 +506,23 @@ public class PanelController implements OnClickListener { MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation); } + public void showComponentWithRepresentation(FilterRepresentation filterRepresentation) { + if (filterRepresentation == null) { + return; + } + Set views = mViews.keySet(); + for (View view : views) { + if (view instanceof FilterIconButton) { + FilterIconButton button = (FilterIconButton) view; + if (button.getFilterRepresentation().getFilterClass() == filterRepresentation.getFilterClass()) { + MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation); + showComponent(view); + return; + } + } + } + } + public void showComponent(View view) { boolean doPanelTransition = true; diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java index 8a505fd4e..2dd05aedf 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java +++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.Message; import android.util.Log; +import android.util.Log; import com.android.gallery3d.filtershow.FilterShowActivity; import com.android.gallery3d.filtershow.HistoryAdapter; import com.android.gallery3d.filtershow.ImageStateAdapter; diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java index 14c671e9f..82592a0f7 100644 --- a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java +++ b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java @@ -129,6 +129,9 @@ public class ImagePreset { } public void updateFilterRepresentation(FilterRepresentation representation) { + if (representation == null) { + return; + } synchronized (mFilters) { if (representation instanceof GeometryMetadata) { setGeometry((GeometryMetadata) representation); @@ -331,6 +334,23 @@ public class ImagePreset { Log.v(LOGTAG, "/// showFilters -- " + mFilters.size() + " filters"); } + public FilterRepresentation getLastRepresentation() { + if (mFilters.size() > 0) { + return mFilters.lastElement(); + } + return null; + } + + public void removeFilter(FilterRepresentation filterRepresentation) { + for (int i = 0; i < mFilters.size(); i++) { + if (mFilters.elementAt(i).getFilterClass() == filterRepresentation.getFilterClass()) { + mFilters.remove(i); + setHistoryName("Remove"); + return; + } + } + } + public void addFilter(FilterRepresentation representation) { if (representation instanceof GeometryMetadata) { setGeometry((GeometryMetadata) representation); @@ -501,4 +521,5 @@ public class ImagePreset { public Rect getPartialRenderingBounds() { return mPartialRenderingBounds; } + } diff --git a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java index 7893980bf..752fef0cd 100644 --- a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java +++ b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java @@ -122,6 +122,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener if (mOverlayOnly) { setIcon(mOverlayBitmap); } + stale_icon = true; invalidate(); } @@ -134,8 +135,8 @@ public class FilterIconButton extends IconButton implements View.OnClickListener if (mOverlayBitmap != null) { mIconBitmap = super.drawImage(mIconBitmap, mOverlayBitmap, mDestination); } - invalidate(); stale_icon = true; + invalidate(); } @Override -- cgit v1.2.3