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; |
28 |
private static Bitmap usedBitmap; |
private static Bitmap usedBitmap; |
29 |
private static long timestamp; |
private static long timestamp; |
30 |
|
|
31 |
final static long UDPATESPAN = 3*60*60*1000; |
final static long UDPATESPAN = 4*60*60*1000; |
|
|
|
|
final static String SAVEDIR = "/sdcard/Side9/"; |
|
|
|
|
32 |
|
|
33 |
static { |
static { |
34 |
timestamp = 0L; |
timestamp = 0L; |
37 |
public Side9WidgetProvider() { |
public Side9WidgetProvider() { |
38 |
Log.i(TAG, "WidgetProvider constructor called"); |
Log.i(TAG, "WidgetProvider constructor called"); |
39 |
} |
} |
40 |
|
|
41 |
|
public void resetStatics() { |
42 |
|
Log.i(TAG, "resetStatics"); |
43 |
|
usedData = null; |
44 |
|
usedBitmap = null; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) { |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) { |
52 |
// 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 |
153 |
SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); |
SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); |
154 |
boolean saveImage = prefs.getBoolean("saveimage", false); |
boolean saveImage = prefs.getBoolean("saveimage", false); |
155 |
|
|
156 |
File file = new File( SAVEDIR + data.getFilename() ); |
final String savepath = Environment.getExternalStorageDirectory() + "/Side9"; |
157 |
|
|
158 |
|
File file = new File( savepath + "/" + data.getFilename() ); |
159 |
|
|
160 |
/* 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 |
161 |
if (saveImage == true) { |
if (saveImage == true) { |
169 |
|
|
170 |
if (saveImage == true) { |
if (saveImage == true) { |
171 |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
172 |
File savedir = new File(SAVEDIR); |
File savedir = new File(savepath); |
173 |
savedir.mkdirs(); |
savedir.mkdirs(); |
174 |
|
|
175 |
if (file.exists()) { |
if (file.exists()) { |
179 |
FileOutputStream fos = new FileOutputStream(file); |
FileOutputStream fos = new FileOutputStream(file); |
180 |
fos.write(imageData); |
fos.write(imageData); |
181 |
fos.close(); |
fos.close(); |
182 |
|
|
183 |
|
Intent rescan = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()) ); |
184 |
|
rescan.putExtra("read-only", false); |
185 |
|
context.sendBroadcast(rescan); |
186 |
|
|
187 |
} else { |
} else { |
188 |
Log.i(TAG, "sdcard is not mounted"); |
Log.i(TAG, "sdcard is not mounted"); |
189 |
} |
} |
198 |
public void onDisabled(Context context) { |
public void onDisabled(Context context) { |
199 |
super.onDisabled(context); |
super.onDisabled(context); |
200 |
Log.i(TAG, "onDisabled"); |
Log.i(TAG, "onDisabled"); |
201 |
|
|
202 |
usedData = null; //free memory |
resetStatics();//free memory |
|
usedBitmap = null; |
|
203 |
} |
} |
204 |
|
|
205 |
|
@Override |
206 |
|
public void onEnabled(Context context) { |
207 |
|
super.onEnabled(context); |
208 |
|
Log.i(TAG, "onEnabled"); |
209 |
|
|
210 |
|
resetStatics();//free memory |
211 |
|
} |
212 |
|
|
213 |
} |
} |