Skip to content

Commit a692a32

Browse files
committed
1、BaseSplashActivity中增强业务代码逻辑健壮性与容错(使用者在继承此Activity时不对任何必要的控件赋值)
1 parent 6f38b88 commit a692a32

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/main/java/common/base/activitys/BaseSplashActiviity.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import android.view.View;
66
import android.view.Window;
77
import android.view.WindowManager;
8+
import android.view.animation.AlphaAnimation;
89
import android.view.animation.Animation;
10+
import android.widget.FrameLayout;
911
import android.widget.TextView;
10-
import common.base.utils.CommonLog;
12+
13+
import common.base.utils.ViewUtil;
1114

1215
/**
1316
* User: fee(1176610771@qq.com)
@@ -56,13 +59,21 @@ protected void onCreate(Bundle savedInstanceState) {
5659
@Override
5760
protected void initViews() {
5861
splashAnimation = getAnimation4BackgroudImsg();
59-
if (splashAnimation != null) {
60-
splashAnimation.setDuration(splashDuringTime);
61-
splashAnimation.setAnimationListener(this);
62+
//added by fee 2016-12-06增加一些提升健壮性代码逻辑,以防止使用者不配置(赋值)一些必要的变量值
63+
if (splashAnimation == null) {
64+
splashAnimation = new AlphaAnimation(0.1f, 1.0f);
6265
}
63-
if (toAnimView != null) {
64-
toAnimView.setAnimation(splashAnimation);
66+
if (splashDuringTime == 0) {
67+
splashDuringTime = 3000;
68+
}
69+
splashAnimation.setDuration(splashDuringTime);
70+
splashAnimation.setAnimationListener(this);
71+
72+
if (toAnimView == null) {//使用者这都不想赋值,本基类为了动画能执行,只好自己造一个视图出来
73+
toAnimView = new FrameLayout(mContext);
74+
ViewUtil.getContentContainerView(this).addView(toAnimView);
6575
}
76+
toAnimView.setAnimation(splashAnimation);
6677
if (tvBtnJumpOverSplash != null) {
6778
tvBtnJumpOverSplash.setOnClickListener(this);
6879
}
@@ -131,7 +142,7 @@ protected Animation getAnimation4BackgroudImsg() {
131142
*/
132143
@Override
133144
public void onAnimationStart(Animation animation) {
134-
CommonLog.e(TAG, " --> onAnimationStart() ");
145+
e(TAG, " --> onAnimationStart() ");
135146
if (countDownTimer != null) {//如果是广告展示,动画开始时则开始倒计时
136147
countDownTimer.start();
137148
}
@@ -145,7 +156,7 @@ public void onAnimationStart(Animation animation) {
145156
*/
146157
@Override
147158
public void onAnimationEnd(Animation animation) {
148-
CommonLog.e(TAG," --> onAnimationEnd() ");
159+
e(TAG," --> onAnimationEnd() ");
149160
if (animation == splashAnimation) {
150161
if (countDownTimer == null) {//如果没有倒计时,则依据闪屏动画完成了来自动跳转,否则依据用户直接点击跳过或者倒计时完成
151162
//动画完成了,跳转到目标界面,子类区分实现

src/main/java/common/base/utils/ViewUtil.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.View;
1111
import android.view.ViewGroup;
1212
import android.widget.EditText;
13+
import android.widget.FrameLayout;
1314
import android.widget.ListAdapter;
1415
import android.widget.ListView;
1516
import android.widget.TextView;
@@ -219,4 +220,17 @@ public static void resolveListViewWholeH(ListView listView) {
219220

220221
listView.setLayoutParams(params);
221222
}
223+
224+
/**
225+
* 获取一个Activity中所在的window中的用来填充该activity布局的容器视图
226+
* @param curActivity
227+
* @return 可能通过
228+
*/
229+
public static FrameLayout getContentContainerView(Activity curActivity) {
230+
FrameLayout contentLayout = null;
231+
if (curActivity != null) {
232+
return (FrameLayout) curActivity.getWindow().getDecorView().findViewById(android.R.id.content);
233+
}
234+
return contentLayout;
235+
}
222236
}

0 commit comments

Comments
 (0)