OSDN Git Service

am 5721cb1d: (-s ours) am 99d2471d: Import revised translations. DO NOT MERGE
[android-x86/packages-apps-Settings.git] / src / com / android / settings / DevelopmentSettings.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.settings;
18
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;
30
31 /*
32  * Displays preferences for application developers.
33  */
34 public class DevelopmentSettings extends PreferenceFragment
35         implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
36
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";
40
41     private CheckBoxPreference mEnableAdb;
42     private CheckBoxPreference mKeepScreenOn;
43     private CheckBoxPreference mAllowMockLocation;
44
45     // To track whether Yes was clicked in the adb warning dialog
46     private boolean mOkClicked;
47
48     private Dialog mOkDialog;
49
50     @Override
51     public void onCreate(Bundle icicle) {
52         super.onCreate(icicle);
53
54         addPreferencesFromResource(R.xml.development_prefs);
55
56         mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
57         mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
58         mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
59     }
60
61     @Override
62     public void onResume() {
63         super.onResume();
64
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);
72     }
73
74     @Override
75     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
76
77         if (Utils.isMonkeyRunning()) {
78             return false;
79         }
80
81         if (preference == mEnableAdb) {
82             if (mEnableAdb.isChecked()) {
83                 mOkClicked = false;
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)
91                         .show();
92                 mOkDialog.setOnDismissListener(this);
93             } else {
94                 Settings.Secure.putInt(getActivity().getContentResolver(),
95                         Settings.Secure.ADB_ENABLED, 0);
96             }
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);
106         }
107
108         return false;
109     }
110
111     private void dismissDialog() {
112         if (mOkDialog == null) return;
113         mOkDialog.dismiss();
114         mOkDialog = null;
115     }
116
117     public void onClick(DialogInterface dialog, int which) {
118         if (which == DialogInterface.BUTTON_POSITIVE) {
119             mOkClicked = true;
120             Settings.Secure.putInt(getActivity().getContentResolver(),
121                     Settings.Secure.ADB_ENABLED, 1);
122         } else {
123             // Reset the toggle
124             mEnableAdb.setChecked(false);
125         }
126     }
127
128     public void onDismiss(DialogInterface dialog) {
129         // Assuming that onClick gets called first
130         if (!mOkClicked) {
131             mEnableAdb.setChecked(false);
132         }
133     }
134
135     @Override
136     public void onDestroy() {
137         dismissDialog();
138         super.onDestroy();
139     }
140 }