杀毒卫士(1)—启动界面
splash界面的功能与作用:
(1)、展示logo,提高公司形象;
(2)、初始化数据(拷贝数据到SD);
(3)、提高用户体验;
(4)、连接服务器是否有新的版本;
启动界面布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_splash_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/logo2" >
<TextView
android:id="@+id/tv_splash_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="版本号:"
android:textColor="#F70000"
android:textSize="18sp" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="130dip" />
</RelativeLayout>
启动逻辑代码:
(1)获取当前的应用程序的版本号:通过一个ViewHelper帮助类获取清单文件的所有信息,主要是获取PackageManager;
(2)创建一个启动动画:
(3)登录验证,版本更新,
(4)下载新版本的apk
具体帮助类可查看杀毒卫士(2)—启动界面帮助类
/**splash界面作用:
*
* ①展示logo,提高公司形象
* ②初始化数据 (拷贝数据到SD)
* ③提高用户体验
* ④连接服务器是否有新的版本
*/
public class SplashActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
//版本号
TextView tv_splash_version = (TextView) findViewById(R.id.tv_splash_version);
//获取版本号,显示
tv_splash_version.setText("版本号:"+ViewHelper.getVersion(this));
//启动动画, 补间动画
AlphaAnimation anim = new AlphaAnimation(0f, 1.0f);
anim.setDuration(2000);
RelativeLayout rl_splash_bg = (RelativeLayout) findViewById(R.id.rl_splash_bg);
rl_splash_bg.setAnimation(anim);
//登陆处理
if(SafePreference.getBoolean(this, Const.ISUPDATA)){
LoginHelper.getInstance(this).loginConnect();
}else{
//不进行http请求,检查版本
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);//如果在ui线程,会阻塞ui线程
} catch (InterruptedException e) {
e.printStackTrace();
}
SplashActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//ui线程中执行的
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
});
}
}).start();
}
}
@Override
protected void onDestroy() {
LoginHelper.getInstance(this).destory();
super.onDestroy();
}
}