summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-02-23 15:23:44 -0800
committerWinson Chung <winsonc@google.com>2012-02-23 15:23:56 -0800
commit88f334571fe41df620ba903ced9b2c69b0170d5c (patch)
tree10cab22bd80262aa11dfc12238eb07394a2b0bf6 /src
parent72d598400da7cef9c7fc4f99bb1fcd7ff0710011 (diff)
downloadandroid_packages_apps_Trebuchet-88f334571fe41df620ba903ced9b2c69b0170d5c.tar.gz
android_packages_apps_Trebuchet-88f334571fe41df620ba903ced9b2c69b0170d5c.tar.bz2
android_packages_apps_Trebuchet-88f334571fe41df620ba903ced9b2c69b0170d5c.zip
Lowering long press time for workspace items.
Change-Id: I6a3b0e13681f07d0e50bf2dcec777037c4ef51a5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/BubbleTextView.java13
-rw-r--r--src/com/android/launcher2/CheckLongPressHelper.java61
-rw-r--r--src/com/android/launcher2/FolderIcon.java34
-rw-r--r--src/com/android/launcher2/LauncherAppWidgetHostView.java48
-rw-r--r--src/com/android/launcher2/LauncherApplication.java6
5 files changed, 121 insertions, 41 deletions
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 01417bf37..6227611d8 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -65,6 +65,7 @@ public class BubbleTextView extends TextView {
private Drawable mBackground;
private boolean mStayPressed;
+ private CheckLongPressHelper mLongPressHelper;
public BubbleTextView(Context context) {
super(context);
@@ -82,6 +83,7 @@ public class BubbleTextView extends TextView {
}
private void init() {
+ mLongPressHelper = new CheckLongPressHelper(this);
mBackground = getBackground();
final Resources res = getContext().getResources();
@@ -222,6 +224,8 @@ public class BubbleTextView extends TextView {
} else {
mDidInvalidateForPressedState = false;
}
+
+ mLongPressHelper.postCheckForLongPress();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
@@ -230,6 +234,8 @@ public class BubbleTextView extends TextView {
if (!isPressed()) {
mPressedOrFocusedBackground = null;
}
+
+ mLongPressHelper.cancelLongPress();
break;
}
return result;
@@ -318,4 +324,11 @@ public class BubbleTextView extends TextView {
}
return true;
}
+
+ @Override
+ public void cancelLongPress() {
+ super.cancelLongPress();
+
+ mLongPressHelper.cancelLongPress();
+ }
}
diff --git a/src/com/android/launcher2/CheckLongPressHelper.java b/src/com/android/launcher2/CheckLongPressHelper.java
new file mode 100644
index 000000000..3ccda2635
--- /dev/null
+++ b/src/com/android/launcher2/CheckLongPressHelper.java
@@ -0,0 +1,61 @@
+/*
+ * 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.launcher2;
+
+import android.view.View;
+
+public class CheckLongPressHelper {
+ private View mView;
+ private boolean mHasPerformedLongPress;
+ private CheckForLongPress mPendingCheckForLongPress;
+
+ class CheckForLongPress implements Runnable {
+ public void run() {
+ if ((mView.getParent() != null) && mView.hasWindowFocus()
+ && !mHasPerformedLongPress) {
+ if (mView.performLongClick()) {
+ mHasPerformedLongPress = true;
+ }
+ }
+ }
+ }
+
+ public CheckLongPressHelper(View v) {
+ mView = v;
+ }
+
+ public void postCheckForLongPress() {
+ mHasPerformedLongPress = false;
+
+ if (mPendingCheckForLongPress == null) {
+ mPendingCheckForLongPress = new CheckForLongPress();
+ }
+ mView.postDelayed(mPendingCheckForLongPress, LauncherApplication.getLongPressTimeout());
+ }
+
+ public void cancelLongPress() {
+ mHasPerformedLongPress = false;
+ if (mPendingCheckForLongPress != null) {
+ mView.removeCallbacks(mPendingCheckForLongPress);
+ mPendingCheckForLongPress = null;
+ }
+ }
+
+ public boolean hasPerformedLongPress() {
+ return mHasPerformedLongPress;
+ }
+}
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
index ff7e10f5f..c005edfcd 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -30,6 +30,7 @@ import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -53,6 +54,8 @@ public class FolderIcon extends LinearLayout implements FolderListener {
FolderInfo mInfo;
private static boolean sStaticValuesDirty = true;
+ private CheckLongPressHelper mLongPressHelper;
+
// The number of icons to display in the
private static final int NUM_ITEMS_IN_PREVIEW = 3;
private static final int CONSUMPTION_ANIMATION_DURATION = 100;
@@ -95,10 +98,16 @@ public class FolderIcon extends LinearLayout implements FolderListener {
public FolderIcon(Context context, AttributeSet attrs) {
super(context, attrs);
+ init();
}
public FolderIcon(Context context) {
super(context);
+ init();
+ }
+
+ private void init() {
+ mLongPressHelper = new CheckLongPressHelper(this);
}
public boolean isDropEnabled() {
@@ -591,4 +600,29 @@ public class FolderIcon extends LinearLayout implements FolderListener {
setContentDescription(String.format(mContext.getString(R.string.folder_name_format),
title));
}
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // Call the superclass onTouchEvent first, because sometimes it changes the state to
+ // isPressed() on an ACTION_UP
+ boolean result = super.onTouchEvent(event);
+
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ mLongPressHelper.postCheckForLongPress();
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+ mLongPressHelper.cancelLongPress();
+ break;
+ }
+ return result;
+ }
+
+ @Override
+ public void cancelLongPress() {
+ super.cancelLongPress();
+
+ mLongPressHelper.cancelLongPress();
+ }
}
diff --git a/src/com/android/launcher2/LauncherAppWidgetHostView.java b/src/com/android/launcher2/LauncherAppWidgetHostView.java
index 0c3bdcaf8..d73dd3008 100644
--- a/src/com/android/launcher2/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher2/LauncherAppWidgetHostView.java
@@ -30,12 +30,12 @@ import com.android.launcher.R;
* {@inheritDoc}
*/
public class LauncherAppWidgetHostView extends AppWidgetHostView {
- private boolean mHasPerformedLongPress;
- private CheckForLongPress mPendingCheckForLongPress;
+ private CheckLongPressHelper mLongPressHelper;
private LayoutInflater mInflater;
public LauncherAppWidgetHostView(Context context) {
super(context);
+ mLongPressHelper = new CheckLongPressHelper(this);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@@ -46,8 +46,8 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView {
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Consume any touch events for ourselves after longpress is triggered
- if (mHasPerformedLongPress) {
- mHasPerformedLongPress = false;
+ if (mLongPressHelper.hasPerformedLongPress()) {
+ mLongPressHelper.cancelLongPress();
return true;
}
@@ -55,16 +55,13 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView {
// users can always pick up this widget
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
- postCheckForLongClick();
+ mLongPressHelper.postCheckForLongPress();
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
- mHasPerformedLongPress = false;
- if (mPendingCheckForLongPress != null) {
- removeCallbacks(mPendingCheckForLongPress);
- }
+ mLongPressHelper.cancelLongPress();
break;
}
@@ -72,42 +69,11 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView {
return false;
}
- class CheckForLongPress implements Runnable {
- private int mOriginalWindowAttachCount;
-
- public void run() {
- if ((mParent != null) && hasWindowFocus()
- && mOriginalWindowAttachCount == getWindowAttachCount()
- && !mHasPerformedLongPress) {
- if (performLongClick()) {
- mHasPerformedLongPress = true;
- }
- }
- }
-
- public void rememberWindowAttachCount() {
- mOriginalWindowAttachCount = getWindowAttachCount();
- }
- }
-
- private void postCheckForLongClick() {
- mHasPerformedLongPress = false;
-
- if (mPendingCheckForLongPress == null) {
- mPendingCheckForLongPress = new CheckForLongPress();
- }
- mPendingCheckForLongPress.rememberWindowAttachCount();
- postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
- }
-
@Override
public void cancelLongPress() {
super.cancelLongPress();
- mHasPerformedLongPress = false;
- if (mPendingCheckForLongPress != null) {
- removeCallbacks(mPendingCheckForLongPress);
- }
+ mLongPressHelper.cancelLongPress();
}
@Override
diff --git a/src/com/android/launcher2/LauncherApplication.java b/src/com/android/launcher2/LauncherApplication.java
index 9936ca682..e69c5ab0b 100644
--- a/src/com/android/launcher2/LauncherApplication.java
+++ b/src/com/android/launcher2/LauncherApplication.java
@@ -25,6 +25,7 @@ import android.content.IntentFilter;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.os.Handler;
+import android.view.MotionEvent;
import java.lang.ref.WeakReference;
@@ -33,6 +34,7 @@ public class LauncherApplication extends Application {
public IconCache mIconCache;
private static boolean sIsScreenLarge;
private static float sScreenDensity;
+ private static int sLongPressTimeout = 300;
WeakReference<LauncherProvider> mLauncherProvider;
@Override
@@ -130,4 +132,8 @@ public class LauncherApplication extends Application {
public static float getScreenDensity() {
return sScreenDensity;
}
+
+ public static int getLongPressTimeout() {
+ return sLongPressTimeout;
+ }
}