ITeye博客

Android Jamendo开源在线音乐播放器源码分析三 程序首界面

bolutes · 2011-10-06 13:58 · Markdown

整个程序的入口Activity从Manifest里面可以找到是SplashscreenActivity,界面截图如下:

程序的代码如下:

备注一:SharedPreferences的保存

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SplashscreenActivity.this);
prefs.edit().putBoolean(FIRST_RUN_PREFERENCE, false).commit();

刚开始的时候以为传入的是SplashscreenActivity,那么生成的那个xml文件的名字应该是和这个activity有关才对,手机没有root权限所以通脱调试看到不是这样的


看以看到是和整个程序的包名有关,现在明白其实这个函数的参数只要是传入的是属于这个程序的context的对象就可以。

再有就是对于何时判断实现这个对话框的判断,刚开始想在onCreate()里面判断是不是显示不是更好,后来发现这样做不好,程序的封装行就被破坏了,我要处理是不是显示对话框,onCreate()只要调用一个函数就可以了,不管你在你在里面是怎样处理的是显示还是不显示。

备注二:动画的处理

如果这个动画让我处理的话可能就是执行动画然后,执行完了跳到对应的activity中去。而在这里是用Handler和Runnable来处理的。

endAnimationHandler.removeCallbacks(endAnimationRunnable);
endAnimationHandler.postDelayed(endAnimationRunnable, 1500);

API中的解释:

void android.os.Handler.removeCallbacks(Runnable r)

Remove any pending posts of Runnable r that are in the message queue.

boolean android.os.Handler.postDelayed(Runnable r, long delayMillis)

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the thread to which this handler is attached.

Parameters:

r The Runnable that will be executed.

delayMillis The delay (in milliseconds) until the Runnable will be executed.

Returns:

Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.

启动这个Runnable后在run()方法里面是findViewById(R.id.splashlayout).startAnimation(endAnimation);可以看出是在view上启动某个动画,动画执行一段时间之后要结束的,结束后要跳到相应的Activity中去,这里使用的是给这个动画加了一个监听事件,当onAnimationEnd的时候:

HomeActivity.launch(SplashscreenActivity.this);
SplashscreenActivity.this.finish();

在HomeActivity里面这个launch是一个静态的函数:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );这里先留一个问题,查了一下还是没能太明白这个的准确意思

备注三:对dialog添加消失的监听事件

dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {}

之前一直不知道有这么一个监听事件,以后可以在程序中使用到

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。