use of android.support.v7.preference.Preference.OnPreferenceChangeListener 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.OnPreferenceChangeListener in project android by owncloud.
the class Preferences method onCreate.
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.actionbar_settings);
// For adding content description tag to a title field in the action bar
int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
if (actionBarTitleView != null) {
// it's null in Android 2.x
getWindow().getDecorView().findViewById(actionBarTitleId).setContentDescription(getString(R.string.actionbar_settings));
}
// Load package info
String temp;
try {
PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
temp = pkg.versionName;
} catch (NameNotFoundException e) {
temp = "";
Log_OC.e(TAG, "Error while showing about dialog", e);
}
final String appVersion = temp;
// Register context menu for list of preferences.
registerForContextMenu(getListView());
pCode = (CheckBoxPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
if (pCode != null) {
pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
Boolean incoming = (Boolean) newValue;
i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : PassCodeActivity.ACTION_CHECK_WITH_RESULT);
startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);
// Don't update just yet, we will decide on it in onActivityResult
return false;
}
});
}
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
Preference pHelp = findPreference("help");
if (pHelp != null) {
if (helpEnabled) {
pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String helpWeb = (String) getText(R.string.url_help);
if (helpWeb != null && helpWeb.length() > 0) {
Uri uriUrl = Uri.parse(helpWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(intent);
}
return true;
}
});
} else {
preferenceCategory.removePreference(pHelp);
}
}
boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
Preference pRecommend = findPreference("recommend");
if (pRecommend != null) {
if (recommendEnabled) {
pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.setData(Uri.parse(getString(R.string.mail_recommend)));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String appName = getString(R.string.app_name);
String downloadUrl = getString(R.string.url_app_download);
String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl);
intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
intent.putExtra(Intent.EXTRA_TEXT, recommendText);
startActivity(intent);
return (true);
}
});
} else {
preferenceCategory.removePreference(pRecommend);
}
}
boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
Preference pFeedback = findPreference("feedback");
if (pFeedback != null) {
if (feedbackEnabled) {
pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String feedbackMail = (String) getText(R.string.mail_feedback);
String feedback = (String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
intent.setData(Uri.parse(feedbackMail));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
}
});
} else {
preferenceCategory.removePreference(pFeedback);
}
}
boolean privacyPolicyEnabled = getResources().getBoolean(R.bool.privacy_policy_enabled);
Preference pPrivacyPolicy = findPreference("privacyPolicy");
if (pPrivacyPolicy != null) {
if (privacyPolicyEnabled) {
pPrivacyPolicy.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent privacyPolicyIntent = new Intent(getApplicationContext(), PrivacyPolicyActivity.class);
startActivity(privacyPolicyIntent);
return true;
}
});
} else {
preferenceCategory.removePreference(pPrivacyPolicy);
}
}
boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG;
Preference pLogger = findPreference("logger");
if (pLogger != null) {
if (loggerEnabled) {
pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
startActivity(loggerIntent);
return true;
}
});
} else {
preferenceCategory.removePreference(pLogger);
}
}
boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
Preference pImprint = findPreference("imprint");
if (pImprint != null) {
if (imprintEnabled) {
pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String imprintWeb = (String) getText(R.string.url_imprint);
if (imprintWeb != null && imprintWeb.length() > 0) {
Uri uriUrl = Uri.parse(imprintWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(intent);
}
//ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
return true;
}
});
} else {
preferenceCategory.removePreference(pImprint);
}
}
mPrefInstantUploadPath = findPreference("instant_upload_path");
if (mPrefInstantUploadPath != null) {
mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
mUploadPath += OCFile.PATH_SEPARATOR;
}
Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
return true;
}
});
}
mPrefInstantUploadCategory = (PreferenceCategory) findPreference("instant_uploading_category");
mPrefInstantUploadWiFi = findPreference("instant_upload_on_wifi");
mPrefInstantUpload = findPreference("instant_uploading");
toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
mPrefInstantUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enableInstantPicture = (Boolean) newValue;
toggleInstantPictureOptions(enableInstantPicture);
toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), enableInstantPicture);
return true;
}
});
mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
if (mPrefInstantVideoUploadPath != null) {
mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
mUploadVideoPath += OCFile.PATH_SEPARATOR;
}
Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
return true;
}
});
}
mPrefInstantVideoUploadWiFi = findPreference("instant_video_upload_on_wifi");
mPrefInstantVideoUpload = findPreference("instant_video_uploading");
toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
toggleInstantVideoOptions((Boolean) newValue);
toggleInstantUploadCommonOptions((Boolean) newValue, ((CheckBoxPreference) mPrefInstantUpload).isChecked());
return true;
}
});
mPrefInstantUploadSourcePath = findPreference("instant_upload_source_path");
if (mPrefInstantUploadSourcePath != null) {
mPrefInstantUploadSourcePath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mSourcePath.endsWith(File.separator)) {
mSourcePath += File.separator;
}
LocalFolderPickerActivity.startLocalFolderPickerActivityForResult(Preferences.this, mSourcePath, ACTION_SELECT_SOURCE_PATH);
return true;
}
});
} else {
Log_OC.e(TAG, "Lost preference instant_upload_source_path");
}
mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour");
toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), ((CheckBoxPreference) mPrefInstantUpload).isChecked());
/* About App */
pAboutApp = (Preference) findPreference("about_app");
if (pAboutApp != null) {
pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
}
loadInstantUploadPath();
loadInstantUploadVideoPath();
loadInstantUploadSourcePath();
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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 android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ConfigureNotificationSettings method initPulse.
// === Pulse notification light ===
private void initPulse() {
final NotificationManager nm = mContext.getSystemService(NotificationManager.class);
final PreferenceCategory category = (PreferenceCategory) findPreference("lights");
mNotificationPulse = (TwoStatePreference) category.findPreference(KEY_NOTIFICATION_PULSE);
if (mNotificationPulse == null) {
Log.i(TAG, "Preference not found: " + KEY_NOTIFICATION_PULSE);
return;
}
if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed) || !nm.doLightsSupport(NotificationManager.LIGHTS_PULSATING_LED)) {
category.removePreference(mNotificationPulse);
} else {
updatePulse();
mNotificationPulse.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean) newValue;
return Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, val ? 1 : 0);
}
});
}
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ZenAccessSettings method reloadList.
private void reloadList() {
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
final ArrayList<ApplicationInfo> apps = new ArrayList<>();
final ArraySet<String> requesting = mNoMan.getPackagesRequestingNotificationPolicyAccess();
if (!requesting.isEmpty()) {
final List<ApplicationInfo> installed = mPkgMan.getInstalledApplications(0);
if (installed != null) {
for (ApplicationInfo app : installed) {
if (requesting.contains(app.packageName)) {
apps.add(app);
}
}
}
}
ArraySet<String> autoApproved = getEnabledNotificationListeners();
requesting.addAll(autoApproved);
Collections.sort(apps, new PackageItemInfo.DisplayNameComparator(mPkgMan));
for (ApplicationInfo app : apps) {
final String pkg = app.packageName;
final CharSequence label = app.loadLabel(mPkgMan);
final SwitchPreference pref = new SwitchPreference(getPrefContext());
pref.setPersistent(false);
pref.setIcon(app.loadIcon(mPkgMan));
pref.setTitle(label);
pref.setChecked(hasAccess(pkg));
if (autoApproved.contains(pkg)) {
pref.setEnabled(false);
pref.setSummary(getString(R.string.zen_access_disabled_package_warning));
}
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean access = (Boolean) newValue;
if (access) {
new ScaryWarningDialogFragment().setPkgInfo(pkg, label).show(getFragmentManager(), "dialog");
} else {
new FriendlyWarningDialogFragment().setPkgInfo(pkg, label).show(getFragmentManager(), "dialog");
}
return false;
}
});
screen.addPreference(pref);
}
}
Aggregations