FilterShowActivity.java revision 8965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4
1a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard/* 2a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Copyright (C) 2012 The Android Open Source Project 3a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * 4a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Licensed under the Apache License, Version 2.0 (the "License"); 5a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * you may not use this file except in compliance with the License. 6a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * You may obtain a copy of the License at 7a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * 8a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * http://www.apache.org/licenses/LICENSE-2.0 9a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * 10a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Unless required by applicable law or agreed to in writing, software 11a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * distributed under the License is distributed on an "AS IS" BASIS, 12a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * See the License for the specific language governing permissions and 14a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * limitations under the License. 15a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard */ 160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardpackage com.android.gallery3d.filtershow; 180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.annotation.TargetApi; 209594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroardimport android.app.ActionBar; 210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.app.Activity; 22ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescuimport android.app.ProgressDialog; 230ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.content.ContentValues; 240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.content.Intent; 25a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroardimport android.content.res.Configuration; 260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.content.res.Resources; 27457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hofordimport android.graphics.Bitmap; 28457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hofordimport android.graphics.BitmapFactory; 2993dfe7a1df07a64701369b480578410efb740a27nicolasroardimport android.graphics.Color; 30fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.graphics.Point; 310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.graphics.drawable.Drawable; 3292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.net.Uri; 333d4f2c7443f6f6015efab769bfaad19263137c67John Hofordimport android.os.AsyncTask; 3492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.os.Bundle; 35fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.util.DisplayMetrics; 360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.util.Log; 370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.util.TypedValue; 38fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.view.Display; 390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.Menu; 409594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroardimport android.view.MenuItem; 410d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.View; 420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.View.OnClickListener; 4398ba1a5eb757bb358d75b2f2e5d6fc4c11d805d9nicolasroardimport android.view.WindowManager; 440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.AdapterView; 450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.AdapterView.OnItemClickListener; 460d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.ImageButton; 470d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.LinearLayout; 480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.ListView; 4992e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.widget.SeekBar; 500ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.widget.ShareActionProvider; 510ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.widget.ShareActionProvider.OnShareTargetSelectedListener; 52e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroardimport android.widget.Toast; 530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 5492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.R; 550addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liuimport com.android.gallery3d.data.LocalAlbum; 5692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.cache.ImageLoader; 5792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilter; 5892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterBorder; 5967fefdb9b77644c955e1c0c5b1fcd51e2374f212John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterBwFilter; 60ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterContrast; 61ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterExposure; 62a19830b4fd9050b48386cd904d99cfd2566cc515John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterFx; 63ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterHue; 6493dfe7a1df07a64701369b480578410efb740a27nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder; 6592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterRS; 66ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterSaturated; 67ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterShadows; 682576a29cccf1d96edeef071914e8b775c230e8e8Sascha Haeberlingimport com.android.gallery3d.filtershow.filters.ImageFilterTinyPlanet; 69ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVibrance; 70ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVignette; 71ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterWBalance; 7292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageBorder; 73de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageCrop; 74de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageFlip; 75de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageRotate; 7692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageShow; 7708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallBorder; 7892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallFilter; 7992e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageStraighten; 802c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet; 81ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageWithIcon; 8292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageZoom; 8392e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.presets.ImagePreset; 8492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.provider.SharedImageProvider; 8592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.tools.SaveCopyTask; 867592704e662e49e4bbf3ba86a43d790774829bb0nicolasroardimport com.android.gallery3d.filtershow.ui.FramedTextButton; 875ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroardimport com.android.gallery3d.filtershow.ui.ImageButtonTitle; 8892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.ui.ImageCurves; 893992ae6cf1cbb7b57a22d8287c40451558408335nicolasroardimport com.android.gallery3d.filtershow.ui.Spline; 900addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liuimport com.android.gallery3d.util.GalleryUtils; 9192e2341248e99c691f38820503984bc5e2f18811nicolasroard 9292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.io.File; 93ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescuimport java.lang.ref.WeakReference; 9492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.util.Vector; 9592e2341248e99c691f38820503984bc5e2f18811nicolasroard 960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard@TargetApi(16) 970ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardpublic class FilterShowActivity extends Activity implements OnItemClickListener, 980ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard OnShareTargetSelectedListener { 990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1005aa454b3bde8b2162eb2b91400973113e2c63070Ruben Brunk public static final String CROP_ACTION = "com.android.camera.action.EDITOR_CROP"; 101a680a0c32ae3321c632288b36083f2782af2c55bDoris Liu public static final String TINY_PLANET_ACTION = "com.android.camera.action.TINY_PLANET"; 102a850a543225e9f7a72c5a49bb6099573c7efda13Bobby Georgescu public static final String LAUNCH_FULLSCREEN = "launch-fullscreen"; 10392e2341248e99c691f38820503984bc5e2f18811nicolasroard private final PanelController mPanelController = new PanelController(); 1040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageLoader mImageLoader = null; 1050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageShow mImageShow = null; 1060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageCurves mImageCurves = null; 1070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageBorder mImageBorders = null; 1080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageStraighten mImageStraighten = null; 1095448bf8095483574649afcc2add7f153670c7450nicolasroard private ImageZoom mImageZoom = null; 11062e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk private ImageCrop mImageCrop = null; 1118537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk private ImageRotate mImageRotate = null; 1128537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk private ImageFlip mImageFlip = null; 1132c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard private ImageTinyPlanet mImageTinyPlanet = null; 1140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private View mListFx = null; 1160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private View mListBorders = null; 1170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private View mListGeometry = null; 1180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private View mListColors = null; 11992e2341248e99c691f38820503984bc5e2f18811nicolasroard private View mListFilterButtons = null; 120bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu private View mSaveButton = null; 1210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageButton mFxButton = null; 1230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageButton mBorderButton = null; 1240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageButton mGeometryButton = null; 1250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private ImageButton mColorsButton = null; 1260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 12708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard private ImageSmallFilter mCurrentImageSmallFilter = null; 1280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private static final int SELECT_PICTURE = 1; 1290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private static final String LOGTAG = "FilterShowActivity"; 13092e2341248e99c691f38820503984bc5e2f18811nicolasroard protected static final boolean ANIMATE_PANELS = true; 131f129cb70f4d2b43a147b399d91650414defa6dd9nicolasroard private static int mImageBorderSize = 4; // in percent 1320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private boolean mShowingHistoryPanel = false; 134bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard private boolean mShowingImageStatePanel = false; 135bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 13692e2341248e99c691f38820503984bc5e2f18811nicolasroard private final Vector<ImageShow> mImageViews = new Vector<ImageShow>(); 13792e2341248e99c691f38820503984bc5e2f18811nicolasroard private final Vector<View> mListViews = new Vector<View>(); 13892e2341248e99c691f38820503984bc5e2f18811nicolasroard private final Vector<ImageButton> mBottomPanelButtons = new Vector<ImageButton>(); 1390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1400ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard private ShareActionProvider mShareActionProvider; 1410ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard private File mSharedOutputFile = null; 1420ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 1430ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard private boolean mSharingImage = false; 1440ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 145ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu private WeakReference<ProgressDialog> mSavingProgressDialog; 1463038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford private static final int SEEK_BAR_MAX = 600; 14755550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard 148d49d53206a197b08ec4754d8751b6860e33d9f48John Reck private LoadBitmapTask mLoadBitmapTask; 149af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford private ImageSmallFilter mNullFxFilter; 150af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford private ImageSmallFilter mNullBorderFilter; 1513d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 1520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard @Override 1530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void onCreate(Bundle savedInstanceState) { 1540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard super.onCreate(savedInstanceState); 1550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1565448bf8095483574649afcc2add7f153670c7450nicolasroard ImageFilterRS.setRenderScriptContext(this); 1575448bf8095483574649afcc2add7f153670c7450nicolasroard 15895404c666640177abf72ca2278585a16f30cf390nicolasroard ImageShow.setDefaultBackgroundColor(getResources().getColor(R.color.background_screen)); 1598965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk ImageSmallFilter.setDefaultBackgroundColor(getResources().getColor( 1608965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk R.color.background_main_toolbar)); 1615ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard // TODO: get those values from XML. 1622f8301760867dc269c90bbeb338495f80e841c08nicolasroard ImageZoom.setZoomedSize(getPixelsFromDip(256)); 1637592704e662e49e4bbf3ba86a43d790774829bb0nicolasroard FramedTextButton.setTextSize((int) getPixelsFromDip(14)); 164f675cd16e8188a8d0b3a34dbc1a74c40ed36eb1enicolasroard FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); 165f675cd16e8188a8d0b3a34dbc1a74c40ed36eb1enicolasroard FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); 1665ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard ImageShow.setTextSize((int) getPixelsFromDip(12)); 1675ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard ImageShow.setTextPadding((int) getPixelsFromDip(10)); 168f7403a58d17e56de6e3bebd9ac08bc77f3cd43e4nicolasroard ImageShow.setOriginalTextMargin((int) getPixelsFromDip(4)); 169f7403a58d17e56de6e3bebd9ac08bc77f3cd43e4nicolasroard ImageShow.setOriginalTextSize((int) getPixelsFromDip(18)); 170f7403a58d17e56de6e3bebd9ac08bc77f3cd43e4nicolasroard ImageShow.setOriginalText(getResources().getString(R.string.original_picture_text)); 1715ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard ImageButtonTitle.setTextSize((int) getPixelsFromDip(12)); 1725ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard ImageButtonTitle.setTextPadding((int) getPixelsFromDip(10)); 17395404c666640177abf72ca2278585a16f30cf390nicolasroard ImageSmallFilter.setMargin((int) getPixelsFromDip(3)); 1745ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard ImageSmallFilter.setTextMargin((int) getPixelsFromDip(4)); 175c5590eb1a20b112e67e4c43684790587f844fc6bnicolasroard Drawable curveHandle = getResources().getDrawable(R.drawable.camera_crop); 1763992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard int curveHandleSize = (int) getResources().getDimension(R.dimen.crop_indicator_size); 1773992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard Spline.setCurveHandle(curveHandle, curveHandleSize); 1783992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard Spline.setCurveWidth((int) getPixelsFromDip(3)); 1795ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard 1800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard setContentView(R.layout.filtershow_activity); 1819594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard ActionBar actionBar = getActionBar(); 182786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 183786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard actionBar.setCustomView(R.layout.filtershow_actionbar); 184786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard 185bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu mSaveButton = actionBar.getCustomView(); 186bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu mSaveButton.setOnClickListener(new OnClickListener() { 187786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard @Override 188786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard public void onClick(View view) { 189786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard saveImage(); 190786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard } 191786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard }); 1920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 193e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard mImageLoader = new ImageLoader(this, getApplicationContext()); 1940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters); 1960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders); 197ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx); 1980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 1990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageShow = (ImageShow) findViewById(R.id.imageShow); 2000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageCurves = (ImageCurves) findViewById(R.id.imageCurves); 2010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageBorders = (ImageBorder) findViewById(R.id.imageBorder); 2020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten); 2035448bf8095483574649afcc2add7f153670c7450nicolasroard mImageZoom = (ImageZoom) findViewById(R.id.imageZoom); 20462e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mImageCrop = (ImageCrop) findViewById(R.id.imageCrop); 2058537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageRotate = (ImageRotate) findViewById(R.id.imageRotate); 2068537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageFlip = (ImageFlip) findViewById(R.id.imageFlip); 2072c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mImageTinyPlanet = (ImageTinyPlanet) findViewById(R.id.imageTinyPlanet); 2080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 2095d834ce0c65f89cf3f249f586b360c1a6d7ab99bRuben Brunk mImageCrop.setAspectTextSize((int) getPixelsFromDip(18)); 210f46da69aefd9afe0b4326a2fcea8e33c294136bbRuben Brunk ImageCrop.setTouchTolerance((int) getPixelsFromDip(25)); 2116e2dd284681a716c55e0937ef2e15a1c7507a1b2Ruben Brunk ImageCrop.setMinCropSize((int) getPixelsFromDip(55)); 2120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageViews.add(mImageShow); 2130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageViews.add(mImageCurves); 2140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageViews.add(mImageBorders); 2150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageViews.add(mImageStraighten); 2165448bf8095483574649afcc2add7f153670c7450nicolasroard mImageViews.add(mImageZoom); 21762e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mImageViews.add(mImageCrop); 2188537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageViews.add(mImageRotate); 2198537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageViews.add(mImageFlip); 2202c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mImageViews.add(mImageTinyPlanet); 2210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 2220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListFx = findViewById(R.id.fxList); 2230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListBorders = findViewById(R.id.bordersList); 22492e2341248e99c691f38820503984bc5e2f18811nicolasroard mListGeometry = findViewById(R.id.geometryList); 22592e2341248e99c691f38820503984bc5e2f18811nicolasroard mListFilterButtons = findViewById(R.id.filterButtonsList); 2260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListColors = findViewById(R.id.colorsFxList); 2270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListViews.add(mListFx); 2280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListViews.add(mListBorders); 2290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListViews.add(mListGeometry); 23092e2341248e99c691f38820503984bc5e2f18811nicolasroard mListViews.add(mListFilterButtons); 2310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mListViews.add(mListColors); 2320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 2330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mFxButton = (ImageButton) findViewById(R.id.fxButton); 2340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mBorderButton = (ImageButton) findViewById(R.id.borderButton); 2350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mGeometryButton = (ImageButton) findViewById(R.id.geometryButton); 2360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mColorsButton = (ImageButton) findViewById(R.id.colorsButton); 23792e2341248e99c691f38820503984bc5e2f18811nicolasroard 23892e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageShow.setImageLoader(mImageLoader); 23992e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageCurves.setImageLoader(mImageLoader); 24092e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageCurves.setMaster(mImageShow); 24192e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageBorders.setImageLoader(mImageLoader); 24292e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageBorders.setMaster(mImageShow); 24392e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageStraighten.setImageLoader(mImageLoader); 24492e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageStraighten.setMaster(mImageShow); 24592e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageZoom.setImageLoader(mImageLoader); 24692e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageZoom.setMaster(mImageShow); 24762e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mImageCrop.setImageLoader(mImageLoader); 24862e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mImageCrop.setMaster(mImageShow); 2498537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageRotate.setImageLoader(mImageLoader); 2508537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageRotate.setMaster(mImageShow); 2518537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageFlip.setImageLoader(mImageLoader); 2528537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mImageFlip.setMaster(mImageShow); 2532c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mImageTinyPlanet.setImageLoader(mImageLoader); 2542c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mImageTinyPlanet.setMaster(mImageShow); 25592e2341248e99c691f38820503984bc5e2f18811nicolasroard 25698ba1a5eb757bb358d75b2f2e5d6fc4c11d805d9nicolasroard mPanelController.setActivity(this); 25798ba1a5eb757bb358d75b2f2e5d6fc4c11d805d9nicolasroard 25892e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addImageView(findViewById(R.id.imageShow)); 25992e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addImageView(findViewById(R.id.imageCurves)); 26092e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addImageView(findViewById(R.id.imageBorder)); 26192e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addImageView(findViewById(R.id.imageStraighten)); 26262e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mPanelController.addImageView(findViewById(R.id.imageCrop)); 2638537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mPanelController.addImageView(findViewById(R.id.imageRotate)); 2648537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mPanelController.addImageView(findViewById(R.id.imageFlip)); 26592e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addImageView(findViewById(R.id.imageZoom)); 2662c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mPanelController.addImageView(findViewById(R.id.imageTinyPlanet)); 26792e2341248e99c691f38820503984bc5e2f18811nicolasroard 26892e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addPanel(mFxButton, mListFx, 0); 26992e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addPanel(mBorderButton, mListBorders, 1); 27092e2341248e99c691f38820503984bc5e2f18811nicolasroard 27192e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addPanel(mGeometryButton, mListGeometry, 2); 27292e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton)); 27362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton)); 27492e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton)); 27592e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton)); 27692e2341248e99c691f38820503984bc5e2f18811nicolasroard 27792e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addPanel(mColorsButton, mListColors, 3); 278ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 2790f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk int[] recastIDs = { 2802576a29cccf1d96edeef071914e8b775c230e8e8Sascha Haeberling R.id.tinyplanetButton, 281ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.vignetteButton, 282ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.vibranceButton, 283ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.contrastButton, 284ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.saturationButton, 28567fefdb9b77644c955e1c0c5b1fcd51e2374f212John Hoford R.id.bwfilterButton, 286ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.wbalanceButton, 287ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.hueButton, 288ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.exposureButton, 289ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.shadowRecoveryButton 290ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 2910f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk ImageFilter[] filters = { 2922576a29cccf1d96edeef071914e8b775c230e8e8Sascha Haeberling new ImageFilterTinyPlanet(), 293ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterVignette(), 294ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterVibrance(), 295ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterContrast(), 296ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterSaturated(), 29767fefdb9b77644c955e1c0c5b1fcd51e2374f212John Hoford new ImageFilterBwFilter(), 298ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterWBalance(), 299ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterHue(), 300ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterExposure(), 301ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford new ImageFilterShadows() 302ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 303ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 304ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford for (int i = 0; i < filters.length; i++) { 305ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford ImageSmallFilter fView = new ImageSmallFilter(this); 306ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford View v = listColors.findViewById(recastIDs[i]); 307ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford int pos = listColors.indexOfChild(v); 308ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford listColors.removeView(v); 309ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 3102f879102d630815df64636b8d37e3a7eea8e8b65Sascha Haeberling filters[i].setParameter(filters[i].getPreviewParameter()); 311a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard if (v instanceof ImageButtonTitle) 31243b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk filters[i].setName(((ImageButtonTitle) v).getText()); 313ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setImageFilter(filters[i]); 314ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setController(this); 315ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setImageLoader(mImageLoader); 316ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setId(recastIDs[i]); 317ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford mPanelController.addComponent(mColorsButton, fView); 3180f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk listColors.addView(fView, pos); 319ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford } 320ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 3210f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk int[] overlayIDs = { 322ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.sharpenButton, 323ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.id.curvesButtonRGB 324ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 3250f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk int[] overlayBitmaps = { 326ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.drawable.filtershow_button_colors_sharpen, 327ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.drawable.filtershow_button_colors_curve 328ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 329a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard int[] overlayNames = { 33043b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.sharpness, 331ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford R.string.curvesRGB 332ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 333ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 3340f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk for (int i = 0; i < overlayIDs.length; i++) { 335ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford ImageWithIcon fView = new ImageWithIcon(this); 336ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford View v = listColors.findViewById(overlayIDs[i]); 337ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford int pos = listColors.indexOfChild(v); 338ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford listColors.removeView(v); 3390f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk final int sid = overlayNames[i]; 3400f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk ImageFilterExposure efilter = new ImageFilterExposure() { 341ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford { 342ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford mName = getString(sid); 343ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford } 344ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford }; 345ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford efilter.setParameter(-300); 346ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford Bitmap bitmap = BitmapFactory.decodeResource(getResources(), 3470f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk overlayBitmaps[i]); 348ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 349ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setIcon(bitmap); 350ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setImageFilter(efilter); 351ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setController(this); 352ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setImageLoader(mImageLoader); 353ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford fView.setId(overlayIDs[i]); 354ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford mPanelController.addComponent(mColorsButton, fView); 3550f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk listColors.addView(fView, pos); 356ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford } 357ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford 35892e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.addView(findViewById(R.id.applyEffect)); 3593992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard mPanelController.addView(findViewById(R.id.pickCurvesChannel)); 3600f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk mPanelController.addView(findViewById(R.id.aspect)); 3610d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard findViewById(R.id.resetOperationsButton).setOnClickListener( 3620d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard createOnClickResetOperationsButton()); 3630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 3640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard ListView operationsList = (ListView) findViewById(R.id.operationsList); 365d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard operationsList.setAdapter(mImageShow.getHistory()); 3660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard operationsList.setOnItemClickListener(this); 367bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard ListView imageStateList = (ListView) findViewById(R.id.imageStateList); 368bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard imageStateList.setAdapter(mImageShow.getImageStateAdapter()); 369d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard mImageLoader.setAdapter(mImageShow.getHistory()); 3700d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 3710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard fillListImages(listFilters); 3720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard fillListBorders(listBorders); 3730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 37492e2341248e99c691f38820503984bc5e2f18811nicolasroard SeekBar seekBar = (SeekBar) findViewById(R.id.filterSeekBar); 3753038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford seekBar.setMax(SEEK_BAR_MAX); 3763038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford 37792e2341248e99c691f38820503984bc5e2f18811nicolasroard mImageShow.setSeekBar(seekBar); 378de154778c8f94121cb2117fcf6224c40c01b6132nicolasroard mImageZoom.setSeekBar(seekBar); 3792c6ea941a80ea22317d664e329aed51f5f7417b9nicolasroard mImageTinyPlanet.setSeekBar(seekBar); 38092e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.setRowPanel(findViewById(R.id.secondRowPanel)); 3818537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk mPanelController.setUtilityPanel(this, findViewById(R.id.filterButtonsList), 38233e58a68ee1d4866169d41b7d88c6eff0c70dae0nicolasroard findViewById(R.id.applyEffect), findViewById(R.id.aspect), 38333e58a68ee1d4866169d41b7d88c6eff0c70dae0nicolasroard findViewById(R.id.pickCurvesChannel)); 38492e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.setMasterImage(mImageShow); 38592e2341248e99c691f38820503984bc5e2f18811nicolasroard mPanelController.setCurrentPanel(mFxButton); 3860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard Intent intent = getIntent(); 387a850a543225e9f7a72c5a49bb6099573c7efda13Bobby Georgescu if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) { 388a850a543225e9f7a72c5a49bb6099573c7efda13Bobby Georgescu getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 389a850a543225e9f7a72c5a49bb6099573c7efda13Bobby Georgescu } 390a850a543225e9f7a72c5a49bb6099573c7efda13Bobby Georgescu 391d49d53206a197b08ec4754d8751b6860e33d9f48John Reck if (intent.getData() != null) { 392d49d53206a197b08ec4754d8751b6860e33d9f48John Reck startLoadBitmap(intent.getData()); 3930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } else { 3940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard pickImage(); 3950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 39663926d2ed2ca2921de8dca9b3a52c1d64d8afc46Ruben Brunk 39763926d2ed2ca2921de8dca9b3a52c1d64d8afc46Ruben Brunk String action = intent.getAction(); 398a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard if (action.equalsIgnoreCase(CROP_ACTION)) { 39963926d2ed2ca2921de8dca9b3a52c1d64d8afc46Ruben Brunk mPanelController.showComponent(findViewById(R.id.cropButton)); 400a680a0c32ae3321c632288b36083f2782af2c55bDoris Liu } else if (action.equalsIgnoreCase(TINY_PLANET_ACTION)) { 401a680a0c32ae3321c632288b36083f2782af2c55bDoris Liu mPanelController.showComponent(findViewById(R.id.tinyplanetButton)); 40263926d2ed2ca2921de8dca9b3a52c1d64d8afc46Ruben Brunk } 4030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 4040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 405d49d53206a197b08ec4754d8751b6860e33d9f48John Reck private void startLoadBitmap(Uri uri) { 40600914f56c3390caa224b1c9fc07624665de40113John Reck final View filters = findViewById(R.id.filtersPanel); 40700914f56c3390caa224b1c9fc07624665de40113John Reck final View loading = findViewById(R.id.loading); 40800914f56c3390caa224b1c9fc07624665de40113John Reck loading.setVisibility(View.VISIBLE); 40900914f56c3390caa224b1c9fc07624665de40113John Reck filters.setVisibility(View.INVISIBLE); 410d49d53206a197b08ec4754d8751b6860e33d9f48John Reck View tinyPlanetView = findViewById(R.id.tinyplanetButton); 411d49d53206a197b08ec4754d8751b6860e33d9f48John Reck if (tinyPlanetView != null) { 412d49d53206a197b08ec4754d8751b6860e33d9f48John Reck tinyPlanetView.setVisibility(View.GONE); 413d49d53206a197b08ec4754d8751b6860e33d9f48John Reck } 414d49d53206a197b08ec4754d8751b6860e33d9f48John Reck mLoadBitmapTask = new LoadBitmapTask(tinyPlanetView); 415d49d53206a197b08ec4754d8751b6860e33d9f48John Reck mLoadBitmapTask.execute(uri); 416d49d53206a197b08ec4754d8751b6860e33d9f48John Reck } 417d49d53206a197b08ec4754d8751b6860e33d9f48John Reck 4188965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> { 4193d4f2c7443f6f6015efab769bfaad19263137c67John Hoford View mTinyPlanetButton; 420d49d53206a197b08ec4754d8751b6860e33d9f48John Reck int mBitmapSize; 4213d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 422d49d53206a197b08ec4754d8751b6860e33d9f48John Reck public LoadBitmapTask(View button) { 4233d4f2c7443f6f6015efab769bfaad19263137c67John Hoford mTinyPlanetButton = button; 424d49d53206a197b08ec4754d8751b6860e33d9f48John Reck mBitmapSize = getScreenImageSize(); 4253d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4263d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 4273d4f2c7443f6f6015efab769bfaad19263137c67John Hoford @Override 428d49d53206a197b08ec4754d8751b6860e33d9f48John Reck protected Boolean doInBackground(Uri... params) { 4298965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk if (!mImageLoader.loadBitmap(params[0], mBitmapSize)) { 4308965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk return false; 4318965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk } 4328965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk publishProgress(mImageLoader.queryLightCycle360()); 4338965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk return true; 4343d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4353d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 4363d4f2c7443f6f6015efab769bfaad19263137c67John Hoford @Override 4378965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk protected void onProgressUpdate(Boolean... values) { 43800914f56c3390caa224b1c9fc07624665de40113John Reck super.onProgressUpdate(values); 4398965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk if (isCancelled()) 4408965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk return; 44100914f56c3390caa224b1c9fc07624665de40113John Reck final View filters = findViewById(R.id.filtersPanel); 44200914f56c3390caa224b1c9fc07624665de40113John Reck final View loading = findViewById(R.id.loading); 44300914f56c3390caa224b1c9fc07624665de40113John Reck loading.setVisibility(View.GONE); 44400914f56c3390caa224b1c9fc07624665de40113John Reck filters.setVisibility(View.VISIBLE); 4458965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk if (values[0]) { 4468965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk mTinyPlanetButton.setVisibility(View.VISIBLE); 4478965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk } 44800914f56c3390caa224b1c9fc07624665de40113John Reck } 44900914f56c3390caa224b1c9fc07624665de40113John Reck 45000914f56c3390caa224b1c9fc07624665de40113John Reck @Override 4513d4f2c7443f6f6015efab769bfaad19263137c67John Hoford protected void onPostExecute(Boolean result) { 4523d4f2c7443f6f6015efab769bfaad19263137c67John Hoford if (isCancelled()) { 4533d4f2c7443f6f6015efab769bfaad19263137c67John Hoford return; 4543d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4558965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk if (!result) { 4568965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk cannotLoadImage(); 4573d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4588965d1f4c2d437e0a0ad4fd225ea2cad9d2471c4Ruben Brunk 459d49d53206a197b08ec4754d8751b6860e33d9f48John Reck mLoadBitmapTask = null; 4603d4f2c7443f6f6015efab769bfaad19263137c67John Hoford super.onPostExecute(result); 4613d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4623d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 4633d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4643d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 4653d4f2c7443f6f6015efab769bfaad19263137c67John Hoford @Override 4663d4f2c7443f6f6015efab769bfaad19263137c67John Hoford protected void onDestroy() { 467d49d53206a197b08ec4754d8751b6860e33d9f48John Reck if (mLoadBitmapTask != null) { 468d49d53206a197b08ec4754d8751b6860e33d9f48John Reck mLoadBitmapTask.cancel(false); 4693d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4703d4f2c7443f6f6015efab769bfaad19263137c67John Hoford super.onDestroy(); 4713d4f2c7443f6f6015efab769bfaad19263137c67John Hoford } 4723d4f2c7443f6f6015efab769bfaad19263137c67John Hoford 4734d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard private int translateMainPanel(View viewPanel) { 4744d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int accessoryPanelWidth = viewPanel.getWidth(); 4754d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int mainViewWidth = findViewById(R.id.mainView).getWidth(); 4764d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int mainPanelWidth = mImageShow.getDisplayedImageBounds().width(); 477f0eb72eab7be3183417deff6dadb4937b90b9e59nicolasroard if (mainPanelWidth == 0) { 478f0eb72eab7be3183417deff6dadb4937b90b9e59nicolasroard mainPanelWidth = mainViewWidth; 479f0eb72eab7be3183417deff6dadb4937b90b9e59nicolasroard } 480cd84d67629075795d4c5c28d980f77ff8d75c593nicolasroard int filtersPanelWidth = findViewById(R.id.filtersPanel).getWidth(); 481cd84d67629075795d4c5c28d980f77ff8d75c593nicolasroard if (mainPanelWidth < filtersPanelWidth) { 482cd84d67629075795d4c5c28d980f77ff8d75c593nicolasroard mainPanelWidth = filtersPanelWidth; 483cd84d67629075795d4c5c28d980f77ff8d75c593nicolasroard } 4844d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int leftOver = mainViewWidth - mainPanelWidth - accessoryPanelWidth; 4854d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard if (leftOver < 0) { 4864d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard return -accessoryPanelWidth; 4874d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard } 4884d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard return 0; 4894d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard } 4904d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard 4910f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk private int getScreenImageSize() { 4920f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk DisplayMetrics metrics = new DisplayMetrics(); 493fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford Display display = getWindowManager().getDefaultDisplay(); 4940f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk Point size = new Point(); 495fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford display.getSize(size); 496fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford display.getMetrics(metrics); 497fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford int msize = Math.min(size.x, size.y); 4980f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk return (133 * msize) / metrics.densityDpi; 499fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford } 500fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford 5010addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu private void showSavingProgress(String albumName) { 502ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu ProgressDialog progress; 503ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu if (mSavingProgressDialog != null) { 504ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu progress = mSavingProgressDialog.get(); 505ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu if (progress != null) { 506ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu progress.show(); 507ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu return; 508ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu } 509ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu } 510ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu // TODO: Allow cancellation of the saving process 5110addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu String progressText; 5120addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu if (albumName == null) { 5130addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu progressText = getString(R.string.saving_image); 5140addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu } else { 5150addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu progressText = getString(R.string.filtershow_saving_image, albumName); 5160addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu } 5170addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu progress = ProgressDialog.show(this, "", progressText, true, false); 518ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu mSavingProgressDialog = new WeakReference<ProgressDialog>(progress); 519ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu } 520ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu 521ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu private void hideSavingProgress() { 522ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu if (mSavingProgressDialog != null) { 523ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu ProgressDialog progress = mSavingProgressDialog.get(); 52408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard if (progress != null) 52508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard progress.dismiss(); 526ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu } 527ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu } 528ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu 5290ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard public void completeSaveImage(Uri saveUri) { 5300ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard if (mSharingImage && mSharedOutputFile != null) { 5310ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard // Image saved, we unblock the content provider 5320ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, 5330ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri.encode(mSharedOutputFile.getAbsolutePath())); 5340ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard ContentValues values = new ContentValues(); 5350ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard values.put(SharedImageProvider.PREPARE, false); 5360ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard getContentResolver().insert(uri, values); 5370ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard } 5380ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard setResult(RESULT_OK, new Intent().setData(saveUri)); 539ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu hideSavingProgress(); 5400ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard finish(); 5410ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard } 5420ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 5430ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard @Override 5440ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) { 54592e2341248e99c691f38820503984bc5e2f18811nicolasroard // First, let's tell the SharedImageProvider that it will need to wait 54692e2341248e99c691f38820503984bc5e2f18811nicolasroard // for the image 5470ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, 5480ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri.encode(mSharedOutputFile.getAbsolutePath())); 5490ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard ContentValues values = new ContentValues(); 5500ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard values.put(SharedImageProvider.PREPARE, true); 5510ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard getContentResolver().insert(uri, values); 5520ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mSharingImage = true; 5530ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 5540ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard // Process and save the image in the background. 5550addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu showSavingProgress(null); 5560ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mImageShow.saveImage(this, mSharedOutputFile); 5570ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard return true; 5580ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard } 5590ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 5600ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard private Intent getDefaultShareIntent() { 5610ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Intent intent = new Intent(Intent.ACTION_SEND); 5620ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 5630ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 5640ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard intent.setType(SharedImageProvider.MIME_TYPE); 5650ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mSharedOutputFile = SaveCopyTask.getNewFile(this, mImageLoader.getUri()); 5660ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, 5670ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard Uri.encode(mSharedOutputFile.getAbsolutePath())); 5680ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard intent.putExtra(Intent.EXTRA_STREAM, uri); 5690ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard return intent; 5700ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard } 5710ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard 5729594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard @Override 5739594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard public boolean onCreateOptionsMenu(Menu menu) { 5749594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu); 575bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard MenuItem showHistory = menu.findItem(R.id.operationsButton); 5769594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard if (mShowingHistoryPanel) { 577bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard showHistory.setTitle(R.string.hide_history_panel); 578bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } else { 579bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard showHistory.setTitle(R.string.show_history_panel); 580bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 581bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard MenuItem showState = menu.findItem(R.id.showImageStateButton); 582bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard if (mShowingImageStatePanel) { 583bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard showState.setTitle(R.string.hide_imagestate_panel); 5849594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } else { 585bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard showState.setTitle(R.string.show_imagestate_panel); 5869594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 5870ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share) 5880ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard .getActionProvider(); 5890ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mShareActionProvider.setShareIntent(getDefaultShareIntent()); 5900ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard mShareActionProvider.setOnShareTargetSelectedListener(this); 59123e58b3595de28bc8f899f3fba1ca9734533213cnicolasroard 59223e58b3595de28bc8f899f3fba1ca9734533213cnicolasroard MenuItem undoItem = menu.findItem(R.id.undoButton); 59323e58b3595de28bc8f899f3fba1ca9734533213cnicolasroard MenuItem redoItem = menu.findItem(R.id.redoButton); 59423e58b3595de28bc8f899f3fba1ca9734533213cnicolasroard MenuItem resetItem = menu.findItem(R.id.resetHistoryButton); 59523e58b3595de28bc8f899f3fba1ca9734533213cnicolasroard mImageShow.getHistory().setMenuItems(undoItem, redoItem, resetItem); 5969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return true; 5979594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 5989594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard 59992e2341248e99c691f38820503984bc5e2f18811nicolasroard @Override 6006e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu public void onPause() { 6016e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu super.onPause(); 6026e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu if (mShareActionProvider != null) { 6036e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu mShareActionProvider.setOnShareTargetSelectedListener(null); 6046e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu } 6056e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu } 6066e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu 6076e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu @Override 6086e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu public void onResume() { 6096e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu super.onResume(); 6106e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu if (mShareActionProvider != null) { 6116e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu mShareActionProvider.setOnShareTargetSelectedListener(this); 6126e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu } 6136e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu } 6146e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu 6156e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu @Override 6169594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard public boolean onOptionsItemSelected(MenuItem item) { 6179594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard switch (item.getItemId()) { 6189594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard case R.id.undoButton: { 619d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard HistoryAdapter adapter = mImageShow.getHistory(); 6209594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard int position = adapter.undo(); 6219594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mImageShow.onItemClick(position); 6229594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mImageShow.showToast("Undo"); 6239594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard invalidateViews(); 6249594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return true; 6259594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 6269594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard case R.id.redoButton: { 627d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard HistoryAdapter adapter = mImageShow.getHistory(); 6289594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard int position = adapter.redo(); 6299594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mImageShow.onItemClick(position); 6309594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mImageShow.showToast("Redo"); 6319594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard invalidateViews(); 6329594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return true; 6339594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 634f47e790e3f3553f69abe054eec20bd7585118843nicolasroard case R.id.resetHistoryButton: { 635f47e790e3f3553f69abe054eec20bd7585118843nicolasroard resetHistory(); 636f47e790e3f3553f69abe054eec20bd7585118843nicolasroard return true; 637f47e790e3f3553f69abe054eec20bd7585118843nicolasroard } 638bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard case R.id.showImageStateButton: { 639bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard toggleImageStatePanel(); 640bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard return true; 641bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 6429594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard case R.id.operationsButton: { 6439594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard toggleHistoryPanel(); 6449594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return true; 6459594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 6469594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard case android.R.id.home: { 6479594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard saveImage(); 6489594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return true; 6499594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 6509594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 6519594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard return false; 6529594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 6539594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard 654bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu public void enableSave(boolean enable) { 655bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu if (mSaveButton != null) 656bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu mSaveButton.setEnabled(enable); 657bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu } 658bf1677a434760fcb7389a30c18e05cc3e7926d40Doris Liu 6590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private void fillListImages(LinearLayout listFilters) { 6600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // TODO: use listview 6610d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // TODO: load the filters straight from the filesystem 662a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 663a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford ImageFilterFx[] fxArray = new ImageFilterFx[18]; 6640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard int p = 0; 665457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford 66608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard int[] drawid = { 66743b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0005_punch, 668457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.drawable.filtershow_fx_0000_vintage, 669457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.drawable.filtershow_fx_0004_bw_contrast, 67043b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0002_bleach, 67143b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0001_instant, 672457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.drawable.filtershow_fx_0007_washout, 67343b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0003_blue_crush, 67443b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0008_washout_color, 67543b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.drawable.filtershow_fx_0006_x_process 676457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford }; 677457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford 67808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard int[] fxNameid = { 67943b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.ffx_punch, 680457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.string.ffx_vintage, 681457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.string.ffx_bw_contrast, 68243b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.ffx_bleach, 68343b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.ffx_instant, 684457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.string.ffx_washout, 68543b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.ffx_blue_crush, 686457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford R.string.ffx_washout_color, 68743b906d81caa4379eae1a1643194c8b3d34b1ad5Ruben Brunk R.string.ffx_x_process 688457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford }; 689457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford 6900a32b7afc5286a5c7aa334b9338591d61a49731fRuben Brunk ImagePreset preset = new ImagePreset(getString(R.string.history_original)); // empty 691e9c55b28a4a155c2e1c1f5aec615a0c56e38ade4John Hoford preset.setImageLoader(mImageLoader); 692af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter = new ImageSmallFilter(this); 693a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 694af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter.setSelected(true); 695af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mCurrentImageSmallFilter = mNullFxFilter; 696a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 697af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter.setImageFilter(new ImageFilterFx(null, getString(R.string.none))); 698a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 699af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter.setController(this); 700af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter.setImageLoader(mImageLoader); 701af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford listFilters.addView(mNullFxFilter); 702af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford ImageSmallFilter previousFilter = mNullFxFilter; 703a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 70453f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford BitmapFactory.Options o = new BitmapFactory.Options(); 70553f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford o.inScaled = false; 70608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard 707457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford for (int i = 0; i < drawid.length; i++) { 70853f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i], o); 709a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford fxArray[p++] = new ImageFilterFx(b, getString(fxNameid[i])); 710457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford } 711af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford ImageSmallFilter filter; 7120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (int i = 0; i < p; i++) { 713a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford filter = new ImageSmallFilter(this); 714a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford filter.setImageFilter(fxArray[i]); 7150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard filter.setController(this); 716af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford filter.setNulfilter(mNullFxFilter); 7170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard filter.setImageLoader(mImageLoader); 7180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard listFilters.addView(filter); 71908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard previousFilter = filter; 7200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // Default preset (original) 723a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford mImageShow.setImagePreset(preset); 7240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private void fillListBorders(LinearLayout listBorders) { 7270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // TODO: use listview 7280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // TODO: load the borders straight from the filesystem 7290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard int p = 0; 73048b29c82472006102911f981be7025d21f5fc805nicolasroard ImageFilter[] borders = new ImageFilter[12]; 7310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard borders[p++] = new ImageFilterBorder(null); 7320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7338e1536da92f155731d5fd729ec5b2bf00709091anicolasroard Drawable npd1 = getResources().getDrawable(R.drawable.filtershow_border_4x5); 7348e1536da92f155731d5fd729ec5b2bf00709091anicolasroard borders[p++] = new ImageFilterBorder(npd1); 7358e1536da92f155731d5fd729ec5b2bf00709091anicolasroard Drawable npd2 = getResources().getDrawable(R.drawable.filtershow_border_brush); 7368e1536da92f155731d5fd729ec5b2bf00709091anicolasroard borders[p++] = new ImageFilterBorder(npd2); 73748b29c82472006102911f981be7025d21f5fc805nicolasroard Drawable npd3 = getResources().getDrawable(R.drawable.filtershow_border_grunge); 73848b29c82472006102911f981be7025d21f5fc805nicolasroard borders[p++] = new ImageFilterBorder(npd3); 73948b29c82472006102911f981be7025d21f5fc805nicolasroard Drawable npd4 = getResources().getDrawable(R.drawable.filtershow_border_sumi_e); 74048b29c82472006102911f981be7025d21f5fc805nicolasroard borders[p++] = new ImageFilterBorder(npd4); 74148b29c82472006102911f981be7025d21f5fc805nicolasroard Drawable npd5 = getResources().getDrawable(R.drawable.filtershow_border_tape); 74248b29c82472006102911f981be7025d21f5fc805nicolasroard borders[p++] = new ImageFilterBorder(npd5); 7435ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, 0); 7440f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, 7450f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk mImageBorderSize); 7465ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, 0); 7470f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, 7480f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk mImageBorderSize); 74948b29c82472006102911f981be7025d21f5fc805nicolasroard int creamColor = Color.argb(255, 237, 237, 227); 75048b29c82472006102911f981be7025d21f5fc805nicolasroard borders[p++] = new ImageFilterParametricBorder(creamColor, mImageBorderSize, 0); 75148b29c82472006102911f981be7025d21f5fc805nicolasroard borders[p++] = new ImageFilterParametricBorder(creamColor, mImageBorderSize, 75248b29c82472006102911f981be7025d21f5fc805nicolasroard mImageBorderSize); 7530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 75408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard ImageSmallFilter previousFilter = null; 7550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (int i = 0; i < p; i++) { 75608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard ImageSmallBorder filter = new ImageSmallBorder(this); 757af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford if (i == 0) { // save the first to reset it 758af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullBorderFilter = filter; 759af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford } else { 760af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford filter.setNulfilter(mNullBorderFilter); 761af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford } 7620a32b7afc5286a5c7aa334b9338591d61a49731fRuben Brunk borders[i].setName(getString(R.string.borders)); 7630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard filter.setImageFilter(borders[i]); 7640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard filter.setController(this); 76593dfe7a1df07a64701369b480578410efb740a27nicolasroard filter.setBorder(true); 7660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard filter.setImageLoader(mImageLoader); 767bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard filter.setShowTitle(false); 7680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard listBorders.addView(filter); 76908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard previousFilter = filter; 7700d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // ////////////////////////////////////////////////////////////////////////////// 7740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // Some utility functions 77592e2341248e99c691f38820503984bc5e2f18811nicolasroard // TODO: finish the cleanup. 7760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void showOriginalViews(boolean value) { 7780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (ImageShow views : mImageViews) { 7790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard views.showOriginal(value); 7800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void invalidateViews() { 7840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (ImageShow views : mImageViews) { 7850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard views.invalidate(); 7868537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk views.updateImage(); 7870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void hideListViews() { 7910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (View view : mListViews) { 7920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard view.setVisibility(View.GONE); 7930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 7950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 7960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void hideImageViews() { 7970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageShow.setShowControls(false); // reset 7980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (View view : mImageViews) { 7990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard view.setVisibility(View.GONE); 8000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 8030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void unselectBottomPanelButtons() { 8040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (ImageButton button : mBottomPanelButtons) { 8050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard button.setSelected(false); 8060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 8090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void unselectPanelButtons(Vector<ImageButton> buttons) { 8100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard for (ImageButton button : buttons) { 8110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard button.setSelected(false); 8120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 8140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 8150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // ////////////////////////////////////////////////////////////////////////////// 816bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard // imageState panel... 817bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 818d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard public boolean isShowingHistoryPanel() { 819d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard return mShowingHistoryPanel; 820d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard } 821d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard 822bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard private void toggleImageStatePanel() { 823bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard final View view = findViewById(R.id.mainPanel); 824bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard final View viewList = findViewById(R.id.imageStatePanel); 825bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 826bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard if (mShowingHistoryPanel) { 827bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard findViewById(R.id.historyPanel).setVisibility(View.INVISIBLE); 828bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mShowingHistoryPanel = false; 829bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 830bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 8314d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int translate = translateMainPanel(viewList); 832bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard if (!mShowingImageStatePanel) { 833bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mShowingImageStatePanel = true; 8344d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard view.animate().setDuration(200).x(translate) 835bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard .withLayer().withEndAction(new Runnable() { 83692e2341248e99c691f38820503984bc5e2f18811nicolasroard @Override 837bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard public void run() { 838bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard viewList.setAlpha(0); 839bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard viewList.setVisibility(View.VISIBLE); 840bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard viewList.animate().setDuration(100) 841bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard .alpha(1.0f).start(); 842bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 843bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard }).start(); 844bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } else { 845bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mShowingImageStatePanel = false; 846bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard viewList.setVisibility(View.INVISIBLE); 847bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard view.animate().setDuration(200).x(0).withLayer() 848bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard .start(); 849bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 850bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard invalidateOptionsMenu(); 851bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 852bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 853a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard @Override 854a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard public void onConfigurationChanged(Configuration newConfig) 855a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard { 856a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard super.onConfigurationChanged(newConfig); 857a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard if (mShowingHistoryPanel) { 858a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard toggleHistoryPanel(); 859a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard } 860a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard } 861a9bc8ef5774557a66bcb9bb6d38cb16f7ef56e2enicolasroard 862bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard // ////////////////////////////////////////////////////////////////////////////// 8630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // history panel... 8640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 865d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard public void toggleHistoryPanel() { 8669594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard final View view = findViewById(R.id.mainPanel); 8679594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard final View viewList = findViewById(R.id.historyPanel); 868bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 869bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard if (mShowingImageStatePanel) { 870bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard findViewById(R.id.imageStatePanel).setVisibility(View.INVISIBLE); 871bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mShowingImageStatePanel = false; 872bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard } 873bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard 8744d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard int translate = translateMainPanel(viewList); 8759594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard if (!mShowingHistoryPanel) { 8769594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mShowingHistoryPanel = true; 8774d276f338bbdc53f8a3b4806265bc26c7fe0ea7cnicolasroard view.animate().setDuration(200).x(translate) 8789594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard .withLayer().withEndAction(new Runnable() { 87992e2341248e99c691f38820503984bc5e2f18811nicolasroard @Override 8809594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard public void run() { 8819594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard viewList.setAlpha(0); 8829594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard viewList.setVisibility(View.VISIBLE); 8839594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard viewList.animate().setDuration(100) 8849594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard .alpha(1.0f).start(); 8859594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 8869594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard }).start(); 8879594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } else { 8889594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mShowingHistoryPanel = false; 8899594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard viewList.setVisibility(View.INVISIBLE); 8909594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard view.animate().setDuration(200).x(0).withLayer() 891bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard .start(); 8929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 8939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard invalidateOptionsMenu(); 8949594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard } 8950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 8969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard private void resetHistory() { 897af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullFxFilter.onClick(mNullFxFilter); 898af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford mNullBorderFilter.onClick(mNullBorderFilter); 899af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford 900d7899c56b8df278dfd6720ae11eadc2f89fe8094nicolasroard HistoryAdapter adapter = mImageShow.getHistory(); 9019594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard adapter.reset(); 9029594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard ImagePreset original = new ImagePreset(adapter.getItem(0)); 9039594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard mImageShow.setImagePreset(original); 9043992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard mPanelController.resetParameters(); 9059594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard invalidateViews(); 9060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 9080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // reset button in the history panel. 9090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard private OnClickListener createOnClickResetOperationsButton() { 9100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard return new View.OnClickListener() { 9110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard @Override 9120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void onClick(View v) { 913af0dc7f486553fd96b33b15e5380cb1928462d69John Hoford 9149594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard resetHistory(); 9150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard }; 9170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 91975608166f54891972ebad3d8fd958fed9a5300e6nicolasroard @Override 92075608166f54891972ebad3d8fd958fed9a5300e6nicolasroard public void onBackPressed() { 92175608166f54891972ebad3d8fd958fed9a5300e6nicolasroard if (mPanelController.onBackPressed()) { 92255550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard saveImage(); 92375608166f54891972ebad3d8fd958fed9a5300e6nicolasroard } 92475608166f54891972ebad3d8fd958fed9a5300e6nicolasroard } 925e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard 926e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard public void cannotLoadImage() { 927e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard CharSequence text = getString(R.string.cannot_load_image); 928e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); 929e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard toast.show(); 930e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard finish(); 931e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard } 932e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard 9330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // ////////////////////////////////////////////////////////////////////////////// 9340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 9350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public float getPixelsFromDip(float value) { 9360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard Resources r = getResources(); 9370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, 9380d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard r.getDisplayMetrics()); 9390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9400d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 94108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard public void useImagePreset(ImageSmallFilter imageSmallFilter, ImagePreset preset) { 9420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard if (preset == null) { 9430d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard return; 9440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 94508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard 94608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard if (mCurrentImageSmallFilter != null) { 94708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter.setSelected(false); 94808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard } 94908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter = imageSmallFilter; 95008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter.setSelected(true); 95108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard 9520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard ImagePreset copy = new ImagePreset(preset); 9530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageShow.setImagePreset(copy); 9540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard if (preset.isFx()) { 9550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // if it's an FX we rest the curve adjustment too 9560d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageCurves.resetCurve(); 9570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard invalidateViews(); 9590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 96108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard public void useImageFilter(ImageSmallFilter imageSmallFilter, ImageFilter imageFilter, 96208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard boolean setBorder) { 9630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard if (imageFilter == null) { 9640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard return; 9650d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 96608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard 96708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard if (mCurrentImageSmallFilter != null) { 96808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter.setSelected(false); 96908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard } 97008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter = imageSmallFilter; 97108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard mCurrentImageSmallFilter.setSelected(true); 97208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard 9730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard ImagePreset oldPreset = mImageShow.getImagePreset(); 9740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard ImagePreset copy = new ImagePreset(oldPreset); 9750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard // TODO: use a numerical constant instead. 976a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 977a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford copy.add(imageFilter); 978a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford 979bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mImageShow.setImagePreset(copy); 9800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard invalidateViews(); 9810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 9830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard @Override 9840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void onItemClick(AdapterView<?> parent, View view, int position, 9850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard long id) { 9860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard mImageShow.onItemClick(position); 9870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard invalidateViews(); 9880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 9900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void pickImage() { 9910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard Intent intent = new Intent(); 9920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard intent.setType("image/*"); 9930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard intent.setAction(Intent.ACTION_GET_CONTENT); 9940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)), 9950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard SELECT_PICTURE); 9960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 9970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 99892e2341248e99c691f38820503984bc5e2f18811nicolasroard @Override 9990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void onActivityResult(int requestCode, int resultCode, Intent data) { 10000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard Log.v(LOGTAG, "onActivityResult"); 10010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard if (resultCode == RESULT_OK) { 10020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard if (requestCode == SELECT_PICTURE) { 10030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard Uri selectedImageUri = data.getData(); 1004d49d53206a197b08ec4754d8751b6860e33d9f48John Reck startLoadBitmap(selectedImageUri); 10050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 10060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 10070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 10080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 10090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard public void saveImage() { 101055550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard if (mImageShow.hasModifications()) { 10110addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu // Get the name of the album, to which the image will be saved 10120addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu File saveDir = SaveCopyTask.getFinalSaveDirectory(this, mImageLoader.getUri()); 10130addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu int bucketId = GalleryUtils.getBucketId(saveDir.getPath()); 10140addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null); 10150addfc7f6342184a67cdd8b5cc3872c6a5c87e55Doris Liu showSavingProgress(albumName); 101655550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard mImageShow.saveImage(this, null); 101755550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard } else { 101855550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard finish(); 101955550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard } 10200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 10210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 10220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard static { 1023e3f9f579d73af613a33ba1d0a93dc101ea671a69nicolasroard System.loadLibrary("jni_filtershow_filters"); 10240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 10250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 10260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard} 1027