mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
More tweaks to the unread widget
This commit is contained in:
parent
64f4f7e4a3
commit
485a505ca0
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:layout_height="wrap_content"
|
||||||
android:padding="2dp"
|
android:padding="2dp"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="@drawable/unread_widget_background"
|
||||||
android:gravity="bottom|center_horizontal">
|
android:gravity="bottom|center_horizontal">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@ -20,6 +23,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/unread_count"
|
android:id="@+id/unread_count"
|
||||||
|
android:visibility="gone"
|
||||||
android:textSize="10dp"
|
android:textSize="10dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -35,6 +39,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/account_name"
|
android:id="@+id/account_name"
|
||||||
|
android:text="@string/app_name"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="12dp"
|
android:textSize="12dp"
|
||||||
android:singleLine="true"
|
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_move_down_action">Move down</string>
|
||||||
<string name="manage_accounts_moving_message">Moving account...</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>
|
<string name="unread_widget_select_account">Show unread count for…</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -20,6 +20,7 @@ import android.view.View;
|
|||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
public class UnreadWidgetProvider extends AppWidgetProvider {
|
public class UnreadWidgetProvider extends AppWidgetProvider {
|
||||||
|
private static final int MAX_COUNT = 9999;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger update for all of our unread widgets.
|
* 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.
|
// Hide TextView for unread count if there are no unread messages.
|
||||||
remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
|
remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
|
||||||
} else {
|
} 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);
|
remoteViews.setTextViewText(R.id.account_name, accountName);
|
||||||
@ -95,7 +100,6 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
|
|||||||
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
|
remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user