Search in sources :

Example 11 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project Roundr by MohammadAdib.

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    /**
		 * Handle Preference Changes
		 */
    // Enable/Disable
    ((Preference) findPreference("enable")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
            } else {
                StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
            }
            return true;
        }
    });
    // Notification
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 16) {
        ((Preference) findPreference("notification")).setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                new AlertDialog.Builder(SettingsActivity.this).setTitle("Notification").setMessage("The notification prevents Android from killing RoundR in low memory situations.\n\nOn Android 4.1+ devices, it can be disabled via the App Info.").setPositiveButton("Continue", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        showInstalledAppDetails("mohammad.adib.roundr");
                    }
                }).show();
                return true;
            }
        });
    } else {
        ((Preference) findPreference("notification")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                StandOutWindow.sendData(SettingsActivity.this, Corner.class, Corner.wildcard, Corner.NOTIFICATION_CODE, new Bundle(), Corner.class, StandOutWindow.DISREGARD_ID);
                return true;
            }
        });
    }
    // Enable specific corners
    for (int i = 0; i < 4; i++) {
        ((Preference) findPreference("corner" + i)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                refresh();
                return true;
            }
        });
    }
    /**
		 * Overlap Settings TODO: These are messy
		 */
    ((Preference) findPreference("overlap1")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                prefs.edit().putInt("type", LayoutParams.TYPE_SYSTEM_OVERLAY).commit();
                if (prefs.getBoolean("overlap2", false))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED).commit();
            } else {
                prefs.edit().putInt("type", LayoutParams.TYPE_SYSTEM_ALERT).commit();
                if (prefs.getBoolean("overlap2", false))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL).commit();
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    // Disable and Re-enable the corners
                    StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
                }
            }).start();
            return true;
        }
    });
    ((Preference) findPreference("overlap2")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                if (prefs.getBoolean("overlap", true))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
            } else {
                if (prefs.getBoolean("overlap", true))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH).commit();
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    // Disable and Reenable the corners
                    StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
                }
            }).start();
            return true;
        }
    });
/**
		 * TODO: Figure out if Developer Options is enabled. If so, show a
		 * GitHub Source Code Link preference:
		 * "Seems like you are a developer? Check out the RoundR source code on GitHub!"
		 */
}
Also used : AlertDialog(android.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) SuppressLint(android.annotation.SuppressLint) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference)

Example 12 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project k-9 by k9mail.

the class AccountSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    try {
        final Store store = mAccount.getRemoteStore();
        mIsMoveCapable = store.isMoveCapable();
        mIsPushCapable = store.isPushCapable();
        mIsExpungeCapable = store.isExpungeCapable();
        mIsSeenFlagSupported = store.isSeenFlagSupported();
    } catch (Exception e) {
        Timber.e(e, "Could not get remote store");
    }
    addPreferencesFromResource(R.xml.account_settings_preferences);
    mMainScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_MAIN);
    mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
    mAccountDescription.setSummary(mAccount.getDescription());
    mAccountDescription.setText(mAccount.getDescription());
    mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            mAccountDescription.setSummary(summary);
            mAccountDescription.setText(summary);
            return false;
        }
    });
    mMarkMessageAsReadOnView = (CheckBoxPreference) findPreference(PREFERENCE_MARK_MESSAGE_AS_READ_ON_VIEW);
    mMarkMessageAsReadOnView.setChecked(mAccount.isMarkMessageAsReadOnView());
    mMessageFormat = (ListPreference) findPreference(PREFERENCE_MESSAGE_FORMAT);
    mMessageFormat.setValue(mAccount.getMessageFormat().name());
    mMessageFormat.setSummary(mMessageFormat.getEntry());
    mMessageFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mMessageFormat.findIndexOfValue(summary);
            mMessageFormat.setSummary(mMessageFormat.getEntries()[index]);
            mMessageFormat.setValue(summary);
            return false;
        }
    });
    mAlwaysShowCcBcc = (CheckBoxPreference) findPreference(PREFERENCE_ALWAYS_SHOW_CC_BCC);
    mAlwaysShowCcBcc.setChecked(mAccount.isAlwaysShowCcBcc());
    mMessageReadReceipt = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGE_READ_RECEIPT);
    mMessageReadReceipt.setChecked(mAccount.isMessageReadReceiptAlways());
    mAccountQuotePrefix = (EditTextPreference) findPreference(PREFERENCE_QUOTE_PREFIX);
    mAccountQuotePrefix.setSummary(mAccount.getQuotePrefix());
    mAccountQuotePrefix.setText(mAccount.getQuotePrefix());
    mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String value = newValue.toString();
            mAccountQuotePrefix.setSummary(value);
            mAccountQuotePrefix.setText(value);
            return false;
        }
    });
    mAccountDefaultQuotedTextShown = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT_QUOTED_TEXT_SHOWN);
    mAccountDefaultQuotedTextShown.setChecked(mAccount.isDefaultQuotedTextShown());
    mReplyAfterQuote = (CheckBoxPreference) findPreference(PREFERENCE_REPLY_AFTER_QUOTE);
    mReplyAfterQuote.setChecked(mAccount.isReplyAfterQuote());
    mStripSignature = (CheckBoxPreference) findPreference(PREFERENCE_STRIP_SIGNATURE);
    mStripSignature.setChecked(mAccount.isStripSignature());
    mComposingScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_COMPOSING);
    Preference.OnPreferenceChangeListener quoteStyleListener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final QuoteStyle style = QuoteStyle.valueOf(newValue.toString());
            int index = mQuoteStyle.findIndexOfValue(newValue.toString());
            mQuoteStyle.setSummary(mQuoteStyle.getEntries()[index]);
            if (style == QuoteStyle.PREFIX) {
                mComposingScreen.addPreference(mAccountQuotePrefix);
                mComposingScreen.addPreference(mReplyAfterQuote);
            } else if (style == QuoteStyle.HEADER) {
                mComposingScreen.removePreference(mAccountQuotePrefix);
                mComposingScreen.removePreference(mReplyAfterQuote);
            }
            return true;
        }
    };
    mQuoteStyle = (ListPreference) findPreference(PREFERENCE_QUOTE_STYLE);
    mQuoteStyle.setValue(mAccount.getQuoteStyle().name());
    mQuoteStyle.setSummary(mQuoteStyle.getEntry());
    mQuoteStyle.setOnPreferenceChangeListener(quoteStyleListener);
    // Call the onPreferenceChange() handler on startup to update the Preference dialogue based
    // upon the existing quote style setting.
    quoteStyleListener.onPreferenceChange(mQuoteStyle, mAccount.getQuoteStyle().name());
    mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
    mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
    mCheckFrequency.setSummary(mCheckFrequency.getEntry());
    mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mCheckFrequency.findIndexOfValue(summary);
            mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]);
            mCheckFrequency.setValue(summary);
            return false;
        }
    });
    mDisplayMode = (ListPreference) findPreference(PREFERENCE_DISPLAY_MODE);
    mDisplayMode.setValue(mAccount.getFolderDisplayMode().name());
    mDisplayMode.setSummary(mDisplayMode.getEntry());
    mDisplayMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayMode.findIndexOfValue(summary);
            mDisplayMode.setSummary(mDisplayMode.getEntries()[index]);
            mDisplayMode.setValue(summary);
            return false;
        }
    });
    mSyncMode = (ListPreference) findPreference(PREFERENCE_SYNC_MODE);
    mSyncMode.setValue(mAccount.getFolderSyncMode().name());
    mSyncMode.setSummary(mSyncMode.getEntry());
    mSyncMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncMode.findIndexOfValue(summary);
            mSyncMode.setSummary(mSyncMode.getEntries()[index]);
            mSyncMode.setValue(summary);
            return false;
        }
    });
    mTargetMode = (ListPreference) findPreference(PREFERENCE_TARGET_MODE);
    mTargetMode.setValue(mAccount.getFolderTargetMode().name());
    mTargetMode.setSummary(mTargetMode.getEntry());
    mTargetMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mTargetMode.findIndexOfValue(summary);
            mTargetMode.setSummary(mTargetMode.getEntries()[index]);
            mTargetMode.setValue(summary);
            return false;
        }
    });
    mDeletePolicy = (ListPreference) findPreference(PREFERENCE_DELETE_POLICY);
    if (!mIsSeenFlagSupported) {
        removeListEntry(mDeletePolicy, DeletePolicy.MARK_AS_READ.preferenceString());
    }
    mDeletePolicy.setValue(mAccount.getDeletePolicy().preferenceString());
    mDeletePolicy.setSummary(mDeletePolicy.getEntry());
    mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDeletePolicy.findIndexOfValue(summary);
            mDeletePolicy.setSummary(mDeletePolicy.getEntries()[index]);
            mDeletePolicy.setValue(summary);
            return false;
        }
    });
    mExpungePolicy = (ListPreference) findPreference(PREFERENCE_EXPUNGE_POLICY);
    if (mIsExpungeCapable) {
        mExpungePolicy.setValue(mAccount.getExpungePolicy().name());
        mExpungePolicy.setSummary(mExpungePolicy.getEntry());
        mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mExpungePolicy.findIndexOfValue(summary);
                mExpungePolicy.setSummary(mExpungePolicy.getEntries()[index]);
                mExpungePolicy.setValue(summary);
                return false;
            }
        });
    } else {
        ((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mExpungePolicy);
    }
    mSyncRemoteDeletions = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_REMOTE_DELETIONS);
    mSyncRemoteDeletions.setChecked(mAccount.syncRemoteDeletions());
    mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
    mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
    mSearchableFolders.setSummary(mSearchableFolders.getEntry());
    mSearchableFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSearchableFolders.findIndexOfValue(summary);
            mSearchableFolders.setSummary(mSearchableFolders.getEntries()[index]);
            mSearchableFolders.setValue(summary);
            return false;
        }
    });
    mDisplayCount = (ListPreference) findPreference(PREFERENCE_DISPLAY_COUNT);
    mDisplayCount.setValue(String.valueOf(mAccount.getDisplayCount()));
    mDisplayCount.setSummary(mDisplayCount.getEntry());
    mDisplayCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayCount.findIndexOfValue(summary);
            mDisplayCount.setSummary(mDisplayCount.getEntries()[index]);
            mDisplayCount.setValue(summary);
            return false;
        }
    });
    mMessageAge = (ListPreference) findPreference(PREFERENCE_MESSAGE_AGE);
    if (!mAccount.isSearchByDateCapable()) {
        ((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mMessageAge);
    } else {
        mMessageAge.setValue(String.valueOf(mAccount.getMaximumPolledMessageAge()));
        mMessageAge.setSummary(mMessageAge.getEntry());
        mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mMessageAge.findIndexOfValue(summary);
                mMessageAge.setSummary(mMessageAge.getEntries()[index]);
                mMessageAge.setValue(summary);
                return false;
            }
        });
    }
    mMessageSize = (ListPreference) findPreference(PREFERENCE_MESSAGE_SIZE);
    mMessageSize.setValue(String.valueOf(mAccount.getMaximumAutoDownloadMessageSize()));
    mMessageSize.setSummary(mMessageSize.getEntry());
    mMessageSize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mMessageSize.findIndexOfValue(summary);
            mMessageSize.setSummary(mMessageSize.getEntries()[index]);
            mMessageSize.setValue(summary);
            return false;
        }
    });
    mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
    mAccountDefault.setChecked(mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()));
    mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES);
    mAccountShowPictures.setValue("" + mAccount.getShowPictures());
    mAccountShowPictures.setSummary(mAccountShowPictures.getEntry());
    mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountShowPictures.findIndexOfValue(summary);
            mAccountShowPictures.setSummary(mAccountShowPictures.getEntries()[index]);
            mAccountShowPictures.setValue(summary);
            return false;
        }
    });
    mLocalStorageProvider = (ListPreference) findPreference(PREFERENCE_LOCAL_STORAGE_PROVIDER);
    {
        final Map<String, String> providers;
        providers = StorageManager.getInstance(this).getAvailableProviders();
        int i = 0;
        final String[] providerLabels = new String[providers.size()];
        final String[] providerIds = new String[providers.size()];
        for (final Map.Entry<String, String> entry : providers.entrySet()) {
            providerIds[i] = entry.getKey();
            providerLabels[i] = entry.getValue();
            i++;
        }
        mLocalStorageProvider.setEntryValues(providerIds);
        mLocalStorageProvider.setEntries(providerLabels);
        mLocalStorageProvider.setValue(mAccount.getLocalStorageProviderId());
        mLocalStorageProvider.setSummary(providers.get(mAccount.getLocalStorageProviderId()));
        mLocalStorageProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                mLocalStorageProvider.setSummary(providers.get(newValue));
                return true;
            }
        });
    }
    // IMAP-specific preferences
    mSearchScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_SEARCH);
    mCloudSearchEnabled = (CheckBoxPreference) findPreference(PREFERENCE_CLOUD_SEARCH_ENABLED);
    mRemoteSearchNumResults = (ListPreference) findPreference(PREFERENCE_REMOTE_SEARCH_NUM_RESULTS);
    mRemoteSearchNumResults.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference pref, Object newVal) {
            updateRemoteSearchLimit((String) newVal);
            return true;
        }
    });
    //mRemoteSearchFullText = (CheckBoxPreference) findPreference(PREFERENCE_REMOTE_SEARCH_FULL_TEXT);
    mPushPollOnConnect = (CheckBoxPreference) findPreference(PREFERENCE_PUSH_POLL_ON_CONNECT);
    mIdleRefreshPeriod = (ListPreference) findPreference(PREFERENCE_IDLE_REFRESH_PERIOD);
    mMaxPushFolders = (ListPreference) findPreference(PREFERENCE_MAX_PUSH_FOLDERS);
    if (mIsPushCapable) {
        mPushPollOnConnect.setChecked(mAccount.isPushPollOnConnect());
        mCloudSearchEnabled.setChecked(mAccount.allowRemoteSearch());
        String searchNumResults = Integer.toString(mAccount.getRemoteSearchNumResults());
        mRemoteSearchNumResults.setValue(searchNumResults);
        updateRemoteSearchLimit(searchNumResults);
        //mRemoteSearchFullText.setChecked(mAccount.isRemoteSearchFullText());
        mIdleRefreshPeriod.setValue(String.valueOf(mAccount.getIdleRefreshMinutes()));
        mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntry());
        mIdleRefreshPeriod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mIdleRefreshPeriod.findIndexOfValue(summary);
                mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntries()[index]);
                mIdleRefreshPeriod.setValue(summary);
                return false;
            }
        });
        mMaxPushFolders.setValue(String.valueOf(mAccount.getMaxPushFolders()));
        mMaxPushFolders.setSummary(mMaxPushFolders.getEntry());
        mMaxPushFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mMaxPushFolders.findIndexOfValue(summary);
                mMaxPushFolders.setSummary(mMaxPushFolders.getEntries()[index]);
                mMaxPushFolders.setValue(summary);
                return false;
            }
        });
        mPushMode = (ListPreference) findPreference(PREFERENCE_PUSH_MODE);
        mPushMode.setValue(mAccount.getFolderPushMode().name());
        mPushMode.setSummary(mPushMode.getEntry());
        mPushMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mPushMode.findIndexOfValue(summary);
                mPushMode.setSummary(mPushMode.getEntries()[index]);
                mPushMode.setValue(summary);
                return false;
            }
        });
    } else {
        PreferenceScreen incomingPrefs = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING);
        incomingPrefs.removePreference((PreferenceScreen) findPreference(PREFERENCE_SCREEN_PUSH_ADVANCED));
        incomingPrefs.removePreference((ListPreference) findPreference(PREFERENCE_PUSH_MODE));
        mMainScreen.removePreference(mSearchScreen);
    }
    mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
    mAccountNotify.setChecked(mAccount.isNotifyNewMail());
    mAccountNotifyNewMailMode = (ListPreference) findPreference(PREFERENCE_NOTIFY_NEW_MAIL_MODE);
    mAccountNotifyNewMailMode.setValue(mAccount.getFolderNotifyNewMailMode().name());
    mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntry());
    mAccountNotifyNewMailMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountNotifyNewMailMode.findIndexOfValue(summary);
            mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntries()[index]);
            mAccountNotifyNewMailMode.setValue(summary);
            return false;
        }
    });
    mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
    mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());
    mAccountNotifyContactsMailOnly = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY);
    mAccountNotifyContactsMailOnly.setChecked(mAccount.isNotifyContactsMailOnly());
    mAccountNotifySync = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SYNC);
    mAccountNotifySync.setChecked(mAccount.isShowOngoing());
    mAccountRingtone = (RingtonePreference) findPreference(PREFERENCE_RINGTONE);
    // XXX: The following two lines act as a workaround for the RingtonePreference
    //      which does not let us set/get the value programmatically
    SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
    String currentRingtone = (!mAccount.getNotificationSetting().shouldRing() ? null : mAccount.getNotificationSetting().getRingtone());
    prefs.edit().putString(PREFERENCE_RINGTONE, currentRingtone).commit();
    mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
    mAccountVibrate.setChecked(mAccount.getNotificationSetting().shouldVibrate());
    mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
    mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
    mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntry());
    mAccountVibratePattern.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountVibratePattern.findIndexOfValue(summary);
            mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntries()[index]);
            mAccountVibratePattern.setValue(summary);
            doVibrateTest(preference);
            return false;
        }
    });
    mAccountVibrateTimes = (ListPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
    mAccountVibrateTimes.setValue(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
    mAccountVibrateTimes.setSummary(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
    mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String value = newValue.toString();
            mAccountVibrateTimes.setSummary(value);
            mAccountVibrateTimes.setValue(value);
            doVibrateTest(preference);
            return false;
        }
    });
    mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED);
    mAccountLed.setChecked(mAccount.getNotificationSetting().isLed());
    mNotificationOpensUnread = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
    mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
    new PopulateFolderPrefsTask().execute();
    mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
    mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onChooseChipColor();
            return false;
        }
    });
    mLedColor = findPreference(PREFERENCE_LED_COLOR);
    mLedColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onChooseLedColor();
            return false;
        }
    });
    findPreference(PREFERENCE_COMPOSITION).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onCompositionSettings();
            return true;
        }
    });
    findPreference(PREFERENCE_MANAGE_IDENTITIES).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onManageIdentities();
            return true;
        }
    });
    findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            mIncomingChanged = true;
            onIncomingSettings();
            return true;
        }
    });
    findPreference(PREFERENCE_OUTGOING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onOutgoingSettings();
            return true;
        }
    });
    mHasCrypto = K9.isOpenPgpProviderConfigured();
    PreferenceScreen cryptoMenu = (PreferenceScreen) findPreference(PREFERENCE_CRYPTO);
    if (mHasCrypto) {
        mCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
        mCryptoKey.setValue(mAccount.getCryptoKey());
        mCryptoKey.setOpenPgpProvider(K9.getOpenPgpProvider());
        // TODO: other identities?
        mCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(mAccount.getIdentity(0)));
        mCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                long value = (Long) newValue;
                mCryptoKey.setValue(value);
                return false;
            }
        });
        cryptoMenu.setOnPreferenceClickListener(null);
    } else {
        cryptoMenu.setSummary(R.string.account_settings_no_openpgp_provider_configured);
        cryptoMenu.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Dialog dialog = ((PreferenceScreen) preference).getDialog();
                if (dialog != null) {
                    dialog.dismiss();
                }
                Toast.makeText(AccountSettings.this, R.string.no_crypto_provider_see_global, Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Store(com.fsck.k9.mail.Store) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) QuoteStyle(com.fsck.k9.Account.QuoteStyle) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) OpenPgpKeyPreference(org.openintents.openpgp.util.OpenPgpKeyPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Dialog(android.app.Dialog) ColorPickerDialog(com.fsck.k9.activity.ColorPickerDialog) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Map(java.util.Map)

Example 13 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 14 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project Notes by MiCode.

the class NotesPreferenceActivity method loadAccountPreference.

private void loadAccountPreference() {
    mAccountCategory.removeAll();
    Preference accountPref = new Preference(this);
    final String defaultAccount = getSyncAccountName(this);
    accountPref.setTitle(getString(R.string.preferences_account_title));
    accountPref.setSummary(getString(R.string.preferences_account_summary));
    accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            if (!GTaskSyncService.isSyncing()) {
                if (TextUtils.isEmpty(defaultAccount)) {
                    // the first time to set account
                    showSelectAccountAlertDialog();
                } else {
                    // if the account has already been set, we need to promp
                    // user about the risk
                    showChangeAccountConfirmAlertDialog();
                }
            } else {
                Toast.makeText(NotesPreferenceActivity.this, R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });
    mAccountCategory.addPreference(accountPref);
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference)

Example 15 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener 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)));
}
Also used : WifiManager(android.net.wifi.WifiManager) NetworkInfo(android.net.NetworkInfo) CheckBoxPreference(android.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) ConnectivityManager(android.net.ConnectivityManager) FileNotFoundException(java.io.FileNotFoundException) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) Uri(android.net.Uri) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) TargetApi(android.annotation.TargetApi)

Aggregations

OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)22 Preference (android.preference.Preference)21 CheckBoxPreference (android.preference.CheckBoxPreference)6 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)6 Intent (android.content.Intent)5 SharedPreferences (android.content.SharedPreferences)5 ListPreference (android.preference.ListPreference)5 DialogInterface (android.content.DialogInterface)4 PreferenceCategory (android.preference.PreferenceCategory)4 PreferenceScreen (android.preference.PreferenceScreen)4 AlertDialog (android.app.AlertDialog)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 View (android.view.View)3 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)3 SyncPreference (org.chromium.chrome.browser.preferences.SyncPreference)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 EditTextPreference (android.preference.EditTextPreference)2