14 |
import android.graphics.Bitmap; |
import android.graphics.Bitmap; |
15 |
import android.graphics.BitmapFactory; |
import android.graphics.BitmapFactory; |
16 |
import android.net.ConnectivityManager; |
import android.net.ConnectivityManager; |
17 |
|
import android.net.Uri; |
18 |
|
import android.os.Environment; |
19 |
import android.util.Log; |
import android.util.Log; |
20 |
import android.widget.RemoteViews; |
import android.widget.RemoteViews; |
21 |
import dk.thoerup.androidutils.HttpUtil; |
import dk.thoerup.androidutils.HttpUtil; |
41 |
public Side9WidgetProvider() { |
public Side9WidgetProvider() { |
42 |
Log.i(TAG, "WidgetProvider constructor called"); |
Log.i(TAG, "WidgetProvider constructor called"); |
43 |
} |
} |
44 |
|
|
45 |
|
public void resetStatics() { |
46 |
|
Log.i(TAG, "resetStatics"); |
47 |
|
usedData = null; |
48 |
|
usedBitmap = null; |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) { |
private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) { |
56 |
// 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 |
68 |
//views.setTextViewText(R.id.caption, newData.caption); |
//views.setTextViewText(R.id.caption, newData.caption); |
69 |
|
|
70 |
|
|
71 |
|
Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/")); |
72 |
|
|
73 |
|
|
74 |
//View single file |
//View single file |
84 |
//viewIntent.setClassName("com.android.camera", "com.android.camera.GalleryPicker"); |
//viewIntent.setClassName("com.android.camera", "com.android.camera.GalleryPicker"); |
85 |
|
|
86 |
|
|
87 |
Intent viewIntent = new Intent(); |
/*Intent viewIntent = new Intent(); |
88 |
viewIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
viewIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
89 |
viewIntent.setAction(Intent.ACTION_MAIN); |
viewIntent.setAction(Intent.ACTION_MAIN); |
90 |
viewIntent.setComponent(new ComponentName("com.android.camera", ".GalleryPicker")); |
viewIntent.setComponent(new ComponentName("com.android.camera", ".GalleryPicker")); |
91 |
viewIntent.setFlags(0x10200000); |
viewIntent.setFlags(0x10200000);*/ |
92 |
|
|
93 |
|
|
94 |
|
|
159 |
|
|
160 |
File file = new File( SAVEDIR + data.getFilename() ); |
File file = new File( SAVEDIR + data.getFilename() ); |
161 |
|
|
162 |
if (saveImage == true) { |
/* if the picture changes later on the day we do NOT want to use an old and invalid image |
163 |
|
if (saveImage == true) { |
164 |
if (file.exists()) { |
if (file.exists()) { |
165 |
return BitmapFactory.decodeFile(file.getAbsolutePath()); |
return BitmapFactory.decodeFile(file.getAbsolutePath()); |
166 |
} |
} |
167 |
} |
}*/ |
168 |
|
|
169 |
|
|
170 |
byte imageData[] = HttpUtil.getContent(data.url, 2500); |
byte imageData[] = HttpUtil.getContent(data.url, 2500); |
171 |
|
|
172 |
if (saveImage == true) { |
if (saveImage == true) { |
173 |
File savedir = new File(SAVEDIR); |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
174 |
savedir.mkdirs(); |
File savedir = new File(SAVEDIR); |
175 |
|
savedir.mkdirs(); |
176 |
FileOutputStream fos = new FileOutputStream(file); |
|
177 |
fos.write(imageData); |
if (file.exists()) { |
178 |
fos.close(); |
file.delete(); |
179 |
|
} |
180 |
|
|
181 |
|
FileOutputStream fos = new FileOutputStream(file); |
182 |
|
fos.write(imageData); |
183 |
|
fos.close(); |
184 |
|
} else { |
185 |
|
Log.i(TAG, "sdcard is not mounted"); |
186 |
|
} |
187 |
} |
} |
188 |
|
|
189 |
return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); |
return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); |
195 |
public void onDisabled(Context context) { |
public void onDisabled(Context context) { |
196 |
super.onDisabled(context); |
super.onDisabled(context); |
197 |
Log.i(TAG, "onDisabled"); |
Log.i(TAG, "onDisabled"); |
198 |
|
|
199 |
usedData = null; //free memory |
resetStatics();//free memory |
|
usedBitmap = null; |
|
200 |
} |
} |
201 |
|
|
202 |
|
@Override |
203 |
|
public void onEnabled(Context context) { |
204 |
|
super.onEnabled(context); |
205 |
|
Log.i(TAG, "onEnabled"); |
206 |
|
|
207 |
|
resetStatics();//free memory |
208 |
|
} |
209 |
|
|
210 |
} |
} |