7 |
import android.app.PendingIntent; |
import android.app.PendingIntent; |
8 |
import android.appwidget.AppWidgetManager; |
import android.appwidget.AppWidgetManager; |
9 |
import android.appwidget.AppWidgetProvider; |
import android.appwidget.AppWidgetProvider; |
|
import android.content.ComponentName; |
|
10 |
import android.content.Context; |
import android.content.Context; |
11 |
import android.content.Intent; |
import android.content.Intent; |
12 |
import android.content.SharedPreferences; |
import android.content.SharedPreferences; |
16 |
import android.net.Uri; |
import android.net.Uri; |
17 |
import android.os.Environment; |
import android.os.Environment; |
18 |
import android.util.Log; |
import android.util.Log; |
19 |
|
import android.view.View; |
20 |
import android.widget.RemoteViews; |
import android.widget.RemoteViews; |
21 |
import dk.thoerup.androidutils.HttpUtil; |
import dk.thoerup.androidutils.HttpUtil; |
22 |
|
|
29 |
private static Bitmap usedBitmap; |
private static Bitmap usedBitmap; |
30 |
private static long timestamp; |
private static long timestamp; |
31 |
|
|
32 |
final static long UDPATESPAN = 3*60*60*1000; |
final static long UDPATESPAN = 4*60*60*1000; |
|
|
|
|
final static String SAVEDIR = "/sdcard/Side9/"; |
|
|
|
|
33 |
|
|
34 |
static { |
static { |
35 |
timestamp = 0L; |
timestamp = 0L; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) { |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { |
53 |
// Perform this loop procedure for each App Widget that belongs to this provider |
// Perform this loop procedure for each App Widget that belongs to this provider |
54 |
final int N = appWidgetIds.length; |
final int N = appWidgetIds.length; |
55 |
for (int i=0; i<N; i++) { |
for (int i=0; i<N; i++) { |
57 |
|
|
58 |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.side9widget); |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.side9widget); |
59 |
|
|
60 |
if (image != null) { |
if (usedBitmap != null) { |
61 |
views.setImageViewBitmap(R.id.side9picture, image); |
views.setImageViewBitmap(R.id.side9picture, usedBitmap); |
62 |
} else { |
} else { |
63 |
views.setImageViewResource(R.id.side9picture, R.drawable.side9logo); |
views.setImageViewResource(R.id.side9picture, R.drawable.side9logo); |
64 |
} |
} |
|
//views.setTextViewText(R.id.caption, newData.caption); |
|
|
|
|
|
|
|
|
Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/")); |
|
|
|
|
|
|
|
|
//View single file |
|
|
// Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW); |
|
|
// viewIntent.setDataAndType(Uri.parse("file:///sdcard/Side9/20100531_400.jpg"), "image/png"); |
|
65 |
|
|
66 |
//view single file |
boolean showcaption = context. |
67 |
//Intent viewIntent = new Intent(Intent.ACTION_VIEW); |
getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE). |
68 |
//Uri u = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "1" ); |
getBoolean(Side9Config.PREFS_SHOWCAPTION, false); |
|
//viewIntent.setData(u); |
|
|
|
|
|
//Intent viewIntent = new Intent(); |
|
|
//viewIntent.setClassName("com.android.camera", "com.android.camera.GalleryPicker"); |
|
69 |
|
|
70 |
|
if (showcaption == true) { |
71 |
|
views.setTextViewText(R.id.caption, " " + usedData.caption + " "); |
72 |
|
} else { |
73 |
|
views.setViewVisibility(R.id.caption, View.GONE); |
74 |
|
} |
75 |
|
|
|
/*Intent viewIntent = new Intent(); |
|
|
viewIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
|
|
viewIntent.setAction(Intent.ACTION_MAIN); |
|
|
viewIntent.setComponent(new ComponentName("com.android.camera", ".GalleryPicker")); |
|
|
viewIntent.setFlags(0x10200000);*/ |
|
76 |
|
|
77 |
|
//Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/")); |
78 |
|
|
79 |
|
Intent viewIntent = new Intent(context, dk.thoerup.side9.PictureOverview.class ); |
80 |
|
|
81 |
|
|
82 |
PendingIntent pending = PendingIntent.getActivity(context, 0, viewIntent, Intent.FLAG_ACTIVITY_NEW_TASK); |
PendingIntent pending = PendingIntent.getActivity(context, 0, viewIntent, Intent.FLAG_ACTIVITY_NEW_TASK); |
83 |
views.setOnClickPendingIntent(R.id.side9picture, pending); |
views.setOnClickPendingIntent(R.id.side9picture, pending); |
134 |
Log.e("Side9Pigen", "update failed", e); |
Log.e("Side9Pigen", "update failed", e); |
135 |
} |
} |
136 |
|
|
137 |
setImage(context,appWidgetManager,appWidgetIds, usedBitmap); |
setImage(context,appWidgetManager,appWidgetIds); |
138 |
Log.i("Side9Pigen", "update completed"); |
Log.i("Side9Pigen", "update completed"); |
139 |
} |
} |
140 |
|
|
141 |
Bitmap getImageData(Context context, Side9Data data) throws IOException { |
Bitmap getImageData(Context context, Side9Data data) throws IOException { |
142 |
|
|
143 |
SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); |
SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); |
144 |
boolean saveImage = prefs.getBoolean("saveimage", false); |
boolean saveImage = prefs.getBoolean(Side9Config.PREFS_SAVEIMAGE, false); |
145 |
|
|
146 |
File file = new File( SAVEDIR + data.getFilename() ); |
final String savepath = Environment.getExternalStorageDirectory() + "/Side9"; |
147 |
|
|
148 |
|
File file = new File( savepath + "/" + data.getFilename() ); |
149 |
|
|
150 |
/* if the picture changes later on the day we do NOT want to use an old and invalid image |
/* if the picture changes later on the day we do NOT want to use an old and invalid image |
151 |
if (saveImage == true) { |
if (saveImage == true) { |
159 |
|
|
160 |
if (saveImage == true) { |
if (saveImage == true) { |
161 |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
162 |
File savedir = new File(SAVEDIR); |
File savedir = new File(savepath); |
163 |
savedir.mkdirs(); |
savedir.mkdirs(); |
164 |
|
|
165 |
if (file.exists()) { |
if (file.exists()) { |
169 |
FileOutputStream fos = new FileOutputStream(file); |
FileOutputStream fos = new FileOutputStream(file); |
170 |
fos.write(imageData); |
fos.write(imageData); |
171 |
fos.close(); |
fos.close(); |
172 |
|
|
173 |
|
Intent rescan = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()) ); |
174 |
|
rescan.putExtra("read-only", false); |
175 |
|
context.sendBroadcast(rescan); |
176 |
|
|
177 |
} else { |
} else { |
178 |
Log.i(TAG, "sdcard is not mounted"); |
Log.i(TAG, "sdcard is not mounted"); |
179 |
} |
} |
180 |
} |
} |
181 |
|
|
182 |
return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); |
Bitmap full = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); |
183 |
|
Bitmap scaled = Bitmap.createScaledBitmap(full, 400, 577, true); |
184 |
|
return scaled; |
185 |
} |
} |
186 |
|
|
187 |
|
|