109 lines
3.2 KiB
Java
109 lines
3.2 KiB
Java
package com.ubt.jimu.controller.component;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Point;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import com.ubt.jimu.controller.view.ItemBaseView;
|
|
import com.ubtrobot.log.ALog;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MenuItemView extends ItemBaseView {
|
|
private boolean d;
|
|
private MenuItemOnTouchListener e;
|
|
private float f;
|
|
private MenuItemType g;
|
|
|
|
public interface MenuItemOnTouchListener<T> {
|
|
void a(T t, MenuItemView menuItemView);
|
|
|
|
void b(T t, MenuItemView menuItemView);
|
|
}
|
|
|
|
public enum MenuItemType {
|
|
ACTION_ADD_ITEM,
|
|
ACTION_ITEM,
|
|
WIDGET_ITEM,
|
|
WIDGET_ADD_ITEM
|
|
}
|
|
|
|
public class MyDragShadowBuilder extends View.DragShadowBuilder {
|
|
public MyDragShadowBuilder(MenuItemView menuItemView) {
|
|
}
|
|
|
|
@Override // android.view.View.DragShadowBuilder
|
|
public void onProvideShadowMetrics(Point point, Point point2) {
|
|
point.set(1, 1);
|
|
point2.set(0, 0);
|
|
}
|
|
}
|
|
|
|
public MenuItemView(Context context) {
|
|
super(context);
|
|
a();
|
|
}
|
|
|
|
private void a() {
|
|
}
|
|
|
|
public MenuItemType getMenuItemType() {
|
|
return this.g;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
int action = motionEvent.getAction();
|
|
if (action == 0) {
|
|
this.f = motionEvent.getX();
|
|
return true;
|
|
}
|
|
if (action == 1) {
|
|
this.f = 0.0f;
|
|
this.d = false;
|
|
MenuItemOnTouchListener menuItemOnTouchListener = this.e;
|
|
if (menuItemOnTouchListener != null) {
|
|
menuItemOnTouchListener.b(super.getData(), this);
|
|
}
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
if (action == 2) {
|
|
float abs = Math.abs(this.f - motionEvent.getX());
|
|
if (!this.d) {
|
|
this.d = true;
|
|
if (abs > 20.0f) {
|
|
MenuItemOnTouchListener menuItemOnTouchListener2 = this.e;
|
|
if (menuItemOnTouchListener2 != null) {
|
|
menuItemOnTouchListener2.a(super.getData(), this);
|
|
}
|
|
ALog.a("DRAG").d("start drag");
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
startDragAndDrop(null, new MyDragShadowBuilder(this), null, 0);
|
|
} else {
|
|
startDrag(null, new MyDragShadowBuilder(this), null, 0);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
} else if (action != 3) {
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
this.d = false;
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
|
|
public void setMenuItemOnTouchListener(MenuItemOnTouchListener menuItemOnTouchListener) {
|
|
this.e = menuItemOnTouchListener;
|
|
}
|
|
|
|
public void setMenuItemType(MenuItemType menuItemType) {
|
|
this.g = menuItemType;
|
|
}
|
|
|
|
public MenuItemView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
a();
|
|
}
|
|
}
|