2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings;
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.ContentResolver;
22 import android.content.DialogInterface;
23 import android.os.BatteryManager;
24 import android.os.Bundle;
25 import android.preference.Preference;
26 import android.preference.PreferenceFragment;
27 import android.preference.PreferenceScreen;
28 import android.preference.CheckBoxPreference;
29 import android.provider.Settings;
32 * Displays preferences for application developers.
34 public class DevelopmentSettings extends PreferenceFragment
35 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
37 private static final String ENABLE_ADB = "enable_adb";
38 private static final String KEEP_SCREEN_ON = "keep_screen_on";
39 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
41 private CheckBoxPreference mEnableAdb;
42 private CheckBoxPreference mKeepScreenOn;
43 private CheckBoxPreference mAllowMockLocation;
45 // To track whether Yes was clicked in the adb warning dialog
46 private boolean mOkClicked;
48 private Dialog mOkDialog;
51 public void onCreate(Bundle icicle) {
52 super.onCreate(icicle);
54 addPreferencesFromResource(R.xml.development_prefs);
56 mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
57 mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
58 mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
62 public void onResume() {
65 final ContentResolver cr = getActivity().getContentResolver();
66 mEnableAdb.setChecked(Settings.Secure.getInt(cr,
67 Settings.Secure.ADB_ENABLED, 0) != 0);
68 mKeepScreenOn.setChecked(Settings.System.getInt(cr,
69 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
70 mAllowMockLocation.setChecked(Settings.Secure.getInt(cr,
71 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
75 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
77 if (Utils.isMonkeyRunning()) {
81 if (preference == mEnableAdb) {
82 if (mEnableAdb.isChecked()) {
84 if (mOkDialog != null) dismissDialog();
85 mOkDialog = new AlertDialog.Builder(getActivity()).setMessage(
86 getActivity().getResources().getString(R.string.adb_warning_message))
87 .setTitle(R.string.adb_warning_title)
88 .setIcon(android.R.drawable.ic_dialog_alert)
89 .setPositiveButton(android.R.string.yes, this)
90 .setNegativeButton(android.R.string.no, this)
92 mOkDialog.setOnDismissListener(this);
94 Settings.Secure.putInt(getActivity().getContentResolver(),
95 Settings.Secure.ADB_ENABLED, 0);
97 } else if (preference == mKeepScreenOn) {
98 Settings.System.putInt(getActivity().getContentResolver(),
99 Settings.System.STAY_ON_WHILE_PLUGGED_IN,
100 mKeepScreenOn.isChecked() ?
101 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
102 } else if (preference == mAllowMockLocation) {
103 Settings.Secure.putInt(getActivity().getContentResolver(),
104 Settings.Secure.ALLOW_MOCK_LOCATION,
105 mAllowMockLocation.isChecked() ? 1 : 0);
111 private void dismissDialog() {
112 if (mOkDialog == null) return;
117 public void onClick(DialogInterface dialog, int which) {
118 if (which == DialogInterface.BUTTON_POSITIVE) {
120 Settings.Secure.putInt(getActivity().getContentResolver(),
121 Settings.Secure.ADB_ENABLED, 1);
124 mEnableAdb.setChecked(false);
128 public void onDismiss(DialogInterface dialog) {
129 // Assuming that onClick gets called first
131 mEnableAdb.setChecked(false);
136 public void onDestroy() {