summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java
blob: 5e007b1eb746718f0b82c1f19e9bfb0776f0cb71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.gallery3d.filtershow.imageshow;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.HistoryAdapter;
import com.android.gallery3d.filtershow.ImageStateAdapter;
import com.android.gallery3d.filtershow.PanelController;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.presets.ImagePreset;
import com.android.gallery3d.filtershow.ui.SliderController;
import com.android.gallery3d.filtershow.ui.SliderListener;

import java.io.File;

public class ImageShow extends View implements OnGestureListener,
        OnDoubleTapListener,
        SliderListener,
        OnSeekBarChangeListener {

    private static final String LOGTAG = "ImageShow";

    protected Paint mPaint = new Paint();
    protected static int mTextSize = 24;
    protected static int mTextPadding = 20;

    protected ImagePreset mImagePreset = null;
    protected ImagePreset mImageGeometryOnlyPreset = null;
    protected ImagePreset mImageFiltersOnlyPreset = null;

    protected ImageLoader mImageLoader = null;
    private ImageFilter mCurrentFilter = null;
    private boolean mDirtyGeometry = true;

    private Bitmap mBackgroundImage = null;
    private final boolean USE_BACKGROUND_IMAGE = false;
    private static int mBackgroundColor = Color.RED;

    private Bitmap mGeometryOnlyImage = null;
    private Bitmap mFiltersOnlyImage = null;
    private Bitmap mFilteredImage = null;

    private final boolean USE_SLIDER_GESTURE = false; // set to true to have
                                                      // slider gesture
    protected SliderController mSliderController = new SliderController();

    private GestureDetector mGestureDetector = null;

    private HistoryAdapter mHistoryAdapter = null;
    private ImageStateAdapter mImageStateAdapter = null;

    private Rect mImageBounds = null;

    private boolean mTouchShowOriginal = false;
    private long mTouchShowOriginalDate = 0;
    private final long mTouchShowOriginalDelayMin = 200; // 200ms
    private final long mTouchShowOriginalDelayMax = 300; // 300ms
    private int mShowOriginalDirection = 0;
    private static int UNVEIL_HORIZONTAL = 1;
    private static int UNVEIL_VERTICAL = 2;

    private int mTouchDownX = 0;
    private int mTouchDownY = 0;
    protected float mTouchX = 0;
    protected float mTouchY = 0;

    private static int mOriginalTextMargin = 8;
    private static int mOriginalTextSize = 26;
    private static String mOriginalText = "Original";

    protected GeometryMetadata getGeometry() {
        return new GeometryMetadata(getImagePreset().mGeoData);
    }

    public void setGeometry(GeometryMetadata d) {
        getImagePreset().mGeoData.set(d);
    }

    private boolean mShowControls = false;
    private boolean mShowOriginal = false;
    private String mToast = null;
    private boolean mShowToast = false;
    private boolean mImportantToast = false;

    private SeekBar mSeekBar = null;
    private PanelController mController = null;

    private FilterShowActivity mActivity = null;

    public static void setDefaultBackgroundColor(int value) {
        mBackgroundColor = value;
    }

    public static void setTextSize(int value) {
        mTextSize = value;
    }

    public static void setTextPadding(int value) {
        mTextPadding = value;
    }

    public static void setOriginalTextMargin(int value) {
        mOriginalTextMargin = value;
    }

    public static void setOriginalTextSize(int value) {
        mOriginalTextSize = value;
    }

    public static void setOriginalText(String text) {
        mOriginalText = text;
    }

    private final Handler mHandler = new Handler();

    public void select() {
        if (getCurrentFilter() != null) {
            int parameter = getCurrentFilter().getParameter();
            int maxp = getCurrentFilter().getMaxParameter();
            int minp = getCurrentFilter().getMinParameter();
            updateSeekBar(parameter, minp, maxp);
        }
        if (mSeekBar != null) {
            mSeekBar.setOnSeekBarChangeListener(this);
        }
    }

    private int parameterToUI(int parameter, int minp, int maxp, int uimax) {
        return (uimax * (parameter - minp)) / (maxp - minp);
    }

    private int uiToParameter(int ui, int minp, int maxp, int uimax) {
        return ((maxp - minp) * ui) / uimax + minp;
    }

    public void updateSeekBar(int parameter, int minp, int maxp) {
        if (mSeekBar == null) {
            return;
        }
        int seekMax = mSeekBar.getMax();
        int progress = parameterToUI(parameter, minp, maxp, seekMax);
        mSeekBar.setProgress(progress);
        if (getPanelController() != null) {
            getPanelController().onNewValue(parameter);
        }
    }

    public void unselect() {

    }

    public boolean hasModifications() {
        if (getImagePreset() == null) {
            return false;
        }
        return getImagePreset().hasModifications();
    }

    public void resetParameter() {
        ImageFilter currentFilter = getCurrentFilter();
        if (currentFilter != null) {
            onNewValue(currentFilter.getDefaultParameter());
        }
        if (USE_SLIDER_GESTURE) {
            mSliderController.reset();
        }
    }

    public void setPanelController(PanelController controller) {
        mController = controller;
    }

    public PanelController getPanelController() {
        return mController;
    }

    @Override
    public void onNewValue(int parameter) {
        int maxp = 100;
        int minp = -100;
        if (getCurrentFilter() != null) {
            getCurrentFilter().setParameter(parameter);
            maxp = getCurrentFilter().getMaxParameter();
            minp = getCurrentFilter().getMinParameter();
        }
        if (getImagePreset() != null) {
            mImageLoader.resetImageForPreset(getImagePreset(), this);
            getImagePreset().fillImageStateAdapter(mImageStateAdapter);
        }
        if (getPanelController() != null) {
            getPanelController().onNewValue(parameter);
        }
        updateSeekBar(parameter, minp, maxp);
        invalidate();
    }

    @Override
    public void onTouchDown(float x, float y) {
        mTouchX = x;
        mTouchY = y;
        invalidate();
    }

    @Override
    public void onTouchUp() {
    }

    public ImageShow(Context context, AttributeSet attrs) {
        super(context, attrs);
        if (USE_SLIDER_GESTURE) {
            mSliderController.setListener(this);
        }
        mHistoryAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
                R.id.rowTextView);
        mImageStateAdapter = new ImageStateAdapter(context,
                R.layout.filtershow_imagestate_row);
        setupGestureDetector(context);
        mActivity = (FilterShowActivity) context;
    }

    public ImageShow(Context context) {
        super(context);
        if (USE_SLIDER_GESTURE) {
            mSliderController.setListener(this);
        }
        mHistoryAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
                R.id.rowTextView);
        setupGestureDetector(context);
        mActivity = (FilterShowActivity) context;
    }

    public void setupGestureDetector(Context context) {
        mGestureDetector = new GestureDetector(context, this);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
        int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(parentWidth, parentHeight);
        if (USE_SLIDER_GESTURE) {
            mSliderController.setWidth(parentWidth);
            mSliderController.setHeight(parentHeight);
        }
    }

    public void setSeekBar(SeekBar seekBar) {
        mSeekBar = seekBar;
    }

    public void setCurrentFilter(ImageFilter filter) {
        mCurrentFilter = filter;
    }

    public ImageFilter getCurrentFilter() {
        return mCurrentFilter;
    }

    public void setAdapter(HistoryAdapter adapter) {
        mHistoryAdapter = adapter;
    }

    public void showToast(String text) {
        showToast(text, false);
    }

    public void showToast(String text, boolean important) {
        mToast = text;
        mShowToast = true;
        mImportantToast = important;
        invalidate();

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mShowToast = false;
                invalidate();
            }
        }, 400);
    }

    public Rect getImageBounds() {
        Rect dst = new Rect();
        getImagePreset().mGeoData.getPhotoBounds().roundOut(dst);
        return dst;
    }

    public Rect getDisplayedImageBounds() {
        return mImageBounds;
    }

    public ImagePreset getImagePreset() {
        return mImagePreset;
    }

    public void drawToast(Canvas canvas) {
        if (mShowToast && mToast != null) {
            Paint paint = new Paint();
            paint.setTextSize(128);
            float textWidth = paint.measureText(mToast);
            int toastX = (int) ((getWidth() - textWidth) / 2.0f);
            int toastY = (int) (getHeight() / 3.0f);

            paint.setARGB(255, 0, 0, 0);
            canvas.drawText(mToast, toastX - 2, toastY - 2, paint);
            canvas.drawText(mToast, toastX - 2, toastY, paint);
            canvas.drawText(mToast, toastX, toastY - 2, paint);
            canvas.drawText(mToast, toastX + 2, toastY + 2, paint);
            canvas.drawText(mToast, toastX + 2, toastY, paint);
            canvas.drawText(mToast, toastX, toastY + 2, paint);
            if (mImportantToast) {
                paint.setARGB(255, 200, 0, 0);
            } else {
                paint.setARGB(255, 255, 255, 255);
            }
            canvas.drawText(mToast, toastX, toastY, paint);
        }
    }

    public void defaultDrawImage(Canvas canvas) {
        drawImage(canvas, getFilteredImage());
        drawPartialImage(canvas, getGeometryOnlyImage());
    }

    @Override
    public void onDraw(Canvas canvas) {
        drawBackground(canvas);
        requestFilteredImages();
        defaultDrawImage(canvas);

        if (showTitle() && getImagePreset() != null) {
            mPaint.setARGB(200, 0, 0, 0);
            mPaint.setTextSize(mTextSize);

            Rect textRect = new Rect(0, 0, getWidth(), mTextSize + mTextPadding);
            canvas.drawRect(textRect, mPaint);
            mPaint.setARGB(255, 200, 200, 200);
            canvas.drawText(getImagePreset().name(), mTextPadding,
                    1.5f * mTextPadding, mPaint);
        }

        if (showControls()) {
            if (USE_SLIDER_GESTURE) {
                mSliderController.onDraw(canvas);
            }
        }

        drawToast(canvas);
    }

    public void resetImageCaches(ImageShow caller) {
        if (mImageLoader == null) {
            return;
        }
        if (getImagePreset() != null) {
            mImageLoader.resetImageForPreset(getImagePreset(), caller);
        }
        mImageGeometryOnlyPreset = null;
        mImageFiltersOnlyPreset = null;
        invalidate();
    }

    public void updateImagePresets(boolean force) {
        ImagePreset preset = getImagePreset();
        if (preset == null) {
            return;
        }
        if (force) {
            mImageLoader.resetImageForPreset(getImagePreset(), this);
        }
        if (force || mImageGeometryOnlyPreset == null) {
            mImageGeometryOnlyPreset = new ImagePreset(preset);
            mImageGeometryOnlyPreset.setDoApplyFilters(false);
            mGeometryOnlyImage = null;
        }
        if (force || mImageFiltersOnlyPreset == null) {
            mImageFiltersOnlyPreset = new ImagePreset(preset);
            mImageFiltersOnlyPreset.setDoApplyGeometry(false);
            mFiltersOnlyImage = null;
        }
    }

    public void requestFilteredImages() {
        if (mImageLoader != null) {
            Bitmap bitmap = mImageLoader.getImageForPreset(this,
                    getImagePreset(), showHires());

            if (bitmap != null) {
                if (mFilteredImage == null) {
                    invalidate();
                }
                mFilteredImage = bitmap;
            }

            updateImagePresets(false);
            if (mImageGeometryOnlyPreset != null) {
                mGeometryOnlyImage = mImageLoader.getImageForPreset(this, mImageGeometryOnlyPreset,
                        showHires());
            }
            if (mImageFiltersOnlyPreset != null) {
                mFiltersOnlyImage = mImageLoader.getImageForPreset(this, mImageFiltersOnlyPreset,
                        showHires());
            }
        }

        if (mShowOriginal) {
            mFilteredImage = mGeometryOnlyImage;
        }
    }

    public Bitmap getFiltersOnlyImage() {
        return mFiltersOnlyImage;
    }

    public Bitmap getGeometryOnlyImage() {
        return mGeometryOnlyImage;
    }

    public Bitmap getFilteredImage() {
        return mFilteredImage;
    }

    public void drawImage(Canvas canvas, Bitmap image) {
        if (image != null) {
            Rect s = new Rect(0, 0, image.getWidth(),
                    image.getHeight());
            float ratio = image.getWidth()
                    / (float) image.getHeight();
            float w = getWidth();
            float h = w / ratio;
            float ty = (getHeight() - h) / 2.0f;
            float tx = 0;
            if (ratio < 1.0f || (getHeight() < w)) {
                h = getHeight();
                w = h * ratio;
                tx = (getWidth() - w) / 2.0f;
                ty = 0;
            }
            Rect d = new Rect((int) tx, (int) ty, (int) (w + tx),
                    (int) (h + ty));
            mImageBounds = d;
            canvas.drawBitmap(image, s, d, mPaint);
        }
    }

    public void drawPartialImage(Canvas canvas, Bitmap image) {
        if (!mTouchShowOriginal)
            return;
        canvas.save();
        if (image != null) {
            if (mShowOriginalDirection == 0) {
                if ((mTouchY - mTouchDownY) > (mTouchX - mTouchDownX)) {
                    mShowOriginalDirection = UNVEIL_VERTICAL;
                } else {
                    mShowOriginalDirection = UNVEIL_HORIZONTAL;
                }
            }

            int px = 0;
            int py = 0;
            if (mShowOriginalDirection == UNVEIL_VERTICAL) {
                px = mImageBounds.width();
                py = (int) (mTouchY - mImageBounds.top);
            } else {
                px = (int) (mTouchX - mImageBounds.left);
                py = mImageBounds.height();
            }

            Rect d = new Rect(mImageBounds.left, mImageBounds.top,
                    mImageBounds.left + px, mImageBounds.top + py);
            canvas.clipRect(d);
            drawImage(canvas, image);
            Paint paint = new Paint();
            paint.setColor(Color.BLACK);

            if (mShowOriginalDirection == UNVEIL_VERTICAL) {
                canvas.drawLine(mImageBounds.left, mTouchY - 1,
                        mImageBounds.right, mTouchY - 1, paint);
            } else {
                canvas.drawLine(mTouchX - 1, mImageBounds.top,
                        mTouchX - 1, mImageBounds.bottom, paint);
            }

            Rect bounds = new Rect();
            paint.setTextSize(mOriginalTextSize);
            paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds);
            paint.setColor(Color.BLACK);
            canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin + 1,
                    mImageBounds.top + bounds.height() + mOriginalTextMargin + 1, paint);
            paint.setColor(Color.WHITE);
            canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin,
                    mImageBounds.top + bounds.height() + mOriginalTextMargin, paint);
        }
        canvas.restore();
    }

    public void drawBackground(Canvas canvas) {
        if (USE_BACKGROUND_IMAGE) {
            if (mBackgroundImage == null) {
                mBackgroundImage = mImageLoader.getBackgroundBitmap(getResources());
            }
            if (mBackgroundImage != null) {
                Rect s = new Rect(0, 0, mBackgroundImage.getWidth(),
                        mBackgroundImage.getHeight());
                Rect d = new Rect(0, 0, getWidth(), getHeight());
                canvas.drawBitmap(mBackgroundImage, s, d, mPaint);
            }
        } else {
            canvas.drawColor(mBackgroundColor);
        }
    }

    public ImageShow setShowControls(boolean value) {
        mShowControls = value;
        if (mShowControls) {
            if (mSeekBar != null) {
                mSeekBar.setVisibility(View.VISIBLE);
            }
        } else {
            if (mSeekBar != null) {
                mSeekBar.setVisibility(View.INVISIBLE);
            }
        }
        return this;
    }

    public boolean showControls() {
        return mShowControls;
    }

    public boolean showHires() {
        return true;
    }

    public boolean showTitle() {
        return false;
    }

    public void setImagePreset(ImagePreset preset) {
        setImagePreset(preset, true);
    }

    public void setImagePreset(ImagePreset preset, boolean addToHistory) {
        if (preset == null) {
            return;
        }
        mImagePreset = preset;
        getImagePreset().setImageLoader(mImageLoader);
        updateImagePresets(true);
        if (addToHistory) {
            mHistoryAdapter.addHistoryItem(getImagePreset());
        }
        getImagePreset().setEndpoint(this);
        updateImage();
        mImagePreset.fillImageStateAdapter(mImageStateAdapter);
        invalidate();
    }

    public void setImageLoader(ImageLoader loader) {
        mImageLoader = loader;
        if (mImageLoader != null) {
            mImageLoader.addListener(this);
            if (mImagePreset != null) {
                mImagePreset.setImageLoader(mImageLoader);
            }
        }
    }

    private void setDirtyGeometryFlag() {
        mDirtyGeometry = true;
    }

    protected void clearDirtyGeometryFlag() {
        mDirtyGeometry = false;
    }

    protected boolean getDirtyGeometryFlag() {
        return mDirtyGeometry;
    }

    private void imageSizeChanged(Bitmap image) {
        if (image == null || getImagePreset() == null)
            return;
        float w = image.getWidth();
        float h = image.getHeight();
        GeometryMetadata geo = getImagePreset().mGeoData;
        RectF pb = geo.getPhotoBounds();
        if (w == pb.width() && h == pb.height()) {
            return;
        }
        RectF r = new RectF(0, 0, w, h);
        getImagePreset().mGeoData.setPhotoBounds(r);
        getImagePreset().mGeoData.setCropBounds(r);
        setDirtyGeometryFlag();
    }

    public boolean updateGeometryFlags() {
        return true;
    }

    public void updateImage() {
        if (!updateGeometryFlags()) {
            return;
        }
        Bitmap bitmap = mImageLoader.getOriginalBitmapLarge();
        if (bitmap != null) {
            imageSizeChanged(bitmap);
            invalidate();
        }
    }

    public void updateFilteredImage(Bitmap bitmap) {
        mFilteredImage = bitmap;
    }

    public void saveImage(FilterShowActivity filterShowActivity, File file) {
        mImageLoader.saveImage(getImagePreset(), filterShowActivity, file);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
        if (USE_SLIDER_GESTURE) {
            mSliderController.onTouchEvent(event);
        }
        if (mGestureDetector != null) {
            mGestureDetector.onTouchEvent(event);
        }
        int ex = (int) event.getX();
        int ey = (int) event.getY();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mTouchDownX = ex;
            mTouchDownY = ey;
            mTouchShowOriginalDate = System.currentTimeMillis();
            mShowOriginalDirection = 0;
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            mTouchX = ex;
            mTouchY = ey;
            if (!mActivity.isShowingHistoryPanel()
                    && (System.currentTimeMillis() - mTouchShowOriginalDate
                    > mTouchShowOriginalDelayMin)) {
                mTouchShowOriginal = true;
            }
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
            mTouchShowOriginal = false;
            mTouchDownX = 0;
            mTouchDownY = 0;
            mTouchX = 0;
            mTouchY = 0;
        }
        invalidate();
        return true;
    }

    // listview stuff

    public HistoryAdapter getHistory() {
        return mHistoryAdapter;
    }

    public ArrayAdapter getImageStateAdapter() {
        return mImageStateAdapter;
    }

    public void onItemClick(int position) {
        setImagePreset(new ImagePreset(mHistoryAdapter.getItem(position)), false);
        // we need a copy from the history
        mHistoryAdapter.setCurrentPreset(position);
    }

    public void showOriginal(boolean show) {
        mShowOriginal = show;
        invalidate();
    }

    public float getImageRotation() {
        return getImagePreset().mGeoData.getRotation();
    }

    public float getImageRotationZoomFactor() {
        return getImagePreset().mGeoData.getScaleFactor();
    }

    public void setImageRotation(float r) {
        getImagePreset().mGeoData.setRotation(r);
    }

    public void setImageRotationZoomFactor(float f) {
        getImagePreset().mGeoData.setScaleFactor(f);
    }

    public void setImageRotation(float imageRotation,
            float imageRotationZoomFactor) {
        float r = getImageRotation();
        if (imageRotation != r) {
            invalidate();
        }
        setImageRotation(imageRotation);
        setImageRotationZoomFactor(imageRotationZoomFactor);
    }

    @Override
    public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
        int parameter = progress;
        if (getCurrentFilter() != null) {
            int maxp = getCurrentFilter().getMaxParameter();
            int minp = getCurrentFilter().getMinParameter();
            parameter = uiToParameter(progress, minp, maxp, arg0.getMax());
        }

        onNewValue(parameter);
    }

    @Override
    public void onStartTrackingTouch(SeekBar arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStopTrackingTouch(SeekBar arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onDoubleTap(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float arg2, float arg3) {
        if ((!mActivity.isShowingHistoryPanel() && startEvent.getX() > endEvent.getX())
                || (mActivity.isShowingHistoryPanel() && endEvent.getX() > startEvent.getX())) {
            if (!mTouchShowOriginal
                    || (mTouchShowOriginal &&
                    (System.currentTimeMillis() - mTouchShowOriginalDate
                    < mTouchShowOriginalDelayMax))) {
                mActivity.toggleHistoryPanel();
            }
        }
        return true;
    }

    @Override
    public void onLongPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

}