Skip to content

Commit f656b3a

Browse files
committed
Merge branch 'dev'
2 parents a8a296b + e67edb7 commit f656b3a

26 files changed

Lines changed: 1417 additions & 18 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
- 本库libs下有个**AndroidUtils.aar**的依赖包,是由[AndroidUtils](https://github.com/D-clock/AndroidUtils)代码编译生成;
99
- 想要查看**AndroidUtils.aar**中的源代码,可以参考[这里](https://github.com/D-clock/Doc/blob/master/Android/%E4%B8%AA%E4%BA%BA%E6%94%B6%E8%97%8F/%E5%A6%82%E4%BD%95%E6%9F%A5%E7%9C%8Baar%E7%9A%84%E6%BA%90%E4%BB%A3%E7%A0%81.md)
1010

11-
## 最新更新(编辑于2016-06-08
11+
## 最新更新(编辑于2016-08-29
1212

13-
- 兼容处理 Android M 版本的 Runtime Permission ;
14-
- 优化 build.gradle ,提高导入 moudle 体验;
13+
- 兼添加夜间模式的实现分析,详见文章 [知乎和简书的夜间模式实现套路](notes/知乎和简书的夜间模式实现套路.md)
1514

1615
## 归档文章
1716

1817
- [你需要知道的Android拍照适配问题](notes/你需要知道的Android拍照适配问题.md)
1918
- [深入理解Android中的Matrix](notes/深入理解Android中的Matrix.md)
19+
- [知乎和简书的夜间模式实现套路](notes/知乎和简书的夜间模式实现套路.md)
2020

2121
## 找我
2222

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.1.2'
6+
classpath 'com.android.tools.build:gradle:2.1.3'
77
// NOTE: Do not place your application dependencies here; they belong
88
// in the individual module build.gradle files
99
}
@@ -17,7 +17,7 @@ android {
1717

1818
defaultConfig {
1919
applicationId "com.clock.study"
20-
minSdkVersion 9
20+
minSdkVersion 11
2121
targetSdkVersion 23
2222
versionCode 1
2323
versionName "1.0"
@@ -42,4 +42,6 @@ dependencies {
4242
compile(name: 'AndroidUtils', ext: 'aar')
4343
//compile project(":AndroidUtils")
4444
compile 'com.android.support:appcompat-v7:23.2.1'
45+
compile 'com.android.support:recyclerview-v7:23.2.1'
46+
compile 'com.android.support:cardview-v7:23.1.1'
4547
}

notes/深入使用 RecyclerView.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

notes/知乎和简书的夜间模式实现套路.md

Lines changed: 353 additions & 0 deletions
Large diffs are not rendered by default.

src/main/AndroidManifest.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@
2929
android:name=".activity.PhotoPreviewActivity"
3030
android:label="@string/photo_preview"
3131
android:screenOrientation="portrait" />
32-
<activity android:name=".activity.AnimationActivity" />
33-
<activity android:name=".activity.AnimationTestActivity"/>
32+
<activity
33+
android:name=".activity.AnimationActivity"
34+
android:label="@string/android_animation" />
35+
<activity
36+
android:name=".activity.AnimationTestActivity"
37+
android:label="@string/animation_test" />
38+
<activity
39+
android:name=".activity.AnimatorActivity"
40+
android:label="@string/android_animator" />
41+
<activity
42+
android:name=".activity.DayNightActivity"
43+
android:label="@string/day_night_mode" />
44+
<activity
45+
android:name=".activity.AuthorActivity"
46+
android:label="Just a boy" />
3447
</application>
3548

3649
</manifest>

src/main/java/com/clock/study/activity/AnimationTestActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public long getItemId(int position) {
5959
@Override
6060
public View getView(int position, View convertView, ViewGroup parent) {
6161
if (convertView == null) {
62-
convertView = View.inflate(parent.getContext(), R.layout.list_view_test_item, null);
62+
convertView = View.inflate(parent.getContext(), R.layout.author_info_layout, null);
6363
}
6464
return convertView;
6565
}
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
package com.clock.study.activity;
2+
3+
import android.animation.AnimatorInflater;
4+
import android.animation.AnimatorSet;
5+
import android.animation.Keyframe;
6+
import android.animation.ObjectAnimator;
7+
import android.animation.PropertyValuesHolder;
8+
import android.animation.ValueAnimator;
9+
import android.graphics.Color;
10+
import android.os.Bundle;
11+
import android.support.v4.view.ViewCompat;
12+
import android.support.v7.app.AppCompatActivity;
13+
import android.util.Log;
14+
import android.view.View;
15+
import android.view.animation.BounceInterpolator;
16+
17+
import com.clock.study.R;
18+
19+
/**
20+
* About Android Animator
21+
*
22+
* @author Clock
23+
* @since 2016-07-21
24+
*/
25+
public class AnimatorActivity extends AppCompatActivity implements View.OnClickListener {
26+
27+
private static final String TAG = AnimatorActivity.class.getSimpleName();
28+
29+
private View mTarget;
30+
31+
@Override
32+
protected void onCreate(Bundle savedInstanceState) {
33+
super.onCreate(savedInstanceState);
34+
setContentView(R.layout.activity_animator);
35+
36+
mTarget = findViewById(R.id.anim_target);
37+
38+
findViewById(R.id.btn_value_anim).setOnClickListener(this);
39+
findViewById(R.id.btn_object_anim_alpha).setOnClickListener(this);
40+
findViewById(R.id.btn_object_anim_rotation).setOnClickListener(this);
41+
findViewById(R.id.btn_object_anim_set).setOnClickListener(this);
42+
findViewById(R.id.btn_object_anim_xml).setOnClickListener(this);
43+
findViewById(R.id.btn_simple_value_animator).setOnClickListener(this);
44+
findViewById(R.id.btn_value_animator_argb).setOnClickListener(this);
45+
findViewById(R.id.btn_bounce_interpolator).setOnClickListener(this);
46+
findViewById(R.id.btn_simple_key_frame).setOnClickListener(this);
47+
findViewById(R.id.btn_shake_key_frame).setOnClickListener(this);
48+
49+
}
50+
51+
@Override
52+
public void onClick(View v) {
53+
int viewId = v.getId();
54+
if (viewId == R.id.btn_value_anim) {
55+
ValueAnimator valueAnimator = ValueAnimator.ofInt(1, 100);
56+
valueAnimator.setDuration(3000);
57+
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
58+
@Override
59+
public void onAnimationUpdate(ValueAnimator animation) {
60+
int currentValue = (int) animation.getAnimatedValue();
61+
Log.i(TAG, "currentValue: " + currentValue);
62+
}
63+
});
64+
valueAnimator.start();
65+
66+
} else if (viewId == R.id.btn_object_anim_alpha) {
67+
ObjectAnimator alphaObjectAnimator = ObjectAnimator.ofFloat(mTarget, "alpha", 1f, 0f, 1f);
68+
alphaObjectAnimator.setDuration(3000);
69+
alphaObjectAnimator.start();
70+
71+
} else if (viewId == R.id.btn_object_anim_rotation) {
72+
ObjectAnimator rotationObjectAnimator = ObjectAnimator.ofFloat(mTarget, "rotation", 0f, 360f);
73+
rotationObjectAnimator.setDuration(3000);
74+
rotationObjectAnimator.start();
75+
76+
} else if (viewId == R.id.btn_object_anim_set) {
77+
AnimatorSet animatorSet = new AnimatorSet();
78+
ObjectAnimator alphaObjectAnimator = ObjectAnimator.ofFloat(mTarget, "alpha", 1f, 0f, 1f);
79+
ObjectAnimator rotationObjectAnimator = ObjectAnimator.ofFloat(mTarget, "rotation", 0f, 360f);
80+
animatorSet.play(alphaObjectAnimator).with(rotationObjectAnimator);
81+
//animatorSet.play(alphaObjectAnimator).after(rotationObjectAnimator);
82+
//animatorSet.playTogether(alphaObjectAnimator, rotationObjectAnimator);
83+
animatorSet.setDuration(3000);
84+
animatorSet.start();
85+
86+
} else if (viewId == R.id.btn_object_anim_xml) {
87+
AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.simple_animator);
88+
animatorSet.setTarget(mTarget);
89+
animatorSet.start();
90+
91+
} else if (viewId == R.id.btn_simple_value_animator) {
92+
displayColorAnimation(mTarget, "#0000ff", "#ff0000");
93+
94+
} else if (viewId == R.id.btn_value_animator_argb) {
95+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
96+
int startColor = 0x00000000;
97+
int centerColor = 0xff00ff89;
98+
int endColor = 0x00000000;
99+
ValueAnimator valueAnimator = ValueAnimator.ofArgb(startColor, centerColor, endColor);
100+
valueAnimator.setDuration(6000);
101+
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
102+
@Override
103+
public void onAnimationUpdate(ValueAnimator animation) {
104+
int color = (int) animation.getAnimatedValue();
105+
mTarget.setBackgroundColor(color);
106+
}
107+
});
108+
valueAnimator.start();
109+
}
110+
111+
} else if (viewId == R.id.btn_bounce_interpolator) {
112+
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTarget, "translationY", 0f, 1500f);
113+
objectAnimator.setInterpolator(new BounceInterpolator());
114+
objectAnimator.setDuration(4000);
115+
objectAnimator.start();
116+
117+
} else if (viewId == R.id.btn_simple_key_frame) {
118+
Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
119+
Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
120+
Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
121+
PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
122+
ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(mTarget, pvhRotation);
123+
rotationAnim.setDuration(5000);
124+
rotationAnim.start();
125+
126+
} else if (viewId == R.id.btn_shake_key_frame) {
127+
displayShakeAnimator(mTarget, 1f);
128+
129+
}
130+
}
131+
132+
/**
133+
* 创建一个旋转动画
134+
*
135+
* @param target
136+
* @param shakeFactor
137+
* @return
138+
*/
139+
private void displayShakeAnimator(View target, float shakeFactor) {
140+
Keyframe scaleXkf0 = Keyframe.ofFloat(0f, 1f);
141+
Keyframe scaleXkf1 = Keyframe.ofFloat(0.1f, 0.9f);
142+
Keyframe scaleXkf2 = Keyframe.ofFloat(0.2f, 0.9f);
143+
Keyframe scaleXkf3 = Keyframe.ofFloat(0.3f, 0.9f);
144+
Keyframe scaleXkf4 = Keyframe.ofFloat(0.4f, 1.1f);
145+
Keyframe scaleXkf5 = Keyframe.ofFloat(0.5f, 1.1f);
146+
Keyframe scaleXkf6 = Keyframe.ofFloat(0.6f, 1.1f);
147+
Keyframe scaleXkf7 = Keyframe.ofFloat(0.7f, 1.1f);
148+
Keyframe scaleXkf8 = Keyframe.ofFloat(0.8f, 1.1f);
149+
Keyframe scaleXkf9 = Keyframe.ofFloat(0.9f, 1.1f);
150+
Keyframe scaleXkf10 = Keyframe.ofFloat(1f, 1f);
151+
152+
PropertyValuesHolder scaleXHolder = PropertyValuesHolder.ofKeyframe("scaleX", scaleXkf0, scaleXkf1, scaleXkf2, scaleXkf3, scaleXkf4,
153+
scaleXkf5, scaleXkf6, scaleXkf7, scaleXkf8, scaleXkf9, scaleXkf10);
154+
155+
Keyframe scaleYkf0 = Keyframe.ofFloat(0f, 1f);
156+
Keyframe scaleYkf1 = Keyframe.ofFloat(0.1f, 0.9f);
157+
Keyframe scaleYkf2 = Keyframe.ofFloat(0.2f, 0.9f);
158+
Keyframe scaleYkf3 = Keyframe.ofFloat(0.3f, 0.9f);
159+
Keyframe scaleYkf4 = Keyframe.ofFloat(0.4f, 1.1f);
160+
Keyframe scaleYkf5 = Keyframe.ofFloat(0.5f, 1.1f);
161+
Keyframe scaleYkf6 = Keyframe.ofFloat(0.6f, 1.1f);
162+
Keyframe scaleYkf7 = Keyframe.ofFloat(0.7f, 1.1f);
163+
Keyframe scaleYkf8 = Keyframe.ofFloat(0.8f, 1.1f);
164+
Keyframe scaleYkf9 = Keyframe.ofFloat(0.9f, 1.1f);
165+
Keyframe scaleYkf10 = Keyframe.ofFloat(1f, 1f);
166+
PropertyValuesHolder scaleYHolder = PropertyValuesHolder.ofKeyframe("scaleY", scaleYkf0, scaleYkf1, scaleYkf2, scaleYkf3, scaleYkf4,
167+
scaleYkf5, scaleYkf6, scaleYkf7, scaleYkf8, scaleYkf9, scaleYkf10);
168+
169+
170+
PropertyValuesHolder rotationHolder = PropertyValuesHolder.ofKeyframe("rotation",
171+
Keyframe.ofFloat(0f, 0),
172+
Keyframe.ofFloat(0.1f, -3 * shakeFactor),
173+
Keyframe.ofFloat(0.2f, -3 * shakeFactor),
174+
Keyframe.ofFloat(0.3f, 3 * shakeFactor),
175+
Keyframe.ofFloat(0.4f, -3 * shakeFactor),
176+
Keyframe.ofFloat(0.5f, 3 * shakeFactor),
177+
Keyframe.ofFloat(0.6f, -3 * shakeFactor),
178+
Keyframe.ofFloat(0.7f, -3 * shakeFactor),
179+
Keyframe.ofFloat(0.8f, 3 * shakeFactor),
180+
Keyframe.ofFloat(0.9f, -3 * shakeFactor),
181+
Keyframe.ofFloat(1f, 0));
182+
183+
184+
ObjectAnimator.ofPropertyValuesHolder(target, scaleXHolder, scaleYHolder, rotationHolder).setDuration(1000).start();
185+
}
186+
187+
/**
188+
* 显示颜色变化的动画
189+
*
190+
* @param target
191+
* @param startColor
192+
* @param endColor
193+
*/
194+
private void displayColorAnimation(final View target, final String startColor, final String endColor) {
195+
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 100f);
196+
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
197+
@Override
198+
public void onAnimationUpdate(ValueAnimator animation) {
199+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
200+
float fraction = animation.getAnimatedFraction();
201+
if (target != null) {
202+
int startRed = Integer.parseInt(startColor.substring(1, 3), 16);
203+
int startGreen = Integer.parseInt(startColor.substring(3, 5), 16);
204+
int startBlue = Integer.parseInt(startColor.substring(5, 7), 16);
205+
int endRed = Integer.parseInt(endColor.substring(1, 3), 16);
206+
int endGreen = Integer.parseInt(endColor.substring(3, 5), 16);
207+
int endBlue = Integer.parseInt(endColor.substring(5, 7), 16);
208+
209+
int redDiff = Math.abs(endRed - startRed);
210+
int greenDiff = Math.abs(endGreen - startGreen);
211+
int blueDiff = Math.abs(endBlue - startBlue);
212+
int colorDiff = redDiff + greenDiff + blueDiff;
213+
214+
int currRed = getCurrentColor(startRed, endRed, colorDiff, fraction);
215+
int currGreen = getCurrentColor(startGreen, endGreen, colorDiff, fraction);
216+
int currBlue = getCurrentColor(startBlue, endBlue, colorDiff, fraction);
217+
218+
String colorString = "#" + getHexString(currRed) + getHexString(currGreen) + getHexString(currBlue);
219+
int color = Color.parseColor(colorString);
220+
target.setBackgroundColor(color);
221+
222+
}
223+
}
224+
225+
}
226+
});
227+
valueAnimator.setDuration(3000);
228+
valueAnimator.start();
229+
230+
}
231+
232+
/**
233+
* 获取当前新颜色
234+
*
235+
* @param startColor
236+
* @param endColor
237+
* @param colorDiff
238+
* @param fraction
239+
* @return
240+
*/
241+
private int getCurrentColor(int startColor, int endColor, int colorDiff, float fraction) {
242+
int currentColor = 0;
243+
if (startColor > endColor) {
244+
currentColor = (int) (startColor - fraction * colorDiff);
245+
} else {
246+
currentColor = (int) (startColor + fraction * colorDiff);
247+
}
248+
if (currentColor >= 0 && currentColor <= 256) {//最终的色值要确保在0到256之间
249+
return currentColor;
250+
} else {
251+
currentColor = endColor;
252+
}
253+
return currentColor;
254+
}
255+
256+
/**
257+
* 将10进制颜色值转换成16进制。
258+
*/
259+
private String getHexString(int value) {
260+
String hexString = Integer.toHexString(value);
261+
if (hexString.length() == 1) {
262+
hexString = "0" + hexString;
263+
}
264+
return hexString;
265+
}
266+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.clock.study.activity;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
6+
import com.clock.study.R;
7+
import com.clock.study.helper.DayNightHelper;
8+
9+
public class AuthorActivity extends AppCompatActivity {
10+
11+
private DayNightHelper mDayNightHelper;
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
initData();
17+
initTheme();
18+
setContentView(R.layout.activity_author);
19+
}
20+
21+
private void initData() {
22+
mDayNightHelper = new DayNightHelper(this);
23+
}
24+
25+
private void initTheme() {
26+
if (mDayNightHelper.isDay()) {
27+
setTheme(R.style.DayTheme);
28+
} else {
29+
setTheme(R.style.NightTheme);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)