Merging stylus click logic in longpress helper for better state-management

Bug: 150825081
Change-Id: I7c507c41e67c09bff5a4ad3abc7a7a62fecf910e
This commit is contained in:
Sunny Goyal
2020-03-24 13:55:15 -07:00
parent ba1a2b9b62
commit 17feee8995
7 changed files with 123 additions and 310 deletions

View File

@@ -31,10 +31,9 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.CheckLongPressHelper;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.SimpleOnStylusPressListener;
import com.android.launcher3.StylusEventHelper;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.icons.BaseIconFactory;
import com.android.launcher3.model.WidgetItem;
@@ -71,7 +70,6 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
protected WidgetItem mItem;
private WidgetPreviewLoader mWidgetPreviewLoader;
private StylusEventHelper mStylusEventHelper;
protected CancellationSignal mActiveRequest;
private boolean mAnimatePreview = true;
@@ -80,7 +78,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
private Bitmap mDeferredBitmap;
protected final BaseActivity mActivity;
protected DeviceProfile mDeviceProfile;
protected final DeviceProfile mDeviceProfile;
private final CheckLongPressHelper mLongPressHelper;
public WidgetCell(Context context) {
this(context, null);
@@ -95,8 +94,9 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
mActivity = BaseActivity.fromContext(context);
mDeviceProfile = mActivity.getDeviceProfile();
mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
mLongPressHelper = new CheckLongPressHelper(this);
mLongPressHelper.setLongPressTimeoutFactor(1);
setContainerWidth();
setWillNotDraw(false);
setClipToPadding(false);
@@ -210,11 +210,15 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean handled = super.onTouchEvent(ev);
if (mStylusEventHelper.onMotionEvent(ev)) {
return true;
}
return handled;
super.onTouchEvent(ev);
mLongPressHelper.onTouchEvent(ev);
return true;
}
@Override
public void cancelLongPress() {
super.cancelLongPress();
mLongPressHelper.cancelLongPress();
}
/**