blob: 85fe11fcb716bfb2a34c03071a3738f2885d4589 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
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
17package com.android.settings;
18
19import android.app.AlertDialog;
20import android.content.DialogInterface;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080021import android.content.res.Configuration;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070022import android.os.Bundle;
23import android.preference.CheckBoxPreference;
24import android.preference.Preference;
25import android.preference.PreferenceActivity;
26import android.preference.PreferenceScreen;
27import android.provider.Settings;
28
29public class ApplicationSettings extends PreferenceActivity implements
30 DialogInterface.OnClickListener {
31
32 private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080033 private static final String KEY_QUICK_LAUNCH = "quick_launch";
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070034
35 private CheckBoxPreference mToggleAppInstallation;
36
37 private DialogInterface mWarnInstallApps;
38
39 @Override
40 protected void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
42
43 addPreferencesFromResource(R.xml.application_settings);
44
45 mToggleAppInstallation = (CheckBoxPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
46 mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080047
48 if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS) {
49 // No hard keyboard, remove the setting for quick launch
50 Preference quickLaunchSetting = findPreference(KEY_QUICK_LAUNCH);
51 getPreferenceScreen().removePreference(quickLaunchSetting);
52 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070053 }
54
55 @Override
56 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
57 if (preference == mToggleAppInstallation) {
58 if (mToggleAppInstallation.isChecked()) {
59 mToggleAppInstallation.setChecked(false);
60 warnAppInstallation();
61 } else {
62 setNonMarketAppsAllowed(false);
63 }
64 }
65
66 return super.onPreferenceTreeClick(preferenceScreen, preference);
67 }
68
69 public void onClick(DialogInterface dialog, int which) {
70 if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON1) {
71 setNonMarketAppsAllowed(true);
72 mToggleAppInstallation.setChecked(true);
73 }
74 }
75
76 private void setNonMarketAppsAllowed(boolean enabled) {
77 // Change the system setting
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080078 Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS,
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070079 enabled ? 1 : 0);
80 }
81
82 private boolean isNonMarketAppsAllowed() {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080083 return Settings.Secure.getInt(getContentResolver(),
84 Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070085 }
86
87 private void warnAppInstallation() {
88 mWarnInstallApps = new AlertDialog.Builder(this)
89 .setTitle(getString(R.string.error_title))
90 .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
91 .setMessage(getResources().getString(R.string.install_all_warning))
92 .setPositiveButton(android.R.string.yes, this)
93 .setNegativeButton(android.R.string.no, null)
94 .show();
95 }
96
97
98}