You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2014/01/22 20:38:51 UTC
[40/50] [abbrv] git commit: CB-5504: Moving code to the App plugin
inside Cordova,
the place where the grey area beween plugin and platform exists
CB-5504: Moving code to the App plugin inside Cordova, the place where the grey area beween plugin and platform exists
Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/eec8045f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/eec8045f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/eec8045f
Branch: refs/heads/master
Commit: eec8045f83735acae19834797aa2a8e41b9f8280
Parents: 474fb53
Author: Joe Bowser <bo...@apache.org>
Authored: Mon Dec 9 14:03:22 2013 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Jan 22 11:37:22 2014 -0800
----------------------------------------------------------------------
framework/src/org/apache/cordova/App.java | 62 ++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/eec8045f/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index 64af74e..965748d 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -27,6 +27,12 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.telephony.TelephonyManager;
+
import java.util.HashMap;
/**
@@ -34,6 +40,22 @@ import java.util.HashMap;
*/
public class App extends CordovaPlugin {
+ protected static final String TAG = "CordovaApp";
+ private BroadcastReceiver telephonyReceiver;
+
+ /**
+ * Sets the context of the Command. This can then be used to do things like
+ * get file paths associated with the Activity.
+ *
+ * @param cordova The context of the main Activity.
+ * @param webView The CordovaWebView Cordova is running in.
+ */
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+ super.initialize(cordova, webView);
+ this.initTelephonyReceiver();
+ }
+
+
/**
* Executes the request and returns PluginResult.
*
@@ -221,5 +243,45 @@ public class App extends CordovaPlugin {
public void exitApp() {
this.webView.postMessage("exit", null);
}
+
+
+ /**
+ * Listen for telephony events: RINGING, OFFHOOK and IDLE
+ * Send these events to all plugins using
+ * CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
+ */
+ private void initTelephonyReceiver() {
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
+ //final CordovaInterface mycordova = this.cordova;
+ this.telephonyReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ // If state has changed
+ if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
+ if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
+ String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
+ if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
+ LOG.i(TAG, "Telephone RINGING");
+ webView.postMessage("telephone", "ringing");
+ }
+ else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
+ LOG.i(TAG, "Telephone OFFHOOK");
+ webView.postMessage("telephone", "offhook");
+ }
+ else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
+ LOG.i(TAG, "Telephone IDLE");
+ webView.postMessage("telephone", "idle");
+ }
+ }
+ }
+ }
+ };
+
+ // Register the receiver
+ this.cordova.getActivity().registerReceiver(this.telephonyReceiver, intentFilter);
+ }
}