Formating and removal of commented code.

This commit is contained in:
Bryce Curtis 2012-05-14 22:06:33 -05:00
parent c8fafa6bbd
commit 3829df665f
16 changed files with 403 additions and 871 deletions

View File

@ -25,11 +25,6 @@ import org.apache.cordova.api.PluginResult;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//import android.webkit.WebView;
import android.app.Activity;
import android.view.View;
import java.util.HashMap; import java.util.HashMap;
/** /**
@ -59,12 +54,6 @@ public class App extends Plugin {
webView.postMessage("spinner", "stop"); webView.postMessage("spinner", "stop");
} }
}); });
// final CordovaWebView wv = this.webView;
// ((Activity) this.ctx).runOnUiThread(new Runnable() {
// public void run() {
// wv.setVisibility(View.VISIBLE);
// }
// });
} }
else if (action.equals("loadUrl")) { else if (action.equals("loadUrl")) {
this.loadUrl(args.getString(0), args.optJSONObject(1)); this.loadUrl(args.getString(0), args.optJSONObject(1));
@ -168,6 +157,7 @@ public class App extends Plugin {
/** /**
* Cancel loadUrl before it has been loaded (Only works on a CordovaInterface class) * Cancel loadUrl before it has been loaded (Only works on a CordovaInterface class)
*/ */
@Deprecated
public void cancelLoadUrl() { public void cancelLoadUrl() {
this.ctx.cancelLoadUrl(); this.ctx.cancelLoadUrl();
} }

View File

@ -22,16 +22,13 @@ import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import java.util.ArrayList; import java.util.ArrayList;
import org.apache.cordova.api.LOG; //import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin; import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import java.util.HashMap; import java.util.HashMap;
//import java.util.Map.Entry;
/** /**
* This class called by CordovaActivity to play and record audio. * This class called by CordovaActivity to play and record audio.
* The file can be local or over a network using http. * The file can be local or over a network using http.

View File

@ -25,11 +25,8 @@ import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.URLEncoder;
import java.util.LinkedList; import java.util.LinkedList;
import android.util.Log;
/** /**
* This class provides a way for Java to run JavaScript in the web page that has loaded Cordova. * This class provides a way for Java to run JavaScript in the web page that has loaded Cordova.
* The CallbackServer class implements an XHR server and a polling server with a list of JavaScript * The CallbackServer class implements an XHR server and a polling server with a list of JavaScript
@ -55,307 +52,309 @@ import android.util.Log;
* 3. The client repeats #1 in loop. * 3. The client repeats #1 in loop.
*/ */
public class CallbackServer implements Runnable { public class CallbackServer implements Runnable {
private static final String LOG_TAG = "CallbackServer";
/** @SuppressWarnings("unused")
* The list of JavaScript statements to be sent to JavaScript. private static final String LOG_TAG = "CallbackServer";
*/
private LinkedList<String> javascript; /**
* The list of JavaScript statements to be sent to JavaScript.
/** */
* The port to listen on. private LinkedList<String> javascript;
*/
private int port; /**
* The port to listen on.
/** */
* The server thread. private int port;
*/
private Thread serverThread; /**
* The server thread.
/** */
* Indicates the server is running. private Thread serverThread;
*/
private boolean active; /**
* Indicates the server is running.
/** */
* Indicates that the JavaScript statements list is empty private boolean active;
*/
private boolean empty; /**
* Indicates that the JavaScript statements list is empty
/** */
* Indicates that polling should be used instead of XHR. private boolean empty;
*/
private boolean usePolling = true; /**
* Indicates that polling should be used instead of XHR.
/** */
* Security token to prevent other apps from accessing this callback server via XHR private boolean usePolling = true;
*/
private String token; /**
* Security token to prevent other apps from accessing this callback server via XHR
/** */
* Constructor. private String token;
*/
public CallbackServer() { /**
//Log.d(LOG_TAG, "CallbackServer()"); * Constructor.
this.active = false; */
this.empty = true; public CallbackServer() {
this.port = 0; //Log.d(LOG_TAG, "CallbackServer()");
this.javascript = new LinkedList<String>(); this.active = false;
} this.empty = true;
this.port = 0;
/** this.javascript = new LinkedList<String>();
* Init callback server and start XHR if running local app. }
*
* If Cordova app is loaded from file://, then we can use XHR /**
* otherwise we have to use polling due to cross-domain security restrictions. * Init callback server and start XHR if running local app.
* *
* @param url The URL of the Cordova app being loaded * If Cordova app is loaded from file://, then we can use XHR
*/ * otherwise we have to use polling due to cross-domain security restrictions.
public void init(String url) { *
//Log.d(LOG_TAG, "CallbackServer.start("+url+")"); * @param url The URL of the Cordova app being loaded
this.active = false; */
this.empty = true; @SuppressWarnings("deprecation")
this.port = 0; public void init(String url) {
this.javascript = new LinkedList<String>(); //Log.d(LOG_TAG, "CallbackServer.start("+url+")");
this.active = false;
this.empty = true;
this.port = 0;
this.javascript = new LinkedList<String>();
// Determine if XHR or polling is to be used
if ((url != null) && !url.startsWith("file://")) {
this.usePolling = true;
this.stopServer();
}
else if (android.net.Proxy.getDefaultHost() != null) {
this.usePolling = true;
this.stopServer();
}
else {
this.usePolling = false;
this.startServer();
}
}
// Determine if XHR or polling is to be used
if ((url != null) && !url.startsWith("file://")) {
this.usePolling = true;
this.stopServer();
}
else if (android.net.Proxy.getDefaultHost() != null) {
this.usePolling = true;
this.stopServer();
}
else {
this.usePolling = false;
this.startServer();
}
}
/** /**
* Re-init when loading a new HTML page into webview. * Re-init when loading a new HTML page into webview.
* *
* @param url The URL of the Cordova app being loaded * @param url The URL of the Cordova app being loaded
*/ */
public void reinit(String url) { public void reinit(String url) {
this.stopServer(); this.stopServer();
this.init(url); this.init(url);
} }
/**
* Return if polling is being used instead of XHR.
*
* @return
*/
public boolean usePolling() {
return this.usePolling;
}
/**
* Get the port that this server is running on.
*
* @return
*/
public int getPort() {
return this.port;
}
/**
* Get the security token that this server requires when calling getJavascript().
*
* @return
*/
public String getToken() {
return this.token;
}
/**
* Start the server on a new thread.
*/
public void startServer() {
//Log.d(LOG_TAG, "CallbackServer.startServer()");
this.active = false;
// Start server on new thread
this.serverThread = new Thread(this);
this.serverThread.start();
}
/** /**
* Restart the server on a new thread. * Return if polling is being used instead of XHR.
*/ *
public void restartServer() { * @return
*/
// Stop server public boolean usePolling() {
this.stopServer(); return this.usePolling;
}
// Start server again
this.startServer();
}
/** /**
* Start running the server. * Get the port that this server is running on.
* This is called automatically when the server thread is started. *
*/ * @return
public void run() { */
public int getPort() {
// Start server return this.port;
try { }
this.active = true;
String request;
ServerSocket waitSocket = new ServerSocket(0);
this.port = waitSocket.getLocalPort();
//Log.d(LOG_TAG, "CallbackServer -- using port " +this.port);
this.token = java.util.UUID.randomUUID().toString();
//Log.d(LOG_TAG, "CallbackServer -- using token "+this.token);
while (this.active) { /**
//Log.d(LOG_TAG, "CallbackServer: Waiting for data on socket"); * Get the security token that this server requires when calling getJavascript().
Socket connection = waitSocket.accept(); *
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()),40); * @return
DataOutputStream output = new DataOutputStream(connection.getOutputStream()); */
request = xhrReader.readLine(); public String getToken() {
String response = ""; return this.token;
//Log.d(LOG_TAG, "CallbackServerRequest="+request); }
if (this.active && (request != null)) {
if (request.contains("GET")) {
// Get requested file
String[] requestParts = request.split(" ");
// Must have security token
if ((requestParts.length == 3) && (requestParts[1].substring(1).equals(this.token))) {
//Log.d(LOG_TAG, "CallbackServer -- Processing GET request");
// Wait until there is some data to send, or send empty data every 10 sec /**
// to prevent XHR timeout on the client * Start the server on a new thread.
synchronized (this) { */
while (this.empty) { public void startServer() {
try { //Log.d(LOG_TAG, "CallbackServer.startServer()");
this.wait(10000); // prevent timeout from happening this.active = false;
//Log.d(LOG_TAG, "CallbackServer>>> break <<<");
break;
}
catch (Exception e) { }
}
}
// If server is still running // Start server on new thread
if (this.active) { this.serverThread = new Thread(this);
this.serverThread.start();
}
// If no data, then send 404 back to client before it times out /**
if (this.empty) { * Restart the server on a new thread.
//Log.d(LOG_TAG, "CallbackServer -- sending data 0"); */
response = "HTTP/1.1 404 NO DATA\r\n\r\n "; // need to send content otherwise some Android devices fail, so send space public void restartServer() {
}
else {
//Log.d(LOG_TAG, "CallbackServer -- sending item");
response = "HTTP/1.1 200 OK\r\n\r\n";
String js = this.getJavascript();
if (js != null) {
response += encode(js, "UTF-8");
}
}
}
else {
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
}
}
else {
response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
}
}
else {
response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
}
//Log.d(LOG_TAG, "CallbackServer: response="+response);
//Log.d(LOG_TAG, "CallbackServer: closing output");
output.writeBytes(response);
output.flush();
}
output.close();
xhrReader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
this.active = false;
//Log.d(LOG_TAG, "CallbackServer.startServer() - EXIT");
}
/**
* Stop server.
* This stops the thread that the server is running on.
*/
public void stopServer() {
//Log.d(LOG_TAG, "CallbackServer.stopServer()");
if (this.active) {
this.active = false;
// Break out of server wait // Stop server
synchronized (this) { this.stopServer();
this.notify();
} // Start server again
} this.startServer();
} }
/**
* Start running the server.
* This is called automatically when the server thread is started.
*/
public void run() {
// Start server
try {
this.active = true;
String request;
ServerSocket waitSocket = new ServerSocket(0);
this.port = waitSocket.getLocalPort();
//Log.d(LOG_TAG, "CallbackServer -- using port " +this.port);
this.token = java.util.UUID.randomUUID().toString();
//Log.d(LOG_TAG, "CallbackServer -- using token "+this.token);
while (this.active) {
//Log.d(LOG_TAG, "CallbackServer: Waiting for data on socket");
Socket connection = waitSocket.accept();
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()), 40);
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
request = xhrReader.readLine();
String response = "";
//Log.d(LOG_TAG, "CallbackServerRequest="+request);
if (this.active && (request != null)) {
if (request.contains("GET")) {
// Get requested file
String[] requestParts = request.split(" ");
// Must have security token
if ((requestParts.length == 3) && (requestParts[1].substring(1).equals(this.token))) {
//Log.d(LOG_TAG, "CallbackServer -- Processing GET request");
// Wait until there is some data to send, or send empty data every 10 sec
// to prevent XHR timeout on the client
synchronized (this) {
while (this.empty) {
try {
this.wait(10000); // prevent timeout from happening
//Log.d(LOG_TAG, "CallbackServer>>> break <<<");
break;
} catch (Exception e) {
}
}
}
// If server is still running
if (this.active) {
// If no data, then send 404 back to client before it times out
if (this.empty) {
//Log.d(LOG_TAG, "CallbackServer -- sending data 0");
response = "HTTP/1.1 404 NO DATA\r\n\r\n "; // need to send content otherwise some Android devices fail, so send space
}
else {
//Log.d(LOG_TAG, "CallbackServer -- sending item");
response = "HTTP/1.1 200 OK\r\n\r\n";
String js = this.getJavascript();
if (js != null) {
response += encode(js, "UTF-8");
}
}
}
else {
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
}
}
else {
response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
}
}
else {
response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
}
//Log.d(LOG_TAG, "CallbackServer: response="+response);
//Log.d(LOG_TAG, "CallbackServer: closing output");
output.writeBytes(response);
output.flush();
}
output.close();
xhrReader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
this.active = false;
//Log.d(LOG_TAG, "CallbackServer.startServer() - EXIT");
}
/**
* Stop server.
* This stops the thread that the server is running on.
*/
public void stopServer() {
//Log.d(LOG_TAG, "CallbackServer.stopServer()");
if (this.active) {
this.active = false;
// Break out of server wait
synchronized (this) {
this.notify();
}
}
}
/** /**
* Destroy * Destroy
*/ */
public void destroy() { public void destroy() {
this.stopServer(); this.stopServer();
} }
/** /**
* Get the number of JavaScript statements. * Get the number of JavaScript statements.
* *
* @return int * @return int
*/ */
public int getSize() { public int getSize() {
synchronized(this) { synchronized (this) {
int size = this.javascript.size(); int size = this.javascript.size();
return size; return size;
} }
} }
/** /**
* Get the next JavaScript statement and remove from list. * Get the next JavaScript statement and remove from list.
* *
* @return String * @return String
*/ */
public String getJavascript() { public String getJavascript() {
synchronized(this) { synchronized (this) {
if (this.javascript.size() == 0) { if (this.javascript.size() == 0) {
return null; return null;
} }
String statement = this.javascript.remove(0); String statement = this.javascript.remove(0);
if (this.javascript.size() == 0) { if (this.javascript.size() == 0) {
this.empty = true; this.empty = true;
} }
return statement; return statement;
} }
} }
/** /**
* Add a JavaScript statement to the list. * Add a JavaScript statement to the list.
* *
* @param statement * @param statement
*/ */
public void sendJavascript(String statement) { public void sendJavascript(String statement) {
synchronized (this) { synchronized (this) {
this.javascript.add(statement); this.javascript.add(statement);
this.empty = false; this.empty = false;
this.notify(); this.notify();
} }
} }
/* The Following code has been modified from original implementation of URLEncoder */ /* The Following code has been modified from original implementation of URLEncoder */
/* start */ /* start */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
@ -371,7 +370,7 @@ public class CallbackServer implements Runnable {
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
static final String digits = "0123456789ABCDEF"; static final String digits = "0123456789ABCDEF";
/** /**
* This will encode the return value to JavaScript. We revert the encoding for * This will encode the return value to JavaScript. We revert the encoding for
@ -382,13 +381,13 @@ public class CallbackServer implements Runnable {
* @param enc encoding type * @param enc encoding type
* @return encoded string * @return encoded string
*/ */
public static String encode(String s, String enc) throws UnsupportedEncodingException { public static String encode(String s, String enc) throws UnsupportedEncodingException {
if (s == null || enc == null) { if (s == null || enc == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
// check for UnsupportedEncodingException // check for UnsupportedEncodingException
"".getBytes(enc); "".getBytes(enc);
// Guess a bit bigger for encoded form // Guess a bit bigger for encoded form
StringBuilder buf = new StringBuilder(s.length() + 16); StringBuilder buf = new StringBuilder(s.length() + 16);
int start = -1; int start = -1;
@ -426,6 +425,6 @@ public class CallbackServer implements Runnable {
buf.append(digits.charAt(bytes[j] & 0xf)); buf.append(digits.charAt(bytes[j] & 0xf));
} }
} }
/* end */ /* end */
} }

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.LOG; import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin; import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult;
@ -32,7 +31,6 @@ import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
//import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;

View File

@ -20,4 +20,9 @@
package org.apache.cordova; package org.apache.cordova;
public class CordovaException extends Exception { public class CordovaException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1373339564758328799L;
} }

View File

@ -22,7 +22,6 @@ package org.apache.cordova;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.Stack; import java.util.Stack;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -47,9 +46,6 @@ public class CordovaWebView extends WebView {
public static final String TAG = "CordovaWebView"; public static final String TAG = "CordovaWebView";
/** The authorization tokens. */
//private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
/** The whitelist **/ /** The whitelist **/
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>(); private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>(); private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
@ -59,6 +55,7 @@ public class CordovaWebView extends WebView {
/** Actvities and other important classes **/ /** Actvities and other important classes **/
private CordovaInterface mCtx; private CordovaInterface mCtx;
CordovaWebViewClient viewClient; CordovaWebViewClient viewClient;
@SuppressWarnings("unused")
private CordovaChromeClient chromeClient; private CordovaChromeClient chromeClient;
//This is for the polyfil history //This is for the polyfil history
@ -71,12 +68,6 @@ public class CordovaWebView extends WebView {
// Flag to track that a loadUrl timeout occurred // Flag to track that a loadUrl timeout occurred
int loadUrlTimeout = 0; int loadUrlTimeout = 0;
// LoadUrl timeout value in msec (default of 20 sec)
//protected int loadUrlTimeoutValue = 20000;
//preferences read from cordova.xml
//protected PreferenceSet preferences;
/** /**
* Constructor. * Constructor.
* *
@ -85,7 +76,6 @@ public class CordovaWebView extends WebView {
public CordovaWebView(CordovaInterface context) { public CordovaWebView(CordovaInterface context) {
super(context.getActivity()); super(context.getActivity());
this.mCtx = context; this.mCtx = context;
//preferences = new PreferenceSet();
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -99,7 +89,6 @@ public class CordovaWebView extends WebView {
public CordovaWebView(CordovaInterface context, AttributeSet attrs) { public CordovaWebView(CordovaInterface context, AttributeSet attrs) {
super(context.getActivity(), attrs); super(context.getActivity(), attrs);
this.mCtx = context; this.mCtx = context;
//preferences = new PreferenceSet();
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -114,7 +103,6 @@ public class CordovaWebView extends WebView {
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle) { public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle) {
super(context.getActivity(), attrs, defStyle); super(context.getActivity(), attrs, defStyle);
this.mCtx = context; this.mCtx = context;
//preferences = new PreferenceSet();
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -130,7 +118,6 @@ public class CordovaWebView extends WebView {
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
super(context.getActivity(), attrs, defStyle, privateBrowsing); super(context.getActivity(), attrs, defStyle, privateBrowsing);
this.mCtx = context; this.mCtx = context;
//preferences = new PreferenceSet();
this.loadConfiguration(); this.loadConfiguration();
this.setup(); this.setup();
} }
@ -138,6 +125,7 @@ public class CordovaWebView extends WebView {
/** /**
* Initialize webview. * Initialize webview.
*/ */
@SuppressWarnings("deprecation")
private void setup() { private void setup() {
this.setInitialScale(0); this.setInitialScale(0);
@ -158,10 +146,6 @@ public class CordovaWebView extends WebView {
String databasePath = this.mCtx.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); String databasePath = this.mCtx.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath); settings.setDatabasePath(databasePath);
//Setup the WebChromeClient and WebViewClient
//setWebViewClient(new CordovaWebViewClient(mCtx, this));
//setWebChromeClient(new CordovaChromeClient(mCtx, this));
// Enable DOM storage // Enable DOM storage
settings.setDomStorageEnabled(true); settings.setDomStorageEnabled(true);
@ -588,16 +572,8 @@ public class CordovaWebView extends WebView {
String name = xml.getAttributeValue(null, "name"); String name = xml.getAttributeValue(null, "name");
String value = xml.getAttributeValue(null, "value"); String value = xml.getAttributeValue(null, "value");
// TODO @bc Is preferences needed? Just use Intent.putExtra?
//String readonlyString = xml.getAttributeValue(null, "readonly");
//boolean readonly = (readonlyString != null &&
// readonlyString.equals("true"));
LOG.i("CordovaLog", "Found preference for %s=%s", name, value); LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
//preferences.add(new PreferenceNode(name, value, readonly));
// Save preferences in Intent // Save preferences in Intent
this.mCtx.getActivity().getIntent().putExtra(name, value); this.mCtx.getActivity().getIntent().putExtra(name, value);
} }
@ -612,7 +588,6 @@ public class CordovaWebView extends WebView {
} }
// Init preferences // Init preferences
//this.useBrowserHistory = preferences.prefMatches("useBrowserHistory", "true");
if ("true".equals(this.getProperty("useBrowserHistory", "true"))) { if ("true".equals(this.getProperty("useBrowserHistory", "true"))) {
this.useBrowserHistory = true; this.useBrowserHistory = true;
} }

View File

@ -25,8 +25,6 @@ import org.apache.cordova.api.LOG;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//import android.app.Activity;
//import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -34,7 +32,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.net.http.SslError; import android.net.http.SslError;
//import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.HttpAuthHandler; import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler; import android.webkit.SslErrorHandler;
@ -274,7 +271,6 @@ public class CordovaWebViewClient extends WebViewClient {
Thread.sleep(2000); Thread.sleep(2000);
ctx.getActivity().runOnUiThread(new Runnable() { ctx.getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
//appView.setVisibility(View.VISIBLE);
appView.postMessage("spinner", "stop"); appView.postMessage("spinner", "stop");
} }
}); });
@ -290,7 +286,6 @@ public class CordovaWebViewClient extends WebViewClient {
if (this.appView.callbackServer != null) { if (this.appView.callbackServer != null) {
this.appView.callbackServer.destroy(); this.appView.callbackServer.destroy();
} }
//this.ctx.endActivity();
this.ctx.getActivity().finish(); this.ctx.getActivity().finish();
} }
} }
@ -311,11 +306,7 @@ public class CordovaWebViewClient extends WebViewClient {
// Clear timeout flag // Clear timeout flag
this.appView.loadUrlTimeout++; this.appView.loadUrlTimeout++;
// Stop "app loading" spinner if showing
//this.ctx.spinnerStop();
// Handle error // Handle error
//this.ctx.onReceivedError(errorCode, description, failingUrl);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
try { try {
data.put("errorCode", errorCode); data.put("errorCode", errorCode);

View File

@ -31,107 +31,108 @@ import android.os.StatFs;
* It is used by the FileUtils class. * It is used by the FileUtils class.
*/ */
public class DirectoryManager { public class DirectoryManager {
private static final String LOG_TAG = "DirectoryManager";
/** @SuppressWarnings("unused")
* Determine if a file or directory exists. private static final String LOG_TAG = "DirectoryManager";
*
* @param name The name of the file to check. /**
* @return T=exists, F=not found * Determine if a file or directory exists.
*/ *
protected static boolean testFileExists(String name) { * @param name The name of the file to check.
boolean status; * @return T=exists, F=not found
*/
// If SD card exists protected static boolean testFileExists(String name) {
if ((testSaveLocationExists()) && (!name.equals(""))) { boolean status;
File path = Environment.getExternalStorageDirectory();
// If SD card exists
if ((testSaveLocationExists()) && (!name.equals(""))) {
File path = Environment.getExternalStorageDirectory();
File newPath = constructFilePaths(path.toString(), name); File newPath = constructFilePaths(path.toString(), name);
status = newPath.exists(); status = newPath.exists();
} }
// If no SD card // If no SD card
else{ else {
status = false; status = false;
} }
return status; return status;
} }
/** /**
* Get the free disk space * Get the free disk space
* *
* @return Size in KB or -1 if not available * @return Size in KB or -1 if not available
*/ */
protected static long getFreeDiskSpace(boolean checkInternal) { protected static long getFreeDiskSpace(boolean checkInternal) {
String status = Environment.getExternalStorageState(); String status = Environment.getExternalStorageState();
long freeSpace = 0; long freeSpace = 0;
// If SD card exists // If SD card exists
if (status.equals(Environment.MEDIA_MOUNTED)) { if (status.equals(Environment.MEDIA_MOUNTED)) {
freeSpace = freeSpaceCalculation(Environment.getExternalStorageDirectory().getPath()); freeSpace = freeSpaceCalculation(Environment.getExternalStorageDirectory().getPath());
} }
else if (checkInternal) { else if (checkInternal) {
freeSpace = freeSpaceCalculation("/"); freeSpace = freeSpaceCalculation("/");
} }
// If no SD card and we haven't been asked to check the internal directory then return -1 // If no SD card and we haven't been asked to check the internal directory then return -1
else { else {
return -1; return -1;
} }
return freeSpace; return freeSpace;
} }
/** /**
* Given a path return the number of free KB * Given a path return the number of free KB
* *
* @param path to the file system * @param path to the file system
* @return free space in KB * @return free space in KB
*/ */
private static long freeSpaceCalculation(String path) { private static long freeSpaceCalculation(String path) {
StatFs stat = new StatFs(path); StatFs stat = new StatFs(path);
long blockSize = stat.getBlockSize(); long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks(); long availableBlocks = stat.getAvailableBlocks();
return availableBlocks*blockSize/1024; return availableBlocks * blockSize / 1024;
} }
/** /**
* Determine if SD card exists. * Determine if SD card exists.
* *
* @return T=exists, F=not found * @return T=exists, F=not found
*/ */
protected static boolean testSaveLocationExists() { protected static boolean testSaveLocationExists() {
String sDCardStatus = Environment.getExternalStorageState(); String sDCardStatus = Environment.getExternalStorageState();
boolean status; boolean status;
// If SD card is mounted // If SD card is mounted
if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) { if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
status = true; status = true;
} }
// If no SD card // If no SD card
else { else {
status = false; status = false;
} }
return status; return status;
} }
/** /**
* Create a new file object from two file paths. * Create a new file object from two file paths.
* *
* @param file1 Base file path * @param file1 Base file path
* @param file2 Remaining file path * @param file2 Remaining file path
* @return File object * @return File object
*/ */
private static File constructFilePaths (String file1, String file2) { private static File constructFilePaths(String file1, String file2) {
File newPath; File newPath;
if (file2.startsWith(file1)) { if (file2.startsWith(file1)) {
newPath = new File(file2); newPath = new File(file2);
} }
else { else {
newPath = new File(file1+"/"+file2); newPath = new File(file1 + "/" + file2);
} }
return newPath; return newPath;
} }
/** /**
* Determine if we can use the SD Card to store the temporary file. If not then use * Determine if we can use the SD Card to store the temporary file. If not then use
* the internal cache directory. * the internal cache directory.
@ -140,12 +141,12 @@ public class DirectoryManager {
*/ */
protected static String getTempDirectoryPath(Context ctx) { protected static String getTempDirectoryPath(Context ctx) {
File cache = null; File cache = null;
// SD Card Mounted // SD Card Mounted
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + ctx.getPackageName() + "/cache/"); "/Android/data/" + ctx.getPackageName() + "/cache/");
} }
// Use internal storage // Use internal storage
else { else {
cache = ctx.getCacheDir(); cache = ctx.getCacheDir();

View File

@ -18,24 +18,13 @@
*/ */
package org.apache.cordova; package org.apache.cordova;
//import java.io.IOException;
//import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
//import java.util.Hashtable;
//import java.util.Iterator;
//import java.util.Stack;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//import org.apache.cordova.PreferenceNode;
//import org.apache.cordova.PreferenceSet;
import org.apache.cordova.api.IPlugin; import org.apache.cordova.api.IPlugin;
import org.apache.cordova.api.LOG; import org.apache.cordova.api.LOG;
import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.CordovaInterface;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
//import org.apache.cordova.api.PluginManager;
//import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -45,10 +34,8 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
//import android.content.res.XmlResourceParser;
import android.graphics.Color; import android.graphics.Color;
import android.media.AudioManager; import android.media.AudioManager;
//import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.Display; import android.view.Display;
@ -59,10 +46,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
//import android.webkit.WebChromeClient;
//import android.webkit.WebSettings;
//import android.webkit.WebSettings.LayoutAlgorithm;
//import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -161,11 +144,7 @@ public class DroidGap extends Activity implements CordovaInterface {
// The initial URL for our app // The initial URL for our app
// ie http://server/path/index.html#abc?query // ie http://server/path/index.html#abc?query
private String url = null; //private String url = null;
//private Stack<String> urls = new Stack<String>();
// Url was specified from extras (activity was started programmatically)
//private String initUrl = null;
private static int ACTIVITY_STARTING = 0; private static int ACTIVITY_STARTING = 0;
private static int ACTIVITY_RUNNING = 1; private static int ACTIVITY_RUNNING = 1;
@ -181,9 +160,6 @@ public class DroidGap extends Activity implements CordovaInterface {
protected IPlugin activityResultCallback = null; protected IPlugin activityResultCallback = null;
protected boolean activityResultKeepRunning; protected boolean activityResultKeepRunning;
// Flag indicates that a loadUrl timeout occurred
//int loadUrlTimeout = 0;
// Default background color for activity // Default background color for activity
// (this is not the color for the webview, which is set in HTML) // (this is not the color for the webview, which is set in HTML)
private int backgroundColor = Color.BLACK; private int backgroundColor = Color.BLACK;
@ -197,20 +173,11 @@ public class DroidGap extends Activity implements CordovaInterface {
protected int splashscreen = 0; protected int splashscreen = 0;
protected int splashscreenTime = 0; protected int splashscreenTime = 0;
// LoadUrl timeout value in msec (default of 20 sec)
//protected int loadUrlTimeoutValue = 20000;
// Keep app running when pause is received. (default = true) // Keep app running when pause is received. (default = true)
// If true, then the JavaScript and native code continue to run in the background // If true, then the JavaScript and native code continue to run in the background
// when another application (activity) is started. // when another application (activity) is started.
protected boolean keepRunning = true; protected boolean keepRunning = true;
// Store the useBrowserHistory preference until we actually need it.
//private boolean useBrowserHistory = false;
// preferences read from cordova.xml
//protected PreferenceSet preferences;
/** /**
* Sets the authentication token. * Sets the authentication token.
* *
@ -298,14 +265,6 @@ public class DroidGap extends Activity implements CordovaInterface {
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
// If url was passed in to intent, then init webview, which will load the url
// Bundle bundle = this.getIntent().getExtras();
// if (bundle != null) {
// String url = bundle.getString("url");
// if (url != null) {
// this.initUrl = url;
// }
// }
// Setup the hardware volume controls to handle volume control // Setup the hardware volume controls to handle volume control
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);
} }
@ -346,15 +305,6 @@ public class DroidGap extends Activity implements CordovaInterface {
webViewClient.setWebView(this.appView); webViewClient.setWebView(this.appView);
webChromeClient.setWebView(this.appView); webChromeClient.setWebView(this.appView);
// Load Cordova configuration:
// white list of allowed URLs
// debug setting
//this.loadConfiguration();
//Now we can check the preference
//this.appView.useBrowserHistory = preferences.prefMatches("useBrowserHistory", "true");
//
this.appView.setLayoutParams(new LinearLayout.LayoutParams( this.appView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
@ -369,30 +319,6 @@ public class DroidGap extends Activity implements CordovaInterface {
this.cancelLoadUrl = false; this.cancelLoadUrl = false;
} }
/**
* Look at activity parameters and process them.
* This must be called from the main UI thread.
*/
//private void handleActivityParameters() {
// If backgroundColor
//this.backgroundColor = this.getIntegerProperty("backgroundColor", Color.BLACK);
//LOG.e(TAG, "Setting background color=" + this.backgroundColor);
//this.root.setBackgroundColor(this.backgroundColor);
// If spashscreen
//this.splashscreen = this.getIntegerProperty("splashscreen", 0);
// If loadUrlTimeoutValue
//int timeout = this.getIntegerProperty("loadUrlTimeoutValue", 0);
//if (timeout > 0) {
// this.loadUrlTimeoutValue = timeout;
//}
// If keepRunning
//this.keepRunning = this.getBooleanProperty("keepRunning", true);
//}
/** /**
* Load the url into the webview. * Load the url into the webview.
* *
@ -405,9 +331,6 @@ public class DroidGap extends Activity implements CordovaInterface {
this.init(); this.init();
} }
// Handle activity parameters
//this.handleActivityParameters();
// If backgroundColor // If backgroundColor
this.backgroundColor = this.getIntegerProperty("backgroundColor", Color.BLACK); this.backgroundColor = this.getIntegerProperty("backgroundColor", Color.BLACK);
LOG.e(TAG, "Setting background color=" + this.backgroundColor); LOG.e(TAG, "Setting background color=" + this.backgroundColor);
@ -420,15 +343,6 @@ public class DroidGap extends Activity implements CordovaInterface {
this.loadSpinner(); this.loadSpinner();
this.appView.loadUrl(url); this.appView.loadUrl(url);
// // If first page of app, then set URL to load to be the one passed in
// if (this.initUrl == null || (this.urls.size() > 0)) {
// this.loadUrlIntoView(url);
// }
// // Otherwise use the URL specified in the activity's extras bundle
// else {
// this.loadUrlIntoView(this.initUrl);
// }
} }
/* /*
@ -464,71 +378,6 @@ public class DroidGap extends Activity implements CordovaInterface {
} }
} }
/**
* Load the url into the webview.
*
* @param url
*/
// private void loadUrlIntoView(final String url) {
// if (!url.startsWith("javascript:")) {
// LOG.d(TAG, "DroidGap.loadUrl(%s)", url);
// }
//
// if (!url.startsWith("javascript:")) {
// LOG.d(TAG, "DroidGap: url=%s baseUrl=%s", url, baseUrl);
// }
//
// // Load URL on UI thread
// final DroidGap me = this;
//
//// final Runnable loadError = new Runnable() {
//// public void run() {
//// me.appView.stopLoading();
//// LOG.e(TAG, "DroidGap: TIMEOUT ERROR! - calling webViewClient");
//// appView.viewClient.onReceivedError(me.appView, -6, "The connection to the server was unsuccessful.", url);
//// }
//// };
//
// this.runOnUiThread(new Runnable() {
// public void run() {
//
// // Init web view if not already done
// if (me.appView == null) {
// me.init();
// }
//
// // Handle activity parameters (TODO: Somehow abstract this)
// me.handleActivityParameters();
//
// // Then load the spinner
// me.loadSpinner();
//
//// // Create a timeout timer for loadUrl
//// final int currentLoadUrlTimeout = me.loadUrlTimeout;
//// Runnable runnable = new Runnable() {
//// public void run() {
//// try {
//// synchronized (this) {
//// wait(me.loadUrlTimeoutValue);
//// }
//// } catch (InterruptedException e) {
//// e.printStackTrace();
//// }
////
//// // If timeout, then stop loading and handle error
//// if (me.loadUrlTimeout == currentLoadUrlTimeout) {
//// me.runOnUiThread(loadError);
////
//// }
//// }
//// };
//// Thread thread = new Thread(runnable);
//// thread.start();
// me.appView.loadUrl(url);
// }
// });
// }
/** /**
* Load the url into the webview after waiting for period of time. * Load the url into the webview after waiting for period of time.
* This is used to display the splashscreen for certain amount of time. * This is used to display the splashscreen for certain amount of time.
@ -545,45 +394,8 @@ public class DroidGap extends Activity implements CordovaInterface {
this.splashscreenTime = time; this.splashscreenTime = time;
this.appView.loadUrl(url, time); this.appView.loadUrl(url, time);
// // If first page of app, then set URL to load to be the one passed in
// if (this.initUrl == null || (this.urls.size() > 0)) {
// this.loadUrlIntoView(url, time);
// }
// // Otherwise use the URL specified in the activity's extras bundle
// else {
// this.loadUrlIntoView(this.initUrl);
// }
} }
/**
* Load the url into the webview after waiting for period of time.
* This is used to display the splashscreen for certain amount of time.
*
* @param url
* @param time The number of ms to wait before showing webview
*/
// private void loadUrlIntoView(final String url, final int time) {
//
// // Clear cancel flag
// this.cancelLoadUrl = false;
//
// // If not first page of app, then load immediately
// if (this.urls.size() > 0) {
// this.loadUrlIntoView(url);
// }
//
// if (!url.startsWith("javascript:")) {
// LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time);
// }
//
// this.handleActivityParameters();
// if (this.splashscreen != 0) {
// this.showSplashScreen(time);
// }
// this.loadUrlIntoView(url);
// }
/** /**
* Cancel loadUrl before it has been loaded. * Cancel loadUrl before it has been loaded.
*/ */
@ -607,13 +419,6 @@ public class DroidGap extends Activity implements CordovaInterface {
*/ */
public void clearHistory() { public void clearHistory() {
this.appView.clearHistory(); this.appView.clearHistory();
// this.urls.clear();
// this.appView.clearHistory();
//
// // Leave current url on history stack
// if (this.url != null) {
// this.urls.push(this.url);
// }
} }
/** /**
@ -939,7 +744,6 @@ public class DroidGap extends Activity implements CordovaInterface {
* End this activity by calling finish for activity * End this activity by calling finish for activity
*/ */
public void endActivity() { public void endActivity() {
//this.activityState = ACTIVITY_EXITING;
this.finish(); this.finish();
} }
@ -998,23 +802,6 @@ public class DroidGap extends Activity implements CordovaInterface {
return false; return false;
} }
/**
* Any calls to Activity.startActivityForResult must use method below, so
* the result can be routed to them correctly.
*
* This is done to eliminate the need to modify DroidGap.java to receive activity results.
*
* @param intent The intent to start
* @param requestCode Identifies who to send the result to
*
* @throws RuntimeException
*/
//@Override
//public void startActivityForResult(Intent intent, int requestCode) throws RuntimeException {
// LOG.d(TAG, "DroidGap.startActivityForResult(intent,%d)", requestCode);
// super.startActivityForResult(intent, requestCode);
//}
/** /**
* Launch an activity for which you would like a result when it finished. When this activity exits, * Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method will be called. * your onActivityResult() method will be called.
@ -1129,61 +916,6 @@ public class DroidGap extends Activity implements CordovaInterface {
}); });
} }
/**
* Load Cordova configuration from res/xml/cordova.xml.
* Approved list of URLs that can be loaded into DroidGap
* <access origin="http://server regexp" subdomains="true" />
* Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR)
* <log level="DEBUG" />
*/
// private void loadConfiguration() {
// int id = getResources().getIdentifier("cordova", "xml", getPackageName());
// if (id == 0) {
// LOG.i("CordovaLog", "cordova.xml missing. Ignoring...");
// return;
// }
// XmlResourceParser xml = getResources().getXml(id);
// int eventType = -1;
// while (eventType != XmlResourceParser.END_DOCUMENT) {
// if (eventType == XmlResourceParser.START_TAG) {
// String strNode = xml.getName();
// if (strNode.equals("access")) {
// String origin = xml.getAttributeValue(null, "origin");
// String subdomains = xml.getAttributeValue(null, "subdomains");
// if (origin != null) {
// appView.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
// }
// }
// else if (strNode.equals("log")) {
// String level = xml.getAttributeValue(null, "level");
// LOG.i("CordovaLog", "Found log level %s", level);
// if (level != null) {
// LOG.setLogLevel(level);
// }
// }
// else if (strNode.equals("preference")) {
// String name = xml.getAttributeValue(null, "name");
// String value = xml.getAttributeValue(null, "value");
// String readonlyString = xml.getAttributeValue(null, "readonly");
//
// boolean readonly = (readonlyString != null &&
// readonlyString.equals("true"));
//
// LOG.i("CordovaLog", "Found preference for %s", name);
//
// preferences.add(new PreferenceNode(name, value, readonly));
// }
// }
// try {
// eventType = xml.next();
// } catch (XmlPullParserException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
/** /**
* Determine if URL is in approved list of URLs to load. * Determine if URL is in approved list of URLs to load.
* *

View File

@ -217,6 +217,7 @@ public class FileTransfer extends Plugin {
* @param params key:value pairs of user-defined parameters * @param params key:value pairs of user-defined parameters
* @return FileUploadResult containing result of upload request * @return FileUploadResult containing result of upload request
*/ */
@SuppressWarnings("deprecation")
public FileUploadResult upload(String file, String server, final String fileKey, final String fileName, public FileUploadResult upload(String file, String server, final String fileKey, final String fileName,
final String mimeType, JSONObject params, boolean trustEveryone, boolean chunkedMode) throws IOException, SSLException { final String mimeType, JSONObject params, boolean trustEveryone, boolean chunkedMode) throws IOException, SSLException {
// Create return object // Create return object

View File

@ -52,6 +52,7 @@ import android.webkit.MimeTypeMap;
* Only files on the SD card can be accessed. * Only files on the SD card can be accessed.
*/ */
public class FileUtils extends Plugin { public class FileUtils extends Plugin {
@SuppressWarnings("unused")
private static final String LOG_TAG = "FileUtils"; private static final String LOG_TAG = "FileUtils";
private static final String _DATA = "_data"; // The column name where the file path is stored private static final String _DATA = "_data"; // The column name where the file path is stored
@ -222,7 +223,7 @@ public class FileUtils extends Plugin {
* @param filePath the path to check * @param filePath the path to check
*/ */
private void notifyDelete(String filePath) { private void notifyDelete(String filePath) {
int result = this.ctx.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, this.ctx.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
MediaStore.Images.Media.DATA + " = ?", MediaStore.Images.Media.DATA + " = ?",
new String[] { filePath }); new String[] { filePath });
} }
@ -237,6 +238,7 @@ public class FileUtils extends Plugin {
* @throws IOException if the user can't read the file * @throws IOException if the user can't read the file
* @throws JSONException * @throws JSONException
*/ */
@SuppressWarnings("deprecation")
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
String decoded = URLDecoder.decode(url, "UTF-8"); String decoded = URLDecoder.decode(url, "UTF-8");
@ -1039,6 +1041,7 @@ public class FileUtils extends Plugin {
* @param ctx) the current applicaiton context * @param ctx) the current applicaiton context
* @return the full path to the file * @return the full path to the file
*/ */
@SuppressWarnings("deprecation")
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) { protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) {
String[] proj = { _DATA }; String[] proj = { _DATA };
Cursor cursor = ctx.getActivity().managedQuery(contentUri, proj, null, null, null); Cursor cursor = ctx.getActivity().managedQuery(contentUri, proj, null, null, null);

View File

@ -70,7 +70,7 @@ public class HttpHandler {
* writes a HTTP entity to the specified filename and location on disk * writes a HTTP entity to the specified filename and location on disk
*/ */
{ {
int i = 0; //int i = 0;
String FilePath = "/sdcard/" + file; String FilePath = "/sdcard/" + file;
InputStream in = entity.getContent(); InputStream in = entity.getContent();
byte buff[] = new byte[1024]; byte buff[] = new byte[1024];
@ -81,7 +81,7 @@ public class HttpHandler {
if (numread <= 0) if (numread <= 0)
break; break;
out.write(buff, 0, numread); out.write(buff, 0, numread);
i++; //i++;
} while (true); } while (true);
out.flush(); out.flush();
out.close(); out.close();

View File

@ -18,22 +18,8 @@
*/ */
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;
//import android.view.Menu;
//import android.view.MenuItem;
/** /**
* The Cordova activity abstract class that is extended by DroidGap. * The Cordova activity abstract class that is extended by DroidGap.
@ -72,17 +58,6 @@ public interface CordovaInterface {
*/ */
public abstract boolean isBackButtonBound(); public abstract boolean isBackButtonBound();
/*
* Hook in DroidGap for menu plugins
* (This is in the Android SDK, do we need this on the Interface?)
*/
//public abstract boolean onCreateOptionsMenu(Menu menu);
//public abstract boolean onPrepareOptionsMenu(Menu menu);
//public abstract boolean onOptionsItemSelected(MenuItem item);
/** /**
* Get the Android activity. * Get the Android activity.
* *
@ -90,114 +65,9 @@ public interface CordovaInterface {
*/ */
public abstract Activity getActivity(); public abstract Activity getActivity();
/**
* @deprecated
* Add services to res/xml/plugins.xml instead.
*
* Add a class that implements a service.
*
* @param serviceType
* @param className
*/
// @Deprecated
// abstract public void addService(String serviceType, String className);
/**
* @deprecated
* Send JavaScript statement back to JavaScript.
*
* @param message
*/
// @Deprecated
// abstract public void sendJavascript(String statement);
/**
* @deprecated
* Launch an activity for which you would not like a result when it finished.
*
* @param intent The intent to start
*/
// @Deprecated
// abstract public void startActivity(Intent intent);
/**
* @deprecated
* Load the specified URL in the Cordova webview.
*
* @param url The URL to load.
*/
// @Deprecated
// abstract public void loadUrl(String url);
/**
* @deprecated
* Send a message to all plugins.
*
* @param id The message id
* @param data The message data
*/
// @Deprecated
// abstract public void postMessage(String id, Object data);
// @Deprecated
// public abstract Resources getResources();
// @Deprecated
// public abstract String getPackageName();
// @Deprecated
// public abstract Object getSystemService(String service);
// @Deprecated
// public abstract Context getContext();
// @Deprecated
// public abstract Context getBaseContext();
// @Deprecated
// public abstract Intent registerReceiver(BroadcastReceiver receiver,
// IntentFilter intentFilter);
// @Deprecated
// public abstract ContentResolver getContentResolver();
// @Deprecated
// public abstract void unregisterReceiver(BroadcastReceiver receiver);
// @Deprecated
// public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
// String[] selectionArgs, String sortOrder);
// @Deprecated
// public abstract void runOnUiThread(Runnable runnable);
// @Deprecated
// public abstract AssetManager getAssets();
// @Deprecated
// public abstract void clearCache();
// @Deprecated
// public abstract void clearHistory();
// @Deprecated
// public abstract boolean backHistory();
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
@Deprecated @Deprecated
public abstract void cancelLoadUrl(); public abstract void cancelLoadUrl();
// @Deprecated
// public abstract void showWebPage(String url, boolean openExternal,
// boolean clearHistory, HashMap<String, Object> params);
// @Deprecated
// public abstract Context getApplicationContext();
// @Deprecated
// public abstract boolean isUrlWhiteListed(String source);
/** /**
* Called when a message is sent to plugin. * Called when a message is sent to plugin.
* *
@ -206,14 +76,4 @@ public interface CordovaInterface {
*/ */
public void onMessage(String id, Object data); public void onMessage(String id, Object data);
/**
* Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
* The errorCode parameter corresponds to one of the ERROR_* constants.
*
* @param errorCode The error code corresponding to an ERROR_* value.
* @param description A String describing the error.
* @param failingUrl The url that failed to load.
*/
//public void onReceivedError(final int errorCode, final String description, final String failingUrl);
} }

View File

@ -24,8 +24,6 @@ import org.json.JSONArray;
//import android.content.Context; //import android.content.Context;
import android.content.Intent; import android.content.Intent;
//import android.webkit.WebView;
/** /**
* Plugin interface must be implemented by any plugin classes. * Plugin interface must be implemented by any plugin classes.
* *

View File

@ -21,12 +21,8 @@ package org.apache.cordova.api;
import org.apache.cordova.CordovaWebView; import org.apache.cordova.CordovaWebView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
//import android.content.Context;
import android.content.Intent; import android.content.Intent;
//import android.webkit.WebView;
/** /**
* Plugin interface must be implemented by any plugin classes. * Plugin interface must be implemented by any plugin classes.
* *
@ -36,7 +32,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
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.

View File

@ -65,20 +65,6 @@ public class PluginManager {
this.firstRun = true; this.firstRun = true;
} }
// Called by com.phonegap.api.PluginManager only
// public PluginManager(WebView mApp, CordovaInterface mCtx) throws Exception {
// this.ctx = mCtx; //mCtx.getContext();
// if (CordovaWebView.class.isInstance(mApp))
// {
// this.app = (CordovaWebView) mApp;
// }
// else
// {
// //Throw an exception here
// throw new Exception();
// }
// }
/** /**
* Init when loading a new HTML page into webview. * Init when loading a new HTML page into webview.
*/ */