http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/border/TopRightCorner.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/border/TopRightCorner.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/border/TopRightCorner.java index 0ea4377..73a0adc 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/border/TopRightCorner.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/border/TopRightCorner.java @@ -18,68 +18,47 @@ */ package com.taobao.weex.ui.view.border; -import android.graphics.PointF; import android.graphics.RectF; import android.support.annotation.NonNull; class TopRightCorner extends BorderCorner { - TopRightCorner(float cornerRadius, float preBorderWidth, float postBorderWidth, @NonNull RectF borderBox) { - super(cornerRadius, preBorderWidth, postBorderWidth, borderBox, 315); + void set(float cornerRadius, float preBorderWidth, float postBorderWidth, @NonNull RectF borderBox) { + set(cornerRadius, preBorderWidth, postBorderWidth, borderBox, 315); } - @NonNull @Override - protected RectF getOvalIfInnerCornerExist() { - return new RectF(getBorderBox().width() - (2 * getOuterCornerRadius() - getPostBorderWidth() / 2), - getPreBorderWidth() / 2, - getBorderBox().width() - getPostBorderWidth() / 2, - 2 * getOuterCornerRadius() - getPreBorderWidth() / 2); + protected void prepareOval() { + if (hasInnerCorner()) { + setOvalLeft(getBorderBox().width() - (2 * getOuterCornerRadius() - getPostBorderWidth() / 2)); + setOvalTop(getPreBorderWidth() / 2); + setOvalRight(getBorderBox().width() - getPostBorderWidth() / 2); + setOvalBottom(2 * getOuterCornerRadius() - getPreBorderWidth() / 2); + } else { + setOvalLeft(getBorderBox().width() - 1.5f * getOuterCornerRadius()); + setOvalTop(getOuterCornerRadius() / 2); + setOvalRight(getBorderBox().width() - getOuterCornerRadius() / 2); + setOvalBottom(getOuterCornerRadius() * 1.5f); + } } - @NonNull @Override - protected RectF getOvalIfInnerCornerNotExist() { - return new RectF(getBorderBox().width() - 1.5f * getOuterCornerRadius(), - getOuterCornerRadius() / 2, - getBorderBox().width()-getOuterCornerRadius()/2, - getOuterCornerRadius() * 1.5f); - } - - @NonNull - @Override - protected PointF getRoundCornerStart() { - return new PointF(getBorderBox().width() - getOuterCornerRadius(), - getPreBorderWidth() / 2); - } - - @NonNull - @Override - protected PointF getSharpCornerVertex() { - return new PointF(getBorderBox().width() - getPostBorderWidth() / 2, - getPreBorderWidth() / 2); - } + protected void prepareRoundCorner() { + if (hasOuterCorner()) { + setRoundCornerStartX(getBorderBox().width() - getOuterCornerRadius()); + setRoundCornerStartY(getPreBorderWidth() / 2); - @NonNull - @Override - protected PointF getSharpCornerStart() { - PointF pointF=getSharpCornerVertex(); - pointF.y=0; - return pointF; - } + setRoundCornerEndX(getBorderBox().width() - getPostBorderWidth() / 2); + setRoundCornerEndY(getOuterCornerRadius()); + } else { + final float x = getBorderBox().width() - getPostBorderWidth() / 2; + final float y = getPreBorderWidth() / 2; - @NonNull - @Override - protected PointF getSharpCornerEnd() { - PointF pointF=getSharpCornerVertex(); - pointF.x=getBorderBox().right; - return pointF; - } + setRoundCornerStartX(x); + setRoundCornerStartY(y); - @NonNull - @Override - protected PointF getRoundCornerEnd() { - return new PointF(getBorderBox().width() - getPostBorderWidth() / 2, - getOuterCornerRadius()); + setRoundCornerEndX(x); + setRoundCornerEndY(y); + } } }
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java index 954d118..53a5ac9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java @@ -95,8 +95,8 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement if(parentScrollable != null) { mParentOrientation = parentScrollable.getOrientation(); } - shouldBubbleResult = WXUtils.getBoolean(wxComponent.getDomObject().getAttrs().get(Constants.Name.SHOULD_STOP_PROPAGATION_INIT_RESULT), true); - shouldBubbleInterval = WXUtils.getNumberInt(wxComponent.getDomObject().getAttrs().get(Constants.Name.SHOULD_STOP_PROPAGATION_INTERVAL), 0); + shouldBubbleResult = WXUtils.getBoolean(wxComponent.getAttrs().get(Constants.Name.SHOULD_STOP_PROPAGATION_INIT_RESULT), true); + shouldBubbleInterval = WXUtils.getNumberInt(wxComponent.getAttrs().get(Constants.Name.SHOULD_STOP_PROPAGATION_INTERVAL), 0); } private boolean isParentScrollable() { @@ -109,7 +109,7 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement private boolean hasSameOrientationWithParent(){ return (mParentOrientation == Constants.Orientation.HORIZONTAL && component.containsGesture(HighLevelGesture.HORIZONTALPAN)) - || (mParentOrientation == Constants.Orientation.VERTICAL && component.containsGesture(HighLevelGesture.VERTICALPAN)); + || (mParentOrientation == Constants.Orientation.VERTICAL && component.containsGesture(HighLevelGesture.VERTICALPAN)); } public void setPreventMoveEvent(boolean preventMoveEvent) { @@ -208,7 +208,7 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement if(component.getParent() != null){ component.getParent().requestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent); } - if(mIsTouchEventConsumed && WXUtils.getBoolean(component.getDomObject().getAttrs().get("cancelTouchOnConsume"), false)){//when touch event consumed by one gesture, other component should not consumed + if(mIsTouchEventConsumed && WXUtils.getBoolean(component.getAttrs().get("cancelTouchOnConsume"), false)){//when touch event consumed by one gesture, other component should not consumed event.setAction(MotionEvent.ACTION_CANCEL); } } @@ -351,10 +351,10 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement */ private boolean isPointerNumChanged(MotionEvent event) { return event.getActionMasked() == MotionEvent.ACTION_DOWN || - event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN || - event.getActionMasked() == MotionEvent.ACTION_UP || - event.getActionMasked() == MotionEvent.ACTION_POINTER_UP || - event.getActionMasked() == MotionEvent.ACTION_CANCEL; + event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN || + event.getActionMasked() == MotionEvent.ACTION_UP || + event.getActionMasked() == MotionEvent.ACTION_POINTER_UP || + event.getActionMasked() == MotionEvent.ACTION_CANCEL; } /** @@ -363,8 +363,8 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement */ private boolean containsSimplePan() { return component.containsGesture(HighLevelGesture.PAN_START) || - component.containsGesture(HighLevelGesture.PAN_MOVE) || - component.containsGesture(HighLevelGesture.PAN_END); + component.containsGesture(HighLevelGesture.PAN_MOVE) || + component.containsGesture(HighLevelGesture.PAN_END); } /** @@ -455,7 +455,7 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement component.getRealView().getGlobalVisibleRect(globalRect, globalOffset); globalEventOffset.offset(globalOffset.x, globalOffset.y); return new PointF(WXViewUtils.getWebPxByWidth(globalEventOffset.x,component.getInstance().getInstanceViewPortWidth()), - WXViewUtils.getWebPxByWidth(globalEventOffset.y,component.getInstance().getInstanceViewPortWidth())); + WXViewUtils.getWebPxByWidth(globalEventOffset.y,component.getInstance().getInstanceViewPortWidth())); } /** @@ -501,7 +501,7 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement component.computeVisiblePointInViewCoordinate(locLeftTop); locEventOffset.offset(locLeftTop.x, locLeftTop.y); return new PointF(WXViewUtils.getWebPxByWidth(locEventOffset.x,component.getInstance().getInstanceViewPortWidth()), - WXViewUtils.getWebPxByWidth(locEventOffset.y,component.getInstance().getInstanceViewPortWidth())); + WXViewUtils.getWebPxByWidth(locEventOffset.y,component.getInstance().getInstanceViewPortWidth())); } private static class GestureHandler extends android.os.Handler { @@ -519,9 +519,9 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement if (component.containsGesture(HighLevelGesture.LONG_PRESS)) { List<Map<String, Object>> list = createMultipleFireEventParam(e,null); component.getInstance().fireEvent( - component.getDomObject().getRef(), - HighLevelGesture.LONG_PRESS.toString(), - list.get(list.size() - 1)); + component.getRef(), + HighLevelGesture.LONG_PRESS.toString(), + list.get(list.size() - 1)); mIsTouchEventConsumed = true; } } @@ -563,10 +563,10 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement panDownTime = e1.getEventTime(); mPendingPan = HighLevelGesture.PAN_END; component.fireEvent(HighLevelGesture.PAN_START.toString(), - createFireEventParam(e1, CUR_EVENT, null)); + createFireEventParam(e1, CUR_EVENT, null)); } else { component.fireEvent(HighLevelGesture.PAN_MOVE.toString(), - createFireEventParam(e2, CUR_EVENT, null)); + createFireEventParam(e2, CUR_EVENT, null)); } result = true; } else if (component.containsGesture(HighLevelGesture.SWIPE)) { @@ -579,8 +579,8 @@ public class WXGesture extends GestureDetector.SimpleOnGestureListener implement } else { param.put(GestureInfo.DIRECTION, distanceY > 0 ? UP : DOWN); } - component.getInstance().fireEvent(component.getDomObject().getRef(), - HighLevelGesture.SWIPE.toString(), param); + component.getInstance().fireEvent(component.getRef(), + HighLevelGesture.SWIPE.toString(), param); result = true; } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGestureObservable.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGestureObservable.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGestureObservable.java index 41c714c..1735c30 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGestureObservable.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGestureObservable.java @@ -26,9 +26,9 @@ import com.taobao.weex.ui.view.WXFrameLayout; /** * Views that want to receive Gesture Event must implement this interface. Besides, - * those view must override their {@link android.view.View#dispatchTouchEvent(MotionEvent)} + * those view must override their {@link android.view.View#onTouchEvent(MotionEvent)} * and add method invocation to {@link WXGesture#onTouch(View, MotionEvent)}. - * Refer to {@link WXFrameLayout#dispatchTouchEvent(MotionEvent)}} for more info. + * Refer to {@link WXFrameLayout#onTouchEvent(MotionEvent)} for more info. * */ public interface WXGestureObservable { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXRefreshView.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXRefreshView.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXRefreshView.java index b00e5c2..7c69be8 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXRefreshView.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXRefreshView.java @@ -52,8 +52,8 @@ public class WXRefreshView extends FrameLayout { private void setupViews() { linearLayout = new LinearLayout(getContext()); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams - .MATCH_PARENT,FrameLayout - .LayoutParams.MATCH_PARENT); + .MATCH_PARENT,FrameLayout + .LayoutParams.MATCH_PARENT); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); addView(linearLayout,lp); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java index 72a5215..7e252d5 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java @@ -241,20 +241,20 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, public boolean startNestedScroll(int axes) { boolean result = mNestedScrollingChildHelper.startNestedScroll(axes); if(result){ - if(mNestedScrollAcceptedParent == null){ - ViewParent parent = this.getParent(); - View child = this; - while (parent != null) { - if (ViewParentCompat.onStartNestedScroll(parent, child, this, axes)){ - mNestedScrollAcceptedParent = parent; - break; - } - if(parent instanceof View){ - child = (View) parent; - } - parent = parent.getParent(); - } - } + if(mNestedScrollAcceptedParent == null){ + ViewParent parent = this.getParent(); + View child = this; + while (parent != null) { + if (ViewParentCompat.onStartNestedScroll(parent, child, this, axes)){ + mNestedScrollAcceptedParent = parent; + break; + } + if(parent instanceof View){ + child = (View) parent; + } + parent = parent.getParent(); + } + } } return result; } @@ -385,6 +385,8 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, int spinnerDy = (int) calculateDistanceY(target, dy); + mRefreshing = false; + if (!isConfirm) { if (spinnerDy < 0 && !canChildScrollUp()) { mCurrentAction = PULL_REFRESH; @@ -403,7 +405,7 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, }else if (!canChildScrollDown() && mPullLoadEnable && mTargetView.getTranslationY() < 0 && dy < 0){ - consumed[1] += dy; + consumed[1] += dy; }else{ consumed[1] += spinnerDy; } @@ -685,8 +687,8 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, if (mTargetView instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTargetView; return absListView.getChildCount() > 0 - && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) - .getTop() < absListView.getPaddingTop()); + && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) + .getTop() < absListView.getPaddingTop()); } else { return ViewCompat.canScrollVertically(mTargetView, -1) || mTargetView.getScrollY() > 0; } @@ -708,9 +710,9 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, final AbsListView absListView = (AbsListView) mTargetView; if (absListView.getChildCount() > 0) { int lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1) - .getBottom(); + .getBottom(); return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1 - && lastChildBottom <= absListView.getMeasuredHeight(); + && lastChildBottom <= absListView.getMeasuredHeight(); } else { return false; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/wrapper/BaseBounceView.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/wrapper/BaseBounceView.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/wrapper/BaseBounceView.java index 2319f8c..ca8f510 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/wrapper/BaseBounceView.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/wrapper/BaseBounceView.java @@ -27,7 +27,6 @@ import android.view.View; import android.widget.FrameLayout; import com.taobao.weex.common.Constants; -import com.taobao.weex.dom.ImmutableDomObject; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.view.WXLoadingLayout; import com.taobao.weex.ui.view.WXRefreshLayout; @@ -119,11 +118,10 @@ public abstract class BaseBounceView<T extends View> extends FrameLayout { if (swipeLayout != null) { WXRefreshView refreshView = swipeLayout.getHeaderView(); if (refreshView != null) { - ImmutableDomObject immutableDomObject = refresh.getDomObject(); - if (immutableDomObject != null) { - int refreshHeight = (int) immutableDomObject.getLayoutHeight(); + if (refresh != null) { + int refreshHeight = (int) refresh.getLayoutHeight(); swipeLayout.setRefreshHeight(refreshHeight); - String colorStr = (String) immutableDomObject.getStyles().get(Constants.Name.BACKGROUND_COLOR); + String colorStr = (String) refresh.getStyles().get(Constants.Name.BACKGROUND_COLOR); String bgColor = WXUtils.getString(colorStr, null); if (bgColor != null) { if (!TextUtils.isEmpty(bgColor)) { @@ -148,11 +146,10 @@ public abstract class BaseBounceView<T extends View> extends FrameLayout { if (swipeLayout != null) { WXRefreshView refreshView = swipeLayout.getFooterView(); if (refreshView != null) { - ImmutableDomObject immutableDomObject = loading.getDomObject(); - if (immutableDomObject != null) { - int loadingHeight = (int) immutableDomObject.getLayoutHeight(); + if (loading != null) { + int loadingHeight = (int) loading.getLayoutHeight(); swipeLayout.setLoadingHeight(loadingHeight); - String colorStr = (String) immutableDomObject.getStyles().get(Constants.Name.BACKGROUND_COLOR); + String colorStr = (String) loading.getStyles().get(Constants.Name.BACKGROUND_COLOR); String bgColor = WXUtils.getString(colorStr, null); if (bgColor != null) { if (!TextUtils.isEmpty(bgColor)) { @@ -200,24 +197,24 @@ public abstract class BaseBounceView<T extends View> extends FrameLayout { swipeLayout.setPullLoadEnable(enable); } - @Override - public void removeView(View view) { - if (view instanceof WXLoadingLayout) { - finishPullLoad(); - setLoadmoreEnable(false); - if (swipeLayout != null) { - swipeLayout.removeView(swipeLayout.getFooterView()); - } - } else if (view instanceof WXRefreshLayout) { - finishPullRefresh(); - setRefreshEnable(false); - if (swipeLayout != null) { - swipeLayout.removeView(swipeLayout.getHeaderView()); - } - } else { - super.removeView(view); - } - } + @Override + public void removeView(View view) { + if (view instanceof WXLoadingLayout) { + finishPullLoad(); + setLoadmoreEnable(false); + if (swipeLayout != null) { + swipeLayout.removeView(swipeLayout.getFooterView()); + } + } else if (view instanceof WXRefreshLayout) { + finishPullRefresh(); + setRefreshEnable(false); + if (swipeLayout != null) { + swipeLayout.removeView(swipeLayout.getHeaderView()); + } + } else { + super.removeView(view); + } + } public WXSwipeLayout getSwipeLayout() { return swipeLayout; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/FunctionParser.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/FunctionParser.java b/android/sdk/src/main/java/com/taobao/weex/utils/FunctionParser.java index 2756071..93ace90 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/FunctionParser.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/FunctionParser.java @@ -79,12 +79,16 @@ public class FunctionParser<K, V> { } private String match(Token token) { - if (token == lexer.getCurrentToken()) { - String value = lexer.getCurrentTokenValue(); - lexer.moveOn(); - return value; + try { + if (token == lexer.getCurrentToken()) { + String value = lexer.getCurrentTokenValue(); + lexer.moveOn(); + return value; + } + } catch (Exception e) { + WXLogUtils.e(token + "Token doesn't match" + lexer.source); } - throw new WXInterpretationException(token + "Token doesn't match" + lexer.source); + return ""; } private enum Token { @@ -175,7 +179,7 @@ public class FunctionParser<K, V> { break; } } else if (isCharacterOrDigit(curChar) || curChar == DOT - || curChar == WXUtils.PERCENT || curChar == MINUS || curChar == PLUS) { + || curChar == WXUtils.PERCENT || curChar == MINUS || curChar == PLUS) { pointer++; } else { if (start == pointer) { @@ -219,8 +223,8 @@ public class FunctionParser<K, V> { for (int i = 0; i < funcName.length(); i++) { letter = funcName.charAt(i); if (!((A_LOWER <= letter && letter <= Z_LOWER) || - (A_UPPER <= letter && letter <= Z_UPPER) || - letter == MINUS)) { + (A_UPPER <= letter && letter <= Z_UPPER) || + letter == MINUS)) { return false; } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/ImageDrawable.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/ImageDrawable.java b/android/sdk/src/main/java/com/taobao/weex/utils/ImageDrawable.java index a352cf6..f3ee939 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/ImageDrawable.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/ImageDrawable.java @@ -46,7 +46,7 @@ public class ImageDrawable extends PaintDrawable { Bitmap bm; if (!gif && vWidth > 0 && vHeight > 0) { if (original instanceof BitmapDrawable && - (bm = ((BitmapDrawable) original).getBitmap()) != null) { + (bm = ((BitmapDrawable) original).getBitmap()) != null) { ImageDrawable imageDrawable; imageDrawable = new ImageDrawable(); imageDrawable.bitmapWidth = bm.getWidth(); @@ -58,7 +58,7 @@ public class ImageDrawable extends PaintDrawable { } else if (original instanceof ImageDrawable) { ImageDrawable imageDrawable = (ImageDrawable) original; if (imageDrawable.getPaint() != null && - imageDrawable.getPaint().getShader() instanceof BitmapShader) { + imageDrawable.getPaint().getShader() instanceof BitmapShader) { BitmapShader bitmapShader = (BitmapShader) imageDrawable.getPaint().getShader(); updateShaderAndSize(scaleType, vWidth, vHeight, imageDrawable, bitmapShader); return imageDrawable; @@ -70,8 +70,8 @@ public class ImageDrawable extends PaintDrawable { private static void updateShaderAndSize(@NonNull ImageView.ScaleType scaleType, int vWidth, int vHeight, ImageDrawable imageDrawable, BitmapShader bitmapShader) { Matrix matrix = createShaderMatrix(scaleType, vWidth, vHeight, - imageDrawable.bitmapWidth, - imageDrawable.bitmapHeight); + imageDrawable.bitmapWidth, + imageDrawable.bitmapHeight); int intrinsicWidth = vWidth, intrinsicHeight = vHeight; if (scaleType == ImageView.ScaleType.FIT_CENTER) { RectF bitmapRect = new RectF(0, 0, imageDrawable.bitmapWidth, imageDrawable.bitmapHeight), contentRect = new RectF(); @@ -79,7 +79,7 @@ public class ImageDrawable extends PaintDrawable { intrinsicWidth = (int) contentRect.width(); intrinsicHeight = (int) contentRect.height(); matrix = createShaderMatrix(scaleType, intrinsicWidth, intrinsicHeight, imageDrawable - .bitmapWidth, imageDrawable.bitmapHeight); + .bitmapWidth, imageDrawable.bitmapHeight); } imageDrawable.setIntrinsicWidth(intrinsicWidth); imageDrawable.setIntrinsicHeight(intrinsicHeight); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/SingleFunctionParser.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/SingleFunctionParser.java b/android/sdk/src/main/java/com/taobao/weex/utils/SingleFunctionParser.java index e785fe5..c67b323 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/SingleFunctionParser.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/SingleFunctionParser.java @@ -34,7 +34,7 @@ public class SingleFunctionParser<V> extends FunctionParser<String, List<V>> { } public interface NonUniformMapper<V>{ - List<V> map(List<String> raw); + List<V> map(List<String> raw); } /** http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/StaticLayoutProxy.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/StaticLayoutProxy.java b/android/sdk/src/main/java/com/taobao/weex/utils/StaticLayoutProxy.java index 98fe0ed..a3584ce 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/StaticLayoutProxy.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/StaticLayoutProxy.java @@ -55,13 +55,13 @@ public class StaticLayoutProxy { try { Class<StaticLayout> clazz = StaticLayout.class; Constructor<StaticLayout> constructor = clazz.getConstructor(CharSequence.class, TextPaint.class, - int.class, Layout.Alignment.class, TextDirectionHeuristic.class, - float.class, float.class, - boolean.class); + int.class, Layout.Alignment.class, TextDirectionHeuristic.class, + float.class, float.class, + boolean.class); if (constructor != null) { return constructor.newInstance(source, paint, width, - align, textDir, spacingmult, spacingadd, includepad); + align, textDir, spacingmult, spacingadd, includepad); } } catch (Throwable e) { e.printStackTrace(); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/TypefaceUtil.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/TypefaceUtil.java b/android/sdk/src/main/java/com/taobao/weex/utils/TypefaceUtil.java index 11f58cb..2d113bc 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/TypefaceUtil.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/TypefaceUtil.java @@ -83,12 +83,12 @@ public class TypefaceUtil { int want = 0; if ((weight == Typeface.BOLD) - || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) { + || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) { want |= Typeface.BOLD; } if ((style == Typeface.ITALIC) - || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) { + || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) { want |= Typeface.ITALIC; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXDomUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXDomUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXDomUtils.java index afa8152..bfd0ea5 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXDomUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXDomUtils.java @@ -19,10 +19,12 @@ package com.taobao.weex.utils; -import com.taobao.weex.dom.ImmutableDomObject; -import com.taobao.weex.dom.WXDomObject; -import com.taobao.weex.dom.flex.CSSConstants; -import com.taobao.weex.dom.flex.Spacing; +import android.support.annotation.NonNull; +import com.taobao.weex.dom.CSSConstants; +import com.taobao.weex.dom.CSSShorthand.EDGE; +import com.taobao.weex.dom.WXStyle; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.dom.CSSShorthand; public class WXDomUtils { @@ -31,23 +33,23 @@ public class WXDomUtils { * @return the width of the dom that excludes left-padding, left-border-width, * right-border-width and right-padding. */ - public static float getContentWidth(ImmutableDomObject domObject) { - float rawWidth = domObject.getLayoutWidth(); + public static float getContentWidth(WXComponent component) { + float rawWidth = component.getLayoutWidth(); float leftPadding, rightPadding, leftBorder, rightBorder; - Spacing padding = domObject.getPadding(); - Spacing border = domObject.getBorder(); + CSSShorthand padding = component.getPadding(); + CSSShorthand border = component.getBorder(); - if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) { + if (!CSSConstants.isUndefined((leftPadding = padding.get(CSSShorthand.EDGE.LEFT)))) { rawWidth -= leftPadding; } - if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) { + if (!CSSConstants.isUndefined((rightPadding = padding.get(CSSShorthand.EDGE.RIGHT)))) { rawWidth -= rightPadding; } - if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) { + if (!CSSConstants.isUndefined(leftBorder = border.get(CSSShorthand.EDGE.LEFT))) { rawWidth -= leftBorder; } - if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) { + if (!CSSConstants.isUndefined(rightBorder = border.get(CSSShorthand.EDGE.RIGHT))) { rawWidth -= rightBorder; } return rawWidth; @@ -58,25 +60,47 @@ public class WXDomUtils { * @return the height of the dom that excludes top-padding, top-border-width, bottom-padding * and bottom-border-width. */ - public static float getContentHeight(ImmutableDomObject domObject) { - float rawHeight = domObject.getLayoutHeight(); + public static float getContentHeight(WXComponent component) { + float rawHeight = component.getLayoutHeight(); float topPadding, bottomPadding, topBorder, bottomBorder; - Spacing padding = domObject.getPadding(); - Spacing border = domObject.getBorder(); + CSSShorthand padding = component.getPadding(); + CSSShorthand border = component.getBorder(); - if (!CSSConstants.isUndefined((topPadding = padding.get(Spacing.TOP)))) { + if (!CSSConstants.isUndefined((topPadding = padding.get(CSSShorthand.EDGE.TOP)))) { rawHeight -= topPadding; } - if (!CSSConstants.isUndefined((bottomPadding = padding.get(Spacing.BOTTOM)))) { + if (!CSSConstants.isUndefined((bottomPadding = padding.get(CSSShorthand.EDGE.BOTTOM)))) { rawHeight -= bottomPadding; } - if (!CSSConstants.isUndefined(topBorder = border.get(Spacing.TOP))) { + if (!CSSConstants.isUndefined(topBorder = border.get(CSSShorthand.EDGE.TOP))) { rawHeight -= topBorder; } - if (!CSSConstants.isUndefined(bottomBorder = border.get(Spacing.BOTTOM))) { + if (!CSSConstants.isUndefined(bottomBorder = border.get(CSSShorthand.EDGE.BOTTOM))) { rawHeight -= bottomBorder; } return rawHeight; } + + public static float getContentWidth( + @NonNull CSSShorthand padding, + @NonNull CSSShorthand border, + float layoutWidth){ + float leftPadding, rightPadding, leftBorder, rightBorder; + + if (!CSSConstants.isUndefined((leftPadding = padding.get(EDGE.LEFT)))) { + layoutWidth -= leftPadding; + } + if (!CSSConstants.isUndefined((rightPadding = padding.get(EDGE.RIGHT)))) { + layoutWidth -= rightPadding; + } + + if (!CSSConstants.isUndefined(leftBorder = border.get(EDGE.LEFT))) { + layoutWidth -= leftBorder; + } + if (!CSSConstants.isUndefined(rightBorder = border.get(EDGE.RIGHT))) { + layoutWidth -= rightBorder; + } + return layoutWidth; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXExceptionUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXExceptionUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXExceptionUtils.java index c571ba2..26a4980 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXExceptionUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXExceptionUtils.java @@ -42,74 +42,74 @@ import java.util.Map; public class WXExceptionUtils { - /** - * degradeUrl for degrade case - */ - public static String degradeUrl = "BundleUrlDefaultDegradeUrl"; + /** + * degradeUrl for degrade case + */ + public static String degradeUrl = "BundleUrlDefaultDegradeUrl"; - /** - * commitCriticalExceptionRT eg:JsRuntime Exception or JsFramework Init Exception - * @param instanceId - * @param errCode - * @param function - * @param exception - * @param extParams - */ - public static void commitCriticalExceptionRT(@Nullable final String instanceId, - @Nullable final WXErrorCode errCode, - @Nullable final String function, - @Nullable final String exception, - @Nullable final Map<String,String> extParams ) { - IWXJSExceptionAdapter adapter = WXSDKManager.getInstance().getIWXJSExceptionAdapter(); - WXSDKInstance instance; - WXJSExceptionInfo exceptionCommit; - String bundleUrlCommit = "BundleUrlDefault"; - String instanceIdCommit = "InstanceIdDefalut"; - String exceptionMsgCommit = exception; - Map<String, String> commitMap = extParams; - if (null == commitMap){ - commitMap = new HashMap<>(); - } - commitMap.put("activity","empty"); + /** + * commitCriticalExceptionRT eg:JsRuntime Exception or JsFramework Init Exception + * @param instanceId + * @param errCode + * @param function + * @param exception + * @param extParams + */ + public static void commitCriticalExceptionRT(@Nullable final String instanceId, + @Nullable final WXErrorCode errCode, + @Nullable final String function, + @Nullable final String exception, + @Nullable final Map<String,String> extParams ) { + IWXJSExceptionAdapter adapter = WXSDKManager.getInstance().getIWXJSExceptionAdapter(); + WXSDKInstance instance; + WXJSExceptionInfo exceptionCommit; + String bundleUrlCommit = "BundleUrlDefault"; + String instanceIdCommit = "InstanceIdDefalut"; + String exceptionMsgCommit = exception; + Map<String, String> commitMap = extParams; + if (null == commitMap){ + commitMap = new HashMap<>(); + } + commitMap.put("activity","empty"); - if (!TextUtils.isEmpty(instanceId)) { - instanceIdCommit = instanceId; - instance = WXSDKManager.getInstance().getSDKInstance(instanceId); + if (!TextUtils.isEmpty(instanceId)) { + instanceIdCommit = instanceId; + instance = WXSDKManager.getInstance().getSDKInstance(instanceId); - if (null != instance && instance.getContainerView() != null){ - Context c = instance.getContainerView().getContext(); - if (c instanceof Activity){ - commitMap.put("activity",c.getClass().getSimpleName()); - } - } + if (null != instance && instance.getContainerView() != null){ + Context c = instance.getContainerView().getContext(); + if (c instanceof Activity){ + commitMap.put("activity",c.getClass().getSimpleName()); + } + } - if (null != instance && instance.getContext() != null && instance.getBundleUrl() != null) { - bundleUrlCommit = instance.getBundleUrl(); - exceptionMsgCommit += "\n instance.getTemplateInfo()==" + instance.getTemplateInfo(); - if (TextUtils.isEmpty(bundleUrlCommit) || bundleUrlCommit.equals(WXPerformance.DEFAULT)) { - if (!TextUtils.equals(degradeUrl, "BundleUrlDefaultDegradeUrl")) { - bundleUrlCommit = degradeUrl; - } else - bundleUrlCommit = WXSDKInstance.requestUrl; - } - } - } else {//instance is null for instance id is null - if (!TextUtils.isEmpty(WXSDKInstance.requestUrl)) { - bundleUrlCommit = WXSDKInstance.requestUrl; - } - if (commitMap != null && commitMap.size() > 0) { - bundleUrlCommit = TextUtils.isEmpty(commitMap.get("weexUrl")) ? commitMap.get("weexUrl") - : commitMap.get("bundleUrl"); - } - } + if (null != instance && instance.getContext() != null && instance.getBundleUrl() != null) { + bundleUrlCommit = instance.getBundleUrl(); + exceptionMsgCommit += "\n instance.getTemplateInfo()==" + instance.getTemplateInfo(); + if (TextUtils.isEmpty(bundleUrlCommit) || bundleUrlCommit.equals(WXPerformance.DEFAULT)) { + if (!TextUtils.equals(degradeUrl, "BundleUrlDefaultDegradeUrl")) { + bundleUrlCommit = degradeUrl; + } else + bundleUrlCommit = WXSDKInstance.requestUrl; + } + } + } else {//instance is null for instance id is null + if (!TextUtils.isEmpty(WXSDKInstance.requestUrl)) { + bundleUrlCommit = WXSDKInstance.requestUrl; + } + if (commitMap != null && commitMap.size() > 0) { + bundleUrlCommit = TextUtils.isEmpty(commitMap.get("weexUrl")) ? commitMap.get("weexUrl") + : commitMap.get("bundleUrl"); + } + } - exceptionCommit = new WXJSExceptionInfo(instanceIdCommit, bundleUrlCommit, errCode, function, exceptionMsgCommit, commitMap); - if (adapter != null) { - adapter.onJSException(exceptionCommit); - } + exceptionCommit = new WXJSExceptionInfo(instanceIdCommit, bundleUrlCommit, errCode, function, exceptionMsgCommit, commitMap); + if (adapter != null) { + adapter.onJSException(exceptionCommit); + } - WXAnalyzerDataTransfer.transferError(exceptionCommit, instanceId); + WXAnalyzerDataTransfer.transferError(exceptionCommit, instanceId); - } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXJsonUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXJsonUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXJsonUtils.java index 7856a05..cb8e2a7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXJsonUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXJsonUtils.java @@ -25,9 +25,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import com.taobao.weex.WXEnvironment; -import com.taobao.weex.bridge.WXJSObject; import com.taobao.weex.common.WXRuntimeException; -import com.taobao.weex.wson.Wson; import java.util.ArrayList; import java.util.List; @@ -92,39 +90,4 @@ public class WXJsonUtils { } } } - - - /** - * total entry, with wson support, and can degrade to json - * */ - public static final Object parseWson(byte[] data){ - if(data == null){ - return null; - } - try{ - if(USE_WSON){ - return Wson.parse(data); - }else{ - return JSON.parse(new String(data, "UTF-8")); - } - }catch (Exception e){ - WXLogUtils.e("weex wson parse error ", e); - return null; - } - } - - - public static final WXJSObject wsonWXJSObject(Object tasks){ - //CompatibleUtils.checkDiff(tasks); - if(USE_WSON) { - return new WXJSObject(WXJSObject.WSON, Wson.toWson(tasks)); - }else{ - return new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks)); - } - } - /** - * config whether use json or wson, you should update this value by updateGlobalConfig(String config) - * in WXBridgeManager class method - * */ - public static boolean USE_WSON = true; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXLogUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXLogUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXLogUtils.java index b03fb95..44ea057 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXLogUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXLogUtils.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -72,21 +72,21 @@ public class WXLogUtils { } private static void log(String tag, String msg, LogLevel level){ - if(msg != null && tag != null && sLogWatcher !=null){ - sLogWatcher.onLog(level.getName(), tag, msg); - } + if(msg != null && tag != null && sLogWatcher !=null){ + sLogWatcher.onLog(level.getName(), tag, msg); + } - if (WXEnvironment.isApkDebugable()) { - Log.println(level.getPriority(),tag, msg); + if (WXEnvironment.isApkDebugable()) { + Log.println(level.getPriority(),tag, msg); // if not debug level then print log if(!level.getName().equals("debug")){ - writeConsoleLog(level.getName(), msg); - } + writeConsoleLog(level.getName(), msg); + } }else { - if(level.getPriority() - LogLevel.WARN.getPriority() >=0){ - Log.println(level.getPriority(),tag, msg); - } - } + if(level.getPriority() - LogLevel.WARN.getPriority() >=0){ + Log.println(level.getPriority(),tag, msg); + } + } } public static void d(String msg) { @@ -123,11 +123,11 @@ public class WXLogUtils { public static void d(String tag, String msg) { - if(!TextUtils.isEmpty(tag) && !TextUtils.isEmpty(msg)){ - log(tag, msg, LogLevel.DEBUG); + if(!TextUtils.isEmpty(tag) && !TextUtils.isEmpty(msg)){ + log(tag, msg, LogLevel.DEBUG); - if(WXEnvironment.isApkDebugable()){//sLogLevel in debug mode is "LogLevel.DEBUG" - if ("jsLog".equals(tag) && jsLogWatcherList != null && jsLogWatcherList.size() > 0) { + if(WXEnvironment.isApkDebugable()){//sLogLevel in debug mode is "LogLevel.DEBUG" + if ("jsLog".equals(tag) && jsLogWatcherList != null && jsLogWatcherList.size() > 0) { for (JsLogWatcher jsLogWatcher : jsLogWatcherList) { if (msg.endsWith("__DEBUG")) { jsLogWatcher.onJsLog(Log.DEBUG, msg.replace("__DEBUG", "")); @@ -141,20 +141,20 @@ public class WXLogUtils { jsLogWatcher.onJsLog(Log.DEBUG, msg); } } - } - - /** This log method will be invoked from jni code, so try to extract loglevel from message. **/ - writeConsoleLog("debug", tag + ":" + msg); - if(msg.contains(" | __")){ - String[] msgs=msg.split(" | __"); - LogLevel level; - if( msgs!=null && msgs.length==4 && !TextUtils.isEmpty(msgs[0]) && !TextUtils.isEmpty(msgs[2])){ - level=getLogLevel(msgs[2]); - return; - } - } - } - } + } + + /** This log method will be invoked from jni code, so try to extract loglevel from message. **/ + writeConsoleLog("debug", tag + ":" + msg); + if(msg.contains(" | __")){ + String[] msgs=msg.split(" | __"); + LogLevel level; + if( msgs!=null && msgs.length==4 && !TextUtils.isEmpty(msgs[0]) && !TextUtils.isEmpty(msgs[2])){ + level=getLogLevel(msgs[2]); + return; + } + } + } + } } private static LogLevel getLogLevel(String level) { @@ -220,12 +220,12 @@ public class WXLogUtils { } public static void w(String prefix, Throwable e) { - w(prefix + getStackTrace(e)); + w(prefix + getStackTrace(e)); } public static void e(String prefix, Throwable e) { - e(prefix + getStackTrace(e)); + e(prefix + getStackTrace(e)); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXReflectionUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXReflectionUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXReflectionUtils.java index a3dff5e..31ecd2f 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXReflectionUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXReflectionUtils.java @@ -32,14 +32,14 @@ public class WXReflectionUtils { public static Object parseArgument(Type paramClazz, Object value) { if(value != null){ - if(value.getClass() == paramClazz){ - return value; - } - if(paramClazz instanceof Class){ - if( ((Class<?>) paramClazz).isAssignableFrom(value.getClass())) { - return value; - } + if(value.getClass() == paramClazz){ + return value; + } + if(paramClazz instanceof Class){ + if( ((Class<?>) paramClazz).isAssignableFrom(value.getClass())) { + return value; } + } } if (paramClazz == String.class) { return value instanceof String ? value : JSON.toJSONString(value); @@ -125,8 +125,8 @@ public class WXReflectionUtils { * @throws NoSuchMethodException */ public static void setProperty(Object bean, Field field, Object value) throws IllegalAccessException, - InvocationTargetException, - NoSuchMethodException { + InvocationTargetException, + NoSuchMethodException { if (bean == null || field == null) { return; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXResourceUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXResourceUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXResourceUtils.java index 8ebf2c7..105f7ad 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXResourceUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXResourceUtils.java @@ -22,6 +22,7 @@ import android.graphics.Color; import android.graphics.LinearGradient; import android.graphics.Shader; import android.support.annotation.NonNull; +import android.support.v4.util.LruCache; import android.util.Pair; import android.text.TextUtils; @@ -44,38 +45,38 @@ public class WXResourceUtils { private final static String RGB = "rgb"; private final static String RGBA = "rgba"; private final static SingleFunctionParser.FlatMapper<Integer> FUNCTIONAL_RGB_MAPPER = - new SingleFunctionParser.FlatMapper<Integer>() { - @Override - public Integer map(String raw) { - int color = WXUtils.parseUnitOrPercent(raw, COLOR_RANGE); - if (color < 0) { - color = 0; - } else if (color > COLOR_RANGE) { - color = COLOR_RANGE; - } - return color; - } - }; + new SingleFunctionParser.FlatMapper<Integer>() { + @Override + public Integer map(String raw) { + int color = WXUtils.parseUnitOrPercent(raw, COLOR_RANGE); + if (color < 0) { + color = 0; + } else if (color > COLOR_RANGE) { + color = COLOR_RANGE; + } + return color; + } + }; private final static SingleFunctionParser.NonUniformMapper<Number> FUNCTIONAL_RGBA_MAPPER = - new SingleFunctionParser.NonUniformMapper<Number>() { - @Override - public List<Number> map(List<String> raw) { - List<Number> result = new ArrayList<>(RGBA_SIZE); - int i, color; - for (i = 0; i < RGB_SIZE; i++) { - color = WXUtils.parseUnitOrPercent(raw.get(i), COLOR_RANGE); - if (color < 0) { - color = 0; - } else if (color > COLOR_RANGE) { - color = COLOR_RANGE; + new SingleFunctionParser.NonUniformMapper<Number>() { + @Override + public List<Number> map(List<String> raw) { + List<Number> result = new ArrayList<>(RGBA_SIZE); + int i, color; + for (i = 0; i < RGB_SIZE; i++) { + color = WXUtils.parseUnitOrPercent(raw.get(i), COLOR_RANGE); + if (color < 0) { + color = 0; + } else if (color > COLOR_RANGE) { + color = COLOR_RANGE; + } + result.add(color); + } + result.add(Float.valueOf(raw.get(i))); + return result; } - result.add(color); - } - result.add(Float.valueOf(raw.get(i))); - return result; - } - }; + }; static { colorMap.put("aliceblue", 0XFFF0F8FF); @@ -238,21 +239,28 @@ public class WXResourceUtils { } color = color.trim(); //remove non visible codes - int resultColor = defaultColor; - Pair<Boolean, Integer> result; - ColorConvertHandler[] handlers = ColorConvertHandler.values(); - for (ColorConvertHandler handler : handlers) { - try { - result = handler.handle(color); - if (result.first) { - resultColor = result.second; - break; + Integer cache = WXUtils.sCache.get(color); + if(cache!=null){ + return cache; + } + else { + int resultColor = defaultColor; + Pair<Boolean, Integer> result; + ColorConvertHandler[] handlers = ColorConvertHandler.values(); + for (ColorConvertHandler handler : handlers) { + try { + result = handler.handle(color); + if (result.first) { + resultColor = result.second; + WXUtils.sCache.put(color, resultColor); + break; + } + } catch (RuntimeException e) { + WXLogUtils.v("Color_Parser", WXLogUtils.getStackTrace(e)); } - } catch (RuntimeException e) { - WXLogUtils.v("Color_Parser", WXLogUtils.getStackTrace(e)); } + return resultColor; } - return resultColor; } /** @@ -267,9 +275,9 @@ public class WXResourceUtils { if (valueList != null && valueList.size() == 3) { float[] points = parseGradientDirection(valueList.get(0), width, height); Shader shader = new LinearGradient(points[0], points[1], - points[2], points[3], - getColor(valueList.get(1), Color.WHITE), getColor(valueList.get(2), Color.WHITE), - Shader.TileMode.REPEAT); + points[2], points[3], + getColor(valueList.get(1), Color.WHITE), getColor(valueList.get(2), Color.WHITE), + Shader.TileMode.REPEAT); return shader; } return null; @@ -398,7 +406,7 @@ public class WXResourceUtils { @NonNull Pair<Boolean, Integer> handle(String rawColor) { SingleFunctionParser<Integer> functionParser = new SingleFunctionParser<>(rawColor, FUNCTIONAL_RGB_MAPPER); List<Integer> rgb = functionParser.parse(RGB); - if (rgb.size() == RGB_SIZE) { + if (null != rgb && rgb.size() == RGB_SIZE) { return new Pair<>(Boolean.TRUE, Color.rgb(rgb.get(0), rgb.get(1), rgb.get(2))); } else { return new Pair<>(Boolean.FALSE, Color.TRANSPARENT); @@ -413,10 +421,10 @@ public class WXResourceUtils { List<Number> rgba = functionParser.parse(RGBA); if (rgba.size() == RGBA_SIZE) { return new Pair<>(Boolean.TRUE, Color.argb( - parseAlpha(rgba.get(3).floatValue()), - rgba.get(0).intValue(), - rgba.get(1).intValue(), - rgba.get(2).intValue())); + parseAlpha(rgba.get(3).floatValue()), + rgba.get(0).intValue(), + rgba.get(1).intValue(), + rgba.get(2).intValue())); } else { return new Pair<>(Boolean.FALSE, Color.TRANSPARENT); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java index 7fc1009..c493937 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java @@ -23,13 +23,12 @@ import android.content.pm.ApplicationInfo; import android.os.Build; import android.text.TextUtils; +import com.taobao.weex.BuildConfig; import com.taobao.weex.IWXStatisticsListener; -import com.taobao.weappplus_sdk.BuildConfig; import com.taobao.weex.WXEnvironment; import com.taobao.weex.adapter.IWXSoLoaderAdapter; import com.taobao.weex.adapter.IWXUserTrackAdapter; import com.taobao.weex.common.WXErrorCode; -import com.taobao.weex.common.WXPerformance; import java.io.File; import java.io.FileInputStream; @@ -111,10 +110,10 @@ public class WXSoInstallMgrSdk { public static boolean initSo(String libName, int version, IWXUserTrackAdapter utAdapter) { String cpuType = _cpuType(); if (cpuType.equalsIgnoreCase(MIPS) ) { - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, - "initSo", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for android cpuType is MIPS", - null); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, + "initSo", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for android cpuType is MIPS", + null); return false; } @@ -122,7 +121,7 @@ public class WXSoInstallMgrSdk { copyStartUpSo(); boolean InitSuc = false; - if (checkSoIsValid(libName, BuildConfig.ARMEABI_Size) ||checkSoIsValid(libName, BuildConfig.X86_Size)) { +// if (checkSoIsValid(libName, BuildConfig.ARMEABI_Size) ||checkSoIsValid(libName, BuildConfig.X86_Size)) { /** * Load library with {@link System#loadLibrary(String)} @@ -139,11 +138,11 @@ public class WXSoInstallMgrSdk { InitSuc = true; } catch (Exception | Error e2) { if (cpuType.contains(ARMEABI) || cpuType.contains(X86)) { - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, - "initSo", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for android cpuType is " +cpuType + - "\n Detail Error is: " +e2.getMessage(), - null); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, + "initSo", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for android cpuType is " +cpuType + + "\n Detail Error is: " +e2.getMessage(), + null); } InitSuc = false; } @@ -179,7 +178,7 @@ public class WXSoInstallMgrSdk { InitSuc = false; e.printStackTrace(); } - } + // } return InitSuc; } @@ -294,11 +293,11 @@ public class WXSoInstallMgrSdk { } } }catch(Throwable e ){ - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, - "checkSoIsValid", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for " + - "weex so size check fail exception :"+e.getMessage(), - null); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, + "checkSoIsValid", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for " + + "weex so size check fail exception :"+e.getMessage(), + null); WXLogUtils.e("weex so size check fail exception :"+e.getMessage()); } @@ -373,20 +372,20 @@ public class WXSoInstallMgrSdk { } initSuc = true; } catch (Throwable e) { - initSuc = false; - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT, - "_loadUnzipSo", "[WX_KEY_EXCEPTION_SDK_INIT_WX_ERR_COPY_FROM_APK] " + - "\n Detail Msg is : " + e.getMessage(), - null); + initSuc = false; + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT, + "_loadUnzipSo", "[WX_KEY_EXCEPTION_SDK_INIT_WX_ERR_COPY_FROM_APK] " + + "\n Detail Msg is : " + e.getMessage(), + null); WXLogUtils.e("", e); } return initSuc; } static boolean unZipSelectedFiles(String libName, - int version, - IWXUserTrackAdapter utAdapter) throws ZipException, IOException { + int version, + IWXUserTrackAdapter utAdapter) throws ZipException, IOException { String sourcePath = "lib/armeabi/lib" + libName + ".so"; String zipPath = ""; @@ -420,7 +419,7 @@ public class WXSoInstallMgrSdk { //Copy file in = zf.getInputStream(entry); os = context.openFileOutput("lib" + libName + "bk" + version + ".so", - Context.MODE_PRIVATE); + Context.MODE_PRIVATE); channel = os.getChannel(); byte[] buffers = new byte[1024]; @@ -472,11 +471,11 @@ public class WXSoInstallMgrSdk { } } catch (java.io.IOException e) { e.printStackTrace(); - WXExceptionUtils.commitCriticalExceptionRT(null, - WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT, - "unZipSelectedFiles", "[WX_KEY_EXCEPTION_SDK_INIT_unZipSelectedFiles] " + - "\n Detail msg is: " + e.getMessage(), - null); + WXExceptionUtils.commitCriticalExceptionRT(null, + WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT, + "unZipSelectedFiles", "[WX_KEY_EXCEPTION_SDK_INIT_unZipSelectedFiles] " + + "\n Detail msg is: " + e.getMessage(), + null); } finally { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java index 66cb622..e3eac68 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.res.Configuration; import android.os.Looper; import android.support.annotation.Nullable; +import android.support.v4.util.LruCache; import android.text.TextUtils; import com.taobao.weex.WXEnvironment; import com.taobao.weex.common.Constants; @@ -30,6 +31,7 @@ import com.taobao.weex.common.WXConfig; public class WXUtils { + final static LruCache<String, Integer> sCache = new LruCache<>(64); public static final char PERCENT = '%'; private static final int HUNDRED =100; /** @@ -51,8 +53,8 @@ public class WXUtils { } String temp = value.toString().trim(); if (Constants.Name.AUTO.equals(temp) - || Constants.Name.UNDEFINED.equals(temp) - || TextUtils.isEmpty(temp)) { + || Constants.Name.UNDEFINED.equals(temp) + || TextUtils.isEmpty(temp)) { WXLogUtils.e("Argument Warning ! value is " + temp + "And default Value:" + Float.NaN); return Float.NaN; } @@ -97,8 +99,8 @@ public class WXUtils { String temp = value.toString().trim(); if(Constants.Name.AUTO.equals(temp) - || Constants.Name.UNDEFINED.equals(temp) - || TextUtils.isEmpty(temp)){ + || Constants.Name.UNDEFINED.equals(temp) + || TextUtils.isEmpty(temp)){ WXLogUtils.e("Argument Warning ! value is " + temp + "And default Value:"+Float.NaN); return df; } @@ -178,7 +180,7 @@ public class WXUtils { } } else{ - throw new NumberFormatException("Illegal separator"); + // throw new NumberFormatException("Illegal separator"); } } @@ -186,7 +188,8 @@ public class WXUtils { result*=-1; return result; } - throw new NumberFormatException("NullNumber"); + return 0; + // throw new NumberFormatException("NullNumber"); } /** @@ -199,6 +202,44 @@ public class WXUtils { return fastGetFloat(raw, Integer.MAX_VALUE); } + public static int parseInt(String value) { + try { + if (!TextUtils.isEmpty(value) && !value.contains(".")) { + return Integer.parseInt(value); + } + } catch (NumberFormatException e) { + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.e(WXLogUtils.getStackTrace(e)); + } + } + return 0; + } + + public static int parseInt(Object value) { + return parseInt(String.valueOf(value)); + } + + public static float parseFloat(Object value) { + return parseFloat(String.valueOf(value)); + } + + public static float parseFloat(String value) { + try { + if (!TextUtils.isEmpty(value) && !TextUtils.equals(value, "null")) { + return Float.parseFloat(value); + } else { + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.e("WXUtils parseFloat illegal value is " + value); + } + } + } catch (NumberFormatException e) { + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.e(WXLogUtils.getStackTrace(e)); + } + } + return 0; + } + public static int getInt(Object value) { return getInteger(value, 0); } @@ -209,43 +250,68 @@ public class WXUtils { return df; } - try { - return (Integer) value; - } catch (ClassCastException cce) { - String temp = value.toString().trim(); + String temp = value.toString().trim(); + String key = temp; + Integer cache = sCache.get(key); + if (cache != null) { + return cache; + } else { + Integer ret = df; + String suffix = ""; + if (temp.length() >= 2) { + suffix = temp.substring(temp.length() - 2, temp.length()); + } - if (temp.endsWith("wx")) { + if (TextUtils.equals("wx", suffix)) { if (WXEnvironment.isApkDebugable()) { - WXLogUtils.w("the value of " + value + " use wx unit, which will be not supported soon after."); + WXLogUtils + .w("the value of " + value + + " use wx unit, which will be not supported soon after."); } try { - return (int) transferWx(temp, 750); + ret = (int)transferWx(temp, 750); } catch (NumberFormatException e) { WXLogUtils.e("Argument format error! value is " + value, e); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } - }else if (temp.endsWith("px")) { + } else if (TextUtils.equals("px", suffix)) { try { - temp = temp.substring(0, temp.indexOf("px")); - return Integer.parseInt(temp); + temp = temp.substring(0, temp.length() - 2); + if (!TextUtils.isEmpty(temp) && temp.contains(".")) { + ret = (int)WXUtils.parseFloat(temp); + } else { + ret = Integer.parseInt(temp); + } } catch (NumberFormatException nfe) { WXLogUtils.e("Argument format error! value is " + value, nfe); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } - }else { + } else { try { - return Integer.parseInt(temp); + if (!TextUtils.isEmpty(temp)) { + if (temp.contains(".")) { + ret = (int)WXUtils.parseFloat(temp); + } else { + ret = Integer.parseInt(temp); + } + } else { + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.e("Argument value is null, df is" + df); + } + } } catch (NumberFormatException nfe) { WXLogUtils.e("Argument format error! value is " + value, nfe); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } } + if (!ret.equals(df)) { + sCache.put(key, ret); + } + return ret; } - - return df; } /** @@ -389,7 +455,7 @@ public class WXUtils { return parsePercent(raw.substring(0, suffix), unit); } else { - return Integer.parseInt(raw); + return WXUtils.parseInt(raw); } } @@ -420,12 +486,12 @@ public class WXUtils { int offsetCountBegin = content.indexOf(commentBegin); if (offsetCountBegin == -1) { - return null; + return null; } offsetCountBegin += commentBegin.length(); int offsetCountEnd = indexLineBreak(content, offsetCountBegin); if (offsetCountEnd == -1) { - return null; + return null; } String countStr = content.substring(offsetCountBegin, offsetCountEnd); int count = Integer.parseInt(countStr); @@ -433,7 +499,7 @@ public class WXUtils { String commentBody = content.substring(offsetCountEnd + 1, offsetCountEnd + 1 + count); int offsetBodyEnd = commentBody.lastIndexOf(commentEnd); if (offsetBodyEnd == -1) { - return null; + return null; } commentBody = commentBody.substring(0, offsetBodyEnd); @@ -441,45 +507,46 @@ public class WXUtils { String[] items = splitLineBreak(commentBody); for (String item : items) { - commentBodyBuilder.append(item.replaceFirst(asteriskRegex, replacement)); + commentBodyBuilder.append(item.replaceFirst(asteriskRegex, replacement)); } return commentBodyBuilder.toString(); -} + } -private static int indexLineBreak(String str, int fromIndex) { + private static int indexLineBreak(String str, int fromIndex) { final String lineBreakIos = "\r"; final String lineBreakUnix = "\n"; final String linebreakWin = "\r\n"; int index = str.indexOf(lineBreakIos, fromIndex); if (index == -1) { - index = str.indexOf(lineBreakUnix, fromIndex); + index = str.indexOf(lineBreakUnix, fromIndex); } if (index == -1) { - index = str.indexOf(linebreakWin, fromIndex); + index = str.indexOf(linebreakWin, fromIndex); } return index; -} + } -private static String[] splitLineBreak(String str) { + private static String[] splitLineBreak(String str) { final String lineBreakIos = "\r"; final String lineBreakUnix = "\n"; final String linebreakWin = "\r\n"; String[] items = str.split(lineBreakIos); if (items.length == 1) { - items = str.split(lineBreakUnix); + items = str.split(lineBreakUnix); } if (items.length == 1) { - items = str.split(linebreakWin); + items = str.split(linebreakWin); } return items; -} + } + /** * get number * */ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java index 3a9f73b..a654cf2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java @@ -76,6 +76,7 @@ public class WXViewUtils { public static final int DIMENSION_UNSET = -1; private static final boolean mUseWebPx = false; + private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); @SuppressLint("NewApi") @@ -138,7 +139,7 @@ public class WXViewUtils { @Deprecated public static int setScreenWidth(int screenWidth) { - return mScreenWidth = screenWidth; + return mScreenWidth = screenWidth; } public static float getScreenDensity(Context ctx){ @@ -177,7 +178,7 @@ public class WXViewUtils { public static int getScreenHeight(Context cxt) { if(cxt!=null){ - mScreenHeight =cxt.getResources().getDisplayMetrics().heightPixels; + mScreenHeight =cxt.getResources().getDisplayMetrics().heightPixels; } else if (WXEnvironment.isApkDebugable()){ throw new WXRuntimeException("Error Context is null When getScreenHeight"); } @@ -196,7 +197,7 @@ public class WXViewUtils { @Deprecated public static float getRealPxByWidth(float pxValue) { - return getRealPxByWidth(pxValue,750); + return getRealPxByWidth(pxValue,750); } public static float getRealPxByWidth(float pxValue,int customViewport) { if (Float.isNaN(pxValue)) { @@ -294,7 +295,7 @@ public class WXViewUtils { float scale = 2; try { scale = WXEnvironment.getApplication().getResources() - .getDisplayMetrics().density; + .getDisplayMetrics().density; } catch (Exception e) { WXLogUtils.e("[WXViewUtils] dip2px:", e); } @@ -318,7 +319,7 @@ public class WXViewUtils { } return (p[1] > 0 && (p[1] - WXViewUtils.getScreenHeight(WXEnvironment.sApplication) < 0)) - || (viewH + p[1] > 0 && p[1] <= 0); + || (viewH + p[1] > 0 && p[1] <= 0); } /** @@ -383,13 +384,13 @@ public class WXViewUtils { public static void clipCanvasWithinBorderBox(View targetView, Canvas canvas) { Drawable drawable; if (clipCanvasDueToAndroidVersion(canvas) && - clipCanvasIfAnimationExist(targetView) && - ((drawable = targetView.getBackground()) instanceof BorderDrawable)) { + clipCanvasIfAnimationExist(targetView) && + ((drawable = targetView.getBackground()) instanceof BorderDrawable)) { BorderDrawable borderDrawable = (BorderDrawable) drawable; if (borderDrawable.isRounded()) { if (clipCanvasIfBackgroundImageExist(targetView, borderDrawable)) { Path path = borderDrawable.getContentPath( - new RectF(0, 0, targetView.getWidth(), targetView.getHeight())); + new RectF(0, 0, targetView.getWidth(), targetView.getHeight())); canvas.clipPath(path); } } @@ -399,12 +400,12 @@ public class WXViewUtils { public static void clipCanvasWithinBorderBox(Widget widget, Canvas canvas) { BorderDrawable borderDrawable; if (clipCanvasDueToAndroidVersion(canvas) && - clipCanvasIfAnimationExist(null) && - (borderDrawable=widget.getBackgroundAndBorder())!=null ) { + clipCanvasIfAnimationExist(null) && + (borderDrawable=widget.getBackgroundAndBorder())!=null ) { if (borderDrawable.isRounded() && clipCanvasIfBackgroundImageExist(widget, borderDrawable)) { - Path path = borderDrawable.getContentPath( - new RectF(0, 0, widget.getBorderBox().width(), widget.getBorderBox().height())); - canvas.clipPath(path); + Path path = borderDrawable.getContentPath( + new RectF(0, 0, widget.getBorderBox().width(), widget.getBorderBox().height())); + canvas.clipPath(path); } else { canvas.clipRect(widget.getBorderBox()); @@ -420,7 +421,7 @@ public class WXViewUtils { */ private static boolean clipCanvasDueToAndroidVersion(Canvas canvas) { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 || - !canvas.isHardwareAccelerated(); + !canvas.isHardwareAccelerated(); } /** @@ -455,8 +456,8 @@ public class WXViewUtils { for (int i = 0; i < count; i++) { child = parent.getChildAt(i); if (child.getBackground() instanceof BorderDrawable && - ((BorderDrawable) child.getBackground()).hasImage() && - Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + ((BorderDrawable) child.getBackground()).hasImage() && + Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } } @@ -465,11 +466,11 @@ public class WXViewUtils { } private static boolean clipCanvasIfBackgroundImageExist(@NonNull Widget widget, - @NonNull BorderDrawable borderDrawable) { + @NonNull BorderDrawable borderDrawable) { if (widget instanceof WidgetGroup) { for (Widget child : ((WidgetGroup) widget).getChildren()) { if (child.getBackgroundAndBorder().hasImage() && - Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } }
