Exemplo n.º 1
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (Utils.isMonkeyRunning()) {
      return false;
    }

    if (preference == mEnableAdb) {
      if (mEnableAdb.isChecked()) {
        mOkClicked = false;
        if (mOkDialog != null) dismissDialog();
        mOkDialog =
            new AlertDialog.Builder(getActivity())
                .setMessage(getActivity().getResources().getString(R.string.adb_warning_message))
                .setTitle(R.string.adb_warning_title)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(android.R.string.yes, this)
                .setNegativeButton(android.R.string.no, this)
                .show();
        mOkDialog.setOnDismissListener(this);
      } else {
        Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
      }
    } else if (preference == mKeepScreenOn) {
      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.STAY_ON_WHILE_PLUGGED_IN,
          mKeepScreenOn.isChecked()
              ? (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB)
              : 0);
    } else if (preference == mAllowMockLocation) {
      Settings.Secure.putInt(
          getActivity().getContentResolver(),
          Settings.Secure.ALLOW_MOCK_LOCATION,
          mAllowMockLocation.isChecked() ? 1 : 0);
    } else if (preference == mStrictMode) {
      writeStrictModeVisualOptions();
    } else if (preference == mPointerLocation) {
      writePointerLocationOptions();
    } else if (preference == mShowTouches) {
      writeShowTouchesOptions();
    } else if (preference == mShowScreenUpdates) {
      writeFlingerOptions();
    } else if (preference == mShowCpuUsage) {
      writeCpuUsageOptions();
    } else if (preference == mImmediatelyDestroyActivities) {
      writeImmediatelyDestroyActivitiesOptions();
    } else if (preference == mShowAllANRs) {
      writeShowAllANRsOptions();
    } else if (preference == mForceHardwareUi) {
      writeHardwareUiOptions();
    }

    return false;
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (Utils.isMonkeyRunning()) {
      return false;
    }

    if (preference == mEnableAdb) {
      if (mEnableAdb.isChecked()) {
        mOkClicked = false;
        if (mOkDialog != null) dismissDialog();
        mOkDialog =
            new AlertDialog.Builder(this)
                .setMessage(getResources().getString(R.string.adb_warning_message))
                .setTitle(R.string.adb_warning_title)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(android.R.string.yes, this)
                .setNegativeButton(android.R.string.no, this)
                .show();
        mOkDialog.setOnDismissListener(this);
      } else {
        Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
        SystemProperties.set("persist.service.adb.enable", "0");
      }
    } else if (preference == mAdbNotify) {
      Settings.Secure.putInt(
          getContentResolver(), Settings.Secure.ADB_NOTIFY, mAdbNotify.isChecked() ? 1 : 0);
    } else if (preference == mKeepScreenOn) {
      Settings.System.putInt(
          getContentResolver(),
          Settings.System.STAY_ON_WHILE_PLUGGED_IN,
          mKeepScreenOn.isChecked()
              ? (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB)
              : 0);
    } else if (preference == mAllowMockLocation) {
      Settings.Secure.putInt(
          getContentResolver(),
          Settings.Secure.ALLOW_MOCK_LOCATION,
          mAllowMockLocation.isChecked() ? 1 : 0);
    }

    return false;
  }
 @Override
 public void onDestroy() {
   dismissDialog();
   super.onDestroy();
 }