Anyone have any comments? Just trying to better my code if can be done. Thanks.
public class SacWidget extends AppWidgetProvider {
String roseUrl;
AQuery aq;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, DangerRose.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setImageViewBitmap(R.id.ivdangerrose, getRose());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private Bitmap getRose() {
Bitmap bitmap = null;
File f = new File("/storage/emulated/0/acr/sac/dangerrose.png");
try {
bitmap = BitmapFactory.decodeStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return bitmap;
}
}
EDIT... Made some changes via the comments...
public class SacWidget extends AppWidgetProvider {
private static final String TAG = "SacWidget";
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds){
File ext = Environment.getExternalStorageDirectory();
File file = new File(ext,"acr/sac/dangerrose.png");
Date lastModified = new Date(file.lastModified());
String lm = "Updated: " + lastModified.toLocaleString();
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
Intent clickIntent = new Intent(context, ReportFullActivity.class);
PendingIntent clickapp = PendingIntent.getActivity(context, 0,
clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.ivdangerrose, clickapp);
views.setTextViewText(R.id.tvupdated, lm);
views.setImageViewBitmap(R.id.ivdangerrose, getRose());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private Bitmap getRose() {
Bitmap bitmap = null;
File ext = Environment.getExternalStorageDirectory();
File dangerrosefile = new File(ext,"acr/sac/dangerrose.png");
try {
FileInputStream input = new FileInputStream(dangerrosefile);
bitmap = BitmapFactory.decodeStream(input);
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e(TAG, "Uncaught exception", e);
}
} catch (FileNotFoundException e) {
Log.e(TAG, "Uncaught exception", e);
}
return bitmap;
}
}