use of android.preference.CheckBoxPreference in project k-9 by k9mail.
the class Prefs method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.global_preferences);
mTheme = setupListPreference(PREFERENCE_THEME, themeIdToName(K9.getK9Theme()));
mFixedMessageTheme = (CheckBoxPreference) findPreference(PREFERENCE_FIXED_MESSAGE_THEME);
mFixedMessageTheme.setChecked(K9.useFixedMessageViewTheme());
mMessageTheme = setupListPreference(PREFERENCE_MESSAGE_VIEW_THEME, themeIdToName(K9.getK9MessageViewThemeSetting()));
mComposerTheme = setupListPreference(PREFERENCE_COMPOSER_THEME, themeIdToName(K9.getK9ComposerThemeSetting()));
findPreference(PREFERENCE_FONT_SIZE).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onFontSizeSettings();
return true;
}
});
mAnimations = (CheckBoxPreference) findPreference(PREFERENCE_ANIMATIONS);
mAnimations.setChecked(K9.showAnimations());
mGestures = (CheckBoxPreference) findPreference(PREFERENCE_GESTURES);
mGestures.setChecked(K9.gesturesEnabled());
mVolumeNavigation = (CheckBoxListPreference) findPreference(PREFERENCE_VOLUME_NAVIGATION);
mVolumeNavigation.setItems(new CharSequence[] { getString(R.string.volume_navigation_message), getString(R.string.volume_navigation_list) });
mVolumeNavigation.setCheckedItems(new boolean[] { K9.useVolumeKeysForNavigationEnabled(), K9.useVolumeKeysForListNavigationEnabled() });
mStartIntegratedInbox = (CheckBoxPreference) findPreference(PREFERENCE_START_INTEGRATED_INBOX);
mStartIntegratedInbox.setChecked(K9.startIntegratedInbox());
mConfirmActions = (CheckBoxListPreference) findPreference(PREFERENCE_CONFIRM_ACTIONS);
boolean canDeleteFromNotification = NotificationController.platformSupportsExtendedNotifications();
CharSequence[] confirmActionEntries = new CharSequence[canDeleteFromNotification ? 6 : 5];
boolean[] confirmActionValues = new boolean[confirmActionEntries.length];
int index = 0;
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete);
confirmActionValues[index++] = K9.confirmDelete();
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete_starred);
confirmActionValues[index++] = K9.confirmDeleteStarred();
if (canDeleteFromNotification) {
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete_notif);
confirmActionValues[index++] = K9.confirmDeleteFromNotification();
}
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_spam);
confirmActionValues[index++] = K9.confirmSpam();
confirmActionEntries[index] = getString(R.string.global_settings_confirm_menu_discard);
confirmActionValues[index++] = K9.confirmDiscardMessage();
confirmActionEntries[index] = getString(R.string.global_settings_confirm_menu_mark_all_read);
confirmActionValues[index++] = K9.confirmMarkAllRead();
mConfirmActions.setItems(confirmActionEntries);
mConfirmActions.setCheckedItems(confirmActionValues);
mNotificationHideSubject = setupListPreference(PREFERENCE_NOTIFICATION_HIDE_SUBJECT, K9.getNotificationHideSubject().toString());
mMeasureAccounts = (CheckBoxPreference) findPreference(PREFERENCE_MEASURE_ACCOUNTS);
mMeasureAccounts.setChecked(K9.measureAccounts());
mCountSearch = (CheckBoxPreference) findPreference(PREFERENCE_COUNT_SEARCH);
mCountSearch.setChecked(K9.countSearchMessages());
mHideSpecialAccounts = (CheckBoxPreference) findPreference(PREFERENCE_HIDE_SPECIAL_ACCOUNTS);
mHideSpecialAccounts.setChecked(K9.isHideSpecialAccounts());
mPreviewLines = setupListPreference(PREFERENCE_MESSAGELIST_PREVIEW_LINES, Integer.toString(K9.messageListPreviewLines()));
mSenderAboveSubject = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_SENDER_ABOVE_SUBJECT);
mSenderAboveSubject.setChecked(K9.messageListSenderAboveSubject());
mCheckboxes = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_CHECKBOXES);
mCheckboxes.setChecked(K9.messageListCheckboxes());
mStars = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_STARS);
mStars.setChecked(K9.messageListStars());
mShowCorrespondentNames = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_SHOW_CORRESPONDENT_NAMES);
mShowCorrespondentNames.setChecked(K9.showCorrespondentNames());
mShowContactName = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_SHOW_CONTACT_NAME);
mShowContactName.setChecked(K9.showContactName());
mShowContactPicture = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_SHOW_CONTACT_PICTURE);
mShowContactPicture.setChecked(K9.showContactPicture());
mColorizeMissingContactPictures = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_COLORIZE_MISSING_CONTACT_PICTURES);
mColorizeMissingContactPictures.setChecked(K9.isColorizeMissingContactPictures());
mBackgroundAsUnreadIndicator = (CheckBoxPreference) findPreference(PREFERENCE_BACKGROUND_AS_UNREAD_INDICATOR);
mBackgroundAsUnreadIndicator.setChecked(K9.useBackgroundAsUnreadIndicator());
mChangeContactNameColor = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR);
mChangeContactNameColor.setChecked(K9.changeContactNameColor());
mThreadedView = (CheckBoxPreference) findPreference(PREFERENCE_THREADED_VIEW);
mThreadedView.setChecked(K9.isThreadedViewEnabled());
if (K9.changeContactNameColor()) {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
} else {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_default);
}
mChangeContactNameColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final Boolean checked = (Boolean) newValue;
if (checked) {
onChooseContactNameColor();
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
} else {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_default);
}
mChangeContactNameColor.setChecked(checked);
return false;
}
});
mFixedWidth = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGEVIEW_FIXEDWIDTH);
mFixedWidth.setChecked(K9.messageViewFixedWidthFont());
mReturnToList = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST);
mReturnToList.setChecked(K9.messageViewReturnToList());
mShowNext = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGEVIEW_SHOW_NEXT);
mShowNext.setChecked(K9.messageViewShowNext());
mAutofitWidth = (CheckBoxPreference) findPreference(PREFERENCE_AUTOFIT_WIDTH);
mAutofitWidth.setChecked(K9.autofitWidth());
mQuietTimeEnabled = (CheckBoxPreference) findPreference(PREFERENCE_QUIET_TIME_ENABLED);
mQuietTimeEnabled.setChecked(K9.getQuietTimeEnabled());
mDisableNotificationDuringQuietTime = (CheckBoxPreference) findPreference(PREFERENCE_DISABLE_NOTIFICATION_DURING_QUIET_TIME);
mDisableNotificationDuringQuietTime.setChecked(!K9.isNotificationDuringQuietTimeEnabled());
mQuietTimeStarts = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_STARTS);
mQuietTimeStarts.setDefaultValue(K9.getQuietTimeStarts());
mQuietTimeStarts.setSummary(K9.getQuietTimeStarts());
mQuietTimeStarts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String time = (String) newValue;
mQuietTimeStarts.setSummary(time);
return false;
}
});
mQuietTimeEnds = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_ENDS);
mQuietTimeEnds.setSummary(K9.getQuietTimeEnds());
mQuietTimeEnds.setDefaultValue(K9.getQuietTimeEnds());
mQuietTimeEnds.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String time = (String) newValue;
mQuietTimeEnds.setSummary(time);
return false;
}
});
mNotificationQuickDelete = setupListPreference(PREFERENCE_NOTIF_QUICK_DELETE, K9.getNotificationQuickDeleteBehaviour().toString());
if (!NotificationController.platformSupportsExtendedNotifications()) {
PreferenceScreen prefs = (PreferenceScreen) findPreference("notification_preferences");
prefs.removePreference(mNotificationQuickDelete);
mNotificationQuickDelete = null;
}
mLockScreenNotificationVisibility = setupListPreference(PREFERENCE_LOCK_SCREEN_NOTIFICATION_VISIBILITY, K9.getLockScreenNotificationVisibility().toString());
if (!NotificationController.platformSupportsLockScreenNotifications()) {
((PreferenceScreen) findPreference("notification_preferences")).removePreference(mLockScreenNotificationVisibility);
mLockScreenNotificationVisibility = null;
}
mBackgroundOps = setupListPreference(PREFERENCE_BACKGROUND_OPS, K9.getBackgroundOps().name());
mDebugLogging = (CheckBoxPreference) findPreference(PREFERENCE_DEBUG_LOGGING);
mSensitiveLogging = (CheckBoxPreference) findPreference(PREFERENCE_SENSITIVE_LOGGING);
mHideUserAgent = (CheckBoxPreference) findPreference(PREFERENCE_HIDE_USERAGENT);
mHideTimeZone = (CheckBoxPreference) findPreference(PREFERENCE_HIDE_TIMEZONE);
mDebugLogging.setChecked(K9.isDebug());
mSensitiveLogging.setChecked(K9.DEBUG_SENSITIVE);
mHideUserAgent.setChecked(K9.hideUserAgent());
mHideTimeZone.setChecked(K9.hideTimeZone());
mOpenPgpProvider = (OpenPgpAppPreference) findPreference(PREFERENCE_OPENPGP_PROVIDER);
mOpenPgpProvider.setValue(K9.getOpenPgpProvider());
if (OpenPgpAppPreference.isApgInstalled(getApplicationContext())) {
mOpenPgpProvider.addLegacyProvider(APG_PROVIDER_PLACEHOLDER, getString(R.string.apg), R.drawable.ic_apg_small);
}
mOpenPgpProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
if (APG_PROVIDER_PLACEHOLDER.equals(value)) {
mOpenPgpProvider.setValue("");
showDialog(DIALOG_APG_DEPRECATION_WARNING);
} else {
mOpenPgpProvider.setValue(value);
}
return false;
}
});
mOpenPgpSupportSignOnly = (CheckBoxPreference) findPreference(PREFERENCE_OPENPGP_SUPPORT_SIGN_ONLY);
mOpenPgpSupportSignOnly.setChecked(K9.getOpenPgpSupportSignOnly());
mAttachmentPathPreference = findPreference(PREFERENCE_ATTACHMENT_DEF_PATH);
mAttachmentPathPreference.setSummary(K9.getAttachmentDefaultPath());
mAttachmentPathPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
FileBrowserHelper.getInstance().showFileBrowserActivity(Prefs.this, new File(K9.getAttachmentDefaultPath()), ACTIVITY_CHOOSE_FOLDER, callback);
return true;
}
FileBrowserFailOverCallback callback = new FileBrowserFailOverCallback() {
@Override
public void onPathEntered(String path) {
mAttachmentPathPreference.setSummary(path);
K9.setAttachmentDefaultPath(path);
}
@Override
public void onCancel() {
// canceled, do nothing
}
};
});
mWrapFolderNames = (CheckBoxPreference) findPreference(PREFERENCE_FOLDERLIST_WRAP_NAME);
mWrapFolderNames.setChecked(K9.wrapFolderNames());
mVisibleRefileActions = (CheckBoxListPreference) findPreference(PREFERENCE_MESSAGEVIEW_VISIBLE_REFILE_ACTIONS);
CharSequence[] visibleRefileActionsEntries = new CharSequence[5];
visibleRefileActionsEntries[VISIBLE_REFILE_ACTIONS_DELETE] = getString(R.string.delete_action);
visibleRefileActionsEntries[VISIBLE_REFILE_ACTIONS_ARCHIVE] = getString(R.string.archive_action);
visibleRefileActionsEntries[VISIBLE_REFILE_ACTIONS_MOVE] = getString(R.string.move_action);
visibleRefileActionsEntries[VISIBLE_REFILE_ACTIONS_COPY] = getString(R.string.copy_action);
visibleRefileActionsEntries[VISIBLE_REFILE_ACTIONS_SPAM] = getString(R.string.spam_action);
boolean[] visibleRefileActionsValues = new boolean[5];
visibleRefileActionsValues[VISIBLE_REFILE_ACTIONS_DELETE] = K9.isMessageViewDeleteActionVisible();
visibleRefileActionsValues[VISIBLE_REFILE_ACTIONS_ARCHIVE] = K9.isMessageViewArchiveActionVisible();
visibleRefileActionsValues[VISIBLE_REFILE_ACTIONS_MOVE] = K9.isMessageViewMoveActionVisible();
visibleRefileActionsValues[VISIBLE_REFILE_ACTIONS_COPY] = K9.isMessageViewCopyActionVisible();
visibleRefileActionsValues[VISIBLE_REFILE_ACTIONS_SPAM] = K9.isMessageViewSpamActionVisible();
mVisibleRefileActions.setItems(visibleRefileActionsEntries);
mVisibleRefileActions.setCheckedItems(visibleRefileActionsValues);
mSplitViewMode = (ListPreference) findPreference(PREFERENCE_SPLITVIEW_MODE);
initListPreference(mSplitViewMode, K9.getSplitViewMode().name(), mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues());
}
use of android.preference.CheckBoxPreference in project android by cSploit.
the class MsfPreferences method createPreferenceHierarchy.
private PreferenceScreen createPreferenceHierarchy() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
String title = null;
PreferenceCategory cat_required = new PreferenceCategory(this);
PreferenceCategory cat_general = new PreferenceCategory(this);
PreferenceCategory cat_advanced = new PreferenceCategory(this);
PreferenceCategory cat_evasion = new PreferenceCategory(this);
ArrayList<Preference> required = new ArrayList<Preference>();
ArrayList<Preference> general = new ArrayList<Preference>();
ArrayList<Preference> advanced = new ArrayList<Preference>();
ArrayList<Preference> evasion = new ArrayList<Preference>();
Payload payload = System.getCurrentPayload();
MsfExploit exploit = (MsfExploit) System.getCurrentExploit();
System.setCurrentPayload(null);
System.setCurrentExploit(null);
if (payload != null) {
options = payload.getOptions();
title = payload.toString();
} else if (exploit != null) {
options = exploit.getOptions();
title = exploit.toString();
}
if (options == null) {
options = new ArrayList<Option>();
title = getString(R.string.error);
String error_message;
if (exploit != null)
error_message = String.format("cannot retrieve options for '%s'", exploit.getName());
else if (payload != null)
error_message = String.format("cannot retrieve options for '%s'", payload.getName());
else
error_message = "called without Payload or MsfExploit";
Logger.error(error_message);
}
setTitle(title + " > " + getString(R.string.menu_settings));
cat_required.setTitle(R.string.required);
cat_general.setTitle(R.string.pref_general);
cat_advanced.setTitle(R.string.pref_advanced);
cat_evasion.setTitle(R.string.evasion);
for (Option opt : options) {
Preference item = null;
int inputType = 0;
switch(opt.getType()) {
case ADDRESS:
case STRING:
case PATH:
case INTEGER:
case PORT:
item = new EditTextPreference(this);
item.setTitle(opt.getName());
((EditTextPreference) item).setDialogTitle(opt.getName());
((EditTextPreference) item).setDialogMessage(opt.getDescription());
item.setSummary(opt.getDescription());
item.setKey(opt.getName());
item.setDefaultValue(opt.getValue());
break;
case BOOLEAN:
item = new CheckBoxPreference(this);
item.setTitle(opt.getName());
item.setKey(opt.getName());
item.setSummary(opt.getDescription());
((CheckBoxPreference) item).setChecked(opt.getValue().equals("true"));
break;
case ENUM:
item = new ListPreference(this);
((ListPreference) item).setEntries(opt.getEnum());
((ListPreference) item).setEntryValues(opt.getEnum());
((ListPreference) item).setDialogTitle(opt.getName());
((ListPreference) item).setValue(opt.getValue());
item.setKey(opt.getName());
item.setTitle(opt.getName());
item.setSummary(opt.getDescription());
break;
}
switch(opt.getType()) {
case ADDRESS:
inputType = InputType.TYPE_CLASS_PHONE;
break;
case PATH:
case STRING:
inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
break;
case PORT:
case INTEGER:
inputType = InputType.TYPE_CLASS_NUMBER;
break;
}
if (inputType != 0)
((EditTextPreference) item).getEditText().setInputType(inputType);
if (opt.isAdvanced())
advanced.add(item);
else if (opt.isRequired())
required.add(item);
else if (opt.isEvasion())
evasion.add(item);
else
general.add(item);
if (item != null) {
item.setOnPreferenceChangeListener(listener);
}
}
if (required.size() > 0) {
root.addPreference(cat_required);
for (Preference i : required) cat_required.addPreference(i);
}
if (general.size() > 0) {
root.addPreference(cat_general);
for (Preference i : general) cat_general.addPreference(i);
}
if (advanced.size() > 0) {
root.addPreference(cat_advanced);
for (Preference i : advanced) cat_advanced.addPreference(i);
}
if (evasion.size() > 0) {
root.addPreference(cat_evasion);
for (Preference i : evasion) cat_evasion.addPreference(i);
}
return root;
}
use of android.preference.CheckBoxPreference in project routerkeygenAndroid by routerkeygen.
the class Preferences method onCreate.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
getActionBar().setDisplayHomeAsUpEnabled(true);
findPreference("download").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (isDictionaryServiceRunning()) {
Toast.makeText(getBaseContext(), getString(R.string.pref_msg_download_running), Toast.LENGTH_SHORT).show();
return true;
}
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo == null || !netInfo.isConnectedOrConnecting()) {
Toast.makeText(getBaseContext(), getString(R.string.pref_msg_no_network), Toast.LENGTH_SHORT).show();
return true;
}
// wifi connection
if ((((WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE))).getConnectionInfo().getSSID() != null) {
try {
checkCurrentDictionary();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else
showDialog(DIALOG_ASK_DOWNLOAD);
return true;
}
});
boolean app_installed = AdsUtils.checkDonation(this);
final PreferenceCategory mCategory = (PreferenceCategory) findPreference("2section");
if (!app_installed) {
mCategory.removePreference(findPreference("analytics_enabled"));
// If you haven't the donate app installed remove the paypal donate
// link.
mCategory.removePreference(findPreference("donate_paypal"));
findPreference("donate_playstore").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GOOGLE_PLAY_DOWNLOADER)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + GOOGLE_PLAY_DOWNLOADER)));
}
Toast.makeText(getApplicationContext(), R.string.msg_donation, Toast.LENGTH_LONG).show();
return true;
}
});
} else {
// If you have the donate app installed no need to link to it.
mCategory.removePreference(findPreference("donate_playstore"));
if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) {
//Play Store is quite restrictive nowadays
mCategory.removePreference(findPreference("donate_paypal"));
} else {
findPreference("donate_paypal").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
final String donateLink = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V3FFBTRTTV5DN";
Uri uri = Uri.parse(donateLink);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
}
});
}
}
if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) {
mCategory.removePreference(findPreference("update"));
} else {
findPreference("update").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
showDialog(DIALOG_WAIT);
}
protected Void doInBackground(Void... params) {
lastVersion = UpdateCheckerService.getLatestVersion();
return null;
}
protected void onPostExecute(Void result) {
removeDialog(DIALOG_WAIT);
if (isFinishing())
return;
if (lastVersion == null) {
showDialog(DIALOG_ERROR);
return;
}
if (!Preferences.VERSION.equals(lastVersion.version)) {
showDialog(DIALOG_UPDATE_NEEDED);
} else {
Toast.makeText(Preferences.this, R.string.msg_app_updated, Toast.LENGTH_SHORT).show();
}
}
};
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute();
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// Checking for updates every week
startService(new Intent(getApplicationContext(), UpdateCheckerService.class));
return true;
}
});
}
findPreference("changelog").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_CHANGELOG);
return true;
}
});
findPreference("about").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_ABOUT);
return true;
}
});
findPreference(dicLocalPref).setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(new Intent(getApplicationContext(), FileChooserActivity.class), 0);
return true;
}
});
final CheckBoxPreference autoScan = (CheckBoxPreference) findPreference("autoScan");
autoScan.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
findPreference("autoScanInterval").setEnabled(autoScan.isChecked());
return true;
}
});
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
findPreference("autoScanInterval").setEnabled(prefs.getBoolean(Preferences.autoScanPref, getResources().getBoolean(R.bool.autoScanDefault)));
}
use of android.preference.CheckBoxPreference in project Signal-Android by WhisperSystems.
the class AdvancedPreferenceFragment method initializePushMessagingToggle.
private void initializePushMessagingToggle() {
CheckBoxPreference preference = (CheckBoxPreference) this.findPreference(PUSH_MESSAGING_PREF);
if (TextSecurePreferences.isPushRegistered(getActivity())) {
preference.setChecked(true);
preference.setSummary(TextSecurePreferences.getLocalNumber(getActivity()));
} else {
preference.setChecked(false);
preference.setSummary(R.string.preferences__free_private_messages_and_calls);
}
preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
}
use of android.preference.CheckBoxPreference 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();
}
Aggregations