SplashscreenActivity随笔

public class SplashscreenActivity extends Activity {
	public final static String FIRST_RUN_PREFERENCE = "first_run";
	
	private Animation endAnimation;
	
	private Handler endAnimationHandler;
	private Runnable endAnimationRunnable;
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.splashscreen);
		findViewById(R.id.splashlayout);

		endAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
		endAnimation.setFillAfter(true);
		
		endAnimationHandler = new Handler();
		endAnimationRunnable = new Runnable() {
			@Override
			public void run() {
				findViewById(R.id.splashlayout).startAnimation(endAnimation);
			}
		};
		
		endAnimation.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {	}
			
			@Override
			public void onAnimationRepeat(Animation animation) { }
			
			@Override
			public void onAnimationEnd(Animation animation) {
				HomeActivity.launch(SplashscreenActivity.this);
				SplashscreenActivity.this.finish();
			}
		});

		showTutorial();
	}

	final void showTutorial() {
		boolean showTutorial = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(FIRST_RUN_PREFERENCE, true);
		if (showTutorial) {
			final TutorialDialog dlg = new TutorialDialog(this);
			dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
				@Override
				public void onDismiss(DialogInterface dialog) {
					CheckBox cb = (CheckBox) dlg.findViewById(R.id.toggleFirstRun);
					if (cb != null && cb.isChecked()) {
						SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SplashscreenActivity.this);
						prefs.edit().putBoolean(FIRST_RUN_PREFERENCE, false).commit();
					}
					endAnimationHandler.removeCallbacks(endAnimationRunnable);
					endAnimationHandler.postDelayed(endAnimationRunnable, 2000);
				}
			});
			dlg.show();

		} else {
			endAnimationHandler.removeCallbacks(endAnimationRunnable);
			endAnimationHandler.postDelayed(endAnimationRunnable, 1500);
		}
	}
}
动画xml文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:zAdjustment="bottom" android:fillAfter="false">

	<alpha android:fromAlpha="1.0" android:toAlpha="0"
		android:duration="400" />

</set>



1、Animation类的使用

①定义好xml资源文件

②load

endAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
	endAnimation.setFillAfter(true);	//if true, the transformation that this animation performed will persist when it is finished.


③startAnimation,只要是View就可以用

findViewById(R.id.splashlayout).startAnimation(endAnimation);


④若要对动画的状态做处理,只要设置setAnimationListener即可。

endAnimation.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {	}
			
			@Override
			public void onAnimationRepeat(Animation animation) { }
			
			@Override
			public void onAnimationEnd(Animation animation) {
				
			}
		});




2、若只想延时来做某个动作,只要用Handler类的postDelayed即可

Handler  endAnimationHandler = new Handler();
	endAnimationHandler.removeCallbacks(endAnimationRunnable);
	endAnimationHandler.postDelayed(endAnimationRunnable, 2000);

3、PreferenceManager首选项的使用

PreferenceManager类似于VC下的ini配置文件

SharedPreferences mPerferences = PreferenceManager.getDefaultSharedPreferences(this);       
        //read  
        int counter = mPerferences.getInt("counter", 0);              
        Log.i("zxd", "This app has been started " + counter + " times.");      
                  
        //write  
        SharedPreferences.Editor mEditor = mPerferences.edit();       
        mEditor.putInt("counter", ++counter);       
        mEditor.commit();  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值