diff --git a/src/android/plugin/google/maps/GoogleMaps.java b/src/android/plugin/google/maps/GoogleMaps.java index 7307ff49..62008150 100644 --- a/src/android/plugin/google/maps/GoogleMaps.java +++ b/src/android/plugin/google/maps/GoogleMaps.java @@ -192,9 +192,9 @@ public void run() { e.printStackTrace(); } */ - if (Build.VERSION.SDK_INT >= 21 || "org.xwalk.core.XWalkView".equals(view.getClass().getName())){ - view.setLayerType(View.LAYER_TYPE_HARDWARE, null); - } + + view.setLayerType(View.LAYER_TYPE_HARDWARE, null); + root.setBackgroundColor(Color.WHITE); if (VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { @@ -587,6 +587,7 @@ public void onMapReady(GoogleMap googleMap) { if (args.length() == 3) { GoogleMaps.this.mapDivLayoutJSON = args.getJSONObject(1); mPluginLayout.attachMyView(mapView); + Log.e("client", "-- calling GoogleMaps.this.resizeMap"); GoogleMaps.this.resizeMap(args, callbackContext); } callbackContext.success(); @@ -784,33 +785,45 @@ private void resizeMap(JSONArray args, CallbackContext callbackContext) throws J return; } mapDivLayoutJSON = args.getJSONObject(args.length() - 2); - JSONArray HTMLs = args.getJSONArray(args.length() - 1); - JSONObject elemInfo, elemSize; - String elemId; - float divW, divH, divLeft, divTop; - if (mPluginLayout == null) { - this.sendNoResult(callbackContext); - return; - } + final JSONArray HTMLs = args.getJSONArray(args.length() - 1); + this.mPluginLayout.clearHTMLElement(); - for (int i = 0; i < HTMLs.length(); i++) { - elemInfo = HTMLs.getJSONObject(i); - try { - elemId = elemInfo.getString("id"); - elemSize = elemInfo.getJSONObject("size"); - - divW = contentToView(elemSize.getLong("width")); - divH = contentToView(elemSize.getLong("height")); - divLeft = contentToView(elemSize.getLong("left")); - divTop = contentToView(elemSize.getLong("top")); - mPluginLayout.putHTMLElement(elemId, divLeft, divTop, divLeft + divW, divTop + divH); - } catch (Exception e){ - e.printStackTrace(); + cordova.getThreadPool().execute(new Runnable() { + + @Override + public void run(){ + + try { + JSONObject elemInfo, elemSize; + String elemId; + float divW, divH, divLeft, divTop; + for (int i = 0; i < HTMLs.length(); i++) { + elemInfo = HTMLs.getJSONObject(i); + try { + elemId = elemInfo.getString("id"); + elemSize = elemInfo.getJSONObject("size"); + + divW = contentToView(elemSize.getLong("width")); + divH = contentToView(elemSize.getLong("height")); + divLeft = contentToView(elemSize.getLong("left")); + divTop = contentToView(elemSize.getLong("top")); + mPluginLayout.putHTMLElement(elemId, divLeft, divTop, divLeft + divW, divTop + divH); + } catch (Exception e){ + e.printStackTrace(); + } + } + } catch (Exception e){} + //mPluginLayout.inValidate(); + cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateMapViewLayout(); + } + }); } - } - //mPluginLayout.inValidate(); - updateMapViewLayout(); + }); + this.sendNoResult(callbackContext); } diff --git a/src/android/plugin/google/maps/MyPluginLayout.java b/src/android/plugin/google/maps/MyPluginLayout.java index 7d27b887..f7c9744b 100644 --- a/src/android/plugin/google/maps/MyPluginLayout.java +++ b/src/android/plugin/google/maps/MyPluginLayout.java @@ -25,6 +25,7 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ScrollView; +import android.util.Log; @SuppressWarnings("deprecation") public class MyPluginLayout extends FrameLayout { @@ -44,7 +45,7 @@ public class MyPluginLayout extends FrameLayout { private boolean isClickable = true; private Map HTMLNodes = new HashMap(); private Activity mActivity = null; - + @SuppressLint("NewApi") public MyPluginLayout(View view, Activity activity) { super(view.getContext()); @@ -52,11 +53,12 @@ public MyPluginLayout(View view, Activity activity) { this.view = view; this.root = (ViewGroup) view.getParent(); this.context = view.getContext(); - if (VERSION.SDK_INT >= 21 || "org.xwalk.core.XWalkView".equals(view.getClass().getName())) { - view.setLayerType(View.LAYER_TYPE_HARDWARE, null); - } + Log.e("client", view.getClass().getName() ); + + view.setLayerType(View.LAYER_TYPE_HARDWARE, null); + frontLayer = new FrontLayerLayout(this.context); - + scrollView = new ScrollView(this.context); scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); @@ -65,18 +67,18 @@ public MyPluginLayout(View view, Activity activity) { backgroundView.setVerticalScrollBarEnabled(false); backgroundView.setHorizontalScrollBarEnabled(false); backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 9999)); - + scrollFrameLayout = new FrameLayout(this.context); scrollFrameLayout.addView(backgroundView); scrollFrameLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - + scrollView.setHorizontalScrollBarEnabled(false); scrollView.setVerticalScrollBarEnabled(false); - + this.touchableWrapper = new TouchableWrapper(this.context); - + } - + public void setDrawingRect(float left, float top, float right, float bottom) { this.drawRect.left = left; this.drawRect.top = top; @@ -86,7 +88,7 @@ public void setDrawingRect(float left, float top, float right, float bottom) { this.inValidate(); } } - + public void putHTMLElement(String domId, float left, float top, float right, float bottom) { RectF rect = null; if (this.HTMLNodes.containsKey(domId)) { @@ -122,7 +124,7 @@ public void setClickable(boolean clickable) { this.inValidate(); } } - + public void updateViewPosition() { if (myView == null) { return; @@ -152,7 +154,7 @@ public void updateViewPosition() { params.leftMargin = (int) this.drawRect.left; params.gravity = Gravity.TOP; myView.setLayoutParams(params); - } + } if (android.os.Build.VERSION.SDK_INT < 11) { // Force redraw myView.requestLayout(); @@ -177,37 +179,36 @@ public void detachMyView() { root.removeView(this); this.removeView(frontLayer); frontLayer.removeView(view); - + scrollFrameLayout.removeView(myView); myView.removeView(this.touchableWrapper); - + this.removeView(this.scrollView); this.scrollView.removeView(scrollFrameLayout); if (orgLayoutParams != null) { myView.setLayoutParams(orgLayoutParams); } - + root.addView(view); myView = null; mActivity.getWindow().getDecorView().requestFocus(); } - + public void attachMyView(ViewGroup pluginView) { view.setBackgroundColor(Color.TRANSPARENT); - if("org.xwalk.core.XWalkView".equals(view.getClass().getName()) - || "org.crosswalk.engine.XWalkCordovaView".equals(view.getClass().getName())) { - try { - /* view.setZOrderOnTop(true) - * Called just in time as with root.setBackground(...) the color - * come in front and take the whoel screen */ - view.getClass().getMethod("setZOrderOnTop", boolean.class) - .invoke(view, true); - } - catch(Exception e) {} + + try { + /* view.setZOrderOnTop(true) + * Called just in time as with root.setBackground(...) the color + * come in front and take the whoel screen */ + view.getClass().getMethod("setZOrderOnTop", boolean.class) + .invoke(view, true); } + catch(Exception e) {} + scrollView.setHorizontalScrollBarEnabled(false); scrollView.setVerticalScrollBarEnabled(false); - + scrollView.scrollTo(view.getScrollX(), view.getScrollY()); if (myView == pluginView) { return; @@ -215,7 +216,7 @@ public void attachMyView(ViewGroup pluginView) { this.detachMyView(); } //backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) (view.getContentHeight() * view.getScale() + view.getHeight()))); - + myView = pluginView; ViewGroup.LayoutParams lParams = myView.getLayoutParams(); orgLayoutParams = null; @@ -225,26 +226,26 @@ public void attachMyView(ViewGroup pluginView) { root.removeView(view); scrollView.addView(scrollFrameLayout); this.addView(scrollView); - + pluginView.addView(this.touchableWrapper); scrollFrameLayout.addView(pluginView); - + frontLayer.addView(view); this.addView(frontLayer); root.addView(this); mActivity.getWindow().getDecorView().requestFocus(); - + scrollView.setHorizontalScrollBarEnabled(true); scrollView.setVerticalScrollBarEnabled(true); } - + public void setPageSize(int width, int height) { android.view.ViewGroup.LayoutParams lParams = backgroundView.getLayoutParams(); lParams.width = width; lParams.height = height; backgroundView.setLayoutParams(lParams); } - + public void scrollTo(int x, int y) { this.scrollView.scrollTo(x, y); } @@ -253,19 +254,19 @@ public void scrollTo(int x, int y) { public void setBackgroundColor(int color) { this.backgroundView.setBackgroundColor(color); } - + public void inValidate() { this.frontLayer.invalidate(); } - + private class FrontLayerLayout extends FrameLayout { - + public FrontLayerLayout(Context context) { super(context); this.setWillNotDraw(false); } - + @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (isClickable == false || myView == null || myView.getVisibility() != View.VISIBLE) { @@ -280,7 +281,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) { isScrolling = (contains == false && action == MotionEvent.ACTION_DOWN) ? true : isScrolling; isScrolling = (action == MotionEvent.ACTION_UP) ? false : isScrolling; contains = isScrolling == true ? false : contains; - + if (contains) { // Is the touch point on any HTML elements? Set> elements = MyPluginLayout.this.HTMLNodes.entrySet(); @@ -312,7 +313,7 @@ protected void onDraw(Canvas canvas) { int width = canvas.getWidth(); int height = canvas.getHeight(); int scrollY = view.getScrollY(); - + Paint paint = new Paint(); paint.setColor(Color.argb(100, 0, 255, 0)); if (isClickable == false) { @@ -323,10 +324,10 @@ protected void onDraw(Canvas canvas) { canvas.drawRect(0, drawRect.top, drawRect.left, drawRect.bottom, paint); canvas.drawRect(drawRect.right, drawRect.top, width, drawRect.bottom, paint); canvas.drawRect(0, drawRect.bottom, width, height, paint); - - + + paint.setColor(Color.argb(100, 255, 0, 0)); - + Set> elements = MyPluginLayout.this.HTMLNodes.entrySet(); Iterator> iterator = elements.iterator(); Entry entry; @@ -342,9 +343,9 @@ protected void onDraw(Canvas canvas) { } } } - + private class TouchableWrapper extends FrameLayout { - + public TouchableWrapper(Context context) { super(context); } @@ -357,5 +358,5 @@ public boolean dispatchTouchEvent(MotionEvent event) { } return super.dispatchTouchEvent(event); } - } + } }