Refactors ButtonDropTarget to add extension data

Also fixes a bug where DeleteDropTarget was logging Remove instead of
Cancel.

Bug: 78793340
Test: Enable verbose logging and manual test
Change-Id: I0f0cfff070eab003ebb745292630bc6ce3243f4d
This commit is contained in:
Mehdi Alizadeh 2018-05-01 19:26:05 -07:00
parent 954157a228
commit bda47cf925
5 changed files with 32 additions and 11 deletions

View File

@ -104,9 +104,9 @@ enum ControlType {
VERTICAL_SCROLL = 9;
HOME_INTENT = 10; // Deprecated, use enum Command instead
BACK_BUTTON = 11; // Deprecated, use enum Command instead
// GO_TO_PLAYSTORE
QUICK_SCRUB_BUTTON = 12;
CLEAR_ALL_BUTTON = 13;
CANCEL_TARGET = 14;
}
// Used to define the action component of the LauncherEvent.

View File

@ -45,6 +45,7 @@ import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
@ -375,5 +376,5 @@ public abstract class ButtonDropTarget extends TextView
return !mText.equals(displayedText);
}
public abstract int getControlTypeForLogging();
public abstract Target getDropTargetForLogging();
}

View File

@ -24,10 +24,14 @@ import android.view.View;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.logging.LoggerUtils;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
public class DeleteDropTarget extends ButtonDropTarget {
private int mControlType = ControlType.DEFAULT_CONTROLTYPE;
public DeleteDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@ -49,6 +53,7 @@ public class DeleteDropTarget extends ButtonDropTarget {
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
super.onDragStart(dragObject, options);
setTextBasedOnDragSource(dragObject.dragInfo);
setControlTypeBasedOnDragSource(dragObject.dragInfo);
}
/**
@ -83,6 +88,14 @@ public class DeleteDropTarget extends ButtonDropTarget {
}
}
/**
* Set mControlType depending on the drag item.
*/
private void setControlTypeBasedOnDragSource(ItemInfo item) {
mControlType = item.id != ItemInfo.NO_ID ? ControlType.REMOVE_TARGET
: ControlType.CANCEL_TARGET;
}
@Override
public void completeDrop(DragObject d) {
ItemInfo item = d.dragInfo;
@ -106,7 +119,9 @@ public class DeleteDropTarget extends ButtonDropTarget {
}
@Override
public int getControlTypeForLogging() {
return ControlType.REMOVE_TARGET;
public Target getDropTargetForLogging() {
Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
t.controlType = mControlType;
return t;
}
}

View File

@ -8,8 +8,6 @@ import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_NO;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType.SETTINGS_BUTTON;
import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType.UNINSTALL_TARGET;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
@ -33,6 +31,8 @@ import android.widget.Toast;
import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.logging.LoggerUtils;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Themes;
@ -98,8 +98,11 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList
}
@Override
public int getControlTypeForLogging() {
return mCurrentAccessibilityAction == UNINSTALL ? UNINSTALL_TARGET : SETTINGS_BUTTON;
public Target getDropTargetForLogging() {
Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
t.controlType = mCurrentAccessibilityAction == UNINSTALL ? ControlType.UNINSTALL_TARGET
: ControlType.SETTINGS_BUTTON;
return t;
}
@Override

View File

@ -167,11 +167,10 @@ public class LoggerUtils {
if (!(v instanceof ButtonDropTarget)) {
return newTarget(Target.Type.CONTAINER);
}
Target t = newTarget(Target.Type.CONTROL);
if (v instanceof ButtonDropTarget) {
t.controlType = ((ButtonDropTarget) v).getControlTypeForLogging();
return ((ButtonDropTarget) v).getDropTargetForLogging();
}
return t;
return newTarget(Target.Type.CONTROL);
}
public static Target newTarget(int targetType, TargetExtension extension) {
@ -186,6 +185,7 @@ public class LoggerUtils {
t.type = targetType;
return t;
}
public static Target newContainerTarget(int containerType) {
Target t = newTarget(Target.Type.CONTAINER);
t.containerType = containerType;
@ -197,11 +197,13 @@ public class LoggerUtils {
a.type = type;
return a;
}
public static Action newCommandAction(int command) {
Action a = newAction(Action.Type.COMMAND);
a.command = command;
return a;
}
public static Action newTouchAction(int touch) {
Action a = newAction(Action.Type.TOUCH);
a.touch = touch;