The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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.content.DialogInterface; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame^] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
| 23 | import android.preference.CheckBoxPreference; |
| 24 | import android.preference.Preference; |
| 25 | import android.preference.PreferenceActivity; |
| 26 | import android.preference.PreferenceScreen; |
| 27 | import android.provider.Settings; |
| 28 | |
| 29 | public 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame^] | 33 | private static final String KEY_QUICK_LAUNCH = "quick_launch"; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | |
| 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame^] | 47 | |
| 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 Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | } |
| 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame^] | 78 | Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 79 | enabled ? 1 : 0); |
| 80 | } |
| 81 | |
| 82 | private boolean isNonMarketAppsAllowed() { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame^] | 83 | return Settings.Secure.getInt(getContentResolver(), |
| 84 | Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | } |
| 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 | } |