list widget
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.headlezz.notificationlogger.widget;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
@@ -7,10 +8,13 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import net.headlezz.notificationlogger.MainActivity;
|
||||
import net.headlezz.notificationlogger.R;
|
||||
|
||||
public class ListWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
public static final String SHOW_NOTIFICATION_ACTION = "net.headlezz.notificationlogger.listwidget.SHOW_NOTIFICATION_ACTION";
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
for(int widgetId : appWidgetIds) {
|
||||
@@ -27,11 +31,25 @@ public class ListWidgetProvider extends AppWidgetProvider {
|
||||
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
|
||||
|
||||
Intent showNotificationIntent = new Intent(context, ListWidgetProvider.class);
|
||||
showNotificationIntent.setAction(ListWidgetProvider.SHOW_NOTIFICATION_ACTION);
|
||||
PendingIntent pi = PendingIntent.getBroadcast(context, 0, showNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
rvs.setPendingIntentTemplate(R.id.list_widget_listView, pi);
|
||||
|
||||
rvs.setRemoteAdapter(R.id.list_widget_listView, serviceIntent);
|
||||
rvs.setEmptyView(R.id.list_widget_listView, R.id.list_widget_empty_view);
|
||||
|
||||
|
||||
|
||||
return rvs;
|
||||
}
|
||||
|
||||
// receives the intent broadcast from list items
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(SHOW_NOTIFICATION_ACTION)) {
|
||||
Intent mainActivityIntent = new Intent(context, MainActivity.class);
|
||||
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(mainActivityIntent);
|
||||
}
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package net.headlezz.notificationlogger.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.SpannableString;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.RemoteViewsService;
|
||||
|
||||
@@ -55,13 +59,22 @@ public class ListWidgetViewFactory implements RemoteViewsService.RemoteViewsFact
|
||||
@Override
|
||||
public RemoteViews getViewAt(int position) {
|
||||
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_list_item);
|
||||
mCursor.moveToPosition(position);
|
||||
|
||||
mCursor.moveToPosition(position);
|
||||
LoggedNotification notification = Logged_notificationTable.getRow(mCursor, false);
|
||||
|
||||
rv.setTextViewText(R.id.widget_list_item_title, notification.appName);
|
||||
rv.setTextViewText(R.id.widget_list_item_notification, notification.title + ": " + notification.message);
|
||||
|
||||
String title = notification.title + ":";
|
||||
SpannableString titleSpan = new SpannableString(title + " " + notification.message);
|
||||
titleSpan.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), 0);
|
||||
|
||||
rv.setTextViewText(R.id.widget_list_item_notification, titleSpan);
|
||||
rv.setTextViewText(R.id.widget_list_item_date, DateUtils.formatDateTime(mContext, notification.date, DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE));
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Logged_notificationTable.FIELD__ID, notification.id);
|
||||
rv.setOnClickFillInIntent(R.id.widget_list_item, intent);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,22 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="4dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:padding="16dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/widget_list_title"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- ListView to be shown on widget -->
|
||||
<ListView
|
||||
android:visibility="gone"
|
||||
android:dividerHeight="4dp"
|
||||
android:id="@+id/list_widget_listView"
|
||||
android:layout_width="match_parent"
|
||||
@@ -14,13 +25,13 @@
|
||||
|
||||
<!-- Empty view is show if list items are empty -->
|
||||
<TextView
|
||||
android:background="@android:color/white"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:id="@+id/list_widget_empty_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="Empty list"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="20sp"
|
||||
android:visibility="gone" />
|
||||
android:text="@string/widget_list_empty"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -4,35 +4,46 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/widget_list_item"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:layout_alignParentStart="true"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
android:id="@+id/widget_list_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:textColor="@android:color/black"
|
||||
android:textStyle="bold"
|
||||
tools:text="appname" />
|
||||
tools:text="appname asd asdasqweqwe qw q asd asd aweq"
|
||||
android:layout_toStartOf="@+id/widget_list_item_date" />
|
||||
|
||||
<TextView
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:layout_alignParentStart="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:layout_below="@+id/widget_list_item_title"
|
||||
android:id="@+id/widget_list_item_notification"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:textColor="@android:color/black"
|
||||
tools:text="message" />
|
||||
tools:text="notification" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
|
||||
android:id="@+id/widget_list_item_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:textColor="@android:color/black"
|
||||
android:textColor="@color/colorAccent"
|
||||
tools:text="date"
|
||||
android:layout_alignTop="@+id/widget_list_item_title"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
<string name="pref_export_snack_action">Show</string>
|
||||
<string name="pref_export_snack_show_chooser_title">Open folder</string>
|
||||
<string name="pref_export_snack_show_activity_not_found">No file browser installed.</string>
|
||||
<string name="widget_list_title">Latest Notifications</string>
|
||||
<string name="widget_list_empty">No notifications logged.</string>
|
||||
|
||||
<string-array name="notification_list_options">
|
||||
<item>Show more info</item>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="250dp"
|
||||
android:minWidth="110dp"
|
||||
android:minHeight="110dp"
|
||||
android:updatePeriodMillis="300000"
|
||||
android:previewImage="@drawable/widget_list_preview"
|
||||
android:initialLayout="@layout/widget_list"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
|
||||
Reference in New Issue
Block a user