summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/deviceinfo
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-06-30 14:47:46 -0400
committerMike Lockwood <lockwood@android.com>2011-07-06 10:56:13 -0400
commit02900a12b11efc89057fc5d0a19c08d20ff8d2c1 (patch)
tree35b963e1dd7b9dd7e0ad71df0cbd139312cec7bc /src/com/android/settings/deviceinfo
parentfce1543ae90c613ee0e3bfd76ad43ca5e332b4bf (diff)
downloadpackages_apps_Settings-02900a12b11efc89057fc5d0a19c08d20ff8d2c1.tar.gz
packages_apps_Settings-02900a12b11efc89057fc5d0a19c08d20ff8d2c1.tar.bz2
packages_apps_Settings-02900a12b11efc89057fc5d0a19c08d20ff8d2c1.zip
Super rough implementation of new USB settings
There does not seem to be a way to implement radio buttons in a settings screen, so I am using check boxes as a temporary hack. Change-Id: I2d2c7931f689ff04608662b64aafc4862cfef48e Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'src/com/android/settings/deviceinfo')
-rw-r--r--src/com/android/settings/deviceinfo/Memory.java37
-rw-r--r--src/com/android/settings/deviceinfo/UsbSettings.java150
2 files changed, 187 insertions, 0 deletions
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java
index 94ad3e66b..3205a3ea3 100644
--- a/src/com/android/settings/deviceinfo/Memory.java
+++ b/src/com/android/settings/deviceinfo/Memory.java
@@ -34,8 +34,12 @@ import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.preference.Preference;
+import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.Toast;
import com.android.settings.R;
@@ -47,6 +51,8 @@ public class Memory extends SettingsPreferenceFragment {
private static final int DLG_CONFIRM_UNMOUNT = 1;
private static final int DLG_ERROR_UNMOUNT = 2;
+ private static final int MENU_ID_USB = Menu.FIRST;
+
private Resources mResources;
// The mountToggle Preference that has last been clicked.
@@ -88,6 +94,9 @@ public class Memory extends SettingsPreferenceFragment {
}
StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
+ // mass storage is enabled if primary volume supports it
+ boolean massStorageEnabled = (storageVolumes.length > 0
+ && storageVolumes[0].allowMassStorage());
int length = storageVolumes.length;
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
for (int i = 0; i < length; i++) {
@@ -99,6 +108,9 @@ public class Memory extends SettingsPreferenceFragment {
getPreferenceScreen().addPreference(storagePreferenceCategory);
storagePreferenceCategory.init();
}
+
+ // only show options menu if we are not using the legacy USB mass storage support
+ setHasOptionsMenu(!massStorageEnabled);
}
@Override
@@ -153,6 +165,31 @@ public class Memory extends SettingsPreferenceFragment {
super.onDestroy();
}
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ menu.add(Menu.NONE, MENU_ID_USB, 0, R.string.storage_menu_usb)
+ //.setIcon(com.android.internal.R.drawable.stat_sys_data_usb)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_ID_USB:
+ if (getActivity() instanceof PreferenceActivity) {
+ ((PreferenceActivity) getActivity()).startPreferencePanel(
+ UsbSettings.class.getCanonicalName(),
+ null,
+ R.string.storage_title_usb, null,
+ this, 0);
+ } else {
+ startFragment(this, UsbSettings.class.getCanonicalName(), -1, null);
+ }
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
private synchronized IMountService getMountService() {
if (mMountService == null) {
IBinder service = ServiceManager.getService("mount");
diff --git a/src/com/android/settings/deviceinfo/UsbSettings.java b/src/com/android/settings/deviceinfo/UsbSettings.java
new file mode 100644
index 000000000..5da13af14
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/UsbSettings.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.settings.deviceinfo;
+
+import android.content.ContentQueryMap;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.hardware.usb.UsbManager;
+import android.os.Bundle;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import java.io.File;
+
+/**
+ * USB storage settings.
+ */
+public class UsbSettings extends SettingsPreferenceFragment {
+
+ private static final String TAG = "UsbSettings";
+
+ private static final String KEY_MTP = "usb_mtp";
+ private static final String KEY_PTP = "usb_ptp";
+ private static final String KEY_INSTALLER_CD = "usb_installer_cd";
+ private static final int MENU_ID_INSTALLER_CD = Menu.FIRST;
+
+ private UsbManager mUsbManager;
+ private String mInstallerImagePath;
+ private CheckBoxPreference mMtp;
+ private CheckBoxPreference mPtp;
+
+ private PreferenceScreen createPreferenceHierarchy() {
+ PreferenceScreen root = getPreferenceScreen();
+ if (root != null) {
+ root.removeAll();
+ }
+ addPreferencesFromResource(R.xml.usb_settings);
+ root = getPreferenceScreen();
+
+ mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP);
+ mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP);
+
+ return root;
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
+ mInstallerImagePath = getString(com.android.internal.R.string.config_isoImagePath);
+ if (!(new File(mInstallerImagePath)).exists()) {
+ mInstallerImagePath = null;
+ }
+ setHasOptionsMenu(mInstallerImagePath != null);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // Make sure we reload the preference hierarchy since some of these settings
+ // depend on others...
+ createPreferenceHierarchy();
+ updateToggles();
+ }
+
+ private void updateToggles() {
+ if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MTP)) {
+ mMtp.setChecked(true);
+ mPtp.setChecked(false);
+ } else if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_PTP)) {
+ mMtp.setChecked(false);
+ mPtp.setChecked(true);
+ } else {
+ mMtp.setChecked(false);
+ mPtp.setChecked(false);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ Log.d(TAG, "onPreferenceTreeClick " + preference);
+
+ // temporary hack - using check boxes as radio buttons
+ // don't allow unchecking them
+ if (preference instanceof CheckBoxPreference) {
+ CheckBoxPreference checkBox = (CheckBoxPreference)preference;
+ if (!checkBox.isChecked()) {
+ checkBox.setChecked(true);
+ return true;
+ }
+ }
+
+ if (preference == mMtp) {
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);
+ mPtp.setChecked(false);
+ } else if (preference == mPtp) {
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true);
+ mMtp.setChecked(false);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ menu.add(Menu.NONE, MENU_ID_INSTALLER_CD, 0, R.string.usb_label_installer_cd)
+ //.setIcon(com.android.internal.R.drawable.stat_sys_data_usb)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_ID_INSTALLER_CD:
+ // installer CD is never default
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MASS_STORAGE, false);
+ mUsbManager.setMassStorageBackingFile(mInstallerImagePath);
+ mMtp.setChecked(false);
+ mPtp.setChecked(false);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}