FilterShowActivity.java revision 5ec40a6ba587fa8bd50958d263bb6fc6280de4c1
10d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
20d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardpackage com.android.gallery3d.filtershow;
30d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
40d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.annotation.TargetApi;
59594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroardimport android.app.ActionBar;
60d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.app.Activity;
7ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescuimport android.app.ProgressDialog;
80ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.content.ContentValues;
90d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.content.Intent;
100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.content.res.Resources;
11457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hofordimport android.graphics.Bitmap;
12457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hofordimport android.graphics.BitmapFactory;
1393dfe7a1df07a64701369b480578410efb740a27nicolasroardimport android.graphics.Color;
14fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.graphics.Point;
150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.graphics.drawable.Drawable;
1692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.net.Uri;
1792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.os.Bundle;
18fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.util.DisplayMetrics;
190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.util.Log;
200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.util.TypedValue;
21fafb2edbb9928039b887f59685d82593bd79e06aJohn Hofordimport android.view.Display;
220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.Menu;
239594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroardimport android.view.MenuItem;
240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.View;
250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.view.View.OnClickListener;
260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.AdapterView;
270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.AdapterView.OnItemClickListener;
280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.ImageButton;
290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.LinearLayout;
300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.widget.ListView;
3192e2341248e99c691f38820503984bc5e2f18811nicolasroardimport android.widget.SeekBar;
320ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.widget.ShareActionProvider;
330ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardimport android.widget.ShareActionProvider.OnShareTargetSelectedListener;
340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.R;
3692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.cache.ImageLoader;
3792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilter;
3892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterBorder;
39ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterContrast;
40ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterExposure;
41a19830b4fd9050b48386cd904d99cfd2566cc515John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterFx;
42ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterHue;
4393dfe7a1df07a64701369b480578410efb740a27nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
4492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterRS;
45ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterSaturated;
46ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterShadows;
47ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVibrance;
48ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVignette;
49ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterWBalance;
5092e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageBorder;
51de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageCrop;
52de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageFlip;
53de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageRotate;
5492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageShow;
5508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallBorder;
5692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallFilter;
5792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageStraighten;
58ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageWithIcon;
5992e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageZoom;
6092e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.presets.ImagePreset;
6192e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.provider.SharedImageProvider;
6292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.tools.SaveCopyTask;
635ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroardimport com.android.gallery3d.filtershow.ui.ImageButtonTitle;
6492e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.ui.ImageCurves;
6592e2341248e99c691f38820503984bc5e2f18811nicolasroard
6692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.io.File;
67ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescuimport java.lang.ref.WeakReference;
6892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.util.Vector;
6992e2341248e99c691f38820503984bc5e2f18811nicolasroard
700d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard@TargetApi(16)
710ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardpublic class FilterShowActivity extends Activity implements OnItemClickListener,
720ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        OnShareTargetSelectedListener {
730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7492e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final PanelController mPanelController = new PanelController();
750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageLoader mImageLoader = null;
760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageShow mImageShow = null;
770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageCurves mImageCurves = null;
780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageBorder mImageBorders = null;
790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageStraighten mImageStraighten = null;
805448bf8095483574649afcc2add7f153670c7450nicolasroard    private ImageZoom mImageZoom = null;
8162e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk    private ImageCrop mImageCrop = null;
828537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk    private ImageRotate mImageRotate = null;
838537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk    private ImageFlip mImageFlip = null;
840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListFx = null;
860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListBorders = null;
870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListGeometry = null;
880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListColors = null;
8992e2341248e99c691f38820503984bc5e2f18811nicolasroard    private View mListFilterButtons = null;
900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mFxButton = null;
920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mBorderButton = null;
930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mGeometryButton = null;
940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mColorsButton = null;
950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
9608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    private ImageSmallFilter mCurrentImageSmallFilter = null;
970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private static final int SELECT_PICTURE = 1;
980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private static final String LOGTAG = "FilterShowActivity";
9992e2341248e99c691f38820503984bc5e2f18811nicolasroard    protected static final boolean ANIMATE_PANELS = true;
1005ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard    private static int mImageBorderSize = 40;
1010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private boolean mShowingHistoryPanel = false;
103bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    private boolean mShowingImageStatePanel = false;
104bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
10592e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
10692e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<View> mListViews = new Vector<View>();
10792e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<ImageButton> mBottomPanelButtons = new Vector<ImageButton>();
1080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1090ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private ShareActionProvider mShareActionProvider;
1100ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private File mSharedOutputFile = null;
1110ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
1120ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private boolean mSharingImage = false;
1130ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
114ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private WeakReference<ProgressDialog> mSavingProgressDialog;
115ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
1160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    @Override
1170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onCreate(Bundle savedInstanceState) {
1180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        super.onCreate(savedInstanceState);
1190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1205448bf8095483574649afcc2add7f153670c7450nicolasroard        ImageFilterRS.setRenderScriptContext(this);
1215448bf8095483574649afcc2add7f153670c7450nicolasroard
1225ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        // TODO: get those values from XML.
1235ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextSize((int) getPixelsFromDip(12));
1245ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextPadding((int) getPixelsFromDip(10));
1255ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextSize((int) getPixelsFromDip(12));
1265ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextPadding((int) getPixelsFromDip(10));
1275ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageSmallFilter.setMargin((int) getPixelsFromDip(6));
1285ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageSmallFilter.setTextMargin((int) getPixelsFromDip(4));
1295ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        mImageBorderSize = (int) getPixelsFromDip(20);
1305ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard
1310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        setContentView(R.layout.filtershow_activity);
1329594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        ActionBar actionBar = getActionBar();
133786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
134786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setCustomView(R.layout.filtershow_actionbar);
135786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard
136786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.getCustomView().setOnClickListener(new OnClickListener() {
137786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            @Override
138786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            public void onClick(View view) {
139786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard                saveImage();
140786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            }
141786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        });
1420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1430d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageLoader = new ImageLoader(getApplicationContext());
1440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters);
1460d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders);
147ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx);
1480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1490d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow = (ImageShow) findViewById(R.id.imageShow);
1500d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageCurves = (ImageCurves) findViewById(R.id.imageCurves);
1510d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageBorders = (ImageBorder) findViewById(R.id.imageBorder);
1520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten);
1535448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageZoom = (ImageZoom) findViewById(R.id.imageZoom);
15462e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop = (ImageCrop) findViewById(R.id.imageCrop);
1558537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate = (ImageRotate) findViewById(R.id.imageRotate);
1568537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip = (ImageFlip) findViewById(R.id.imageFlip);
1570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageShow);
1590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageCurves);
1600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageBorders);
1610d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageStraighten);
1625448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageViews.add(mImageZoom);
16362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageViews.add(mImageCrop);
1648537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageRotate);
1658537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageFlip);
1660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListFx = findViewById(R.id.fxList);
1680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListBorders = findViewById(R.id.bordersList);
16992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListGeometry = findViewById(R.id.geometryList);
17092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListFilterButtons = findViewById(R.id.filterButtonsList);
1710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListColors = findViewById(R.id.colorsFxList);
1720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListFx);
1730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListBorders);
1740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListGeometry);
17592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListViews.add(mListFilterButtons);
1760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListColors);
1770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mFxButton = (ImageButton) findViewById(R.id.fxButton);
1790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mBorderButton = (ImageButton) findViewById(R.id.borderButton);
1800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mGeometryButton = (ImageButton) findViewById(R.id.geometryButton);
1810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mColorsButton = (ImageButton) findViewById(R.id.colorsButton);
18292e2341248e99c691f38820503984bc5e2f18811nicolasroard
18392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setImageLoader(mImageLoader);
18492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setImageLoader(mImageLoader);
18592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setMaster(mImageShow);
18692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setImageLoader(mImageLoader);
18792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setMaster(mImageShow);
18892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setImageLoader(mImageLoader);
18992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setMaster(mImageShow);
19092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setImageLoader(mImageLoader);
19192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setMaster(mImageShow);
19262e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setImageLoader(mImageLoader);
19362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setMaster(mImageShow);
1948537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setImageLoader(mImageLoader);
1958537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setMaster(mImageShow);
1968537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setImageLoader(mImageLoader);
1978537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setMaster(mImageShow);
19892e2341248e99c691f38820503984bc5e2f18811nicolasroard
19992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageShow));
20092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageCurves));
20192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageBorder));
20292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageStraighten));
20362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addImageView(findViewById(R.id.imageCrop));
2048537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageRotate));
2058537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageFlip));
20692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageZoom));
20792e2341248e99c691f38820503984bc5e2f18811nicolasroard
20892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mFxButton, mListFx, 0);
20992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mBorderButton, mListBorders, 1);
21092e2341248e99c691f38820503984bc5e2f18811nicolasroard
21192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mGeometryButton, mListGeometry, 2);
21292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton));
21362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton));
21492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton));
21592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton));
21692e2341248e99c691f38820503984bc5e2f18811nicolasroard
21792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mColorsButton, mListColors, 3);
218ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
219ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []recastIDs = {
220ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vignetteButton,
221ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vibranceButton,
222ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.contrastButton,
223ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.saturationButton,
224ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.wbalanceButton,
225ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.hueButton,
226ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.exposureButton,
227ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.shadowRecoveryButton
228ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
229ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        ImageFilter []filters = {
230ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVignette(),
231ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVibrance(),
232ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterContrast(),
233ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterSaturated(),
234ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterWBalance(),
235ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterHue(),
236ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterExposure(),
237ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterShadows()
238ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
239ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
240ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
241ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        for (int i = 0; i < filters.length; i++) {
242ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
243ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageSmallFilter fView = new ImageSmallFilter(this);
244ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(recastIDs[i]);
245ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
246ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
247ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
248ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            filters[i].setParameter(100);
249ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(filters[i]);
250ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
251ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
252ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(recastIDs[i]);
253ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
254ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
255ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.addView(fView,pos);
256ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
257ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
258ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayIDs = {
259ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.sharpenButton,
260ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.curvesButtonRGB
261ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
262ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayBitmaps = {
263ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_sharpen,
264ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_curve
265ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
266ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayNames = {
267ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.sharpen,
268ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.curvesRGB
269ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
270ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
271ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        for (int i = 0; i < overlayIDs.length; i++)  {
272ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageWithIcon fView = new ImageWithIcon(this);
273ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(overlayIDs[i]);
274ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
275ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
276ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            final int sid =overlayNames[i];
277ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageFilterExposure efilter = new ImageFilterExposure(){
278ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                {
279ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                    mName = getString(sid);
280ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                }
281ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            };
282ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            efilter.setParameter(-300);
283ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
284ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                    overlayBitmaps[i] );
285ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
286ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setIcon(bitmap);
287ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(efilter);
288ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
289ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
290ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(overlayIDs[i]);
291ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
292ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
293ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.addView(fView,pos);
294ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
295ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
29692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.curvesButtonRGB));
29792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.sharpenButton));
29892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.vibranceButton));
29992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.contrastButton));
30092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.saturationButton));
3014988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.wbalanceButton));
3024988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.hueButton));
30392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.exposureButton));
30492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.shadowRecoveryButton));
30592e2341248e99c691f38820503984bc5e2f18811nicolasroard
30692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addView(findViewById(R.id.applyEffect));
30792e2341248e99c691f38820503984bc5e2f18811nicolasroard
3080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        findViewById(R.id.resetOperationsButton).setOnClickListener(
3090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                createOnClickResetOperationsButton());
3100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ListView operationsList = (ListView) findViewById(R.id.operationsList);
312bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        operationsList.setAdapter(mImageShow.getHistoryAdapter());
3130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        operationsList.setOnItemClickListener(this);
314bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        ListView imageStateList = (ListView) findViewById(R.id.imageStateList);
315bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        imageStateList.setAdapter(mImageShow.getImageStateAdapter());
316bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mImageLoader.setAdapter((HistoryAdapter) mImageShow.getHistoryAdapter());
3170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListImages(listFilters);
3190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListBorders(listBorders);
3200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
32192e2341248e99c691f38820503984bc5e2f18811nicolasroard        SeekBar seekBar = (SeekBar) findViewById(R.id.filterSeekBar);
32292e2341248e99c691f38820503984bc5e2f18811nicolasroard        seekBar.setMax(200);
32392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setSeekBar(seekBar);
324de154778c8f94121cb2117fcf6224c40c01b6132nicolasroard        mImageZoom.setSeekBar(seekBar);
32592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setRowPanel(findViewById(R.id.secondRowPanel));
3268537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.setUtilityPanel(this, findViewById(R.id.filterButtonsList),
32792e2341248e99c691f38820503984bc5e2f18811nicolasroard                findViewById(R.id.applyEffect));
32892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setMasterImage(mImageShow);
32992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setCurrentPanel(mFxButton);
3300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Intent intent = getIntent();
3310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        String data = intent.getDataString();
3320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (data != null) {
3330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            Uri uri = Uri.parse(data);
334fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford            mImageLoader.loadBitmap(uri,getScreenImageSize());
3350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        } else {
3360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            pickImage();
3370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
3380d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
3390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
340fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford    private int getScreenImageSize(){
341fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        DisplayMetrics metrics = new  DisplayMetrics();
342fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        Display display = getWindowManager().getDefaultDisplay();
343fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        Point size = new  Point();
344fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getSize(size);
345fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getMetrics(metrics);
346fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        int msize = Math.min(size.x, size.y);
347fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        return  (133*msize)/metrics.densityDpi;
348fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford    }
349fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford
350ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void showSavingProgress() {
351ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        ProgressDialog progress;
352ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
353ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            progress = mSavingProgressDialog.get();
354ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            if (progress != null) {
355ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                progress.show();
356ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                return;
357ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            }
358ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
359ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        // TODO: Allow cancellation of the saving process
360ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        progress = ProgressDialog.show(this, "", getString(R.string.saving_image), true, false);
361ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        mSavingProgressDialog = new WeakReference<ProgressDialog>(progress);
362ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
363ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
364ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void hideSavingProgress() {
365ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
366ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            ProgressDialog progress = mSavingProgressDialog.get();
36708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            if (progress != null)
36808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard                progress.dismiss();
369ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
370ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
371ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
3720ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public void completeSaveImage(Uri saveUri) {
3730ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        if (mSharingImage && mSharedOutputFile != null) {
3740ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            // Image saved, we unblock the content provider
3750ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
3760ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                    Uri.encode(mSharedOutputFile.getAbsolutePath()));
3770ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            ContentValues values = new ContentValues();
3780ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            values.put(SharedImageProvider.PREPARE, false);
3790ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            getContentResolver().insert(uri, values);
3800ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        }
3810ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        setResult(RESULT_OK, new Intent().setData(saveUri));
382ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        hideSavingProgress();
3830ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        finish();
3840ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
3850ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
3860ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    @Override
3870ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) {
38892e2341248e99c691f38820503984bc5e2f18811nicolasroard        // First, let's tell the SharedImageProvider that it will need to wait
38992e2341248e99c691f38820503984bc5e2f18811nicolasroard        // for the image
3900ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
3910ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
3920ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        ContentValues values = new ContentValues();
3930ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        values.put(SharedImageProvider.PREPARE, true);
3940ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        getContentResolver().insert(uri, values);
3950ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharingImage = true;
3960ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
3970ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        // Process and save the image in the background.
398ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        showSavingProgress();
3990ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mImageShow.saveImage(this, mSharedOutputFile);
4000ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return true;
4010ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4020ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4030ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private Intent getDefaultShareIntent() {
4040ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Intent intent = new Intent(Intent.ACTION_SEND);
4050ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
4060ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
4070ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.setType(SharedImageProvider.MIME_TYPE);
4080ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharedOutputFile = SaveCopyTask.getNewFile(this, mImageLoader.getUri());
4090ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
4100ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
4110ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.putExtra(Intent.EXTRA_STREAM, uri);
4120ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return intent;
4130ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4140ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4159594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    @Override
4169594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onCreateOptionsMenu(Menu menu) {
4179594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
418bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showHistory = menu.findItem(R.id.operationsButton);
4199594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        if (mShowingHistoryPanel) {
420bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.hide_history_panel);
421bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        } else {
422bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.show_history_panel);
423bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
424bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showState = menu.findItem(R.id.showImageStateButton);
425bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingImageStatePanel) {
426bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.hide_imagestate_panel);
4279594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        } else {
428bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.show_imagestate_panel);
4299594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
4300ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
4310ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                .getActionProvider();
4320ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setShareIntent(getDefaultShareIntent());
4330ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setOnShareTargetSelectedListener(this);
4349594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return true;
4359594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
4369594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
43792e2341248e99c691f38820503984bc5e2f18811nicolasroard    @Override
4386e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onPause() {
4396e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onPause();
4406e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4416e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(null);
4426e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4436e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4446e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4456e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4466e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onResume() {
4476e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onResume();
4486e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4496e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(this);
4506e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4516e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4526e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4536e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4549594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onOptionsItemSelected(MenuItem item) {
4559594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        switch (item.getItemId()) {
4569594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.undoButton: {
4579594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
458bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4599594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.undo();
4609594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4619594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Undo");
4629594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4639594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4649594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4659594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.redoButton: {
4669594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
467bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4689594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.redo();
4699594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4709594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Redo");
4719594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4729594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4739594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
474f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            case R.id.resetHistoryButton: {
475f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                resetHistory();
476f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                return true;
477f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            }
478bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            case R.id.showImageStateButton: {
479bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                toggleImageStatePanel();
480bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                return true;
481bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            }
4829594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.operationsButton: {
4839594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                toggleHistoryPanel();
4849594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4859594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4869594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case android.R.id.home: {
4879594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                saveImage();
4889594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4899594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4909594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
4919594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return false;
4929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
4939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
4940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private void fillListImages(LinearLayout listFilters) {
4950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use listview
4960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: load the filters straight from the filesystem
497a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
498a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageFilterFx[] fxArray = new ImageFilterFx[18];
4990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        int p = 0;
500457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
50108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] drawid = {
502457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0000_vintage,
503457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0001_instant,
504457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0002_bleach,
505457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0003_blue_crush,
506457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0004_bw_contrast,
507457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0005_punch,
508457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0006_x_process,
509457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0007_washout,
510457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0008_washout_color
511457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
512457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
51308458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] fxNameid = {
514457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_vintage,
515457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_instant,
516457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bleach,
517457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_blue_crush,
518457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bw_contrast,
519457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_punch,
520457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_x_process,
521457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout,
522457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout_color,
523457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
524457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
525a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImagePreset preset = new ImagePreset(); // empty
526a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageSmallFilter filter = new ImageSmallFilter(this);
527a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
528a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setSelected(true);
529a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        mCurrentImageSmallFilter = filter;
530a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
531a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setPreviousImageSmallFilter(null);
532a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        preset.setIsFx(true);
533a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setImagePreset(preset);
534a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
535a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setController(this);
536a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setImageLoader(mImageLoader);
537a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        listFilters.addView(filter);
538a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageSmallFilter   previousFilter = filter;
539a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
54053f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        BitmapFactory.Options o = new BitmapFactory.Options();
54153f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        o.inScaled = false;
54208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
543457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        for (int i = 0; i < drawid.length; i++) {
54453f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford            Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i], o);
545a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            fxArray[p++] = new ImageFilterFx(b, getString(fxNameid[i]));
546457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        }
547457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
5480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
549a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            filter = new ImageSmallFilter(this);
550a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
55108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            filter.setPreviousImageSmallFilter(previousFilter);
552a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            filter.setImageFilter(fxArray[i]);
5530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setController(this);
5540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageLoader(mImageLoader);
5550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            listFilters.addView(filter);
55608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            previousFilter = filter;
5570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
5580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // Default preset (original)
560a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        mImageShow.setImagePreset(preset);
5610d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
5620d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private void fillListBorders(LinearLayout listBorders) {
5640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use listview
5650d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: load the borders straight from the filesystem
5660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        int p = 0;
56793dfe7a1df07a64701369b480578410efb740a27nicolasroard        ImageFilter[] borders = new ImageFilter[7];
5680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        borders[p++] = new ImageFilterBorder(null);
5690d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5708e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        Drawable npd1 = getResources().getDrawable(R.drawable.filtershow_border_4x5);
5718e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        borders[p++] = new ImageFilterBorder(npd1);
5728e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        Drawable npd2 = getResources().getDrawable(R.drawable.filtershow_border_brush);
5738e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        borders[p++] = new ImageFilterBorder(npd2);
5745ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, 0);
5755ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, mImageBorderSize);
5765ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, 0);
5775ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, mImageBorderSize);
5780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
57908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        ImageSmallFilter previousFilter = null;
5800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
58108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            ImageSmallBorder filter = new ImageSmallBorder(this);
58208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            filter.setPreviousImageSmallFilter(previousFilter);
5830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageFilter(borders[i]);
5840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setController(this);
58593dfe7a1df07a64701369b480578410efb740a27nicolasroard            filter.setBorder(true);
5860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageLoader(mImageLoader);
587bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            filter.setShowTitle(false);
5880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            listBorders.addView(filter);
58908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            previousFilter = filter;
5900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
5910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
5920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
5940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // Some utility functions
59592e2341248e99c691f38820503984bc5e2f18811nicolasroard    // TODO: finish the cleanup.
5960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void showOriginalViews(boolean value) {
5980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
5990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.showOriginal(value);
6000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void invalidateViews() {
6040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
6050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.invalidate();
6068537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk            views.updateImage();
6070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideListViews() {
6110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mListViews) {
6120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideImageViews() {
6170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.setShowControls(false); // reset
6180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mImageViews) {
6190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectBottomPanelButtons() {
6240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : mBottomPanelButtons) {
6250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectPanelButtons(Vector<ImageButton> buttons) {
6300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : buttons) {
6310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
637bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    // imageState panel...
638bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
639bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    private void toggleImageStatePanel() {
640bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        final View view = findViewById(R.id.mainPanel);
641bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        final View viewList = findViewById(R.id.imageStatePanel);
642bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
643bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingHistoryPanel) {
644bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            findViewById(R.id.historyPanel).setVisibility(View.INVISIBLE);
645bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingHistoryPanel = false;
646bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
647bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
648bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (!mShowingImageStatePanel) {
649bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = true;
650bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            view.animate().setDuration(200).x(-viewList.getWidth())
651bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .withLayer().withEndAction(new Runnable() {
65292e2341248e99c691f38820503984bc5e2f18811nicolasroard                        @Override
653bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        public void run() {
654bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.setAlpha(0);
655bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.setVisibility(View.VISIBLE);
656bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.animate().setDuration(100)
657bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                                    .alpha(1.0f).start();
658bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        }
659bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    }).start();
660bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        } else {
661bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = false;
662bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            viewList.setVisibility(View.INVISIBLE);
663bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            view.animate().setDuration(200).x(0).withLayer()
664bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .start();
665bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
666bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        invalidateOptionsMenu();
667bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    }
668bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
669bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    // //////////////////////////////////////////////////////////////////////////////
6700d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // history panel...
6710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6729594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    private void toggleHistoryPanel() {
6739594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        final View view = findViewById(R.id.mainPanel);
6749594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        final View viewList = findViewById(R.id.historyPanel);
675bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
676bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingImageStatePanel) {
677bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            findViewById(R.id.imageStatePanel).setVisibility(View.INVISIBLE);
678bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = false;
679bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
680bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
6819594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        if (!mShowingHistoryPanel) {
6829594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            mShowingHistoryPanel = true;
6839594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            view.animate().setDuration(200).x(-viewList.getWidth())
6849594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                    .withLayer().withEndAction(new Runnable() {
68592e2341248e99c691f38820503984bc5e2f18811nicolasroard                        @Override
6869594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                        public void run() {
6879594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.setAlpha(0);
6889594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.setVisibility(View.VISIBLE);
6899594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.animate().setDuration(100)
6909594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                                    .alpha(1.0f).start();
6919594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                        }
6929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                    }).start();
6939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        } else {
6949594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            mShowingHistoryPanel = false;
6959594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            viewList.setVisibility(View.INVISIBLE);
6969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            view.animate().setDuration(200).x(0).withLayer()
697bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .start();
6989594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
6999594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        invalidateOptionsMenu();
7009594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
7010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7029594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    private void resetHistory() {
7039594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        HistoryAdapter adapter = (HistoryAdapter) mImageShow
704bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                .getHistoryAdapter();
7059594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        adapter.reset();
7069594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        ImagePreset original = new ImagePreset(adapter.getItem(0));
7079594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        mImageShow.setImagePreset(original);
7089594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        invalidateViews();
7090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // reset button in the history panel.
7120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private OnClickListener createOnClickResetOperationsButton() {
7130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        return new View.OnClickListener() {
7140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            @Override
7150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            public void onClick(View v) {
7169594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                resetHistory();
7170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            }
7180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        };
7190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
72175608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    @Override
72275608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    public void onBackPressed() {
72375608166f54891972ebad3d8fd958fed9a5300e6nicolasroard        if (mPanelController.onBackPressed()) {
72475608166f54891972ebad3d8fd958fed9a5300e6nicolasroard            finish();
72575608166f54891972ebad3d8fd958fed9a5300e6nicolasroard        }
72675608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    }
7270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
7280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public float getPixelsFromDip(float value) {
7300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Resources r = getResources();
7310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
7320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                r.getDisplayMetrics());
7330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
73508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    public void useImagePreset(ImageSmallFilter imageSmallFilter, ImagePreset preset) {
7360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (preset == null) {
7370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            return;
7380d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
73908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
74008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        if (mCurrentImageSmallFilter != null) {
74108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            mCurrentImageSmallFilter.setSelected(false);
74208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        }
74308458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter = imageSmallFilter;
74408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter.setSelected(true);
74508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
7460d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset copy = new ImagePreset(preset);
7470d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.setImagePreset(copy);
7480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (preset.isFx()) {
7490d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            // if it's an FX we rest the curve adjustment too
7500d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            mImageCurves.resetCurve();
7510d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
7520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
75508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    public void useImageFilter(ImageSmallFilter imageSmallFilter, ImageFilter imageFilter,
75608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            boolean setBorder) {
7570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (imageFilter == null) {
7580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            return;
7590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
76008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
76108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        if (mCurrentImageSmallFilter != null) {
76208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            mCurrentImageSmallFilter.setSelected(false);
76308458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        }
76408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter = imageSmallFilter;
76508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter.setSelected(true);
76608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
7670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset oldPreset = mImageShow.getImagePreset();
7680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset copy = new ImagePreset(oldPreset);
7690d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use a numerical constant instead.
770a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
771a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        copy.add(imageFilter);
772a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
773bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mImageShow.setImagePreset(copy);
7740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    @Override
7780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onItemClick(AdapterView<?> parent, View view, int position,
7790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            long id) {
7800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.onItemClick(position);
7810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void pickImage() {
7850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Intent intent = new Intent();
7860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        intent.setType("image/*");
7870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        intent.setAction(Intent.ACTION_GET_CONTENT);
7880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
7890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                SELECT_PICTURE);
7900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
79292e2341248e99c691f38820503984bc5e2f18811nicolasroard    @Override
7930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onActivityResult(int requestCode, int resultCode, Intent data) {
7940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Log.v(LOGTAG, "onActivityResult");
7950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (resultCode == RESULT_OK) {
7960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            if (requestCode == SELECT_PICTURE) {
7970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                Uri selectedImageUri = data.getData();
798fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford                mImageLoader.loadBitmap(selectedImageUri,getScreenImageSize());
7990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            }
8000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
8010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void saveImage() {
804ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        showSavingProgress();
8050ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mImageShow.saveImage(this, null);
8060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    static {
809e3f9f579d73af613a33ba1d0a93dc101ea671a69nicolasroard        System.loadLibrary("jni_filtershow_filters");
8100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard}
813