FilterShowActivity.java revision e34a5a5eaedb870798a5cc7415079d04a6ca42e0
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;
117ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
1180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    @Override
1190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void onCreate(Bundle savedInstanceState) {
1200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        super.onCreate(savedInstanceState);
1210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1225448bf8095483574649afcc2add7f153670c7450nicolasroard        ImageFilterRS.setRenderScriptContext(this);
1235448bf8095483574649afcc2add7f153670c7450nicolasroard
1245ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        // TODO: get those values from XML.
1255ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextSize((int) getPixelsFromDip(12));
1265ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageShow.setTextPadding((int) getPixelsFromDip(10));
1275ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextSize((int) getPixelsFromDip(12));
1285ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageButtonTitle.setTextPadding((int) getPixelsFromDip(10));
1295ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageSmallFilter.setMargin((int) getPixelsFromDip(6));
1305ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        ImageSmallFilter.setTextMargin((int) getPixelsFromDip(4));
1315ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        mImageBorderSize = (int) getPixelsFromDip(20);
1323992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Drawable curveHandle = getResources().getDrawable(R.drawable.camera_crop_holo);
1333992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        int curveHandleSize = (int) getResources().getDimension(R.dimen.crop_indicator_size);
1343992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Spline.setCurveHandle(curveHandle, curveHandleSize);
1353992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        Spline.setCurveWidth((int) getPixelsFromDip(3));
1365ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard
1370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        setContentView(R.layout.filtershow_activity);
1389594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        ActionBar actionBar = getActionBar();
139786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
140786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.setCustomView(R.layout.filtershow_actionbar);
141786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard
142786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        actionBar.getCustomView().setOnClickListener(new OnClickListener() {
143786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            @Override
144786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            public void onClick(View view) {
145786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard                saveImage();
146786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard            }
147786fe6476e4ccf4b98489ff69d8ef439533cdc2anicolasroard        });
1480d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
149e34a5a5eaedb870798a5cc7415079d04a6ca42e0nicolasroard        mImageLoader = new ImageLoader(this, getApplicationContext());
1500d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1510d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters);
1520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders);
153ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx);
1540d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow = (ImageShow) findViewById(R.id.imageShow);
1560d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageCurves = (ImageCurves) findViewById(R.id.imageCurves);
1570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageBorders = (ImageBorder) findViewById(R.id.imageBorder);
1580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten);
1595448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageZoom = (ImageZoom) findViewById(R.id.imageZoom);
16062e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop = (ImageCrop) findViewById(R.id.imageCrop);
1618537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate = (ImageRotate) findViewById(R.id.imageRotate);
1628537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip = (ImageFlip) findViewById(R.id.imageFlip);
1630d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1640d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageShow);
1650d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageCurves);
1660d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageBorders);
1670d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageViews.add(mImageStraighten);
1685448bf8095483574649afcc2add7f153670c7450nicolasroard        mImageViews.add(mImageZoom);
16962e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageViews.add(mImageCrop);
1708537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageRotate);
1718537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageViews.add(mImageFlip);
1720d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1730d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListFx = findViewById(R.id.fxList);
1740d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListBorders = findViewById(R.id.bordersList);
17592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListGeometry = findViewById(R.id.geometryList);
17692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListFilterButtons = findViewById(R.id.filterButtonsList);
1770d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListColors = findViewById(R.id.colorsFxList);
1780d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListFx);
1790d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListBorders);
1800d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListGeometry);
18192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mListViews.add(mListFilterButtons);
1820d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mListViews.add(mListColors);
1830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
1840d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mFxButton = (ImageButton) findViewById(R.id.fxButton);
1850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mBorderButton = (ImageButton) findViewById(R.id.borderButton);
1860d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mGeometryButton = (ImageButton) findViewById(R.id.geometryButton);
1870d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mColorsButton = (ImageButton) findViewById(R.id.colorsButton);
18892e2341248e99c691f38820503984bc5e2f18811nicolasroard
18992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setImageLoader(mImageLoader);
19092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setImageLoader(mImageLoader);
19192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageCurves.setMaster(mImageShow);
19292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setImageLoader(mImageLoader);
19392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageBorders.setMaster(mImageShow);
19492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setImageLoader(mImageLoader);
19592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageStraighten.setMaster(mImageShow);
19692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setImageLoader(mImageLoader);
19792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageZoom.setMaster(mImageShow);
19862e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setImageLoader(mImageLoader);
19962e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mImageCrop.setMaster(mImageShow);
2008537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setImageLoader(mImageLoader);
2018537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageRotate.setMaster(mImageShow);
2028537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setImageLoader(mImageLoader);
2038537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mImageFlip.setMaster(mImageShow);
20492e2341248e99c691f38820503984bc5e2f18811nicolasroard
20592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageShow));
20692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageCurves));
20792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageBorder));
20892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageStraighten));
20962e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addImageView(findViewById(R.id.imageCrop));
2108537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageRotate));
2118537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.addImageView(findViewById(R.id.imageFlip));
21292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addImageView(findViewById(R.id.imageZoom));
21392e2341248e99c691f38820503984bc5e2f18811nicolasroard
21492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mFxButton, mListFx, 0);
21592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mBorderButton, mListBorders, 1);
21692e2341248e99c691f38820503984bc5e2f18811nicolasroard
21792e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mGeometryButton, mListGeometry, 2);
21892e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton));
21962e962bcb9fc03f3cfeac5ece8d3e95fc2dd0718Ruben Brunk        mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton));
22092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton));
22192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton));
22292e2341248e99c691f38820503984bc5e2f18811nicolasroard
22392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addPanel(mColorsButton, mListColors, 3);
224ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
225ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []recastIDs = {
226ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vignetteButton,
227ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.vibranceButton,
228ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.contrastButton,
229ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.saturationButton,
230ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.wbalanceButton,
231ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.hueButton,
232ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.exposureButton,
233ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.shadowRecoveryButton
234ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
235ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        ImageFilter []filters = {
236ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVignette(),
237ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterVibrance(),
238ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterContrast(),
239ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterSaturated(),
240ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterWBalance(),
241ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterHue(),
242ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterExposure(),
243ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                new ImageFilterShadows()
244ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
245ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
246ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
247ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        for (int i = 0; i < filters.length; i++) {
248ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
249ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageSmallFilter fView = new ImageSmallFilter(this);
250ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(recastIDs[i]);
251ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
252ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
253ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
254ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            filters[i].setParameter(100);
255ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(filters[i]);
256ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
257ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
258ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(recastIDs[i]);
259ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
260ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
261ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.addView(fView,pos);
262ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
263ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
264ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayIDs = {
265ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.sharpenButton,
266ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.id.curvesButtonRGB
267ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
268ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayBitmaps = {
269ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_sharpen,
270ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.drawable.filtershow_button_colors_curve
271ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
272ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        int []overlayNames = {
273ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.sharpen,
274ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                R.string.curvesRGB
275ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        };
276ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
277ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        for (int i = 0; i < overlayIDs.length; i++)  {
278ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageWithIcon fView = new ImageWithIcon(this);
279ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            View v = listColors.findViewById(overlayIDs[i]);
280ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            int pos = listColors.indexOfChild(v);
281ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.removeView(v);
282ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            final int sid =overlayNames[i];
283ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            ImageFilterExposure efilter = new ImageFilterExposure(){
284ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                {
285ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                    mName = getString(sid);
286ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                }
287ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            };
288ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            efilter.setParameter(-300);
289ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
290ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford                    overlayBitmaps[i] );
291ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
292ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setIcon(bitmap);
293ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageFilter(efilter);
294ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setController(this);
295ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setImageLoader(mImageLoader);
296ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            fView.setId(overlayIDs[i]);
297ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
298ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            mPanelController.addComponent(mColorsButton, fView);
299ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford            listColors.addView(fView,pos);
300ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford        }
301ea5df36ac1cdfbb569e6ba725c2df433d614d0f5John Hoford
30292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.curvesButtonRGB));
30392e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.sharpenButton));
30492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.vibranceButton));
30592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.contrastButton));
30692e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.saturationButton));
3074988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.wbalanceButton));
3084988eff4c8eda325a616337d1aaa0666cc301a7cJohn Hoford        mPanelController.addComponent(mColorsButton, findViewById(R.id.hueButton));
30992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.exposureButton));
31092e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addComponent(mColorsButton, findViewById(R.id.shadowRecoveryButton));
31192e2341248e99c691f38820503984bc5e2f18811nicolasroard
31292e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.addView(findViewById(R.id.applyEffect));
3133992ae6cf1cbb7b57a22d8287c40451558408335nicolasroard        mPanelController.addView(findViewById(R.id.pickCurvesChannel));
3140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        findViewById(R.id.resetOperationsButton).setOnClickListener(
3150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard                createOnClickResetOperationsButton());
3160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        ListView operationsList = (ListView) findViewById(R.id.operationsList);
318bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        operationsList.setAdapter(mImageShow.getHistoryAdapter());
3190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        operationsList.setOnItemClickListener(this);
320bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        ListView imageStateList = (ListView) findViewById(R.id.imageStateList);
321bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        imageStateList.setAdapter(mImageShow.getImageStateAdapter());
322bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mImageLoader.setAdapter((HistoryAdapter) mImageShow.getHistoryAdapter());
3230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
3240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListImages(listFilters);
3250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        fillListBorders(listBorders);
3260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
32792e2341248e99c691f38820503984bc5e2f18811nicolasroard        SeekBar seekBar = (SeekBar) findViewById(R.id.filterSeekBar);
32892e2341248e99c691f38820503984bc5e2f18811nicolasroard        seekBar.setMax(200);
32992e2341248e99c691f38820503984bc5e2f18811nicolasroard        mImageShow.setSeekBar(seekBar);
330de154778c8f94121cb2117fcf6224c40c01b6132nicolasroard        mImageZoom.setSeekBar(seekBar);
33192e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setRowPanel(findViewById(R.id.secondRowPanel));
3328537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk        mPanelController.setUtilityPanel(this, findViewById(R.id.filterButtonsList),
33392e2341248e99c691f38820503984bc5e2f18811nicolasroard                findViewById(R.id.applyEffect));
33492e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setMasterImage(mImageShow);
33592e2341248e99c691f38820503984bc5e2f18811nicolasroard        mPanelController.setCurrentPanel(mFxButton);
3360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        Intent intent = getIntent();
3370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        String data = intent.getDataString();
3380d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        if (data != null) {
3390d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            Uri uri = Uri.parse(data);
340fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford            mImageLoader.loadBitmap(uri,getScreenImageSize());
3410d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        } else {
3420d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            pickImage();
3430d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
3440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
3450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
346fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford    private int getScreenImageSize(){
347fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        DisplayMetrics metrics = new  DisplayMetrics();
348fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        Display display = getWindowManager().getDefaultDisplay();
349fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        Point size = new  Point();
350fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getSize(size);
351fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        display.getMetrics(metrics);
352fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        int msize = Math.min(size.x, size.y);
353fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford        return  (133*msize)/metrics.densityDpi;
354fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford    }
355fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford
356ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void showSavingProgress() {
357ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        ProgressDialog progress;
358ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
359ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            progress = mSavingProgressDialog.get();
360ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            if (progress != null) {
361ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                progress.show();
362ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu                return;
363ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            }
364ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
365ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        // TODO: Allow cancellation of the saving process
366ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        progress = ProgressDialog.show(this, "", getString(R.string.saving_image), true, false);
367ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        mSavingProgressDialog = new WeakReference<ProgressDialog>(progress);
368ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
369ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
370ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    private void hideSavingProgress() {
371ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        if (mSavingProgressDialog != null) {
372ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu            ProgressDialog progress = mSavingProgressDialog.get();
37308458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            if (progress != null)
37408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard                progress.dismiss();
375ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        }
376ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu    }
377ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu
3780ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public void completeSaveImage(Uri saveUri) {
3790ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        if (mSharingImage && mSharedOutputFile != null) {
3800ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            // Image saved, we unblock the content provider
3810ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
3820ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                    Uri.encode(mSharedOutputFile.getAbsolutePath()));
3830ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            ContentValues values = new ContentValues();
3840ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            values.put(SharedImageProvider.PREPARE, false);
3850ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard            getContentResolver().insert(uri, values);
3860ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        }
3870ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        setResult(RESULT_OK, new Intent().setData(saveUri));
388ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        hideSavingProgress();
3890ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        finish();
3900ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
3910ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
3920ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    @Override
3930ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) {
39492e2341248e99c691f38820503984bc5e2f18811nicolasroard        // First, let's tell the SharedImageProvider that it will need to wait
39592e2341248e99c691f38820503984bc5e2f18811nicolasroard        // for the image
3960ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
3970ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
3980ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        ContentValues values = new ContentValues();
3990ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        values.put(SharedImageProvider.PREPARE, true);
4000ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        getContentResolver().insert(uri, values);
4010ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharingImage = true;
4020ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4030ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        // Process and save the image in the background.
404ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        showSavingProgress();
4050ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mImageShow.saveImage(this, mSharedOutputFile);
4060ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return true;
4070ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4080ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4090ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    private Intent getDefaultShareIntent() {
4100ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Intent intent = new Intent(Intent.ACTION_SEND);
4110ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
4120ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
4130ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.setType(SharedImageProvider.MIME_TYPE);
4140ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mSharedOutputFile = SaveCopyTask.getNewFile(this, mImageLoader.getUri());
4150ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
4160ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                Uri.encode(mSharedOutputFile.getAbsolutePath()));
4170ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        intent.putExtra(Intent.EXTRA_STREAM, uri);
4180ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        return intent;
4190ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard    }
4200ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard
4219594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    @Override
4229594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onCreateOptionsMenu(Menu menu) {
4239594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
424bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showHistory = menu.findItem(R.id.operationsButton);
4259594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        if (mShowingHistoryPanel) {
426bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.hide_history_panel);
427bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        } else {
428bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showHistory.setTitle(R.string.show_history_panel);
429bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        }
430bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        MenuItem showState = menu.findItem(R.id.showImageStateButton);
431bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        if (mShowingImageStatePanel) {
432bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.hide_imagestate_panel);
4339594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        } else {
434bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            showState.setTitle(R.string.show_imagestate_panel);
4359594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
4360ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
4370ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard                .getActionProvider();
4380ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setShareIntent(getDefaultShareIntent());
4390ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mShareActionProvider.setOnShareTargetSelectedListener(this);
4409594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return true;
4419594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
4429594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
44392e2341248e99c691f38820503984bc5e2f18811nicolasroard    @Override
4446e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onPause() {
4456e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onPause();
4466e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4476e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(null);
4486e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4496e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4506e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4516e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4526e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    public void onResume() {
4536e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        super.onResume();
4546e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        if (mShareActionProvider != null) {
4556e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu            mShareActionProvider.setOnShareTargetSelectedListener(this);
4566e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu        }
4576e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    }
4586e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu
4596e733b74465ad6994c23d624fd8ee9b7c249e7b3Bobby Georgescu    @Override
4609594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    public boolean onOptionsItemSelected(MenuItem item) {
4619594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        switch (item.getItemId()) {
4629594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.undoButton: {
4639594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
464bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4659594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.undo();
4669594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4679594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Undo");
4689594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4699594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4709594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4719594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.redoButton: {
4729594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                HistoryAdapter adapter = (HistoryAdapter) mImageShow
473bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                        .getHistoryAdapter();
4749594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                int position = adapter.redo();
4759594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.onItemClick(position);
4769594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                mImageShow.showToast("Redo");
4779594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                invalidateViews();
4789594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4799594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
480f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            case R.id.resetHistoryButton: {
481f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                resetHistory();
482f47e790e3f3553f69abe054eec20bd7585118843nicolasroard                return true;
483f47e790e3f3553f69abe054eec20bd7585118843nicolasroard            }
484bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            case R.id.showImageStateButton: {
485bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                toggleImageStatePanel();
486bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard                return true;
487bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            }
4889594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case R.id.operationsButton: {
4899594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                toggleHistoryPanel();
4909594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4919594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4929594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            case android.R.id.home: {
4939594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                saveImage();
4949594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard                return true;
4959594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard            }
4969594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        }
4979594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard        return false;
4989594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard    }
4999594c8d3e0dd0d6157710ceae1d1deea8e566db4nicolasroard
5000d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    private void fillListImages(LinearLayout listFilters) {
5010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: use listview
5020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        // TODO: load the filters straight from the filesystem
503a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
504a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageFilterFx[] fxArray = new ImageFilterFx[18];
5050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        int p = 0;
506457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
50708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] drawid = {
508457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0000_vintage,
509457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0001_instant,
510457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0002_bleach,
511457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0003_blue_crush,
512457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0004_bw_contrast,
513457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0005_punch,
514457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0006_x_process,
515457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0007_washout,
516457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.drawable.filtershow_fx_0008_washout_color
517457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
518457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
51908458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        int[] fxNameid = {
520457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_vintage,
521457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_instant,
522457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bleach,
523457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_blue_crush,
524457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_bw_contrast,
525457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_punch,
526457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_x_process,
527457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout,
528457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford                R.string.ffx_washout_color,
529457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        };
530457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
531a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImagePreset preset = new ImagePreset(); // empty
532a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageSmallFilter filter = new ImageSmallFilter(this);
533a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
534a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setSelected(true);
535a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        mCurrentImageSmallFilter = filter;
536a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
537a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setPreviousImageSmallFilter(null);
53820fb632c407a2dfb5ec769560c61deacc77b8764John Hoford        filter.setImageFilter(new ImageFilterFx(null,ImageFilterFx.ORIG));
539a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
540a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setController(this);
541a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        filter.setImageLoader(mImageLoader);
542a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        listFilters.addView(filter);
543a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford        ImageSmallFilter   previousFilter = filter;
544a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
54553f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        BitmapFactory.Options o = new BitmapFactory.Options();
54653f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford        o.inScaled = false;
54708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard
548457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        for (int i = 0; i < drawid.length; i++) {
54953f24f0fbfd787a4ab2f129499d2c7ef240a517fJohn Hoford            Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i], o);
550a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            fxArray[p++] = new ImageFilterFx(b, getString(fxNameid[i]));
551457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford        }
552457e88cd2ba6a8a93b1643a3fb3d50ee758671adJohn Hoford
5530d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
554a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford            filter = new ImageSmallFilter(this);
555a19830b4fd9050b48386cd904d99cfd2566cc515John Hoford
55608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            filter.setPreviousImageSmallFilter(previousFilter);
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);
5805ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.BLACK, mImageBorderSize, mImageBorderSize);
5815ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, 0);
5825ec40a6ba587fa8bd50958d263bb6fc6280de4c1nicolasroard        borders[p++] = new ImageFilterParametricBorder(Color.WHITE, mImageBorderSize, mImageBorderSize);
5830d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
58408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard        ImageSmallFilter previousFilter = null;
5850d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (int i = 0; i < p; i++) {
58608458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            ImageSmallBorder filter = new ImageSmallBorder(this);
58708458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            filter.setPreviousImageSmallFilter(previousFilter);
5880d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageFilter(borders[i]);
5890d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setController(this);
59093dfe7a1df07a64701369b480578410efb740a27nicolasroard            filter.setBorder(true);
5910d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            filter.setImageLoader(mImageLoader);
592bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard            filter.setShowTitle(false);
5930d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            listBorders.addView(filter);
59408458dc637d92ee5f12e34d49c34cc10f4e19c7dnicolasroard            previousFilter = filter;
5950d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
5960d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
5970d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
5980d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // //////////////////////////////////////////////////////////////////////////////
5990d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    // Some utility functions
60092e2341248e99c691f38820503984bc5e2f18811nicolasroard    // TODO: finish the cleanup.
6010d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6020d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void showOriginalViews(boolean value) {
6030d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
6040d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.showOriginal(value);
6050d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6060d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6070d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6080d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void invalidateViews() {
6090d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageShow views : mImageViews) {
6100d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            views.invalidate();
6118537d097f8827caedc8c39564de54d36eae8b16fRuben Brunk            views.updateImage();
6120d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideListViews() {
6160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mListViews) {
6170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6190d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void hideImageViews() {
6220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        mImageShow.setShowControls(false); // reset
6230d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (View view : mImageViews) {
6240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            view.setVisibility(View.GONE);
6250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectBottomPanelButtons() {
6290d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : mBottomPanelButtons) {
6300d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6310d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
6320d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
6330d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
6340d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void unselectPanelButtons(Vector<ImageButton> buttons) {
6350d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        for (ImageButton button : buttons) {
6360d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            button.setSelected(false);
6370d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
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()) {
73075608166f54891972ebad3d8fd958fed9a5300e6nicolasroard            finish();
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();
812fafb2edbb9928039b887f59685d82593bd79e06aJohn Hoford                mImageLoader.loadBitmap(selectedImageUri,getScreenImageSize());
8130d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard            }
8140d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard        }
8150d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    public void saveImage() {
818ec29b73d77a8ff2f000eb04d662d85d63d8f8d09Bobby Georgescu        showSavingProgress();
8190ee91a2b74808fa3f51d370daaddf99f588d72efnicolasroard        mImageShow.saveImage(this, null);
8200d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    static {
823e3f9f579d73af613a33ba1d0a93dc101ea671a69nicolasroard        System.loadLibrary("jni_filtershow_filters");
8240d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard    }
8250d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard
8260d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard}
827