FilterShowActivity.java revision 55550694a3f40fbf5dfc95c35a8e253aedab931e
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;
34e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroardimport android.widget.Toast;
350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3692e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.R;
3792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.cache.ImageLoader;
3892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilter;
3992e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterBorder;
40ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterContrast;
41ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterExposure;
42a19830b4fd9050b48386cd904d99cfd2566cc515John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterFx;
43ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterHue;
4493dfe7a1df07a64701369b480578410efb740a27nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
4592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.filters.ImageFilterRS;
46ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterSaturated;
47ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterShadows;
48ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVibrance;
49ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterVignette;
50ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterWBalance;
5192e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageBorder;
52de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageCrop;
53de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageFlip;
54de154778c8f94121cb2117fcf6224c40c01b6132nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageRotate;
5592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageShow;
5608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallBorder;
5792e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageSmallFilter;
5892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageStraighten;
59ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageWithIcon;
6092e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.imageshow.ImageZoom;
6192e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.presets.ImagePreset;
6292e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.provider.SharedImageProvider;
6392e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.tools.SaveCopyTask;
645ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroardimport com.android.gallery3d.filtershow.ui.ImageButtonTitle;
6592e2341248e99c691f38820503984bc5e2f18811nicolasroardimport com.android.gallery3d.filtershow.ui.ImageCurves;
663992ae6cf1cbb7b57a22d8287c40451558408335nicolasroardimport com.android.gallery3d.filtershow.ui.Spline;
6792e2341248e99c691f38820503984bc5e2f18811nicolasroard
6892e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.io.File;
69ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescuimport java.lang.ref.WeakReference;
7092e2341248e99c691f38820503984bc5e2f18811nicolasroardimport java.util.Vector;
7192e2341248e99c691f38820503984bc5e2f18811nicolasroard
720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard@TargetApi(16)
730ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroardpublic class FilterShowActivity extends Activity implements OnItemClickListener,
740ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        OnShareTargetSelectedListener {
750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7692e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final PanelController mPanelController = new PanelController();
770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageLoader mImageLoader = null;
780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageShow mImageShow = null;
790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageCurves mImageCurves = null;
800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageBorder mImageBorders = null;
810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageStraighten mImageStraighten = null;
825448bf8095483574649afcc2add7f153670c7450nicolasroard    private ImageZoom mImageZoom = null;
8362e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk    private ImageCrop mImageCrop = null;
848537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk    private ImageRotate mImageRotate = null;
858537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk    private ImageFlip mImageFlip = null;
860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListFx = null;
880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListBorders = null;
890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListGeometry = null;
900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private View mListColors = null;
9192e2341248e99c691f38820503984bc5e2f18811nicolasroard    private View mListFilterButtons = null;
920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mFxButton = null;
940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mBorderButton = null;
950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mGeometryButton = null;
960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private ImageButton mColorsButton = null;
970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
9808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    private ImageSmallFilter mCurrentImageSmallFilter = null;
990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private static final int SELECT_PICTURE = 1;
1000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private static final String LOGTAG = "FilterShowActivity";
10192e2341248e99c691f38820503984bc5e2f18811nicolasroard    protected static final boolean ANIMATE_PANELS = true;
1025ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard    private static int mImageBorderSize = 40;
1030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private boolean mShowingHistoryPanel = false;
105bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    private boolean mShowingImageStatePanel = false;
106bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
10792e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
10892e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<View> mListViews = new Vector<View>();
10992e2341248e99c691f38820503984bc5e2f18811nicolasroard    private final Vector<ImageButton> mBottomPanelButtons = new Vector<ImageButton>();
1100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1110ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private ShareActionProvider mShareActionProvider;
1120ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private File mSharedOutputFile = null;
1130ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
1140ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private boolean mSharingImage = false;
1150ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
116ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private WeakReference<ProgressDialog> mSavingProgressDialog;
1173038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford    private static final int SEEK_BAR_MAX = 600;
11855550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard
1190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    @Override
1200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onCreate(Bundle savedInstanceState) {
1210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        super.onCreate(savedInstanceState);
1220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1235448bf8095483574649afcc2add7f153670c7450nicolasroard        ImageFilterRS.setRenderScriptContext(this);
1245448bf8095483574649afcc2add7f153670c7450nicolasroard
12595404c666640177abf72ca2278585a16f30cf390nicolasroard        ImageShow.setDefaultBackgroundColor(getResources().getColor(R.color.background_screen));
1265ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        // TODO: get those values from XML.
1275ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextSize((int) getPixelsFromDip(12));
1285ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextPadding((int) getPixelsFromDip(10));
1295ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextSize((int) getPixelsFromDip(12));
1305ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextPadding((int) getPixelsFromDip(10));
13195404c666640177abf72ca2278585a16f30cf390nicolasroard        ImageSmallFilter.setMargin((int) getPixelsFromDip(3));
1325ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageSmallFilter.setTextMargin((int) getPixelsFromDip(4));
1335ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        mImageBorderSize = (int) getPixelsFromDip(20);
1343992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Drawable curveHandle = getResources().getDrawable(R.drawable.camera_crop_holo);
1353992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        int curveHandleSize = (int) getResources().getDimension(R.dimen.crop_indicator_size);
1363992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Spline.setCurveHandle(curveHandle, curveHandleSize);
1373992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Spline.setCurveWidth((int) getPixelsFromDip(3));
1385ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard
1390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        setContentView(R.layout.filtershow_activity);
1409594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        ActionBar actionBar = getActionBar();
141786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
142786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setCustomView(R.layout.filtershow_actionbar);
143786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard
144786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.getCustomView().setOnClickListener(new OnClickListener() {
145786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            @Override
146786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            public void onClick(View view) {
147786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard                saveImage();
148786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            }
149786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        });
1500d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
151e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        mImageLoader = new ImageLoader(this, getApplicationContext());
1520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters);
1540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders);
155ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx);
1560d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow = (ImageShow) findViewById(R.id.imageShow);
1580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageCurves = (ImageCurves) findViewById(R.id.imageCurves);
1590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageBorders = (ImageBorder) findViewById(R.id.imageBorder);
1600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten);
1615448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageZoom = (ImageZoom) findViewById(R.id.imageZoom);
16262e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop = (ImageCrop) findViewById(R.id.imageCrop);
1638537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate = (ImageRotate) findViewById(R.id.imageRotate);
1648537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip = (ImageFlip) findViewById(R.id.imageFlip);
1650d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageShow);
1670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageCurves);
1680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageBorders);
1690d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageStraighten);
1705448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageViews.add(mImageZoom);
17162e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageViews.add(mImageCrop);
1728537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageRotate);
1738537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageFlip);
1740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListFx = findViewById(R.id.fxList);
1760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListBorders = findViewById(R.id.bordersList);
17792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListGeometry = findViewById(R.id.geometryList);
17892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListFilterButtons = findViewById(R.id.filterButtonsList);
1790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListColors = findViewById(R.id.colorsFxList);
1800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListFx);
1810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListBorders);
1820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListGeometry);
18392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListViews.add(mListFilterButtons);
1840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListColors);
1850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mFxButton = (ImageButton) findViewById(R.id.fxButton);
1870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mBorderButton = (ImageButton) findViewById(R.id.borderButton);
1880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mGeometryButton = (ImageButton) findViewById(R.id.geometryButton);
1890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mColorsButton = (ImageButton) findViewById(R.id.colorsButton);
19092e2341248e99c691f38820503984bc5e2f18811nicolasroard
19192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setImageLoader(mImageLoader);
19292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setImageLoader(mImageLoader);
19392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setMaster(mImageShow);
19492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setImageLoader(mImageLoader);
19592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setMaster(mImageShow);
19692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setImageLoader(mImageLoader);
19792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setMaster(mImageShow);
19892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setImageLoader(mImageLoader);
19992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setMaster(mImageShow);
20062e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setImageLoader(mImageLoader);
20162e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setMaster(mImageShow);
2028537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setImageLoader(mImageLoader);
2038537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setMaster(mImageShow);
2048537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setImageLoader(mImageLoader);
2058537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setMaster(mImageShow);
20692e2341248e99c691f38820503984bc5e2f18811nicolasroard
20792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageShow));
20892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageCurves));
20992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageBorder));
21092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageStraighten));
21162e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addImageView(findViewById(R.id.imageCrop));
2128537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageRotate));
2138537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageFlip));
21492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageZoom));
21592e2341248e99c691f38820503984bc5e2f18811nicolasroard
21692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mFxButton, mListFx, 0);
21792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mBorderButton, mListBorders, 1);
21892e2341248e99c691f38820503984bc5e2f18811nicolasroard
21992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mGeometryButton, mListGeometry, 2);
22092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton));
22162e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton));
22292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton));
22392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton));
22492e2341248e99c691f38820503984bc5e2f18811nicolasroard
22592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mColorsButton, mListColors, 3);
226ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
2270f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        int[] recastIDs = {
228ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vignetteButton,
229ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vibranceButton,
230ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.contrastButton,
231ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.saturationButton,
232ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.wbalanceButton,
233ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.hueButton,
234ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.exposureButton,
235ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.shadowRecoveryButton
236ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
2370f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        ImageFilter[] filters = {
238ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVignette(),
239ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVibrance(),
240ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterContrast(),
241ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterSaturated(),
242ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterWBalance(),
243ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterHue(),
244ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterExposure(),
245ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterShadows()
246ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
247ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
248ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        for (int i = 0; i < filters.length; i++) {
249ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
250ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageSmallFilter fView = new ImageSmallFilter(this);
251ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(recastIDs[i]);
252ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
253ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
254ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
255ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            filters[i].setParameter(100);
256ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(filters[i]);
257ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
258ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
259ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(recastIDs[i]);
260ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
261ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
2620f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk            listColors.addView(fView, pos);
263ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
264ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
2650f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        int[] overlayIDs = {
266ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.sharpenButton,
267ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.curvesButtonRGB
268ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
2690f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        int[] overlayBitmaps = {
270ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_sharpen,
271ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_curve
272ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
2730f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        int[] overlayNames = {
274ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.sharpen,
275ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.curvesRGB
276ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
277ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
2780f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        for (int i = 0; i < overlayIDs.length; i++) {
279ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageWithIcon fView = new ImageWithIcon(this);
280ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(overlayIDs[i]);
281ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
282ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
2830f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk            final int sid = overlayNames[i];
2840f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk            ImageFilterExposure efilter = new ImageFilterExposure() {
285ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                {
286ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                    mName = getString(sid);
287ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                }
288ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            };
289ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            efilter.setParameter(-300);
290ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
2910f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk                    overlayBitmaps[i]);
292ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
293ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setIcon(bitmap);
294ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(efilter);
295ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
296ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
297ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(overlayIDs[i]);
298ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
299ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
3000f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk            listColors.addView(fView, pos);
301ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
302ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
30392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.curvesButtonRGB));
30492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.sharpenButton));
30592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.vibranceButton));
30692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.contrastButton));
30792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.saturationButton));
3084988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.wbalanceButton));
3094988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.hueButton));
31092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.exposureButton));
31192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.shadowRecoveryButton));
31292e2341248e99c691f38820503984bc5e2f18811nicolasroard
31392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addView(findViewById(R.id.applyEffect));
3143992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        mPanelController.addView(findViewById(R.id.pickCurvesChannel));
3150f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        mPanelController.addView(findViewById(R.id.aspect));
3160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        findViewById(R.id.resetOperationsButton).setOnClickListener(
3170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                createOnClickResetOperationsButton());
3180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ListView operationsList = (ListView) findViewById(R.id.operationsList);
320bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        operationsList.setAdapter(mImageShow.getHistoryAdapter());
3210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        operationsList.setOnItemClickListener(this);
322bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        ListView imageStateList = (ListView) findViewById(R.id.imageStateList);
323bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        imageStateList.setAdapter(mImageShow.getImageStateAdapter());
324bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mImageLoader.setAdapter((HistoryAdapter) mImageShow.getHistoryAdapter());
3250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListImages(listFilters);
3270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListBorders(listBorders);
3280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
32992e2341248e99c691f38820503984bc5e2f18811nicolasroard        SeekBar seekBar = (SeekBar) findViewById(R.id.filterSeekBar);
3303038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford        seekBar.setMax(SEEK_BAR_MAX);
3313038d014b7ade998d1820c997242b9d9d8bc7ccfJohn Hoford
33292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setSeekBar(seekBar);
333de154778c8f94121cb2117fcf6224c40c01b6132nicolasroard        mImageZoom.setSeekBar(seekBar);
33492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setRowPanel(findViewById(R.id.secondRowPanel));
3358537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.setUtilityPanel(this, findViewById(R.id.filterButtonsList),
3360f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk                findViewById(R.id.applyEffect), findViewById(R.id.aspect));
33792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setMasterImage(mImageShow);
33892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setCurrentPanel(mFxButton);
3390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Intent intent = getIntent();
3400d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        String data = intent.getDataString();
3410d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (data != null) {
3420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            Uri uri = Uri.parse(data);
3430f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk            mImageLoader.loadBitmap(uri, getScreenImageSize());
3440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        } else {
3450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            pickImage();
3460d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
3470d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
3480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3490f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk    private int getScreenImageSize() {
3500f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        DisplayMetrics metrics = new DisplayMetrics();
351fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        Display display = getWindowManager().getDefaultDisplay();
3520f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        Point size = new Point();
353fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getSize(size);
354fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getMetrics(metrics);
355fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        int msize = Math.min(size.x, size.y);
3560f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        return (133 * msize) / metrics.densityDpi;
357fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford    }
358fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford
359ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void showSavingProgress() {
360ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        ProgressDialog progress;
361ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
362ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            progress = mSavingProgressDialog.get();
363ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            if (progress != null) {
364ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                progress.show();
365ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                return;
366ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            }
367ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
368ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        // TODO: Allow cancellation of the saving process
369ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        progress = ProgressDialog.show(this, "", getString(R.string.saving_image), true, false);
370ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        mSavingProgressDialog = new WeakReference<ProgressDialog>(progress);
371ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
372ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
373ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void hideSavingProgress() {
374ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
375ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            ProgressDialog progress = mSavingProgressDialog.get();
37608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            if (progress != null)
37708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard                progress.dismiss();
378ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
379ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
380ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
3810ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public void completeSaveImage(Uri saveUri) {
3820ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        if (mSharingImage && mSharedOutputFile != null) {
3830ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            // Image saved, we unblock the content provider
3840ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
3850ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                    Uri.encode(mSharedOutputFile.getAbsolutePath()));
3860ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            ContentValues values = new ContentValues();
3870ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            values.put(SharedImageProvider.PREPARE, false);
3880ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            getContentResolver().insert(uri, values);
3890ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        }
3900ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        setResult(RESULT_OK, new Intent().setData(saveUri));
391ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        hideSavingProgress();
3920ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        finish();
3930ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
3940ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
3950ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    @Override
3960ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) {
39792e2341248e99c691f38820503984bc5e2f18811nicolasroard        // First, let's tell the SharedImageProvider that it will need to wait
39892e2341248e99c691f38820503984bc5e2f18811nicolasroard        // for the image
3990ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
4000ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
4010ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        ContentValues values = new ContentValues();
4020ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        values.put(SharedImageProvider.PREPARE, true);
4030ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        getContentResolver().insert(uri, values);
4040ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharingImage = true;
4050ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4060ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        // Process and save the image in the background.
407ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        showSavingProgress();
4080ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mImageShow.saveImage(this, mSharedOutputFile);
4090ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return true;
4100ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4110ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4120ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private Intent getDefaultShareIntent() {
4130ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Intent intent = new Intent(Intent.ACTION_SEND);
4140ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
4150ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
4160ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.setType(SharedImageProvider.MIME_TYPE);
4170ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharedOutputFile = SaveCopyTask.getNewFile(this, mImageLoader.getUri());
4180ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
4190ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
4200ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.putExtra(Intent.EXTRA_STREAM, uri);
4210ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return intent;
4220ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4230ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4249594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    @Override
4259594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onCreateOptionsMenu(Menu menu) {
4269594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
427bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showHistory = menu.findItem(R.id.operationsButton);
4289594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        if (mShowingHistoryPanel) {
429bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.hide_history_panel);
430bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        } else {
431bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.show_history_panel);
432bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
433bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showState = menu.findItem(R.id.showImageStateButton);
434bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingImageStatePanel) {
435bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.hide_imagestate_panel);
4369594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        } else {
437bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.show_imagestate_panel);
4389594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
4390ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
4400ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                .getActionProvider();
4410ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setShareIntent(getDefaultShareIntent());
4420ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setOnShareTargetSelectedListener(this);
4439594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return true;
4449594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
4459594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
44692e2341248e99c691f38820503984bc5e2f18811nicolasroard    @Override
4476e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onPause() {
4486e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onPause();
4496e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4506e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(null);
4516e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4526e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4536e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4546e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4556e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onResume() {
4566e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onResume();
4576e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4586e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(this);
4596e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4606e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4616e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4626e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4639594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onOptionsItemSelected(MenuItem item) {
4649594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        switch (item.getItemId()) {
4659594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.undoButton: {
4669594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
467bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4689594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.undo();
4699594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4709594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Undo");
4719594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4729594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4739594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4749594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.redoButton: {
4759594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
476bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4779594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.redo();
4789594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4799594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Redo");
4809594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4819594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4829594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
483f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            case R.id.resetHistoryButton: {
484f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                resetHistory();
485f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                return true;
486f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            }
487bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            case R.id.showImageStateButton: {
488bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                toggleImageStatePanel();
489bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                return true;
490bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            }
4919594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.operationsButton: {
4929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                toggleHistoryPanel();
4939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4949594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4959594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case android.R.id.home: {
4969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                saveImage();
4979594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4989594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4999594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
5009594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return false;
5019594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
5029594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
5030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private void fillListImages(LinearLayout listFilters) {
5040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use listview
5050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: load the filters straight from the filesystem
506a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
507a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageFilterFx[] fxArray = new ImageFilterFx[18];
5080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        int p = 0;
509457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
51008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] drawid = {
511457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0000_vintage,
512457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0001_instant,
513457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0002_bleach,
514457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0003_blue_crush,
515457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0004_bw_contrast,
516457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0005_punch,
517457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0006_x_process,
518457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0007_washout,
519457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0008_washout_color
520457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
521457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
52208458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] fxNameid = {
523457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_vintage,
524457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_instant,
525457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bleach,
526457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_blue_crush,
527457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bw_contrast,
528457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_punch,
529457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_x_process,
530457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout,
531457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout_color,
532457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
533457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
534a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImagePreset preset = new ImagePreset(); // empty
535a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageSmallFilter filter = new ImageSmallFilter(this);
536a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
537a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setSelected(true);
538a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        mCurrentImageSmallFilter = filter;
539a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
54055550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard        filter.setImageFilter(new ImageFilterFx(null, getString(R.string.ffx_original)));
541a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
542a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setController(this);
543a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setImageLoader(mImageLoader);
544a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        listFilters.addView(filter);
5450f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        ImageSmallFilter previousFilter = filter;
546a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
54753f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        BitmapFactory.Options o = new BitmapFactory.Options();
54853f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        o.inScaled = false;
54908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
550457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        for (int i = 0; i < drawid.length; i++) {
55153f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford            Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i], o);
552a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            fxArray[p++] = new ImageFilterFx(b, getString(fxNameid[i]));
553457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        }
554457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
5550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
556a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            filter = new ImageSmallFilter(this);
557a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            filter.setImageFilter(fxArray[i]);
5580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setController(this);
5590d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageLoader(mImageLoader);
5600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            listFilters.addView(filter);
56108458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            previousFilter = filter;
5620d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
5630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // Default preset (original)
565a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        mImageShow.setImagePreset(preset);
5660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
5670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private void fillListBorders(LinearLayout listBorders) {
5690d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use listview
5700d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: load the borders straight from the filesystem
5710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        int p = 0;
57293dfe7a1df07a64701369b480578410efb740a27nicolasroard        ImageFilter[] borders = new ImageFilter[7];
5730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        borders[p++] = new ImageFilterBorder(null);
5740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5758e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        Drawable npd1 = getResources().getDrawable(R.drawable.filtershow_border_4x5);
5768e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        borders[p++] = new ImageFilterBorder(npd1);
5778e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        Drawable npd2 = getResources().getDrawable(R.drawable.filtershow_border_brush);
5788e1536da92f155731d5fd729ec5b2bf00709091anicolasroard        borders[p++] = new ImageFilterBorder(npd2);
5795ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, 0);
5800f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize,
5810f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk                mImageBorderSize);
5825ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, 0);
5830f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize,
5840f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk                mImageBorderSize);
5850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
58608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        ImageSmallFilter previousFilter = null;
5870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
58808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            ImageSmallBorder filter = new ImageSmallBorder(this);
5890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageFilter(borders[i]);
5900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setController(this);
59193dfe7a1df07a64701369b480578410efb740a27nicolasroard            filter.setBorder(true);
5920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageLoader(mImageLoader);
593bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            filter.setShowTitle(false);
5940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            listBorders.addView(filter);
59508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            previousFilter = filter;
5960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
5970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
5980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
6000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // Some utility functions
60192e2341248e99c691f38820503984bc5e2f18811nicolasroard    // TODO: finish the cleanup.
6020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void showOriginalViews(boolean value) {
6040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
6050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.showOriginal(value);
6060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void invalidateViews() {
6100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
6110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.invalidate();
6128537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk            views.updateImage();
6130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideListViews() {
6170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mListViews) {
6180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideImageViews() {
6230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.setShowControls(false); // reset
6240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mImageViews) {
6250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectBottomPanelButtons() {
6300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : mBottomPanelButtons) {
6310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectPanelButtons(Vector<ImageButton> buttons) {
6360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : buttons) {
6370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6380d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6400d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6410d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
642bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    // imageState panel...
643bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
644bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    private void toggleImageStatePanel() {
645bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        final View view = findViewById(R.id.mainPanel);
646bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        final View viewList = findViewById(R.id.imageStatePanel);
647bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
648bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingHistoryPanel) {
649bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            findViewById(R.id.historyPanel).setVisibility(View.INVISIBLE);
650bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingHistoryPanel = false;
651bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
652bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
653bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (!mShowingImageStatePanel) {
654bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = true;
655bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            view.animate().setDuration(200).x(-viewList.getWidth())
656bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .withLayer().withEndAction(new Runnable() {
65792e2341248e99c691f38820503984bc5e2f18811nicolasroard                        @Override
658bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        public void run() {
659bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.setAlpha(0);
660bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.setVisibility(View.VISIBLE);
661bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                            viewList.animate().setDuration(100)
662bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                                    .alpha(1.0f).start();
663bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        }
664bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    }).start();
665bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        } else {
666bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = false;
667bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            viewList.setVisibility(View.INVISIBLE);
668bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            view.animate().setDuration(200).x(0).withLayer()
669bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .start();
670bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
671bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        invalidateOptionsMenu();
672bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    }
673bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
674bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    // //////////////////////////////////////////////////////////////////////////////
6750d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // history panel...
6760d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6779594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    private void toggleHistoryPanel() {
6789594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        final View view = findViewById(R.id.mainPanel);
6799594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        final View viewList = findViewById(R.id.historyPanel);
680bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
681bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingImageStatePanel) {
682bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            findViewById(R.id.imageStatePanel).setVisibility(View.INVISIBLE);
683bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            mShowingImageStatePanel = false;
684bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
685bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard
6869594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        if (!mShowingHistoryPanel) {
6879594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            mShowingHistoryPanel = true;
6889594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            view.animate().setDuration(200).x(-viewList.getWidth())
6899594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                    .withLayer().withEndAction(new Runnable() {
69092e2341248e99c691f38820503984bc5e2f18811nicolasroard                        @Override
6919594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                        public void run() {
6929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.setAlpha(0);
6939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.setVisibility(View.VISIBLE);
6949594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                            viewList.animate().setDuration(100)
6959594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                                    .alpha(1.0f).start();
6969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                        }
6979594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                    }).start();
6989594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        } else {
6999594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            mShowingHistoryPanel = false;
7009594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            viewList.setVisibility(View.INVISIBLE);
7019594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            view.animate().setDuration(200).x(0).withLayer()
702bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                    .start();
7039594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
7049594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        invalidateOptionsMenu();
7059594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
7060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7079594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    private void resetHistory() {
7089594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        HistoryAdapter adapter = (HistoryAdapter) mImageShow
709bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                .getHistoryAdapter();
7109594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        adapter.reset();
7119594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        ImagePreset original = new ImagePreset(adapter.getItem(0));
7129594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        mImageShow.setImagePreset(original);
7133992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        mPanelController.resetParameters();
7149594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        invalidateViews();
7150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // reset button in the history panel.
7180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private OnClickListener createOnClickResetOperationsButton() {
7190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        return new View.OnClickListener() {
7200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            @Override
7210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            public void onClick(View v) {
7229594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                resetHistory();
7230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            }
7240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        };
7250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
72775608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    @Override
72875608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    public void onBackPressed() {
72975608166f54891972ebad3d8fd958fed9a5300e6nicolasroard        if (mPanelController.onBackPressed()) {
73055550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard            saveImage();
73175608166f54891972ebad3d8fd958fed9a5300e6nicolasroard        }
73275608166f54891972ebad3d8fd958fed9a5300e6nicolasroard    }
733e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard
734e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard    public void cannotLoadImage() {
735e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        CharSequence text = getString(R.string.cannot_load_image);
736e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
737e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        toast.show();
738e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        finish();
739e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard    }
740e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard
7410d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
7420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7430d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public float getPixelsFromDip(float value) {
7440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Resources r = getResources();
7450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
7460d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                r.getDisplayMetrics());
7470d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
74908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    public void useImagePreset(ImageSmallFilter imageSmallFilter, ImagePreset preset) {
7500d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (preset == null) {
7510d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            return;
7520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
75308458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
75408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        if (mCurrentImageSmallFilter != null) {
75508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            mCurrentImageSmallFilter.setSelected(false);
75608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        }
75708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter = imageSmallFilter;
75808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter.setSelected(true);
75908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
7600d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset copy = new ImagePreset(preset);
7610d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.setImagePreset(copy);
7620d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (preset.isFx()) {
7630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            // if it's an FX we rest the curve adjustment too
7640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            mImageCurves.resetCurve();
7650d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
7660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7680d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
76908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard    public void useImageFilter(ImageSmallFilter imageSmallFilter, ImageFilter imageFilter,
77008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            boolean setBorder) {
7710d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (imageFilter == null) {
7720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            return;
7730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
77408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
77508458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        if (mCurrentImageSmallFilter != null) {
77608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            mCurrentImageSmallFilter.setSelected(false);
77708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        }
77808458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter = imageSmallFilter;
77908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        mCurrentImageSmallFilter.setSelected(true);
78008458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
7810d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset oldPreset = mImageShow.getImagePreset();
7820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ImagePreset copy = new ImagePreset(oldPreset);
7830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use a numerical constant instead.
784a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
785a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        copy.add(imageFilter);
786a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
787bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mImageShow.setImagePreset(copy);
7880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7900d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    @Override
7920d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onItemClick(AdapterView<?> parent, View view, int position,
7930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            long id) {
7940d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.onItemClick(position);
7950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        invalidateViews();
7960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
7970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
7980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void pickImage() {
7990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Intent intent = new Intent();
8000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        intent.setType("image/*");
8010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        intent.setAction(Intent.ACTION_GET_CONTENT);
8020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
8030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                SELECT_PICTURE);
8040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
80692e2341248e99c691f38820503984bc5e2f18811nicolasroard    @Override
8070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onActivityResult(int requestCode, int resultCode, Intent data) {
8080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Log.v(LOGTAG, "onActivityResult");
8090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (resultCode == RESULT_OK) {
8100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            if (requestCode == SELECT_PICTURE) {
8110d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                Uri selectedImageUri = data.getData();
8120f7dc6ef6e736c0993240450b50b91721c79c43eRuben Brunk                mImageLoader.loadBitmap(selectedImageUri, getScreenImageSize());
8130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            }
8140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
8150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void saveImage() {
81855550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard        if (mImageShow.hasModifications()) {
81955550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard            showSavingProgress();
82055550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard            mImageShow.saveImage(this, null);
82155550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard        } else {
82255550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard            finish();
82355550694a3f40fbf5dfc95c35a8e253aedab931enicolasroard        }
8240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    static {
827e3f9f579d73af613a33ba1d0a93dc101ea671a69nicolasroard        System.loadLibrary("jni_filtershow_filters");
8280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard}
831