use of android.support.v7.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ZenModePrioritySettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.zen_mode_priority_settings);
final PreferenceScreen root = getPreferenceScreen();
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
mReminders = (SwitchPreference) root.findPreference(KEY_REMINDERS);
mReminders.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REMINDERS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowReminders=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_REMINDERS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mEvents = (SwitchPreference) root.findPreference(KEY_EVENTS);
mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_EVENTS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowEvents=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_EVENTS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mMessages = (DropDownPreference) root.findPreference(KEY_MESSAGES);
addSources(mMessages);
mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return false;
final int val = Integer.parseInt((String) newValue);
final boolean allowMessages = val != SOURCE_NONE;
final int allowMessagesFrom = val == SOURCE_NONE ? mPolicy.priorityMessageSenders : val;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_MESSAGES, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowMessages=" + allowMessages + " allowMessagesFrom=" + ZenModeConfig.sourceToString(allowMessagesFrom));
savePolicy(getNewPriorityCategories(allowMessages, Policy.PRIORITY_CATEGORY_MESSAGES), mPolicy.priorityCallSenders, allowMessagesFrom, mPolicy.suppressedVisualEffects);
return true;
}
});
mCalls = (DropDownPreference) root.findPreference(KEY_CALLS);
addSources(mCalls);
mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return false;
final int val = Integer.parseInt((String) newValue);
final boolean allowCalls = val != SOURCE_NONE;
final int allowCallsFrom = val == SOURCE_NONE ? mPolicy.priorityCallSenders : val;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_CALLS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowCalls=" + allowCalls + " allowCallsFrom=" + ZenModeConfig.sourceToString(allowCallsFrom));
savePolicy(getNewPriorityCategories(allowCalls, Policy.PRIORITY_CATEGORY_CALLS), allowCallsFrom, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mRepeatCallers = (SwitchPreference) root.findPreference(KEY_REPEAT_CALLERS);
mRepeatCallers.setSummary(mContext.getString(R.string.zen_mode_repeat_callers_summary, mContext.getResources().getInteger(com.android.internal.R.integer.config_zen_repeat_callers_threshold)));
mRepeatCallers.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REPEAT_CALLS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowRepeatCallers=" + val);
int priorityCategories = getNewPriorityCategories(val, NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
savePolicy(priorityCategories, mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
updateControls();
}
use of android.support.v7.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WirelessSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
}
log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
mContext = getActivity();
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mPm = getPackageManager();
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
addPreferencesFromResource(R.xml.wireless_settings);
final boolean isAdmin = mUm.isAdminUser();
final Activity activity = getActivity();
mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
RestrictedPreference androidBeam = (RestrictedPreference) findPreference(KEY_ANDROID_BEAM_SETTINGS);
PreferenceScreen nfcPayment = (PreferenceScreen) findPreference(KEY_NFC_PAYMENT_SETTINGS);
PreferenceCategory nfcCategory = (PreferenceCategory) findPreference(KEY_NFC_CATEGORY_SETTINGS);
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam, nfcPayment);
mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
String toggleable = Settings.Global.getString(activity.getContentResolver(), Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
//enable/disable wimax depending on the value in config.xml
final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
PreferenceScreen root = getPreferenceScreen();
Preference ps = findPreference(KEY_WIMAX_SETTINGS);
if (ps != null)
root.removePreference(ps);
} else {
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX) && isWimaxEnabled) {
Preference ps = findPreference(KEY_WIMAX_SETTINGS);
ps.setDependency(KEY_TOGGLE_AIRPLANE);
}
}
// Manually set dependencies for Wifi when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
}
// TODO: http://b/23693383
if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
removePreference(KEY_VPN_SETTINGS);
}
// Manually set dependencies for Bluetooth when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
// No bluetooth-dependent items in the list. Code kept in case one is added later.
}
// Manually set dependencies for NFC when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
findPreference(KEY_NFC_PAYMENT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
}
// Remove NFC if not available
mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (mNfcAdapter == null) {
getPreferenceScreen().removePreference(nfcCategory);
mNfcEnabler = null;
} else if (!mPm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
// Only show if we have the HCE feature
nfcCategory.removePreference(nfcPayment);
}
// if it's a wifi-only device, or for MSIM devices
if (!isAdmin || Utils.isWifiOnly(getActivity()) || Utils.showSimCardTile(getActivity()) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
removePreference(KEY_MOBILE_NETWORK_SETTINGS);
removePreference(KEY_MANAGE_MOBILE_PLAN);
}
// Remove Mobile Network Settings and Manage Mobile Plan
// if config_show_mobile_plan sets false.
final boolean isMobilePlanEnabled = this.getResources().getBoolean(R.bool.config_show_mobile_plan);
if (!isMobilePlanEnabled) {
Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
if (pref != null) {
removePreference(KEY_MANAGE_MOBILE_PLAN);
}
}
// Remove Airplane Mode settings if it's a stationary device such as a TV.
if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
removePreference(KEY_TOGGLE_AIRPLANE);
}
// Enable Proxy selector settings if allowed.
Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
// proxy UI disabled until we have better app support
getPreferenceScreen().removePreference(mGlobalProxy);
mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
// Disable Tethering if it's not allowed or if it's a wifi-only device
final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
} else if (!adminDisallowedTetherConfig) {
Preference p = findPreference(KEY_TETHER_SETTINGS);
p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
// Grey out if provisioning is not available.
p.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(getActivity()));
}
// Remove network reset if not allowed
if (RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
removePreference(KEY_NETWORK_RESET);
}
// Enable link to CMAS app settings depending on the value in config.xml.
boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(com.android.internal.R.bool.config_cellBroadcastAppLinks);
try {
if (isCellBroadcastAppLinkEnabled) {
if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
// CMAS app disabled
isCellBroadcastAppLinkEnabled = false;
}
}
} catch (IllegalArgumentException ignored) {
// CMAS app not installed
isCellBroadcastAppLinkEnabled = false;
}
if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled || RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId())) {
removePreference(KEY_CELL_BROADCAST_SETTINGS);
}
}
use of android.support.v7.preference.PreferenceScreen 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.PreferenceScreen 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.PreferenceScreen 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