|
3 | 3 | import android.animation.ValueAnimator;
|
4 | 4 | import android.content.Context;
|
5 | 5 | import android.content.Intent;
|
6 |
| -import android.graphics.BitmapFactory; |
7 |
| -import android.graphics.BitmapShader; |
8 |
| -import android.graphics.BlurMaskFilter; |
9 | 6 | import android.graphics.Color;
|
10 | 7 | import android.graphics.LinearGradient;
|
11 | 8 | import android.graphics.Matrix;
|
12 | 9 | import android.graphics.Shader;
|
13 |
| -import android.graphics.Typeface; |
14 | 10 | import android.os.Bundle;
|
15 | 11 | import android.support.annotation.Nullable;
|
16 | 12 | import android.support.v4.content.ContextCompat;
|
17 |
| -import android.text.Layout; |
18 | 13 | import android.text.SpannableStringBuilder;
|
19 | 14 | import android.text.TextPaint;
|
20 | 15 | import android.text.method.LinkMovementMethod;
|
@@ -106,80 +101,84 @@ public void updateDrawState(TextPaint ds) {
|
106 | 101 | textSize = tvAboutSpan.getTextSize();
|
107 | 102 | density = getResources().getDisplayMetrics().density;
|
108 | 103 |
|
109 |
| - initAnimSpan(); |
110 |
| - startAnim(); |
| 104 | +// initAnimSpan(); |
| 105 | +// startAnim(); |
111 | 106 |
|
112 | 107 |
|
113 | 108 | tvAboutSpan.setText(new SpanUtils()
|
114 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
115 |
| - .append("大图").setBackgroundColor(Color.LTGRAY) |
116 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
117 |
| - .append("顶部").setBackgroundColor(Color.LTGRAY) |
118 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
119 |
| - .appendLine("对齐").setBackgroundColor(Color.LTGRAY) |
120 |
| - |
121 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
122 |
| - .append("大图").setBackgroundColor(Color.GREEN) |
123 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
124 |
| - .append("居中").setBackgroundColor(Color.GREEN) |
125 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
126 |
| - .appendLine("对齐").setBackgroundColor(Color.GREEN) |
127 |
| - |
128 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
129 |
| - .append("大图").setBackgroundColor(Color.LTGRAY) |
130 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
131 |
| - .append("底部").setBackgroundColor(Color.LTGRAY) |
132 |
| - .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
133 |
| - .appendLine("对齐").setBackgroundColor(Color.LTGRAY) |
134 |
| - |
135 |
| - .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER) |
136 |
| - .appendLine("前景色").setForegroundColor(Color.GREEN) |
137 |
| - .appendLine("背景色").setBackgroundColor(Color.LTGRAY) |
138 |
| - .appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
139 |
| - .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
140 |
| - .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
141 |
| - .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN) |
142 |
| - .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY) |
143 |
| - .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN) |
144 |
| - .appendLine("32dp 字体").setFontSize(32, true) |
145 |
| - .appendLine("2 倍字体").setFontProportion(2) |
146 |
| - .appendLine("横向 2 倍字体").setFontXProportion(1.5f) |
147 |
| - .appendLine("删除线").setStrikethrough() |
148 |
| - .appendLine("下划线").setUnderline() |
149 |
| - .append("测试").appendLine("上标").setSuperscript() |
150 |
| - .append("测试").appendLine("下标").setSubscript() |
151 |
| - .appendLine("粗体").setBold() |
152 |
| - .appendLine("斜体").setItalic() |
153 |
| - .appendLine("粗斜体").setBoldItalic() |
154 |
| - .appendLine("monospace 字体").setFontFamily("monospace") |
155 |
| - .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf")) |
156 |
| - .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE) |
157 |
| - .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER) |
158 |
| - .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL) |
159 |
| - .append("测试").appendLine("点击事件").setClickSpan(clickableSpan) |
160 |
| - .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode") |
161 |
| - .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL) |
162 |
| - .appendLine("颜色渐变").setShader(new LinearGradient(0, 0, |
163 |
| - 64 * density * 4, 0, |
164 |
| - getResources().getIntArray(R.array.rainbow), |
165 |
| - null, |
166 |
| - Shader.TileMode.REPEAT)).setFontSize(64, true) |
167 |
| - .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.span_cheetah), |
168 |
| - Shader.TileMode.REPEAT, |
169 |
| - Shader.TileMode.REPEAT)) |
170 |
| - .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE) |
171 |
| - |
172 |
| - .append("小图").setBackgroundColor(Color.GREEN) |
173 |
| - .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP) |
174 |
| - .append("顶部").setBackgroundColor(Color.GREEN) |
175 |
| - .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER) |
176 |
| - .append("居中").setBackgroundColor(Color.GREEN) |
177 |
| - .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE) |
178 |
| - .append("底部").setBackgroundColor(Color.GREEN) |
179 |
| - .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM) |
180 |
| - .appendLine("对齐").setBackgroundColor(Color.GREEN) |
181 |
| - |
182 |
| - .append("测试空格").appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN).appendSpace(100).appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN) |
| 109 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
| 110 | +// .append("大图").setBackgroundColor(Color.LTGRAY) |
| 111 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
| 112 | +// .append("顶部").setBackgroundColor(Color.LTGRAY) |
| 113 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
| 114 | +// .appendLine("对齐").setBackgroundColor(Color.LTGRAY) |
| 115 | +// |
| 116 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
| 117 | +// .append("大图").setBackgroundColor(Color.GREEN) |
| 118 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
| 119 | +// .append("居中").setBackgroundColor(Color.GREEN) |
| 120 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
| 121 | +// .appendLine("对齐").setBackgroundColor(Color.GREEN) |
| 122 | +// |
| 123 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
| 124 | +// .append("大图").setBackgroundColor(Color.LTGRAY) |
| 125 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
| 126 | +// .append("底部").setBackgroundColor(Color.LTGRAY) |
| 127 | +// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
| 128 | +// .appendLine("对齐").setBackgroundColor(Color.LTGRAY) |
| 129 | +// |
| 130 | +// .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER) |
| 131 | +// .appendLine("前景色").setForegroundColor(Color.GREEN) |
| 132 | +// .appendLine("背景色").setBackgroundColor(Color.LTGRAY) |
| 133 | + .append("行高顶部对齐").setLineHeight(3 * lineHeight, SpanUtils.ALIGN_TOP).setFontSize(20).setBackgroundColor(Color.GREEN) |
| 134 | + .append("行高").setLineHeight(3 * lineHeight, SpanUtils.ALIGN_CENTER).setFontSize(40).setBackgroundColor(Color.LTGRAY) |
| 135 | + .appendLine("行高顶部").setLineHeight(3 * lineHeight, SpanUtils.ALIGN_BOTTOM).setFontSize(60).setBackgroundColor(Color.LTGRAY) |
| 136 | + .append("行高").setFontSize(100).setBackgroundColor(Color.GREEN) |
| 137 | + .append("行高").setFontSize(20).setBackgroundColor(Color.LTGRAY).setUnderline().setVerticalAlign(SpanUtils.ALIGN_CENTER) |
| 138 | +// .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
| 139 | +// .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
| 140 | +// .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN) |
| 141 | +// .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY) |
| 142 | +// .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN) |
| 143 | +// .appendLine("32dp 字体").setFontSize(32, true) |
| 144 | +// .appendLine("2 倍字体").setFontProportion(2) |
| 145 | +// .appendLine("横向 2 倍字体").setFontXProportion(1.5f) |
| 146 | +// .appendLine("删除线").setStrikethrough() |
| 147 | +// .appendLine("下划线").setUnderline() |
| 148 | +// .append("测试").appendLine("上标").setSuperscript() |
| 149 | +// .append("测试").appendLine("下标").setSubscript() |
| 150 | +// .appendLine("粗体").setBold() |
| 151 | +// .appendLine("斜体").setItalic() |
| 152 | +// .appendLine("粗斜体").setBoldItalic() |
| 153 | +// .appendLine("monospace 字体").setFontFamily("monospace") |
| 154 | +// .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf")) |
| 155 | +// .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE) |
| 156 | +// .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER) |
| 157 | +// .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL) |
| 158 | +// .append("测试").appendLine("点击事件").setClickSpan(clickableSpan) |
| 159 | +// .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode") |
| 160 | +// .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL) |
| 161 | +// .appendLine("颜色渐变").setShader(new LinearGradient(0, 0, |
| 162 | +// 64 * density * 4, 0, |
| 163 | +// getResources().getIntArray(R.array.rainbow), |
| 164 | +// null, |
| 165 | +// Shader.TileMode.REPEAT)).setFontSize(64, true) |
| 166 | +// .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.span_cheetah), |
| 167 | +// Shader.TileMode.REPEAT, |
| 168 | +// Shader.TileMode.REPEAT)) |
| 169 | +// .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE) |
| 170 | +// |
| 171 | +// .append("小图").setBackgroundColor(Color.GREEN) |
| 172 | +// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP) |
| 173 | +// .append("顶部").setBackgroundColor(Color.GREEN) |
| 174 | +// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER) |
| 175 | +// .append("居中").setBackgroundColor(Color.GREEN) |
| 176 | +// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE) |
| 177 | +// .append("底部").setBackgroundColor(Color.GREEN) |
| 178 | +// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM) |
| 179 | +// .appendLine("对齐").setBackgroundColor(Color.GREEN) |
| 180 | +// |
| 181 | +// .append("测试空格").appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN).appendSpace(100).appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN) |
183 | 182 | .create());
|
184 | 183 | }
|
185 | 184 |
|
@@ -261,7 +260,9 @@ public void onWidgetClick(View view) {
|
261 | 260 |
|
262 | 261 | @Override
|
263 | 262 | protected void onDestroy() {
|
264 |
| - valueAnimator.cancel(); |
| 263 | + if (valueAnimator != null && valueAnimator.isRunning()) { |
| 264 | + valueAnimator.cancel(); |
| 265 | + } |
265 | 266 | super.onDestroy();
|
266 | 267 | }
|
267 | 268 | }
|
0 commit comments