Search in sources :

Example 31 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener 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());
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) TimePickerPreference(com.fsck.k9.preferences.TimePickerPreference) CheckBoxPreference(android.preference.CheckBoxPreference) OpenPgpAppPreference(org.openintents.openpgp.util.OpenPgpAppPreference) CheckBoxListPreference(com.fsck.k9.preferences.CheckBoxListPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) FileBrowserFailOverCallback(com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback) File(java.io.File)

Example 32 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener 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();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) CheckBoxPreference(android.preference.CheckBoxPreference) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View) Uri(android.net.Uri) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ActionBar(android.support.v7.app.ActionBar)

Example 33 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project Etar-Calendar by Etar-Group.

the class GeneralPreferences method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Activity activity = getActivity();
    // Make sure to always use the same preferences file regardless of the package name
    // we're running under
    final PreferenceManager preferenceManager = getPreferenceManager();
    final SharedPreferences sharedPreferences = getSharedPreferences(activity);
    preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.general_preferences);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
    mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
        PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
        mAlertGroup.removePreference(mVibrate);
    }
    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
    String ringToneUri = Utils.getRingTonePreference(activity);
    // Set the ringToneUri to the backup-able shared pref only so that
    // the Ringtone dialog will open up with the correct value.
    final Editor editor = preferenceScreen.getEditor();
    editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();
    String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
    mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);
    mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
    mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
    mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();
    mTheme.setSummary(mTheme.getEntry());
    mWeekStart.setSummary(mWeekStart.getEntry());
    mDayWeek.setSummary(mDayWeek.getEntry());
    mDefaultReminder.setSummary(mDefaultReminder.getEntry());
    mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
    mDefaultStart.setSummary(mDefaultStart.getEntry());
    // This triggers an asynchronous call to the provider to refresh the data in shared pref
    mTimeZoneId = Utils.getTimeZone(activity, null);
    SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);
    // off, we will explicitly read it.
    if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
        mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
    }
    mHomeTZ.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showTimezoneDialog();
            return true;
        }
    });
    if (mTzPickerUtils == null) {
        mTzPickerUtils = new TimeZonePickerUtils(getActivity());
    }
    CharSequence timezoneName = mTzPickerUtils.getGmtDisplayName(getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
    mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);
    TimeZonePickerDialog tzpd = (TimeZonePickerDialog) activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
        tzpd.setOnTimeZoneSetListener(this);
    }
    migrateOldPreferences(sharedPreferences);
    updateChildPreferences();
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) PreferenceManager(android.preference.PreferenceManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) TimeZonePickerUtils(com.android.timezonepicker.TimeZonePickerUtils) TimeZonePickerDialog(com.android.timezonepicker.TimeZonePickerDialog) Vibrator(android.os.Vibrator) Editor(android.content.SharedPreferences.Editor)

Example 34 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project android by nextcloud.

the class Preferences method setupCalendarPreference.

private void setupCalendarPreference(PreferenceCategory preferenceCategoryMore) {
    boolean calendarContactsEnabled = getResources().getBoolean(R.bool.davdroid_integration_enabled);
    Preference pCalendarContacts = findPreference("calendar_contacts");
    if (pCalendarContacts != null) {
        if (calendarContactsEnabled) {
            final Activity activity = this;
            pCalendarContacts.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    try {
                        launchDavDroidLogin();
                    } catch (Throwable t) {
                        Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t);
                        DisplayUtils.showSnackMessage(activity, R.string.prefs_calendar_contacts_address_resolve_error);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pCalendarContacts);
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) PreferenceActivity(android.preference.PreferenceActivity) Activity(android.app.Activity)

Example 35 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project android by nextcloud.

the class Preferences method setupLoggingPreference.

private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore) {
    SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG || appPrefs.getBoolean(PREFERENCE_EXPERT_MODE, false);
    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 {
            preferenceCategoryMore.removePreference(pLogger);
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) SharedPreferences(android.content.SharedPreferences) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) Intent(android.content.Intent)

Aggregations

OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)51 Preference (android.preference.Preference)50 Intent (android.content.Intent)26 ListPreference (android.preference.ListPreference)21 CheckBoxPreference (android.preference.CheckBoxPreference)15 SwitchPreference (android.preference.SwitchPreference)15 DialogInterface (android.content.DialogInterface)8 SharedPreferences (android.content.SharedPreferences)8 PreferenceCategory (android.preference.PreferenceCategory)8 PreferenceScreen (android.preference.PreferenceScreen)8 EditTextPreference (android.preference.EditTextPreference)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)7 AlertDialog (android.app.AlertDialog)6 Bundle (android.os.Bundle)6 Uri (android.net.Uri)5 View (android.view.View)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 TextView (android.widget.TextView)4 Activity (android.app.Activity)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3