incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bcur...@apache.org
Subject [10/15] Updates.
Date Tue, 15 May 2012 04:38:01 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c8fafa6b/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java
index 5751464..94d7e9c 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -26,7 +26,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.commons.codec.binary.Base64;
-import org.apache.cordova.api.CordovaInterface;
+//import org.apache.cordova.api.CordovaInterface;
 import org.apache.cordova.api.LOG;
 import org.apache.cordova.api.Plugin;
 import org.apache.cordova.api.PluginResult;
@@ -35,7 +35,7 @@ import org.json.JSONException;
 
 import android.app.Activity;
 import android.content.ContentValues;
-import android.content.Context;
+//import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
 import android.graphics.Bitmap;
@@ -53,50 +53,50 @@ public class CameraLauncher extends Plugin {
 
     private static final int DATA_URL = 0;              // Return base64 encoded string
     private static final int FILE_URI = 1;              // Return file uri (content://media/external/images/media/2 for Android)
-    
+
     private static final int PHOTOLIBRARY = 0;          // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
     private static final int CAMERA = 1;                // Take picture from camera
     private static final int SAVEDPHOTOALBUM = 2;       // Choose image from picture library (same as PHOTOLIBRARY for Android)
-    
+
     private static final int PICTURE = 0;               // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
     private static final int VIDEO = 1;                 // allow selection of video only, ONLY RETURNS URL
     private static final int ALLMEDIA = 2;              // allow selection from all media types
-    
+
     private static final int JPEG = 0;                  // Take a picture of type JPEG
     private static final int PNG = 1;                   // Take a picture of type PNG
     private static final String GET_PICTURE = "Get Picture";
     private static final String GET_VIDEO = "Get Video";
     private static final String GET_All = "Get All";
-    
+
     private static final String LOG_TAG = "CameraLauncher";
-    
+
     private int mQuality;                   // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
     private int targetWidth;                // desired width of the image
     private int targetHeight;               // desired height of the image
     private Uri imageUri;                   // Uri of captured image       
     private int encodingType;               // Type of encoding to use
     private int mediaType;                  // What type of media to retrieve
-     
+
     public String callbackId;
     private int numPics;
-    
+
     //This should never be null!
-    private CordovaInterface cordova;
-    
+    //private CordovaInterface cordova;
+
     /**
      * Constructor.
      */
     public CameraLauncher() {
     }
 
-    public void setContext(Context mCtx) {
-      super.setContext(mCtx);
-      if(CordovaInterface.class.isInstance(mCtx))
-        cordova = (CordovaInterface) mCtx;
-      else
-        LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
-    }
-    
+//    public void setContext(CordovaInterface mCtx) {
+//        super.setContext(mCtx);
+//        if (CordovaInterface.class.isInstance(mCtx))
+//            cordova = (CordovaInterface) mCtx;
+//        else
+//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
+//    }
+
     /**
      * Executes the request and returns PluginResult.
      * 
@@ -107,9 +107,9 @@ public class CameraLauncher extends Plugin {
      */
     public PluginResult execute(String action, JSONArray args, String callbackId) {
         PluginResult.Status status = PluginResult.Status.OK;
-        String result = "";     
+        String result = "";
         this.callbackId = callbackId;
-        
+
         try {
             if (action.equals("takePicture")) {
                 int srcType = CAMERA;
@@ -127,7 +127,7 @@ public class CameraLauncher extends Plugin {
                 this.targetHeight = args.getInt(4);
                 this.encodingType = args.getInt(5);
                 this.mediaType = args.getInt(6);
-                
+
                 if (srcType == CAMERA) {
                     this.takePicture(destType, encodingType);
                 }
@@ -144,11 +144,11 @@ public class CameraLauncher extends Plugin {
             return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
         }
     }
-    
+
     //--------------------------------------------------------------------------
     // LOCAL METHODS
     //--------------------------------------------------------------------------
-    
+
     /**
      * Take a picture with the camera.
      * When an image is captured or the camera view is cancelled, the result is returned
@@ -166,20 +166,21 @@ public class CameraLauncher extends Plugin {
     public void takePicture(int returnType, int encodingType) {
         // Save the number of images currently on disk for later
         this.numPics = queryImgDB().getCount();
-                
+
         // Display camera
         Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
-        
+
         // Specify file so that large image is captured and returned
         // TODO: What if there isn't any external storage?
         File photo = createCaptureFile(encodingType);
         intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
         this.imageUri = Uri.fromFile(photo);
-        
-        if(cordova != null)
-          cordova.startActivityForResult((Plugin) this, intent, (CAMERA+1)*16 + returnType+1);
-        else
-          LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
+
+        if (this.ctx != null) {
+            this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
+        }
+//        else
+//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
     }
 
     /**
@@ -191,9 +192,9 @@ public class CameraLauncher extends Plugin {
     private File createCaptureFile(int encodingType) {
         File photo = null;
         if (encodingType == JPEG) {
-            photo = new File(DirectoryManager.getTempDirectoryPath(ctx),  "Pic.jpg");
+            photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Pic.jpg");
         } else if (encodingType == PNG) {
-            photo = new File(DirectoryManager.getTempDirectoryPath(ctx),  "Pic.png");            
+            photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Pic.png");
         } else {
             throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
         }
@@ -212,23 +213,25 @@ public class CameraLauncher extends Plugin {
         Intent intent = new Intent();
         String title = GET_PICTURE;
         if (this.mediaType == PICTURE) {
-            intent.setType("image/*");  
+            intent.setType("image/*");
         }
         else if (this.mediaType == VIDEO) {
-            intent.setType("video/*");     
+            intent.setType("video/*");
             title = GET_VIDEO;
         }
         else if (this.mediaType == ALLMEDIA) {
             // I wanted to make the type 'image/*, video/*' but this does not work on all versions 
             // of android so I had to go with the wildcard search.
-            intent.setType("*/*"); 
+            intent.setType("*/*");
             title = GET_All;
         }
-        
+
         intent.setAction(Intent.ACTION_GET_CONTENT);
         intent.addCategory(Intent.CATEGORY_OPENABLE);
-        cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent,
-                new String(title)), (srcType+1)*16 + returnType + 1);
+        if (this.ctx != null) {
+            this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent,
+                    new String(title)), (srcType + 1) * 16 + returnType + 1);
+        }
     }
 
     /**
@@ -262,8 +265,8 @@ public class CameraLauncher extends Plugin {
         // kept and Bitmap.SCALE_TO_FIT specified when scaling, but this
         // would result in whitespace in the new image.
         else {
-            double newRatio = newWidth / (double)newHeight;
-            double origRatio = origWidth / (double)origHeight;
+            double newRatio = newWidth / (double) newHeight;
+            double origRatio = origWidth / (double) origHeight;
 
             if (origRatio > newRatio) {
                 newHeight = (newWidth * origHeight) / origWidth;
@@ -271,10 +274,10 @@ public class CameraLauncher extends Plugin {
                 newWidth = (newHeight * origWidth) / origHeight;
             }
         }
-        
+
         return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
     }
-    
+
     /**
      * Called when the camera view exits. 
      * 
@@ -284,22 +287,22 @@ public class CameraLauncher extends Plugin {
      * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
      */
     public void onActivityResult(int requestCode, int resultCode, Intent intent) {
-        
+
         // Get src and dest types from request code
-        int srcType = (requestCode/16) - 1;
+        int srcType = (requestCode / 16) - 1;
         int destType = (requestCode % 16) - 1;
-     int rotate = 0;
-        
-     // Create an ExifHelper to save the exif data that is lost during compression
-     ExifHelper exif = new ExifHelper();
-     try {
-         if (this.encodingType == JPEG) {
-            exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
-            exif.readExifData();
-         }
-     } catch (IOException e) {
-         e.printStackTrace();
-     }
+        int rotate = 0;
+
+        // Create an ExifHelper to save the exif data that is lost during compression
+        ExifHelper exif = new ExifHelper();
+        try {
+            if (this.encodingType == JPEG) {
+                exif.createInFile(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/Pic.jpg");
+                exif.readExifData();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
 
         // If CAMERA
         if (srcType == CAMERA) {
@@ -309,15 +312,15 @@ public class CameraLauncher extends Plugin {
                     // Read in bitmap of captured image
                     Bitmap bitmap;
                     try {
-                        bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
+                        bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(), imageUri);
                     } catch (FileNotFoundException e) {
                         Uri uri = intent.getData();
-                        android.content.ContentResolver resolver = this.ctx.getContentResolver();
+                        android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver();
                         bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
                     }
 
                     bitmap = scaleBitmap(bitmap);
-                    
+
                     // If sending base64 image back
                     if (destType == DATA_URL) {
                         this.processPicture(bitmap);
@@ -325,33 +328,33 @@ public class CameraLauncher extends Plugin {
                     }
 
                     // If sending filename back
-                    else if (destType == FILE_URI){
+                    else if (destType == FILE_URI) {
                         // Create entry in media store for image
                         // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
                         ContentValues values = new ContentValues();
                         values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
                         Uri uri = null;
                         try {
-                            uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
+                            uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                         } catch (UnsupportedOperationException e) {
                             LOG.d(LOG_TAG, "Can't write to external media storage.");
                             try {
-                                uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
+                                uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                             } catch (UnsupportedOperationException ex) {
-                                LOG.d(LOG_TAG, "Can't write to internal media storage.");                           
+                                LOG.d(LOG_TAG, "Can't write to internal media storage.");
                                 this.failPicture("Error capturing image - no media storage found.");
                                 return;
                             }
                         }
 
                         // Add compressed version of captured image to returned media store Uri
-                        OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
+                        OutputStream os = this.ctx.getActivity().getContentResolver().openOutputStream(uri);
                         bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                         os.close();
-                        
+
                         // Restore exif data to file
                         if (this.encodingType == JPEG) {
-                            exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
+                            exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
                             exif.writeExifData();
                         }
 
@@ -361,12 +364,12 @@ public class CameraLauncher extends Plugin {
                     bitmap.recycle();
                     bitmap = null;
                     System.gc();
-                    
+
                     checkForDuplicateImage(FILE_URI);
                 } catch (IOException e) {
                     e.printStackTrace();
                     this.failPicture("Error capturing image.");
-                }       
+                }
             }
 
             // If cancelled
@@ -379,37 +382,37 @@ public class CameraLauncher extends Plugin {
                 this.failPicture("Did not complete!");
             }
         }
-        
+
         // If retrieving photo from library
         else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
             if (resultCode == Activity.RESULT_OK) {
                 Uri uri = intent.getData();
-                android.content.ContentResolver resolver = this.ctx.getContentResolver();
-                
+                android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver();
+
                 // If you ask for video or all media type you will automatically get back a file URI 
                 // and there will be no attempt to resize any returned data
                 if (this.mediaType != PICTURE) {
-                    this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);                        
+                    this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
                 }
                 else {
                     // If sending base64 image back
                     if (destType == DATA_URL) {
                         try {
                             Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
-                 String[] cols = { MediaStore.Images.Media.ORIENTATION };
-                 Cursor cursor = this.ctx.getContentResolver().query(intent.getData(), 
-                                         cols, 
-                                         null, null, null);
-                 if (cursor != null) {
-                 cursor.moveToPosition(0);
-                 rotate = cursor.getInt(0);
-                 cursor.close();
-                 }
-                 if (rotate != 0) {
-                 Matrix matrix = new Matrix();
-                 matrix.setRotate(rotate);
-                 bitmap = bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
-                 }
+                            String[] cols = { MediaStore.Images.Media.ORIENTATION };
+                            Cursor cursor = this.ctx.getActivity().getContentResolver().query(intent.getData(),
+                                    cols,
+                                    null, null, null);
+                            if (cursor != null) {
+                                cursor.moveToPosition(0);
+                                rotate = cursor.getInt(0);
+                                cursor.close();
+                            }
+                            if (rotate != 0) {
+                                Matrix matrix = new Matrix();
+                                matrix.setRotate(rotate);
+                                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
+                            }
                             bitmap = scaleBitmap(bitmap);
                             this.processPicture(bitmap);
                             bitmap.recycle();
@@ -420,7 +423,7 @@ public class CameraLauncher extends Plugin {
                             this.failPicture("Error retrieving image.");
                         }
                     }
-                    
+
                     // If sending filename back
                     else if (destType == FILE_URI) {
                         // Do we need to scale the returned file
@@ -428,21 +431,21 @@ public class CameraLauncher extends Plugin {
                             try {
                                 Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
                                 bitmap = scaleBitmap(bitmap);
-    
-                                String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
-                                OutputStream os = new FileOutputStream(fileName);                         
+
+                                String fileName = DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/resize.jpg";
+                                OutputStream os = new FileOutputStream(fileName);
                                 bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                                 os.close();
-    
+
                                 // Restore exif data to file
                                 if (this.encodingType == JPEG) {
-                                    exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) ctx)));
+                                    exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
                                     exif.writeExifData();
                                 }
 
                                 bitmap.recycle();
                                 bitmap = null;
-                                
+
                                 // The resized image is cached by the app in order to get around this and not have to delete you 
                                 // application cache I'm adding the current system time to the end of the file url.
                                 this.success(new PluginResult(PluginResult.Status.OK, ("file://" + fileName + "?" + System.currentTimeMillis())), this.callbackId);
@@ -453,16 +456,16 @@ public class CameraLauncher extends Plugin {
                             }
                         }
                         else {
-                            this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);                        
+                            this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
                         }
                     }
                 }
             }
             else if (resultCode == Activity.RESULT_CANCELED) {
-                this.failPicture("Selection cancelled.");               
+                this.failPicture("Selection cancelled.");
             }
             else {
-                this.failPicture("Selection did not complete!");                
+                this.failPicture("Selection did not complete!");
             }
         }
     }
@@ -473,14 +476,14 @@ public class CameraLauncher extends Plugin {
      * @return a cursor
      */
     private Cursor queryImgDB() {
-        return this.ctx.getContentResolver().query(
+        return this.ctx.getActivity().getContentResolver().query(
                 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                 new String[] { MediaStore.Images.Media._ID },
                 null,
                 null,
                 null);
     }
-    
+
     /**
      * Used to find out if we are in a situation where the Camera Intent adds to images
      * to the content store. If we are using a FILE_URI and the number of images in the DB 
@@ -492,17 +495,17 @@ public class CameraLauncher extends Plugin {
         int diff = 1;
         Cursor cursor = queryImgDB();
         int currentNumOfImages = cursor.getCount();
-        
+
         if (type == FILE_URI) {
             diff = 2;
         }
-        
+
         // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
         if ((currentNumOfImages - numPics) == diff) {
             cursor.moveToLast();
-            int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;                    
+            int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
             Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
-            this.ctx.getContentResolver().delete(uri, null, null);
+            this.ctx.getActivity().getContentResolver().delete(uri, null, null);
         }
     }
 
@@ -511,25 +514,24 @@ public class CameraLauncher extends Plugin {
      *
      * @param bitmap
      */
-    public void processPicture(Bitmap bitmap) {     
+    public void processPicture(Bitmap bitmap) {
         ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
         try {
             if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
-                byte[] code  = jpeg_data.toByteArray();
+                byte[] code = jpeg_data.toByteArray();
                 byte[] output = Base64.encodeBase64(code);
                 String js_out = new String(output);
                 this.success(new PluginResult(PluginResult.Status.OK, js_out), this.callbackId);
                 js_out = null;
                 output = null;
                 code = null;
-            }   
-        }
-        catch(Exception e) {
+            }
+        } catch (Exception e) {
             this.failPicture("Error compressing image.");
-        }       
+        }
         jpeg_data = null;
     }
-    
+
     /**
      * Send error message to JavaScript.
      * 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c8fafa6b/framework/src/org/apache/cordova/Capture.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java
index c1ee74f..bfb5307 100644
--- a/framework/src/org/apache/cordova/Capture.java
+++ b/framework/src/org/apache/cordova/Capture.java
@@ -32,7 +32,7 @@ import org.json.JSONObject;
 
 import android.app.Activity;
 import android.content.ContentValues;
-import android.content.Context;
+//import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -40,47 +40,47 @@ import android.media.MediaPlayer;
 import android.net.Uri;
 import android.util.Log;
 
-
 public class Capture extends Plugin {
 
     private static final String VIDEO_3GPP = "video/3gpp";
-    private static final String VIDEO_MP4  = "video/mp4";
+    private static final String VIDEO_MP4 = "video/mp4";
     private static final String AUDIO_3GPP = "audio/3gpp";
     private static final String IMAGE_JPEG = "image/jpeg";
-    
+
     private static final int CAPTURE_AUDIO = 0;     // Constant for capture audio
     private static final int CAPTURE_IMAGE = 1;     // Constant for capture image
     private static final int CAPTURE_VIDEO = 2;     // Constant for capture video
     private static final String LOG_TAG = "Capture";
-    
+
     private static final int CAPTURE_INTERNAL_ERR = 0;
-    private static final int CAPTURE_APPLICATION_BUSY = 1;
-    private static final int CAPTURE_INVALID_ARGUMENT = 2;
+//    private static final int CAPTURE_APPLICATION_BUSY = 1;
+//    private static final int CAPTURE_INVALID_ARGUMENT = 2;
     private static final int CAPTURE_NO_MEDIA_FILES = 3;
-    private static final int CAPTURE_NOT_SUPPORTED = 20;
-    
+//    private static final int CAPTURE_NOT_SUPPORTED = 20;
+
     private String callbackId;                      // The ID of the callback to be invoked with our result
     private long limit;                             // the number of pics/vids/clips to take
     private double duration;                        // optional duration parameter for video recording
     private JSONArray results;                      // The array of results to be returned to the user
     private Uri imageUri;                           // Uri of captured image 
-    private CordovaInterface cordova;
-
-    public void setContext(Context mCtx)
-    {
-      if(CordovaInterface.class.isInstance(mCtx))
-        cordova = (CordovaInterface) mCtx;
-      else
-        LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
-    }
-    
+
+    //private CordovaInterface cordova;
+
+//    public void setContext(Context mCtx)
+//    {
+//        if (CordovaInterface.class.isInstance(mCtx))
+//            cordova = (CordovaInterface) mCtx;
+//        else
+//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
+//    }
+
     @Override
     public PluginResult execute(String action, JSONArray args, String callbackId) {
         this.callbackId = callbackId;
         this.limit = 1;
         this.duration = 0.0f;
         this.results = new JSONArray();
-        
+
         JSONObject options = args.optJSONObject(0);
         if (options != null) {
             limit = options.optLong("limit", 1);
@@ -102,9 +102,9 @@ public class Capture extends Plugin {
             this.captureImage();
         }
         else if (action.equals("captureVideo")) {
-            this.captureVideo(duration);    
+            this.captureVideo(duration);
         }
-        
+
         PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
         r.setKeepCallback(true);
         return r;
@@ -133,7 +133,7 @@ public class Capture extends Plugin {
                 mimeType = FileUtils.getMimeType(filePath);
             }
             Log.d(LOG_TAG, "Mime type = " + mimeType);
-            
+
             if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) {
                 obj = getImageData(filePath, obj);
             }
@@ -143,8 +143,7 @@ public class Capture extends Plugin {
             else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) {
                 obj = getAudioVideoData(filePath, obj, true);
             }
-        }
-        catch (JSONException e) {
+        } catch (JSONException e) {
             Log.d(LOG_TAG, "Error: setting media file data object");
         }
         return obj;
@@ -179,15 +178,14 @@ public class Capture extends Plugin {
         try {
             player.setDataSource(filePath);
             player.prepare();
-            obj.put("duration", player.getDuration()/1000);
+            obj.put("duration", player.getDuration() / 1000);
             if (video) {
                 obj.put("height", player.getVideoHeight());
                 obj.put("width", player.getVideoWidth());
             }
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             Log.d(LOG_TAG, "Error: loading video file");
-        } 
+        }
         return obj;
     }
 
@@ -197,7 +195,7 @@ public class Capture extends Plugin {
     private void captureAudio() {
         Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
 
-        cordova.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
+        this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
     }
 
     /**
@@ -207,11 +205,11 @@ public class Capture extends Plugin {
         Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 
         // Specify file so that large image is captured and returned
-        File photo = new File(DirectoryManager.getTempDirectoryPath(ctx),  "Capture.jpg");
+        File photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Capture.jpg");
         intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
         this.imageUri = Uri.fromFile(photo);
 
-        cordova.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
+        this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
     }
 
     /**
@@ -221,10 +219,10 @@ public class Capture extends Plugin {
         Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
         // Introduced in API 8
         //intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
-        
-        cordova.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
+
+        this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
     }
-    
+
     /**
      * Called when the video view exits. 
      * 
@@ -260,11 +258,11 @@ public class Capture extends Plugin {
                 try {
                     // Create an ExifHelper to save the exif data that is lost during compression
                     ExifHelper exif = new ExifHelper();
-                    exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
+                    exif.createInFile(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/Capture.jpg");
                     exif.readExifData();
-                    
+
                     // Read in bitmap of captured image
-                    Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
+                    Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(), imageUri);
 
                     // Create entry in media store for image
                     // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
@@ -272,34 +270,34 @@ public class Capture extends Plugin {
                     values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG);
                     Uri uri = null;
                     try {
-                        uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
+                        uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                     } catch (UnsupportedOperationException e) {
                         LOG.d(LOG_TAG, "Can't write to external media storage.");
                         try {
-                            uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
+                            uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                         } catch (UnsupportedOperationException ex) {
-                            LOG.d(LOG_TAG, "Can't write to internal media storage.");                           
+                            LOG.d(LOG_TAG, "Can't write to internal media storage.");
                             this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image - no media storage found."));
                             return;
                         }
                     }
 
                     // Add compressed version of captured image to returned media store Uri
-                    OutputStream os  = this.ctx.getContentResolver().openOutputStream(uri);
+                    OutputStream os = this.ctx.getActivity().getContentResolver().openOutputStream(uri);
                     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
                     os.close();
 
                     bitmap.recycle();
                     bitmap = null;
                     System.gc();
-                    
+
                     // Restore exif data to file
-                    exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
+                    exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
                     exif.writeExifData();
-                    
+
                     // Add image to results
                     results.put(createMediaFile(uri));
-                    
+
                     if (results.length() >= limit) {
                         // Send Uri back to JavaScript for viewing image
                         this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
@@ -330,7 +328,7 @@ public class Capture extends Plugin {
         else if (resultCode == Activity.RESULT_CANCELED) {
             // If we have partial results send them back to the user
             if (results.length() > 0) {
-                this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);                
+                this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
             }
             // user canceled the action
             else {
@@ -341,7 +339,7 @@ public class Capture extends Plugin {
         else {
             // If we have partial results send them back to the user
             if (results.length() > 0) {
-                this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);                
+                this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
             }
             // something bad happened
             else {
@@ -357,38 +355,38 @@ public class Capture extends Plugin {
      * @return a JSONObject that represents a File
      * @throws IOException 
      */
-    private JSONObject createMediaFile(Uri data){
-        File fp = new File(FileUtils.getRealPathFromURI(data, ((Activity) this.ctx)));
+    private JSONObject createMediaFile(Uri data) {
+        File fp = new File(FileUtils.getRealPathFromURI(data, this.ctx));
         JSONObject obj = new JSONObject();
 
-        try {       
+        try {
             // File properties
             obj.put("name", fp.getName());
             obj.put("fullPath", fp.getAbsolutePath());
-            
+
             // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files 
             // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it 
             // is stored in the audio or video content store.
             if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
                 if (data.toString().contains("/audio/")) {
-                    obj.put("type", AUDIO_3GPP);                
+                    obj.put("type", AUDIO_3GPP);
                 } else {
-                    obj.put("type", VIDEO_3GPP);                
-                }               
+                    obj.put("type", VIDEO_3GPP);
+                }
             } else {
-                obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));                
+                obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));
             }
-            
+
             obj.put("lastModifiedDate", fp.lastModified());
             obj.put("size", fp.length());
         } catch (JSONException e) {
             // this will never happen
             e.printStackTrace();
         }
-        
+
         return obj;
     }
-    
+
     private JSONObject createErrorObject(int code, String message) {
         JSONObject obj = new JSONObject();
         try {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c8fafa6b/framework/src/org/apache/cordova/CompassListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CompassListener.java b/framework/src/org/apache/cordova/CompassListener.java
index 65b33bb..e9fbcac 100755
--- a/framework/src/org/apache/cordova/CompassListener.java
+++ b/framework/src/org/apache/cordova/CompassListener.java
@@ -27,7 +27,6 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-
 import android.hardware.Sensor;
 import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener;
@@ -43,18 +42,18 @@ public class CompassListener extends Plugin implements SensorEventListener {
     public static int STARTING = 1;
     public static int RUNNING = 2;
     public static int ERROR_FAILED_TO_START = 3;
-    
+
     public long TIMEOUT = 30000;        // Timeout in msec to shut off listener
-    
+
     int status;                         // status of listener
     float heading;                      // most recent heading value
     long timeStamp;                     // time of most recent value
     long lastAccessTime;                // time the value was last retrieved
     int accuracy;                       // accuracy of the sensor
-    
+
     private SensorManager sensorManager;// Sensor manager
     Sensor mSensor;                     // Compass sensor returned by sensor manager
-    
+
     /**
      * Constructor.
      */
@@ -70,9 +69,9 @@ public class CompassListener extends Plugin implements SensorEventListener {
      * 
      * @param ctx The context of the main Activity.
      */
-    public void setContext(Context ctx) {
+    public void setContext(CordovaInterface ctx) {
         super.setContext(ctx);
-        this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
+        this.sensorManager = (SensorManager) ctx.getActivity().getSystemService(Context.SENSOR_SERVICE);
     }
 
     /**
@@ -85,8 +84,8 @@ public class CompassListener extends Plugin implements SensorEventListener {
      */
     public PluginResult execute(String action, JSONArray args, String callbackId) {
         PluginResult.Status status = PluginResult.Status.OK;
-        String result = "";     
-        
+        String result = "";
+
         try {
             if (action.equals("start")) {
                 this.start();
@@ -116,7 +115,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
                         }
                     }
                     if (timeout == 0) {
-                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);                     
+                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);
                     }
                 }
                 return new PluginResult(status, getCompassHeading());
@@ -159,7 +158,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
         }
         return false;
     }
-    
+
     /**
      * Called when listener is to be shut down and object is being destroyed.
      */
@@ -177,13 +176,14 @@ public class CompassListener extends Plugin implements SensorEventListener {
      * @return          status of listener
      */
     public int start() {
-        
+
         // If already starting or running, then just return
         if ((this.status == CompassListener.RUNNING) || (this.status == CompassListener.STARTING)) {
             return this.status;
         }
 
         // Get compass sensor from sensor manager
+        @SuppressWarnings("deprecation")
         List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
 
         // If found, then register as listener
@@ -198,10 +198,10 @@ public class CompassListener extends Plugin implements SensorEventListener {
         else {
             this.setStatus(CompassListener.ERROR_FAILED_TO_START);
         }
-        
+
         return this.status;
     }
-    
+
     /**
      * Stop listening to compass sensor.
      */
@@ -211,8 +211,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
         }
         this.setStatus(CompassListener.STOPPED);
     }
-    
-    
+
     public void onAccuracyChanged(Sensor sensor, int accuracy) {
         // TODO Auto-generated method stub  
     }
@@ -237,7 +236,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
             this.stop();
         }
     }
-    
+
     /**
      * Get status of compass sensor.
      * 
@@ -246,7 +245,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
     public int getStatus() {
         return this.status;
     }
-    
+
     /**
      * Get the most recent compass heading.
      * 
@@ -256,7 +255,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
         this.lastAccessTime = System.currentTimeMillis();
         return this.heading;
     }
-    
+
     /**
      * Set the timeout to turn off compass sensor if getHeading() hasn't been called.
      * 
@@ -265,7 +264,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
     public void setTimeout(long timeout) {
         this.TIMEOUT = timeout;
     }
-    
+
     /**
      * Get the timeout to turn off compass sensor if getHeading() hasn't been called.
      * 
@@ -290,7 +289,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
      */
     private JSONObject getCompassHeading() {
         JSONObject obj = new JSONObject();
-        
+
         try {
             obj.put("magneticHeading", this.getHeading());
             obj.put("trueHeading", this.getHeading());
@@ -301,7 +300,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
         } catch (JSONException e) {
             // Should never happen
         }
-        
+
         return obj;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c8fafa6b/framework/src/org/apache/cordova/ContactAccessor.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactAccessor.java b/framework/src/org/apache/cordova/ContactAccessor.java
index 12669ce..99c375a 100644
--- a/framework/src/org/apache/cordova/ContactAccessor.java
+++ b/framework/src/org/apache/cordova/ContactAccessor.java
@@ -18,11 +18,12 @@ package org.apache.cordova;
 
 import java.util.HashMap;
 
-import android.app.Activity;
-import android.content.Context;
+//import android.app.Activity;
+//import android.content.Context;
 import android.util.Log;
 import android.webkit.WebView;
 
+import org.apache.cordova.api.CordovaInterface;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -35,11 +36,11 @@ import org.json.JSONObject;
  * Eclair or higher, we want to use {@link ContactAccessorSdk5}.
  */
 public abstract class ContactAccessor {
-  
+
     protected final String LOG_TAG = "ContactsAccessor";
-    protected Context mApp;
+    protected CordovaInterface mApp;
     protected WebView mView;
-  
+
     /**
      * Check to see if the data associated with the key is required to 
      * be populated in the Contact object.
@@ -47,22 +48,22 @@ public abstract class ContactAccessor {
      * @param map created by running buildPopulationSet.
      * @return true if the key data is required
      */
-    protected boolean isRequired(String key, HashMap<String,Boolean> map) {
-    Boolean retVal = map.get(key);
-    return (retVal == null) ? false : retVal.booleanValue();
-  }
-    
+    protected boolean isRequired(String key, HashMap<String, Boolean> map) {
+        Boolean retVal = map.get(key);
+        return (retVal == null) ? false : retVal.booleanValue();
+    }
+
     /**
      * Create a hash map of what data needs to be populated in the Contact object
      * @param fields the list of fields to populate
      * @return the hash map of required data
      */
-  protected HashMap<String,Boolean> buildPopulationSet(JSONArray fields) {
-    HashMap<String,Boolean> map = new HashMap<String,Boolean>();
-    
-    String key;
-    try {
-        if (fields.length() == 1 && fields.getString(0).equals("*")) {
+    protected HashMap<String, Boolean> buildPopulationSet(JSONArray fields) {
+        HashMap<String, Boolean> map = new HashMap<String, Boolean>();
+
+        String key;
+        try {
+            if (fields.length() == 1 && fields.getString(0).equals("*")) {
                 map.put("displayName", true);
                 map.put("name", true);
                 map.put("nickname", true);
@@ -76,90 +77,88 @@ public abstract class ContactAccessor {
                 map.put("urls", true);
                 map.put("photos", true);
                 map.put("categories", true);
-        } 
-        else {
-          for (int i=0; i<fields.length(); i++) {
-            key = fields.getString(i);
-            if (key.startsWith("displayName")) {
-              map.put("displayName", true);
-            }
-            else if (key.startsWith("name")) {
-                map.put("displayName", true);
-                map.put("name", true);
-            }
-            else if (key.startsWith("nickname")) {
-              map.put("nickname", true);
-            }
-            else if (key.startsWith("phoneNumbers")) {
-              map.put("phoneNumbers", true);
-            }
-            else if (key.startsWith("emails")) {
-              map.put("emails", true);
-            }
-            else if (key.startsWith("addresses")) {
-              map.put("addresses", true);
-            }
-            else if (key.startsWith("ims")) {
-              map.put("ims", true);
-            }
-            else if (key.startsWith("organizations")) {
-              map.put("organizations", true);
-            }
-            else if (key.startsWith("birthday")) {
-              map.put("birthday", true);
-            }
-            else if (key.startsWith("note")) {
-              map.put("note", true);
-            }
-            else if (key.startsWith("urls")) {
-              map.put("urls", true);
             }
+            else {
+                for (int i = 0; i < fields.length(); i++) {
+                    key = fields.getString(i);
+                    if (key.startsWith("displayName")) {
+                        map.put("displayName", true);
+                    }
+                    else if (key.startsWith("name")) {
+                        map.put("displayName", true);
+                        map.put("name", true);
+                    }
+                    else if (key.startsWith("nickname")) {
+                        map.put("nickname", true);
+                    }
+                    else if (key.startsWith("phoneNumbers")) {
+                        map.put("phoneNumbers", true);
+                    }
+                    else if (key.startsWith("emails")) {
+                        map.put("emails", true);
+                    }
+                    else if (key.startsWith("addresses")) {
+                        map.put("addresses", true);
+                    }
+                    else if (key.startsWith("ims")) {
+                        map.put("ims", true);
+                    }
+                    else if (key.startsWith("organizations")) {
+                        map.put("organizations", true);
+                    }
+                    else if (key.startsWith("birthday")) {
+                        map.put("birthday", true);
+                    }
+                    else if (key.startsWith("note")) {
+                        map.put("note", true);
+                    }
+                    else if (key.startsWith("urls")) {
+                        map.put("urls", true);
+                    }
                     else if (key.startsWith("photos")) {
                         map.put("photos", true);
                     }
                     else if (key.startsWith("categories")) {
                         map.put("categories", true);
                     }
-          }
+                }
+            }
+        } catch (JSONException e) {
+            Log.e(LOG_TAG, e.getMessage(), e);
         }
+        return map;
     }
-    catch (JSONException e) {
-      Log.e(LOG_TAG, e.getMessage(), e);
-    }
-    return map;
-  }
-  
-  /**
-   * Convenience method to get a string from a JSON object.  Saves a 
-   * lot of try/catch writing.
-   * If the property is not found in the object null will be returned.
-   * 
-   * @param obj contact object to search
-   * @param property to be looked up
-   * @return The value of the property
-   */
-  protected String getJsonString(JSONObject obj, String property) {
-    String value = null;
-    try {
-        if (obj != null) {
-      value = obj.getString(property);
-          if (value.equals("null")) {
-            Log.d(LOG_TAG, property + " is string called 'null'");
-            value = null;
-          }
+
+    /**
+     * Convenience method to get a string from a JSON object.  Saves a 
+     * lot of try/catch writing.
+     * If the property is not found in the object null will be returned.
+     * 
+     * @param obj contact object to search
+     * @param property to be looked up
+     * @return The value of the property
+     */
+    protected String getJsonString(JSONObject obj, String property) {
+        String value = null;
+        try {
+            if (obj != null) {
+                value = obj.getString(property);
+                if (value.equals("null")) {
+                    Log.d(LOG_TAG, property + " is string called 'null'");
+                    value = null;
+                }
+            }
+        } catch (JSONException e) {
+            Log.d(LOG_TAG, "Could not get = " + e.getMessage());
         }
+        return value;
     }
-    catch (JSONException e) {
-      Log.d(LOG_TAG, "Could not get = " + e.getMessage());
-    }   
-    return value;
-  }
 
     /**
      * Handles adding a JSON Contact object into the database.
      * @return TODO
      */
-  public abstract String save(JSONObject contact);
+    public abstract String save(JSONObject contact);
 
     /**
      * Handles searching through SDK-specific contacts API.
@@ -175,25 +174,29 @@ public abstract class ContactAccessor {
     /**
      * Handles removing a contact from the database.
      */
-  public abstract boolean remove(String id);
-  
-  /**
-   * A class that represents the where clause to be used in the database query 
-   */
-  class WhereOptions {
-    private String where;
-    private String[] whereArgs;
-    public void setWhere(String where) {
-      this.where = where;
-    }
-    public String getWhere() {
-      return where;
-    }
-    public void setWhereArgs(String[] whereArgs) {
-      this.whereArgs = whereArgs;
-    }
-    public String[] getWhereArgs() {
-      return whereArgs;
+    public abstract boolean remove(String id);
+
+    /**
+     * A class that represents the where clause to be used in the database query 
+     */
+    class WhereOptions {
+        private String where;
+        private String[] whereArgs;
+
+        public void setWhere(String where) {
+            this.where = where;
+        }
+
+        public String getWhere() {
+            return where;
+        }
+
+        public void setWhereArgs(String[] whereArgs) {
+            this.whereArgs = whereArgs;
+        }
+
+        public String[] getWhereArgs() {
+            return whereArgs;
+        }
     }
-  }
 }


Mime
View raw message