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 |
|
|
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 |
} |
} |
65 |
//views.setTextViewText(R.id.caption, newData.caption); |
|
66 |
|
boolean showcaption = context. |
67 |
|
getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE). |
68 |
|
getBoolean(Side9Config.PREFS_SHOWCAPTION, false); |
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 |
|
|
76 |
|
|
77 |
//Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/")); |
//Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/")); |
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 |
final String savepath = Environment.getExternalStorageDirectory() + "/Side9"; |
final String savepath = Environment.getExternalStorageDirectory() + "/Side9"; |
147 |
|
|
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 |
|
|