blob: 5ab9217b6b12814096feaf3fca85fe58b0fd3554 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.internal.app;
18
Dianne Hackborn4f6ee252010-10-21 16:39:53 -070019import com.android.internal.os.storage.ExternalStorageFormatter;
20
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.app.AlertDialog;
22import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.DialogInterface;
25import android.content.Intent;
26import android.content.IntentFilter;
27import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import 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 */
34public class ExternalMediaFormatActivity extends AlertActivity implements DialogInterface.OnClickListener {
35
Christian Mehlmauer15d24702010-05-17 21:27:27 +020036 private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
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 Hackborn4f6ee252010-10-21 16:39:53 -070096 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY);
97 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
98 startService(intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 }
100
101 // No matter what, finish the activity
102 finish();
103 }
104}