Skip to content

Commit ca68aa9

Browse files
committed
重构设置全局TitleBarView设置方式
1 parent bdb984e commit ca68aa9

29 files changed

+180
-1005
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ dependencies {
135135

136136
## 重大更新日志
137137

138+
* 2.2.9-beta6
139+
       
140+
* 重构设置全局TitleBarView设置方式(通过TitleBarViewControl实现可参看AppImpl实现类)
141+
138142
* 2.2.9-beta5
139143

140144
* library 直接compile UIWidget core 3.1.0版本

apk/sample.apk

-7.67 KB
Binary file not shown.

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ dependencies {
7979
//万能适配器--一般都需要吧
8080
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
8181
//webView库 继承FastWebActivity需要,不需要内置WebView可以不compile
82-
compile 'com.just.agentweb:agentweb:3.1.0'
82+
compile 'com.just.agentweb:agentweb:4.0.2'
83+
//webView提供下载功能
84+
compile 'com.just.agentweb:download:4.0.2'
85+
// compile 'com.just.agentweb:filechooser:4.0.2'
8386
//下拉刷新库注意刷新头SmartRefreshHeader版本最好对应尤其头版本不要低于SmartRefreshLayout版本
8487
compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
8588
//图片加载 4.X

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import com.aries.library.fast.FastConfig;
1111
import com.aries.library.fast.entity.FastQuitConfigEntity;
12-
import com.aries.library.fast.entity.FastTitleConfigEntity;
1312
import com.aries.library.fast.manager.LoggerManager;
1413
import com.aries.library.fast.retrofit.FastMultiUrl;
1514
import com.aries.library.fast.retrofit.FastRetrofit;
@@ -77,24 +76,11 @@ public void onCreate() {
7776

7877
//全局配置参数
7978
AppImpl impl = new AppImpl(mContext);
80-
//全局标题栏TitleBarView设置--推荐先获取library里默认标题栏TitleBarView配置再按需修改的模式 FastTitleConfigEntity
81-
FastTitleConfigEntity titleConfig = FastConfig.getInstance(mContext).getTitleConfig();
8279
//全局主页面返回键操作设置--推荐先获取library里默认主页面点击返回键配置FastQuitConfigEntity配置再按需修改的模式 FastQuitConfigEntity
8380
FastQuitConfigEntity quitConfig = FastConfig.getInstance(mContext).getQuitConfig();
8481
FastConfig.getInstance(mContext)
8582
//设置Activity是否支持滑动返回-添加透明主题参考Demo样式;
8683
.setSwipeBackEnable(true, this)
87-
// 设置全局TitleBarView-其它属性请查看getInstance默认设置
88-
.setTitleConfig(titleConfig
89-
//设置TitleBarView 所有TextView颜色
90-
.setTitleTextColor(getResources().getColor(R.color.colorTitleText))
91-
//设置TitleBarView背景资源
92-
.setTitleBackgroundResource(R.color.colorTitleBackground)
93-
//设置是否状态栏浅色模式(深色状态栏文字及图标)
94-
.setLightStatusBarEnable(true)
95-
.setDividerHeight(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? SizeUtil.dp2px(0.5f) : 0)
96-
//设置TitleBarView海拔高度
97-
.setTitleElevation(mContext.getResources().getDimension(R.dimen.dp_elevation)))
9884
//设置Activity 点击返回键提示退出程序或返回桌面相关参数
9985
.setQuitConfig(quitConfig
10086
//设置是否退回桌面否则直接退出程序
@@ -124,6 +110,7 @@ public void onCreate() {
124110
.setHttpErrorControl(impl)
125111
//设置SmartRefreshLayout刷新头-自定加载使用BaseRecyclerViewAdapterHelper
126112
.setDefaultRefreshHeader(impl)
113+
.setTitleBarViewControl(impl)
127114
//设置虚拟导航栏控制
128115
.setNavigationBarControl(impl);
129116
LoggerManager.d(TAG, "total:" + (System.currentTimeMillis() - start));

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.graphics.Color;
6+
import android.graphics.drawable.Drawable;
7+
import android.os.Build;
68
import android.support.annotation.NonNull;
79
import android.support.annotation.Nullable;
10+
import android.support.v4.view.ViewCompat;
811
import android.view.View;
912

1013
import com.aries.library.fast.demo.helper.RefreshHeaderHelper;
@@ -15,15 +18,19 @@
1518
import com.aries.library.fast.i.LoadingDialog;
1619
import com.aries.library.fast.i.MultiStatusView;
1720
import com.aries.library.fast.i.NavigationBarControl;
21+
import com.aries.library.fast.i.TitleBarViewControl;
1822
import com.aries.library.fast.manager.LoggerManager;
1923
import com.aries.library.fast.retrofit.FastError;
24+
import com.aries.library.fast.util.FastUtil;
2025
import com.aries.library.fast.util.SizeUtil;
2126
import com.aries.library.fast.util.ToastUtil;
2227
import com.aries.library.fast.widget.FastLoadDialog;
2328
import com.aries.library.fast.widget.FastLoadMoreView;
2429
import com.aries.library.fast.widget.FastMultiStatusView;
2530
import com.aries.ui.helper.navigation.NavigationViewHelper;
2631
import com.aries.ui.util.RomUtil;
32+
import com.aries.ui.util.StatusBarUtil;
33+
import com.aries.ui.view.title.TitleBarView;
2734
import com.chad.library.adapter.base.BaseQuickAdapter;
2835
import com.chad.library.adapter.base.loadmore.LoadMoreView;
2936
import com.marno.easystatelibrary.EasyStatusView;
@@ -39,7 +46,7 @@
3946
* Description:
4047
*/
4148
public class AppImpl implements DefaultRefreshHeaderCreater
42-
, LoadMoreFoot, MultiStatusView, LoadingDialog, HttpErrorControl, NavigationBarControl {
49+
, LoadMoreFoot, MultiStatusView, LoadingDialog, HttpErrorControl, TitleBarViewControl, NavigationBarControl {
4350

4451
private Context mContext;
4552
private String TAG = this.getClass().getSimpleName();
@@ -118,7 +125,7 @@ public IMultiStatusView createMultiStatusView() {
118125
//根据具体情况可设置更多属性具体请参考FastMultiStatusView.Builder里set方法
119126
//默认设置请参考Builder(Context context)里初始化
120127
return new FastMultiStatusView.Builder(mContext)
121-
.setLoadingTextFakeBold(true)
128+
.setLoadingTextFakeBold(false)
122129
// .setTextColor(Color.MAGENTA)
123130
// .setTextColorResource(R.color.colorMultiText)
124131
// .setTextSizeResource(R.dimen.dp_multi_text_size)
@@ -190,6 +197,30 @@ public boolean createHttpErrorControl(int errorRes, int errorCode, @io.reactivex
190197
return false;
191198
}
192199

200+
/**
201+
* 控制全局TitleBarView
202+
*
203+
* @param titleBar
204+
* @param isActivity
205+
* @return
206+
*/
207+
@Override
208+
public boolean createTitleBarViewControl(TitleBarView titleBar, boolean isActivity) {
209+
//默认的MD风格返回箭头icon如使用该风格可以不用设置
210+
Drawable mDrawable = FastUtil.getTintDrawable(mContext.getResources().getDrawable(R.drawable.fast_ic_back),
211+
mContext.getResources().getColor(R.color.colorTitleText));
212+
//是否支持状态栏白色
213+
boolean isSupport = StatusBarUtil.isSupportStatusBarFontChange();
214+
//设置TitleBarView 所有TextView颜色
215+
titleBar.setStatusBarLightMode(isSupport)
216+
//不支持黑字的设置白透明
217+
.setStatusAlpha(isSupport ? 0 : 102)
218+
.setLeftTextDrawable(isActivity ? mDrawable : null)
219+
.setDividerHeight(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? SizeUtil.dp2px(0.5f) : 0);
220+
ViewCompat.setElevation(titleBar, mContext.getResources().getDimension(R.dimen.dp_elevation));
221+
return false;
222+
}
223+
193224
@NonNull
194225
@Override
195226
public NavigationViewHelper createNavigationBarControl(Activity activity, View bottomView) {
@@ -222,4 +253,6 @@ public NavigationViewHelper createNavigationBarControl(Activity activity, View b
222253
protected boolean isTrans() {
223254
return RomUtil.isEMUI() && (RomUtil.getEMUIVersion().compareTo("EmotionUI_4.1") > 0);
224255
}
256+
257+
225258
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public class SplashActivity extends FastTitleActivity {
2929
@BindView(R.id.tv_versionSplash) TextView tvVersion;
3030
@BindView(R.id.tv_copyRightSplash) TextView tvCopyRight;
3131

32-
@Override
33-
public boolean isLightStatusBarEnable() {
34-
return false;
35-
}
36-
3732
@Override
3833
public void beforeSetContentView() {
3934
if (!isTaskRoot()) {//防止应用后台后点击桌面图标造成重启的假象---MIUI及Flyme上发现过(原生未发现)
@@ -50,7 +45,8 @@ public void beforeInitView() {
5045

5146
@Override
5247
public void setTitleBar(TitleBarView titleBar) {
53-
titleBar.setVisibility(View.GONE);
48+
titleBar.setStatusBarLightMode(false)
49+
.setVisibility(View.GONE);
5450
}
5551

5652
@Override
@@ -63,7 +59,7 @@ public void initView(Bundle savedInstanceState) {
6359
if (!isTaskRoot()) {
6460
return;
6561
}
66-
if (!StatusBarUtil.isSupportStatusBarFontChange() && isLightStatusBarEnable()) {
62+
if (!StatusBarUtil.isSupportStatusBarFontChange()) {
6763
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏
6864
}
6965
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.aries.library.fast.module.activity.FastWebActivity;
1717
import com.aries.ui.view.title.TitleBarView;
1818
import com.just.agentweb.AgentWeb;
19-
import com.just.agentweb.DownLoadResultListener;
2019

2120
import java.io.File;
2221

@@ -49,11 +48,6 @@ protected int getProgressHeight() {
4948
return super.getProgressHeight();
5049
}
5150

52-
@Override
53-
public boolean isLightStatusBarEnable() {
54-
return mIsShowTitle;
55-
}
56-
5751
@Override
5852
public int getContentBackground() {
5953
return -1;
@@ -69,27 +63,14 @@ public void setTitleBar(TitleBarView titleBar) {
6963
}
7064

7165
@Override
72-
protected void setAgentWeb(AgentWeb.CommonAgentBuilder mAgentBuilder) {
66+
protected void setAgentWeb(AgentWeb.CommonBuilder mAgentBuilder) {
7367
super.setAgentWeb(mAgentBuilder);
74-
mAgentBuilder.addDownLoadResultListener(new DownLoadResultListener() {
75-
@Override
76-
public void success(String path) {
77-
if (path.endsWith(".apk")) {
78-
installApk(getApplicationContext(), path);
79-
}
80-
}
81-
82-
@Override
83-
public void error(String path, String resUrl, String cause, Throwable e) {
84-
85-
}
86-
});
8768
}
8869

8970
@Override
9071
protected void setAgentWeb(AgentWeb mAgentWeb) {
9172
super.setAgentWeb(mAgentWeb);
92-
WebView mWebView = mAgentWeb.getWebCreator().get();
73+
WebView mWebView = mAgentWeb.getWebCreator().getWebView();
9374
mWebView.setOnLongClickListener(new View.OnLongClickListener() {
9475
@Override
9576
public boolean onLongClick(View v) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
public class QQTitleActivity extends FastTitleActivity {
1616

17-
@Override
18-
public boolean isLightStatusBarEnable() {
19-
return false;
20-
}
21-
2217
@Override
2318
public int getContentLayout() {
2419
return R.layout.activity_qq_title;
@@ -32,6 +27,7 @@ public void initView(Bundle savedInstanceState) {
3227
@Override
3328
public void setTitleBar(TitleBarView titleBar) {
3429
titleBar.setLeftTextDrawable(R.drawable.ic_back_white)
30+
.setStatusBarLightMode(false)
3531
.setTitleMainText("QQ默认主题TitleBar背景渐变")
3632
.setTitleMainTextColor(Color.WHITE)
3733
.setBgResource(R.drawable.shape_qq_bg);

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,18 @@ protected boolean isSwipeBackEnable() {
3737
return true;
3838
}
3939

40-
@Override
41-
public boolean isLightStatusBarEnable() {
42-
return false;
43-
}
44-
4540
@Override
4641
public void setTitleBar(TitleBarView titleBar) {
4742
title = getIntent().getStringExtra("title");
48-
titleBar.setStatusAlpha(102)
43+
titleBar.setStatusBarLightMode(false)
4944
.setCenterGravityLeft(true)
45+
//微信之前版本是有半透明效果最新版是全透明的
46+
// .setStatusAlpha(102)
5047
.setCenterGravityLeftPadding(SizeUtil.dp2px(24))
5148
.setTitleMainText(title)
5249
.setTitleMainTextColor(Color.WHITE)
5350
.setLeftTextDrawable(R.drawable.ic_back_white)
54-
.setBackgroundColor(Color.parseColor("#38393E"));
51+
.setBgColor(Color.parseColor("#373A41"));
5552
}
5653

5754
@Override

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
*/
1616
public abstract class ALiPayBaseFragment extends FastTitleFragment {
1717
String[] titles;
18-
19-
@Override
20-
public boolean isLightStatusBarEnable() {
21-
return false;
22-
}
23-
2418
@Override
2519
public void beforeSetTitleBar(TitleBarView titleBar) {
2620
super.beforeSetTitleBar(titleBar);
2721
titles = getResources().getStringArray(R.array.arrays_tab_ali);
2822
titleBar.setStatusAlpha(75)
23+
.setStatusBarLightMode(false)
2924
.setLeftTextColor(Color.WHITE)
3025
.setRightTextColor(Color.WHITE)
3126
.setLeftTextSize(TypedValue.COMPLEX_UNIT_DIP, 16)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ ext{
3232
targetSdkVersion = 25
3333
supportVersion = "25.3.1"
3434
versionCode = 229
35-
versionName = "2.2.9-beta5"
35+
versionName = "2.2.9-beta6"
3636
}

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies {
4747
//万能适配器
4848
provided 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
4949
//webView库
50-
provided 'com.just.agentweb:agentweb:3.0.0'
50+
provided 'com.just.agentweb:agentweb:4.0.2'
5151
//下拉刷新库
5252
provided 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
5353
//图片加载

0 commit comments

Comments
 (0)