Пример #1
0
 /**
  * @param context TalkBackService whose {@code performCustomGesture} will be called when taps are
  *     detected
  */
 public SideTapManager(MyAccessibilityService context, GestureController gestureController) {
   if (gestureController == null) throw new IllegalStateException();
   mContext = context;
   mIntegratedTapDetector =
       new IntegratedTapDetector(
           (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE));
   mIntegratedTapDetector.addListener(this);
   mIntegratedTapDetector.setPostDelayTimeMillis(
       MIN_TIME_BETWEEN_TOUCH_AND_TAP_NANOS / MILIS_PER_NANO);
   mGestureController = gestureController;
 }
Пример #2
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (!MyAccessibilityService.isServiceActive()) {
      return;
    }

    String action = intent.getAction();
    if (action.equals(Intent.ACTION_SCREEN_ON)) {
      onReloadPreferences();
    }
    if (action.equals(Intent.ACTION_SCREEN_OFF)) {
      mIntegratedTapDetector.stop();
    }
  }
Пример #3
0
  /** Enables tap detection if appropriate based on preferences. */
  public void onReloadPreferences() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext);

    boolean enableTapDetection = false;
    if (!settings
        .getString(
            mContext.getString(R.string.pref_shortcut_single_tap_key),
            mContext.getString(R.string.pref_shortcut_single_tap_default))
        .equals(mContext.getString(R.string.shortcut_value_unassigned))) {
      /* Single tap is assigned */
      enableTapDetection = true;
    }

    if (!settings
        .getString(
            mContext.getString(R.string.pref_shortcut_double_tap_key),
            mContext.getString(R.string.pref_shortcut_double_tap_default))
        .equals(mContext.getString(R.string.shortcut_value_unassigned))) {
      /* Double tap is assigned */
      enableTapDetection = true;
      mIntegratedTapDetector.setMaxDoubleTapSpacingNanos(DOUBLE_TAP_SPACING_NANOS);
    } else {
      mIntegratedTapDetector.setMaxDoubleTapSpacingNanos(0);
    }

    /* The setting is 'sensitivity', which is the opposite of the detector's 'quality' */
    if (settings
        .getString(
            mContext.getString(R.string.pref_tap_sensitivity_key),
            mContext.getString(R.string.pref_tap_sensitivity_default))
        .equals(mContext.getString(R.string.tap_sensitivity_value_lowest))) {
      mIntegratedTapDetector.setTapDetectionQuality(IntegratedTapDetector.TAP_QUALITY_HIGHEST);
    }

    if (settings
        .getString(
            mContext.getString(R.string.pref_tap_sensitivity_key),
            mContext.getString(R.string.pref_tap_sensitivity_default))
        .equals(mContext.getString(R.string.tap_sensitivity_value_low))) {
      mIntegratedTapDetector.setTapDetectionQuality(IntegratedTapDetector.TAP_QUALITY_HIGH);
    }

    if (settings
        .getString(
            mContext.getString(R.string.pref_tap_sensitivity_key),
            mContext.getString(R.string.pref_tap_sensitivity_default))
        .equals(mContext.getString(R.string.tap_sensitivity_value_medium))) {
      mIntegratedTapDetector.setTapDetectionQuality(IntegratedTapDetector.TAP_QUALITY_MEDIUM);
    }

    if (settings
        .getString(
            mContext.getString(R.string.pref_tap_sensitivity_key),
            mContext.getString(R.string.pref_tap_sensitivity_default))
        .equals(mContext.getString(R.string.tap_sensitivity_value_high))) {
      mIntegratedTapDetector.setTapDetectionQuality(IntegratedTapDetector.TAP_QUALITY_LOW);
    }

    /* Second tap of double taps can be low quality */
    mIntegratedTapDetector.setDoubleTapDetectionQuality(IntegratedTapDetector.TAP_QUALITY_LOW);

    if (enableTapDetection) {
      mIntegratedTapDetector.start();
    } else {
      mIntegratedTapDetector.stop();
    }
  }
Пример #4
0
 /** Stops tap detection. */
 public void onSuspendInfrastructure() {
   mIntegratedTapDetector.stop();
 }