mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-cordova-android into CordovaWebView
This commit is contained in:
commit
d5dd43289b
@ -48,6 +48,7 @@ import android.graphics.Color;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -917,8 +918,33 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.finish();
|
this.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the back key is pressed
|
||||||
|
*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onBackPressed()
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
public void onBackPressed()
|
||||||
|
{
|
||||||
|
Log.d("BackPressed", "in onBackPressed");
|
||||||
|
Log.d("BackPressed", "bound = " + this.bound);
|
||||||
|
//Log.d("BackPressed", "backHistory = " + this.backHistory());
|
||||||
|
// If back key is bound, then send event to JavaScript
|
||||||
|
|
||||||
|
if (!(this.bound || this.backHistory())) {
|
||||||
|
Log.d("BackPressed", "exiting");
|
||||||
|
this.activityState = ACTIVITY_EXITING;
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a key is pressed.
|
* Called when a key is de-pressed. (Key UP)
|
||||||
*
|
*
|
||||||
* @param keyCode
|
* @param keyCode
|
||||||
* @param event
|
* @param event
|
||||||
@ -931,21 +957,19 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
|
|
||||||
// If back key
|
// If back key
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
Log.d("BackButton", "I got an up from KEYCODE_BACK");
|
||||||
|
|
||||||
// If back key is bound, then send event to JavaScript
|
// If back key is bound, then send event to JavaScript
|
||||||
if (this.bound) {
|
if (this.bound) {
|
||||||
|
Log.d("BackButton", "bound is true firing an event to JS");
|
||||||
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
|
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
// If not bound
|
||||||
// If not bound
|
|
||||||
else {
|
|
||||||
|
|
||||||
// Go to previous page in webview if it is possible to go back
|
// Go to previous page in webview if it is possible to go back
|
||||||
if (this.backHistory()) {
|
if (this.backHistory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not, then invoke behavior of super class
|
// If not, then invoke behavior of super class
|
||||||
else {
|
else {
|
||||||
this.activityState = ACTIVITY_EXITING;
|
this.activityState = ACTIVITY_EXITING;
|
||||||
@ -966,6 +990,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d("BackPressed", "returning false");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ public class FileTransfer extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public JSONObject download(String source, String target) throws IOException {
|
public JSONObject download(String source, String target) throws IOException {
|
||||||
try {
|
try {
|
||||||
File file = new File(target);
|
File file = getFileFromPath(target);
|
||||||
|
|
||||||
// create needed directories
|
// create needed directories
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
@ -421,6 +421,14 @@ public class FileTransfer extends Plugin {
|
|||||||
URL url = new URL(source);
|
URL url = new URL(source);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
|
||||||
|
//Add cookie support
|
||||||
|
String cookie = CookieManager.getInstance().getCookie(source);
|
||||||
|
if(cookie != null)
|
||||||
|
{
|
||||||
|
connection.setRequestProperty("cookie", cookie);
|
||||||
|
}
|
||||||
|
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
Log.d(LOG_TAG, "Download file:" + url);
|
Log.d(LOG_TAG, "Download file:" + url);
|
||||||
@ -480,4 +488,17 @@ public class FileTransfer extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a File object from the passed in path
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private File getFileFromPath(String path) {
|
||||||
|
if (path.startsWith("file://")) {
|
||||||
|
return new File(path.substring(7));
|
||||||
|
} else {
|
||||||
|
return new File(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class NetworkManager extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public void setContext(Context ctx) {
|
public void setContext(Context ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
this.sockMan = (ConnectivityManager) ctx.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
|
||||||
@ -98,7 +98,7 @@ public class NetworkManager extends Plugin {
|
|||||||
if (this.receiver == null) {
|
if (this.receiver == null) {
|
||||||
this.receiver = new BroadcastReceiver() {
|
this.receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
|
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -117,13 +117,12 @@ public class NetworkManager extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
PluginResult.Status status = PluginResult.Status.INVALID_ACTION;
|
PluginResult.Status status = PluginResult.Status.INVALID_ACTION;
|
||||||
String result = "Unsupported Operation: " + action;
|
String result = "Unsupported Operation: " + action;
|
||||||
|
|
||||||
if (action.equals("getConnectionInfo")) {
|
if (action.equals("getConnectionInfo")) {
|
||||||
this.connectionCallbackId = callbackId;
|
this.connectionCallbackId = callbackId;
|
||||||
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
||||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
|
||||||
pluginResult.setKeepCallback(true);
|
|
||||||
return pluginResult;
|
return pluginResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,8 +136,7 @@ public class NetworkManager extends Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
// All methods take a while, so always use async
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +180,7 @@ public class NetworkManager extends Plugin {
|
|||||||
// If we are not connected to any network set type to none
|
// If we are not connected to any network set type to none
|
||||||
if (!info.isConnected()) {
|
if (!info.isConnected()) {
|
||||||
type = TYPE_NONE;
|
type = TYPE_NONE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
type = getType(info);
|
type = getType(info);
|
||||||
}
|
}
|
||||||
@ -197,7 +195,6 @@ public class NetworkManager extends Plugin {
|
|||||||
*/
|
*/
|
||||||
private void sendUpdate(String type) {
|
private void sendUpdate(String type) {
|
||||||
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
|
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
|
||||||
result.setKeepCallback(true);
|
|
||||||
this.success(result, this.connectionCallbackId);
|
this.success(result, this.connectionCallbackId);
|
||||||
|
|
||||||
// Send to all plugins
|
// Send to all plugins
|
||||||
@ -212,7 +209,7 @@ public class NetworkManager extends Plugin {
|
|||||||
*/
|
*/
|
||||||
private String getType(NetworkInfo info) {
|
private String getType(NetworkInfo info) {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
String type = info.getTypeName();
|
String type = info.getTypeName();
|
||||||
|
|
||||||
if (type.toLowerCase().equals(WIFI)) {
|
if (type.toLowerCase().equals(WIFI)) {
|
||||||
return TYPE_WIFI;
|
return TYPE_WIFI;
|
||||||
|
Loading…
Reference in New Issue
Block a user