The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google Inc. |
| 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.internal.app; |
| 18 | |
Dianne Hackborn | 4f6ee25 | 2010-10-21 16:39:53 -0700 | [diff] [blame] | 19 | import com.android.internal.os.storage.ExternalStorageFormatter; |
| 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
| 24 | import android.content.DialogInterface; |
| 25 | import android.content.Intent; |
| 26 | import android.content.IntentFilter; |
| 27 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
| 30 | /** |
| 31 | * This activity is shown to the user to confirm formatting of external media. |
| 32 | * It uses the alert dialog style. It will be launched from a notification, or from settings |
| 33 | */ |
| 34 | public class ExternalMediaFormatActivity extends AlertActivity implements DialogInterface.OnClickListener { |
| 35 | |
Christian Mehlmauer | 15d2470 | 2010-05-17 21:27:27 +0200 | [diff] [blame] | 36 | private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
| 38 | /** Used to detect when the media state changes, in case we need to call finish() */ |
| 39 | private BroadcastReceiver mStorageReceiver = new BroadcastReceiver() { |
| 40 | @Override |
| 41 | public void onReceive(Context context, Intent intent) { |
| 42 | String action = intent.getAction(); |
| 43 | Log.d("ExternalMediaFormatActivity", "got action " + action); |
| 44 | |
| 45 | if (action == Intent.ACTION_MEDIA_REMOVED || |
| 46 | action == Intent.ACTION_MEDIA_CHECKING || |
| 47 | action == Intent.ACTION_MEDIA_MOUNTED || |
| 48 | action == Intent.ACTION_MEDIA_SHARED) { |
| 49 | finish(); |
| 50 | } |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | @Override |
| 55 | protected void onCreate(Bundle savedInstanceState) { |
| 56 | super.onCreate(savedInstanceState); |
| 57 | |
| 58 | Log.d("ExternalMediaFormatActivity", "onCreate!"); |
| 59 | // Set up the "dialog" |
| 60 | final AlertController.AlertParams p = mAlertParams; |
| 61 | p.mIconId = com.android.internal.R.drawable.stat_sys_warning; |
| 62 | p.mTitle = getString(com.android.internal.R.string.extmedia_format_title); |
| 63 | p.mMessage = getString(com.android.internal.R.string.extmedia_format_message); |
| 64 | p.mPositiveButtonText = getString(com.android.internal.R.string.extmedia_format_button_format); |
| 65 | p.mPositiveButtonListener = this; |
| 66 | p.mNegativeButtonText = getString(com.android.internal.R.string.cancel); |
| 67 | p.mNegativeButtonListener = this; |
| 68 | setupAlert(); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected void onResume() { |
| 73 | super.onResume(); |
| 74 | |
| 75 | IntentFilter filter = new IntentFilter(); |
| 76 | filter.addAction(Intent.ACTION_MEDIA_REMOVED); |
| 77 | filter.addAction(Intent.ACTION_MEDIA_CHECKING); |
| 78 | filter.addAction(Intent.ACTION_MEDIA_MOUNTED); |
| 79 | filter.addAction(Intent.ACTION_MEDIA_SHARED); |
| 80 | registerReceiver(mStorageReceiver, filter); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | protected void onPause() { |
| 85 | super.onPause(); |
| 86 | |
| 87 | unregisterReceiver(mStorageReceiver); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * {@inheritDoc} |
| 92 | */ |
| 93 | public void onClick(DialogInterface dialog, int which) { |
| 94 | |
| 95 | if (which == POSITIVE_BUTTON) { |
Dianne Hackborn | 4f6ee25 | 2010-10-21 16:39:53 -0700 | [diff] [blame] | 96 | Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY); |
| 97 | intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); |
| 98 | startService(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // No matter what, finish the activity |
| 102 | finish(); |
| 103 | } |
| 104 | } |