Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/pr586' into apache-0.16-dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	android/sdk/libs/x86/libweexjsc.so
  • Loading branch information
misakuo committed Aug 15, 2017
2 parents 71b0792 + 57802c0 commit 2074156
Show file tree
Hide file tree
Showing 97 changed files with 10,990 additions and 8,674 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ matrix:
components:
- platform-tools
- tools
- build-tools-23.0.3
- android-23
- build-tools-25.0.3
- android-25
- extra-google-m2repository
- extra-android-m2repository
- sys-img-armeabi-v7a-android-22
Expand Down Expand Up @@ -77,8 +77,8 @@ before_script:
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools
echo yes | sdkmanager platform-tools
echo yes | sdkmanager tools #tools
echo yes | sdkmanager "build-tools;23.0.3" #build-tool
echo yes | sdkmanager "platforms;android-23" #compile target
echo yes | sdkmanager "build-tools;25.0.3" #build-tool
echo yes | sdkmanager "platforms;android-25" #compile target
echo yes | sdkmanager "extras;android;m2repository" #support
fi
script:
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ subprojects {
}
}
ext {
compileSdkVersion=23
buildToolsVersion="23.0.3"
compileSdkVersion=25
buildToolsVersion="25.0.3"
minSdkVersion=14
appMinSdkVersion=15
targetSdkVersion=23
supportLibVersion="23.4.0"
targetSdkVersion=25
supportLibVersion="25.3.1"
fastjsonLibVersion="1.1.46.android"
}
}
Expand Down
Binary file modified android/sdk/libs/x86/libweexjsc.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public interface Name {
String OFFSET_X_ACCURACY = "offsetXAccuracy";
String OFFSET_X_RATIO = "offsetXRatio";
String ELEVATION = "elevation";
String PERSPECTIVE = "perspective";
String SCROLLABLE = "scrollable";
String DRAGGABLE = "draggable";
String DISTANCE_Y = "dy";
Expand All @@ -169,6 +170,8 @@ public interface Name {
String OFFSET = "offset";
String ANIMATED = "animated";
String STABLE = "stable";
String TRANSFORM = "transform";
String TRANSFORM_ORIGIN = "transformOrigin";

String INSERT_CELL_ANIMATION = "insertAnimation";
String DELETE_CELL_ANIMATION = "deleteAnimation";
Expand Down
15 changes: 13 additions & 2 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.bridge.WXValidateProcessor;
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.Constants.Name;
import com.taobao.weex.dom.flex.CSSLayoutContext;
import com.taobao.weex.dom.flex.CSSNode;
import com.taobao.weex.dom.flex.Spacing;
Expand All @@ -54,8 +55,18 @@ public class WXDomObject extends CSSNode implements Cloneable,ImmutableDomObject
public static final String TYPE = "type";
public static final String TAG = WXDomObject.class.getSimpleName();
public static final String ROOT = "_root";
public static final String TRANSFORM = "transform";
public static final String TRANSFORM_ORIGIN = "transformOrigin";

/**
* Use {@link Name#TRANSFORM} instead.
*/
@Deprecated
public static final String TRANSFORM = Name.TRANSFORM;

/**
* Use {@link Name#TRANSFORM_ORIGIN} instead.
*/
@Deprecated
public static final String TRANSFORM_ORIGIN = Name.TRANSFORM_ORIGIN;
static final WXDomObject DESTROYED = new WXDomObject();
static{
DESTROYED.mRef = "_destroyed";
Expand Down
91 changes: 60 additions & 31 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXTextDomObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
*/
package com.taobao.weex.dom;

import static com.taobao.weex.dom.WXStyle.UNSET;

import android.graphics.Canvas;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.AlignmentSpan;
import android.text.style.ForegroundColorSpan;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.common.Constants;
import com.taobao.weex.dom.flex.CSSConstants;
Expand All @@ -45,15 +49,12 @@
import com.taobao.weex.utils.WXDomUtils;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXResourceUtils;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static com.taobao.weex.dom.WXStyle.UNSET;

/**
* Class for calculating a given text's height and width. The calculating of width and height of
* text is done by {@link Layout}.
Expand Down Expand Up @@ -299,7 +300,7 @@ Layout createLayout(float width, boolean forceWidth, @Nullable Layout previousLa
Layout layout;
if (!FloatUtil.floatsEqual(previousWidth, textWidth) || previousLayout == null) {
layout = new StaticLayout(spanned, mTextPaint, (int) Math.ceil(textWidth),
Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
} else {
layout = previousLayout;
}
Expand All @@ -308,37 +309,65 @@ Layout createLayout(float width, boolean forceWidth, @Nullable Layout previousLa
lastLineStart = layout.getLineStart(mNumberOfLines - 1);
lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
if (lastLineStart < lastLineEnd) {
String text = mText.subSequence(0, lastLineStart).toString() +
truncate(mText.substring(lastLineStart, lastLineEnd),
mTextPaint, layout.getWidth(), textOverflow);
spanned = createSpanned(text);
SpannableStringBuilder builder = new SpannableStringBuilder(spanned.subSequence(0, lastLineStart));
Editable lastLine = new SpannableStringBuilder(spanned.subSequence(lastLineStart, lastLineEnd));
builder.append(truncate(lastLine, mTextPaint, layout.getWidth(), textOverflow));
adjustSpansRange(spanned, builder);
spanned = builder;
return new StaticLayout(spanned, mTextPaint, (int) Math.ceil(textWidth),
Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
}
}
return layout;
}

public @NonNull String truncate(@Nullable String source, @NonNull TextPaint paint,
int desired, @Nullable TextUtils.TruncateAt truncateAt){
if(!TextUtils.isEmpty(source)){
StringBuilder builder;
Spanned spanned;
/**
* Truncate the source span to the specified lines.
* Caller of this method must ensure that the lines of text is <strong>greater than desired lines and need truncate</strong>.
* Otherwise, unexpected behavior may happen.
* @param source The source span.
* @param paint the textPaint
* @param desired specified lines.
* @param truncateAt truncate method, null value means clipping overflow text directly, non-null value means using ellipsis strategy to clip
* @return The spans after clipped.
*/
private
@NonNull
Spanned truncate(@Nullable Editable source, @NonNull TextPaint paint,
int desired, @Nullable TextUtils.TruncateAt truncateAt) {
Spanned ret = new SpannedString("");
if (!TextUtils.isEmpty(source) && source.length() > 0) {
StaticLayout layout;
for(int i=source.length();i>0;i--){
builder=new StringBuilder(i+1);
builder.append(source, 0, i);
if(truncateAt!=null){
builder.append(ELLIPSIS);
}
spanned = createSpanned(builder.toString());
layout = new StaticLayout(spanned, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
if(layout.getLineCount()<=1){
return spanned.toString();
if (truncateAt != null) {
source.append(ELLIPSIS);
}
while (source.length() > 1) {
source.delete(source.length() - 2, source.length() - 1);
layout = new StaticLayout(source, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
if (layout.getLineCount() <= 1) {
ret = source;
break;
}
}
}
return "";
return ret;
}

/**
* Adjust span range after truncate due to the wrong span range during span copy and slicing.
* @param beforeTruncate The span before truncate
* @param afterTruncate The span after truncate
*/
private void adjustSpansRange(@NonNull Spanned beforeTruncate, @NonNull Spannable afterTruncate){
Object[] spans = beforeTruncate.getSpans(0, beforeTruncate.length(), Object.class);
for(Object span:spans){
int start = beforeTruncate.getSpanStart(span);
int end = beforeTruncate.getSpanEnd(span);
if(start == 0 && end == beforeTruncate.length()){
afterTruncate.removeSpan(span);
afterTruncate.setSpan(span, 0, afterTruncate.length(), beforeTruncate.getSpanFlags(span));
}
}
}

/**
Expand All @@ -350,7 +379,7 @@ Layout createLayout(float width, boolean forceWidth, @Nullable Layout previousLa
* @return if forceToDesired is false, it will be the minimum value of the width of text and
* outerWidth in case of outerWidth is defined, in other case, it will be outer width.
*/
/** package **/ float getTextWidth(TextPaint textPaint,float outerWidth, boolean forceToDesired) {
float getTextWidth(TextPaint textPaint,float outerWidth, boolean forceToDesired) {
float textWidth;
if (forceToDesired) {
textWidth = outerWidth;
Expand Down Expand Up @@ -385,7 +414,7 @@ protected void updateSpannable(Spannable spannable, int spanFlag) {
List<SetSpanOperation> ops = createSetSpanOperation(spannable.length(), spanFlag);
if (mFontSize == UNSET) {
ops.add(new SetSpanOperation(0, spannable.length(),
new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), spanFlag));
new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), spanFlag));
}
Collections.reverse(ops);
for (SetSpanOperation op : ops) {
Expand All @@ -408,7 +437,7 @@ private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) {
}
if (mIsColorSet) {
ops.add(new SetSpanOperation(start, end,
new ForegroundColorSpan(mColor), spanFlag));
new ForegroundColorSpan(mColor), spanFlag));
}
if (mFontSize != UNSET) {
ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag));
Expand All @@ -417,8 +446,8 @@ private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) {
|| mFontWeight != UNSET
|| mFontFamily != null) {
ops.add(new SetSpanOperation(start, end,
new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily),
spanFlag));
new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily),
spanFlag));
}
ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag));
if (mLineHeight != UNSET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXCompone
if (interpolator != null) {
animator.setInterpolator(interpolator);
}
component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance());
animator.setDuration(mAnimationBean.duration);
animator.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.taobao.weex.bridge.SimpleJSCallback;
import com.taobao.weex.dom.RenderAction;
import com.taobao.weex.dom.RenderActionContext;
import com.taobao.weex.ui.component.ContentMeasurable;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.utils.WXViewUtils;

Expand Down Expand Up @@ -74,6 +75,17 @@ public void executeRender(RenderActionContext context) {
size.put("top", getWebPxValue(sizes.top,viewPort));
options.put("size", size);
options.put("result", true);

if (component instanceof ContentMeasurable) {
Rect contentFrame = ((ContentMeasurable) component).getContentFrame();
if (contentFrame != null) {
Map<String, Float> contentSize = new HashMap<>(2);
contentSize.put("width", getWebPxValue(contentFrame.width(), viewPort));
contentSize.put("height", getWebPxValue(contentFrame.height(), viewPort));
options.put("contentSize", contentSize);
}
}

} else {
options.put("errMsg", "Component does not exist");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.ui.animation;

import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.util.Property;
import android.view.View;


class CameraDistanceProperty extends Property<View, Float> {

private final static String TAG = "CameraDistance";
private static CameraDistanceProperty instance;

static Property<View, Float> getInstance(){
return instance;
}

private CameraDistanceProperty() {
super(Float.class, TAG);
}

@Override
public Float get(View view) {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
return view.getCameraDistance();
}
else{
return Float.NaN;
}
}

@Override
public void set(View object, Float value) {
object.setCameraDistance(value);
}
}
Loading

0 comments on commit 2074156

Please sign in to comment.