use of android.support.v7.preference.Preference in project AntennaPod by AntennaPod.
the class PreferenceController method buildAutodownloadSelectedNetworsPreference.
private void buildAutodownloadSelectedNetworsPreference() {
final Activity activity = ui.getActivity();
if (selectedNetworks != null) {
clearAutodownloadSelectedNetworsPreference();
}
// get configured networks
WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
if (networks != null) {
Collections.sort(networks, new Comparator<WifiConfiguration>() {
@Override
public int compare(WifiConfiguration x, WifiConfiguration y) {
return x.SSID.compareTo(y.SSID);
}
});
selectedNetworks = new CheckBoxPreference[networks.size()];
List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN);
Preference.OnPreferenceClickListener clickListener = preference -> {
if (preference instanceof CheckBoxPreference) {
String key = preference.getKey();
List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()));
boolean newValue = ((CheckBoxPreference) preference).isChecked();
Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
int index = prefValuesList.indexOf(key);
if (index >= 0 && !newValue) {
prefValuesList.remove(index);
} else if (index < 0 && newValue) {
prefValuesList.add(key);
}
UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[prefValuesList.size()]));
return true;
} else {
return false;
}
};
// value
for (int i = 0; i < networks.size(); i++) {
WifiConfiguration config = networks.get(i);
CheckBoxPreference pref = new CheckBoxPreference(activity);
String key = Integer.toString(config.networkId);
pref.setTitle(config.SSID);
pref.setKey(key);
pref.setOnPreferenceClickListener(clickListener);
pref.setPersistent(false);
pref.setChecked(prefValues.contains(key));
selectedNetworks[i] = pref;
prefScreen.addPreference(pref);
}
} else {
Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
}
}
use of android.support.v7.preference.Preference in project wire-android by wireapp.
the class DeviceDetailPreferences method updateOtrClientDetails.
private void updateOtrClientDetails() {
// Name
Preference preference = findPreference(getString(R.string.pref_device_details_device_key));
preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), otrClient));
preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), otrClient, true));
// Fingerprint
final FingerprintPreference fingerPrintPreference = (FingerprintPreference) findPreference(getString(R.string.pref_device_details_fingerprint_key));
if (fingerprint == null) {
fingerprint = otrClient.getFingerprint();
fingerprintSubscription = fingerprint.subscribe(new Subscriber<Fingerprint>() {
@Override
public void next(Fingerprint fingerprint) {
fingerPrintPreference.setFingerprint(fingerprint);
}
});
}
//Trust
final SwitchPreference verifySwitchPreference = (SwitchPreference) findPreference(getString(R.string.pref_device_details_trust_key));
if (currentDevice) {
PreferenceCategory group = (PreferenceCategory) findPreference(getString(R.string.pref_device_details_fingerprint_category_key));
group.removePreference(verifySwitchPreference);
} else {
verifySwitchPreference.setChecked(otrClient.getVerified() == Verification.VERIFIED);
// Note: Using OnPreferenceClickListener as it was some issues with getting
// OnPreferenceChangeListener to work.
verifySwitchPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
boolean newVerifiredValue = otrClient.getVerified() != Verification.VERIFIED;
otrClient.setVerified(newVerifiredValue);
verifySwitchPreference.setChecked(newVerifiredValue);
trackVerified(newVerifiredValue);
return true;
}
});
}
// Remove
if (currentDevice) {
Preference actionsPreference = findPreference(getString(R.string.pref_device_details_actions_category_key));
PreferenceScreen screen = (PreferenceScreen) findPreference(getString(R.string.pref_device_details_screen_key));
screen.removePreference(actionsPreference);
} else {
Preference resetSessionPreference = findPreference(getString(R.string.pref_device_details_reset_session_key));
resetSessionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
resetSession();
return true;
}
});
preference = findPreference(getString(R.string.pref_device_details_remove_key));
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {
@Override
public void execute(NetworkMode networkMode) {
if (getControllerFactory().getPasswordController().hasPassword()) {
deleteCurrentDevice();
} else {
showRemoveDeviceDialog();
}
}
@Override
public void onNoNetwork() {
ViewUtils.showAlertDialog(DeviceDetailPreferences.this.getActivity(), R.string.otr__remove_device__no_internet__title, R.string.otr__remove_device__no_internet__message, R.string.otr__remove_device__no_internet__button, null, true);
}
});
return true;
}
});
}
}
use of android.support.v7.preference.Preference in project wire-android by wireapp.
the class DevicesPreferences method addClientToGroup.
private void addClientToGroup(final OtrClient otrClient, PreferenceGroup preferenceGroup) {
DevicePreference preference = new DevicePreference(getContext());
preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), otrClient));
preference.setKey(getString(R.string.pref_device_details_screen_key));
preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), otrClient, false));
preference.setVerified(otrClient.getVerified() == Verification.VERIFIED);
final PreferenceScreen preferenceScreen = new PreferenceScreen(getContext(), null);
preferenceScreen.getExtras().putParcelable(DeviceDetailPreferences.PREFS_OTR_CLIENT, otrClient);
preferenceScreen.setTitle(preference.getTitle());
preferenceScreen.setKey(preference.getKey());
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
PreferenceManager preferenceManager = getPreferenceManager();
if (preferenceManager != null) {
PreferenceManager.OnNavigateToScreenListener listener = preferenceManager.getOnNavigateToScreenListener();
if (listener != null) {
listener.onNavigateToScreen(preferenceScreen);
return true;
}
}
return false;
}
});
preferenceGroup.addPreference(preference);
}
use of android.support.v7.preference.Preference in project wire-android by wireapp.
the class DevicesPreferences method setupOtrDevices.
private void setupOtrDevices() {
if (getStoreFactory() == null || getStoreFactory().isTornDown()) {
return;
}
Self self = getStoreFactory().getZMessagingApiStore().getApi().getSelf();
if (otrClient == null) {
otrClient = self.getOtrClient();
}
if (otherClients == null) {
otherClients = self.getOtherOtrClients();
otherClients.addUpdateListener(otrClientsUpdateListener);
}
updateOtrDevices();
final PreferenceGroup currentOtrClientPreferenceGroup = (PreferenceGroup) findPreference(getString(R.string.pref_devices_current_device_category_key));
otrClientSubscription = otrClient.subscribe(new Subscriber<OtrClient>() {
@Override
public void next(OtrClient value) {
if (getActivity() == null) {
return;
}
currentOtrClientPreferenceGroup.setTitle(getString(R.string.pref_devices_current_device_category_title));
currentOtrClientPreferenceGroup.removeAll();
net.xpece.android.support.preference.Preference preference = new net.xpece.android.support.preference.Preference(getContext());
preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), value));
preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), value, false));
preference.setKey(getString(R.string.pref_device_details_screen_key));
final PreferenceScreen preferenceScreen = new PreferenceScreen(getContext(), null);
preferenceScreen.getExtras().putParcelable(DeviceDetailPreferences.PREFS_OTR_CLIENT, value);
preferenceScreen.getExtras().putBoolean(DeviceDetailPreferences.PREFS_CURRENT_DEVICE, true);
preferenceScreen.setTitle(preference.getTitle());
preferenceScreen.setKey(preference.getKey());
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
PreferenceManager preferenceManager = getPreferenceManager();
if (preferenceManager != null) {
PreferenceManager.OnNavigateToScreenListener listener = preferenceManager.getOnNavigateToScreenListener();
if (listener != null) {
listener.onNavigateToScreen(preferenceScreen);
return true;
}
}
return false;
}
});
currentOtrClientPreferenceGroup.addPreference(preference);
}
});
}
use of android.support.v7.preference.Preference in project NetGuard by M66B.
the class ActivityMain method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("enabled".equals(name)) {
// Get enabled
boolean enabled = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != enabled)
swEnabled.setChecked(enabled);
} else if ("whitelist_wifi".equals(name) || "screen_on".equals(name) || "screen_wifi".equals(name) || "whitelist_other".equals(name) || "screen_other".equals(name) || "whitelist_roaming".equals(name) || "show_user".equals(name) || "show_system".equals(name) || "show_nointernet".equals(name) || "show_disabled".equals(name) || "sort".equals(name) || "imported".equals(name)) {
updateApplicationList(null);
final LinearLayout llWhitelist = (LinearLayout) findViewById(R.id.llWhitelist);
boolean screen_on = prefs.getBoolean("screen_on", true);
boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false);
boolean whitelist_other = prefs.getBoolean("whitelist_other", false);
boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true);
llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE);
} else if ("manage_system".equals(name)) {
invalidateOptionsMenu();
updateApplicationList(null);
LinearLayout llSystem = (LinearLayout) findViewById(R.id.llSystem);
boolean system = prefs.getBoolean("manage_system", false);
boolean hint = prefs.getBoolean("hint_system", true);
llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);
} else if ("theme".equals(name) || "dark_theme".equals(name))
recreate();
}
Aggregations