Skip to content

Commit

Permalink
see 10/25 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Oct 25, 2018
1 parent b9b1a1a commit 3155dcd
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png

[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.21.1-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.21.2-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen

[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png

[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.21.1-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.21.2-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.BlurMaskFilter;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
Expand Down Expand Up @@ -56,7 +61,7 @@ public class SpanActivity extends BaseBackActivity {

float density;
TextView tvAboutSpan;
TextView tvAboutAnimRainbow;
TextView tvAboutAnimSpan;

public static void start(Context context) {
Intent starter = new Intent(context, SpanActivity.class);
Expand Down Expand Up @@ -91,7 +96,7 @@ public void updateDrawState(TextPaint ds) {
};

tvAboutSpan = findViewById(R.id.tv_about_span);
tvAboutAnimRainbow = findViewById(R.id.tv_about_anim_span);
tvAboutAnimSpan = findViewById(R.id.tv_about_anim_span);

// 响应点击事件的话必须设置以下属性
tvAboutSpan.setMovementMethod(LinkMovementMethod.getInstance());
Expand All @@ -101,58 +106,11 @@ public void updateDrawState(TextPaint ds) {
textSize = tvAboutSpan.getTextSize();
density = getResources().getDisplayMetrics().density;

// initAnimSpan();
// startAnim();
initAnimSpan();
startAnim();


tvAboutSpan.setText(new SpanUtils()
// .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER)
// .appendLine("前景色").setForegroundColor(Color.GREEN)
// .appendLine("背景色").setBackgroundColor(Color.LTGRAY)
// .appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN)
// .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY)
// .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN)
// .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN)
// .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY)
// .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN)
// .appendLine("32dp 字体").setFontSize(32, true)
// .appendLine("2 倍字体").setFontProportion(2)
// .appendLine("横向 2 倍字体").setFontXProportion(1.5f)
// .appendLine("删除线").setStrikethrough()
// .appendLine("下划线").setUnderline()
// .append("测试").appendLine("上标").setSuperscript()
// .append("测试").appendLine("下标").setSubscript()
// .appendLine("粗体").setBold()
// .appendLine("斜体").setItalic()
// .appendLine("粗斜体").setBoldItalic()
// .appendLine("monospace 字体").setFontFamily("monospace")
// .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf"))
// .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE)
// .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER)
// .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL)
// .append("测试").appendLine("点击事件").setClickSpan(clickableSpan)
// .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode")
// .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL)
// .appendLine("颜色渐变").setShader(new LinearGradient(0, 0,
// 64 * density * 4, 0,
// getResources().getIntArray(R.array.rainbow),
// null,
// Shader.TileMode.REPEAT)).setFontSize(64, true)
// .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.span_cheetah),
// Shader.TileMode.REPEAT,
// Shader.TileMode.REPEAT))
// .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE)
//
// .append("小图").setBackgroundColor(Color.GREEN)
// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP)
// .append("顶部").setBackgroundColor(Color.GREEN)
// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER)
// .append("居中").setBackgroundColor(Color.GREEN)
// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE)
// .append("底部").setBackgroundColor(Color.GREEN)
// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM)
// .appendLine("对齐").setBackgroundColor(Color.GREEN)

.appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP)
.append("大图").setBackgroundColor(Color.LTGRAY)
.appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP)
Expand All @@ -174,6 +132,53 @@ public void updateDrawState(TextPaint ds) {
.appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM)
.appendLine("对齐").setBackgroundColor(Color.LTGRAY)

.appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER)
.appendLine("前景色").setForegroundColor(Color.GREEN)
.appendLine("背景色").setBackgroundColor(Color.LTGRAY)
.appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN)
.appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY)
.appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN)
.appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN)
.appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY)
.appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN)
.appendLine("32dp 字体").setFontSize(32, true)
.appendLine("2 倍字体").setFontProportion(2)
.appendLine("横向 2 倍字体").setFontXProportion(1.5f)
.appendLine("删除线").setStrikethrough()
.appendLine("下划线").setUnderline()
.append("测试").appendLine("上标").setSuperscript()
.append("测试").appendLine("下标").setSubscript()
.appendLine("粗体").setBold()
.appendLine("斜体").setItalic()
.appendLine("粗斜体").setBoldItalic()
.appendLine("monospace 字体").setFontFamily("monospace")
.appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf"))
.appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE)
.appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER)
.appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL)
.append("测试").appendLine("点击事件").setClickSpan(clickableSpan)
.append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode")
.append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL)
.appendLine("颜色渐变").setShader(new LinearGradient(0, 0,
64 * density * 4, 0,
getResources().getIntArray(R.array.rainbow),
null,
Shader.TileMode.REPEAT)).setFontSize(64, true)
.appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.span_cheetah),
Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT))
.appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE)

.append("小图").setBackgroundColor(Color.GREEN)
.appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP)
.append("顶部").setBackgroundColor(Color.GREEN)
.appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER)
.append("居中").setBackgroundColor(Color.GREEN)
.appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE)
.append("底部").setBackgroundColor(Color.GREEN)
.appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM)
.appendLine("对齐").setBackgroundColor(Color.GREEN)

.append("测试空格").appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN).appendSpace(100).appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN)
.create());
}
Expand Down Expand Up @@ -234,7 +239,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
mForegroundAlphaColorSpanGroup.setAlpha((Float) animation.getAnimatedValue());

// update
tvAboutAnimRainbow.setText(animSsb);
tvAboutAnimSpan.setText(animSsb);
}
});

Expand Down
6 changes: 3 additions & 3 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ext {
compileSdkVersion: 27,
minSdkVersion : 14,
targetSdkVersion : 27,
versionCode : 1_021_001,
versionName : '1.21.1'// E.g. 1.9.72 => 1,009,072
versionCode : 1_021_002,
versionName : '1.21.2'// E.g. 1.9.72 => 1,009,072
]

versionConfig = [
Expand Down Expand Up @@ -177,7 +177,7 @@ def configAppDependencies(Project pro) {
// LeakCanary
debugImplementation depConfig.leakcanary.android
releaseImplementation depConfig.leakcanary.android_no_op
// implementation 'com.blankj:utilcode:1.21.1'
// implementation 'com.blankj:utilcode:1.21.2'
}
}

Expand Down
1 change: 1 addition & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* `18/10/25` [fix] SpanUtils#setLineHeight bug of multi lines. Publish v1.21.2.
* `18/10/24` [fix] SpanUtils#appendImage on VIVO. Publish v1.21.1.
* `18/10/16` [add] BusUtils, DeviceUtils#isAdbEnabled. Publish v1.21.0.
* `18/09/29` [fix] ToastUtils which causes crash in the some devices of Xiaomi. Publish v1.20.4.
Expand Down
2 changes: 1 addition & 1 deletion utilcode/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.21.1'
implementation 'com.blankj:utilcode:1.21.2'
```


Expand Down
2 changes: 1 addition & 1 deletion utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.21.1'
implementation 'com.blankj:utilcode:1.21.2'
```


Expand Down
36 changes: 18 additions & 18 deletions utilcode/src/main/java/com/blankj/utilcode/util/SpanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,27 +915,27 @@ class CustomLineHeightSpan extends CharacterStyle
public void chooseHeight(final CharSequence text, final int start, final int end,
final int spanstartv, final int v, final Paint.FontMetricsInt fm) {
int need = height - (v + fm.descent - fm.ascent - spanstartv);
// if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.descent += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.descent += need / 2;
fm.ascent -= need / 2;
} else {
fm.ascent -= need;
if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.descent += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.descent += need / 2;
fm.ascent -= need / 2;
} else {
fm.ascent -= need;
}
}
// }
need = height - (v + fm.bottom - fm.top - spanstartv);
// if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.top += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.bottom += need / 2;
fm.top -= need / 2;
} else {
fm.top -= need;
if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.top += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.bottom += need / 2;
fm.top -= need / 2;
} else {
fm.top -= need;
}
}
// }
}

@Override
Expand Down

0 comments on commit 3155dcd

Please sign in to comment.