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

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

  ViewVC Help
Powered by ViewVC 1.1.20