Conditionally remove settings that aren't required on the tablet.

Bug: 2985267

Changes not done : SD card related stuff, as we need some way still
to figure out if there is a real SD card in the device.

Change-Id: I21c41f18ebe6c050981918481a7f6d69f04b65d0
This commit is contained in:
Amith Yamasani
2010-09-11 14:17:31 -07:00
parent cc0e4db618
commit 60133dd036
7 changed files with 68 additions and 39 deletions

View File

@@ -116,21 +116,6 @@
android:title="@string/storage_settings"> android:title="@string/storage_settings">
</com.android.settings.IconPreferenceScreen> </com.android.settings.IconPreferenceScreen>
<!-- Search.
The settings activity will ensure that this is resolved to an
activity on the system image, otherwise it will remove this
preference.
The intent action is the same as
android.app.SearchManager.INTENT_ACTION_SEARCH_SETTINGS.
-->
<com.android.settings.IconPreferenceScreen
settings:icon="@drawable/ic_settings_search"
android:title="@string/search_settings"
android:key="search_settings">
<intent android:action="android.search.action.SEARCH_SETTINGS" />
</com.android.settings.IconPreferenceScreen>
<!-- Language --> <!-- Language -->
<com.android.settings.IconPreferenceScreen <com.android.settings.IconPreferenceScreen

View File

@@ -46,6 +46,7 @@
android:streamType="ring" /> android:streamType="ring" />
<PreferenceCategory <PreferenceCategory
android:key="category_calls"
android:title="@string/sound_category_calls_title"/> android:title="@string/sound_category_calls_title"/>
<com.android.settings.DefaultRingtonePreference <com.android.settings.DefaultRingtonePreference
@@ -57,6 +58,7 @@
android:ringtoneType="ringtone" /> android:ringtoneType="ringtone" />
<PreferenceCategory <PreferenceCategory
android:key="category_notification"
android:title="@string/sound_category_notification_title"/> android:title="@string/sound_category_notification_title"/>
<!-- Do not nest these, or removals in code will break --> <!-- Do not nest these, or removals in code will break -->

View File

@@ -136,7 +136,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment {
displayNoAppsAlert(); displayNoAppsAlert();
} }
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)) { if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)
&& Utils.isVoiceCapable(getActivity())) {
int incallPowerBehavior = Settings.Secure.getInt(getContentResolver(), int incallPowerBehavior = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT); Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
@@ -148,7 +149,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment {
mPowerButtonEndsCallCheckBox.setChecked(powerButtonCheckboxEnabled); mPowerButtonEndsCallCheckBox.setChecked(powerButtonCheckboxEnabled);
mPowerButtonEndsCallCheckBox.setEnabled(true); mPowerButtonEndsCallCheckBox.setEnabled(true);
} else { } else {
// No POWER key on the current device; this entire category is irrelevant. // No POWER key on the current device or no voice capability;
// this entire category is irrelevant.
getPreferenceScreen().removePreference(mPowerButtonCategory); getPreferenceScreen().removePreference(mPowerButtonCategory);
} }
} }

View File

@@ -45,6 +45,12 @@ public class RingerVolumePreference extends VolumePreference implements
R.id.media_volume_seekbar, R.id.media_volume_seekbar,
R.id.alarm_volume_seekbar R.id.alarm_volume_seekbar
}; };
private static final int[] NEED_VOICE_CAPABILITY_ID = new int[] {
com.android.internal.R.id.seekbar, R.id.notification_volume_title,
R.id.notification_volume_seekbar
};
private static final int[] SEEKBAR_TYPE = new int[] { private static final int[] SEEKBAR_TYPE = new int[] {
AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_MUSIC, AudioManager.STREAM_MUSIC,
@@ -83,6 +89,17 @@ public class RingerVolumePreference extends VolumePreference implements
getContext().getContentResolver(), getContext().getContentResolver(),
Settings.System.NOTIFICATIONS_USE_RING_VOLUME, 1) == 1); Settings.System.NOTIFICATIONS_USE_RING_VOLUME, 1) == 1);
setNotificationVolumeVisibility(!mNotificationsUseRingVolumeCheckbox.isChecked()); setNotificationVolumeVisibility(!mNotificationsUseRingVolumeCheckbox.isChecked());
disableSettingsThatNeedVoice(view);
}
private void disableSettingsThatNeedVoice(View parent) {
final boolean voiceCapable = getContext().getResources()
.getBoolean(com.android.internal.R.bool.config_voice_capable);
if (!voiceCapable) {
for (int id : NEED_VOICE_CAPABILITY_ID) {
parent.findViewById(id).setVisibility(View.GONE);
}
}
} }
@Override @Override

View File

@@ -18,7 +18,6 @@ package com.android.settings;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.Fragment.InstantiationException;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
@@ -130,17 +129,12 @@ public class Settings extends Activity
} }
private boolean showFragment(String fragmentClass, Bundle extras) { private boolean showFragment(String fragmentClass, Bundle extras) {
try { Fragment f = Fragment.instantiate(this, fragmentClass, extras);
Fragment f = Fragment.instantiate(this, fragmentClass, extras); if (f instanceof SettingsPreferenceFragment) {
if (f instanceof SettingsPreferenceFragment) { ((SettingsPreferenceFragment) f).setOnStateListener(this);
((SettingsPreferenceFragment) f).setOnStateListener(this);
}
getFragmentManager().openTransaction().replace(R.id.prefs, f).commit();
return true;
} catch (InstantiationException exc) {
Log.d(TAG, "Couldn't instantiate fragment " + fragmentClass);
return false;
} }
getFragmentManager().openTransaction().replace(R.id.prefs, f).commit();
return true;
} }
private void addToBreadCrumbs(Fragment fragment) { private void addToBreadCrumbs(Fragment fragment) {
@@ -209,9 +203,6 @@ public class Settings extends Activity
PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT); PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT);
Utils.updatePreferenceToSpecificActivityOrRemove(activity, parent, Utils.updatePreferenceToSpecificActivityOrRemove(activity, parent,
KEY_SYNC_SETTINGS, 0); KEY_SYNC_SETTINGS, 0);
Utils.updatePreferenceToSpecificActivityOrRemove(activity, parent,
KEY_SEARCH_SETTINGS, 0);
Preference dockSettings = parent.findPreference(KEY_DOCK_SETTINGS); Preference dockSettings = parent.findPreference(KEY_DOCK_SETTINGS);
if (activity.getResources().getBoolean(R.bool.has_dock_settings) == false if (activity.getResources().getBoolean(R.bool.has_dock_settings) == false
&& dockSettings != null) { && dockSettings != null) {
@@ -222,6 +213,11 @@ public class Settings extends Activity
KEY_OPERATOR_SETTINGS); KEY_OPERATOR_SETTINGS);
Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(activity, parent, Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(activity, parent,
KEY_MANUFACTURER_SETTINGS); KEY_MANUFACTURER_SETTINGS);
Preference callSettings = parent.findPreference(KEY_CALL_SETTINGS);
if (!Utils.isVoiceCapable(activity) && callSettings != null) {
parent.removePreference(callSettings);
}
} }
@Override @Override

View File

@@ -49,12 +49,21 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private static final String KEY_SOUND_SETTINGS = "sound_settings"; private static final String KEY_SOUND_SETTINGS = "sound_settings";
private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
private static final String KEY_LOCK_SOUNDS = "lock_sounds"; private static final String KEY_LOCK_SOUNDS = "lock_sounds";
private static final String KEY_RINGTONE = "ringtone";
private static final String KEY_NOTIFICATION_SOUND = "notification_sound";
private static final String KEY_CATEGORY_CALLS = "category_calls";
private static final String KEY_CATEGORY_NOTIFICATION = "category_notification";
private static final String VALUE_VIBRATE_NEVER = "never"; private static final String VALUE_VIBRATE_NEVER = "never";
private static final String VALUE_VIBRATE_ALWAYS = "always"; private static final String VALUE_VIBRATE_ALWAYS = "always";
private static final String VALUE_VIBRATE_ONLY_SILENT = "silent"; private static final String VALUE_VIBRATE_ONLY_SILENT = "silent";
private static final String VALUE_VIBRATE_UNLESS_SILENT = "notsilent"; private static final String VALUE_VIBRATE_UNLESS_SILENT = "notsilent";
private static final String[] NEED_VOICE_CAPABILITY = {
KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
KEY_EMERGENCY_TONE
};
private CheckBoxPreference mSilent; private CheckBoxPreference mSilent;
/* /*
@@ -145,6 +154,14 @@ public class SoundSettings extends SettingsPreferenceFragment implements
} }
} }
if (!Utils.isVoiceCapable(getActivity())) {
for (String prefKey : NEED_VOICE_CAPABILITY) {
Preference pref = findPreference(prefKey);
if (pref != null) {
getPreferenceScreen().removePreference(pref);
}
}
}
} }
@Override @Override

View File

@@ -16,23 +16,24 @@
package com.android.settings; package com.android.settings;
import java.util.List;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.SystemProperties;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.Resources.NotFoundException; import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.List;
public class Utils { public class Utils {
/** /**
@@ -207,4 +208,13 @@ public class Utils {
public static boolean isMonkeyRunning() { public static boolean isMonkeyRunning() {
return SystemProperties.getBoolean("ro.monkey", false); return SystemProperties.getBoolean("ro.monkey", false);
} }
/**
* Returns whether the device is voice-capable (meaning, it is also a phone).
*/
public static boolean isVoiceCapable(Context context) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isVoiceCapable();
}
} }