Moved the CordovaInterface over to master, doing this before working on CordovaJS

This commit is contained in:
Joe Bowser 2012-02-17 13:11:15 -08:00
parent 95b9cd0229
commit 040619cd61
9 changed files with 99 additions and 19 deletions

View File

@ -18,9 +18,11 @@
*/ */
package com.phonegap.api; package com.phonegap.api;
import android.app.Activity;
/** /**
* The Cordova activity abstract class that is extended by DroidGap. * The Cordova activity abstract class that is extended by DroidGap.
* It is used to isolate plugin development, and remove dependency on entire Cordova library. * It is used to isolate plugin development, and remove dependency on entire Cordova library.
*/ */
public abstract class PhonegapActivity extends org.apache.cordova.api.CordovaInterface { public abstract class PhonegapActivity extends Activity implements org.apache.cordova.api.CordovaInterface {
} }

View File

@ -179,9 +179,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(ctx), "Pic.jpg"); photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.jpg");
} else if (encodingType == PNG) { } else if (encodingType == PNG) {
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png"); photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.png");
} else { } else {
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType); throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
} }
@ -285,7 +285,7 @@ public class CameraLauncher extends Plugin {
// 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();
if (this.encodingType == JPEG) { if (this.encodingType == JPEG) {
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg"); exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
exif.readExifData(); exif.readExifData();
} }
@ -398,7 +398,7 @@ 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(ctx) + "/resize.jpg"; String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/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();

View File

@ -196,7 +196,7 @@ 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(ctx), "Capture.jpg"); File photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "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);
@ -249,7 +249,7 @@ 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(ctx) + "/Capture.jpg"); exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
exif.readExifData(); exif.readExifData();
// Read in bitmap of captured image // Read in bitmap of captured image

View File

@ -19,6 +19,7 @@ package org.apache.cordova;
import java.util.HashMap; import java.util.HashMap;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.util.Log; import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
@ -36,7 +37,7 @@ import org.json.JSONObject;
public abstract class ContactAccessor { public abstract class ContactAccessor {
protected final String LOG_TAG = "ContactsAccessor"; protected final String LOG_TAG = "ContactsAccessor";
protected Activity mApp; protected Context mApp;
protected WebView mView; protected WebView mView;
/** /**

View File

@ -43,6 +43,7 @@ import android.content.ContentProviderOperation;
import android.content.ContentProviderResult; import android.content.ContentProviderResult;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException; import android.content.OperationApplicationException;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -121,8 +122,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
/** /**
* Create an contact accessor. * Create an contact accessor.
*/ */
public ContactAccessorSdk5(WebView view, Activity app) { public ContactAccessorSdk5(WebView view, Context context) {
mApp = app; mApp = context;
mView = view; mView = view;
} }

View File

@ -79,7 +79,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.ctx.getContext());
} }
try { try {

View File

@ -37,6 +37,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@ -47,6 +48,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.media.AudioManager; import android.media.AudioManager;
@ -159,7 +161,7 @@ import android.widget.LinearLayout;
* ... * ...
* </plugins> * </plugins>
*/ */
public class DroidGap extends CordovaInterface { public class DroidGap extends Activity implements CordovaInterface {
public static String TAG = "DroidGap"; public static String TAG = "DroidGap";
// The webview for our app // The webview for our app
@ -1171,7 +1173,6 @@ public class DroidGap extends CordovaInterface {
} }
} }
@Override
public void setActivityResultCallback(IPlugin plugin) { public void setActivityResultCallback(IPlugin plugin) {
this.activityResultCallback = plugin; this.activityResultCallback = plugin;
} }
@ -1388,4 +1389,23 @@ public class DroidGap extends CordovaInterface {
this.postMessage("onOptionsItemSelected", item); this.postMessage("onOptionsItemSelected", item);
return true; return true;
} }
public Context getContext() {
return this;
}
public Cursor managedQuery(Uri parse, String[] strings, Object object,
Object object2, Object object3) {
return this.managedQuery(parse, strings, object, object2, object3);
}
public void bindBackButton(boolean override) {
// TODO Auto-generated method stub
}
public boolean isBackButtonBound() {
// TODO Auto-generated method stub
return false;
}
} }

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, ringtone); Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
// If phone is not set to silent mode // If phone is not set to silent mode
if (notification != null) { if (notification != null) {
@ -190,7 +190,7 @@ public class Notification extends Plugin {
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx); AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle(title); dlg.setTitle(title);
dlg.setCancelable(false); dlg.setCancelable(false);
@ -226,7 +226,7 @@ public class Notification extends Plugin {
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx); AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
dlg.setMessage(message); dlg.setMessage(message);
dlg.setTitle(title); dlg.setTitle(title);
dlg.setCancelable(false); dlg.setCancelable(false);
@ -287,7 +287,7 @@ public class Notification extends Plugin {
final CordovaInterface ctx = this.ctx; final CordovaInterface ctx = this.ctx;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true, notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), 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;
@ -323,7 +323,7 @@ public class Notification extends Plugin {
final CordovaInterface ctx = this.ctx; final CordovaInterface ctx = this.ctx;
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
notification.progressDialog = new ProgressDialog(ctx); notification.progressDialog = new ProgressDialog(ctx.getContext());
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);

View File

@ -18,14 +18,27 @@
*/ */
package org.apache.cordova.api; package org.apache.cordova.api;
import java.util.HashMap;
import android.app.Activity; import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.hardware.SensorManager;
import android.net.Uri;
/** /**
* The Cordova activity abstract class that is extended by DroidGap. * The Cordova activity abstract class that is extended by DroidGap.
* It is used to isolate plugin development, and remove dependency on entire Cordova library. * It is used to isolate plugin development, and remove dependency on entire Cordova library.
*/ */
public abstract class CordovaInterface extends Activity { public interface CordovaInterface {
/** /**
* @deprecated * @deprecated
@ -77,4 +90,47 @@ public abstract class CordovaInterface extends Activity {
* @param data The message data * @param data The message data
*/ */
abstract public void postMessage(String id, Object data); abstract public void postMessage(String id, Object data);
public abstract Resources getResources();
public abstract String getPackageName();
public abstract Object getSystemService(String service);
public abstract Context getContext();
public abstract Context getBaseContext();
public abstract Intent registerReceiver(BroadcastReceiver receiver,
IntentFilter intentFilter);
public abstract ContentResolver getContentResolver();
public abstract void unregisterReceiver(BroadcastReceiver receiver);
public abstract Cursor managedQuery(Uri parse, String[] strings,
Object object, Object object2, Object object3);
public abstract void runOnUiThread(Runnable runnable);
public abstract AssetManager getAssets();
public abstract void clearCache();
public abstract void clearHistory();
public abstract boolean backHistory();
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
public abstract void bindBackButton(boolean override);
public abstract boolean isBackButtonBound();
public abstract void cancelLoadUrl();
public abstract void showWebPage(String url, boolean openExternal,
boolean clearHistory, HashMap<String, Object> params);
public abstract Context getApplicationContext();
} }