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>
This commit is contained in:
@@ -880,6 +880,46 @@
|
|||||||
android:resource="@id/application_settings" />
|
android:resource="@id/application_settings" />
|
||||||
</activity-alias>
|
</activity-alias>
|
||||||
|
|
||||||
|
<activity android:name="Settings$UsbSettingsActivity"
|
||||||
|
android:theme="@android:style/Theme.Holo"
|
||||||
|
android:label="@string/storage_title_usb"
|
||||||
|
android:clearTaskOnLaunch="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<action android:name="android.settings.STORAGE_USB_SETTINGS" />
|
||||||
|
<action android:name="com.android.settings.STORAGE_USB_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.deviceinfo.UsbSettings" />
|
||||||
|
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
||||||
|
android:resource="@id/storage_settings" />
|
||||||
|
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"
|
||||||
|
android:resource="@string/storage_settings_title" />
|
||||||
|
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.Settings$StorageSettingsActivity" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity-alias android:name="UsbSettings"
|
||||||
|
android:clearTaskOnLaunch="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/storage_title_usb"
|
||||||
|
android:targetActivity="Settings$DevelopmentSettingsActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<action android:name="android.settings.STORAGE_USB_SETTINGS" />
|
||||||
|
<action android:name="com.android.settings.STORAGE_USB_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.deviceinfo.UsbSettings" />
|
||||||
|
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
||||||
|
android:resource="@id/storage_settings" />
|
||||||
|
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"
|
||||||
|
android:resource="@string/storage_settings_title" />
|
||||||
|
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.Settings$StorageSettingsActivity" />
|
||||||
|
</activity-alias>
|
||||||
|
|
||||||
<!-- Bluetooth stuff -->
|
<!-- Bluetooth stuff -->
|
||||||
|
|
||||||
|
@@ -1724,6 +1724,17 @@
|
|||||||
<!-- SD card eject progress text -->
|
<!-- SD card eject progress text -->
|
||||||
<string name="sd_ejecting_summary">Unmount in progress</string>
|
<string name="sd_ejecting_summary">Unmount in progress</string>
|
||||||
|
|
||||||
|
<!-- Storage setting. Menu option for USB transfer settings [CHAR LIMIT=30]-->
|
||||||
|
<string name="storage_menu_usb">USB transfer settings</string>
|
||||||
|
<!-- Storage setting. Title for USB transfer settings [CHAR LIMIT=30]-->
|
||||||
|
<string name="storage_title_usb">USB transfer settings</string>
|
||||||
|
<!-- Storage setting. Label for MTP setting [CHAR LIMIT=30]-->
|
||||||
|
<string name="usb_label_mtp">Connect as a media device (MTP)</string>
|
||||||
|
<!-- Storage setting. Label for PTP setting [CHAR LIMIT=30]-->
|
||||||
|
<string name="usb_label_ptp">Connect as a camera (PTP)</string>
|
||||||
|
<!-- Storage setting. Label for installer CD [CHAR LIMIT=30]-->
|
||||||
|
<string name="usb_label_installer_cd">Install file transfer tools</string>
|
||||||
|
|
||||||
<!-- Phone info screen, section titles: -->
|
<!-- Phone info screen, section titles: -->
|
||||||
<string name="battery_status_title">Battery status</string>
|
<string name="battery_status_title">Battery status</string>
|
||||||
<!-- Phone info screen, section titles: -->
|
<!-- Phone info screen, section titles: -->
|
||||||
|
30
res/xml/usb_settings.xml
Normal file
30
res/xml/usb_settings.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:title="@string/location_settings_title">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="usb_mtp"
|
||||||
|
android:title="@string/usb_label_mtp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="usb_ptp"
|
||||||
|
android:title="@string/usb_label_ptp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -34,8 +34,12 @@ import android.os.storage.StorageEventListener;
|
|||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.os.storage.StorageVolume;
|
import android.os.storage.StorageVolume;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.settings.R;
|
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_CONFIRM_UNMOUNT = 1;
|
||||||
private static final int DLG_ERROR_UNMOUNT = 2;
|
private static final int DLG_ERROR_UNMOUNT = 2;
|
||||||
|
|
||||||
|
private static final int MENU_ID_USB = Menu.FIRST;
|
||||||
|
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
|
|
||||||
// The mountToggle Preference that has last been clicked.
|
// The mountToggle Preference that has last been clicked.
|
||||||
@@ -88,6 +94,9 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
|
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;
|
int length = storageVolumes.length;
|
||||||
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
|
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
@@ -99,6 +108,9 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
getPreferenceScreen().addPreference(storagePreferenceCategory);
|
getPreferenceScreen().addPreference(storagePreferenceCategory);
|
||||||
storagePreferenceCategory.init();
|
storagePreferenceCategory.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only show options menu if we are not using the legacy USB mass storage support
|
||||||
|
setHasOptionsMenu(!massStorageEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,6 +165,31 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
super.onDestroy();
|
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() {
|
private synchronized IMountService getMountService() {
|
||||||
if (mMountService == null) {
|
if (mMountService == null) {
|
||||||
IBinder service = ServiceManager.getService("mount");
|
IBinder service = ServiceManager.getService("mount");
|
||||||
|
150
src/com/android/settings/deviceinfo/UsbSettings.java
Normal file
150
src/com/android/settings/deviceinfo/UsbSettings.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user