Skip to content

Commit 815d862

Browse files
committed
1、全新优化NavigationViewHelper
1 parent 64bbd25 commit 815d862

File tree

10 files changed

+104
-61
lines changed

10 files changed

+104
-61
lines changed

apk/sample.apk

8 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
minSdkVersion ext.minSdkVersion
1616
targetSdkVersion ext.targetSdkVersion
1717
versionCode 229
18-
versionName "2.2.9-beta1"
18+
versionName "2.2.9-beta2"
1919
multiDexEnabled true
2020
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2121
buildConfigField "String", "BASE_URL", "\"https://api.douban.com/\""

app/src/main/java/com/aries/library/fast/demo/AppImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.graphics.Color;
56
import android.support.annotation.NonNull;
67
import android.support.annotation.Nullable;
78
import android.view.View;
@@ -200,13 +201,27 @@ public boolean createHttpErrorControl(int errorRes, int errorCode, @io.reactivex
200201
@Override
201202
public NavigationViewHelper createNavigationBarControl(Activity activity, View bottomView) {
202203
NavigationViewHelper helper = NavigationViewHelper.with(activity)
204+
//是否控制虚拟导航栏true 后续属性有效--第一优先级
203205
.setControlEnable(true)
204-
.setTransEnable(false)
206+
//是否全透明导航栏优先级第二--同步设置setNavigationViewColor故注意调用顺序
207+
//华为的半透明和全透明类似
208+
.setTransEnable(RomUtil.isEMUI())
209+
//是否增加假的NavigationView用于沉浸至虚拟导航栏遮住
205210
.setPlusNavigationViewEnable(
206211
activity.getClass() == SplashActivity.class ? false :
207212
RomUtil.isEMUI())
213+
//设置是否控制底部输入框--默认属性
208214
.setControlBottomEditTextEnable(true)
209-
.setBottomView(bottomView);
215+
//设置最下边View用于增加paddingBottom--建议activity 根布局
216+
.setBottomView(bottomView)
217+
//影响setPlusNavigationViewEnable(true)单个条件
218+
//或者(setPlusNavigationViewEnable(false)&&setControlEnable(true))--两个前置条件
219+
//半透明默认设置102
220+
.setNavigationViewColor(Color.argb(102, 0, 0, 0))
221+
//setPlusNavigationViewEnable(true)才有效注意与setNavigationViewColor调用顺序
222+
// .setNavigationViewDrawable(mContext.getResources().getDrawable(R.drawable.img_bg_login))
223+
//setPlusNavigationViewEnable(true)有效
224+
.setNavigationLayoutColor(Color.WHITE);
210225
return helper;
211226
}
212227

app/src/main/java/com/aries/library/fast/demo/module/WebViewActivity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,4 @@ public void onConfigurationChanged(Configuration newConfig) {
144144
mSwipeBackHelper.setSwipeBackEnable(false);
145145
}
146146
}
147-
148-
@Override
149-
protected View getNavigationBarControlView() {
150-
return isSwipeBackEnable()?super.getNavigationBarControlView():null;
151-
}
152147
}

app/src/main/java/com/aries/library/fast/demo/module/main/MainActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import com.aries.library.fast.demo.module.activity.ActivityFragment;
77
import com.aries.library.fast.demo.module.mine.MineFragment;
88
import com.aries.library.fast.entity.FastTabEntity;
9+
import com.aries.library.fast.helper.NavigationViewHelper;
910
import com.aries.library.fast.module.activity.FastMainActivity;
1011
import com.flyco.tablayout.CommonTabLayout;
1112

1213
import java.util.ArrayList;
1314
import java.util.List;
1415

16+
import butterknife.BindView;
17+
1518

1619
/**
1720
* Created: AriesHoo on 2017/9/7 10:59
@@ -20,6 +23,8 @@
2023
*/
2124
public class MainActivity extends FastMainActivity {
2225

26+
@BindView(R.id.tabLayout_commonFastLib) CommonTabLayout mTabLayout;
27+
2328
@Override
2429
public boolean isSwipeEnable() {
2530
return false;
@@ -35,6 +40,12 @@ public int getContentBackground() {
3540
return 0;
3641
}
3742

43+
@Override
44+
protected void beforeControlNavigation(NavigationViewHelper navigationHelper) {
45+
super.beforeControlNavigation(navigationHelper);
46+
navigationHelper.setBottomView(mTabLayout);
47+
}
48+
3849
@Override
3950
public List<FastTabEntity> getTabList() {
4051
ArrayList<FastTabEntity> tabEntities = new ArrayList<>();

app/src/main/java/com/aries/library/fast/demo/module/main/sample/ToastActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.widget.Toast;
88

99
import com.aries.library.fast.demo.R;
10+
import com.aries.library.fast.helper.NavigationViewHelper;
1011
import com.aries.library.fast.module.activity.FastTitleActivity;
1112
import com.aries.library.fast.util.ToastUtil;
1213
import com.aries.ui.view.title.TitleBarView;
@@ -27,15 +28,21 @@ public int getContentLayout() {
2728
}
2829

2930
@Override
30-
public void initView(Bundle savedInstanceState) {
31-
mContentView.setBackgroundColor(Color.BLUE);
31+
protected void beforeControlNavigation(NavigationViewHelper navigationHelper) {
32+
super.beforeControlNavigation(navigationHelper);
33+
navigationHelper.setNavigationLayoutColor(Color.BLUE);
3234
}
3335

3436
@Override
3537
public void setTitleBar(TitleBarView titleBar) {
3638
titleBar.setTitleMainText("ToastUtil工具类示例");
3739
}
3840

41+
@Override
42+
public void initView(Bundle savedInstanceState) {
43+
mContentView.setBackgroundColor(Color.BLUE);
44+
}
45+
3946
@OnClick({R.id.rtv_system, R.id.rtv_normal, R.id.rtv_success, R.id.rtv_failed, R.id.rtv_warning})
4047
public void onViewClicked(View view) {
4148
switch (view.getId()) {

app/src/main/java/com/aries/library/fast/demo/module/main/sample/ali/ALiPayMainActivity.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.aries.library.fast.demo.module.main.sample.ali;
22

33
import android.os.Bundle;
4-
import android.view.View;
54

65
import com.aries.library.fast.demo.R;
76
import com.aries.library.fast.entity.FastTabEntity;
7+
import com.aries.library.fast.helper.NavigationViewHelper;
88
import com.aries.library.fast.module.activity.FastMainActivity;
99
import com.flyco.tablayout.CommonTabLayout;
1010

@@ -47,6 +47,12 @@ public void setTabLayout(CommonTabLayout tabLayout) {
4747
tabLayout.setTextSelectColor(getResources().getColor(R.color.colorMainAli));
4848
}
4949

50+
@Override
51+
protected void beforeControlNavigation(NavigationViewHelper navigationHelper) {
52+
super.beforeControlNavigation(navigationHelper);
53+
navigationHelper.setBottomView(mTabLayout);
54+
}
55+
5056
@Override
5157
public void beforeInitView() {
5258
titles = getResources().getStringArray(R.array.arrays_tab_ali);
@@ -62,9 +68,4 @@ public void initView(Bundle savedInstanceState) {
6268
public void onBackPressed() {
6369
finish();
6470
}
65-
66-
@Override
67-
protected View getNavigationBarControlView() {
68-
return mTabLayout;
69-
}
7071
}

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 15
1010
targetSdkVersion 25
1111
versionCode 229
12-
versionName "2.2.9-beta1"
12+
versionName "2.2.9-beta2"
1313
}
1414
buildTypes {
1515
release {

library/src/main/java/com/aries/library/fast/basis/BasisActivity.java

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
import com.aries.library.fast.entity.FastQuitConfigEntity;
1212
import com.aries.library.fast.helper.NavigationViewHelper;
1313
import com.aries.library.fast.i.IBasisView;
14-
import com.aries.library.fast.i.NavigationBarControl;
1514
import com.aries.library.fast.manager.LoggerManager;
1615
import com.aries.library.fast.manager.RxJavaManager;
1716
import com.aries.library.fast.util.FastStackUtil;
1817
import com.aries.library.fast.util.FastUtil;
18+
import com.aries.library.fast.util.NavigationBarUtil;
19+
import com.aries.library.fast.util.SPUtil;
1920
import com.aries.library.fast.util.SnackBarUtil;
2021
import com.aries.library.fast.util.ToastUtil;
2122
import com.trello.rxlifecycle2.android.ActivityEvent;
@@ -40,21 +41,51 @@ public abstract class BasisActivity extends RxAppCompatActivity implements IBasi
4041
protected View mContentView;
4142
protected Unbinder mUnBinder;
4243
protected BGASwipeBackHelper mSwipeBackHelper;
43-
protected NavigationViewHelper mNavigationViewHelper;
4444

4545
protected boolean mIsViewLoaded = false;
4646
protected boolean mIsFirstShow = true;
4747
protected boolean mIsFirstBack = true;
4848
protected long mDelayBack = 2000;
4949
protected final String TAG = getClass().getSimpleName();
5050
protected FastQuitConfigEntity mQuitEntity;
51+
private NavigationViewHelper mNavigationViewHelper;
5152

52-
protected NavigationBarControl getNavigationBarControl() {
53-
return FastConfig.getInstance(this).getNavigationBarControl();
53+
@Nullable
54+
public <T extends View> T findViewByViewId(@IdRes int viewId) {
55+
return (T) findViewById(viewId);
56+
}
57+
58+
@Override
59+
public int getContentBackground() {
60+
return FastConfig.getInstance(this).getContentViewBackgroundResource();
61+
}
62+
63+
/**
64+
* 设置屏幕方向
65+
* 默认自动 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
66+
* 竖屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
67+
* 横屏 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
68+
* {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}
69+
*
70+
* @return
71+
*/
72+
public int getOrientation() {
73+
return FastConfig.getInstance(this).getRequestedOrientation();
74+
}
75+
76+
/**
77+
* 是否开启滑动返回
78+
*/
79+
protected boolean isSwipeBackEnable() {
80+
return FastConfig.getInstance(this).isSwipeBackEnable();
5481
}
5582

56-
protected View getNavigationBarControlView() {
57-
return mContentView;
83+
/**
84+
* 设置init之前用于调整属性
85+
*
86+
* @param navigationHelper
87+
*/
88+
protected void beforeControlNavigation(NavigationViewHelper navigationHelper) {
5889
}
5990

6091
@Override
@@ -79,14 +110,6 @@ protected void onCreate(Bundle savedInstanceState) {
79110
initView(savedInstanceState);
80111
}
81112

82-
private void setControlNavigation() {
83-
mNavigationViewHelper =
84-
getNavigationBarControl() != null ?
85-
getNavigationBarControl().createNavigationBarControl(this, getNavigationBarControlView()) :
86-
FastConfig.getInstance(this).getNavigationBarControl().createNavigationBarControl(this, getNavigationBarControlView());
87-
mNavigationViewHelper.init();
88-
}
89-
90113
@Override
91114
protected void onResume() {
92115
beforeLazyLoad();
@@ -109,31 +132,6 @@ protected void onDestroy() {
109132
FastStackUtil.getInstance().pop(this, false);
110133
}
111134

112-
/**
113-
* 是否开启滑动返回
114-
*/
115-
protected boolean isSwipeBackEnable() {
116-
return FastConfig.getInstance(this).isSwipeBackEnable();
117-
}
118-
119-
@Override
120-
public int getContentBackground() {
121-
return FastConfig.getInstance(this).getContentViewBackgroundResource();
122-
}
123-
124-
/**
125-
* 设置屏幕方向
126-
* 默认自动 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
127-
* 竖屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
128-
* 横屏 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
129-
* {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}
130-
*
131-
* @return
132-
*/
133-
public int getOrientation() {
134-
return FastConfig.getInstance(this).getRequestedOrientation();
135-
}
136-
137135
/**
138136
* 初始化滑动返回
139137
*/
@@ -167,11 +165,6 @@ public void onSwipeBackLayoutExecuted() {
167165
}
168166
}
169167

170-
@Nullable
171-
public <T extends View> T findViewByViewId(@IdRes int viewId) {
172-
return (T) findViewById(viewId);
173-
}
174-
175168
@Override
176169
public void beforeSetContentView() {
177170
mQuitEntity = FastConfig.getInstance(this).getQuitConfig();
@@ -185,6 +178,17 @@ public void beforeInitView() {
185178
}
186179
}
187180

181+
/**
182+
* 设置NavigationView控制
183+
*/
184+
private void setControlNavigation() {
185+
mNavigationViewHelper = FastConfig.getInstance(this).getNavigationBarControl()
186+
.createNavigationBarControl(this, mContentView);
187+
beforeControlNavigation(mNavigationViewHelper);
188+
mNavigationViewHelper.init();
189+
}
190+
191+
188192
@Override
189193
public void loadData() {
190194

@@ -226,10 +230,14 @@ protected void quitApp(boolean isSnackBar, boolean isBackToTask) {
226230
}
227231
if (mIsFirstBack) {
228232
if (isSnackBar) {
233+
boolean transEnable = (boolean) SPUtil.get(this, getClass().getSimpleName() + "0", false);
234+
boolean plusNavigationViewEnable = (boolean) SPUtil.get(this, getClass().getSimpleName() + "1", false);
229235
SnackBarUtil.with(mContentView)
230236
.setBgColor(mQuitEntity.getSnackBarBackgroundColor())
231237
.setMessageColor(mQuitEntity.getSnackBarMessageColor())
232238
.setMessage(mQuitEntity.getQuitMessage())
239+
.setBottomMargin(transEnable && !plusNavigationViewEnable ?
240+
NavigationBarUtil.getNavigationBarHeight(getWindowManager()) : 0)
233241
.show();
234242
} else {
235243
ToastUtil.show(mQuitEntity.getQuitMessage());

library/src/main/java/com/aries/library/fast/helper/NavigationViewHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.aries.library.fast.R;
1919
import com.aries.library.fast.manager.LoggerManager;
2020
import com.aries.library.fast.util.NavigationBarUtil;
21+
import com.aries.library.fast.util.SPUtil;
2122

2223
import java.lang.ref.SoftReference;
2324

@@ -180,7 +181,12 @@ public void init() {
180181
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
181182
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
182183
window.setNavigationBarColor(Color.TRANSPARENT);
184+
if (mTransEnable && !mPlusNavigationViewEnable) {
185+
window.setNavigationBarColor(mNavigationViewColor);
186+
}
183187
}
188+
SPUtil.put(activity, activity.getClass().getSimpleName() + "0", mTransEnable);
189+
SPUtil.put(activity, activity.getClass().getSimpleName() + "1", mPlusNavigationViewEnable);
184190
//控制底部输入框
185191
if (mControlBottomEditTextEnable) {
186192
setBottomView(!mPlusNavigationViewEnable && mControlEnable ? null : mBottomView);

0 commit comments

Comments
 (0)