コード例 #1
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        if (v.getId() == R.id.llDemoMainServerSettingActivity) {
          touchDownTime = System.currentTimeMillis();
          Log.i(TAG, "onTouch MotionEvent.ACTION: touchDownTime=" + touchDownTime);
          return true;
        }
      case MotionEvent.ACTION_UP:
        if (v.getId() == R.id.llDemoMainServerSettingActivity) {
          long time = System.currentTimeMillis() - touchDownTime;
          if (time < 5000 || time > 8000) {
            showShortToast("请长按5-8秒");
          } else {
            toActivity(
                ServerSettingActivity.createIntent(
                    context,
                    SettingUtil.getServerAddress(context, false),
                    SettingUtil.getServerAddress(context, true),
                    SettingUtil.APP_SETTING,
                    Context.MODE_PRIVATE,
                    SettingUtil.KEY_SERVER_ADDRESS_NORMAL,
                    SettingUtil.KEY_SERVER_ADDRESS_TEST));
            return true;
          }
        }
        break;
      default:
        break;
    }

    return super.onTouch(v, event);
  }