use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.
the class ChannelListPreferenceController method findOrCreateGroupCategoryForKey.
/**
* Looks for the category for the given group's key at the expected index, if that doesn't
* match, it checks all groups, and if it can't find that group anywhere, it creates it.
*/
@NonNull
private PreferenceCategory findOrCreateGroupCategoryForKey(@NonNull PreferenceCategory groupPrefsList, @Nullable String key, int expectedIndex) {
if (key == null) {
key = KEY_GENERAL_CATEGORY;
}
int preferenceCount = groupPrefsList.getPreferenceCount();
if (expectedIndex < preferenceCount) {
Preference preference = groupPrefsList.getPreference(expectedIndex);
if (key.equals(preference.getKey())) {
return (PreferenceCategory) preference;
}
}
for (int i = 0; i < preferenceCount; i++) {
Preference preference = groupPrefsList.getPreference(i);
if (key.equals(preference.getKey())) {
preference.setOrder(expectedIndex);
return (PreferenceCategory) preference;
}
}
PreferenceCategory groupCategory = new PreferenceCategory(mContext);
groupCategory.setOrder(expectedIndex);
groupCategory.setKey(key);
groupPrefsList.addPreference(groupCategory);
return groupCategory;
}
use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.
the class NotificationAccessSettings method updateList.
private void updateList(List<ServiceInfo> services) {
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
final PreferenceScreen screen = getPreferenceScreen();
final PreferenceCategory allowedCategory = screen.findPreference(ALLOWED_KEY);
allowedCategory.removeAll();
final PreferenceCategory notAllowedCategory = screen.findPreference(NOT_ALLOWED_KEY);
notAllowedCategory.removeAll();
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
for (ServiceInfo service : services) {
final ComponentName cn = new ComponentName(service.packageName, service.name);
CharSequence title = null;
try {
title = mPm.getApplicationInfoAsUser(service.packageName, 0, UserHandle.myUserId()).loadLabel(mPm);
} catch (PackageManager.NameNotFoundException e) {
// unlikely, as we are iterating over live services.
Log.e(TAG, "can't find package name", e);
}
final AppPreference pref = new AppPreference(getPrefContext());
pref.setTitle(title);
pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid)));
pref.setKey(cn.flattenToString());
pref.setSummary(mBackend.getDeviceList(ICompanionDeviceManager.Stub.asInterface(ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)), com.android.settings.bluetooth.Utils.getLocalBtManager(mContext), service.packageName, UserHandle.myUserId()));
if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted(service.packageName, managedProfileId)) {
pref.setSummary(R.string.work_profile_notification_access_blocked_summary);
}
pref.setOnPreferenceClickListener(preference -> {
final Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, cn.getPackageName());
args.putInt(AppInfoBase.ARG_PACKAGE_UID, service.applicationInfo.uid);
Bundle extras = new Bundle();
extras.putString(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, cn.flattenToString());
new SubSettingLauncher(getContext()).setDestination(NotificationAccessDetails.class.getName()).setSourceMetricsCategory(getMetricsCategory()).setTitleRes(R.string.manage_notification_access_title).setArguments(args).setExtras(extras).setUserHandle(UserHandle.getUserHandleForUid(service.applicationInfo.uid)).launch();
return true;
});
pref.setKey(cn.flattenToString());
if (mNm.isNotificationListenerAccessGranted(cn)) {
allowedCategory.addPreference(pref);
} else {
notAllowedCategory.addPreference(pref);
}
}
highlightPreferenceIfNeeded();
}
use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.
the class WifiDisplaySettings method buildCertificationMenu.
private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
if (mCertCategory == null) {
mCertCategory = new PreferenceCategory(getPrefContext());
mCertCategory.setTitle(R.string.wifi_display_certification_heading);
mCertCategory.setOrder(ORDER_CERTIFICATION);
} else {
mCertCategory.removeAll();
}
preferenceScreen.addPreference(mCertCategory);
// display session info if there is an active p2p session
if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
Preference p = new Preference(getPrefContext());
p.setTitle(R.string.wifi_display_session_info);
p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
mCertCategory.addPreference(p);
// show buttons for Pause/Resume when a WFD session is established
if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
mCertCategory.addPreference(new Preference(getPrefContext()) {
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
Button b = (Button) view.findViewById(R.id.left_button);
b.setText(R.string.wifi_display_pause);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDisplayManager.pauseWifiDisplay();
}
});
b = (Button) view.findViewById(R.id.right_button);
b.setText(R.string.wifi_display_resume);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDisplayManager.resumeWifiDisplay();
}
});
}
});
mCertCategory.setLayoutResource(R.layout.two_buttons_panel);
}
}
// switch for Listen Mode
SwitchPreference pref = new SwitchPreference(getPrefContext()) {
@Override
protected void onClick() {
mListen = !mListen;
setListenMode(mListen);
setChecked(mListen);
}
};
pref.setTitle(R.string.wifi_display_listen_mode);
pref.setChecked(mListen);
mCertCategory.addPreference(pref);
// switch for Autonomous GO
pref = new SwitchPreference(getPrefContext()) {
@Override
protected void onClick() {
mAutoGO = !mAutoGO;
if (mAutoGO) {
startAutoGO();
} else {
stopAutoGO();
}
setChecked(mAutoGO);
}
};
pref.setTitle(R.string.wifi_display_autonomous_go);
pref.setChecked(mAutoGO);
mCertCategory.addPreference(pref);
// Drop down list for choosing WPS method (PBC/KEYPAD/DISPLAY)
ListPreference lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int wpsConfig = Integer.parseInt((String) value);
if (wpsConfig != mWpsConfig) {
mWpsConfig = wpsConfig;
getActivity().invalidateOptionsMenu();
Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, mWpsConfig);
}
return true;
}
});
mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
String[] wpsValues = { "" + WpsInfo.INVALID, "" + WpsInfo.PBC, "" + WpsInfo.KEYPAD, "" + WpsInfo.DISPLAY };
lp.setKey("wps");
lp.setTitle(R.string.wifi_display_wps_config);
lp.setEntries(wpsEntries);
lp.setEntryValues(wpsValues);
lp.setValue("" + mWpsConfig);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
// Drop down list for choosing listen channel
lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int channel = Integer.parseInt((String) value);
if (channel != mListenChannel) {
mListenChannel = channel;
getActivity().invalidateOptionsMenu();
setWifiP2pChannels(mListenChannel, mOperatingChannel);
}
return true;
}
});
String[] lcEntries = { "Auto", "1", "6", "11" };
String[] lcValues = { "0", "1", "6", "11" };
lp.setKey("listening_channel");
lp.setTitle(R.string.wifi_display_listen_channel);
lp.setEntries(lcEntries);
lp.setEntryValues(lcValues);
lp.setValue("" + mListenChannel);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
// Drop down list for choosing operating channel
lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int channel = Integer.parseInt((String) value);
if (channel != mOperatingChannel) {
mOperatingChannel = channel;
getActivity().invalidateOptionsMenu();
setWifiP2pChannels(mListenChannel, mOperatingChannel);
}
return true;
}
});
String[] ocEntries = { "Auto", "1", "6", "11", "36" };
String[] ocValues = { "0", "1", "6", "11", "36" };
lp.setKey("operating_channel");
lp.setTitle(R.string.wifi_display_operating_channel);
lp.setEntries(ocEntries);
lp.setEntryValues(ocValues);
lp.setValue("" + mOperatingChannel);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
}
use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AppsPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Context context = RuntimeEnvironment.application;
ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mAppState);
mRecentAppsCategory = spy(new PreferenceCategory(context));
mGeneralCategory = new PreferenceCategory(context);
mSeeAllPref = new Preference(context);
mAllAppsInfoPref = new Preference(context);
when(mScreen.findPreference(KEY_RECENT_APPS_CATEGORY)).thenReturn(mRecentAppsCategory);
when(mScreen.findPreference(KEY_GENERAL_CATEGORY)).thenReturn(mGeneralCategory);
when(mScreen.findPreference(KEY_SEE_ALL)).thenReturn(mSeeAllPref);
when(mScreen.findPreference(KEY_ALL_APP_INFO)).thenReturn(mAllAppsInfoPref);
mController = spy(new AppsPreferenceController(context));
mController.setFragment(mFragment);
mController.mRecentAppsCategory = mRecentAppsCategory;
mController.mGeneralCategory = mGeneralCategory;
mController.mSeeAllPref = mSeeAllPref;
mController.mAllAppsInfoPref = mAllAppsInfoPref;
}
use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.
the class ToggleFeaturePreferenceFragment method initShortcutPreference.
protected void initShortcutPreference() {
// Initial the shortcut preference.
mShortcutPreference = new ShortcutPreference(getPrefContext(), /* attrs= */
null);
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
mShortcutPreference.setTitle(title);
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
generalCategory.addPreference(mShortcutPreference);
}
Aggregations