/[projects]/android/Side9/src/dk/thoerup/side9/Side9WidgetProvider.java
ViewVC logotype

Diff of /android/Side9/src/dk/thoerup/side9/Side9WidgetProvider.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 914 by torben, Sat Jun 26 09:42:40 2010 UTC revision 924 by torben, Sat Jun 26 18:16:01 2010 UTC
# Line 15  import android.graphics.BitmapFactory; Line 15  import android.graphics.BitmapFactory;
15  import android.net.ConnectivityManager;  import android.net.ConnectivityManager;
16  import android.net.Uri;  import android.net.Uri;
17  import android.os.Environment;  import android.os.Environment;
18    import android.util.DisplayMetrics;
19  import android.util.Log;  import android.util.Log;
20  import android.view.View;  import android.view.View;
21    import android.view.WindowManager;
22  import android.widget.RemoteViews;  import android.widget.RemoteViews;
23  import dk.thoerup.androidutils.HttpUtil;  import dk.thoerup.androidutils.HttpUtil;
24    
# Line 28  public class Side9WidgetProvider extends Line 30  public class Side9WidgetProvider extends
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    
# Line 67  public class Side9WidgetProvider extends Line 70  public class Side9WidgetProvider extends
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 {
# Line 109  public class Side9WidgetProvider extends Line 112  public class Side9WidgetProvider extends
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);
# Line 127  public class Side9WidgetProvider extends Line 132  public class Side9WidgetProvider extends
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    
# Line 180  public class Side9WidgetProvider extends Line 185  public class Side9WidgetProvider extends
185                          }                          }
186                  }                  }
187                                    
188                  Bitmap full = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);                   DisplayMetrics metrics = new DisplayMetrics();
189                  Bitmap scaled = Bitmap.createScaledBitmap(full, 400, 577, true);                   WindowManager wmgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
190                  return scaled;                   wmgr.getDefaultDisplay().getMetrics(metrics);
191                     int w = metrics.widthPixels - (2*40);
192                     int h = getHeight(w);
193                    
194                     Log.e(TAG, "w=" + w + "   h=" + h);
195                    
196                     Bitmap full = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
197                     Bitmap scaled = Bitmap.createScaledBitmap(full, w, h, true);
198                     return scaled;
199            }
200    
201            private static int getHeight(int w) {
202                    double h = w * (650.0 / 450.0);
203                    return (int)h;
204          }          }
205            
   
206          //Called when the last widget is removed/disabled          //Called when the last widget is removed/disabled
207          @Override          @Override
208          public void onDisabled(Context context) {          public void onDisabled(Context context) {

Legend:
Removed from v.914  
changed lines
  Added in v.924

  ViewVC Help
Powered by ViewVC 1.1.20