Skip to content

Commit 03ad314

Browse files
wangxqwangxq
authored andcommitted
添加debugview
1 parent b5d0f15 commit 03ad314

File tree

15 files changed

+694
-212
lines changed

15 files changed

+694
-212
lines changed

commonlibrary/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ dependencies {
227227

228228
//七牛sdk上传文件啥的
229229
api rootProject.ext.deps["qiniu"]
230+
//状态栏工具类
230231
api rootProject.ext.deps["immersionbar"]
231232
api rootProject.ext.deps["immersionbar-components"]
232-
233+
api rootProject.ext.deps["statusbarutil"]
234+
api 'com.github.ltym2016:StatusBarUtils:1.0.6'
235+
//debug 视图成
236+
api rootProject.ext.deps["debugkit"]
233237
// api rootProject.ext.deps["bmob-sdk"]
234238

235239
// api rootProject.ext.deps["bmob-push"]

commonlibrary/src/main/java/com/wxq/commonlibrary/base/BaseActivity.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
import android.content.IntentFilter;
77
import android.os.Bundle;
88
import androidx.annotation.Nullable;
9+
import androidx.core.content.ContextCompat;
910
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
1011
import android.view.LayoutInflater;
1112
import android.view.View;
13+
import android.view.ViewGroup;
14+
import android.widget.FrameLayout;
1215
import android.widget.LinearLayout;
1316

1417
import com.alibaba.android.arouter.launcher.ARouter;
18+
import com.gyf.immersionbar.BarHide;
1519
import com.gyf.immersionbar.ImmersionBar;
1620
import com.orhanobut.logger.Logger;
21+
import com.samluys.statusbar.StatusBarUtils;
1722
import com.tbruyelle.rxpermissions2.RxPermissions;
1823
import com.trello.rxlifecycle2.LifecycleTransformer;
1924
import com.trello.rxlifecycle2.android.ActivityEvent;
@@ -23,8 +28,10 @@
2328
import com.wxq.commonlibrary.baserx.Event;
2429
import com.wxq.commonlibrary.baserx.RxBusManager;
2530
import com.wxq.commonlibrary.util.AppManager;
31+
import com.wxq.commonlibrary.util.BarUtils;
2632
import com.wxq.commonlibrary.util.RxHelp;
2733
import com.wxq.commonlibrary.util.ToastUtils;
34+
import com.wxq.commonlibrary.weiget.DebugView;
2835
import com.wxq.commonlibrary.weiget.DialogManager;
2936
import com.wxq.commonlibrary.weiget.TopBarHeard;
3037

@@ -57,11 +64,31 @@ public abstract class BaseActivity<T extends BasePresenter> extends RxAppCompatA
5764
* 默认显示顶部top栏
5865
*/
5966
public boolean needHeardLayout = true;
60-
67+
private DebugView debugView;
6168
@Override
6269
protected void onCreate(@Nullable Bundle savedInstanceState) {
6370
super.onCreate(savedInstanceState);
6471
needHeardLayout = isNeedHeardLayout();
72+
73+
StatusBarUtils.transparencyBar(this);
74+
// if (mIsStatusBarDark) {
75+
StatusBarUtils.StatusBarIconDark(this);
76+
// } else {
77+
// StatusBarUtils.StatusBarIconLight(this);
78+
// }
79+
// ImmersionBar.with(this)
80+
// .transparentStatusBar()
81+
//// .statusBarColor(R.color.red_300)
82+
// .hideBar(BarHide.FLAG_HIDE_BAR)
83+
// .init();
84+
85+
// BarUtils.setStatusBarVisibility(this,false);
86+
// if (mIsStatusBarDark) {
87+
// StatusBarUtils.StatusBarIconDark(this);
88+
// } else {
89+
// StatusBarUtils.StatusBarIconLight(this);
90+
// }
91+
6592
if (needHeardLayout) {
6693
LinearLayout linearLayout = new LinearLayout(this);
6794
linearLayout.setOrientation(LinearLayout.VERTICAL);
@@ -73,6 +100,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
73100
} else {
74101
setContentView(attachLayoutRes());
75102
}
103+
104+
debugView = new DebugView(this);
105+
106+
//夜间模式上面盖的控件
107+
nightFrameLayout = new View(this);
108+
109+
76110
unbinder = ButterKnife.bind(this);
77111
context = this;
78112
lifecycleSubject.onNext(ActivityEvent.CREATE);
@@ -90,9 +124,31 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
90124
initRxBus();
91125
// arouter 依赖注入
92126
ARouter.getInstance().inject(this);
127+
addExtraView();
128+
}
129+
protected View nightFrameLayout;
130+
private void addExtraView() {
131+
FrameLayout rootView = findViewById(android.R.id.content);
132+
if (rootView == null) {
133+
return;
134+
}
93135

136+
if (debugView != null) {
137+
rootView.removeView(debugView);
138+
rootView.addView(debugView);
139+
}
140+
//
141+
if (nightFrameLayout != null) {
142+
nightFrameLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.black_transparency_100));
143+
rootView.removeView(nightFrameLayout);
144+
rootView.addView(nightFrameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
145+
}
94146
}
95147

148+
149+
150+
151+
96152
private void initRxBus() {
97153
disposable = RxBusManager.getInstance().registerEvent(Event.class, new Consumer<Event>() {
98154
@Override
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
package com.wxq.commonlibrary.weiget;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.graphics.Color;
6+
import android.graphics.Rect;
7+
import android.util.AttributeSet;
8+
import android.view.Gravity;
9+
import android.view.MotionEvent;
10+
import android.view.View;
11+
import android.widget.FrameLayout;
12+
import android.widget.ImageView;
13+
import androidx.annotation.NonNull;
14+
import androidx.annotation.Nullable;
15+
import androidx.appcompat.app.AppCompatActivity;
16+
import androidx.customview.widget.ViewDragHelper;
17+
import androidx.fragment.app.Fragment;
18+
import androidx.fragment.app.FragmentManager;
19+
20+
import com.hulab.debugkit.DebugFunction;
21+
import com.hulab.debugkit.DevTool;
22+
import com.hulab.debugkit.DevToolFragment;
23+
import com.wxq.commonlibrary.R;
24+
import com.wxq.commonlibrary.util.DensityUtil;
25+
import com.wxq.commonlibrary.util.ScreenUtils;
26+
import com.wxq.commonlibrary.util.StringUtils;
27+
28+
/**
29+
* @author ArcherYc
30+
* @date on 2018/9/27 上午9:16
31+
* @mail 247067345@qq.com
32+
*/
33+
public class DebugView extends FrameLayout {
34+
35+
private ViewDragHelper mViewDragHelper;
36+
37+
private Context mContext;
38+
39+
private AppCompatActivity mActivity;
40+
41+
private ImageView imvDebug;
42+
43+
private DevTool.Builder builder;
44+
45+
46+
public DebugView(AppCompatActivity activity) {
47+
this(activity, null);
48+
this.mContext = activity;
49+
this.mActivity = activity;
50+
builder = new DevTool.Builder(activity);
51+
setBackgroundColor(Color.TRANSPARENT);
52+
init();
53+
}
54+
55+
private DebugView(Context context) {
56+
this(context, null);
57+
}
58+
59+
private DebugView(Context context, @Nullable AttributeSet attrs) {
60+
this(context, attrs, 0);
61+
}
62+
63+
private DebugView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
64+
super(context, attrs, defStyleAttr);
65+
}
66+
67+
private void init() {
68+
initDebugBuilder();
69+
70+
initFloatButton();
71+
}
72+
73+
private void initDebugBuilder() {
74+
int screenWidth = ScreenUtils.getScreenWidth();
75+
int screenHeight = ScreenUtils.getScreenHeight();
76+
int consoleWidth = screenWidth / 3 * 2;
77+
int consoleHeight = screenHeight / 2;
78+
builder.getTool().setConsoleWidth(DensityUtil.px2dip(mContext, consoleWidth));
79+
builder.getTool().setConsoleHeight(DensityUtil.px2dip(mContext, consoleHeight));
80+
// builder.addFunction(new DebugFunction("跳转调试页面") {
81+
// @Override
82+
// public String call() throws Exception {
83+
// mContext.startActivity(new Intent(mContext, ChooseCityActivity.class));
84+
// return null;
85+
// }
86+
// });
87+
// builder.addFunction(new DebugFunction("测试js") {
88+
// @Override
89+
// public String call() throws Exception {
90+
//
91+
// return null;
92+
// }
93+
// });
94+
builder.addFunction(new DebugFunction("activity") {
95+
@Override
96+
public String call() throws Exception {
97+
return "\n" + mActivity.getClass().getSimpleName();
98+
}
99+
}).addFunction(new DebugFunction("fragment") {
100+
@Override
101+
public String call() throws Exception {
102+
FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
103+
StringBuilder sb = new StringBuilder("\n");
104+
addFragmentStr(sb, fragmentManager);
105+
if (StringUtils.isEmpty(sb.toString())) {
106+
return "no fragment";
107+
} else {
108+
return sb.toString();
109+
}
110+
}
111+
});
112+
builder.setTheme(DevToolFragment.DevToolTheme.DARK)
113+
.displayAt(screenWidth / 2 - consoleWidth / 2, screenHeight / 2 - consoleHeight / 2);
114+
}
115+
116+
private void addFragmentStr(StringBuilder sb, FragmentManager activityFragmentManager) {
117+
for (Fragment fragment : activityFragmentManager.getFragments()) {
118+
View view = fragment.getView();
119+
Rect rect = new Rect();
120+
boolean visible = false;
121+
if (view != null) {
122+
visible = view.getGlobalVisibleRect(rect);
123+
}
124+
if (visible && fragment.isVisible() && fragment.getChildFragmentManager().getFragments().size() == 0) {
125+
sb.append(fragment.getClass().getSimpleName() + "--->visible" + "\n");
126+
} else {
127+
sb.append(fragment.getClass().getSimpleName() + "\n");
128+
}
129+
if (fragment.isVisible() && fragment.getChildFragmentManager().getFragments().size() > 0) {
130+
addFragmentStr(sb, fragment.getChildFragmentManager());
131+
}
132+
}
133+
}
134+
135+
private void initFloatButton() {
136+
imvDebug = new ImageView(mContext);
137+
imvDebug.setImageResource(R.mipmap.icon_debug);
138+
LayoutParams lp = new LayoutParams(DensityUtil.dip2px(mContext, 45),
139+
DensityUtil.dip2px(mContext, 45));
140+
lp.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
141+
imvDebug.setLayoutParams(lp);
142+
imvDebug.setOnClickListener(new OnClickListener() {
143+
@Override
144+
public void onClick(View v) {
145+
if (!builder.getTool().isAdded()) {
146+
builder.build();
147+
}
148+
}
149+
});
150+
151+
addView(imvDebug);
152+
mViewDragHelper = ViewDragHelper.create(this, new ViewDragHelper.Callback() {
153+
@Override
154+
public boolean tryCaptureView(@NonNull View view, int i) {
155+
if (view.equals(imvDebug)) {
156+
return true;
157+
} else {
158+
return false;
159+
}
160+
}
161+
162+
@Override
163+
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
164+
return left;
165+
}
166+
167+
@Override
168+
public int clampViewPositionVertical(@NonNull View child, int top, int dy) {
169+
return top;
170+
}
171+
172+
@Override
173+
public int getViewVerticalDragRange(@NonNull View child) {
174+
return getContext().getResources().getDisplayMetrics().heightPixels;
175+
}
176+
177+
@Override
178+
public int getViewHorizontalDragRange(@NonNull View child) {
179+
return getContext().getResources().getDisplayMetrics().widthPixels;
180+
}
181+
});
182+
}
183+
184+
@Override
185+
public boolean onInterceptTouchEvent(MotionEvent ev) {
186+
if (mViewDragHelper != null) {
187+
return mViewDragHelper.shouldInterceptTouchEvent(ev);
188+
}
189+
return false;
190+
}
191+
192+
@Override
193+
public boolean onTouchEvent(MotionEvent event) {
194+
if (mViewDragHelper != null) {
195+
mViewDragHelper.processTouchEvent(event);
196+
}
197+
boolean inX = event.getX() > imvDebug.getX() && event.getX() < imvDebug.getX() + imvDebug.getWidth();
198+
boolean inY = event.getY() > imvDebug.getY() && event.getY() < imvDebug.getY() + imvDebug.getHeight();
199+
return inX && inY;
200+
}
201+
202+
public void dismissDebugView() {
203+
if (builder != null) {
204+
if (builder.getTool().isAdded()) {
205+
try {
206+
mActivity.getFragmentManager()
207+
.beginTransaction()
208+
.remove(builder.getTool())
209+
.commit();
210+
} catch (Exception e) {
211+
e.printStackTrace();
212+
}
213+
}
214+
}
215+
}
216+
217+
public DevTool.Builder getDebugTool() {
218+
return builder;
219+
}
220+
221+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

config.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ ext {
240240
//个推
241241
"getui" : "com.getui:sdk:2.13.2.0",
242242
//沉浸式状态栏
243-
"immersionbar" : "com.gyf.immersionbar:immersionbar:3.0.0-beta07",
244-
"immersionbar-components" : "com.gyf.immersionbar:immersionbar-components:3.0.0-beta07",
245-
"flexbox" : "com.google.android:flexbox:1.1.1"
243+
"immersionbar" : "com.gyf.immersionbar:immersionbar:3.0.0",
244+
"immersionbar-components" : "com.gyf.immersionbar:immersionbar-components:3.0.0",
245+
"flexbox" : "com.google.android:flexbox:1.1.1",
246+
"debugkit" : "com.hulab.android:debugkit:1.2.1",
247+
"statusbarutil" : "com.jaeger.statusbarutil:library:1.5.1",
246248

247249

248250
]

interviewdemo/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ dependencies {
3232
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3333
annotationProcessor "com.neenbedankt.gradle.plugins:android-apt:1.8"
3434

35-
// 运行时注解
36-
implementation project(':inject')
37-
//编译时注解
38-
implementation project(':inject_annotion')
39-
annotationProcessor project(':inject_compiler')
35+
// // 运行时注解
36+
// implementation project(':inject')
37+
// //编译时注解
38+
// implementation project(':inject_annotion')
39+
// annotationProcessor project(':inject_compiler')
4040

4141
// implementation project(':trackpoint')
4242
}

0 commit comments

Comments
 (0)