Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 355eaea0 authored by Angus Kong's avatar Angus Kong Committed by Android (Google) Code Review
Browse files

Merge "Add more gestures and animations in FilmStripView." into gb-ub-photos-bryce

parents 7811d8de be3e9920
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.widget.ImageView;

import com.android.camera.Storage;
import com.android.camera.ui.FilmStripView;
import com.android.camera.ui.FilmStripView.ImageData;

import java.util.ArrayList;
import java.util.List;
@@ -79,7 +80,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {

    private List<LocalImageData> mImages;

    private FilmStripView mFilmStripView;
    private Listener mListener;
    private View mCameraPreviewView;
    private ColorDrawable mPlaceHolder;

@@ -101,7 +102,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
    }

    @Override
    public FilmStripView.ImageData getImageData(int id) {
    public ImageData getImageData(int id) {
        if (id >= mImages.size()) return null;
        return mImages.get(id);
    }
@@ -142,8 +143,8 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
    }

    @Override
    public void setDataListener(FilmStripView v) {
        mFilmStripView = v;
    public void setListener(Listener listener) {
        mListener = listener;
    }

    private LocalImageData buildCameraImageData(int width, int height, int orientation) {
@@ -152,6 +153,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
        d.height = height;
        d.orientation = orientation;
        d.isCameraData = true;
        d.supportedAction = ImageData.ACTION_NONE;
        return d;
    }

@@ -179,6 +181,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
        d.orientation = c.getInt(COL_ORIENTATION);
        d.width = c.getInt(COL_WIDTH);
        d.height = c.getInt(COL_HEIGHT);
        d.supportedAction = ImageData.ACTION_PROMOTE | ImageData.ACTION_DEMOTE;
        if (d.width <= 0 || d.height <= 0) {
            Log.v(TAG, "warning! zero dimension for "
                    + d.path + ":" + d.width + "x" + d.height);
@@ -229,6 +232,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
        // width and height should be adjusted according to orientation.
        public int width;
        public int height;
        public int supportedAction;

        @Override
        public int getWidth() {
@@ -240,6 +244,17 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
            return height;
        }

        @Override
        public int getType() {
            if (isCameraData) return ImageData.TYPE_CAMERA_PREVIEW;
            return ImageData.TYPE_PHOTO;
        }

        @Override
        public boolean isActionSupported(int action) {
            return ((action & supportedAction) != 0);
        }

        @Override
        public String toString() {
            return "LocalImageData:" + ",data=" + path + ",mimeType=" + mimeType
@@ -281,7 +296,7 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
            mImages = l;
            if (first != null) addOrReplaceCameraData(first);
            // both might be null.
            if (changed) mFilmStripView.onDataChanged();
            if (changed && mListener != null) mListener.onDataLoaded();
        }
    }

+107 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 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.camera.ui;

import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

// This class aggregates three gesture detectors: GestureDetector,
// ScaleGestureDetector.
public class FilmStripGestureRecognizer {
    @SuppressWarnings("unused")
    private static final String TAG = "FilmStripGestureRecognizer";

    public interface Listener {
        boolean onSingleTapUp(float x, float y);
        boolean onDoubleTap(float x, float y);
        boolean onScroll(float x, float y, float dx, float dy);
        boolean onFling(float velocityX, float velocityY);
        boolean onScaleBegin(float focusX, float focusY);
        boolean onScale(float focusX, float focusY, float scale);
        boolean onDown(float x, float y);
        void onScaleEnd();
    }

    private final GestureDetector mGestureDetector;
    private final ScaleGestureDetector mScaleDetector;
    private final Listener mListener;

    public FilmStripGestureRecognizer(Context context, Listener listener) {
        mListener = listener;
        mGestureDetector = new GestureDetector(context, new MyGestureListener(),
                null, true /* ignoreMultitouch */);
        mScaleDetector = new ScaleGestureDetector(
                context, new MyScaleListener());
    }

    public boolean onTouchEvent(MotionEvent event) {
        return mGestureDetector.onTouchEvent(event) || mScaleDetector.onTouchEvent(event);
    }

    private class MyGestureListener
                extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return mListener.onSingleTapUp(e.getX(), e.getY());
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            return mListener.onDoubleTap(e.getX(), e.getY());
        }

        @Override
        public boolean onScroll(
                MotionEvent e1, MotionEvent e2, float dx, float dy) {
            return mListener.onScroll(e2.getX(), e2.getY(), dx, dy);
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            return mListener.onFling(velocityX, velocityY);
        }

        @Override
        public boolean onDown(MotionEvent e) {
            mListener.onDown(e.getX(), e.getY());
            return super.onDown(e);
        }
    }

    private class MyScaleListener
            extends ScaleGestureDetector.SimpleOnScaleGestureListener {
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            return mListener.onScaleBegin(
                    detector.getFocusX(), detector.getFocusY());
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            return mListener.onScale(detector.getFocusX(),
                    detector.getFocusY(), detector.getScaleFactor());
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            mListener.onScaleEnd();
        }
    }
}
+430 −113

File changed.

Preview size limit exceeded, changes collapsed.