use of com.fsck.k9.K9 in project k-9 by k9mail.
the class MessageProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (K9.app == null) {
return null;
}
Timber.v("MessageProvider/query: %s", uri);
int code = uriMatcher.match(uri);
if (code == -1) {
throw new IllegalStateException("Unrecognized URI: " + uri);
}
Cursor cursor;
try {
QueryHandler handler = queryHandlers.get(code);
cursor = handler.query(uri, projection, selection, selectionArgs, sortOrder);
} catch (Exception e) {
Timber.e(e, "Unable to execute query for URI: %s", uri);
return null;
}
return cursor;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class UnreadWidgetProvider method updateWidget.
public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String accountUuid) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.unread_widget_layout);
int unreadCount = 0;
String accountName = context.getString(R.string.app_name);
Intent clickIntent = null;
try {
BaseAccount account = null;
AccountStats stats = null;
SearchAccount searchAccount = null;
if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
searchAccount = SearchAccount.createUnifiedInboxAccount(context);
} else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
searchAccount = SearchAccount.createAllMessagesAccount(context);
}
if (searchAccount != null) {
account = searchAccount;
MessagingController controller = MessagingController.getInstance(context);
stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
clickIntent = MessageList.intentDisplaySearch(context, searchAccount.getRelatedSearch(), false, true, true);
} else {
Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
if (realAccount != null) {
account = realAccount;
stats = realAccount.getStats(context);
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, false);
} else {
LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
search.addAllowedFolder(realAccount.getAutoExpandFolderName());
search.addAccountUuid(account.getUuid());
clickIntent = MessageList.intentDisplaySearch(context, search, false, true, true);
}
clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
}
}
if (account != null) {
accountName = account.getDescription();
}
if (stats != null) {
unreadCount = stats.unreadMessageCount;
}
} catch (Exception e) {
Timber.e(e, "Error getting widget configuration");
}
if (unreadCount <= 0) {
// Hide TextView for unread count if there are no unread messages.
remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
} else {
remoteViews.setViewVisibility(R.id.unread_count, View.VISIBLE);
String displayCount = (unreadCount <= MAX_COUNT) ? String.valueOf(unreadCount) : String.valueOf(MAX_COUNT) + "+";
remoteViews.setTextViewText(R.id.unread_count, displayCount);
}
remoteViews.setTextViewText(R.id.account_name, accountName);
if (clickIntent == null) {
// If the widget configuration couldn't be loaded we open the configuration
// activity when the user clicks the widget.
clickIntent = new Intent(context, UnreadWidgetConfiguration.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
}
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class BootReceiver method receive.
@Override
public Integer receive(Context context, Intent intent, Integer tmpWakeLockId) {
Timber.i("BootReceiver.onReceive %s", 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();
Timber.i("BootReceiver Got alarm to fire alarmedIntent %s", 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);
Timber.i("BootReceiver Scheduling intent %s for %tc", alarmedIntent, 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);
Timber.i("BootReceiver Canceling alarmedIntent %s", alarmedIntent);
PendingIntent pi = buildPendingIntent(context, intent);
K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context);
alarmMgr.cancel(pi);
}
return tmpWakeLockId;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class RemoteControlService method startService.
@Override
public int startService(final Intent intent, final int startId) {
Timber.i("RemoteControlService started with startId = %d", startId);
final Preferences preferences = Preferences.getPreferences(this);
if (RESCHEDULE_ACTION.equals(intent.getAction())) {
Timber.i("RemoteControlService requesting MailService poll reschedule");
MailService.actionReschedulePoll(this, null);
}
if (PUSH_RESTART_ACTION.equals(intent.getAction())) {
Timber.i("RemoteControlService requesting MailService push restart");
MailService.actionRestartPushers(this, null);
} else if (RemoteControlService.SET_ACTION.equals(intent.getAction())) {
Timber.i("RemoteControlService got request to change settings");
execute(getApplication(), new Runnable() {
public void run() {
try {
boolean needsReschedule = false;
boolean needsPushRestart = false;
String uuid = intent.getStringExtra(K9_ACCOUNT_UUID);
boolean allAccounts = intent.getBooleanExtra(K9_ALL_ACCOUNTS, false);
if (allAccounts) {
Timber.i("RemoteControlService changing settings for all accounts");
} else {
Timber.i("RemoteControlService changing settings for account with UUID %s", uuid);
}
List<Account> accounts = preferences.getAccounts();
for (Account account : accounts) {
//warning: account may not be isAvailable()
if (allAccounts || account.getUuid().equals(uuid)) {
Timber.i("RemoteControlService changing settings for account %s", account.getDescription());
String notificationEnabled = intent.getStringExtra(K9_NOTIFICATION_ENABLED);
String ringEnabled = intent.getStringExtra(K9_RING_ENABLED);
String vibrateEnabled = intent.getStringExtra(K9_VIBRATE_ENABLED);
String pushClasses = intent.getStringExtra(K9_PUSH_CLASSES);
String pollClasses = intent.getStringExtra(K9_POLL_CLASSES);
String pollFrequency = intent.getStringExtra(K9_POLL_FREQUENCY);
if (notificationEnabled != null) {
account.setNotifyNewMail(Boolean.parseBoolean(notificationEnabled));
}
if (ringEnabled != null) {
account.getNotificationSetting().setRing(Boolean.parseBoolean(ringEnabled));
}
if (vibrateEnabled != null) {
account.getNotificationSetting().setVibrate(Boolean.parseBoolean(vibrateEnabled));
}
if (pushClasses != null) {
needsPushRestart |= account.setFolderPushMode(FolderMode.valueOf(pushClasses));
}
if (pollClasses != null) {
needsReschedule |= account.setFolderSyncMode(FolderMode.valueOf(pollClasses));
}
if (pollFrequency != null) {
String[] allowedFrequencies = getResources().getStringArray(R.array.account_settings_check_frequency_values);
for (String allowedFrequency : allowedFrequencies) {
if (allowedFrequency.equals(pollFrequency)) {
Integer newInterval = Integer.parseInt(allowedFrequency);
needsReschedule |= account.setAutomaticCheckIntervalMinutes(newInterval);
}
}
}
account.save(Preferences.getPreferences(RemoteControlService.this));
}
}
Timber.i("RemoteControlService changing global settings");
String backgroundOps = intent.getStringExtra(K9_BACKGROUND_OPERATIONS);
if (K9RemoteControl.K9_BACKGROUND_OPERATIONS_ALWAYS.equals(backgroundOps) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_NEVER.equals(backgroundOps) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_WHEN_CHECKED_AUTO_SYNC.equals(backgroundOps)) {
BACKGROUND_OPS newBackgroundOps = BACKGROUND_OPS.valueOf(backgroundOps);
boolean needsReset = K9.setBackgroundOps(newBackgroundOps);
needsPushRestart |= needsReset;
needsReschedule |= needsReset;
}
String theme = intent.getStringExtra(K9_THEME);
if (theme != null) {
K9.setK9Theme(K9RemoteControl.K9_THEME_DARK.equals(theme) ? K9.Theme.DARK : K9.Theme.LIGHT);
}
Storage storage = preferences.getStorage();
StorageEditor editor = storage.edit();
K9.save(editor);
editor.commit();
if (needsReschedule) {
Intent i = new Intent(RemoteControlService.this, RemoteControlService.class);
i.setAction(RESCHEDULE_ACTION);
long nextTime = System.currentTimeMillis() + 10000;
BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
}
if (needsPushRestart) {
Intent i = new Intent(RemoteControlService.this, RemoteControlService.class);
i.setAction(PUSH_RESTART_ACTION);
long nextTime = System.currentTimeMillis() + 10000;
BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
}
} catch (Exception e) {
Timber.e(e, "Could not handle K9_SET");
Toast toast = Toast.makeText(RemoteControlService.this, e.getMessage(), Toast.LENGTH_LONG);
toast.show();
}
}
}, RemoteControlService.REMOTE_CONTROL_SERVICE_WAKE_LOCK_TIMEOUT, startId);
}
return START_NOT_STICKY;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class NotificationContentCreator method getMessageSender.
private String getMessageSender(Account account, Message message) {
boolean isSelf = false;
final Contacts contacts = K9.showContactName() ? Contacts.getInstance(context) : null;
final Address[] fromAddresses = message.getFrom();
if (fromAddresses != null) {
isSelf = account.isAnIdentity(fromAddresses);
if (!isSelf && fromAddresses.length > 0) {
return MessageHelper.toFriendly(fromAddresses[0], contacts).toString();
}
}
if (isSelf) {
// show To: if the message was sent from me
Address[] recipients = message.getRecipients(Message.RecipientType.TO);
if (recipients != null && recipients.length > 0) {
return context.getString(R.string.message_to_fmt, MessageHelper.toFriendly(recipients[0], contacts).toString());
}
}
return null;
}
Aggregations