布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activity.GuideActivity"
>
<!--android:background="#4278F2"-->
<ImageView
android:id="@+id/guide_img_advertising"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/icon_q"/>
<TextView
android:id="@+id/guide_text_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:textSize="18sp"
android:textColor="#fff"
android:text="5S"/>
</RelativeLayout>
BaseAcivity
package com.liu.get.e_commerceproject.base;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.umeng.analytics.MobclickAgent;
public abstract class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContent());
initView();
if(isConnect(this)){
initData();
}else{
Toast.makeText(this,"网络不可用",Toast.LENGTH_SHORT).show();
}
}
/**
* 初始化View
*/
public abstract void initView();
/**
* 初始化数据
*/
public abstract void initData();
/**
* 填充布局
* @return
*/
public abstract int getContent();
public static boolean isConnect(Context context) {
boolean _isConnect = false;
ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conManager.getActiveNetworkInfo();
if (network != null) {
_isConnect = conManager.getActiveNetworkInfo().isAvailable();
}
return _isConnect;
}
public void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
public void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
}
activity
package com.liu.get.e_commerceproject.ui.activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.liu.get.e_commerceproject.R;
import com.liu.get.e_commerceproject.base.BaseActivity;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
/**
* 每一次进入应用都展示 此页面可以做为一个广告页面的展示
*/
public class GuideActivity extends BaseActivity {
private ImageView guide_img_advertising;
private TextView guide_text_countdown;
int time = 6;
private SharedPreferences into;
public void initView() {
guide_img_advertising = (ImageView) findViewById(R.id.guide_img_advertising);
guide_text_countdown = (TextView) findViewById(R.id.guide_text_countdown);
mHandler.sendEmptyMessageDelayed(1,0);
//直接进入程序
guide_text_countdown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
into = getSharedPreferences("into", MODE_PRIVATE);
if (into.getBoolean("isInto", false)) {
startActivity(new Intent(GuideActivity.this,ShelfActivity.class));
finish();
mHandler.removeCallbacksAndMessages(null);
} else {
startActivity(new Intent(GuideActivity.this,LoginActivity.class));
finish();
mHandler.removeCallbacksAndMessages(null);
SharedPreferences.Editor edit = into.edit();
edit.putBoolean("isInto", true);
edit.commit();
}
}
});
}
@Override
public void initData() {
}
@Override
public int getContent() {
return R.layout.activity_guide;
}
//程序倒计时 5S
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(time != 0){
time--;
guide_text_countdown.setText(time+"S");
mHandler.sendEmptyMessageDelayed(1,1000);
}else{
into = getSharedPreferences("into", MODE_PRIVATE);
if (into.getBoolean("isInto", false)) {
startActivity(new Intent(GuideActivity.this,ShelfActivity.class));
finish();
mHandler.removeCallbacksAndMessages(null);
} else {
startActivity(new Intent(GuideActivity.this,LoginActivity.class));
finish();
mHandler.removeCallbacksAndMessages(null);
SharedPreferences.Editor edit = into.edit();
edit.putBoolean("isInto", true);
edit.commit();
}
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
if(mHandler !=null){
mHandler.removeCallbacksAndMessages(null);
mHandler=null;
}
}
}