Skip to content

Commit 94a854d

Browse files
author
Hirbod
committed
Merge pull request #597 from wolf-s/master
Uplift to cordova-android 4.x (Cordova 5.x)
2 parents 2d8bd04 + c321754 commit 94a854d

2 files changed

Lines changed: 30 additions & 74 deletions

File tree

src/android/plugin/google/maps/GoogleMaps.java

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import java.util.List;
77
import java.util.Set;
88

9+
import android.view.*;
910
import org.apache.cordova.CallbackContext;
1011
import org.apache.cordova.CordovaInterface;
1112
import org.apache.cordova.CordovaPlugin;
1213
import org.apache.cordova.CordovaWebView;
1314
import org.apache.cordova.PluginEntry;
1415
import org.apache.cordova.PluginResult;
15-
import org.apache.cordova.ScrollEvent;
1616
import org.json.JSONArray;
1717
import org.json.JSONException;
1818
import org.json.JSONObject;
@@ -44,10 +44,6 @@
4444
import android.os.Handler;
4545
import android.provider.Settings;
4646
import android.util.Log;
47-
import android.view.Gravity;
48-
import android.view.View;
49-
import android.view.ViewGroup;
50-
import android.view.WindowManager;
5147
import android.webkit.WebChromeClient;
5248
import android.widget.AbsoluteLayout;
5349
import android.widget.FrameLayout;
@@ -135,7 +131,8 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV
135131
super.initialize(cordova, webView);
136132
activity = cordova.getActivity();
137133
density = Resources.getSystem().getDisplayMetrics().density;
138-
root = (ViewGroup) webView.getParent();
134+
final View view = webView.getView();
135+
root = (ViewGroup) view.getParent();
139136

140137
// Is this release build version?
141138
boolean isRelease = false;
@@ -194,7 +191,7 @@ public void run() {
194191
}
195192
*/
196193
if (Build.VERSION.SDK_INT >= 11){
197-
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
194+
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
198195
}
199196

200197
root.setBackgroundColor(Color.WHITE);
@@ -203,7 +200,7 @@ public void run() {
203200
}
204201
if (VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
205202
Log.d(TAG, "Google Maps Plugin reloads the browser to change the background color as transparent.");
206-
webView.setBackgroundColor(0);
203+
view.setBackgroundColor(0);
207204
try {
208205
Method method = webView.getClass().getMethod("reload");
209206
method.invoke(webView);
@@ -327,7 +324,7 @@ private void getMap(final JSONArray args, final CallbackContext callbackContext)
327324
return;
328325
}
329326

330-
mPluginLayout = new MyPluginLayout(webView, activity);
327+
mPluginLayout = new MyPluginLayout(webView.getView(), activity);
331328

332329
// ------------------------------
333330
// Check of Google Play Services
@@ -647,46 +644,6 @@ private Boolean getLicenseInfo(JSONArray args, CallbackContext callbackContext)
647644
return true;
648645
}
649646

650-
@Override
651-
public Object onMessage(String id, Object data) {
652-
EVENTS event = null;
653-
try {
654-
event = EVENTS.valueOf(id);
655-
}catch(Exception e) {}
656-
657-
if (event == null) {
658-
return null;
659-
}
660-
661-
switch(event) {
662-
case onScrollChanged:
663-
ScrollEvent scrollEvent = (ScrollEvent)data;
664-
if (mPluginLayout != null) {
665-
mPluginLayout.scrollTo(scrollEvent.nl, scrollEvent.nt);
666-
if (mapDivLayoutJSON != null) {
667-
try {
668-
float divW = contentToView(mapDivLayoutJSON.getLong("width"));
669-
float divH = contentToView(mapDivLayoutJSON.getLong("height"));
670-
float divLeft = contentToView(mapDivLayoutJSON.getLong("left"));
671-
float divTop = contentToView(mapDivLayoutJSON.getLong("top"));
672-
673-
mPluginLayout.setDrawingRect(
674-
divLeft,
675-
divTop - scrollEvent.nt,
676-
divLeft + divW,
677-
divTop + divH - scrollEvent.nt);
678-
} catch (JSONException e) {
679-
e.printStackTrace();
680-
}
681-
}
682-
}
683-
684-
break;
685-
}
686-
687-
return null;
688-
}
689-
690647
private void closeWindow() {
691648
try {
692649
Method method = webView.getClass().getMethod("hideCustomView");
@@ -786,7 +743,7 @@ private void showDialog(final JSONArray args, final CallbackContext callbackCont
786743
licenseLink.setId(LICENSE_LINK_ID);
787744
buttonFrame.addView(licenseLink);
788745

789-
webView.setVisibility(View.GONE);
746+
webView.getView().setVisibility(View.GONE);
790747
root.addView(windowLayer);
791748

792749
/**
@@ -804,7 +761,7 @@ public void onCustomViewHidden() {
804761
mPluginLayout.updateViewPosition();
805762
}
806763
root.removeView(windowLayer);
807-
webView.setVisibility(View.VISIBLE);
764+
webView.getView().setVisibility(View.VISIBLE);
808765
windowLayer = null;
809766

810767

@@ -876,9 +833,9 @@ private void updateMapViewLayout() {
876833
// Update the plugin drawing view rect
877834
mPluginLayout.setDrawingRect(
878835
divLeft,
879-
divTop - webView.getScrollY(),
836+
divTop - webView.getView().getScrollY(),
880837
divLeft + divW,
881-
divTop + divH - webView.getScrollY());
838+
divTop + divH - webView.getView().getScrollY());
882839
mPluginLayout.updateViewPosition();
883840
mapView.requestLayout();
884841
} catch (JSONException e) {

src/android/plugin/google/maps/MyPluginLayout.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Map.Entry;
77
import java.util.Set;
88

9-
import org.apache.cordova.CordovaWebView;
9+
import android.view.View;
1010

1111
import android.annotation.SuppressLint;
1212
import android.app.Activity;
@@ -19,7 +19,6 @@
1919
import android.os.Build.VERSION;
2020
import android.view.Gravity;
2121
import android.view.MotionEvent;
22-
import android.view.View;
2322
import android.view.ViewGroup;
2423
import android.widget.AbsoluteLayout;
2524
import android.widget.FrameLayout;
@@ -28,7 +27,7 @@
2827

2928
@SuppressWarnings("deprecation")
3029
public class MyPluginLayout extends FrameLayout {
31-
private CordovaWebView webView;
30+
private View view;
3231
private ViewGroup root;
3332
private RectF drawRect = new RectF();
3433
private Context context;
@@ -46,15 +45,15 @@ public class MyPluginLayout extends FrameLayout {
4645
private Activity mActivity = null;
4746

4847
@SuppressLint("NewApi")
49-
public MyPluginLayout(CordovaWebView webView, Activity activity) {
50-
super(webView.getContext());
48+
public MyPluginLayout(View view, Activity activity) {
49+
super(view.getContext());
5150
mActivity = activity;
52-
this.webView = webView;
53-
this.root = (ViewGroup) webView.getParent();
54-
this.context = webView.getContext();
55-
webView.setBackgroundColor(Color.TRANSPARENT);
51+
this.view = view;
52+
this.root = (ViewGroup) view.getParent();
53+
this.context = view.getContext();
54+
view.setBackgroundColor(Color.TRANSPARENT);
5655
if (VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
57-
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
56+
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
5857
}
5958
frontLayer = new FrontLayerLayout(this.context);
6059

@@ -129,7 +128,7 @@ public void updateViewPosition() {
129128
return;
130129
}
131130
ViewGroup.LayoutParams lParams = this.myView.getLayoutParams();
132-
int scrollY = webView.getScrollY();
131+
int scrollY = view.getScrollY();
133132

134133
if (lParams instanceof AbsoluteLayout.LayoutParams) {
135134
AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) lParams;
@@ -177,7 +176,7 @@ public void detachMyView() {
177176
}
178177
root.removeView(this);
179178
this.removeView(frontLayer);
180-
frontLayer.removeView(webView);
179+
frontLayer.removeView(view);
181180

182181
scrollFrameLayout.removeView(myView);
183182
myView.removeView(this.touchableWrapper);
@@ -188,7 +187,7 @@ public void detachMyView() {
188187
myView.setLayoutParams(orgLayoutParams);
189188
}
190189

191-
root.addView(webView);
190+
root.addView(view);
192191
myView = null;
193192
mActivity.getWindow().getDecorView().requestFocus();
194193
}
@@ -197,28 +196,28 @@ public void attachMyView(ViewGroup pluginView) {
197196
scrollView.setHorizontalScrollBarEnabled(false);
198197
scrollView.setVerticalScrollBarEnabled(false);
199198

200-
scrollView.scrollTo(webView.getScrollX(), webView.getScrollY());
199+
scrollView.scrollTo(view.getScrollX(), view.getScrollY());
201200
if (myView == pluginView) {
202201
return;
203202
} else {
204203
this.detachMyView();
205204
}
206-
//backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) (webView.getContentHeight() * webView.getScale() + webView.getHeight())));
205+
//backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) (view.getContentHeight() * view.getScale() + view.getHeight())));
207206

208207
myView = pluginView;
209208
ViewGroup.LayoutParams lParams = myView.getLayoutParams();
210209
orgLayoutParams = null;
211210
if (lParams != null) {
212211
orgLayoutParams = new ViewGroup.LayoutParams(lParams);
213212
}
214-
root.removeView(webView);
213+
root.removeView(view);
215214
scrollView.addView(scrollFrameLayout);
216215
this.addView(scrollView);
217216

218217
pluginView.addView(this.touchableWrapper);
219218
scrollFrameLayout.addView(pluginView);
220219

221-
frontLayer.addView(webView);
220+
frontLayer.addView(view);
222221
this.addView(frontLayer);
223222
root.addView(this);
224223
mActivity.getWindow().getDecorView().requestFocus();
@@ -258,12 +257,12 @@ public FrontLayerLayout(Context context) {
258257
@Override
259258
public boolean onInterceptTouchEvent(MotionEvent event) {
260259
if (isClickable == false || myView == null || myView.getVisibility() != View.VISIBLE) {
261-
webView.requestFocus(View.FOCUS_DOWN);
260+
view.requestFocus(View.FOCUS_DOWN);
262261
return false;
263262
}
264263
int x = (int)event.getX();
265264
int y = (int)event.getY();
266-
int scrollY = webView.getScrollY();
265+
int scrollY = view.getScrollY();
267266
boolean contains = drawRect.contains(x, y);
268267
int action = event.getAction();
269268
isScrolling = (contains == false && action == MotionEvent.ACTION_DOWN) ? true : isScrolling;
@@ -289,7 +288,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
289288
}
290289
}
291290
if (!contains) {
292-
webView.requestFocus(View.FOCUS_DOWN);
291+
view.requestFocus(View.FOCUS_DOWN);
293292
}
294293
return contains;
295294
}
@@ -300,7 +299,7 @@ protected void onDraw(Canvas canvas) {
300299
}
301300
int width = canvas.getWidth();
302301
int height = canvas.getHeight();
303-
int scrollY = webView.getScrollY();
302+
int scrollY = view.getScrollY();
304303

305304
Paint paint = new Paint();
306305
paint.setColor(Color.argb(100, 0, 255, 0));

0 commit comments

Comments
 (0)