diff --git a/core/java/com/android/internal/app/UsbStorageActivity.java b/core/java/com/android/internal/app/UsbStorageActivity.java index b8a2136cc9d00..37ea3527841ae 100644 --- a/core/java/com/android/internal/app/UsbStorageActivity.java +++ b/core/java/com/android/internal/app/UsbStorageActivity.java @@ -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(); + } } diff --git a/core/java/com/android/internal/app/UsbStorageStopActivity.java b/core/java/com/android/internal/app/UsbStorageStopActivity.java deleted file mode 100644 index 557a5232a6246..0000000000000 --- a/core/java/com/android/internal/app/UsbStorageStopActivity.java +++ /dev/null @@ -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(); - } - -} diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 54e15a598d54e..665088a4c5baf 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1240,7 +1240,6 @@ + + + + + + + + + + + + +