Merge "New full-screen activity for USB mass storage interaction."

This commit is contained in:
Daniel Sandler
2010-01-29 06:22:33 -08:00
committed by Android (Google) Code Review
9 changed files with 230 additions and 163 deletions

View File

@@ -16,7 +16,7 @@
package com.android.internal.app;
import android.app.AlertDialog;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -28,16 +28,23 @@ import android.os.IMountService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.widget.ImageView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
/**
* This activity is shown to the user for him/her to enable USB mass storage
* on-demand (that is, when the USB cable is connected). It uses the alert
* dialog style. It will be launched from a notification.
*/
public class UsbStorageActivity extends AlertActivity implements DialogInterface.OnClickListener {
private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
public class UsbStorageActivity extends Activity {
private Button mMountButton;
private Button mUnmountButton;
private TextView mBanner;
private TextView mMessage;
private ImageView mIcon;
/** Used to detect when the USB cable is unplugged, so we can call finish() */
private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
@@ -53,16 +60,49 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up the "dialog"
final AlertController.AlertParams p = mAlertParams;
p.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
p.mTitle = getString(com.android.internal.R.string.usb_storage_title);
p.mMessage = getString(com.android.internal.R.string.usb_storage_message);
p.mPositiveButtonText = getString(com.android.internal.R.string.usb_storage_button_mount);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(com.android.internal.R.string.usb_storage_button_unmount);
p.mNegativeButtonListener = this;
setupAlert();
setTitle(getString(com.android.internal.R.string.usb_storage_activity_title));
setContentView(com.android.internal.R.layout.usb_storage_activity);
mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);
mBanner = (TextView) findViewById(com.android.internal.R.id.banner);
mMessage = (TextView) findViewById(com.android.internal.R.id.message);
mMountButton = (Button) findViewById(com.android.internal.R.id.mount_button);
mMountButton.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
mountAsUsbStorage();
// TODO: replace with forthcoming MountService callbacks
switchDisplay(true);
}
});
mUnmountButton = (Button) findViewById(com.android.internal.R.id.unmount_button);
mUnmountButton.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
stopUsbStorage();
// TODO: replace with forthcoming MountService callbacks
switchDisplay(false);
}
});
}
private void switchDisplay(boolean usbStorageInUse) {
if (usbStorageInUse) {
mUnmountButton.setVisibility(View.VISIBLE);
mMountButton.setVisibility(View.GONE);
mIcon.setImageResource(com.android.internal.R.drawable.usb_android_connected);
mBanner.setText(com.android.internal.R.string.usb_storage_stop_title);
mMessage.setText(com.android.internal.R.string.usb_storage_stop_message);
} else {
mUnmountButton.setVisibility(View.GONE);
mMountButton.setVisibility(View.VISIBLE);
mIcon.setImageResource(com.android.internal.R.drawable.usb_android);
mBanner.setText(com.android.internal.R.string.usb_storage_title);
mMessage.setText(com.android.internal.R.string.usb_storage_message);
}
}
@Override
@@ -70,6 +110,18 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
super.onResume();
registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
boolean umsOn = false;
try {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
if (mountService != null) {
umsOn = mountService.getMassStorageEnabled();
}
} catch (android.os.RemoteException exc) {
// pass
}
switchDisplay(umsOn);
}
@Override
@@ -79,19 +131,6 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
unregisterReceiver(mBatteryReceiver);
}
/**
* {@inheritDoc}
*/
public void onClick(DialogInterface dialog, int which) {
if (which == POSITIVE_BUTTON) {
mountAsUsbStorage();
}
// No matter what, finish the activity
finish();
}
private void mountAsUsbStorage() {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
@@ -108,6 +147,22 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
}
}
private void stopUsbStorage() {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
if (mountService == null) {
showStoppingError();
return;
}
try {
mountService.setMassStorageEnabled(false);
} catch (RemoteException e) {
showStoppingError();
return;
}
}
private void handleBatteryChanged(Intent intent) {
int pluggedType = intent.getIntExtra("plugged", 0);
if (pluggedType == 0) {
@@ -120,5 +175,10 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
Toast.makeText(this, com.android.internal.R.string.usb_storage_error_message,
Toast.LENGTH_LONG).show();
}
private void showStoppingError() {
Toast.makeText(this, com.android.internal.R.string.usb_storage_stop_error_message,
Toast.LENGTH_LONG).show();
}
}

View File

@@ -1,123 +0,0 @@
/*
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.internal.app;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.IMountService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.widget.Toast;
/**
* This activity is shown to the user for him/her to disable USB mass storage.
* It uses the alert dialog style. It will be launched from a notification.
*/
public class UsbStorageStopActivity extends AlertActivity implements DialogInterface.OnClickListener {
private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
/** Used to detect when the USB cable is unplugged, so we can call finish() */
private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == Intent.ACTION_BATTERY_CHANGED) {
handleBatteryChanged(intent);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up the "dialog"
final AlertController.AlertParams p = mAlertParams;
p.mIconId = com.android.internal.R.drawable.ic_dialog_alert;
p.mTitle = getString(com.android.internal.R.string.usb_storage_stop_title);
p.mMessage = getString(com.android.internal.R.string.usb_storage_stop_message);
p.mPositiveButtonText = getString(com.android.internal.R.string.usb_storage_stop_button_mount);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(com.android.internal.R.string.usb_storage_stop_button_unmount);
p.mNegativeButtonListener = this;
setupAlert();
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mBatteryReceiver);
}
/**
* {@inheritDoc}
*/
public void onClick(DialogInterface dialog, int which) {
if (which == POSITIVE_BUTTON) {
stopUsbStorage();
}
// No matter what, finish the activity
finish();
}
private void stopUsbStorage() {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
if (mountService == null) {
showStoppingError();
return;
}
try {
mountService.setMassStorageEnabled(false);
} catch (RemoteException e) {
showStoppingError();
return;
}
}
private void handleBatteryChanged(Intent intent) {
int pluggedType = intent.getIntExtra("plugged", 0);
if (pluggedType == 0) {
// It was disconnected from the plug, so finish
finish();
}
}
private void showStoppingError() {
Toast.makeText(this, com.android.internal.R.string.usb_storage_stop_error_message,
Toast.LENGTH_LONG).show();
}
}

View File

@@ -1240,7 +1240,6 @@
</intent-filter>
</activity>
<activity android:name="com.android.internal.app.UsbStorageActivity"
android:theme="@style/Theme.Dialog.Alert"
android:excludeFromRecents="true">
</activity>
<activity android:name="com.android.internal.app.UsbStorageStopActivity"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="18dip"
android:orientation="horizontal"
>
<ImageView android:id="@+id/icon"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:src="@drawable/usb_android" />
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
>
<TextView android:id="@+id/banner"
android:layout_centerHorizontal="true"
android:layout_below="@id/icon"
android:layout_marginTop="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:gravity="center"
android:text="@string/usb_storage_title" />
<TextView android:id="@+id/message"
android:layout_below="@id/banner"
android:layout_marginTop="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:gravity="center"
android:text="@string/usb_storage_message" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/message"
android:layout_marginTop="20dip"
>
<Button android:id="@+id/mount_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dip"
android:paddingRight="18dip"
android:text="@string/usb_storage_button_mount"
/>
<Button android:id="@+id/unmount_button"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dip"
android:paddingRight="18dip"
android:text="@string/usb_storage_stop_button_mount"
/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="18dip"
>
<ImageView android:id="@+id/icon"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/usb_android" />
<TextView android:id="@+id/banner"
android:layout_centerHorizontal="true"
android:layout_below="@id/icon"
android:layout_marginTop="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:gravity="center"
android:text="@string/usb_storage_title" />
<TextView android:id="@+id/message"
android:layout_below="@id/banner"
android:layout_marginTop="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:gravity="center"
android:text="@string/usb_storage_message" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/message"
android:layout_marginTop="20dip"
>
<Button android:id="@+id/mount_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dip"
android:paddingRight="18dip"
android:text="@string/usb_storage_button_mount"
/>
<Button android:id="@+id/unmount_button"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dip"
android:paddingRight="18dip"
android:text="@string/usb_storage_stop_button_mount"
/>
</RelativeLayout>
</RelativeLayout>

View File

@@ -2008,21 +2008,23 @@
<string name="googlewebcontenthelper_loading">Loading\u2026</string>
<!-- USB storage dialog strings -->
<!-- This is the label for the activity, and should never be visible to the user. -->
<!-- This is the title for the activity's window. -->
<string name="usb_storage_activity_title">USB Mass Storage</string>
<!-- See USB_STORAGE. USB_STORAGE_DIALOG: After the user selects the notification, a dialog is shown asking if he wants to mount. This is the title. -->
<string name="usb_storage_title">USB connected</string>
<!-- See USB_STORAGE. This is the message. -->
<string name="usb_storage_message">You have connected your phone to your computer via USB. Select \"Mount\" if you want to copy files between your computer and your phone\'s SD card.</string>
<string name="usb_storage_message">You have connected your phone to your computer via USB. Select the button below if you want to copy files between your computer and your Android\u2018s SD card.</string>
<!-- See USB_STORAGE. This is the button text to mount the phone on the computer. -->
<string name="usb_storage_button_mount">Mount</string>
<!-- See USB_STORAGE. This is the button text to ignore the plugging in of the phone.. -->
<string name="usb_storage_button_unmount">Don\'t mount</string>
<string name="usb_storage_button_mount">Turn on USB storage</string>
<!-- See USB_STORAGE_DIALOG. If there was an error mounting, this is the text. -->
<string name="usb_storage_error_message">There is a problem using your SD card for USB storage.</string>
<!-- USB_STORAGE: When the user connects the phone to a computer via USB, we show a notification asking if he wants to share files across. This is the title -->
<string name="usb_storage_notification_title">USB connected</string>
<!-- See USB_STORAGE. This is the message. -->
<string name="usb_storage_notification_message">Select to copy files to/from your computer.</string>
<!-- USB_STORAGE_STOP: While USB storage is enabled, we show a notification dialog asking if he wants to stop. This is the title -->
<string name="usb_storage_stop_notification_title">Turn off USB storage</string>
<!-- See USB_STORAGE. This is the message. -->
@@ -2031,15 +2033,13 @@
<!-- USB storage stop dialog strings -->
<!-- This is the label for the activity, and should never be visible to the user. -->
<!-- See USB_STORAGE_STOP. USB_STORAGE_STOP_DIALOG: After the user selects the notification, a dialog is shown asking if he wants to stop usb storage. This is the title. -->
<string name="usb_storage_stop_title">Turn off USB storage</string>
<string name="usb_storage_stop_title">USB storage in use</string>
<!-- See USB_STORAGE_STOP. This is the message. -->
<string name="usb_storage_stop_message">Before turning off USB storage, make sure you have unmounted on the USB host. Select \"Turn Off\" to turn off USB storage.</string>
<string name="usb_storage_stop_message">Before turning off USB storage, make sure you have unmounted (\u201cejected\u201d) your Android\u2018s SD card from your computer.</string>
<!-- See USB_STORAGE_STOP. This is the button text to stop usb storage. -->
<string name="usb_storage_stop_button_mount">Turn Off</string>
<!-- See USB_STORAGE_STOP. This is the button text to cancel stoping usb storage. -->
<string name="usb_storage_stop_button_unmount">Cancel</string>
<string name="usb_storage_stop_button_mount">Turn off USB storage</string>
<!-- See USB_STORAGE_STOP_DIALOG. If there was an error stopping, this is the text. -->
<string name="usb_storage_stop_error_message">We\'ve encountered a problem turning off USB storage. Check to make sure you have unmounted the USB host, then try again.</string>
<string name="usb_storage_stop_error_message">There was a problem turning off USB storage. Check to make sure you have unmounted the USB host, then try again.</string>
<!-- External media format dialog strings -->
<!-- This is the label for the activity, and should never be visible to the user. -->

View File

@@ -866,7 +866,7 @@ class MountService extends IMountService.Stub
if (mUmsActiveNotify) {
Intent intent = new Intent();
intent.setClass(mContext, com.android.internal.app.UsbStorageStopActivity.class);
intent.setClass(mContext, com.android.internal.app.UsbStorageActivity.class);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setUsbStorageNotification(com.android.internal.R.string.usb_storage_stop_notification_title,
com.android.internal.R.string.usb_storage_stop_notification_message,