The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [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 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 19 | import com.android.settings.R; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 20 | |
| 21 | import android.app.Activity; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 22 | import android.app.Fragment; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 24 | import android.content.res.Resources; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 26 | import android.preference.Preference; |
| 27 | import android.preference.PreferenceActivity; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 28 | import android.view.LayoutInflater; |
| 29 | import android.view.View; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 30 | import android.view.ViewGroup; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 31 | import android.widget.Button; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 32 | import android.widget.CheckBox; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 36 | * state. Multiple confirmations are required: first, a general "are you sure |
| 37 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 38 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 39 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 40 | * locked, et cetera, then the confirmation sequence is abandoned. |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 41 | * |
| 42 | * This is the initial screen. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 43 | */ |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 44 | public class MasterClear extends Fragment { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 45 | |
| 46 | private static final int KEYGUARD_REQUEST = 55; |
| 47 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 48 | static final String ERASE_EXTERNAL_EXTRA = "erase_sd"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 49 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 50 | private View mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 51 | private Button mInitiateButton; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 52 | private View mExternalStorageContainer; |
| 53 | private CheckBox mExternalStorage; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 54 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 55 | /** |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 56 | * Keyguard validation is run using the standard {@link ConfirmLockPattern} |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 57 | * component as a subactivity |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 58 | * @param request the request code to be returned once confirmation finishes |
| 59 | * @return true if confirmation launched |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 60 | */ |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 61 | private boolean runKeyguardConfirmation(int request) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 62 | Resources res = getActivity().getResources(); |
| 63 | return new ChooseLockSettingsHelper(getActivity(), this) |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 64 | .launchConfirmationActivity(request, |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 65 | res.getText(R.string.master_clear_gesture_prompt), |
| 66 | res.getText(R.string.master_clear_gesture_explanation)); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 70 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 71 | super.onActivityResult(requestCode, resultCode, data); |
| 72 | |
| 73 | if (requestCode != KEYGUARD_REQUEST) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // If the user entered a valid keyguard trace, present the final |
| 78 | // confirmation prompt; otherwise, go back to the initial state. |
| 79 | if (resultCode == Activity.RESULT_OK) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 80 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 81 | } else { |
| 82 | establishInitialState(); |
| 83 | } |
| 84 | } |
| 85 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 86 | private void showFinalConfirmation() { |
| 87 | Preference preference = new Preference(getActivity()); |
| 88 | preference.setFragment(MasterClearConfirm.class.getName()); |
| 89 | preference.setTitle(R.string.master_clear_confirm_title); |
| 90 | preference.getExtras().putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked()); |
| 91 | ((PreferenceActivity) getActivity()).onPreferenceStartFragment(null, preference); |
| 92 | } |
| 93 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 94 | /** |
| 95 | * If the user clicks to begin the reset sequence, we next require a |
| 96 | * keyguard confirmation if the user has currently enabled one. If there |
| 97 | * is no keyguard available, we simply go to the final confirmation prompt. |
| 98 | */ |
| 99 | private Button.OnClickListener mInitiateListener = new Button.OnClickListener() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 100 | |
| 101 | public void onClick(View v) { |
| 102 | if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) { |
| 103 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 104 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 105 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 106 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * In its initial state, the activity presents a button for the user to |
| 110 | * click in order to initiate a confirmation sequence. This method is |
| 111 | * called from various other points in the code to reset the activity to |
| 112 | * this base state. |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 113 | * |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 114 | * <p>Reinflating views from resources is expensive and prevents us from |
| 115 | * caching widget pointers, so we use a single-inflate pattern: we lazy- |
| 116 | * inflate each view, caching all of the widget pointers we'll need at the |
| 117 | * time, then simply reuse the inflated views directly whenever we need |
| 118 | * to change contents. |
| 119 | */ |
| 120 | private void establishInitialState() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 121 | mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear); |
| 122 | mInitiateButton.setOnClickListener(mInitiateListener); |
| 123 | mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container); |
| 124 | mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 125 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 126 | mExternalStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 127 | |
| 128 | @Override |
| 129 | public void onClick(View v) { |
| 130 | mExternalStorage.toggle(); |
| 131 | } |
| 132 | }); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 136 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 137 | Bundle savedInstanceState) { |
| 138 | mContentView = inflater.inflate(R.layout.master_clear, null); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 139 | establishInitialState(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame^] | 140 | return mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 141 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 142 | } |