This commit is contained in:
Anis Kadri 2012-06-19 16:28:11 -07:00
commit d60806bfa6
24 changed files with 154 additions and 150 deletions

View File

@ -23,7 +23,7 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title> <title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title"> <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script> <script type="text/javascript" charset="utf-8" src="cordova-1.9.0rc1.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script> <script type="text/javascript" charset="utf-8" src="main.js"></script>
</head> </head>

View File

@ -19,7 +19,7 @@
<html> <html>
<head> <head>
<title></title> <title></title>
<script src="cordova-1.8.0.js"></script> <script src="cordova-1.9.0rc1.js"></script>
</head> </head>
<body> <body>

View File

@ -68,12 +68,12 @@ public class AccelListener extends Plugin implements SensorEventListener {
* Sets the context of the Command. This can then be used to do things like * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity. * get file paths associated with the Activity.
* *
* @param ctx The context of the main Activity. * @param cordova The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface cordova) {
super.setContext(ctx); super.setContext(cordova);
this.sensorManager = (SensorManager) ctx.getActivity().getSystemService(Context.SENSOR_SERVICE); this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
} }
/** /**

View File

@ -49,7 +49,7 @@ public class App extends Plugin {
this.clearCache(); this.clearCache();
} }
else if (action.equals("show")) { // TODO @bc - Not in master branch. When should this be called? else if (action.equals("show")) { // TODO @bc - Not in master branch. When should this be called?
ctx.getActivity().runOnUiThread(new Runnable() { cordova.getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
webView.postMessage("spinner", "stop"); webView.postMessage("spinner", "stop");
} }
@ -162,7 +162,7 @@ public class App extends Plugin {
*/ */
@Deprecated @Deprecated
public void cancelLoadUrl() { public void cancelLoadUrl() {
this.ctx.cancelLoadUrl(); this.cordova.cancelLoadUrl();
} }
/** /**
@ -188,7 +188,7 @@ public class App extends Plugin {
*/ */
public void overrideBackbutton(boolean override) { public void overrideBackbutton(boolean override) {
LOG.i("App", "WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!"); LOG.i("App", "WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!");
this.ctx.bindBackButton(override); this.cordova.bindBackButton(override);
} }
/** /**
@ -200,7 +200,7 @@ public class App extends Plugin {
*/ */
public void overrideButton(String button, boolean override) { public void overrideButton(String button, boolean override) {
LOG.i("DroidGap", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!"); LOG.i("DroidGap", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!");
((DroidGap)this.ctx).bindButton(button, override); this.cordova.bindButton(button, override);
} }
/** /**
* Return whether the Android back button is overridden by the user. * Return whether the Android back button is overridden by the user.
@ -208,7 +208,7 @@ public class App extends Plugin {
* @return boolean * @return boolean
*/ */
public boolean isBackbuttonOverridden() { public boolean isBackbuttonOverridden() {
return this.ctx.isBackButtonBound(); return this.cordova.isBackButtonBound();
} }
/** /**

View File

@ -305,7 +305,7 @@ public class AudioHandler extends Plugin {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void setAudioOutputDevice(int output) { public void setAudioOutputDevice(int output) {
AudioManager audiMgr = (AudioManager) this.ctx.getActivity().getSystemService(Context.AUDIO_SERVICE); AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
if (output == 2) { if (output == 2) {
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
} }
@ -324,7 +324,7 @@ public class AudioHandler extends Plugin {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public int getAudioOutputDevice() { public int getAudioOutputDevice() {
AudioManager audiMgr = (AudioManager) this.ctx.getActivity().getSystemService(Context.AUDIO_SERVICE); AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) { if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) {
return 1; return 1;
} }

View File

@ -88,7 +88,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3"; this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3";
} else { } else {
this.tempFile = "/data/data/" + handler.ctx.getActivity().getPackageName() + "/cache/tmprecording.mp3"; this.tempFile = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/tmprecording.mp3";
} }
} }
@ -160,7 +160,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath() f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + file)); + File.separator + file));
} else { } else {
f.renameTo(new File("/data/data/" + handler.ctx.getActivity().getPackageName() + "/cache/" + file)); f.renameTo(new File("/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/" + file));
} }
} }
@ -220,7 +220,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
else { else {
if (file.startsWith("/android_asset/")) { if (file.startsWith("/android_asset/")) {
String f = file.substring(15); String f = file.substring(15);
android.content.res.AssetFileDescriptor fd = this.handler.ctx.getActivity().getAssets().openFd(f); android.content.res.AssetFileDescriptor fd = this.handler.cordova.getActivity().getAssets().openFd(f);
this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength()); this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
} }
else { else {

View File

@ -73,7 +73,7 @@ public class BatteryListener extends Plugin {
updateBatteryInfo(intent); updateBatteryInfo(intent);
} }
}; };
ctx.getActivity().registerReceiver(this.receiver, intentFilter); cordova.getActivity().registerReceiver(this.receiver, intentFilter);
} }
// Don't return any result now, since status results will be sent when events come in from broadcast receiver // Don't return any result now, since status results will be sent when events come in from broadcast receiver
@ -105,7 +105,7 @@ public class BatteryListener extends Plugin {
private void removeBatteryListener() { private void removeBatteryListener() {
if (this.receiver != null) { if (this.receiver != null) {
try { try {
this.ctx.getActivity().unregisterReceiver(this.receiver); this.cordova.getActivity().unregisterReceiver(this.receiver);
this.receiver = null; this.receiver = null;
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "Error unregistering battery receiver: " + e.getMessage(), e); Log.e(LOG_TAG, "Error unregistering battery receiver: " + e.getMessage(), e);

View File

@ -176,8 +176,8 @@ public class CameraLauncher extends Plugin {
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
this.imageUri = Uri.fromFile(photo); this.imageUri = Uri.fromFile(photo);
if (this.ctx != null) { if (this.cordova != null) {
this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); this.cordova.startActivityForResult((Plugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
} }
// else // else
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity"); // LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
@ -192,9 +192,9 @@ public class CameraLauncher extends Plugin {
private File createCaptureFile(int encodingType) { private File createCaptureFile(int encodingType) {
File photo = null; File photo = null;
if (encodingType == JPEG) { if (encodingType == JPEG) {
photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Pic.jpg"); photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Pic.jpg");
} else if (encodingType == PNG) { } else if (encodingType == PNG) {
photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Pic.png"); photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Pic.png");
} else { } else {
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType); throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
} }
@ -228,8 +228,8 @@ public class CameraLauncher extends Plugin {
intent.setAction(Intent.ACTION_GET_CONTENT); intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
if (this.ctx != null) { if (this.cordova != null) {
this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent, this.cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent,
new String(title)), (srcType + 1) * 16 + returnType + 1); new String(title)), (srcType + 1) * 16 + returnType + 1);
} }
} }
@ -299,7 +299,7 @@ public class CameraLauncher extends Plugin {
ExifHelper exif = new ExifHelper(); ExifHelper exif = new ExifHelper();
try { try {
if (this.encodingType == JPEG) { if (this.encodingType == JPEG) {
exif.createInFile(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/Pic.jpg"); exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Pic.jpg");
exif.readExifData(); exif.readExifData();
} }
} catch (IOException e) { } catch (IOException e) {
@ -313,10 +313,10 @@ public class CameraLauncher extends Plugin {
// Read in bitmap of captured image // Read in bitmap of captured image
Bitmap bitmap; Bitmap bitmap;
try { try {
bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(), imageUri); bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Uri uri = intent.getData(); Uri uri = intent.getData();
android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
} }
@ -336,11 +336,11 @@ public class CameraLauncher extends Plugin {
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = null; Uri uri = null;
try { try {
uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
LOG.d(LOG_TAG, "Can't write to external media storage."); LOG.d(LOG_TAG, "Can't write to external media storage.");
try { try {
uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException ex) { } 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."); this.failPicture("Error capturing image - no media storage found.");
@ -349,13 +349,13 @@ public class CameraLauncher extends Plugin {
} }
// Add compressed version of captured image to returned media store Uri // Add compressed version of captured image to returned media store Uri
OutputStream os = this.ctx.getActivity().getContentResolver().openOutputStream(uri); OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
os.close(); os.close();
// Restore exif data to file // Restore exif data to file
if (this.encodingType == JPEG) { if (this.encodingType == JPEG) {
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx)); exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova));
exif.writeExifData(); exif.writeExifData();
} }
@ -388,7 +388,7 @@ public class CameraLauncher extends Plugin {
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
Uri uri = intent.getData(); Uri uri = intent.getData();
android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
// If you ask for video or all media type you will automatically get back a file URI // 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 // and there will be no attempt to resize any returned data
@ -401,7 +401,7 @@ public class CameraLauncher extends Plugin {
try { try {
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
String[] cols = { MediaStore.Images.Media.ORIENTATION }; String[] cols = { MediaStore.Images.Media.ORIENTATION };
Cursor cursor = this.ctx.getActivity().getContentResolver().query(intent.getData(), Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(),
cols, cols,
null, null, null); null, null, null);
if (cursor != null) { if (cursor != null) {
@ -433,14 +433,14 @@ public class CameraLauncher extends Plugin {
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
bitmap = scaleBitmap(bitmap); bitmap = scaleBitmap(bitmap);
String fileName = DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/resize.jpg"; String fileName = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
OutputStream os = new FileOutputStream(fileName); OutputStream os = new FileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
os.close(); os.close();
// Restore exif data to file // Restore exif data to file
if (this.encodingType == JPEG) { if (this.encodingType == JPEG) {
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx)); exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova));
exif.writeExifData(); exif.writeExifData();
} }
@ -477,7 +477,7 @@ public class CameraLauncher extends Plugin {
* @return a cursor * @return a cursor
*/ */
private Cursor queryImgDB() { private Cursor queryImgDB() {
return this.ctx.getActivity().getContentResolver().query( return this.cordova.getActivity().getContentResolver().query(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.Media._ID }, new String[] { MediaStore.Images.Media._ID },
null, null,
@ -506,7 +506,7 @@ public class CameraLauncher extends Plugin {
cursor.moveToLast(); 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); Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
this.ctx.getActivity().getContentResolver().delete(uri, null, null); this.cordova.getActivity().getContentResolver().delete(uri, null, null);
} }
} }

View File

@ -195,7 +195,7 @@ public class Capture extends Plugin {
private void captureAudio() { private void captureAudio() {
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION); Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO); this.cordova.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
} }
/** /**
@ -205,11 +205,11 @@ public class Capture extends Plugin {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// Specify file so that large image is captured and returned // Specify file so that large image is captured and returned
File photo = new File(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()), "Capture.jpg"); File photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Capture.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
this.imageUri = Uri.fromFile(photo); this.imageUri = Uri.fromFile(photo);
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE); this.cordova.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
} }
/** /**
@ -220,7 +220,7 @@ public class Capture extends Plugin {
// Introduced in API 8 // Introduced in API 8
//intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration); //intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO); this.cordova.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
} }
/** /**
@ -258,11 +258,11 @@ public class Capture extends Plugin {
try { try {
// Create an ExifHelper to save the exif data that is lost during compression // Create an ExifHelper to save the exif data that is lost during compression
ExifHelper exif = new ExifHelper(); ExifHelper exif = new ExifHelper();
exif.createInFile(DirectoryManager.getTempDirectoryPath(this.ctx.getActivity()) + "/Capture.jpg"); exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");
exif.readExifData(); exif.readExifData();
// Read in bitmap of captured image // Read in bitmap of captured image
Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(), imageUri); Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
// Create entry in media store for image // Create entry in media store for image
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
@ -270,11 +270,11 @@ public class Capture extends Plugin {
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG);
Uri uri = null; Uri uri = null;
try { try {
uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
LOG.d(LOG_TAG, "Can't write to external media storage."); LOG.d(LOG_TAG, "Can't write to external media storage.");
try { try {
uri = this.ctx.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException ex) { } 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.")); this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image - no media storage found."));
@ -283,7 +283,7 @@ public class Capture extends Plugin {
} }
// Add compressed version of captured image to returned media store Uri // Add compressed version of captured image to returned media store Uri
OutputStream os = this.ctx.getActivity().getContentResolver().openOutputStream(uri); OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.close(); os.close();
@ -292,7 +292,7 @@ public class Capture extends Plugin {
System.gc(); System.gc();
// Restore exif data to file // Restore exif data to file
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx)); exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova));
exif.writeExifData(); exif.writeExifData();
// Add image to results // Add image to results
@ -356,7 +356,7 @@ public class Capture extends Plugin {
* @throws IOException * @throws IOException
*/ */
private JSONObject createMediaFile(Uri data) { private JSONObject createMediaFile(Uri data) {
File fp = new File(FileUtils.getRealPathFromURI(data, this.ctx)); File fp = new File(FileUtils.getRealPathFromURI(data, this.cordova));
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
try { try {

View File

@ -67,11 +67,11 @@ public class CompassListener extends Plugin implements SensorEventListener {
* Sets the context of the Command. This can then be used to do things like * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity. * get file paths associated with the Activity.
* *
* @param ctx The context of the main Activity. * @param cordova The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface cordova) {
super.setContext(ctx); super.setContext(cordova);
this.sensorManager = (SensorManager) ctx.getActivity().getSystemService(Context.SENSOR_SERVICE); this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
} }
/** /**

View File

@ -69,7 +69,7 @@ public class ContactManager extends Plugin {
* older phones. * older phones.
*/ */
if (this.contactAccessor == null) { if (this.contactAccessor == null) {
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx); this.contactAccessor = new ContactAccessorSdk5(this.webView, this.cordova);
} }
try { try {

View File

@ -45,16 +45,16 @@ public class CordovaChromeClient extends WebChromeClient {
private String TAG = "CordovaLog"; private String TAG = "CordovaLog";
private long MAX_QUOTA = 100 * 1024 * 1024; private long MAX_QUOTA = 100 * 1024 * 1024;
private CordovaInterface ctx; private CordovaInterface cordova;
private CordovaWebView appView; private CordovaWebView appView;
/** /**
* Constructor. * Constructor.
* *
* @param ctx * @param cordova
*/ */
public CordovaChromeClient(CordovaInterface ctx) { public CordovaChromeClient(CordovaInterface cordova) {
this.ctx = ctx; this.cordova = cordova;
} }
/** /**
@ -64,7 +64,7 @@ public class CordovaChromeClient extends WebChromeClient {
* @param app * @param app
*/ */
public CordovaChromeClient(CordovaInterface ctx, CordovaWebView app) { public CordovaChromeClient(CordovaInterface ctx, CordovaWebView app) {
this.ctx = ctx; this.cordova = ctx;
this.appView = app; this.appView = app;
} }
@ -87,7 +87,7 @@ public class CordovaChromeClient extends WebChromeClient {
*/ */
@Override @Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx.getActivity()); AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle("Alert"); dlg.setTitle("Alert");
//Don't let alerts break the back button //Don't let alerts break the back button
@ -131,7 +131,7 @@ public class CordovaChromeClient extends WebChromeClient {
*/ */
@Override @Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx.getActivity()); AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle("Confirm"); dlg.setTitle("Confirm");
dlg.setCancelable(true); dlg.setCancelable(true);
@ -243,9 +243,9 @@ public class CordovaChromeClient extends WebChromeClient {
// Show dialog // Show dialog
else { else {
final JsPromptResult res = result; final JsPromptResult res = result;
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx.getActivity()); AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
dlg.setMessage(message); dlg.setMessage(message);
final EditText input = new EditText(this.ctx.getActivity()); final EditText input = new EditText(this.cordova.getActivity());
if (defaultValue != null) { if (defaultValue != null) {
input.setText(defaultValue); input.setText(defaultValue);
} }

View File

@ -55,7 +55,7 @@ public class CordovaWebView extends WebView {
public CallbackServer callbackServer; public CallbackServer callbackServer;
/** Actvities and other important classes **/ /** Actvities and other important classes **/
private CordovaInterface mCtx; private CordovaInterface cordova;
CordovaWebViewClient viewClient; CordovaWebViewClient viewClient;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private CordovaChromeClient chromeClient; private CordovaChromeClient chromeClient;
@ -79,7 +79,7 @@ public class CordovaWebView extends WebView {
super(context); super(context);
if (CordovaInterface.class.isInstance(context)) if (CordovaInterface.class.isInstance(context))
{ {
this.mCtx = (CordovaInterface) context; this.cordova = (CordovaInterface) context;
} }
else else
{ {
@ -99,14 +99,14 @@ public class CordovaWebView extends WebView {
super(context, attrs); super(context, attrs);
if (CordovaInterface.class.isInstance(context)) if (CordovaInterface.class.isInstance(context))
{ {
this.mCtx = (CordovaInterface) context; this.cordova = (CordovaInterface) context;
} }
else else
{ {
Log.d(TAG, "Your activity must implement CordovaInterface to work"); Log.d(TAG, "Your activity must implement CordovaInterface to work");
} }
this.setWebChromeClient(new CordovaChromeClient(this.mCtx, this)); this.setWebChromeClient(new CordovaChromeClient(this.cordova, this));
this.setWebViewClient(new CordovaWebViewClient(this.mCtx, this)); this.setWebViewClient(new CordovaWebViewClient(this.cordova, this));
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -123,14 +123,14 @@ public class CordovaWebView extends WebView {
super(context, attrs, defStyle); super(context, attrs, defStyle);
if (CordovaInterface.class.isInstance(context)) if (CordovaInterface.class.isInstance(context))
{ {
this.mCtx = (CordovaInterface) context; this.cordova = (CordovaInterface) context;
} }
else else
{ {
Log.d(TAG, "Your activity must implement CordovaInterface to work"); Log.d(TAG, "Your activity must implement CordovaInterface to work");
} }
this.setWebChromeClient(new CordovaChromeClient(this.mCtx, this)); this.setWebChromeClient(new CordovaChromeClient(this.cordova, this));
this.setWebViewClient(new CordovaWebViewClient(this.mCtx, this)); this.setWebViewClient(new CordovaWebViewClient(this.cordova, this));
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -147,14 +147,14 @@ public class CordovaWebView extends WebView {
super(context, attrs, defStyle, privateBrowsing); super(context, attrs, defStyle, privateBrowsing);
if (CordovaInterface.class.isInstance(context)) if (CordovaInterface.class.isInstance(context))
{ {
this.mCtx = (CordovaInterface) context; this.cordova = (CordovaInterface) context;
} }
else else
{ {
Log.d(TAG, "Your activity must implement CordovaInterface to work"); Log.d(TAG, "Your activity must implement CordovaInterface to work");
} }
this.setWebChromeClient(new CordovaChromeClient(this.mCtx)); this.setWebChromeClient(new CordovaChromeClient(this.cordova));
this.setWebViewClient(new CordovaWebViewClient(this.mCtx)); this.setWebViewClient(new CordovaWebViewClient(this.cordova));
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -180,7 +180,7 @@ public class CordovaWebView extends WebView {
// Enable database // Enable database
settings.setDatabaseEnabled(true); settings.setDatabaseEnabled(true);
String databasePath = this.mCtx.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); String databasePath = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath); settings.setDatabasePath(databasePath);
// Enable DOM storage // Enable DOM storage
@ -191,7 +191,7 @@ public class CordovaWebView extends WebView {
//Start up the plugin manager //Start up the plugin manager
try { try {
this.pluginManager = new PluginManager(this, this.mCtx); this.pluginManager = new PluginManager(this, this.cordova);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -383,13 +383,13 @@ public class CordovaWebView extends WebView {
// If timeout, then stop loading and handle error // If timeout, then stop loading and handle error
if (me.loadUrlTimeout == currentLoadUrlTimeout) { if (me.loadUrlTimeout == currentLoadUrlTimeout) {
me.mCtx.getActivity().runOnUiThread(loadError); me.cordova.getActivity().runOnUiThread(loadError);
} }
} }
}; };
// Load url // Load url
this.mCtx.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
Thread thread = new Thread(timeoutCheck); Thread thread = new Thread(timeoutCheck);
thread.start(); thread.start();
@ -558,7 +558,7 @@ public class CordovaWebView extends WebView {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
mCtx.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e); LOG.e(TAG, "Error loading url " + url, e);
} }
@ -570,7 +570,7 @@ public class CordovaWebView extends WebView {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
mCtx.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e); LOG.e(TAG, "Error loading url " + url, e);
} }
@ -585,7 +585,7 @@ public class CordovaWebView extends WebView {
* <log level="DEBUG" /> * <log level="DEBUG" />
*/ */
private void loadConfiguration() { private void loadConfiguration() {
int id = getResources().getIdentifier("cordova", "xml", this.mCtx.getActivity().getPackageName()); int id = getResources().getIdentifier("cordova", "xml", this.cordova.getActivity().getPackageName());
if (id == 0) { if (id == 0) {
LOG.i("CordovaLog", "cordova.xml missing. Ignoring..."); LOG.i("CordovaLog", "cordova.xml missing. Ignoring...");
return; return;
@ -616,7 +616,7 @@ public class CordovaWebView extends WebView {
LOG.i("CordovaLog", "Found preference for %s=%s", name, value); LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
// Save preferences in Intent // Save preferences in Intent
this.mCtx.getActivity().getIntent().putExtra(name, value); this.cordova.getActivity().getIntent().putExtra(name, value);
} }
} }
try { try {
@ -637,8 +637,8 @@ public class CordovaWebView extends WebView {
} }
if ("true".equals(this.getProperty("fullscreen", "false"))) { if ("true".equals(this.getProperty("fullscreen", "false"))) {
this.mCtx.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); this.cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.mCtx.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this.cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
} }
@ -650,7 +650,7 @@ public class CordovaWebView extends WebView {
* @return * @return
*/ */
public String getProperty(String name, String defaultValue) { public String getProperty(String name, String defaultValue) {
Bundle bundle = this.mCtx.getActivity().getIntent().getExtras(); Bundle bundle = this.cordova.getActivity().getIntent().getExtras();
if (bundle == null) { if (bundle == null) {
return defaultValue; return defaultValue;
} }

View File

@ -44,7 +44,7 @@ import android.webkit.WebViewClient;
public class CordovaWebViewClient extends WebViewClient { public class CordovaWebViewClient extends WebViewClient {
private static final String TAG = "Cordova"; private static final String TAG = "Cordova";
CordovaInterface ctx; CordovaInterface cordova;
CordovaWebView appView; CordovaWebView appView;
private boolean doClearHistory = false; private boolean doClearHistory = false;
@ -54,20 +54,20 @@ public class CordovaWebViewClient extends WebViewClient {
/** /**
* Constructor. * Constructor.
* *
* @param ctx * @param cordova
*/ */
public CordovaWebViewClient(CordovaInterface ctx) { public CordovaWebViewClient(CordovaInterface cordova) {
this.ctx = ctx; this.cordova = cordova;
} }
/** /**
* Constructor. * Constructor.
* *
* @param ctx * @param cordova
* @param view * @param view
*/ */
public CordovaWebViewClient(CordovaInterface ctx, CordovaWebView view) { public CordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
this.ctx = ctx; this.cordova = cordova;
this.appView = view; this.appView = view;
} }
@ -100,7 +100,7 @@ public class CordovaWebViewClient extends WebViewClient {
try { try {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
this.ctx.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error dialing " + url + ": " + e.toString()); LOG.e(TAG, "Error dialing " + url + ": " + e.toString());
} }
@ -111,7 +111,7 @@ public class CordovaWebViewClient extends WebViewClient {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
this.ctx.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error showing map " + url + ": " + e.toString()); LOG.e(TAG, "Error showing map " + url + ": " + e.toString());
} }
@ -122,7 +122,7 @@ public class CordovaWebViewClient extends WebViewClient {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
this.ctx.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error sending email " + url + ": " + e.toString()); LOG.e(TAG, "Error sending email " + url + ": " + e.toString());
} }
@ -154,7 +154,7 @@ public class CordovaWebViewClient extends WebViewClient {
intent.setData(Uri.parse("sms:" + address)); intent.setData(Uri.parse("sms:" + address));
intent.putExtra("address", address); intent.putExtra("address", address);
intent.setType("vnd.android-dir/mms-sms"); intent.setType("vnd.android-dir/mms-sms");
this.ctx.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error sending sms " + url + ":" + e.toString()); LOG.e(TAG, "Error sending sms " + url + ":" + e.toString());
} }
@ -178,7 +178,7 @@ public class CordovaWebViewClient extends WebViewClient {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
this.ctx.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e); LOG.e(TAG, "Error loading url " + url, e);
} }
@ -280,7 +280,7 @@ public class CordovaWebViewClient extends WebViewClient {
public void run() { public void run() {
try { try {
Thread.sleep(2000); Thread.sleep(2000);
ctx.getActivity().runOnUiThread(new Runnable() { cordova.getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
appView.postMessage("spinner", "stop"); appView.postMessage("spinner", "stop");
} }
@ -342,8 +342,8 @@ public class CordovaWebViewClient extends WebViewClient {
@Override @Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
final String packageName = this.ctx.getActivity().getPackageName(); final String packageName = this.cordova.getActivity().getPackageName();
final PackageManager pm = this.ctx.getActivity().getPackageManager(); final PackageManager pm = this.cordova.getActivity().getPackageManager();
ApplicationInfo appInfo; ApplicationInfo appInfo;
try { try {
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

View File

@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
public class Device extends Plugin { public class Device extends Plugin {
public static final String TAG = "Device"; public static final String TAG = "Device";
public static String cordovaVersion = "1.8.0"; // Cordova version public static String cordovaVersion = "1.9.0rc1"; // Cordova version
public static String platform = "Android"; // Device OS public static String platform = "Android"; // Device OS
public static String uuid; // Device UUID public static String uuid; // Device UUID
@ -54,10 +54,10 @@ public class Device extends Plugin {
* Sets the context of the Command. This can then be used to do things like * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity. * get file paths associated with the Activity.
* *
* @param ctx The context of the main Activity. * @param cordova The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface cordova) {
super.setContext(ctx); super.setContext(cordova);
Device.uuid = getUuid(); Device.uuid = getUuid();
this.initTelephonyReceiver(); this.initTelephonyReceiver();
} }
@ -110,7 +110,7 @@ public class Device extends Plugin {
* Unregister receiver. * Unregister receiver.
*/ */
public void onDestroy() { public void onDestroy() {
this.ctx.getActivity().unregisterReceiver(this.telephonyReceiver); this.cordova.getActivity().unregisterReceiver(this.telephonyReceiver);
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@ -125,7 +125,7 @@ public class Device extends Plugin {
private void initTelephonyReceiver() { private void initTelephonyReceiver() {
IntentFilter intentFilter = new IntentFilter(); IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
//final CordovaInterface myctx = this.ctx; //final CordovaInterface mycordova = this.cordova;
this.telephonyReceiver = new BroadcastReceiver() { this.telephonyReceiver = new BroadcastReceiver() {
@Override @Override
@ -153,7 +153,7 @@ public class Device extends Plugin {
}; };
// Register the receiver // Register the receiver
this.ctx.getActivity().registerReceiver(this.telephonyReceiver, intentFilter); this.cordova.getActivity().registerReceiver(this.telephonyReceiver, intentFilter);
} }
/** /**
@ -171,7 +171,7 @@ public class Device extends Plugin {
* @return * @return
*/ */
public String getUuid() { public String getUuid() {
String uuid = Settings.Secure.getString(this.ctx.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
return uuid; return uuid;
} }

View File

@ -524,7 +524,7 @@ public class FileTransfer extends Plugin {
private InputStream getPathFromUri(String path) throws FileNotFoundException { private InputStream getPathFromUri(String path) throws FileNotFoundException {
if (path.startsWith("content:")) { if (path.startsWith("content:")) {
Uri uri = Uri.parse(path); Uri uri = Uri.parse(path);
return ctx.getActivity().getContentResolver().openInputStream(uri); return cordova.getActivity().getContentResolver().openInputStream(uri);
} }
else if (path.startsWith("file://")) { else if (path.startsWith("file://")) {
int question = path.indexOf("?"); int question = path.indexOf("?");

View File

@ -223,9 +223,9 @@ public class FileUtils extends Plugin {
*/ */
private void notifyDelete(String filePath) { private void notifyDelete(String filePath) {
String newFilePath = stripFileProtocol(filePath); String newFilePath = stripFileProtocol(filePath);
int result = this.ctx.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, int result = this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
MediaStore.Images.Media.DATA + " = ?", MediaStore.Images.Media.DATA + " = ?",
new String[] { filePath }); new String[] { newFilePath });
} }
/** /**
@ -246,7 +246,7 @@ public class FileUtils extends Plugin {
// Handle the special case where you get an Android content:// uri. // Handle the special case where you get an Android content:// uri.
if (decoded.startsWith("content:")) { if (decoded.startsWith("content:")) {
Cursor cursor = this.ctx.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null); Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
// Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data" // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst(); cursor.moveToFirst();
@ -728,9 +728,9 @@ public class FileUtils extends Plugin {
private boolean atRootDirectory(String filePath) { private boolean atRootDirectory(String filePath) {
filePath = stripFileProtocol(filePath); filePath = stripFileProtocol(filePath);
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getActivity().getPackageName() + "/cache") || if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) || filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
filePath.equals("/data/data/" + ctx.getActivity().getPackageName())) { filePath.equals("/data/data/" + cordova.getActivity().getPackageName())) {
return true; return true;
} }
return false; return false;
@ -819,16 +819,16 @@ public class FileUtils extends Plugin {
fs.put("name", "temporary"); fs.put("name", "temporary");
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + ctx.getActivity().getPackageName() + "/cache/"); "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
// Create the cache dir if it doesn't exist. // Create the cache dir if it doesn't exist.
fp.mkdirs(); fp.mkdirs();
fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() + fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + ctx.getActivity().getPackageName() + "/cache/")); "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/"));
} else { } else {
fp = new File("/data/data/" + ctx.getActivity().getPackageName() + "/cache/"); fp = new File("/data/data/" + cordova.getActivity().getPackageName() + "/cache/");
// Create the cache dir if it doesn't exist. // Create the cache dir if it doesn't exist.
fp.mkdirs(); fp.mkdirs();
fs.put("root", getEntry("/data/data/" + ctx.getActivity().getPackageName() + "/cache/")); fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName() + "/cache/"));
} }
} }
else if (type == PERSISTENT) { else if (type == PERSISTENT) {
@ -836,7 +836,7 @@ public class FileUtils extends Plugin {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
fs.put("root", getEntry(Environment.getExternalStorageDirectory())); fs.put("root", getEntry(Environment.getExternalStorageDirectory()));
} else { } else {
fs.put("root", getEntry("/data/data/" + ctx.getActivity().getPackageName())); fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName()));
} }
} }
else { else {
@ -943,7 +943,7 @@ public class FileUtils extends Plugin {
String contentType = null; String contentType = null;
if (filename.startsWith("content:")) { if (filename.startsWith("content:")) {
Uri fileUri = Uri.parse(filename); Uri fileUri = Uri.parse(filename);
contentType = this.ctx.getActivity().getContentResolver().getType(fileUri); contentType = this.cordova.getActivity().getContentResolver().getType(fileUri);
} }
else { else {
contentType = getMimeType(filename); contentType = getMimeType(filename);
@ -1026,7 +1026,7 @@ public class FileUtils extends Plugin {
private InputStream getPathFromUri(String path) throws FileNotFoundException { private InputStream getPathFromUri(String path) throws FileNotFoundException {
if (path.startsWith("content")) { if (path.startsWith("content")) {
Uri uri = Uri.parse(path); Uri uri = Uri.parse(path);
return ctx.getActivity().getContentResolver().openInputStream(uri); return cordova.getActivity().getContentResolver().openInputStream(uri);
} }
else { else {
path = stripFileProtocol(path); path = stripFileProtocol(path);
@ -1038,13 +1038,13 @@ public class FileUtils extends Plugin {
* Queries the media store to find out what the file path is for the Uri we supply * Queries the media store to find out what the file path is for the Uri we supply
* *
* @param contentUri the Uri of the audio/image/video * @param contentUri the Uri of the audio/image/video
* @param ctx) the current applicaiton context * @param cordova) the current applicaiton context
* @return the full path to the file * @return the full path to the file
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) { protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) {
String[] proj = { _DATA }; String[] proj = { _DATA };
Cursor cursor = ctx.getActivity().managedQuery(contentUri, proj, null, null, null); Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(_DATA); int column_index = cursor.getColumnIndexOrThrow(_DATA);
cursor.moveToFirst(); cursor.moveToFirst();
return cursor.getString(column_index); return cursor.getString(column_index);

View File

@ -55,7 +55,7 @@ public class GeoBroker extends Plugin {
*/ */
public PluginResult execute(String action, JSONArray args, String callbackId) { public PluginResult execute(String action, JSONArray args, String callbackId) {
if (this.locationManager == null) { if (this.locationManager == null) {
this.locationManager = (LocationManager) this.ctx.getActivity().getSystemService(Context.LOCATION_SERVICE); this.locationManager = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
this.networkListener = new NetworkListener(this.locationManager, this); this.networkListener = new NetworkListener(this.locationManager, this);
this.gpsListener = new GPSListener(this.locationManager, this); this.gpsListener = new GPSListener(this.locationManager, this);
} }

View File

@ -84,11 +84,11 @@ public class NetworkManager extends Plugin {
* Sets the context of the Command. This can then be used to do things like * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity. * get file paths associated with the Activity.
* *
* @param ctx The context of the main Activity. * @param cordova The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface cordova) {
super.setContext(ctx); super.setContext(cordova);
this.sockMan = (ConnectivityManager) ctx.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
this.connectionCallbackId = null; this.connectionCallbackId = null;
// We need to listen to connectivity events to update navigator.connection // We need to listen to connectivity events to update navigator.connection
@ -102,7 +102,7 @@ public class NetworkManager extends Plugin {
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
} }
}; };
ctx.getActivity().registerReceiver(this.receiver, intentFilter); cordova.getActivity().registerReceiver(this.receiver, intentFilter);
} }
} }
@ -146,7 +146,7 @@ public class NetworkManager extends Plugin {
public void onDestroy() { public void onDestroy() {
if (this.receiver != null) { if (this.receiver != null) {
try { try {
this.ctx.getActivity().unregisterReceiver(this.receiver); this.cordova.getActivity().unregisterReceiver(this.receiver);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
} }

View File

@ -143,7 +143,7 @@ public class Notification extends Plugin {
*/ */
public void beep(long count) { public void beep(long count) {
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone notification = RingtoneManager.getRingtone(this.ctx.getActivity().getBaseContext(), ringtone); Ringtone notification = RingtoneManager.getRingtone(this.cordova.getActivity().getBaseContext(), ringtone);
// If phone is not set to silent mode // If phone is not set to silent mode
if (notification != null) { if (notification != null) {
@ -171,7 +171,7 @@ public class Notification extends Plugin {
if (time == 0) { if (time == 0) {
time = 500; time = 500;
} }
Vibrator vibrator = (Vibrator) this.ctx.getActivity().getSystemService(Context.VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(time); vibrator.vibrate(time);
} }
@ -184,13 +184,13 @@ public class Notification extends Plugin {
*/ */
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) { public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
final CordovaInterface ctx = this.ctx; final CordovaInterface cordova = this.cordova;
final Notification notification = this; final Notification notification = this;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getActivity()); AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle(title); dlg.setTitle(title);
dlg.setCancelable(false); dlg.setCancelable(false);
@ -205,7 +205,7 @@ public class Notification extends Plugin {
dlg.show(); dlg.show();
}; };
}; };
this.ctx.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
} }
/** /**
@ -220,13 +220,13 @@ public class Notification extends Plugin {
*/ */
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) { public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
final CordovaInterface ctx = this.ctx; final CordovaInterface cordova = this.cordova;
final Notification notification = this; final Notification notification = this;
final String[] fButtons = buttonLabels.split(","); final String[] fButtons = buttonLabels.split(",");
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getActivity()); AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle(title); dlg.setTitle(title);
dlg.setCancelable(false); dlg.setCancelable(false);
@ -269,7 +269,7 @@ public class Notification extends Plugin {
dlg.show(); dlg.show();
}; };
}; };
this.ctx.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
} }
/** /**
@ -284,10 +284,10 @@ public class Notification extends Plugin {
this.spinnerDialog = null; this.spinnerDialog = null;
} }
final Notification notification = this; final Notification notification = this;
final CordovaInterface ctx = this.ctx; final CordovaInterface cordova = this.cordova;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
notification.spinnerDialog = ProgressDialog.show(ctx.getActivity(), title, message, true, true, notification.spinnerDialog = ProgressDialog.show(cordova.getActivity(), title, message, true, true,
new DialogInterface.OnCancelListener() { new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
notification.spinnerDialog = null; notification.spinnerDialog = null;
@ -295,7 +295,7 @@ public class Notification extends Plugin {
}); });
} }
}; };
this.ctx.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
} }
/** /**
@ -320,10 +320,10 @@ public class Notification extends Plugin {
this.progressDialog = null; this.progressDialog = null;
} }
final Notification notification = this; final Notification notification = this;
final CordovaInterface ctx = this.ctx; final CordovaInterface cordova = this.cordova;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
notification.progressDialog = new ProgressDialog(ctx.getActivity()); notification.progressDialog = new ProgressDialog(cordova.getActivity());
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
notification.progressDialog.setTitle(title); notification.progressDialog.setTitle(title);
notification.progressDialog.setMessage(message); notification.progressDialog.setMessage(message);
@ -339,7 +339,7 @@ public class Notification extends Plugin {
notification.progressDialog.show(); notification.progressDialog.show();
} }
}; };
this.ctx.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
} }
/** /**

View File

@ -141,7 +141,7 @@ public class Storage extends Plugin {
// If no database path, generate from application package // If no database path, generate from application package
if (this.path == null) { if (this.path == null) {
this.path = this.ctx.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); this.path = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
} }
this.dbName = this.path + File.pathSeparator + db + ".db"; this.dbName = this.path + File.pathSeparator + db + ".db";

View File

@ -46,11 +46,11 @@ public class TempListener extends Plugin implements SensorEventListener {
* Sets the context of the Command. This can then be used to do things like * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity. * get file paths associated with the Activity.
* *
* @param ctx The context of the main Activity. * @param cordova The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface cordova) {
super.setContext(ctx); super.setContext(cordova);
this.sensorManager = (SensorManager) ctx.getActivity().getSystemService(Context.SENSOR_SERVICE); this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
} }
/** /**

View File

@ -76,4 +76,6 @@ public interface CordovaInterface {
* @return Object or null * @return Object or null
*/ */
public Object onMessage(String id, Object data); public Object onMessage(String id, Object data);
public abstract void bindButton(String button, boolean override);
} }

View File

@ -33,6 +33,7 @@ public abstract class Plugin implements IPlugin {
public String id; public String id;
public CordovaWebView webView; // WebView object public CordovaWebView webView; // WebView object
public CordovaInterface ctx; // CordovaActivity object public CordovaInterface ctx; // CordovaActivity object
public CordovaInterface cordova;
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
@ -61,7 +62,8 @@ public abstract class Plugin implements IPlugin {
* @param ctx The context of the main Activity. * @param ctx The context of the main Activity.
*/ */
public void setContext(CordovaInterface ctx) { public void setContext(CordovaInterface ctx) {
this.ctx = ctx; this.cordova = ctx;
this.ctx = cordova;
} }
/** /**