Ensure that we use the system long press duration when dragging from AllApps.

- Removing some old code out of LauncherAppState

Bug: 21559400
Change-Id: I3c586094efb7ad8a17d2169bc8aaccf6b0df40a2
This commit is contained in:
Winson Chung
2015-06-02 11:24:28 -07:00
parent 8d8c73b591
commit 7501adf4b7
6 changed files with 28 additions and 27 deletions
@@ -184,6 +184,12 @@ public class BubbleTextView extends TextView {
verifyHighRes();
}
/**
* Overrides the default long press timeout.
*/
public void setLongPressTimeout(int longPressTimeout) {
mLongPressHelper.setLongPressTimeout(longPressTimeout);
}
@Override
protected boolean setFrame(int left, int top, int right, int bottom) {
@@ -51,7 +51,6 @@ public abstract class ButtonDropTarget extends TextView
protected Launcher mLauncher;
private int mBottomDragPadding;
protected TextView mText;
protected SearchDropTargetBar mSearchDropTargetBar;
/** Whether this drop target is active for the current drag */
@@ -82,11 +81,9 @@ public abstract class ButtonDropTarget extends TextView
mOriginalTextColor = getTextColors();
// Remove the text in the Phone UI in landscape
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (!LauncherAppState.getInstance().isScreenLarge()) {
setText("");
}
DeviceProfile grid = ((Launcher) getContext()).getDeviceProfile();
if (grid.isVerticalBarLayout()) {
setText("");
}
}
@@ -21,9 +21,11 @@ import android.view.View;
import com.android.launcher3.util.Thunk;
public class CheckLongPressHelper {
@Thunk View mView;
@Thunk View.OnLongClickListener mListener;
@Thunk boolean mHasPerformedLongPress;
private int mLongPressTimeout = 300;
private CheckForLongPress mPendingCheckForLongPress;
class CheckForLongPress implements Runnable {
@@ -53,14 +55,20 @@ public class CheckLongPressHelper {
mListener = listener;
}
/**
* Overrides the default long press timeout.
*/
public void setLongPressTimeout(int longPressTimeout) {
mLongPressTimeout = longPressTimeout;
}
public void postCheckForLongPress() {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress();
}
mView.postDelayed(mPendingCheckForLongPress,
LauncherAppState.getInstance().getLongPressTimeout());
mView.postDelayed(mPendingCheckForLongPress, mLongPressTimeout);
}
public void cancelLongPress() {
@@ -25,6 +25,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
import android.view.ViewConfiguration;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
@@ -40,9 +41,6 @@ public class LauncherAppState {
private final IconCache mIconCache;
private final WidgetPreviewLoader mWidgetCache;
private final boolean mIsScreenLarge;
private final int mLongPressTimeout = 300;
private boolean mWallpaperChangedSinceLastCheck;
private static WeakReference<LauncherProvider> sLauncherProvider;
@@ -86,8 +84,6 @@ public class LauncherAppState {
MemoryTracker.startTrackingMe(sContext, "L");
}
// set sIsScreenXLarge and mScreenDensity *before* creating icon cache
mIsScreenLarge = isScreenLarge(sContext.getResources());
mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
mWidgetCache = new WidgetPreviewLoader(sContext, mInvariantDeviceProfile, mIconCache);
@@ -149,6 +145,9 @@ public class LauncherAppState {
return mModel;
}
/**
* TODO(winsonc, hyunyoungs): We need to respect this
*/
boolean shouldShowAppOrWidgetProvider(ComponentName componentName) {
return mAppFilter == null || mAppFilter.shouldShowApp(componentName);
}
@@ -168,20 +167,7 @@ public class LauncherAppState {
public WidgetPreviewLoader getWidgetCache() {
return mWidgetCache;
}
public boolean isScreenLarge() {
return mIsScreenLarge;
}
// Need a version that doesn't require an instance of LauncherAppState for the wallpaper picker
public static boolean isScreenLarge(Resources res) {
return res.getBoolean(R.bool.is_large_tablet);
}
public int getLongPressTimeout() {
return mLongPressTimeout;
}
public void onWallpaperChanged() {
mWallpaperChangedSinceLastCheck = true;
}
@@ -432,6 +432,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
icon = (BubbleTextView) mLayoutInflater.inflate(
R.layout.all_apps_prediction_bar_icon, mPredictionBarView, false);
icon.setFocusable(true);
icon.setLongPressTimeout(ViewConfiguration.get(getContext()).getLongPressTimeout());
mPredictionBarView.addView(icon);
}
@@ -27,6 +27,7 @@ import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.TextView;
import com.android.launcher3.AppInfo;
@@ -418,6 +419,8 @@ class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.ViewHol
icon.setOnTouchListener(mTouchListener);
icon.setOnClickListener(mIconClickListener);
icon.setOnLongClickListener(mIconLongClickListener);
icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext())
.getLongPressTimeout());
icon.setFocusable(true);
return new ViewHolder(icon);
default: