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