Advertisement
dimkol

orientationchange handle

Apr 8th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. @Override
  2.     public void onConfigurationChanged(Configuration newConfig) {
  3.         super.onConfigurationChanged(newConfig);
  4.  
  5.         String newOrientation = "";
  6.  
  7.         // Checks the orientation of the screen
  8.         if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
  9.             newOrientation = "landscape";
  10.  
  11.         } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
  12.             newOrientation = "portrait";
  13.         }
  14.  
  15.         try {
  16.             JSONObject json = new JSONObject().put("orientation", orientation);
  17.  
  18.             json.put("newOrientation", newOrientation);
  19.             json.put("oldOrientation", orientation);
  20.  
  21.             sendOrientationDataToJs(json);
  22.  
  23.             orientation = newOrientation;
  24.         }
  25.         catch (JSONException e) {
  26.             Log.e(TAG, "JSONException: " + e.getLocalizedMessage());
  27.         }
  28.     }
  29.  
  30.     public void sendOrientationDataToJs(JSONObject json)
  31.     {
  32.         String pushData =  "cordova.fireDocumentEvent('androidorientationchange', " + json.toString() + ", true);";
  33.  
  34.         this.sendJavascript(pushData);
  35.  
  36.         Log.v(TAG, "Sent orientation data to JS " + json.toString());
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement