use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class Utils method updatePreferenceToSpecificActivityOrRemove.
/**
* Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference.
*
* @param context The context.
* @param parentPreferenceGroup The preference group that contains the
* preference whose intent is being resolved.
* @param preferenceKey The key of the preference whose intent is being
* resolved.
* @param flags 0 or one or more of
* {@link #UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY}
* .
* @return Whether an activity was found. If false, the preference was
* removed.
*/
public static boolean updatePreferenceToSpecificActivityOrRemove(Context context, PreferenceGroup parentPreferenceGroup, String preferenceKey, int flags) {
Preference preference = parentPreferenceGroup.findPreference(preferenceKey);
if (preference == null) {
return false;
}
Intent intent = preference.getIntent();
if (intent != null) {
// Find the activity that is in the system image
PackageManager pm = context.getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// Replace the intent with this specific activity
preference.setIntent(new Intent().setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
if ((flags & UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY) != 0) {
// Set the preference title to the activity's label
preference.setTitle(resolveInfo.loadLabel(pm));
}
return true;
}
}
}
// Did not find a matching activity, so remove the preference
parentPreferenceGroup.removePreference(preference);
return false;
}
use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WallpaperTypeSettings method populateWallpaperTypes.
private void populateWallpaperTypes() {
// Search for activities that satisfy the ACTION_SET_WALLPAPER action
final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
final PackageManager pm = getPackageManager();
final List<ResolveInfo> rList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
final PreferenceScreen parent = getPreferenceScreen();
parent.setOrderingAsAdded(false);
// Add Preference items for each of the matching activities
for (ResolveInfo info : rList) {
Preference pref = new Preference(getPrefContext());
pref.setLayoutResource(R.layout.preference_wallpaper_type);
Intent prefIntent = new Intent(intent);
prefIntent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
pref.setIntent(prefIntent);
CharSequence label = info.loadLabel(pm);
if (label == null)
label = info.activityInfo.packageName;
pref.setTitle(label);
pref.setIcon(info.loadIcon(pm));
parent.addPreference(pref);
}
}
use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class Status method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mHandler = new MyHandler(this);
mCM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
addPreferencesFromResource(R.xml.device_info_status);
mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
mBatteryStatus = findPreference(KEY_BATTERY_STATUS);
mBtAddress = findPreference(KEY_BT_ADDRESS);
mWifiMacAddress = findPreference(KEY_WIFI_MAC_ADDRESS);
mWimaxMacAddress = findPreference(KEY_WIMAX_MAC_ADDRESS);
mIpAddress = findPreference(KEY_IP_ADDRESS);
mRes = getResources();
mUnknown = mRes.getString(R.string.device_info_default);
mUnavailable = mRes.getString(R.string.status_unavailable);
// Note - missing in zaku build, be careful later...
mUptime = findPreference("up_time");
if (!hasBluetooth()) {
getPreferenceScreen().removePreference(mBtAddress);
mBtAddress = null;
}
if (!hasWimax()) {
getPreferenceScreen().removePreference(mWimaxMacAddress);
mWimaxMacAddress = null;
}
mConnectivityIntentFilter = new IntentFilter();
for (String intent : CONNECTIVITY_INTENTS) {
mConnectivityIntentFilter.addAction(intent);
}
updateConnectivity();
String serial = getSerialNumber();
if (serial != null && !serial.equals("")) {
setSummaryText(KEY_SERIAL_NUMBER, serial);
} else {
removePreferenceFromScreen(KEY_SERIAL_NUMBER);
}
//TODO: the bug above will surface in split system user mode.
if (!UserManager.get(getContext()).isAdminUser() || Utils.isWifiOnly(getContext())) {
removePreferenceFromScreen(KEY_SIM_STATUS);
removePreferenceFromScreen(KEY_IMEI_INFO);
} else {
int numPhones = TelephonyManager.getDefault().getPhoneCount();
if (numPhones > 1) {
PreferenceScreen prefSet = getPreferenceScreen();
Preference singleSimPref = prefSet.findPreference(KEY_SIM_STATUS);
SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
for (int i = 0; i < numPhones; i++) {
SubscriptionInfo sir = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(i);
Preference pref = new Preference(getActivity());
pref.setOrder(singleSimPref.getOrder());
pref.setTitle(getString(R.string.sim_card_status_title, i + 1));
if (sir != null) {
pref.setSummary(sir.getDisplayName());
} else {
pref.setSummary(R.string.sim_card_summary_empty);
}
Intent intent = new Intent(getActivity(), Settings.SimStatusActivity.class);
intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_TITLE, getString(R.string.sim_card_status_title, i + 1));
intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
intent.putExtra(SimStatus.EXTRA_SLOT_ID, i);
pref.setIntent(intent);
prefSet.addPreference(pref);
}
prefSet.removePreference(singleSimPref);
}
}
if (SystemProperties.getBoolean("ro.alarm_boot", false)) {
removePreferenceFromScreen(KEY_IMEI_INFO);
}
}
use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PublicVolumeSettings method buildAction.
private Preference buildAction(int titleRes) {
final Preference pref = new Preference(getPrefContext());
pref.setTitle(titleRes);
return pref;
}
use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class InputMethodAndSubtypeEnabler method addInputMethodSubtypePreferences.
private void addInputMethodSubtypePreferences(final InputMethodInfo imi, final PreferenceScreen root) {
final Context context = getPrefContext();
final int subtypeCount = imi.getSubtypeCount();
if (subtypeCount <= 1) {
return;
}
final String imiId = imi.getId();
final PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getPrefContext());
root.addPreference(keyboardSettingsCategory);
final PackageManager pm = getPackageManager();
final CharSequence label = imi.loadLabel(pm);
keyboardSettingsCategory.setTitle(label);
keyboardSettingsCategory.setKey(imiId);
// TODO: Use toggle Preference if images are ready.
final TwoStatePreference autoSelectionPref = new SwitchWithNoTextPreference(getPrefContext());
mAutoSelectionPrefsMap.put(imiId, autoSelectionPref);
keyboardSettingsCategory.addPreference(autoSelectionPref);
autoSelectionPref.setOnPreferenceChangeListener(this);
final PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(getPrefContext());
activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes);
root.addPreference(activeInputMethodsCategory);
CharSequence autoSubtypeLabel = null;
final ArrayList<Preference> subtypePreferences = new ArrayList<>();
for (int index = 0; index < subtypeCount; ++index) {
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
if (subtype.overridesImplicitlyEnabledSubtype()) {
if (autoSubtypeLabel == null) {
autoSubtypeLabel = InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(subtype, context, imi);
}
} else {
final Preference subtypePref = new InputMethodSubtypePreference(context, subtype, imi);
subtypePreferences.add(subtypePref);
}
}
Collections.sort(subtypePreferences, new Comparator<Preference>() {
@Override
public int compare(final Preference lhs, final Preference rhs) {
if (lhs instanceof InputMethodSubtypePreference) {
return ((InputMethodSubtypePreference) lhs).compareTo(rhs, mCollator);
}
return lhs.compareTo(rhs);
}
});
final int prefCount = subtypePreferences.size();
for (int index = 0; index < prefCount; ++index) {
final Preference pref = subtypePreferences.get(index);
activeInputMethodsCategory.addPreference(pref);
pref.setOnPreferenceChangeListener(this);
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
}
mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
if (TextUtils.isEmpty(autoSubtypeLabel)) {
autoSelectionPref.setTitle(R.string.use_system_language_to_select_input_method_subtypes);
} else {
autoSelectionPref.setTitle(autoSubtypeLabel);
}
}
Aggregations