Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5880d5b

Browse files
committed
1、书法家 完成
1 parent46e4b65 commit5880d5b

File tree

13 files changed

+376
-6
lines changed

13 files changed

+376
-6
lines changed
65 Bytes
Binary file not shown.

‎.idea/gradle.xml‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎app/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
implementation project(':code7_svg')
5252
implementation project(':code8_canvas_clip')
5353
implementation project(':code8_canvas_draw')
54+
implementation project(':code8_canvas_text_paint')
5455

5556
// implementation project(':code_x1_drawable_gravity')
5657
// implementation project(':code_x2_recycleview')

‎app/src/main/java/com/zinc/ui2018/MainActivity.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
2121
findViewById(R.id.tv_code7_svg).setOnClickListener(this);
2222
findViewById(R.id.tv_code8_canvas_clip).setOnClickListener(this);
2323
findViewById(R.id.tv_code8_canvas_draw).setOnClickListener(this);
24+
findViewById(R.id.tv_code8_canvas_text).setOnClickListener(this);
2425
}
2526

2627
@Override
@@ -53,6 +54,9 @@ public void onClick(View view) {
5354
caseR.id.tv_code8_canvas_draw:
5455
startActivity(newIntent(this,com.zinc.code8_canvas_draw.activity.ClientActivity.class));
5556
break;
57+
caseR.id.tv_code8_canvas_text:
58+
startActivity(newIntent(this,com.zinc.code8_canvas_text_paint.ClientActivity.class));
59+
break;
5660
}
5761
}
5862

‎app/src/main/res/layout/activity_main.xml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@
5151
<TextView
5252
android:id="@+id/tv_code8_canvas_clip"
5353
style="@style/textview_button"
54-
android:text="8-1、canvas的裁剪函数 clip" />
54+
android:text="8-1、canvas的裁剪师" />
5555

5656
<TextView
5757
android:id="@+id/tv_code8_canvas_draw"
5858
style="@style/textview_button"
59-
android:text="8-2、canvas的绘制函数" />
59+
android:text="8-2、canvas的绘图师" />
60+
61+
<TextView
62+
android:id="@+id/tv_code8_canvas_text"
63+
style="@style/textview_button"
64+
android:text="8-3、canvas的书法家" />
6065

6166
</LinearLayout>
6267

‎build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ allprojects {
2424

2525
ext {
2626
// app 版本信息
27-
versionName='1.2.0'
28-
versionCode=1200
27+
versionName='1.3.0'
28+
versionCode=1300
2929
minSdkVersion=19
3030
targetSdkVersion=27
3131
compileSdkVersion=27
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.zinc.code8_canvas_text_paint" />
2+
package="com.zinc.code8_canvas_text_paint" >
3+
<application>
4+
<activityandroid:name=".TextListActivity"/>
5+
<activityandroid:name=".CommonOperatorActivity"/>
6+
<activityandroid:name=".ClientActivity"/>
7+
<activityandroid:name=".WaveTextActivity"/>
8+
</application>
9+
</manifest>
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
packagecom.zinc.code8_canvas_text_paint;
22

3+
importandroid.app.Activity;
4+
importandroid.content.Intent;
5+
importandroid.os.Bundle;
6+
importandroid.support.annotation.Nullable;
7+
importandroid.view.View;
8+
39
/**
410
* author : zinc
511
* time : 2019/4/28 下午10:58
612
* desc :
713
* version :
814
*/
9-
publicclassClientActivity {
15+
publicclassClientActivityextendsActivity {
16+
17+
@Override
18+
protectedvoidonCreate(@NullableBundlesavedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_canvas_text_paint_client);
21+
}
22+
23+
publicvoidonWaveText(Viewview) {
24+
startActivity(newIntent(this,WaveTextActivity.class));
25+
}
26+
27+
publicvoidonAPI(Viewview) {
28+
startActivity(newIntent(this,TextListActivity.class));
29+
}
1030
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
packagecom.zinc.code8_canvas_text_paint;
2+
3+
importandroid.app.Activity;
4+
importandroid.os.Bundle;
5+
importandroid.support.annotation.Nullable;
6+
importandroid.view.View;
7+
importandroid.widget.CompoundButton;
8+
importandroid.widget.EditText;
9+
importandroid.widget.Switch;
10+
11+
importcom.zinc.code8_canvas_text_paint.widget.WaveTextView;
12+
13+
/**
14+
* author : zinc
15+
* time : 2019/5/21 上午9:18
16+
* desc :
17+
* version :
18+
*/
19+
publicclassWaveTextActivityextendsActivity {
20+
21+
privateWaveTextViewwaveTextView;
22+
privateEditTextetContent;
23+
privateSwitchswHelperLine;
24+
25+
@Override
26+
protectedvoidonCreate(@NullableBundlesavedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_wave_text);
29+
30+
waveTextView =findViewById(R.id.wave_text);
31+
etContent =findViewById(R.id.et_content);
32+
swHelperLine =findViewById(R.id.sw_helper_line);
33+
34+
swHelperLine.setChecked(true);
35+
waveTextView.setIsShowLine(true);
36+
swHelperLine.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
37+
@Override
38+
publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked) {
39+
waveTextView.setIsShowLine(isChecked);
40+
}
41+
});
42+
43+
}
44+
45+
publicvoidonRun(Viewview) {
46+
47+
waveTextView.setContent(etContent.getText().toString().trim());
48+
49+
waveTextView.start();
50+
51+
}
52+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
packagecom.zinc.code8_canvas_text_paint.widget;
2+
3+
importandroid.animation.ValueAnimator;
4+
importandroid.content.Context;
5+
importandroid.graphics.Canvas;
6+
importandroid.graphics.Paint;
7+
importandroid.graphics.Path;
8+
importandroid.support.annotation.Nullable;
9+
importandroid.support.v4.content.ContextCompat;
10+
importandroid.text.TextUtils;
11+
importandroid.util.AttributeSet;
12+
importandroid.view.animation.LinearInterpolator;
13+
14+
importcom.zinc.code8_canvas_text_paint.R;
15+
importcom.zinc.lib_base.BaseView;
16+
importcom.zinc.lib_base.UIUtils;
17+
18+
/**
19+
* author : zinc
20+
* time : 2019/5/15 下午11:07
21+
* desc :
22+
* version :
23+
*/
24+
publicclassWaveTextViewextendsBaseView {
25+
26+
privatestaticfinalintLENGTH_TIMES =2;
27+
privatestaticfinalintPOINT_COUNT =200;
28+
privatestaticfinalfloatA =100;
29+
30+
privateStringmContent;
31+
32+
privatePaintmPaint;
33+
privatePathmPath;
34+
35+
privatefloatmA =0;
36+
37+
privatefloatmLength;
38+
privatefloatmStepLength;
39+
privatebooleanmIsShowLine;
40+
41+
privatefloatm =0;
42+
43+
publicWaveTextView(Contextcontext) {
44+
super(context);
45+
}
46+
47+
privatefloatmLineWidth;
48+
privatefloatmTextWidth;
49+
privateintmLineColor;
50+
privateintmTextColor;
51+
privateintmBgColor;
52+
53+
privatefloatmTextSize;
54+
privateValueAnimatormAnimator;
55+
56+
publicWaveTextView(Contextcontext,@NullableAttributeSetattrs) {
57+
super(context,attrs);
58+
}
59+
60+
publicWaveTextView(Contextcontext,@NullableAttributeSetattrs,intdefStyleAttr) {
61+
super(context,attrs,defStyleAttr);
62+
}
63+
64+
@Override
65+
protectedvoidinit(Contextcontext) {
66+
67+
mTextColor =ContextCompat.getColor(context,R.color.canvas_light_blue_color);
68+
mLineColor =ContextCompat.getColor(context,R.color.canvas_red_color);
69+
70+
mBgColor =ContextCompat.getColor(context,R.color.canvas_pink_color);
71+
72+
mTextWidth =UIUtils.dip2px(context,1);
73+
mLineWidth =UIUtils.dip2px(context,2);
74+
75+
mTextSize =UIUtils.dip2px(context,18);
76+
77+
mPaint =newPaint();
78+
mPaint.setAntiAlias(true);
79+
mPaint.setTextSize(mTextSize);
80+
mPaint.setColor(mTextColor);
81+
mPaint.setStrokeWidth(mTextWidth);
82+
83+
mPath =newPath();
84+
85+
mAnimator =ValueAnimator.ofFloat(0, (float) (2 *Math.PI));
86+
mAnimator.setInterpolator(newLinearInterpolator());
87+
mAnimator.addUpdateListener(newValueAnimator.AnimatorUpdateListener() {
88+
@Override
89+
publicvoidonAnimationUpdate(ValueAnimatoranimation) {
90+
floatprogress = (float)animation.getAnimatedValue();
91+
m =progress;
92+
mA = (float) (1 -progress / (2 *Math.PI)) *A;
93+
invalidate();
94+
}
95+
});
96+
mAnimator.setDuration(1000);
97+
}
98+
99+
publicvoidsetContent(Stringcontent) {
100+
this.mContent =content;
101+
102+
this.mLength =mPaint.measureText(content) *LENGTH_TIMES;
103+
this.mStepLength =mLength / (POINT_COUNT);
104+
}
105+
106+
@Override
107+
protectedvoidonDraw(Canvascanvas) {
108+
109+
canvas.drawColor(mBgColor);
110+
111+
// 绘制网格线
112+
if (mIsShowLine) {
113+
drawCoordinate(canvas);
114+
}
115+
116+
// 空内容就不绘制了
117+
if (TextUtils.isEmpty(mContent)) {
118+
return;
119+
}
120+
121+
// 构建路径
122+
mPath.reset();
123+
for (inti =0;i <POINT_COUNT; ++i) {
124+
125+
floatx = -mLength /LENGTH_TIMES +i *mStepLength;
126+
floaty =calculateY(x);
127+
128+
if (i ==0) {
129+
mPath.moveTo(x,y);
130+
}else {
131+
mPath.lineTo(x,y);
132+
}
133+
134+
}
135+
136+
// 移至中心
137+
canvas.translate(getWidth() /2,getHeight() /2);
138+
// 将字体放中间
139+
canvas.translate(mLength /LENGTH_TIMES /2,0);
140+
141+
// 是否显示path
142+
if (mIsShowLine) {
143+
mPaint.setColor(mLineColor);
144+
mPaint.setStrokeWidth(mLineWidth);
145+
mPaint.setStyle(Paint.Style.STROKE);
146+
147+
canvas.drawPath(mPath,mPaint);
148+
149+
mPaint.setColor(mTextColor);
150+
mPaint.setStrokeWidth(mTextWidth);
151+
mPaint.setStyle(Paint.Style.FILL);
152+
}
153+
154+
// 在路径上画文字
155+
canvas.drawTextOnPath(mContent,mPath,0,0,mPaint);
156+
157+
}
158+
159+
/**
160+
* 计算 y 轴值
161+
* <p>
162+
* 三角函数:A*sin(w*x+m)+k
163+
*/
164+
privatefloatcalculateY(floatx) {
165+
doublea =Math.pow(4 / (4 +Math.pow(x /225,4)),2.5f) *mA;
166+
return (float) (a *Math.sin(Math.PI *x /200 -m));
167+
}
168+
169+
/**
170+
* 是否显示提示线
171+
*/
172+
publicvoidsetIsShowLine(booleanisShowLine) {
173+
this.mIsShowLine =isShowLine;
174+
}
175+
176+
/**
177+
* 开始动画
178+
*/
179+
publicvoidstart() {
180+
if (mAnimator ==null) {
181+
return;
182+
}
183+
184+
if (mAnimator.isRunning()) {
185+
mAnimator.cancel();
186+
}
187+
mAnimator.start();
188+
}
189+
190+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp