/[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 771 by torben, Mon May 31 14:14:59 2010 UTC revision 788 by torben, Thu Jun 3 06:55:59 2010 UTC
# Line 7  import java.io.IOException; Line 7  import java.io.IOException;
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;
# Line 27  public class Side9WidgetProvider extends Line 28  public class Side9WidgetProvider extends
28          private static Bitmap usedBitmap;          private static Bitmap usedBitmap;
29          private static long timestamp;          private static long timestamp;
30    
31          final static long UDPATESPAN = 3*60*60*1000;          final static long UDPATESPAN = 4*60*60*1000;
           
         final static String SAVEDIR = "/sdcard/Side9/";  
   
32    
33          static  {          static  {
34                  timestamp = 0L;                  timestamp = 0L;
# Line 39  public class Side9WidgetProvider extends Line 37  public class Side9WidgetProvider extends
37          public Side9WidgetProvider() {          public Side9WidgetProvider() {
38                  Log.i(TAG, "WidgetProvider constructor called");                  Log.i(TAG, "WidgetProvider constructor called");
39          }          }
40            
41            public void resetStatics() {
42                    Log.i(TAG, "resetStatics");
43                    usedData = null;
44                    usedBitmap = null;              
45            }
46            
47            
48    
49    
50    
51          private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) {          private void setImage(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, Bitmap image) {
52                  // 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
# Line 56  public class Side9WidgetProvider extends Line 64  public class Side9WidgetProvider extends
64                          //views.setTextViewText(R.id.caption, newData.caption);                          //views.setTextViewText(R.id.caption, newData.caption);
65    
66    
67                            Intent viewIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.ekstrabladet.dk/side9/"));                    
68    
69                                                    
70                          //View single file                          //View single file
# Line 71  public class Side9WidgetProvider extends Line 80  public class Side9WidgetProvider extends
80                          //viewIntent.setClassName("com.android.camera", "com.android.camera.GalleryPicker");                          //viewIntent.setClassName("com.android.camera", "com.android.camera.GalleryPicker");
81                                                    
82    
83                          Intent viewIntent = new Intent();                          /*Intent viewIntent = new Intent();
84                          viewIntent.addCategory(Intent.CATEGORY_LAUNCHER);                          viewIntent.addCategory(Intent.CATEGORY_LAUNCHER);
85                          viewIntent.setAction(Intent.ACTION_MAIN);                          viewIntent.setAction(Intent.ACTION_MAIN);
86                          viewIntent.setComponent(new ComponentName("com.android.camera", ".GalleryPicker"));                          viewIntent.setComponent(new ComponentName("com.android.camera", ".GalleryPicker"));
87                          viewIntent.setFlags(0x10200000);                          viewIntent.setFlags(0x10200000);*/
88    
89                                                    
90                                                    
# Line 144  public class Side9WidgetProvider extends Line 153  public class Side9WidgetProvider extends
153                  SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE);                  SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE);
154                  boolean saveImage = prefs.getBoolean("saveimage", false);                  boolean saveImage = prefs.getBoolean("saveimage", false);
155                                    
156                  File file = new File( SAVEDIR + data.getFilename() );                  final String savepath = Environment.getExternalStorageDirectory() + "/Side9";
157                    
158                    File file = new File( savepath + "/" + data.getFilename() );
159                                    
160                  if (saveImage == true) {                                          /* if the picture changes later on the day we do NOT want to use an old and invalid image              
161                    if (saveImage == true) {                        
162                          if (file.exists()) {                          if (file.exists()) {
163                                  return BitmapFactory.decodeFile(file.getAbsolutePath());                                  return BitmapFactory.decodeFile(file.getAbsolutePath());
164                          }                          }
165                  }                  }*/
166                    
167                                                                    
168                  byte imageData[] = HttpUtil.getContent(data.url, 2500);                  byte imageData[] = HttpUtil.getContent(data.url, 2500);
169                                    
170                  if (saveImage == true) {                  if (saveImage == true) {
171                          File savedir = new File(SAVEDIR);                          if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
172                          savedir.mkdirs();                                  File savedir = new File(savepath);
173                                                            savedir.mkdirs();
174                          FileOutputStream fos = new FileOutputStream(file);                                  
175                          fos.write(imageData);                                  if (file.exists()) {
176                          fos.close();                                          file.delete();
177                                    }
178                                    
179                                    FileOutputStream fos = new FileOutputStream(file);
180                                    fos.write(imageData);
181                                    fos.close();
182    
183                                    Intent rescan = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()) );
184                                    rescan.putExtra("read-only", false);                                                            
185                                    context.sendBroadcast(rescan);
186                                    
187                            } else {
188                                    Log.i(TAG, "sdcard is not mounted");
189                            }
190                  }                  }
191                                    
192                  return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);                  return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
# Line 172  public class Side9WidgetProvider extends Line 198  public class Side9WidgetProvider extends
198          public void onDisabled(Context context) {          public void onDisabled(Context context) {
199                  super.onDisabled(context);                  super.onDisabled(context);
200                  Log.i(TAG, "onDisabled");                  Log.i(TAG, "onDisabled");
201                    
202                  usedData = null; //free memory                  resetStatics();//free memory
                 usedBitmap = null;  
203          }          }
204    
205            @Override
206            public void onEnabled(Context context) {
207                    super.onEnabled(context);
208                    Log.i(TAG, "onEnabled");
209                    
210                    resetStatics();//free memory
211            }
212            
213  }  }

Legend:
Removed from v.771  
changed lines
  Added in v.788

  ViewVC Help
Powered by ViewVC 1.1.20