OSDN Git Service

Code drop from //branches/cupcake/...@124589
[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.os.BatteryManager;
20 import android.os.Bundle;
21 import android.os.SystemProperties;
22 import android.preference.Preference;
23 import android.preference.PreferenceActivity;
24 import android.preference.PreferenceScreen;
25 import android.preference.CheckBoxPreference;
26 import android.provider.Settings;
27 import android.text.TextUtils;
28
29 /*
30  * Displays preferences for application developers.
31  */
32 public class DevelopmentSettings extends PreferenceActivity {
33
34     private static final String ENABLE_ADB = "enable_adb";
35     private static final String KEEP_SCREEN_ON = "keep_screen_on";
36     private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
37
38     private CheckBoxPreference mEnableAdb;
39     private CheckBoxPreference mKeepScreenOn;
40     private CheckBoxPreference mAllowMockLocation;
41
42     @Override
43     protected void onCreate(Bundle icicle) {
44         super.onCreate(icicle);
45
46         addPreferencesFromResource(R.xml.development_prefs);
47
48         mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
49         mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
50         mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
51     }
52
53     @Override
54     protected void onResume() {
55         super.onResume();
56         
57         mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
58                 Settings.Secure.ADB_ENABLED, 0) != 0);
59         mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
60                 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
61         mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
62                 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
63     }
64
65     @Override
66     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
67
68         // Those monkeys kept committing suicide, so we add this property
69         // to disable this functionality
70         if (!TextUtils.isEmpty(SystemProperties.get("ro.monkey"))) {
71             return false;
72         }
73
74         if (preference == mEnableAdb) {
75             Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 
76                     mEnableAdb.isChecked() ? 1 : 0);
77         } else if (preference == mKeepScreenOn) {
78             Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN, 
79                     mKeepScreenOn.isChecked() ? 
80                     (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
81         } else if (preference == mAllowMockLocation) {
82             Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
83                     mAllowMockLocation.isChecked() ? 1 : 0);
84         }
85         
86         return false;
87     }
88 }