@Override public Integer receive(Context context, Intent intent, Integer tmpWakeLockId) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent); final String action = intent.getAction(); if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { // K9.setServicesEnabled(context, tmpWakeLockId); // tmpWakeLockId = null; } else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) { MailService.actionCancel(context, tmpWakeLockId); tmpWakeLockId = null; } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) { MailService.actionReset(context, tmpWakeLockId); tmpWakeLockId = null; } else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) { MailService.connectivityChange(context, tmpWakeLockId); tmpWakeLockId = null; } else if ("com.android.sync.SYNC_CONN_STATUS_CHANGED".equals(action)) { K9.BACKGROUND_OPS bOps = K9.getBackgroundOps(); if (bOps == K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) { MailService.actionReset(context, tmpWakeLockId); tmpWakeLockId = null; } } else if (FIRE_INTENT.equals(action)) { Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); String alarmedAction = alarmedIntent.getAction(); if (K9.DEBUG) Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction); alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId); tmpWakeLockId = null; context.startService(alarmedIntent); } else if (SCHEDULE_INTENT.equals(action)) { long atTime = intent.getLongExtra(AT_TIME, -1); Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); if (K9.DEBUG) Log.i( K9.LOG_TAG, "BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime)); PendingIntent pi = buildPendingIntent(context, intent); K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context); alarmMgr.set(AlarmManager.RTC_WAKEUP, atTime, pi); } else if (CANCEL_INTENT.equals(action)) { Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); if (K9.DEBUG) Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent); PendingIntent pi = buildPendingIntent(context, intent); K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context); alarmMgr.cancel(pi); } return tmpWakeLockId; }
@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()); }