SplashscreenActivity随笔
来源:互联网 发布:无声鼠标推荐 知乎 编辑:程序博客网 时间:2024/06/16 08:14
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) */@Overrideprotected 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() {@Overridepublic void run() {findViewById(R.id.splashlayout).startAnimation(endAnimation);}};endAnimation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) { }@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) { }@Overridepublic 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();
- SplashscreenActivity随笔
- android-jamendo源码学习(一)——SplashscreenActivity
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- 随笔
- VS2005 无法调试
- audio 元素能够播放声音文件或者音频流-html5播放音频
- tinyxml在Windows Mobile/windows ce 5.0项目下使用的问题
- 各种拨号缩写
- 随机抽样一致性算法(RANSAC)转载
- SplashscreenActivity随笔
- 正则表达式
- 【动态规划】装配线调度代码
- 简单纹理贴图
- net-snmp安装配置
- 已添加了具有相同键的项 的错误
- shell 字符串
- fcitx 开机无法运行
- replicate-wild-ignore-table