-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcom.cookbook.simple_widget
57 lines (47 loc) · 2.09 KB
/
com.cookbook.simple_widget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.cookbook.simple_widget;
import java.io.File;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.widget.RemoteViews;
public class SimpleWidgetProvider extends AppWidgetProvider {
final static int APPWIDGET = 1001;
@Override
public void onUpdate(Context context,
AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
// Loop through all widgets to display an update
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
String titlePrefix = "AppWidget #";
updateAppWidget(context, appWidgetManager, appWidgetId,
titlePrefix);
}
}
static int imageNum=0;
static void updateAppWidget(Context context, AppWidgetManager
appWidgetManager, int appWidgetId, String titlePrefix) {
String ImageDir = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/DCIM/Camera/";
File directory = new File(ImageDir);
File[] files = directory.listFiles();
// CharSequence text = titlePrefix + files[imageNum++];
// Construct the RemoteViews object.
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
Log.e("DD",""+Uri.fromFile(files[imageNum]));
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap ImageToChange= BitmapFactory.decodeFile(files[imageNum++].toString());
Bitmap bm = Bitmap.createScaledBitmap(ImageToChange, 146, 72, false);
views.setImageViewBitmap(R.id.widget_example_image, bm);
// Tell the widget manager
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}