package cn.zhaoliang5156.toutiao1630a.ui.fragment.activity;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioGroup;
import cn.zhaoliang5156.toutiao1630a.R;
import cn.zhaoliang5156.toutiao1630a.base.BaseActivity;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavFourFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavOneFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavThreeFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavTwoFragment;
/**
* 程序首页面
*
* @author zhaoliang
* @version 1.0
* @create 2018/7/24
*/
public class MainActivity extends BaseActivity implements View.OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
private ImageView ivHead;
// 侧滑菜单
private DrawerLayout drawerLayout;
// 主内容区域
private FrameLayout flContainer;
// 底部导航
private RadioGroup navRadioGroup;
@Override
protected void setOnClickLisener() {
ivHead.setOnClickListener(this);
drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
Log.i(TAG, "===:" + slideOffset);
//滑动过程中不断回调 slideOffset:0~1
View content = drawerLayout.getChildAt(0);
float scale = 1 - slideOffset;//1~0
content.setTranslationX(drawerView.getMeasuredWidth() * (1 - scale));//0~width
}
@Override
public void onDrawerOpened(@NonNull View drawerView) {
}
@Override
public void onDrawerClosed(@NonNull View drawerView) {
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
navRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rb_nav_one:
changePager(new NavOneFragment());
break;
case R.id.rb_nav_two:
changePager(new NavTwoFragment());
break;
case R.id.rb_nav_three:
changePager(new NavThreeFragment());
break;
case R.id.rb_nav_four:
changePager(new NavFourFragment());
break;
}
}
});
}
/**
* 改变页面
*
* @param fragment
*/
private void changePager(Fragment fragment) {
getSupportFragmentManager().beginTransaction().replace(R.id.fl_container, fragment).commit();
}
@Override
protected void initData() {
// 选中第一个页面
navRadioGroup.check(R.id.rb_nav_one);
}
@Override
protected void findView() {
ivHead = findViewById(R.id.iv_head);
drawerLayout = findViewById(R.id.draw_layout);
flContainer = findViewById(R.id.fl_container);
navRadioGroup = findViewById(R.id.rg_nav);
}
@Override
protected void setFullScreen() {
}
@Override
protected int initLayout() {
return R.layout.activity_main;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// 点击头像 展开侧滑
case R.id.iv_head:
if (drawerLayout.isDrawerOpen(Gravity.START)) {
drawerLayout.closeDrawer(Gravity.START);
} else {
drawerLayout.openDrawer(Gravity.START);
}
break;
}
}
}
/闪屏activity
package cn.zhaoliang5156.toutiao1630a.ui.fragment.activity;
import android.content.Intent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;
import cn.zhaoliang5156.toutiao1630a.R;
import cn.zhaoliang5156.toutiao1630a.base.BaseActivity;
/**
* 闪屏页面
*
* @author zhaoliang
* @version 1.0
* @create 2018/7/24
*/
public class SplashActivity extends BaseActivity implements Animation.AnimationListener {
// 渐变动画
private AlphaAnimation alphaAnimation;
// 跟布局
private RelativeLayout rlSplash;
@Override
protected void setOnClickLisener() {
}
@Override
protected void initData() {
alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(2000);
alphaAnimation.setAnimationListener(this);
rlSplash.startAnimation(alphaAnimation);
}
@Override
protected void findView() {
rlSplash = findViewById(R.id.rl_splash);
}
@Override
protected void setFullScreen() {
fullScreen();
}
@Override
protected int initLayout() {
return R.layout.activity_splash;
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
toMain();
}
/**
* 跳转到主界面
*/
private void toMain() {
startActivity(new Intent(this, MainActivity.class));
finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}