diff --git a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java index f74608b587bcd6ab951db6bb5870782b5a06502c..8763bbbbbcb3a77bec17c4c60f4b69b4706c6336 100644 --- a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java +++ b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java @@ -145,6 +145,8 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl private static final int STATE_DEINIT = 1; private static CasCloudPhoneActivity gAcitivity = null; private static CasListener mCasListener = null; + private static final int DOUBLE_CLICK_TIME_DELTA = 500; + private long lastClickTime = 0; // flag public volatile boolean rebuildDone = false; @@ -306,42 +308,46 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl setEnableAssistDirection(150 * getResources().getDisplayMetrics().density, 0f, 0f, 0f). build().toControl(this).show(); textCtrl = (TextView) findViewById(R.id.tv_ctrl); - textCtrl.setOnClickListener(CasCloudPhoneActivity.this); - mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener(){ - @SuppressLint("RestrictedApi") - @Override - public boolean onDoubleTap(MotionEvent e) { - KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HOME); - dispatchKeyEvent(event); - event = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HOME); - dispatchKeyEvent(event); - return true; - } - - @Override - public boolean onDoubleTapEvent(MotionEvent e) { - return false; - } + textCtrl.setOnClickListener(new View.OnClickListener() { + @SuppressLint("RestrictedApi") @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - switchCtrlViewShow(); - return true; + public void onClick(View view) { + long clickTime = System.currentTimeMillis(); + if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){ + // Double click action + KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HOME); + dispatchKeyEvent(event); + event = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HOME); + dispatchKeyEvent(event); + lastClickTime = 0; + } else { + // Single click action + lastClickTime = clickTime; + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (lastClickTime != 0) { + switchCtrlViewShow(); + lastClickTime = 0; + } + } + }, DOUBLE_CLICK_TIME_DELTA); + } } + }); + textCtrl.setOnLongClickListener(new View.OnLongClickListener() { @SuppressLint("RestrictedApi") @Override - public void onLongPress(MotionEvent e) { + public boolean onLongClick(View view) { KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_APP_SWITCH); dispatchKeyEvent(event); event = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_APP_SWITCH); dispatchKeyEvent(event); + return true; } }); - textCtrl.setOnTouchListener((v, event) -> { - mGestureDetector.onTouchEvent(event); - return true; - }); textCtrl.setBackgroundResource(R.drawable.ctrl_view); setRotation(mOrientation);