Skip to content

Commit

Permalink
🚶 immersive
Browse files Browse the repository at this point in the history
  • Loading branch information
Bakumon committed Sep 3, 2017
1 parent ef6f139 commit f80332a
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import me.bakumon.ugank.R;
import me.bakumon.ugank.base.SwipeBackBaseActivity;
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.StatusBarUtil;
import me.bakumon.ugank.widget.PinchImageView;
import me.bakumon.ugank.widget.SquareLoading;

Expand Down Expand Up @@ -43,13 +44,8 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_bigimg);
ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
appbarBigImg.setPadding(
appbarBigImg.getPaddingLeft(),
appbarBigImg.getPaddingTop() + DisplayUtils.getStatusBarHeight(this),
appbarBigImg.getPaddingRight(),
appbarBigImg.getPaddingBottom());
}
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbarBigImg);
setSupportActionBar(toolbarBigImg);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import me.bakumon.ugank.base.SwipeBackBaseActivity;
import me.bakumon.ugank.entity.Favorite;
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.StatusBarUtil;
import me.bakumon.ugank.widget.RecycleViewDivider;
import me.bakumon.ugank.widget.recyclerviewwithfooter.OnLoadMoreListener;
import me.bakumon.ugank.widget.recyclerviewwithfooter.RecyclerViewWithFooter;
Expand All @@ -44,13 +45,8 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_favorite);
ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mAppbarFavorite.setPadding(
mAppbarFavorite.getPaddingLeft(),
mAppbarFavorite.getPaddingTop() + DisplayUtils.getStatusBarHeight(this),
mAppbarFavorite.getPaddingRight(),
mAppbarFavorite.getPaddingBottom());
}
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mToolbarFavorite);
setSupportActionBar(mToolbarFavorite);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down
73 changes: 4 additions & 69 deletions app/src/main/java/me/bakumon/ugank/module/home/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package me.bakumon.ugank.module.home;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
Expand All @@ -18,7 +15,6 @@
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

Expand All @@ -40,6 +36,7 @@
import me.bakumon.ugank.module.setting.SettingActivity;
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.MDTintUtil;
import me.bakumon.ugank.utills.StatusBarUtil;

/**
* HomeActivity
Expand Down Expand Up @@ -91,19 +88,9 @@ protected void onDestroy() {
}

private void initView() {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 4.4 以上版本
// 设置 Toolbar 高度为 80dp,适配状态栏
ViewGroup.LayoutParams layoutParams = mToolbar.getLayoutParams();
layoutParams.height = DisplayUtils.dp2px(80, this);
mToolbar.setLayoutParams(layoutParams);
} else { // 4.4 一下版本
// 设置 设置图标距离顶部(状态栏最底)为
mIvSetting.setPadding(mIvSetting.getPaddingLeft(),
DisplayUtils.dp2px(15, this),
mIvSetting.getPaddingRight(),
mIvSetting.getPaddingBottom());
}
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mIvHomeBanner);
StatusBarUtil.setPaddingSmart(this, mToolbar);

setFabDynamicState();

Expand Down Expand Up @@ -168,7 +155,6 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
layoutParams.height = DisplayUtils.dp2px(240, HomeActivity.this);
mAppBarLayout.setLayoutParams(layoutParams);
isBannerBig = false;
}
} else {
if (state != CollapsingToolbarLayoutState.INTERNEDIATE) {
Expand Down Expand Up @@ -271,57 +257,6 @@ public void collection() {
startActivity(new Intent(HomeActivity.this, FavoriteActivity.class));
}

private boolean isBannerBig; // banner 是否是大图
private boolean isBannerAniming; // banner 放大缩小的动画是否正在执行

@OnClick(R.id.iv_home_banner)
public void wantBig(View view) {
if (isBannerAniming) {
return;
}
startBannerAnim();
}

private void startBannerAnim() {
final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
ValueAnimator animator;
if (isBannerBig) {
animator = ValueAnimator.ofInt(DisplayUtils.getScreenHeight(this), DisplayUtils.dp2px(240, this));
} else {
animator = ValueAnimator.ofInt(DisplayUtils.dp2px(240, this), DisplayUtils.getScreenHeight(this));
}
animator.setDuration(1000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
layoutParams.height = (int) valueAnimator.getAnimatedValue();
mAppBarLayout.setLayoutParams(layoutParams);
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
isBannerBig = !isBannerBig;
isBannerAniming = false;
}
});
animator.start();
isBannerAniming = true;
}

@Override
public void onBackPressed() {
if (isBannerAniming) {
return;
}
if (isBannerBig) {
startBannerAnim();
} else {
super.onBackPressed();
}
}

@OnClick(R.id.iv_home_setting)
public void goSetting() {
startActivityForResult(new Intent(HomeActivity.this, SettingActivity.class), SETTING_REQUEST_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.KeyboardUtils;
import me.bakumon.ugank.utills.MDTintUtil;
import me.bakumon.ugank.utills.StatusBarUtil;
import me.bakumon.ugank.widget.RecycleViewDivider;
import me.bakumon.ugank.widget.recyclerviewwithfooter.OnLoadMoreListener;
import me.bakumon.ugank.widget.recyclerviewwithfooter.RecyclerViewWithFooter;
Expand Down Expand Up @@ -79,14 +80,8 @@ protected void onCreate(Bundle savedInstanceState) {

private void initView() {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mAppbarSearch.setPadding(
mAppbarSearch.getPaddingLeft(),
mAppbarSearch.getPaddingTop() + DisplayUtils.getStatusBarHeight(this),
mAppbarSearch.getPaddingRight(),
mAppbarSearch.getPaddingBottom());
}

StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mToolbarSearch);
setSupportActionBar(mToolbarSearch);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import me.bakumon.ugank.utills.AlipayZeroSdk;
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.MDTintUtil;
import me.bakumon.ugank.utills.StatusBarUtil;
import me.bakumon.ugank.widget.AboutDialog;

public class SettingActivity extends SwipeBackBaseActivity implements SettingContract.View, CompoundButton.OnCheckedChangeListener {
Expand Down Expand Up @@ -68,13 +69,8 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_setting);
ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mAppbarSetting.setPadding(
mAppbarSetting.getPaddingLeft(),
mAppbarSetting.getPaddingTop() + DisplayUtils.getStatusBarHeight(this),
mAppbarSetting.getPaddingRight(),
mAppbarSetting.getPaddingBottom());
}
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mAppbarSetting);
setSupportActionBar(mToolbarSetting);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
Expand All @@ -26,8 +25,8 @@
import me.bakumon.ugank.entity.Favorite;
import me.bakumon.ugank.module.favorite.FavoriteActivity;
import me.bakumon.ugank.utills.AndroidUtil;
import me.bakumon.ugank.utills.DisplayUtils;
import me.bakumon.ugank.utills.MDTintUtil;
import me.bakumon.ugank.utills.StatusBarUtil;
import me.bakumon.ugank.widget.ObservableWebView;

public class WebViewActivity extends SwipeBackBaseActivity implements WebViewContract.View {
Expand Down Expand Up @@ -59,13 +58,8 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_web_view);
ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mAppbar.setPadding(
mAppbar.getPaddingLeft(),
mAppbar.getPaddingTop() + DisplayUtils.getStatusBarHeight(this),
mAppbar.getPaddingRight(),
mAppbar.getPaddingBottom());
}
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mToolbar);
setSupportActionBar(mToolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
Expand Down
Loading

0 comments on commit f80332a

Please sign in to comment.