use of android.support.v7.preference.Preference in project NetGuard by M66B.
the class ActivityLog method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("log".equals(name)) {
// Get enabled
boolean log = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != log)
swEnabled.setChecked(log);
ServiceSinkhole.reload("changed " + name, ActivityLog.this);
}
}
use of android.support.v7.preference.Preference in project Rashr by DsLNeXuS.
the class InformationFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getContext());
ArrayList<InformationItem> items = new ArrayList<>();
items.add(new InformationItem("Device Name", App.Device.getName()));
items.add(new InformationItem("Manufacture", App.Device.getManufacture()));
String recoveryType = "";
boolean recoveryWithPath = false;
boolean recoveryWithBS = false;
switch(App.Device.getRecoveryType()) {
case Device.PARTITION_TYPE_DD:
recoveryType = "DD";
recoveryWithPath = true;
recoveryWithBS = App.Device.getRecoveryBlocksize() > 0;
break;
case Device.PARTITION_TYPE_MTD:
recoveryType = "MTD";
break;
case Device.PARTITION_TYPE_RECOVERY:
recoveryType = "Flash over current Recovery";
break;
case Device.PARTITION_TYPE_NOT_SUPPORTED:
recoveryType = "Not supported";
break;
}
String kernelType = "";
boolean kernelWithPath = false;
boolean kernelWithBS = false;
switch(App.Device.getKernelType()) {
case Device.PARTITION_TYPE_DD:
kernelType = "DD";
kernelWithPath = true;
kernelWithBS = App.Device.getKernelBlocksize() > 0;
break;
case Device.PARTITION_TYPE_MTD:
kernelType = "MTD";
break;
case Device.PARTITION_TYPE_RECOVERY:
kernelType = "Flash over current Recovery";
break;
case Device.PARTITION_TYPE_NOT_SUPPORTED:
kernelType = "Not supported";
}
items.add(new InformationItem(getString(R.string.recovery_type), recoveryType));
if (recoveryWithPath)
items.add(new InformationItem("Recovery Path", App.Device.getRecoveryPath()));
if (recoveryWithBS)
items.add(new InformationItem("Recovery Blocksize", String.valueOf(App.Device.getRecoveryBlocksize())));
items.add(new InformationItem("Kernel Partition Type", kernelType));
if (kernelWithPath)
items.add(new InformationItem("Kernel Path", App.Device.getKernelPath()));
if (kernelWithBS)
items.add(new InformationItem("Kernel Blocksize", String.valueOf(App.Device.getKernelBlocksize())));
int total = 0;
if (App.Device.isCwmRecoverySupported()) {
int tmp = App.Device.getCwmRecoveryVersions().size();
items.add(new InformationItem(getString(R.string.sCWM), String.valueOf(tmp)));
total += tmp;
}
if (App.Device.isTwrpRecoverySupported()) {
int tmp = App.Device.getTwrpRecoveryVersions().size();
items.add(new InformationItem(getString(R.string.sTWRP), String.valueOf(tmp)));
total += tmp;
}
if (App.Device.isPhilzRecoverySupported()) {
int tmp = App.Device.getPhilzRecoveryVersions().size();
items.add(new InformationItem(getString(R.string.sPhilz), String.valueOf(tmp)));
total += tmp;
}
if (App.Device.isXZDualRecoverySupported()) {
int tmp = App.Device.getXZDualRecoveryVersions().size();
items.add(new InformationItem(getString(R.string.xzdualrecovery), String.valueOf(tmp)));
total += tmp;
}
if (App.Device.isStockRecoverySupported()) {
int tmp = App.Device.getStockRecoveryVersions().size();
items.add(new InformationItem(getString(R.string.stock_recovery), String.valueOf(tmp)));
total += tmp;
}
if (App.Device.isStockKernelSupported()) {
int tmp = App.Device.getStockKernelVersions().size();
items.add(new InformationItem(getString(R.string.stock_kernel), String.valueOf(tmp)));
total += tmp;
}
items.add(new InformationItem(getString(R.string.total_images), String.valueOf(total)));
for (String err : App.ERRORS) {
items.add(new InformationItem("Error:", err));
}
for (InformationItem item : items) {
Preference pref = new Preference(getContext());
pref.setTitle(item.id);
pref.setSummary(item.content);
pref.setOnPreferenceClickListener(this);
screen.addPreference(pref);
}
setPreferenceScreen(screen);
}
use of android.support.v7.preference.Preference in project twicalico by moko256.
the class SettingsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String preferenceRoot = getArguments() != null ? getArguments().getString(ARG_PREFERENCE_ROOT, null) : null;
if (preferenceRoot == null) {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(getContext());
AccessToken[] accessTokens = helper.getAccessTokens();
CharSequence[] entries = new CharSequence[accessTokens.length + 1];
CharSequence[] entryValues = new CharSequence[accessTokens.length + 1];
for (int i = 0; i < accessTokens.length; i++) {
AccessToken accessToken = accessTokens[i];
entries[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
entryValues[i] = accessToken.getKeyString();
}
entries[entries.length - 1] = getString(R.string.add_account);
entryValues[entryValues.length - 1] = "-1";
ListPreference nowAccountList = (ListPreference) findPreference("AccountKey");
nowAccountList.setEntries(entries);
nowAccountList.setEntryValues(entryValues);
nowAccountList.setDefaultValue(defaultSharedPreferences.getString("AccountKey", "-1"));
nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.equals("-1")) {
GlobalApplication.twitter = null;
startActivity(new Intent(getContext(), OAuthActivity.class));
} else {
TokenSQLiteOpenHelper tokenOpenHelper = new TokenSQLiteOpenHelper(this.getContext());
AccessToken accessToken = tokenOpenHelper.getAccessToken((String) newValue);
tokenOpenHelper.close();
((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}
return true;
});
findPreference("logout").setOnPreferenceClickListener(preference -> {
new AlertDialog.Builder(getContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
helper.deleteAccessToken(helper.getAccessToken(defaultSharedPreferences.getString("AccountKey", "-1")));
int point = helper.getSize() - 1;
if (point != -1) {
AccessToken accessToken = helper.getAccessTokens()[point];
defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
defaultSharedPreferences.edit().putString("AccountKey", "-1").apply();
GlobalApplication.twitter = null;
startActivity(new Intent(getContext(), OAuthActivity.class));
}
}).setNeutralButton(R.string.back, (dialog, i) -> dialog.cancel()).show();
return false;
});
ListPreference nowThemeMode = (ListPreference) findPreference("nightModeType");
nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
switch(String.valueOf(newValue)) {
case "mode_night_no":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case "mode_night_auto":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
break;
case "mode_night_follow_system":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
break;
case "mode_night_yes":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
default:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
return true;
});
Preference causeError = findPreference("cause_error");
causeError.setOnPreferenceClickListener(preference -> {
getActivity().finish();
throw new NullPointerException();
});
Preference licenseThisApp = findPreference("license_at_this_app");
licenseThisApp.setOnPreferenceClickListener(preference -> {
getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twicalico"));
return true;
});
Preference sourceCodeLink = findPreference("source_code_link");
sourceCodeLink.setOnPreferenceClickListener(preference -> {
AppCustomTabsKt.launchChromeCustomTabs(getContext(), "https://github.com/moko256/twicalico");
return false;
});
Preference version = findPreference("app_version");
version.setSummary(BuildConfig.VERSION_NAME);
version.setOnPreferenceClickListener(preference -> {
Date birthday = new Date(1446956982000L);
Toast.makeText(getContext(), getString(R.string.birthday_of_this_app_is, birthday) + "\n\n" + getString(R.string.age_of_this_app_is, (int) Math.floor((new Date().getTime() - birthday.getTime()) / (31557600000L))), Toast.LENGTH_LONG).show();
return false;
});
} else if (preferenceRoot.equals("license")) {
PreferenceScreen license = getPreferenceScreen();
for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
license.getPreference(i).setOnPreferenceClickListener(preference -> {
getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
preference.getKey().substring(12)));
return true;
});
}
}
}
use of android.support.v7.preference.Preference in project aware-client by denzilferreira.
the class Aware_Client method onPreferenceTreeClick.
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, final Preference preference) {
if (preference instanceof PreferenceScreen) {
Dialog subpref = ((PreferenceScreen) preference).getDialog();
ViewGroup root = (ViewGroup) subpref.findViewById(android.R.id.content).getParent();
Toolbar toolbar = new Toolbar(this);
toolbar.setBackgroundColor(ContextCompat.getColor(preferenceScreen.getContext(), R.color.primary));
toolbar.setTitleTextColor(ContextCompat.getColor(preferenceScreen.getContext(), android.R.color.white));
toolbar.setTitle(preference.getTitle());
// add to the top
root.addView(toolbar, 0);
subpref.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
new SettingsSync().execute(preference);
}
});
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
use of android.support.v7.preference.Preference in project android_packages_apps_crDroidSettings by crdroidandroid.
the class SlimRecentsBlacklist method refreshCustomApplicationPrefs.
private void refreshCustomApplicationPrefs() {
if (!parsePackageList()) {
return;
}
// Add the Application Preferences
if (mBlacklistPrefList != null) {
mBlacklistPrefList.removeAll();
for (Package pkg : mBlacklistPackages.values()) {
try {
Preference pref = createPreferenceFromInfo(pkg);
mBlacklistPrefList.addPreference(pref);
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
}
}
// Keep these at the top
mAddBlacklistPref.setOrder(0);
// Add 'add' options
mBlacklistPrefList.addPreference(mAddBlacklistPref);
}
Aggregations