widget: experimental changes to make it work after boot

This commit is contained in:
Andrew Dolgov 2015-02-13 10:30:45 +03:00
parent 79afbaff3a
commit f3a3b021dd
2 changed files with 50 additions and 11 deletions

View File

@ -1,10 +1,6 @@
package org.fox.ttrss.widget; package org.fox.ttrss.widget;
import org.fox.ttrss.R;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.app.Service;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
import android.content.ComponentName; import android.content.ComponentName;
@ -13,16 +9,58 @@ import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.R;
public class SmallWidgetProvider extends AppWidgetProvider { public class SmallWidgetProvider extends AppWidgetProvider {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
public static final String FORCE_UPDATE_ACTION = "org.fox.ttrss.WIDGET_FORCE_UPDATE"; public static final String FORCE_UPDATE_ACTION = "org.fox.ttrss.WIDGET_FORCE_UPDATE";
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d(TAG, "onUpdate");
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, OnlineActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_small);
views.setOnClickPendingIntent(R.id.widget_main, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
/* Intent updateIntent = new Intent(context, org.fox.ttrss.widget.WidgetUpdateService.class);
PendingIntent updatePendingIntent = PendingIntent.getService(context, 0, updateIntent, 0);
Intent intent = new Intent(context, org.fox.ttrss.OnlineActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_small);
views.setOnClickPendingIntent(R.id.widget_main, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
try {
updatePendingIntent.send();
} catch (CanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */
//RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_small); //RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_small);
final int N = appWidgetIds.length; /* final int N = appWidgetIds.length;
for (int i=0; i < N; i++) { for (int i=0; i < N; i++) {
int appWidgetId = appWidgetIds[i]; int appWidgetId = appWidgetIds[i];
@ -44,14 +82,15 @@ public class SmallWidgetProvider extends AppWidgetProvider {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} } */
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent); super.onReceive(context, intent);
Log.d(TAG, "onReceive");
if (FORCE_UPDATE_ACTION.equals(intent.getAction())) { if (FORCE_UPDATE_ACTION.equals(intent.getAction())) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

View File

@ -25,7 +25,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|center" android:layout_gravity="bottom|center"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:text="@string/app_name" android:text="\?"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/primary_text_dark" android:textColor="@android:color/primary_text_dark"
android:textSize="13sp" /> android:textSize="13sp" />