2 * Copyright (C) 2007 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.internal.app;
19 import com.android.internal.os.storage.ExternalStorageFormatter;
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;
28 import android.util.Log;
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
34 public class ExternalMediaFormatActivity extends AlertActivity implements DialogInterface.OnClickListener {
36 private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
38 /** Used to detect when the media state changes, in case we need to call finish() */
39 private BroadcastReceiver mStorageReceiver = new BroadcastReceiver() {
41 public void onReceive(Context context, Intent intent) {
42 String action = intent.getAction();
43 Log.d("ExternalMediaFormatActivity", "got action " + action);
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) {
55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
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;
72 protected void onResume() {
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);
84 protected void onPause() {
87 unregisterReceiver(mStorageReceiver);
93 public void onClick(DialogInterface dialog, int which) {
95 if (which == POSITIVE_BUTTON) {
96 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY);
97 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
101 // No matter what, finish the activity