Refactor UserEventDispatcher (1/2)
b/28269657 Change-Id: I1083e6f73f42ac1986428a39c6b532050e595ac6
This commit is contained in:
@@ -27,12 +27,12 @@ import android.view.ViewDebug;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.logging.UserEventLogger;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
|
||||
public class Hotseat extends FrameLayout
|
||||
implements UserEventLogger.LaunchSourceProvider{
|
||||
implements UserEventDispatcher.LaunchSourceProvider{
|
||||
|
||||
private CellLayout mContent;
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ import com.android.launcher3.dynamicui.ExtractedColors;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.logging.LoggerUtils;
|
||||
import com.android.launcher3.logging.UserEventLogger;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
@@ -360,7 +360,7 @@ public class Launcher extends Activity
|
||||
int appWidgetId;
|
||||
}
|
||||
|
||||
private UserEventLogger mUserEventLogger;
|
||||
private UserEventDispatcher mUserEventDispatcher;
|
||||
|
||||
public FocusIndicatorView mFocusHandler;
|
||||
private boolean mRotationEnabled = false;
|
||||
@@ -419,8 +419,6 @@ public class Launcher extends Activity
|
||||
mDragController = new DragController(this);
|
||||
mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
|
||||
|
||||
initLogger();
|
||||
|
||||
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
|
||||
|
||||
mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
|
||||
@@ -636,31 +634,36 @@ public class Launcher extends Activity
|
||||
* Since most user event logging is done on the UI, the object is retrieved from the
|
||||
* callback for convenience.
|
||||
*/
|
||||
private void initLogger() {
|
||||
if (mLauncherCallbacks != null) {
|
||||
mUserEventLogger = mLauncherCallbacks.getLogger();
|
||||
}
|
||||
if (mUserEventLogger == null) {
|
||||
mUserEventLogger = new UserEventLogger() {
|
||||
@Override
|
||||
public void processEvent(LauncherLogProto.LauncherEvent ev) {
|
||||
if (!DEBUG_LOGGING) {
|
||||
return;
|
||||
}
|
||||
Log.d("UserEvent", String.format(Locale.US,
|
||||
"action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
|
||||
LoggerUtils.getActionStr(ev.action),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[0]),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[1]),
|
||||
ev.elapsedContainerMillis,
|
||||
ev.elapsedSessionMillis));
|
||||
private UserEventDispatcher createUserEventDispatcher() {
|
||||
return new UserEventDispatcher() {
|
||||
@Override
|
||||
public void dispatchUserEvent(LauncherLogProto.LauncherEvent ev, Intent intent) {
|
||||
if (!DEBUG_LOGGING) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
Log.d("UserEvent", String.format(Locale.US,
|
||||
"action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
|
||||
LoggerUtils.getActionStr(ev.action),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[0]),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[1]),
|
||||
ev.elapsedContainerMillis,
|
||||
ev.elapsedSessionMillis));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public UserEventLogger getLogger() {
|
||||
return mUserEventLogger;
|
||||
public UserEventDispatcher getUserEventDispatcher() {
|
||||
if (mLauncherCallbacks != null) {
|
||||
UserEventDispatcher dispatcher = mLauncherCallbacks.getUserEventDispatcher();
|
||||
if (dispatcher != null) {
|
||||
return dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
if (mUserEventDispatcher == null) {
|
||||
mUserEventDispatcher = createUserEventDispatcher();
|
||||
}
|
||||
return mUserEventDispatcher;
|
||||
}
|
||||
|
||||
public boolean isDraggingEnabled() {
|
||||
@@ -990,7 +993,7 @@ public class Launcher extends Activity
|
||||
}
|
||||
|
||||
super.onResume();
|
||||
mUserEventLogger.resetElapsedSessionMillis();
|
||||
getUserEventDispatcher().resetElapsedSessionMillis();
|
||||
|
||||
// Restore the previous launcher state
|
||||
if (mOnResumeState == State.WORKSPACE) {
|
||||
@@ -2688,7 +2691,7 @@ public class Launcher extends Activity
|
||||
}
|
||||
|
||||
boolean success = startActivitySafely(v, intent, tag);
|
||||
mUserEventLogger.logLaunch(v, intent);
|
||||
getUserEventDispatcher().logAppLaunch(v, intent);
|
||||
|
||||
if (success && v instanceof BubbleTextView) {
|
||||
mWaitingForResume = (BubbleTextView) v;
|
||||
@@ -3460,7 +3463,7 @@ public class Launcher extends Activity
|
||||
List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
|
||||
if (apps != null) {
|
||||
mAppsView.setPredictedApps(apps);
|
||||
mUserEventLogger.setPredictedApps(apps);
|
||||
getUserEventDispatcher().setPredictedApps(apps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.view.Menu;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.allapps.AllAppsSearchBarController;
|
||||
import com.android.launcher3.logging.UserEventLogger;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
@@ -76,7 +76,7 @@ public interface LauncherCallbacks {
|
||||
/*
|
||||
* Extensions points for adding / replacing some other aspects of the Launcher experience.
|
||||
*/
|
||||
public UserEventLogger getLogger();
|
||||
public UserEventDispatcher getUserEventDispatcher();
|
||||
public Intent getFirstRunActivity();
|
||||
public boolean hasFirstRunActivity();
|
||||
public boolean hasDismissableIntroScreen();
|
||||
|
||||
@@ -148,7 +148,7 @@ public class LauncherStateTransitionAnimation {
|
||||
}
|
||||
@Override
|
||||
void onTransitionComplete() {
|
||||
mLauncher.getLogger().resetElapsedContainerMillis();
|
||||
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
||||
if (startSearchAfterTransition) {
|
||||
toView.startAppsSearch();
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public class LauncherStateTransitionAnimation {
|
||||
new PrivateTransitionCallbacks(FINAL_REVEAL_ALPHA_FOR_WIDGETS){
|
||||
@Override
|
||||
void onTransitionComplete() {
|
||||
mLauncher.getLogger().resetElapsedContainerMillis();
|
||||
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -470,7 +470,7 @@ public class LauncherStateTransitionAnimation {
|
||||
}
|
||||
@Override
|
||||
void onTransitionComplete() {
|
||||
mLauncher.getLogger().resetElapsedContainerMillis();
|
||||
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
||||
}
|
||||
};
|
||||
// Only animate the search bar if animating to spring loaded mode from all apps
|
||||
@@ -500,7 +500,7 @@ public class LauncherStateTransitionAnimation {
|
||||
}
|
||||
@Override
|
||||
void onTransitionComplete() {
|
||||
mLauncher.getLogger().resetElapsedContainerMillis();
|
||||
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
||||
}
|
||||
};
|
||||
mCurrentAnimation = startAnimationToWorkspaceFromOverlay(
|
||||
|
||||
@@ -72,7 +72,7 @@ import com.android.launcher3.dragndrop.DragView;
|
||||
import com.android.launcher3.dragndrop.SpringLoadedDragController;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.logging.UserEventLogger;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import com.android.launcher3.util.LongArrayMap;
|
||||
@@ -94,7 +94,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public class Workspace extends PagedView
|
||||
implements DropTarget, DragSource, DragScroller, View.OnTouchListener,
|
||||
DragController.DragListener, LauncherTransitionable, ViewGroup.OnHierarchyChangeListener,
|
||||
Insettable, DropTargetSource, AccessibilityDragSource, UserEventLogger.LaunchSourceProvider {
|
||||
Insettable, DropTargetSource, AccessibilityDragSource, UserEventDispatcher.LaunchSourceProvider {
|
||||
private static final String TAG = "Launcher.Workspace";
|
||||
|
||||
private static boolean ENFORCE_DRAG_EVENT_ORDER = false;
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.logging.UserEventLogger.LaunchSourceProvider;
|
||||
import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import java.util.List;
|
||||
|
||||
@@ -77,7 +77,7 @@ import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragController.DragListener;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.logging.UserEventLogger.LaunchSourceProvider;
|
||||
import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
|
||||
+9
-7
@@ -21,7 +21,6 @@ import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
@@ -29,7 +28,10 @@ import com.android.launcher3.util.ComponentKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class UserEventLogger {
|
||||
/**
|
||||
* Manages the creation of {@link LauncherEvent}.
|
||||
*/
|
||||
public abstract class UserEventDispatcher {
|
||||
|
||||
private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
|
||||
/**
|
||||
@@ -70,7 +72,7 @@ public abstract class UserEventLogger {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String TAG = "UserEventLogger";
|
||||
private String TAG = "UserEvent";
|
||||
|
||||
private long mElapsedContainerMillis;
|
||||
private long mElapsedSessionMillis;
|
||||
@@ -86,7 +88,7 @@ public abstract class UserEventLogger {
|
||||
// intentHash required
|
||||
// --------------------------------------------------------------
|
||||
|
||||
protected LauncherEvent createLogEvent(View v) {
|
||||
protected LauncherEvent createLauncherEvent(View v) {
|
||||
LauncherEvent event = LoggerUtils.initLauncherEvent(
|
||||
Action.TOUCH, Target.ITEM, Target.CONTAINER);
|
||||
event.action.touch = Action.TAP;
|
||||
@@ -105,8 +107,8 @@ public abstract class UserEventLogger {
|
||||
return event;
|
||||
}
|
||||
|
||||
public void logLaunch(View v, Intent intent) {
|
||||
processEvent(createLogEvent(v));
|
||||
public void logAppLaunch(View v, Intent intent) {
|
||||
dispatchUserEvent(createLauncherEvent(v), intent);
|
||||
}
|
||||
|
||||
public void logTap(View v) {
|
||||
@@ -142,7 +144,7 @@ public abstract class UserEventLogger {
|
||||
mActionDurationMillis = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public abstract void processEvent(LauncherLogProto.LauncherEvent ev);
|
||||
public abstract void dispatchUserEvent(LauncherEvent ev, Intent intent);
|
||||
|
||||
public int getPredictedRank(ComponentKey key) {
|
||||
if (mPredictedApps == null) return -1;
|
||||
@@ -12,7 +12,7 @@ import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherCallbacks;
|
||||
import com.android.launcher3.allapps.AllAppsSearchBarController;
|
||||
import com.android.launcher3.logging.UserEventLogger;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
@@ -189,7 +189,7 @@ public class LauncherExtension extends Launcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserEventLogger getLogger() { return null; }
|
||||
public UserEventDispatcher getUserEventDispatcher() { return null; }
|
||||
|
||||
@Override
|
||||
public View getQsbBar() {
|
||||
|
||||
Reference in New Issue
Block a user