More tweaks to the unread widget
This commit is contained in:
parent
64f4f7e4a3
commit
485a505ca0
4 changed files with 28 additions and 4 deletions
15
res/drawable/unread_widget_background.xml
Normal file
15
res/drawable/unread_widget_background.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- FIXME: find a nicer looking way than using 'menuitem_background' -->
|
||||
<item android:drawable="@android:drawable/menuitem_background"
|
||||
android:state_pressed="true" />
|
||||
|
||||
<item android:drawable="@android:drawable/menuitem_background"
|
||||
android:state_focused="true"
|
||||
android:state_enabled="true"
|
||||
android:state_window_focused="true" />
|
||||
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
|
||||
</selector>
|
|
@ -6,6 +6,9 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="2dp"
|
||||
android:orientation="vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="@drawable/unread_widget_background"
|
||||
android:gravity="bottom|center_horizontal">
|
||||
|
||||
<FrameLayout
|
||||
|
@ -20,6 +23,7 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/unread_count"
|
||||
android:visibility="gone"
|
||||
android:textSize="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -35,6 +39,7 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/account_name"
|
||||
android:text="@string/app_name"
|
||||
android:ellipsize="marquee"
|
||||
android:textSize="12dp"
|
||||
android:singleLine="true"
|
||||
|
|
|
@ -1126,6 +1126,6 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
|||
<string name="manage_accounts_move_down_action">Move down</string>
|
||||
<string name="manage_accounts_moving_message">Moving account...</string>
|
||||
|
||||
<string name="unread_widget_label">Unread count</string>
|
||||
<string name="unread_widget_label">K-9 Unread</string>
|
||||
<string name="unread_widget_select_account">Show unread count for…</string>
|
||||
</resources>
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.view.View;
|
|||
import android.widget.RemoteViews;
|
||||
|
||||
public class UnreadWidgetProvider extends AppWidgetProvider {
|
||||
private static final int MAX_COUNT = 9999;
|
||||
|
||||
/**
|
||||
* Trigger update for all of our unread widgets.
|
||||
|
@ -71,11 +72,15 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
|
|||
}
|
||||
}
|
||||
|
||||
if (unreadCount == 0) {
|
||||
if (unreadCount <= 0) {
|
||||
// Hide TextView for unread count if there are no unread messages.
|
||||
remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
|
||||
} else {
|
||||
remoteViews.setTextViewText(R.id.unread_count, String.valueOf(unreadCount));
|
||||
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);
|
||||
|
@ -95,7 +100,6 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
|
|||
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue