summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2013-09-05 18:13:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-05 18:13:37 +0000
commitc0e8b6880ae75c1f5811146ded4b060f8f1a6f84 (patch)
treed431be011b9322e7eecbb12a81b288597418ce09
parent9bd4d28163e3872de9c9019528cbb570f504fe05 (diff)
parent4b94060491eb14f4f1d40b86012414910325751a (diff)
downloadandroid_packages_apps_Trebuchet-c0e8b6880ae75c1f5811146ded4b060f8f1a6f84.zip
android_packages_apps_Trebuchet-c0e8b6880ae75c1f5811146ded4b060f8f1a6f84.tar.gz
android_packages_apps_Trebuchet-c0e8b6880ae75c1f5811146ded4b060f8f1a6f84.tar.bz2
Merge "Show and hide the wallpaper list in response to touch" into jb-ub-gel-agar
-rw-r--r--res/layout/wallpaper_picker.xml1
-rw-r--r--src/com/android/launcher3/CropView.java41
-rw-r--r--src/com/android/launcher3/WallpaperPickerActivity.java30
3 files changed, 69 insertions, 3 deletions
diff --git a/res/layout/wallpaper_picker.xml b/res/layout/wallpaper_picker.xml
index 493606d..347a63e 100644
--- a/res/layout/wallpaper_picker.xml
+++ b/res/layout/wallpaper_picker.xml
@@ -37,6 +37,7 @@
android:indeterminateOnly="true"
android:background="@android:color/transparent" />
<HorizontalScrollView
+ android:id="@+id/wallpaper_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
diff --git a/src/com/android/launcher3/CropView.java b/src/com/android/launcher3/CropView.java
index 25ab5cd..6d29be2 100644
--- a/src/com/android/launcher3/CropView.java
+++ b/src/com/android/launcher3/CropView.java
@@ -22,6 +22,7 @@ import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
+import android.view.ViewConfiguration;
import android.view.ScaleGestureDetector.OnScaleGestureListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
@@ -32,10 +33,18 @@ import com.android.photos.views.TiledImageView;
public class CropView extends TiledImageView implements OnScaleGestureListener {
private ScaleGestureDetector mScaleGestureDetector;
+ private long mTouchDownTime;
+ private float mFirstX, mFirstY;
private float mLastX, mLastY;
private float mMinScale;
private boolean mTouchEnabled = true;
private RectF mTempEdges = new RectF();
+ TouchCallback mTouchCallback;
+
+ public interface TouchCallback {
+ void onTouchDown();
+ void onTap();
+ }
public CropView(Context context) {
this(context, null);
@@ -152,11 +161,12 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
mTouchEnabled = enabled;
}
+ public void setTouchCallback(TouchCallback cb) {
+ mTouchCallback = cb;
+ }
+
@Override
public boolean onTouchEvent(MotionEvent event) {
- if (!mTouchEnabled) {
- return true;
- }
int action = event.getActionMasked();
final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
final int skipIndex = pointerUp ? event.getActionIndex() : -1;
@@ -174,6 +184,31 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
float x = sumX / div;
float y = sumY / div;
+ if (action == MotionEvent.ACTION_DOWN) {
+ mFirstX = x;
+ mFirstY = y;
+ mTouchDownTime = System.currentTimeMillis();
+ if (mTouchCallback != null) {
+ mTouchCallback.onTouchDown();
+ }
+ } else if (action == MotionEvent.ACTION_UP) {
+ ViewConfiguration config = ViewConfiguration.get(getContext());
+
+ float squaredDist = (mFirstX - x) * (mFirstX - x) + (mFirstY - y) * (mFirstY - y);
+ float slop = config.getScaledTouchSlop() * config.getScaledTouchSlop();
+ long now = System.currentTimeMillis();
+ // only do this if it's a small movement
+ if (mTouchCallback != null &&
+ squaredDist < slop &&
+ now < mTouchDownTime + ViewConfiguration.getTapTimeout()) {
+ mTouchCallback.onTap();
+ }
+ }
+
+ if (!mTouchEnabled) {
+ return true;
+ }
+
synchronized (mLock) {
mScaleGestureDetector.onTouchEvent(event);
switch (action) {
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
index 8f323e8..b7226f6 100644
--- a/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -45,6 +45,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
+import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -71,6 +72,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
private View mSelectedThumb;
private CropView mCropView;
+ private boolean mIgnoreNextTap;
private static class ThumbnailMetaData {
public boolean mLaunchesGallery;
@@ -181,6 +183,34 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
setContentView(R.layout.wallpaper_picker);
mCropView = (CropView) findViewById(R.id.cropView);
+ final View wallpaperStrip = findViewById(R.id.wallpaper_strip);
+ mCropView.setTouchCallback(new CropView.TouchCallback() {
+ LauncherViewPropertyAnimator mAnim;
+ public void onTouchDown() {
+ if (mAnim != null) {
+ mAnim.cancel();
+ }
+ if (wallpaperStrip.getTranslationY() == 0) {
+ mIgnoreNextTap = true;
+ }
+ mAnim = new LauncherViewPropertyAnimator(wallpaperStrip);
+ mAnim.translationY(wallpaperStrip.getHeight())
+ .setInterpolator(new DecelerateInterpolator(0.75f));
+ mAnim.start();
+ }
+ public void onTap() {
+ boolean ignoreTap = mIgnoreNextTap;
+ mIgnoreNextTap = false;
+ if (!ignoreTap) {
+ if (mAnim != null) {
+ mAnim.cancel();
+ }
+ mAnim = new LauncherViewPropertyAnimator(wallpaperStrip);
+ mAnim.translationY(0).setInterpolator(new DecelerateInterpolator(0.75f));
+ mAnim.start();
+ }
+ }
+ });
// Populate the built-in wallpapers
findWallpapers();