30 |
private static Side9Data usedData; |
private static Side9Data usedData; |
31 |
private static Bitmap usedBitmap; |
private static Bitmap usedBitmap; |
32 |
private static long timestamp; |
private static long timestamp; |
33 |
|
private static boolean reloadData; |
34 |
|
|
35 |
final static long UDPATESPAN = 4*60*60*1000; |
final static long UDPATESPAN = 4*60*60*1000; |
36 |
|
|
70 |
getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE). |
getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE). |
71 |
getBoolean(Side9Config.PREFS_SHOWCAPTION, false); |
getBoolean(Side9Config.PREFS_SHOWCAPTION, false); |
72 |
|
|
73 |
if (showcaption == true) { |
if (showcaption == true && usedData != null) { |
74 |
views.setTextViewText(R.id.caption, " " + usedData.caption + " "); |
views.setTextViewText(R.id.caption, " " + usedData.caption + " "); |
75 |
views.setViewVisibility(R.id.caption, View.VISIBLE); |
views.setViewVisibility(R.id.caption, View.VISIBLE); |
76 |
} else { |
} else { |
112 |
return; |
return; |
113 |
} |
} |
114 |
|
|
115 |
|
//we need to do a full reload of all data now and then because eb.dk sometimes are a bit slow with publishing the new |
116 |
|
//daily picture, and this is a (crude) way to ensure we have the latest data |
117 |
if (System.currentTimeMillis() > (timestamp+UDPATESPAN) ) { |
if (System.currentTimeMillis() > (timestamp+UDPATESPAN) ) { |
118 |
Log.i(TAG, "time elapsed, force XML reload"); |
Log.i(TAG, "time elapsed, force XML reload"); |
119 |
usedData = null; |
reloadData = true; |
120 |
} |
} |
121 |
|
|
122 |
try { |
try { |
123 |
Side9Data newData = Side9Xml.loadXml(); |
Side9Data newData = Side9Xml.loadXml(); |
124 |
|
|
125 |
if (! newData.equals(usedData)) { |
if (! newData.equals(usedData) || reloadData == true) { |
126 |
|
|
127 |
|
|
128 |
Log.i(TAG, "(Re)loading image:" + newData.url); |
Log.i(TAG, "(Re)loading image:" + newData.url); |
132 |
usedData = newData; // if we made it to here without exceptions, save the new data |
usedData = newData; // if we made it to here without exceptions, save the new data |
133 |
usedBitmap = image; |
usedBitmap = image; |
134 |
timestamp = System.currentTimeMillis(); |
timestamp = System.currentTimeMillis(); |
135 |
|
reloadData = false; |
136 |
|
|
137 |
} // endif |
} // endif |
138 |
|
|
175 |
FileOutputStream fos = new FileOutputStream(file); |
FileOutputStream fos = new FileOutputStream(file); |
176 |
fos.write(imageData); |
fos.write(imageData); |
177 |
fos.close(); |
fos.close(); |
178 |
|
|
179 |
|
File infoFile = new File( file.toString().replace(".jpg", ".txt")); |
180 |
|
if (infoFile.exists()) { |
181 |
|
infoFile.delete(); |
182 |
|
} |
183 |
|
fos = new FileOutputStream(infoFile); |
184 |
|
fos.write(data.caption.getBytes()); |
185 |
|
fos.close(); |
186 |
|
|
187 |
Intent rescan = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()) ); |
Intent rescan = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()) ); |
188 |
rescan.putExtra("read-only", false); |
rescan.putExtra("read-only", false); |