1f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Mirandapackage com.android.launcher3; 2f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 3f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Mirandaimport android.view.View; 4f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 56c46a6d324310bd2fc0ea223c9782ba6394512e7Sunny Goyalimport com.android.launcher3.userevent.nano.LauncherLogProto.Action; 6f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 7f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda/** 8f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda * A specialized listener for Overview buttons where both clicks and long clicks are logged 9f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda * handled the same via {@link #handleViewClick(View)}. 10f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda */ 11f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Mirandapublic abstract class OverviewButtonClickListener implements View.OnClickListener, 12f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda View.OnLongClickListener { 13f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 146c46a6d324310bd2fc0ea223c9782ba6394512e7Sunny Goyal private int mControlType; /** ControlType enum as defined in {@link Action.Touch} */ 15f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 16f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda public OverviewButtonClickListener(int controlType) { 17f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda mControlType = controlType; 18f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 19f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 20f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda public void attachTo(View v) { 21f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda v.setOnClickListener(this); 22f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda v.setOnLongClickListener(this); 23f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 24f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 25f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda @Override 26f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda public void onClick(View view) { 27f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda if (shouldPerformClick(view)) { 286c46a6d324310bd2fc0ea223c9782ba6394512e7Sunny Goyal handleViewClick(view, Action.Touch.TAP); 29f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 30f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 31f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 32f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda @Override 33f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda public boolean onLongClick(View view) { 34f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda if (shouldPerformClick(view)) { 356c46a6d324310bd2fc0ea223c9782ba6394512e7Sunny Goyal handleViewClick(view, Action.Touch.LONGPRESS); 36f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 37f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda return true; 38f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 39f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 40f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda private boolean shouldPerformClick(View view) { 41f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda return !Launcher.getLauncher(view.getContext()).getWorkspace().isSwitchingState(); 42f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 43f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 44f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda private void handleViewClick(View view, int action) { 45f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda handleViewClick(view); 46f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda Launcher.getLauncher(view.getContext()).getUserEventDispatcher() 47f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda .logActionOnControl(action, mControlType); 48f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda } 49f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda 50f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda public abstract void handleViewClick(View view); 51f3e35d93318190f995e6a0fc9d0441ac844b67e4Jon Miranda}