@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.global_preferences); mLanguage = (ListPreference) findPreference(PREFERENCE_LANGUAGE); List<CharSequence> entryVector = new ArrayList<CharSequence>(Arrays.asList(mLanguage.getEntries())); List<CharSequence> entryValueVector = new ArrayList<CharSequence>(Arrays.asList(mLanguage.getEntryValues())); String supportedLanguages[] = getResources().getStringArray(R.array.supported_languages); Set<String> supportedLanguageSet = new HashSet<String>(Arrays.asList(supportedLanguages)); for (int i = entryVector.size() - 1; i > -1; --i) { if (!supportedLanguageSet.contains(entryValueVector.get(i))) { entryVector.remove(i); entryValueVector.remove(i); } } initListPreference( mLanguage, K9.getK9Language(), entryVector.toArray(EMPTY_CHAR_SEQUENCE_ARRAY), entryValueVector.toArray(EMPTY_CHAR_SEQUENCE_ARRAY)); 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 ? 5 : 4]; boolean[] confirmActionValues = new boolean[canDeleteFromNotification ? 5 : 4]; 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(); 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.DEBUG); mSensitiveLogging.setChecked(K9.DEBUG_SENSITIVE); mHideUserAgent.setChecked(K9.hideUserAgent()); mHideTimeZone.setChecked(K9.hideTimeZone()); 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(); checkMailDuringDoze = (CheckBoxPreference) findPreference(PREFERENCE_CHECK_MAIL_DURING_DOZE); checkMailDuringDoze.setChecked(K9.isCheckMailDuringDoze()); mVisibleRefileActions.setItems(visibleRefileActionsEntries); mVisibleRefileActions.setCheckedItems(visibleRefileActionsValues); mSplitViewMode = (ListPreference) findPreference(PREFERENCE_SPLITVIEW_MODE); initListPreference( mSplitViewMode, K9.getSplitViewMode().name(), mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues()); }
/** * Handle hotkeys * * <p>This method is called by {@link #dispatchKeyEvent(KeyEvent)} before any view had the chance * to consume this key event. * * @param keyCode The value in {@code event.getKeyCode()}. * @param event Description of the key event. * @return {@code true} if this event was consumed. */ public boolean onCustomKeyDown(final int keyCode, final KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: { if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST && K9.useVolumeKeysForNavigationEnabled()) { showPreviousMessage(); return true; } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) { mMessageListFragment.onMoveUp(); return true; } break; } case KeyEvent.KEYCODE_VOLUME_DOWN: { if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST && K9.useVolumeKeysForNavigationEnabled()) { showNextMessage(); return true; } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) { mMessageListFragment.onMoveDown(); return true; } break; } case KeyEvent.KEYCODE_C: { mMessageListFragment.onCompose(); return true; } case KeyEvent.KEYCODE_Q: { onShowFolderList(); return true; } case KeyEvent.KEYCODE_O: { mMessageListFragment.onCycleSort(); return true; } case KeyEvent.KEYCODE_I: { mMessageListFragment.onReverseSort(); return true; } case KeyEvent.KEYCODE_DEL: case KeyEvent.KEYCODE_D: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onDelete(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onDelete(); } return true; } case KeyEvent.KEYCODE_S: { mMessageListFragment.toggleMessageSelect(); return true; } case KeyEvent.KEYCODE_G: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onToggleFlagged(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onToggleFlagged(); } return true; } case KeyEvent.KEYCODE_M: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onMove(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onMove(); } return true; } case KeyEvent.KEYCODE_V: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onArchive(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onArchive(); } return true; } case KeyEvent.KEYCODE_Y: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onCopy(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onCopy(); } return true; } case KeyEvent.KEYCODE_Z: { if (mDisplayMode == DisplayMode.MESSAGE_LIST) { mMessageListFragment.onToggleRead(); } else if (mMessageViewFragment != null) { mMessageViewFragment.onToggleRead(); } return true; } case KeyEvent.KEYCODE_F: { if (mMessageViewFragment != null) { mMessageViewFragment.onForward(); } return true; } case KeyEvent.KEYCODE_A: { if (mMessageViewFragment != null) { mMessageViewFragment.onReplyAll(); } return true; } case KeyEvent.KEYCODE_R: { if (mMessageViewFragment != null) { mMessageViewFragment.onReply(); } return true; } case KeyEvent.KEYCODE_J: case KeyEvent.KEYCODE_P: { if (mMessageViewFragment != null) { showPreviousMessage(); } return true; } case KeyEvent.KEYCODE_N: case KeyEvent.KEYCODE_K: { if (mMessageViewFragment != null) { showNextMessage(); } return true; } /* FIXME case KeyEvent.KEYCODE_Z: { mMessageViewFragment.zoom(event); return true; }*/ case KeyEvent.KEYCODE_H: { Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG); toast.show(); return true; } } return false; }