import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import tt.com.yunifangstore.R;
import tt.com.yunifangstore.adapter.LaunchAdapter;
public class LaunchActivity extends AppCompatActivity implements View.OnClickListener {
RelativeLayout timelayout;
ImageView activitylaunch;
private Boolean isFirst;
private ViewPager launch_viewPager;
private int[] pic = {R.mipmap.guidance_1,
R.mipmap.guidance_2,
R.mipmap.guidance_3,
R.mipmap.guidance_4,
R.mipmap.guidance_5,};
private SharedPreferences preferences;
private int t1 = 4;
private int t2 = 5;
private TextView tv_time;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
t1--;
if (t1 == 0) {
removeCallbacksAndMessages(null);
timelayoutAnim();
handler.sendEmptyMessage(1);
}
sendEmptyMessageDelayed(0, 1000);
}
if (msg.what == 1) {
t2--;
tv_time.setText("跳过" + t2 + "s");
if (t2 == 0) {
handler.removeCallbacksAndMessages(null);
if (isFirst) {
SharedPreferences.Editor edit = preferences.edit();
edit.putBoolean("IsFirst", false);
edit.commit();
setContentView(R.layout.launch_layout);
launch_viewPager = (ViewPager) LaunchActivity.this.findViewById(R.id.launch_viewPager);
launch_viewPager.setAdapter(new LaunchAdapter(pic, LaunchActivity.this));
} else {
jump();
}
}
sendEmptyMessageDelayed(1, 1000);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_launch);
initView();
preferences = getSharedPreferences("IsFirstYNF", MODE_PRIVATE);
isFirst = preferences.getBoolean("IsFirst", true);
handler.sendEmptyMessage(0);
}
//跳转
private void jump() {
Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
@Override
public void onClick(View v) {
handler.removeCallbacksAndMessages(null);
jump();
}
private void initView() {
tv_time = (TextView) findViewById(R.id.tv_time);
tv_time.setOnClickListener(this);
timelayout = (RelativeLayout) findViewById(R.id.time_layout);
activitylaunch = (ImageView) findViewById(R.id.activity_launch);
}
/**
* 动画
*/
public void timelayoutAnim() {
activitylaunch.setVisibility(View.INVISIBLE);
timelayout.setVisibility(View.VISIBLE);
AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
alphaAnimation.setFillAfter(true);
alphaAnimation.setDuration(100);
/* TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_PARENT,1,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0);
translateAnimation.setFillAfter(true);
translateAnimation.setDuration(100);
timelayout.startAnimation(translateAnimation);*/
timelayout.startAnimation(alphaAnimation);
}
}
本文介绍了一个Android应用启动页的实现方式,包括启动页的动画效果制作、倒计时跳过功能及首次启动判断逻辑。通过使用SharedPreferences保存是否为首次启动的状态,并结合Handler进行时间控制。
1840

被折叠的 条评论
为什么被折叠?



