예제 #1
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();
    }
  }
예제 #2
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();
    }
  }
예제 #3
0
 /** Stops tap detection. */
 public void onSuspendInfrastructure() {
   mIntegratedTapDetector.stop();
 }