14 |
|
|
15 |
public class Side9WidgetProvider extends AppWidgetProvider { |
public class Side9WidgetProvider extends AppWidgetProvider { |
16 |
|
|
17 |
|
private Side9Data usedData; |
18 |
|
|
19 |
@Override |
@Override |
20 |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { |
26 |
|
|
27 |
|
|
28 |
try { |
try { |
29 |
Side9Xml dataSource = new Side9Xml(); |
Side9Data data = Side9Xml.loadXml(); |
|
Side9Data data = dataSource.loadXml(); |
|
30 |
|
|
31 |
|
if (! data.equals(usedData)) { |
32 |
|
usedData = data; // save the new data |
33 |
|
|
34 |
|
URL imgUrl = new URL( data.url ); |
35 |
|
|
36 |
|
URLConnection conn = imgUrl.openConnection(); |
37 |
|
Bitmap image = BitmapFactory.decodeStream( conn.getInputStream() ); |
38 |
|
|
39 |
|
|
40 |
|
// Perform this loop procedure for each App Widget that belongs to this provider |
41 |
|
for (int i=0; i<N; i++) { |
42 |
|
int appWidgetId = appWidgetIds[i]; |
43 |
|
|
44 |
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.side9widget); |
45 |
|
|
46 |
|
|
47 |
|
views.setImageViewBitmap(R.id.side9picture, image); |
48 |
|
|
49 |
|
|
50 |
|
// Tell the AppWidgetManager to perform an update on the current App Widget |
51 |
|
appWidgetManager.updateAppWidget(appWidgetId, views); |
52 |
|
} |
53 |
|
} //END if (data.equals) |
54 |
|
|
|
URL imgUrl = new URL( data.url ); |
|
|
|
|
|
URLConnection conn = imgUrl.openConnection(); |
|
|
Bitmap image = BitmapFactory.decodeStream( conn.getInputStream() ); |
|
|
|
|
|
|
|
|
// Perform this loop procedure for each App Widget that belongs to this provider |
|
|
for (int i=0; i<N; i++) { |
|
|
int appWidgetId = appWidgetIds[i]; |
|
|
|
|
|
|
|
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.side9widget); |
|
|
|
|
|
|
|
|
views.setImageViewBitmap(R.id.side9picture, image); |
|
|
|
|
|
|
|
|
// Tell the AppWidgetManager to perform an update on the current App Widget |
|
|
appWidgetManager.updateAppWidget(appWidgetId, views); |
|
|
|
|
|
|
|
|
} |
|
55 |
} catch (Exception e) { |
} catch (Exception e) { |
56 |
Log.e("UPDATE", "UPDATE", e); |
Log.e("UPDATE", "UPDATE", e); |
57 |
} |
} |