Skip to content

Commit

Permalink
#2 Cordova-Android 4+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jun 7, 2015
1 parent 6aeae0c commit a980079
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/android/AdMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ public void run() {
if (adViewLayout == null) {
adViewLayout = new RelativeLayout(cordova.getActivity());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
if (CORDOVA_MIN_4) {
((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params);
} else {
try {
((ViewGroup)(((View)webView.getClass().getMethod("getView").invoke(webView)).getParent())).addView(adViewLayout, params);
} catch (Exception e) {
((ViewGroup) webView).addView(adViewLayout, params);
}
}
Expand All @@ -405,16 +405,16 @@ public void run() {
adViewLayout.bringToFront();
} else {
if (CORDOVA_MIN_4) {
ViewGroup wvParentView = (ViewGroup) webView.getView().getParent();
ViewGroup wvParentView = (ViewGroup)getWebView().getParent();
if (parentView == null) {
parentView = new LinearLayout(webView.getContext());
}
if (wvParentView != null && wvParentView != parentView) {
wvParentView.removeView(webView.getView());
wvParentView.removeView(getWebView());
((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL);
parentView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
webView.getView().setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));
parentView.addView(webView.getView());
getWebView().setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));
parentView.addView(getWebView());
cordova.getActivity().setContentView(parentView);
}

Expand Down Expand Up @@ -567,6 +567,14 @@ public void onDestroy() {
super.onDestroy();
}

private View getWebView() {
try {
return (View) webView.getClass().getMethod("getView").invoke(webView);
} catch (Exception e) {
return (View) webView;
}
}

/**
* Gets an AdSize object from the string size passed in from JavaScript.
* Returns null if an improper string is provided.
Expand Down

0 comments on commit a980079

Please sign in to comment.