diff --git a/k9mail/src/main/AndroidManifest.xml b/k9mail/src/main/AndroidManifest.xml index 206106f62..1b208405f 100644 --- a/k9mail/src/main/AndroidManifest.xml +++ b/k9mail/src/main/AndroidManifest.xml @@ -363,21 +363,22 @@ android:resource="@xml/unread_widget_info"/> - + - + + android:name="android.appwidget.provider" + android:resource="@xml/mail_list_view_widget_layout_info" /> - - + mailItems; private int count; + public MailListRemoteViewFactory(Context context) { this.context = context; } @@ -129,7 +134,11 @@ public class MailListRemoteViewFactory implements RemoteViewsService.RemoteViews return true; } + private static class MailItem { + private static Calendar cl = Calendar.getInstance(); + + private String id; private String date; private String sender; @@ -139,10 +148,9 @@ public class MailListRemoteViewFactory implements RemoteViewsService.RemoteViews private String hasAttachment; private String uri; - private static Calendar cl = Calendar.getInstance(); - public MailItem(String id, String sender, String date, String subject, - String preview, String unread, String hasAttachment, String uri) { + public MailItem(String id, String sender, String date, String subject, String preview, String unread, + String hasAttachment, String uri) { this.id = id; this.sender = sender; this.date = date; diff --git a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetConfiguration.java b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetConfiguration.java index 4b578f87c..091413df2 100644 --- a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetConfiguration.java +++ b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetConfiguration.java @@ -1,24 +1,25 @@ package com.fsck.k9.widget.list; + import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; + import com.fsck.k9.BaseAccount; import com.fsck.k9.R; import com.fsck.k9.activity.AccountList; public class MailListViewWidgetConfiguration extends AccountList { - private static final String PREFS_NAME = "mail_list_view_widget_configuration.xml"; - private static final String PREF_PREFIX_KEY = "mail_list_view_widget."; private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; + private static void saveAccountUuid(Context context, int appWidgetId, String accountUuid) { SharedPreferences.Editor editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit(); @@ -45,8 +46,7 @@ public class MailListViewWidgetConfiguration extends AccountList { Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { - appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, - AppWidgetManager.INVALID_APPWIDGET_ID); + appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget ID, just bail. if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { @@ -68,7 +68,8 @@ public class MailListViewWidgetConfiguration extends AccountList { saveAccountUuid(this, appWidgetId, accountUuid); // Update widget Context context = getApplicationContext(); - MailListViewWidgetProvider.updateAppWidget(context, AppWidgetManager.getInstance(context), appWidgetId, accountUuid); + MailListViewWidgetProvider.updateAppWidget( + context, AppWidgetManager.getInstance(context), appWidgetId, accountUuid); // Let the caller know that the configuration was successful Intent resultValue = new Intent(); diff --git a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetProvider.java b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetProvider.java index 72c823a30..aa960d684 100644 --- a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetProvider.java +++ b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetProvider.java @@ -1,5 +1,6 @@ package com.fsck.k9.widget.list; + import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; @@ -8,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.widget.RemoteViews; + import com.fsck.k9.Account; import com.fsck.k9.Preferences; import com.fsck.k9.R; @@ -17,7 +19,6 @@ import com.fsck.k9.activity.MessageList; public class MailListViewWidgetProvider extends AppWidgetProvider { public static final String PACKAGE_NAME = "com.fsck.k9"; - public static String ACTION_VIEW_MAIL_ITEM = PACKAGE_NAME + ".provider.ACTION_VIEW_MAIL_ITEM"; public static String ACTION_COMPOSE_EMAIL = PACKAGE_NAME + ".provider.ACTION_COMPOSE_EMAIL"; @@ -26,7 +27,7 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { Context appContext = context.getApplicationContext(); AppWidgetManager widgetManager = AppWidgetManager.getInstance(appContext); ComponentName widget = new ComponentName(appContext, MailListViewWidgetProvider.class); - int [] widgetIds = widgetManager.getAppWidgetIds(widget); + int[] widgetIds = widgetManager.getAppWidgetIds(widget); Intent intent = new Intent(context, MailListViewWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); @@ -34,7 +35,8 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { context.sendBroadcast(intent); } - public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String acc) { + public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, + String acc) { CharSequence widgetText = context.getString(R.string.mail_list_widget_text); Account account = Preferences.getPreferences(context).getAccount(acc); @@ -78,7 +80,6 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { - // an intent from an item on the listview. get the uri and launch the MessageList activity if (intent.getAction().equals(ACTION_VIEW_MAIL_ITEM)) { Intent viewMailIntent = new Intent(context, MessageList.class); @@ -87,9 +88,8 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { viewMailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(viewMailIntent); } else if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { - AppWidgetManager.getInstance(context) - .notifyAppWidgetViewDataChanged(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), - R.id.listView); + AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged( + intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), R.id.listView); } else if (intent.getAction().equals(ACTION_COMPOSE_EMAIL)) { Intent newMessage = new Intent(context, MessageCompose.class) .putExtra(MessageCompose.EXTRA_ACCOUNT, intent.getStringExtra(MessageCompose.EXTRA_ACCOUNT)) @@ -98,7 +98,7 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { context.startActivity(newMessage); } } - + @Override public void onDeleted(Context context, int[] appWidgetIds) { for (int widgId : appWidgetIds) { @@ -106,4 +106,3 @@ public class MailListViewWidgetProvider extends AppWidgetProvider { } } } - diff --git a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetService.java b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetService.java index 437447252..b34504dec 100644 --- a/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetService.java +++ b/k9mail/src/main/java/com/fsck/k9/widget/list/MailListViewWidgetService.java @@ -1,11 +1,11 @@ package com.fsck.k9.widget.list; + import android.content.Intent; import android.widget.RemoteViewsService; public class MailListViewWidgetService extends RemoteViewsService { - @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { return new MailListRemoteViewFactory(this.getApplicationContext()); diff --git a/k9mail/src/main/res/layout/mail_list_item.xml b/k9mail/src/main/res/layout/mail_list_item.xml index 479e2ab3a..c025c52d3 100644 --- a/k9mail/src/main/res/layout/mail_list_item.xml +++ b/k9mail/src/main/res/layout/mail_list_item.xml @@ -1,55 +1,60 @@ + android:id="@+id/mail_list_item" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="@dimen/widget_padding"> - + - + - + - + - + diff --git a/k9mail/src/main/res/layout/mail_list_loading_view.xml b/k9mail/src/main/res/layout/mail_list_loading_view.xml index 35de944b8..2df87f534 100644 --- a/k9mail/src/main/res/layout/mail_list_loading_view.xml +++ b/k9mail/src/main/res/layout/mail_list_loading_view.xml @@ -1,8 +1,14 @@ - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - \ No newline at end of file + + + diff --git a/k9mail/src/main/res/layout/mail_list_view_widget_layout.xml b/k9mail/src/main/res/layout/mail_list_view_widget_layout.xml index 1871f6be9..be6ae5bd3 100644 --- a/k9mail/src/main/res/layout/mail_list_view_widget_layout.xml +++ b/k9mail/src/main/res/layout/mail_list_view_widget_layout.xml @@ -1,48 +1,56 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + + + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:textSize="18sp" /> - + - + - + + - + android:divider="@color/light_grey" + android:dividerHeight="1dp" /> + + diff --git a/k9mail/src/main/res/xml/mail_list_view_widget_layout_info.xml b/k9mail/src/main/res/xml/mail_list_view_widget_layout_info.xml index b9dac665c..6f18cf114 100644 --- a/k9mail/src/main/res/xml/mail_list_view_widget_layout_info.xml +++ b/k9mail/src/main/res/xml/mail_list_view_widget_layout_info.xml @@ -1,12 +1,12 @@ + android:configure="com.fsck.k9.widget.list.MailListViewWidgetConfiguration" + android:initialKeyguardLayout="@layout/mail_list_view_widget_layout" + android:initialLayout="@layout/mail_list_view_widget_layout" + android:minHeight="180dp" + android:minWidth="250dp" + android:previewImage="@drawable/mail_list_widget_icon" + android:resizeMode="horizontal|vertical" + android:updatePeriodMillis="86400000" + android:widgetCategory="home_screen|keyguard">