Skip to content

Commit

Permalink
feat(dokit): 增加几个公共button
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Jul 11, 2022
1 parent fa6a96e commit a05a529
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 21 deletions.
34 changes: 13 additions & 21 deletions dokit/src/main/java/com/hss01248/dokit/MyDokit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.blankj.utilcode.util.GsonUtils;
import com.didichuxing.doraemonkit.DoraemonKit;
import com.didichuxing.doraemonkit.kit.AbstractKit;
import com.didichuxing.doraemonkit.kit.webdoor.WebDoorManager;
import com.google.gson.GsonBuilder;
import com.hss01248.dokit.btns.ActivityTaskViewBtn;
import com.hss01248.dokit.btns.AndroidConfigInfoDisplayBtn;
import com.hss01248.dokit.btns.BuildTypeInfoDisplayBtn;
import com.hss01248.dokit.btns.DbDebugBtn;
import com.hss01248.dokit.btns.UEKit;
import com.hss01248.dokit.btns.GitBranchBtn;
import com.hss01248.dokit.btns.GoAppSettingsBtn;
import com.hss01248.dokit.btns.UserInfoDisplayBtn;
import com.hss01248.dokit.parts.BaseButton;
import com.hss01248.dokit.parts.BaseSwitcherKit;
import com.hss01248.dokit.parts.ICustomButton;
import com.hss01248.dokit.parts.ThirdToolKit;
import com.hss01248.dokit.switchs.StrickModeKit;

Expand Down Expand Up @@ -53,6 +56,7 @@ public static IDokitConfig getConfig() {
static List<AbstractKit> extraKits = new ArrayList<>();

static void init(Application context){
GsonUtils.setGson("nice",new GsonBuilder().setPrettyPrinting().create());
List<AbstractKit> kits = new ArrayList<>();
kits.add(new ThirdToolKit());
addKitsInternal(kits);
Expand Down Expand Up @@ -80,26 +84,14 @@ public void onFirstActivityCreated(Activity activity) {
}

private static void addKitsInternal(List<AbstractKit> kits) {
kits.add(new BaseButton(new ICustomButton() {
@Override
public int getName() {
return R.string.testkit_go_setting;
}

@Override
public int getIcon() {
return R.drawable.tools_go_settings;
}

@Override
public void onClick() {
InitForDokit.goAppSettings();
}
}));
kits.add(new BaseButton(new GoAppSettingsBtn()));
kits.add(new BaseButton(new ActivityTaskViewBtn()));
kits.add(new BaseButton(new DbDebugBtn()));
kits.add(new StrickModeKit());
kits.add(new UEKit());
kits.add(new BaseButton(new GitBranchBtn()));
kits.add(new BaseButton(new BuildTypeInfoDisplayBtn()));
kits.add(new BaseButton(new AndroidConfigInfoDisplayBtn()));
kits.add(new BaseButton(new UserInfoDisplayBtn()));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.hss01248.dokit.btns;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.Configuration;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.Utils;
import com.hss01248.dokit.R;
import com.hss01248.dokit.parts.ICustomButton;

import java.util.HashMap;
import java.util.Map;

/**
* @Despciption todo
* @Author hss
* @Date 11/07/2022 14:29
* @Version 1.0
*/
public class AndroidConfigInfoDisplayBtn extends ICustomButton {
@Override
public int getName() {
return R.string.tools_build_activity_info;
}

@Override
public int getIcon() {
return R.drawable.icon_info_testtool;
}

@Override
public void onClick() {


String msg = getAndroidConfig();
AlertDialog dialog = new AlertDialog.Builder(ActivityUtils.getTopActivity())
.setTitle("android Config信息")
.setMessage(msg)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).create();
dialog.show();
}

private static String getAndroidConfig() {
Activity activity = ActivityUtils.getTopActivity();
Configuration activityConfiguration = activity.getResources().getConfiguration();

Configuration appConfiguration = Utils.getApp().getResources().getConfiguration();

Map map = new HashMap();
map.put("activityConfiguration",activityConfiguration);
map.put("appConfiguration",appConfiguration);
return GsonUtils.getGson("nice").toJson(map);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.hss01248.dokit.btns;

import android.content.DialogInterface;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.Utils;
import com.hss01248.dokit.R;
import com.hss01248.dokit.parts.ICustomButton;

import java.lang.reflect.Field;

/**
* @Despciption todo
* @Author hss
* @Date 11/07/2022 14:28
* @Version 1.0
*/
public class BuildTypeInfoDisplayBtn extends ICustomButton {
@Override
public int getName() {
return R.string.tools_buildtype_info;
}

@Override
public int getIcon() {
return R.drawable.icon_info_testtool;
}

@Override
public void onClick() {

Class buildConfig = buildConfig();
String msg = "BuildConfig信息未能通过反射得到";
if(buildConfig != null){
Field[] declaredFields = buildConfig.getDeclaredFields();
if(declaredFields != null){
msg = buildConfig.getName()+":\n\n";
for (Field field : declaredFields) {
field.setAccessible(true);
try {
msg += (field.getName().toLowerCase()+": "+field.get(buildConfig)+"\n");
}catch (Throwable throwable){
LogUtils.w(throwable);
}
}
}
}
AlertDialog dialog = new AlertDialog.Builder(ActivityUtils.getTopActivity())
.setTitle("BuildConfig信息")
.setMessage(msg)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).create();
dialog.show();
}

private static Class buildConfig() {
try {
String name0 = Utils.getApp().getPackageName() + ".BuildConfig";
Class clazz = Class.forName(name0);
return clazz;
} catch (Throwable throwable) {
LogUtils.d("getBuildType", "xx", throwable);
String name = Utils.getApp().getClass().getName();
name = name.substring(0, name.lastIndexOf("."));
while (name.contains(".")){
String config = name + ".BuildConfig";
try {
Class clazz = Class.forName(config);
if(clazz != null){
return clazz;
}
} catch (ClassNotFoundException e) {
LogUtils.i(e);
}
name = name.substring(0, name.lastIndexOf("."));
}
return null;
}
}
}
37 changes: 37 additions & 0 deletions dokit/src/main/java/com/hss01248/dokit/btns/GitBranchBtn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.hss01248.dokit.btns;

import com.blankj.utilcode.util.ReflectUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.hss01248.dokit.R;
import com.hss01248.dokit.parts.ICustomButton;

/**
* @Despciption todo
* @Author hss
* @Date 11/07/2022 14:21
* @Version 1.0
*/
public class GitBranchBtn extends ICustomButton {
@Override
public int getName() {
return R.string.tools_show_branch;
}

@Override
public int getIcon() {
return R.drawable.icon_tool_git;
}

@Override
public void onClick() {
try {
String str = ReflectUtils.reflect(Utils.getApp().getPackageName()+".BuildConfig").field("BRANCH").get();
ToastUtils.showLong(str);
}catch (Throwable throwable){
throwable.printStackTrace();
ToastUtils.showLong("请在buildtype里配置: \n buildConfigField 'String', 'BRANCH', '\"' + getGitBranch() + '\"'");
}

}
}
28 changes: 28 additions & 0 deletions dokit/src/main/java/com/hss01248/dokit/btns/GoAppSettingsBtn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hss01248.dokit.btns;

import com.hss01248.dokit.InitForDokit;
import com.hss01248.dokit.R;
import com.hss01248.dokit.parts.ICustomButton;

/**
* @Despciption todo
* @Author hss
* @Date 11/07/2022 14:47
* @Version 1.0
*/
public class GoAppSettingsBtn extends ICustomButton {
@Override
public int getName() {
return R.string.testkit_go_setting;
}

@Override
public int getIcon() {
return R.drawable.tools_go_settings;
}

@Override
public void onClick() {
InitForDokit.goAppSettings();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.hss01248.dokit.btns;

import android.content.DialogInterface;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ActivityUtils;
import com.hss01248.dokit.MyDokit;
import com.hss01248.dokit.R;
import com.hss01248.dokit.parts.ICustomButton;

/**
* @Despciption todo
* @Author hss
* @Date 11/07/2022 14:23
* @Version 1.0
*/
public class UserInfoDisplayBtn extends ICustomButton {
@Override
public int getName() {
return R.string.tools_user_info;
}

@Override
public int getIcon() {
return R.drawable.icon_info_testtool;
}

@Override
public void onClick() {
String msg = "MyDokit.getConfig()未设置";

if( MyDokit.getConfig() != null){
msg = MyDokit.getConfig().getUserInfo();
}
AlertDialog dialog = new AlertDialog.Builder(ActivityUtils.getTopActivity())
.setTitle("用户信息")
.setMessage(msg)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).create();
dialog.show();
}
}
Binary file added dokit/src/main/res/drawable-xxhdpi/apps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dokit/src/main/res/drawable-xxhdpi/block.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/chuck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/combutton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/dns_host.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/ic_leak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/stetho.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/switchhost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dokit/src/main/res/drawable-xxhdpi/uicompare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions dokit/src/main/res/values/stringx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@
<string name="testkit_perfdog">perfDog</string>
<string name="testkit_anr">anr</string>
<string name="testkit_exception">查看exception</string>

<string name="tool_switchhost2">切换环境</string>
<string name="tools_show_branch">显示分支名</string>
<string name="tools_download_apk">下载最新包</string>
<string name="tools_user_info">用户信息</string>
<string name="tools_buildtype_info">BuildConfig</string>
<string name="tools_build_activity_info">ActivityConfig</string>
</resources>

0 comments on commit a05a529

Please sign in to comment.