Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- String newOrientation = "";
- // Checks the orientation of the screen
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- newOrientation = "landscape";
- } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
- newOrientation = "portrait";
- }
- try {
- JSONObject json = new JSONObject().put("orientation", orientation);
- json.put("newOrientation", newOrientation);
- json.put("oldOrientation", orientation);
- sendOrientationDataToJs(json);
- orientation = newOrientation;
- }
- catch (JSONException e) {
- Log.e(TAG, "JSONException: " + e.getLocalizedMessage());
- }
- }
- public void sendOrientationDataToJs(JSONObject json)
- {
- String pushData = "cordova.fireDocumentEvent('androidorientationchange', " + json.toString() + ", true);";
- this.sendJavascript(pushData);
- Log.v(TAG, "Sent orientation data to JS " + json.toString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement