Skip to content

Commit 7594d24

Browse files
committed
fix zzz40500#17, 去除无用资源,优化布局, 优化dialog,修复当圆到方的一瞬间的颜色bug
1 parent 1480aa3 commit 7594d24

File tree

12 files changed

+241
-175
lines changed

12 files changed

+241
-175
lines changed

.idea/copyright/profiles_settings.xml

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

app/app.iml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@
100100
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
101101
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
102102
</content>
103-
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
103+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
104104
<orderEntry type="sourceFolder" forTests="false" />
105-
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
106-
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
107-
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
105+
<orderEntry type="library" exported="" name="support-core-ui-25.3.1" level="project" />
106+
<orderEntry type="library" exported="" name="support-v4-25.3.1" level="project" />
107+
<orderEntry type="library" exported="" name="support-media-compat-25.3.1" level="project" />
108+
<orderEntry type="library" exported="" name="support-annotations-25.3.1" level="project" />
109+
<orderEntry type="library" exported="" name="appcompat-v7-25.3.1" level="project" />
110+
<orderEntry type="library" exported="" name="support-vector-drawable-25.3.1" level="project" />
111+
<orderEntry type="library" exported="" name="support-compat-25.3.1" level="project" />
112+
<orderEntry type="library" exported="" name="support-core-utils-25.3.1" level="project" />
113+
<orderEntry type="library" exported="" name="support-fragment-25.3.1" level="project" />
114+
<orderEntry type="library" exported="" name="animated-vector-drawable-25.3.1" level="project" />
108115
<orderEntry type="module" module-name="shapeloading" exported="" />
109116
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
110117
</component>

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 21
4+
compileSdkVersion 25
55
buildToolsVersion '25.0.0'
66

77
defaultConfig {
88
applicationId "com.mingle"
99
minSdkVersion 9
10-
targetSdkVersion 21
10+
targetSdkVersion 25
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -21,6 +21,6 @@ android {
2121

2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.android.support:appcompat-v7:22.0.0'
24+
compile 'com.android.support:appcompat-v7:25.3.1'
2525
compile project(':shapeloading')
2626
}

app/src/main/java/com/mingle/DialogDemoActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public class DialogDemoActivity extends ActionBarActivity {
1616
protected void onCreate(Bundle savedInstanceState) {
1717
super.onCreate(savedInstanceState);
1818
setContentView(R.layout.activity_dialog_demo);
19-
shapeLoadingDialog=new ShapeLoadingDialog(this);
20-
shapeLoadingDialog.setLoadingText("加载中...");
19+
shapeLoadingDialog = new ShapeLoadingDialog.Builder(this)
20+
.loadText("加载中...")
21+
.build();
2122

2223

2324
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {

shapeloading/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 21
4+
compileSdkVersion 25
55
buildToolsVersion '25.0.0'
66

77
defaultConfig {
88
minSdkVersion 9
9-
targetSdkVersion 21
9+
targetSdkVersion 25
1010
versionCode 1
1111
versionName "1.0.3"
1212
}

shapeloading/shapeloading.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
9595
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9696
</content>
97-
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
97+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9898
<orderEntry type="sourceFolder" forTests="false" />
9999
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
100100
</component>

shapeloading/src/main/java/com/mingle/widget/LoadingView.java

Lines changed: 80 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@
1212
import android.view.ViewGroup;
1313
import android.view.animation.AccelerateInterpolator;
1414
import android.view.animation.DecelerateInterpolator;
15-
import android.widget.FrameLayout;
1615
import android.widget.ImageView;
16+
import android.widget.LinearLayout;
1717
import android.widget.TextView;
1818

1919
import com.mingle.shapeloading.R;
2020
import com.nineoldandroids.animation.Animator;
2121
import com.nineoldandroids.animation.AnimatorSet;
2222
import com.nineoldandroids.animation.ObjectAnimator;
23+
import com.nineoldandroids.view.ViewHelper;
2324

2425

2526
/**
2627
* Created by zzz40500 on 15/4/6.
2728
*/
28-
public class LoadingView extends FrameLayout {
29+
public class LoadingView extends LinearLayout {
2930

3031
private static final int ANIMATION_DURATION = 500;
3132

33+
private static final float FACTOR = 1.2f;
34+
3235
private static float mDistance = 200;
3336

3437
private ShapeLoadingView mShapeLoadingView;
@@ -42,27 +45,23 @@ public class LoadingView extends FrameLayout {
4245
private AnimatorSet mUpAnimatorSet;
4346
private AnimatorSet mDownAnimatorSet;
4447

48+
private boolean mStopped = false;
49+
50+
private int mDelay;
51+
4552
public LoadingView(Context context) {
4653
super(context);
54+
init(context, null);
4755
}
4856

4957
public LoadingView(Context context, AttributeSet attrs) {
50-
super(context, attrs, 0);
58+
super(context, attrs);
5159
init(context, attrs);
5260

5361
}
5462

55-
private void init(Context context, AttributeSet attrs) {
56-
57-
TypedArray typedArray = context
58-
.obtainStyledAttributes(attrs, R.styleable.LoadingView);
59-
mLoadText = typedArray.getString(R.styleable.LoadingView_loadingText);
60-
mTextAppearance = typedArray.getResourceId(R.styleable.LoadingView_loadingTextAppearance, -1);
61-
62-
typedArray.recycle();
63-
}
64-
6563

64+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
6665
public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
6766
super(context, attrs, defStyleAttr);
6867
init(context, attrs);
@@ -74,46 +73,53 @@ public LoadingView(Context context, AttributeSet attrs, int defStyleAttr, int de
7473
init(context, attrs);
7574
}
7675

77-
public int dip2px(float dipValue) {
78-
final float scale = getContext().getResources().getDisplayMetrics().density;
76+
private void init(Context context, AttributeSet attrs) {
77+
78+
setOrientation(VERTICAL);
79+
mDistance = dip2px(context, 54f);
80+
LayoutInflater.from(context).inflate(R.layout.load_view, this, true);
81+
mShapeLoadingView = (ShapeLoadingView) findViewById(R.id.shapeLoadingView);
82+
mIndicationIm = (ImageView) findViewById(R.id.indication);
83+
mLoadTextView = (TextView) findViewById(R.id.promptTV);
84+
ViewHelper.setScaleX(mIndicationIm, 0.2f);
85+
86+
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LoadingView);
87+
String loadText = typedArray.getString(R.styleable.LoadingView_loadingText);
88+
int textAppearance = typedArray.getResourceId(R.styleable.LoadingView_loadingText, -1);
89+
mDelay = typedArray.getInteger(R.styleable.LoadingView_delay, 80);
90+
typedArray.recycle();
91+
92+
if (textAppearance != -1) {
93+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
94+
mLoadTextView.setTextAppearance(textAppearance);
95+
} else {
96+
mLoadTextView.setTextAppearance(getContext(), textAppearance);
97+
}
98+
}
99+
setLoadingText(loadText);
100+
}
101+
102+
private int dip2px(Context context, float dipValue) {
103+
final float scale = context.getResources().getDisplayMetrics().density;
79104
return (int) (dipValue * scale + 0.5f);
80105
}
81106

82107

83108
@Override
84109
protected void onFinishInflate() {
85110
super.onFinishInflate();
86-
87-
View view = LayoutInflater.from(getContext()).inflate(R.layout.load_view, null);
88-
89-
mDistance = dip2px(54f);
90-
91-
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
92-
93-
layoutParams.gravity = Gravity.CENTER;
94-
95-
mShapeLoadingView = (ShapeLoadingView) view.findViewById(R.id.shapeLoadingView);
96-
97-
mIndicationIm = (ImageView) view.findViewById(R.id.indication);
98-
mLoadTextView = (TextView) view.findViewById(R.id.promptTV);
99-
100-
if (mTextAppearance != -1) {
101-
mLoadTextView.setTextAppearance(getContext(), mTextAppearance);
111+
if (getVisibility() == VISIBLE) {
112+
startLoading(mDelay);
102113
}
103-
setLoadingText(mLoadText);
104-
105-
addView(view, layoutParams);
106-
107-
108-
startLoading(900);
109114
}
110115

111-
112-
private AnimatorSet mAnimatorSet = null;
113-
114116
private Runnable mFreeFallRunnable = new Runnable() {
115117
@Override
116118
public void run() {
119+
ViewHelper.setRotation(mShapeLoadingView, 180f);
120+
ViewHelper.setTranslationY(mShapeLoadingView, 0f);
121+
ViewHelper.setScaleX(mIndicationIm, 0.2f);
122+
mStopped = false;
117123
freeFall();
118124
}
119125
};
@@ -137,12 +143,7 @@ protected void onDetachedFromWindow() {
137143
}
138144

139145
private void stopLoading() {
140-
if (mAnimatorSet != null) {
141-
if (mAnimatorSet.isRunning()) {
142-
mAnimatorSet.cancel();
143-
}
144-
mAnimatorSet = null;
145-
}
146+
mStopped = true;
146147
if (mUpAnimatorSet != null) {
147148
if (mUpAnimatorSet.isRunning()) {
148149
mUpAnimatorSet.cancel();
@@ -151,6 +152,7 @@ private void stopLoading() {
151152
for (Animator animator : mUpAnimatorSet.getChildAnimations()) {
152153
animator.removeAllListeners();
153154
}
155+
mUpAnimatorSet = null;
154156
}
155157
if (mDownAnimatorSet != null) {
156158
if (mDownAnimatorSet.isRunning()) {
@@ -160,23 +162,34 @@ private void stopLoading() {
160162
for (Animator animator : mDownAnimatorSet.getChildAnimations()) {
161163
animator.removeAllListeners();
162164
}
165+
mDownAnimatorSet = null;
163166
}
164167
this.removeCallbacks(mFreeFallRunnable);
165168
}
166169

167170
@Override
168171
public void setVisibility(int visibility) {
172+
this.setVisibility(visibility, mDelay);
173+
}
174+
175+
public void setVisibility(int visibility, int delay) {
169176
super.setVisibility(visibility);
170177
if (visibility == View.VISIBLE) {
171-
startLoading(200);
178+
startLoading(delay);
172179
} else {
173180
stopLoading();
174181
}
175182
}
176183

177-
public void setLoadingText(CharSequence loadingText) {
184+
public void setDelay(int delay) {
185+
mDelay = delay;
186+
}
178187

188+
public int getDelay() {
189+
return mDelay;
190+
}
179191

192+
public void setLoadingText(CharSequence loadingText) {
180193
if (TextUtils.isEmpty(loadingText)) {
181194
mLoadTextView.setVisibility(GONE);
182195
} else {
@@ -186,20 +199,24 @@ public void setLoadingText(CharSequence loadingText) {
186199
mLoadTextView.setText(loadingText);
187200
}
188201

202+
public CharSequence getLoadingText(){
203+
return mLoadTextView.getText();
204+
}
205+
189206
/**
190207
* 上抛
191208
*/
192209
public void upThrow() {
193210

194211
if (mUpAnimatorSet == null) {
195212
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mShapeLoadingView, "translationY", mDistance, 0);
196-
ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(mIndicationIm, "scaleX", 0.2f, 1);
213+
ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(mIndicationIm, "scaleX", 1f, 0.2f);
197214

198215
ObjectAnimator objectAnimator1 = null;
199216
switch (mShapeLoadingView.getShape()) {
200217
case SHAPE_RECT:
201218

202-
objectAnimator1 = ObjectAnimator.ofFloat(mShapeLoadingView, "rotation", 0, -120);
219+
objectAnimator1 = ObjectAnimator.ofFloat(mShapeLoadingView, "rotation", 0, 180);
203220

204221
break;
205222
case SHAPE_CIRCLE:
@@ -213,14 +230,12 @@ public void upThrow() {
213230
break;
214231
}
215232

216-
objectAnimator.setDuration(ANIMATION_DURATION);
217-
objectAnimator1.setDuration(ANIMATION_DURATION);
218-
objectAnimator.setInterpolator(new DecelerateInterpolator(factor));
219-
objectAnimator1.setInterpolator(new DecelerateInterpolator(factor));
220233
mUpAnimatorSet = new AnimatorSet();
221-
mUpAnimatorSet.setDuration(ANIMATION_DURATION);
222234
mUpAnimatorSet.playTogether(objectAnimator, objectAnimator1, scaleIndication);
223235

236+
mUpAnimatorSet.setDuration(ANIMATION_DURATION);
237+
mUpAnimatorSet.setInterpolator(new DecelerateInterpolator(FACTOR));
238+
224239
mUpAnimatorSet.addListener(new Animator.AnimatorListener() {
225240
@Override
226241
public void onAnimationStart(Animator animation) {
@@ -229,7 +244,9 @@ public void onAnimationStart(Animator animation) {
229244

230245
@Override
231246
public void onAnimationEnd(Animator animation) {
232-
freeFall();
247+
if (!mStopped) {
248+
freeFall();
249+
}
233250

234251
}
235252

@@ -249,22 +266,19 @@ public void onAnimationRepeat(Animator animation) {
249266

250267
}
251268

252-
public float factor = 1.2f;
253-
254269
/**
255270
* 下落
256271
*/
257272
public void freeFall() {
258273

259274
if (mDownAnimatorSet == null) {
260275
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mShapeLoadingView, "translationY", 0, mDistance);
261-
ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(mIndicationIm, "scaleX", 1, 0.2f);
276+
ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(mIndicationIm, "scaleX", 0.2f, 1f);
262277

263-
objectAnimator.setDuration(ANIMATION_DURATION);
264-
objectAnimator.setInterpolator(new AccelerateInterpolator(factor));
265278
mDownAnimatorSet = new AnimatorSet();
266-
mDownAnimatorSet.setDuration(ANIMATION_DURATION);
267279
mDownAnimatorSet.playTogether(objectAnimator, scaleIndication);
280+
mDownAnimatorSet.setDuration(ANIMATION_DURATION);
281+
mDownAnimatorSet.setInterpolator(new AccelerateInterpolator(FACTOR));
268282
mDownAnimatorSet.addListener(new Animator.AnimatorListener() {
269283
@Override
270284
public void onAnimationStart(Animator animation) {
@@ -273,9 +287,10 @@ public void onAnimationStart(Animator animation) {
273287

274288
@Override
275289
public void onAnimationEnd(Animator animation) {
276-
277-
mShapeLoadingView.changeShape();
278-
upThrow();
290+
if (!mStopped) {
291+
mShapeLoadingView.changeShape();
292+
upThrow();
293+
}
279294
}
280295

281296
@Override

0 commit comments

Comments
 (0)