mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Moved the CordovaInterface over to master, doing this before working on CordovaJS
This commit is contained in:
parent
95b9cd0229
commit
040619cd61
@ -18,9 +18,11 @@
|
||||
*/
|
||||
package com.phonegap.api;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
/**
|
||||
* The Cordova activity abstract class that is extended by DroidGap.
|
||||
* 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 {
|
||||
}
|
||||
|
@ -179,9 +179,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(ctx.getContext()), "Pic.jpg");
|
||||
} else if (encodingType == PNG) {
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png");
|
||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.png");
|
||||
} else {
|
||||
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
|
||||
ExifHelper exif = new ExifHelper();
|
||||
if (this.encodingType == JPEG) {
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
|
||||
exif.readExifData();
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ public class CameraLauncher extends Plugin {
|
||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||
bitmap = scaleBitmap(bitmap);
|
||||
|
||||
String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
|
||||
String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/resize.jpg";
|
||||
OutputStream os = new FileOutputStream(fileName);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||
os.close();
|
||||
|
@ -196,7 +196,7 @@ 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(ctx.getContext()), "Capture.jpg");
|
||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||
this.imageUri = Uri.fromFile(photo);
|
||||
|
||||
@ -249,7 +249,7 @@ 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(ctx.getContext()) + "/Capture.jpg");
|
||||
exif.readExifData();
|
||||
|
||||
// Read in bitmap of captured image
|
||||
|
@ -19,6 +19,7 @@ package org.apache.cordova;
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
@ -36,7 +37,7 @@ import org.json.JSONObject;
|
||||
public abstract class ContactAccessor {
|
||||
|
||||
protected final String LOG_TAG = "ContactsAccessor";
|
||||
protected Activity mApp;
|
||||
protected Context mApp;
|
||||
protected WebView mView;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +43,7 @@ import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@ -121,8 +122,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
/**
|
||||
* Create an contact accessor.
|
||||
*/
|
||||
public ContactAccessorSdk5(WebView view, Activity app) {
|
||||
mApp = app;
|
||||
public ContactAccessorSdk5(WebView view, Context context) {
|
||||
mApp = context;
|
||||
mView = view;
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class ContactManager extends Plugin {
|
||||
* older phones.
|
||||
*/
|
||||
if (this.contactAccessor == null) {
|
||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx);
|
||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -37,6 +37,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
@ -47,6 +48,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
@ -159,7 +161,7 @@ import android.widget.LinearLayout;
|
||||
* ...
|
||||
* </plugins>
|
||||
*/
|
||||
public class DroidGap extends CordovaInterface {
|
||||
public class DroidGap extends Activity implements CordovaInterface {
|
||||
public static String TAG = "DroidGap";
|
||||
|
||||
// The webview for our app
|
||||
@ -1171,7 +1173,6 @@ public class DroidGap extends CordovaInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityResultCallback(IPlugin plugin) {
|
||||
this.activityResultCallback = plugin;
|
||||
}
|
||||
@ -1388,4 +1389,23 @@ public class DroidGap extends CordovaInterface {
|
||||
this.postMessage("onOptionsItemSelected", item);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class Notification extends Plugin {
|
||||
*/
|
||||
public void beep(long count) {
|
||||
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 (notification != null) {
|
||||
@ -190,7 +190,7 @@ public class Notification extends Plugin {
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
@ -226,7 +226,7 @@ public class Notification extends Plugin {
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
@ -287,7 +287,7 @@ public class Notification extends Plugin {
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
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() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.spinnerDialog = null;
|
||||
@ -323,7 +323,7 @@ public class Notification extends Plugin {
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.progressDialog = new ProgressDialog(ctx);
|
||||
notification.progressDialog = new ProgressDialog(ctx.getContext());
|
||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
notification.progressDialog.setTitle(title);
|
||||
notification.progressDialog.setMessage(message);
|
||||
|
@ -18,14 +18,27 @@
|
||||
*/
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
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.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.
|
||||
* It is used to isolate plugin development, and remove dependency on entire Cordova library.
|
||||
*/
|
||||
public abstract class CordovaInterface extends Activity {
|
||||
public interface CordovaInterface {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
@ -77,4 +90,47 @@ public abstract class CordovaInterface extends Activity {
|
||||
* @param data The message 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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user