├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ └── demo_bg.xml
│ │ │ └── layout
│ │ │ │ ├── block_activity.xml
│ │ │ │ ├── common_activity.xml
│ │ │ │ ├── ui_activity.xml
│ │ │ │ ├── database_activity.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── io
│ │ │ │ └── palaima
│ │ │ │ └── debugdrawer
│ │ │ │ └── app
│ │ │ │ ├── UiActivity.java
│ │ │ │ ├── CustomDevActivity.java
│ │ │ │ ├── BlockActivity.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── LeakActivity.java
│ │ │ │ ├── OkHttp3Activity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── DataBaseActivity.java
│ │ │ │ └── utils
│ │ │ │ └── DataBaseHelper.java
│ │ └── AndroidManifest.xml
│ ├── androidTest
│ │ └── java
│ │ │ └── io
│ │ │ └── palaima
│ │ │ └── debugdrawer
│ │ │ └── app
│ │ │ └── ApplicationTest.java
│ └── debug
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── io
│ │ └── palaima
│ │ └── debugdrawer
│ │ └── debug
│ │ ├── CustomDevModule.java
│ │ └── DebugApplication.java
├── proguard-rules.pro
└── build.gradle
├── lib
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── kale.png
│ │ │ ├── dd_module_header_bg.9.png
│ │ │ ├── sak_box_bg.xml
│ │ │ ├── location.xml
│ │ │ ├── wifi.xml
│ │ │ ├── tool.xml
│ │ │ ├── energy.xml
│ │ │ ├── delete.xml
│ │ │ ├── info.xml
│ │ │ └── settings.xml
│ │ ├── values
│ │ │ ├── color.xml
│ │ │ ├── ids.xml
│ │ │ ├── attrs.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ ├── dd_module_title.xml
│ │ │ ├── dd_request_list_activity.xml
│ │ │ ├── dd_debug_drawer.xml
│ │ │ ├── dd_icon_button.xml
│ │ │ ├── dd_debug_drawer_slider.xml
│ │ │ ├── dd_pkg_info_dialog.xml
│ │ │ └── dd_request_info_item.xml
│ │ ├── java
│ │ ├── io
│ │ │ └── palaima
│ │ │ │ └── debugdrawer
│ │ │ │ ├── view
│ │ │ │ ├── EmptyActivity.java
│ │ │ │ └── ScrimInsetsFrameLayout.java
│ │ │ │ ├── DebugWidget.java
│ │ │ │ ├── BaseDebugModule.java
│ │ │ │ ├── modules
│ │ │ │ ├── MemoryModule.java
│ │ │ │ ├── ActivityModule.java
│ │ │ │ ├── SakModule.java
│ │ │ │ ├── DevToolsModule.java
│ │ │ │ ├── DataBaseModule.java
│ │ │ │ ├── LogcatModule.java
│ │ │ │ ├── OkHttp3Module.java
│ │ │ │ ├── MonitorModule.java
│ │ │ │ ├── NetworkModule.java
│ │ │ │ ├── DeviceModule.java
│ │ │ │ ├── SettingsModule.java
│ │ │ │ └── BuildModule.java
│ │ │ │ ├── util
│ │ │ │ ├── DebugDrawerUtil.java
│ │ │ │ ├── UIUtils.java
│ │ │ │ ├── PackageManagerHook.java
│ │ │ │ └── NetworkController.java
│ │ │ │ ├── DebugWidgetStore.java
│ │ │ │ ├── DebugDrawer.java
│ │ │ │ └── DebugWidgetsFrame.java
│ │ └── com
│ │ │ ├── github
│ │ │ └── simonpercic
│ │ │ │ └── oklog
│ │ │ │ └── core
│ │ │ │ ├── RequestModel.java
│ │ │ │ ├── CustomLogManager.java
│ │ │ │ └── RequestListActivity.java
│ │ │ └── wanjian
│ │ │ └── sak
│ │ │ └── config
│ │ │ └── SakConfigBuild.java
│ │ └── AndroidManifest.xml
└── build.gradle
├── settings.gradle
├── images
├── dd01.png
├── dd02.png
└── dd03.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── config.gradle
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
--------------------------------------------------------------------------------
/images/dd01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/images/dd01.png
--------------------------------------------------------------------------------
/images/dd02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/images/dd02.png
--------------------------------------------------------------------------------
/images/dd03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/images/dd03.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/kale.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/lib/src/main/res/drawable/kale.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/dd_module_header_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleai/DebugDrawer/HEAD/lib/src/main/res/drawable/dd_module_header_bg.9.png
--------------------------------------------------------------------------------
/lib/src/main/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #222222
4 | #ee212121
5 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Debug Drawer
3 |
4 | Hello world!
5 | Open DebugView
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #b0ff541a
5 | #ff5722
6 | #e64a19
7 |
8 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 21 11:06:42 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/demo_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/sak_box_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_module_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/io/palaima/debugdrawer/app/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 |
11 | public ApplicationTest() {
12 | super(Application.class);
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/UiActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | /**
8 | * @author Kale
9 | * @date 2017/3/22
10 | */
11 | public class UiActivity extends AppCompatActivity{
12 |
13 | @Override
14 | protected void onCreate(@Nullable Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.ui_activity);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/block_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/common_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 |
3 | android = [compileSdkVersion: 23,
4 | buildToolsVersion: "23.0.2",
5 | minSdkVersion : 16,
6 | targetSdkVersion : 22,
7 | versionCode : 1,
8 | versionName : "1.0.0"]
9 |
10 | dependencies = ["support-v4" : 'com.android.support:support-v4:23.2.1',
11 | "appcompat-v7" : 'com.android.support:appcompat-v7:23.2.1',
12 | "support-annotations": 'com.android.support:support-annotations:23.1.1'
13 | ]
14 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio
29 | .idea/
30 | .gradle
31 | /*/local.properties
32 | /*/out
33 | /*/*/build
34 | /*/*/production
35 | *.iml
36 | *.iws
37 | *.ipr
38 | *~
39 | *.swp
40 | signing.properties
41 | build/
42 |
43 | *.jks
44 |
45 | # Mac OS
46 | .DS_STORE
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/view/EmptyActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.view;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | /**
8 | * @author Kale
9 | * @date 2017/6/28
10 | */
11 | public class EmptyActivity extends Activity{
12 |
13 | @Override
14 | protected void onCreate(@Nullable Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(android.R.layout.list_content);
17 | }
18 |
19 | @Override
20 | protected void onResume() {
21 | super.onResume();
22 | finish();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 320dp
7 |
8 | 0dp
9 |
10 | 8dp
11 |
12 | 16dp
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/CustomDevActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.TextView;
7 |
8 | /**
9 | * @author Kale
10 | * @date 2017/5/10
11 | */
12 | public class CustomDevActivity extends AppCompatActivity{
13 |
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.common_activity);
18 |
19 | ((TextView) findViewById(R.id.content_tv)).setText("Custom Dev Page");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/github/simonpercic/oklog/core/RequestModel.java:
--------------------------------------------------------------------------------
1 | package com.github.simonpercic.oklog.core;
2 |
3 | /**
4 | * @author Kale
5 | * @date 2017/5/12
6 | */
7 | public class RequestModel {
8 |
9 | public String method;
10 |
11 | public String url;
12 |
13 | public int code;
14 |
15 | public String detailUrl;
16 |
17 | public String time;
18 |
19 | public RequestModel(String method, String url, int code, String time) {
20 | this.method = method;
21 | this.url = url;
22 | this.code = code;
23 | this.time = time;
24 | }
25 |
26 | public void setDetailUrl(String detailUrl) {
27 | this.detailUrl = detailUrl;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in init.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/DebugWidget.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * @author Kale
7 | * @date 2017/6/28
8 | */
9 | public class DebugWidget {
10 |
11 | protected String title;
12 |
13 | protected View view;
14 |
15 | protected int id;
16 |
17 | public DebugWidget(String title, View view, int id) {
18 | this.title = title;
19 | this.view = view;
20 | this.id = id;
21 | }
22 |
23 | public String getTitle() {
24 | return title;
25 | }
26 |
27 | public V getView() {
28 | return (V) view;
29 | }
30 |
31 | public int getId() {
32 | return id;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_request_list_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Sat May 30 12:41:55 EEST 2015
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_debug_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_icon_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
25 |
26 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/location.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/BlockActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | /**
9 | * @author Kale
10 | * @date 2017/5/11
11 | */
12 | public class BlockActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.block_activity);
18 | findViewById(R.id.block_btn).setOnClickListener(new View.OnClickListener() {
19 | @Override
20 | public void onClick(View v) {
21 | try {
22 | Thread.sleep(2000);
23 | } catch (InterruptedException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/BaseDebugModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer;
2 |
3 | import android.app.Activity;
4 | import android.support.annotation.NonNull;
5 |
6 | /**
7 | * @author Kale
8 | * @date 2017/3/22
9 | */
10 | public abstract class BaseDebugModule {
11 |
12 | private Activity activity;
13 |
14 | protected void onDrawerOpened() {
15 | }
16 |
17 | @NonNull
18 | public abstract String getName();
19 |
20 | protected abstract DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder);
21 |
22 | protected void onAttachActivity(Activity activity) {
23 | }
24 |
25 | protected void onActivityResume() {
26 | }
27 |
28 | protected void onActivityDestroy() {
29 | }
30 |
31 | public void setActivity(Activity activity) {
32 | this.activity = activity;
33 | onAttachActivity(activity);
34 | }
35 |
36 | public Activity getActivity() {
37 | return activity;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/debug/java/io/palaima/debugdrawer/debug/CustomDevModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.debug;
2 |
3 | import android.content.Intent;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 |
7 | import io.palaima.debugdrawer.BaseDebugModule;
8 | import io.palaima.debugdrawer.DebugWidgetStore;
9 | import io.palaima.debugdrawer.app.CustomDevActivity;
10 |
11 | /**
12 | * @author Kale
13 | * @date 2017/5/10
14 | */
15 | class CustomDevModule extends BaseDebugModule {
16 |
17 | @NonNull
18 | @Override
19 | public String getName() {
20 | return "自定义调试页面";
21 | }
22 |
23 | @Override
24 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
25 | return builder.addButton("跳转到自定义调试页面", new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | getActivity().startActivity(new Intent(getActivity(), CustomDevActivity.class));
29 | }
30 | }).build();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | vectorDrawables.useSupportLibrary = true
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(include: ['*.jar'], dir: 'libs')
23 | provided 'com.squareup.okhttp3:okhttp:3.1.2'
24 | provided 'com.amitshekhar.android:debug-db:1.0.0'
25 | provided 'com.github.tianzhijiexian:Logcat:e6332a63d6'
26 | provided 'com.github.simonpercic:oklog3:2.1.0'
27 | provided 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
28 | provided 'com.github.markzhai:blockcanary-android:1.5.0'
29 | provided 'com.github.xcc3641:watcher:0.5'
30 | provided 'com.wanjian:sak:0.1.2.8'
31 | }
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_debug_drawer_slider.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/wifi.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
17 |
20 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_pkg_info_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
27 |
28 |
35 |
36 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/MemoryModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import java.text.DecimalFormat;
4 |
5 | import android.support.annotation.NonNull;
6 | import android.text.format.Formatter;
7 |
8 | import io.palaima.debugdrawer.BaseDebugModule;
9 | import io.palaima.debugdrawer.DebugWidgetStore;
10 |
11 | /**
12 | * @author Kale
13 | * @date 2017/3/22
14 | */
15 | public class MemoryModule extends BaseDebugModule {
16 |
17 | @NonNull
18 | @Override
19 | public String getName() {
20 | return "Memory";
21 | }
22 |
23 | @Override
24 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
25 | long maxMemory = Runtime.getRuntime().maxMemory();
26 | long totalMemory = Runtime.getRuntime().totalMemory();
27 |
28 | DecimalFormat format = new DecimalFormat("0.00%");
29 | String percent = format.format((double) totalMemory / maxMemory);
30 |
31 | return builder.addText("Total/Max",
32 | Formatter.formatFileSize(getActivity(), totalMemory) + "/" + Formatter.formatFileSize(getActivity(), maxMemory)
33 | + " (" + percent + ")")
34 | .build();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/ActivityModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import android.app.ActivityManager;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 |
7 | import io.palaima.debugdrawer.BaseDebugModule;
8 | import io.palaima.debugdrawer.DebugWidgetStore;
9 |
10 | /**
11 | * @author Kale
12 | * @date 2016/5/4
13 | */
14 | public class ActivityModule extends BaseDebugModule {
15 |
16 | @NonNull
17 | @Override
18 | public String getName() {
19 | return "Current Activity";
20 | }
21 |
22 | @Override
23 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
24 | String fullName = getRunningActivityName(getActivity());
25 | String[] names = fullName.split("\\.");
26 | return builder.addText(null, names[names.length - 1]).build();
27 | }
28 |
29 | /**
30 | * @return 手机当前的activity
31 | */
32 | public static String getRunningActivityName(Context context) {
33 | ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
34 | return activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/tool.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/energy.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
20 |
23 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/util/DebugDrawerUtil.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.util;
2 |
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.SharedPreferences;
8 | import android.content.pm.ResolveInfo;
9 | import android.support.annotation.CheckResult;
10 |
11 | /**
12 | * @author Kale
13 | * @date 2016/5/2
14 | */
15 | /*package*/public class DebugDrawerUtil {
16 |
17 | public static
18 | @CheckResult
19 | boolean hasClass(String className) {
20 | try {
21 | Class.forName(className);
22 | return true;
23 | } catch (ClassNotFoundException e) {
24 | return false;
25 | }
26 | }
27 |
28 | /**
29 | * Queries on-device packages for a handler for the supplied {@link Intent}.
30 | */
31 | public static boolean hasHandler(Context context, Intent intent) {
32 | List handlers = context.getPackageManager().queryIntentActivities(intent, 0);
33 | return !handlers.isEmpty();
34 | }
35 |
36 | public static SharedPreferences getSp(Context context) {
37 | return context.getSharedPreferences("debug_drawer_sp", Context.MODE_PRIVATE);
38 | }
39 |
40 | public static SharedPreferences.Editor getSpEditor(Context context) {
41 | return context.getSharedPreferences("debug_drawer_sp", Context.MODE_PRIVATE).edit();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/MyApplication.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import java.io.File;
4 | import java.util.concurrent.TimeUnit;
5 |
6 | import android.app.Application;
7 |
8 | import okhttp3.Cache;
9 | import okhttp3.OkHttpClient;
10 |
11 | /**
12 | * @author Niklas Baudy (https://github.com/vanniktech)
13 | * @since 01/07/15
14 | */
15 | public class MyApplication extends Application {
16 |
17 | public static OkHttpClient okHttpClient;
18 |
19 | @Override
20 | public void onCreate() {
21 | super.onCreate();
22 | okHttpClient = createOkHttpClientBuilder(this).build();
23 | initDebugDrawer(okHttpClient);
24 | }
25 |
26 | protected void initDebugDrawer(final OkHttpClient client) {
27 | // empty
28 | }
29 |
30 | private static final int DISK_CACHE_SIZE = 30 * 1024 * 1024; // 30 MB
31 |
32 | private static OkHttpClient.Builder createOkHttpClientBuilder(Application app) {
33 | // Install an HTTP cache in the application cache directory.
34 | File cacheDir = new File(app.getCacheDir(), "okhttp3-cache");
35 | Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
36 |
37 | return new OkHttpClient.Builder()
38 | .cache(cache)
39 | .readTimeout(10, TimeUnit.SECONDS)
40 | .writeTimeout(10, TimeUnit.SECONDS)
41 | .connectTimeout(10, TimeUnit.SECONDS);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
24 |
25 |
29 |
30 |
33 |
34 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
16 |
17 |
24 |
25 |
28 |
29 |
32 |
33 |
35 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/github/simonpercic/oklog/core/CustomLogManager.java:
--------------------------------------------------------------------------------
1 | package com.github.simonpercic.oklog.core;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import android.support.annotation.NonNull;
8 |
9 | /**
10 | * @author Kale
11 | * @date 2017/5/12
12 | */
13 | public class CustomLogManager extends LogManager {
14 |
15 | private RequestModel model;
16 |
17 | public static List sRequestList = new ArrayList<>();
18 |
19 | public CustomLogManager(String urlBase, LogInterceptor logInterceptor, boolean useAndroidLog, boolean withRequestBody,
20 | boolean shortenInfoUrl, @NonNull LogDataConfig logDataConfig) {
21 | super(urlBase, logInterceptor, useAndroidLog, withRequestBody, shortenInfoUrl, logDataConfig);
22 | }
23 |
24 | @Override
25 | public void log(LogDataBuilder data) {
26 |
27 | //转换提日期输出格式
28 | SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
29 |
30 | model = new RequestModel(data.getRequestMethod(),
31 | data.getRequestUrl(), data.getResponseCode(), dateFormat.format(System.currentTimeMillis()));
32 | super.log(data);
33 | }
34 |
35 | @Override
36 | void logDebug(String logUrl, String requestMethod, String requestUrlPath) {
37 | super.logDebug(logUrl, requestMethod, requestUrlPath);
38 | model.setDetailUrl(logUrl);
39 | sRequestList.add(model);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/delete.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
22 |
25 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/LeakActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.PowerManager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.TextView;
8 |
9 | /**
10 | * @author Kale
11 | * @date 2017/3/22
12 | *
13 | * http://droidyue.com/blog/2016/11/14/be-careful-using-getsystemservice/index.html
14 | */
15 | public class LeakActivity extends AppCompatActivity {
16 |
17 | /**
18 | * leak
19 | */
20 | private static PowerManager powerManager;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.common_activity);
26 | powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
27 |
28 | LeakClz.getInstance(this);
29 |
30 | ((TextView) findViewById(R.id.content_tv)).setText("LeakCanary");
31 | }
32 |
33 | private static class LeakClz {
34 |
35 | private static Context context;
36 |
37 | private static LeakClz mInstance = null;
38 |
39 | static LeakClz getInstance(Context context) {
40 | if (mInstance == null) {
41 | synchronized (LeakClz.class) {
42 | if (mInstance == null) {
43 | mInstance = new LeakClz(context);
44 | }
45 | }
46 | }
47 | return mInstance;
48 | }
49 |
50 | LeakClz(Context context) {
51 | this.context = context;
52 | }
53 |
54 | private Context getContext() {
55 | return context;
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/wanjian/sak/config/SakConfigBuild.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.sak.config;
2 |
3 | import android.content.Context;
4 |
5 | import com.wanjian.sak.layer.ForceBitmapWidthHeightLayer;
6 | import com.wanjian.sak.layer.InfoLayer;
7 | import com.wanjian.sak.layerview.HorizontalMeasureView;
8 | import com.wanjian.sak.layerview.TreeView;
9 | import com.wanjian.sak.layerview.VerticalMeasureView;
10 |
11 | /**
12 | * @author Kale
13 | * @date 2017/3/22
14 | *
15 | * https://github.com/android-notes/SwissArmyKnife
16 | */
17 | public class SakConfigBuild extends Config.Build {
18 |
19 | public SakConfigBuild(Context context) {
20 | super(context);
21 | for (int i = 0; i < mDefaultLayerViews.size(); i++) {
22 | if (mDefaultLayerViews.get(i) instanceof TreeView) {
23 | mDefaultLayerViews.remove(i);
24 | i--;
25 | continue;
26 | }
27 | if (mDefaultLayerViews.get(i) instanceof HorizontalMeasureView) {
28 | mDefaultLayerViews.remove(i);
29 | i--;
30 | continue;
31 | }
32 | if (mDefaultLayerViews.get(i) instanceof VerticalMeasureView) {
33 | mDefaultLayerViews.remove(i);
34 | i--;
35 | }
36 | }
37 |
38 | for (int i = 0; i < mDefaultLayers.size(); i++) {
39 | if (mDefaultLayers.get(i) instanceof InfoLayer) {
40 | // 删除自定义信息
41 | mDefaultLayers.remove(i);
42 | i--;
43 | continue;
44 | }
45 | if (mDefaultLayers.get(i) instanceof ForceBitmapWidthHeightLayer) {
46 | mDefaultLayers.remove(i);
47 | i--;
48 | }
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/lib/src/main/res/layout/dd_request_info_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
29 |
30 |
35 |
36 |
42 |
43 |
44 |
45 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/OkHttp3Activity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import java.io.IOException;
4 |
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.widget.TextView;
10 |
11 | import okhttp3.Call;
12 | import okhttp3.Callback;
13 | import okhttp3.Request;
14 | import okhttp3.Response;
15 |
16 | /**
17 | * @author Kale
18 | * @date 2017/3/22
19 | */
20 | public class OkHttp3Activity extends AppCompatActivity {
21 |
22 | private static final String TAG = "OkHttp3Activity";
23 |
24 | @Override
25 | protected void onCreate(@Nullable Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.common_activity);
28 |
29 | ((TextView) findViewById(R.id.content_tv)).setText("OkHttp");
30 |
31 | sendRequest("http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1");
32 | sendRequest("http://gank.io/api/random/data/%E7%A6%8F%E5%88%A9/20");
33 | sendRequest("http://gank.io/api/fail");
34 | sendRequest("http://ip.taobao.com/service/getIpInfo.php?ip=117.89.35.58");
35 | sendRequest("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=218.4.255.255");
36 | }
37 |
38 | private void sendRequest(String url) {
39 | Request request = new Request.Builder().url(url).build();
40 | MyApplication.okHttpClient.newCall(request).enqueue(new Callback() {
41 | @Override
42 | public void onFailure(Call call, IOException e) {
43 | }
44 |
45 | @Override
46 | public void onResponse(Call call, Response response) throws IOException {
47 | Log.d(TAG, "onResponse: ---- " + call.request().url());
48 | }
49 | });
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
14 |
17 |
21 |
25 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/ui_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
28 |
29 |
35 |
36 |
43 |
44 |
51 |
52 |
53 |
54 |
63 |
64 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/SakModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import android.content.Intent;
4 | import android.os.Handler;
5 | import android.support.annotation.NonNull;
6 | import android.widget.CompoundButton;
7 | import android.widget.Toast;
8 |
9 | import com.wanjian.sak.SAK;
10 | import com.wanjian.sak.config.SakConfigBuild;
11 |
12 | import io.palaima.debugdrawer.BaseDebugModule;
13 | import io.palaima.debugdrawer.DebugWidgetStore;
14 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
15 | import io.palaima.debugdrawer.view.EmptyActivity;
16 |
17 | /**
18 | * @author Kale
19 | * @date 2017/6/28
20 | */
21 | public class SakModule extends BaseDebugModule {
22 |
23 | public SakModule() {
24 | if (!DebugDrawerUtil.hasClass("com.wanjian.sak.SAK")) {
25 | throw new RuntimeException("SAK dependency is not found");
26 | }
27 | }
28 |
29 | @NonNull
30 | @Override
31 | public String getName() {
32 | return "Swiss Army Knife";
33 | }
34 |
35 | @Override
36 | protected DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
37 | return builder.addSwitch("Running", false, new CompoundButton.OnCheckedChangeListener() {
38 | @Override
39 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
40 | if (isChecked) {
41 | new Handler().postDelayed(new Runnable(){
42 | public void run() {
43 | getActivity().startActivity(new Intent(getActivity(), EmptyActivity.class));
44 | }
45 | }, 300);
46 | // 新开activity后生效
47 | Toast.makeText(getActivity(), "Success~~~!", Toast.LENGTH_SHORT).show();
48 | SAK.init(getActivity().getApplication(), new SakConfigBuild(getActivity()).build());
49 | } else {
50 | SAK.unInstall(getActivity().getApplication());
51 | }
52 | }
53 | }).build();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/DevToolsModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 | import android.support.annotation.NonNull;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import io.palaima.debugdrawer.BaseDebugModule;
12 | import io.palaima.debugdrawer.DebugWidgetStore;
13 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
14 |
15 | /**
16 | * @author Kale
17 | * @date 2017/3/22
18 | */
19 | public class DevToolsModule extends BaseDebugModule {
20 |
21 | private Activity activity;
22 |
23 | @NonNull
24 | @Override
25 | public String getName() {
26 | return "Dev Tools";
27 | }
28 |
29 | @Override
30 | public void onAttachActivity(Activity activity) {
31 | super.onAttachActivity(activity);
32 | this.activity = activity;
33 | }
34 |
35 | @Override
36 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
37 | return builder.addButton("Jump to Dev-Tools", new View.OnClickListener() {
38 | @Override
39 | public void onClick(View view) {
40 | Intent intent = new Intent(Intent.ACTION_MAIN);
41 | intent.addCategory(Intent.CATEGORY_LAUNCHER);
42 | String pkgName = "cn.trinea.android.developertools";
43 | ComponentName cn = new ComponentName(pkgName, pkgName + ".MainActivity");
44 | intent.setComponent(cn);
45 |
46 | if (DebugDrawerUtil.hasHandler(getActivity(), intent)) {
47 | activity.startActivity(intent);
48 | } else {
49 | Toast.makeText(activity, "本功能需要下载外部应用", Toast.LENGTH_SHORT).show();
50 | Uri uri = Uri.parse("http://app.mi.com/details?id=cn.trinea.android.developertools");
51 | activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));
52 | }
53 | }
54 | }).build();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | applicationId "io.palaima.debugdrawer.app"
9 | minSdkVersion 16
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 |
15 | signingConfigs {
16 | release {
17 | storeFile file('../test_key.jks')
18 | storePassword 'test123'
19 | keyAlias 'kale'
20 | keyPassword 'test123'
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | signingConfig signingConfigs.release
29 | }
30 | }
31 |
32 |
33 |
34 | lintOptions {
35 | // This seems to be firing due to okio referencing java.nio.File
36 | // which is harmless for us. Not sure how to disable this in
37 | // more targeted fashion...
38 | warning 'InvalidPackage'
39 | }
40 |
41 | dataBinding {
42 | enabled = true
43 | }
44 | }
45 | dependencies {
46 | compile fileTree(include: ['*.jar'], dir: 'libs')
47 | debugCompile project(':lib')
48 |
49 | compile 'com.android.support:appcompat-v7:25.3.0'
50 | compile 'com.squareup.picasso:picasso:2.5.2'
51 | compile 'com.squareup.okhttp3:okhttp:3.1.2'
52 | compile 'com.jakewharton.scalpel:scalpel:1.1.2'
53 | compile 'com.github.bumptech.glide:glide:3.7.0'
54 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
55 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
56 | testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
57 | compile 'com.wanjian:sak:0.1.2.8'
58 | compile 'com.amitshekhar.android:debug-db:1.0.0'
59 | compile 'com.github.tianzhijiexian:Logcat:e6332a63d6'
60 | compile 'com.github.simonpercic:oklog3:2.1.0'
61 | compile 'com.github.markzhai:blockcanary-android:1.5.0'
62 | compile 'com.github.xcc3641:watcher:0.5'
63 |
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
28 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/DataBaseModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | import android.support.annotation.NonNull;
6 | import android.widget.CompoundButton;
7 |
8 | import com.amitshekhar.DebugDB;
9 |
10 | import io.palaima.debugdrawer.BaseDebugModule;
11 | import io.palaima.debugdrawer.DebugWidgetStore;
12 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
13 | import kale.debug.log.util.NetworkUtils;
14 |
15 | /**
16 | * @author Kale
17 | * @date 2017/3/22
18 | *
19 | * https://github.com/amitshekhariitbhu/Android-Debug-Database
20 | */
21 | public class DataBaseModule extends BaseDebugModule {
22 |
23 | public DataBaseModule() {
24 | if (!DebugDrawerUtil.hasClass("com.amitshekhar.DebugDB")) {
25 | throw new RuntimeException("DebugDB dependency is not found");
26 | }
27 | }
28 |
29 | @NonNull
30 | @Override
31 | public String getName() {
32 | return "DataBase";
33 | }
34 |
35 | @Override
36 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
37 | return builder
38 | .addSwitch("DB Server", isServerRunning(), new CompoundButton.OnCheckedChangeListener() {
39 | @Override
40 | public void onCheckedChanged(CompoundButton compoundButton, boolean opened) {
41 | if (opened) {
42 | DebugDB.initialize(getActivity());
43 | } else {
44 | DebugDB.shutDown();
45 | }
46 | }
47 | })
48 | .addText("Address", NetworkUtils.getPhoneLocalIp(getActivity(), 8080))
49 | .build();
50 | }
51 |
52 | private boolean isServerRunning() {
53 | try {
54 | Class> debugDB = Class.forName("com.amitshekhar.DebugDB");
55 | Field server = debugDB.getDeclaredField("clientServer");
56 | if (server != null) {
57 | return true;
58 | }
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | return false;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/LogcatModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import android.app.Activity;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 | import android.widget.CompoundButton;
7 |
8 | import io.palaima.debugdrawer.BaseDebugModule;
9 | import io.palaima.debugdrawer.DebugWidgetStore;
10 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
11 | import kale.debug.log.Logcat;
12 | import kale.debug.log.util.NetworkUtils;
13 |
14 | /**
15 | * @author Kale
16 | * @date 2016/3/26
17 | */
18 | public class LogcatModule extends BaseDebugModule {
19 |
20 | private Activity activity;
21 |
22 | public LogcatModule() {
23 | if (!DebugDrawerUtil.hasClass("kale.debug.log.ui.LogActivity")) {
24 | throw new RuntimeException("Logcat dependency is not found");
25 | }
26 | }
27 |
28 | @NonNull
29 | @Override
30 | public String getName() {
31 | return "Logcat";
32 | }
33 |
34 | @Override
35 | public void onAttachActivity(Activity activity) {
36 | super.onAttachActivity(activity);
37 | this.activity = activity;
38 | }
39 |
40 | @Override
41 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
42 | String address = NetworkUtils.getWebLogcatAddress(activity, Logcat.LOGCAT_PORT);
43 | return builder
44 | .addSwitch("Logcat Server", Logcat.isServerRunning(), new CompoundButton.OnCheckedChangeListener() {
45 | @Override
46 | public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
47 | if (isChecked) {
48 | Logcat.startLogCatServer(activity);
49 | } else {
50 | Logcat.shutDownServer(activity);
51 | }
52 | }
53 | })
54 | .addText("Address", address)
55 | .addButton("Show App Log", new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | Logcat.jumpToLogcatActivity(activity);
59 | }
60 | }).build();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import io.palaima.debugdrawer.DebugDrawer;
9 | import kale.debug.log.Logcat;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 | Logcat.startLogCatServer(this);
18 |
19 | findViewById(R.id.open_btn).setOnClickListener(new View.OnClickListener() {
20 | @Override
21 | public void onClick(View view) {
22 | DebugDrawer.openDrawer(MainActivity.this);
23 | }
24 | });
25 | findViewById(R.id.db_btn).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | startActivity(new Intent(MainActivity.this, DataBaseActivity.class));
29 | }
30 | });
31 | findViewById(R.id.leak_btn).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View view) {
34 | startActivity(new Intent(MainActivity.this, LeakActivity.class));
35 | }
36 | });
37 | findViewById(R.id.okhttp_btn).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View view) {
40 | startActivity(new Intent(MainActivity.this, OkHttp3Activity.class));
41 | }
42 | });
43 | findViewById(R.id.ui_btn).setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View view) {
46 | startActivity(new Intent(MainActivity.this, UiActivity.class));
47 | }
48 | });
49 | findViewById(R.id.block_btn).setOnClickListener(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View view) {
52 | startActivity(new Intent(MainActivity.this, BlockActivity.class));
53 | }
54 | });
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/OkHttp3Module.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.support.annotation.NonNull;
6 | import android.text.format.Formatter;
7 | import android.view.View;
8 |
9 | import com.github.simonpercic.oklog.core.RequestListActivity;
10 |
11 | import io.palaima.debugdrawer.BaseDebugModule;
12 | import io.palaima.debugdrawer.DebugWidgetStore;
13 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
14 | import okhttp3.Cache;
15 | import okhttp3.OkHttpClient;
16 |
17 | public class OkHttp3Module extends BaseDebugModule {
18 |
19 | private final Cache cache;
20 |
21 | private Activity activity;
22 |
23 | public OkHttp3Module(@NonNull OkHttpClient client) {
24 | this.cache = client.cache();
25 | }
26 |
27 | @NonNull
28 | @Override
29 | public String getName() {
30 | return "OkHttp Cache";
31 | }
32 |
33 | @Override
34 | public void onAttachActivity(Activity activity) {
35 | super.onAttachActivity(activity);
36 | this.activity = activity;
37 | }
38 |
39 | @Override
40 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
41 | if (cache != null) {
42 | builder = builder.addText("Max Size", Formatter.formatFileSize(activity, cache.maxSize()))
43 | .addText("Write Errors", getWriteErrorCount())
44 | .addText("Request Count", cache.requestCount())
45 | .addText("Network Count", cache.networkCount())
46 | .addText("Hit Count", cache.hitCount());
47 | }
48 |
49 | if (DebugDrawerUtil.hasClass("com.github.simonpercic.oklog3.OkLogInterceptor")) {
50 | builder.addButton("Request List", new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | getActivity().startActivity(new Intent(getActivity(), RequestListActivity.class));
54 | }
55 | });
56 | }
57 | return builder.build();
58 | }
59 |
60 | private String getWriteErrorCount() {
61 | int writeAbortCount = cache.writeAbortCount();
62 | int writeTotal = cache.writeSuccessCount() + writeAbortCount;
63 | int percentage = (int) ((1f * writeAbortCount / writeTotal) * 100);
64 | return String.valueOf(writeAbortCount) + " / " + writeTotal + " (" + percentage + "%)";
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/debug/java/io/palaima/debugdrawer/debug/DebugApplication.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.debug;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | import io.palaima.debugdrawer.BaseDebugModule;
8 | import io.palaima.debugdrawer.DebugDrawer;
9 | import io.palaima.debugdrawer.app.MyApplication;
10 | import io.palaima.debugdrawer.modules.ActivityModule;
11 | import io.palaima.debugdrawer.modules.BuildModule;
12 | import io.palaima.debugdrawer.modules.DataBaseModule;
13 | import io.palaima.debugdrawer.modules.DevToolsModule;
14 | import io.palaima.debugdrawer.modules.DeviceModule;
15 | import io.palaima.debugdrawer.modules.LogcatModule;
16 | import io.palaima.debugdrawer.modules.MemoryModule;
17 | import io.palaima.debugdrawer.modules.MonitorModule;
18 | import io.palaima.debugdrawer.modules.NetworkModule;
19 | import io.palaima.debugdrawer.modules.OkHttp3Module;
20 | import io.palaima.debugdrawer.modules.SakModule;
21 | import io.palaima.debugdrawer.modules.SettingsModule;
22 | import okhttp3.OkHttpClient;
23 |
24 | /**
25 | * @author Kale
26 | * @date 2017/6/30
27 | */
28 | public class DebugApplication extends MyApplication {
29 |
30 | @Override
31 | protected void initDebugDrawer(final OkHttpClient client) {
32 | super.initDebugDrawer(client);
33 | okHttpClient = DebugDrawer.createOkLogHttpClient(client); // 依赖于:com.github.simonpercic:oklog3:2.1.0
34 |
35 | DebugDrawer.init(this, new DebugDrawer.Config() {
36 | @Override
37 | protected List getModules() {
38 | return new ArrayList<>(Arrays.asList(
39 | new ActivityModule(),
40 | new MonitorModule(), // 依赖于:com.github.xcc3641:watcher:0.5
41 | new MemoryModule(),
42 | new CustomDevModule(), // 自定义的module
43 | new DevToolsModule(),
44 | new BuildModule(),
45 | new NetworkModule(),
46 | new OkHttp3Module(okHttpClient), // 依赖于:com.squareup.okhttp3:okhttp:3.1.2
47 | new DataBaseModule(), // 依赖于:com.amitshekhar.android:debug-db:1.0.0
48 | new LogcatModule(), // 依赖于:com.github.tianzhijiexian:Logcat:1.0.7
49 | new DeviceModule(),
50 | new SettingsModule(),
51 | new SakModule() // 依赖于:com.wanjian:sak:0.1.2.8
52 | ));
53 | }
54 | });
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/database_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
14 |
22 |
23 |
32 |
33 |
40 |
41 |
49 |
50 |
51 |
59 |
60 |
69 |
70 |
71 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/MonitorModule.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.modules;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | import android.support.annotation.NonNull;
6 | import android.widget.CompoundButton;
7 |
8 | import com.github.moduth.blockcanary.BlockCanary;
9 | import com.hugo.watcher.Watcher;
10 |
11 | import io.palaima.debugdrawer.BaseDebugModule;
12 | import io.palaima.debugdrawer.DebugWidgetStore;
13 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
14 |
15 | /**
16 | * @author Kale
17 | * @date 2017/5/11
18 | *
19 | * https://github.com/xcc3641/Watcher
20 | */
21 | public class MonitorModule extends BaseDebugModule {
22 |
23 | @NonNull
24 | @Override
25 | public String getName() {
26 | return "Monitor";
27 | }
28 |
29 | @Override
30 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
31 | builder.addSwitch("Fps & Memory", isFpsFloatShown(), new CompoundButton.OnCheckedChangeListener() {
32 | @Override
33 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
34 | if (isChecked) {
35 | Watcher.getInstance().start(getActivity());
36 | } else {
37 | Watcher.getInstance().stop(getActivity());
38 | }
39 | }
40 | });
41 | if (DebugDrawerUtil.hasClass("com.github.moduth.blockcanary.BlockCanary")) {
42 | builder.addSwitch("Block Canary", isBlockCanaryRunning(), new CompoundButton.OnCheckedChangeListener() {
43 | @Override
44 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
45 | if (isChecked) {
46 | BlockCanary.get().start();
47 | } else {
48 | BlockCanary.get().stop();
49 | }
50 | }
51 | });
52 | }
53 | return builder.build();
54 | }
55 |
56 | private boolean isFpsFloatShown() {
57 | try {
58 | Class> watcher = Class.forName("com.hugo.watcher.Watcher");
59 | Field hasStarted = watcher.getDeclaredField("mHasStarted");
60 | hasStarted.setAccessible(true);
61 | return hasStarted.getBoolean(Watcher.getInstance());
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | return false;
66 | }
67 |
68 | private boolean isBlockCanaryRunning() {
69 | try {
70 | Class> watcher = Class.forName("com.github.moduth.blockcanary.BlockCanary");
71 | Field hasStarted = watcher.getDeclaredField("mMonitorStarted");
72 | hasStarted.setAccessible(true);
73 | return hasStarted.getBoolean(BlockCanary.get());
74 | } catch (Exception e) {
75 | e.printStackTrace();
76 | }
77 | return false;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
21 |
22 |
29 |
30 |
37 |
38 |
45 |
46 |
53 |
54 |
61 |
62 |
69 |
70 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/util/UIUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Mantas Palaima
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.util;
18 |
19 | import android.annotation.SuppressLint;
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.util.DisplayMetrics;
23 |
24 | import io.palaima.debugdrawer.R;
25 |
26 | @SuppressLint("InlinedApi")
27 | public class UIUtils {
28 |
29 | /**
30 | * Returns the screen width in pixels
31 | *
32 | * @param context is the context to get the resources
33 | * @return the screen width in pixels
34 | */
35 | public static int getScreenWidth(Context context) {
36 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
37 | return metrics.widthPixels;
38 | }
39 |
40 | /**
41 | * helper to calculate the optimal drawer width
42 | */
43 | public static int getOptimalDrawerWidth(Context context) {
44 | int possibleMinDrawerWidth = UIUtils.getScreenWidth(context) - UIUtils.getActionBarHeight(context);
45 | int maxDrawerWidth = context.getResources().getDimensionPixelSize(
46 | R.dimen.dd_debug_drawer_width);
47 | return Math.min(possibleMinDrawerWidth, maxDrawerWidth);
48 | }
49 |
50 | /**
51 | * helper to calculate the actionBar height
52 | */
53 | public static int getActionBarHeight(Context context) {
54 | int actionBarHeight = UIUtils.getThemeAttributeDimensionSize(context,
55 | android.R.attr.actionBarSize);
56 | // FIXME: 2016/3/25 R.dimen.abc_action_bar_default_height_material is private in android framework
57 | /*if (actionBarHeight == 0) {
58 | actionBarHeight = context.getResources()
59 | .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material);
60 | }*/
61 | return actionBarHeight;
62 | }
63 |
64 | /**
65 | * Returns the size in pixels of an attribute dimension
66 | *
67 | * @param context the context to get the resources from
68 | * @param attr is the attribute dimension we want to know the size from
69 | * @return the size in pixels of an attribute dimension
70 | */
71 | public static int getThemeAttributeDimensionSize(Context context, int attr) {
72 | TypedArray a = null;
73 | try {
74 | a = context.getTheme().obtainStyledAttributes(new int[]{attr});
75 | return a.getDimensionPixelSize(0, 0);
76 | } finally {
77 | if (a != null) {
78 | a.recycle();
79 | }
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/NetworkModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Mantas Palaima
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.modules;
18 |
19 | import android.app.Activity;
20 | import android.os.Build;
21 | import android.support.annotation.NonNull;
22 | import android.widget.CompoundButton;
23 |
24 | import io.palaima.debugdrawer.BaseDebugModule;
25 | import io.palaima.debugdrawer.DebugWidgetStore;
26 | import io.palaima.debugdrawer.util.NetworkController;
27 |
28 |
29 | public class NetworkModule extends BaseDebugModule {
30 |
31 | private NetworkController networkController;
32 |
33 | @NonNull
34 | @Override
35 | public String getName() {
36 | return "Network";
37 | }
38 |
39 | @Override
40 | public void onAttachActivity(Activity activity) {
41 | super.onAttachActivity(activity);
42 | networkController = NetworkController.newInstance(activity);
43 | }
44 |
45 | @Override
46 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
47 | builder.addSwitch("Wifi", networkController.isWifiEnabled(),
48 | new CompoundButton.OnCheckedChangeListener() {
49 | @Override
50 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
51 | networkController.setWifiEnabled(isChecked);
52 | }
53 | });
54 |
55 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
56 | // In JellyBean 4.2, mobile network settings are only accessible from system apps
57 | builder.addText("Mobile", networkController.isMobileNetworkEnabled());
58 | } else {
59 | builder.addSwitch("Mobile", networkController.isMobileNetworkEnabled(),
60 | new CompoundButton.OnCheckedChangeListener() {
61 | @Override
62 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
63 | networkController.setMobileNetworkEnabled(isChecked);
64 | }
65 | });
66 | }
67 |
68 | if (networkController.isBluetoothAvailable()) {
69 | builder.addSwitch("Bluetooth", networkController.isBluetoothEnabled(),
70 | new CompoundButton.OnCheckedChangeListener() {
71 | @Override
72 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
73 | networkController.setBluetoothEnabled(isChecked);
74 | }
75 | });
76 | }
77 | return builder.build();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Debug Drawer
2 |
3 | [](https://gitter.im/palaima/DebugDrawer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 |
5 | [](http://android-arsenal.com/details/1/1892)
6 |
7 | Faster development with Debug Drawer
8 |
9 | 
10 | 
11 | 
12 |
13 | Android App进程的内存使用是有限制的,通过以下两个方法可以查看App可用内存的大小:
14 |
15 | ActivityManager.getMemoryClass()获得正常情况下可用内存的大小
16 | ActivityManager.getLargeMemoryClass()可以获得开启largeHeap最大的内存大小
17 |
18 | ## Add Gradle dependencies:
19 |
20 | #### `DebugDrawer`
21 | ```gradle
22 | dependencies {
23 | debugCompile 'io.palaima.debugdrawer:debugdrawer:0.7.0'
24 | releaseCompile 'io.palaima.debugdrawer:debugdrawer-no-op:0.7.0'
25 | }
26 | ```
27 |
28 | #### `optional`
29 |
30 | ```gradle
31 | compile 'com.amitshekhar.android:debug-db:1.0.0'
32 | compile 'com.github.tianzhijiexian:Logcat:1.0.7'
33 | compile 'com.github.simonpercic:oklog3:2.1.0'
34 | compile 'com.github.markzhai:blockcanary-android:1.5.0'
35 | compile 'com.github.xcc3641:watcher:0.5'
36 | ```
37 |
38 | https://github.com/amitshekhariitbhu/Android-Debug-Database
39 | https://github.com/tianzhijiexian/Logcat
40 | https://github.com/markzhai/AndroidPerformanceMonitor
41 | https://github.com/xcc3641/Watcher
42 | https://github.com/simonpercic/OkLog
43 |
44 | ## Initialization in Application
45 |
46 | ```java
47 | // create a okhttp3 client...
48 | // dependent on com.github.simonpercic:oklog3:2.1.0
49 | okHttpClient = DebugDrawer.createOkLogHttpClient(okHttpClient);
50 |
51 | DebugDrawer.init(this, new DebugDrawer.Config() {
52 | @Override
53 | protected List getModules() {
54 | return new ArrayList(Arrays.asList(
55 | new ActivityModule(),
56 | new MonitorModule(), // dependent on com.github.xcc3641:watcher:0.5
57 | new MemoryModule(),
58 | new CustomDevModule(), // custom module
59 | new DevToolsModule(),
60 | new BuildModule(),
61 | new NetworkModule(),
62 | new OkHttp3Module(okHttpClient), // dependent on com.squareup.okhttp3:okhttp:3.1.2
63 | new DataBaseModule(), // dependent on com.amitshekhar.android:debug-db:1.0.0
64 | new LogcatModule(), // dependent on com.github.tianzhijiexian:Logcat:1.0.7
65 | new DeviceModule(),
66 | new SettingsModule()
67 | ));
68 | }
69 | });
70 | ```
71 |
72 | License
73 | --------
74 |
75 | Copyright 2016 Mantas Palaima.
76 |
77 | Licensed under the Apache License, Version 2.0 (the "License");
78 | you may not use this file except in compliance with the License.
79 | You may obtain a copy of the License at
80 |
81 | http://www.apache.org/licenses/LICENSE-2.0
82 |
83 | Unless required by applicable law or agreed to in writing, software
84 | distributed under the License is distributed on an "AS IS" BASIS,
85 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86 | See the License for the specific language governing permissions and
87 | limitations under the License.
88 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/util/PackageManagerHook.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.util;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.InvocationHandler;
5 | import java.lang.reflect.InvocationTargetException;
6 | import java.lang.reflect.Method;
7 | import java.lang.reflect.Proxy;
8 |
9 | import android.content.Context;
10 | import android.content.SharedPreferences;
11 | import android.content.pm.PackageInfo;
12 |
13 |
14 | /**
15 | * https://github.com/AlanCheen/Climb/blob/master/app/src/main/java/me/yifeiyuan/climb/hook/PackageManagerHook.java
16 | *
17 | * @date 2017/5/8
18 | */
19 | public class PackageManagerHook {
20 |
21 | public static final String TAG = "PkgManagerHook";
22 |
23 | public static final String KEY_CURRENT_VERSION_CODE = "key_current_version_code";
24 |
25 | public static final String KEY_CURRENT_VERSION_NAME = "key_current_version_name";
26 |
27 | /**
28 | * 越早 hook 越好,推荐在 attachBaseContext 调用
29 | *
30 | * @param context base
31 | */
32 | public static void hook(final Context context) {
33 | try {
34 | // 获取 activityThread
35 | Class> activityThreadClazz = Class.forName("android.app.ActivityThread", false, context.getClassLoader());
36 | Method currentActivityThread = activityThreadClazz.getDeclaredMethod("currentActivityThread");
37 | currentActivityThread.setAccessible(true);
38 | Object activityThread = currentActivityThread.invoke(null);
39 |
40 | // 获取 activityThread 的 packageManager
41 | Method getPackageManager = activityThreadClazz.getDeclaredMethod("getPackageManager");
42 | getPackageManager.setAccessible(true);
43 | final Object pkgManager = getPackageManager.invoke(activityThread);//IPackageManager$Stub$Proxy
44 |
45 | // 动态代理
46 | Class> packageManagerClazz = Class.forName("android.content.pm.IPackageManager", false, context.getClassLoader());
47 |
48 | Object pmProxy = Proxy.newProxyInstance(context.getClassLoader(), new Class[]{packageManagerClazz}, new InvocationHandler() {
49 | @Override
50 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
51 | Object result = method.invoke(pkgManager, args);
52 |
53 | if ("getPackageInfo".equals(method.getName())) {
54 | PackageInfo pkgInfo = (PackageInfo) result;
55 |
56 | SharedPreferences sp = DebugDrawerUtil.getSp(context);
57 | pkgInfo.versionCode = sp.getInt(KEY_CURRENT_VERSION_CODE, 0);
58 | pkgInfo.versionName = sp.getString(KEY_CURRENT_VERSION_NAME, "1.0");
59 | }
60 | return result;
61 | }
62 | });
63 |
64 | //hook sPackageManager
65 | Field packageManagerField = activityThreadClazz.getDeclaredField("sPackageManager");
66 | packageManagerField.setAccessible(true);
67 | packageManagerField.set(activityThread, pmProxy);
68 | } catch (ClassNotFoundException e) {
69 | e.printStackTrace();
70 | } catch (InvocationTargetException e) {
71 | e.printStackTrace();
72 | } catch (IllegalAccessException e) {
73 | e.printStackTrace();
74 | } catch (NoSuchMethodException e) {
75 | e.printStackTrace();
76 | } catch (NoSuchFieldException e) {
77 | e.printStackTrace();
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/DataBaseActivity.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app;
2 |
3 | import java.util.Map;
4 |
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 | import android.database.Cursor;
8 | import android.databinding.DataBindingUtil;
9 | import android.os.Bundle;
10 | import android.support.annotation.NonNull;
11 | import android.support.annotation.Nullable;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.view.View;
14 |
15 | import io.palaima.debugdrawer.app.databinding.DatabaseActivityBinding;
16 | import io.palaima.debugdrawer.app.utils.DataBaseHelper;
17 |
18 | /**
19 | * @author Kale
20 | * @date 2017/3/22
21 | */
22 | public class DataBaseActivity extends AppCompatActivity {
23 |
24 | private SharedPreferences mFirstSp;
25 |
26 | private SharedPreferences mSecondSp;
27 |
28 | private DataBaseHelper mFirstHelper;
29 |
30 | private DataBaseHelper mSecondHelper;
31 |
32 | @Override
33 | protected void onCreate(@Nullable Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | final DatabaseActivityBinding b = DataBindingUtil.setContentView(this, R.layout.database_activity);
36 |
37 | initSp();
38 | initDB();
39 |
40 | renderSpData(b);
41 | b.refreshSpBtn.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View view) {
44 | renderSpData(b);
45 | }
46 | });
47 |
48 | renderDbData(b);
49 | b.refreshDbBtn.setOnClickListener(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View view) {
52 | renderDbData(b);
53 | }
54 | });
55 | }
56 |
57 | private void renderDbData(DatabaseActivityBinding b) {
58 | StringBuilder stringBuilder = readDbData(mFirstHelper.queryDataById("1"));
59 | b.firstDbTv.setText(stringBuilder.toString());
60 |
61 | StringBuilder sb = readDbData(mSecondHelper.queryDataById("1"));
62 | b.secondDbTv.setText(sb.toString());
63 | }
64 |
65 | private void renderSpData(DatabaseActivityBinding b) {
66 | Map firstSpMap = mFirstSp.getAll();
67 | b.firstSpTv.setText(firstSpMap.toString());
68 | b.secondSpTv.setText(mSecondSp.getAll().toString());
69 | }
70 |
71 | @NonNull
72 | private StringBuilder readDbData(Cursor cursor) {
73 | StringBuilder stringBuilder = new StringBuilder();
74 | if (cursor.moveToNext()) {
75 | stringBuilder.append(cursor.getString(cursor.getColumnIndex(DataBaseHelper.CATEGORY)))
76 | .append(cursor.getInt(cursor.getColumnIndex(DataBaseHelper.LINE)))
77 | .append(cursor.getString(cursor.getColumnIndex(DataBaseHelper.EXTRA)));
78 | }
79 | return stringBuilder;
80 | }
81 |
82 | private void initSp() {
83 | mFirstSp = getApplicationContext().getSharedPreferences("first_sp", Context.MODE_PRIVATE);
84 | mFirstSp.edit()
85 | .putInt("key_01", 123)
86 | .putString("key_02", "kale")
87 | .putBoolean("key_03", true)
88 | .apply();
89 |
90 | mSecondSp = getSharedPreferences("second_sp", Context.MODE_PRIVATE);
91 | mSecondSp.edit().putString("name", "kale").apply();
92 |
93 | getSharedPreferences("third_sp", Context.MODE_PRIVATE);
94 |
95 | }
96 |
97 | private void initDB() {
98 | mFirstHelper = new DataBaseHelper(this, "First-DB");
99 | mFirstHelper.insertData("类别", 4351, "{name:kale}");
100 |
101 | mSecondHelper = new DataBaseHelper(this, "Second-DB");
102 | mSecondHelper.insertData("歌名", 232, "晴天");
103 | }
104 |
105 | @Override
106 | protected void onDestroy() {
107 | super.onDestroy();
108 | mFirstHelper.closeDB();
109 | mSecondHelper.closeDB();
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/io/palaima/debugdrawer/app/utils/DataBaseHelper.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer.app.utils;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.database.sqlite.SQLiteException;
7 | import android.database.sqlite.SQLiteOpenHelper;
8 | import android.util.Log;
9 |
10 | /**
11 | * @author Kale
12 | * @date 2015/12/17
13 | */
14 | public class DataBaseHelper extends SQLiteOpenHelper {
15 |
16 | private static final String TAG = "DataBaseHelper";
17 |
18 | private static final String TABLE_NAME = "test_table";
19 |
20 | public static final String CATEGORY = "category";
21 |
22 | public static final String LINE = "line";
23 |
24 | public static final String EXTRA = "extra";
25 |
26 | private static final String CREATE_NEW_TABLE = "create table " + TABLE_NAME + "(" +
27 | "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
28 | CATEGORY + " TEXT," +
29 | LINE + " INTEGER," +
30 | EXTRA + " TEXT);";
31 |
32 | private SQLiteDatabase mDb;
33 |
34 | public DataBaseHelper(Context context, String dbName) {
35 | super(context, dbName, null, 1);
36 | try {
37 | mDb = getReadableDatabase();
38 | } catch (Exception e) {
39 | mDb = null;
40 | }
41 | }
42 |
43 | @Override
44 | public void onCreate(SQLiteDatabase db) {
45 | db.execSQL(CREATE_NEW_TABLE);
46 | }
47 |
48 | @Override
49 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
50 |
51 | }
52 |
53 | public void createNewTable() {
54 | if (!executeSql(CREATE_NEW_TABLE)) {
55 | Log.i(TAG, "建表成功");
56 | } else {
57 | Log.e(TAG, "建表失败");
58 | }
59 | }
60 |
61 | /**
62 | * 新增数据
63 | */
64 | public void insertData(String category, int line, String extra) {
65 | String sb = "'" + category + "'," + line + "," + "'" + extra + "'";
66 | String sql = "insert into " + TABLE_NAME + " (category,line,extra) " + "values(" + sb + ")";
67 | if (!executeSql(sql)) {
68 | Log.e(TAG, "插入失败");
69 | }
70 | }
71 |
72 | /**
73 | * 通过表名来删除一个表
74 | */
75 | public void deleteAllLog() {
76 | String sql = "delete from " + TABLE_NAME;
77 | if (executeSql(sql)) {
78 | Log.i(TAG, "删除成功");
79 | } else {
80 | Log.e(TAG, "删除失败");
81 | }
82 | }
83 |
84 | public Cursor queryAll() {
85 | return queryByColumn(new String[]{CATEGORY, LINE, EXTRA});
86 | }
87 |
88 | private Cursor queryByColumn(String[] column) {
89 | StringBuilder sb = new StringBuilder();
90 | for (String c : column) {
91 | sb.append(",").append(c);
92 | }
93 | String sql = "select _id" + sb.toString() + " from " + TABLE_NAME;
94 | return executeSql(sql, null);
95 | }
96 |
97 | /**
98 | * 查询数据,?是占位符,用于和string数组搭配使用
99 | */
100 | public Cursor queryDataById(String id) {
101 | String sql = "select * from " + TABLE_NAME + " where _id=?";
102 | return executeSql(sql, new String[]{id});
103 | }
104 |
105 | /**
106 | * 建立表
107 | * SQLite内部只支持NULL,INTEGER,REAL(浮点),TEXT(文本),BLOB(大二进制)5种数据类型
108 | * 建立表成功了,返回true
109 | */
110 | private boolean executeSql(String sql) {
111 | try {
112 | if (mDb != null) {
113 | mDb.execSQL(sql);
114 | return true;
115 | }
116 | return false;
117 | } catch (SQLiteException e) {
118 | return false;
119 | } catch (Exception e) {
120 | Log.e(TAG, "Unknown error");
121 | return false;
122 | }
123 | }
124 |
125 | private Cursor executeSql(String sql, String[] args) {
126 | try {
127 | if (mDb != null) {
128 | return mDb.rawQuery(sql, args);
129 | }
130 | } catch (Exception e) {
131 | e.printStackTrace();
132 | }
133 | return null;
134 | }
135 |
136 | /**
137 | * 关闭连接
138 | */
139 | public void closeDB() {
140 | if (mDb != null) {
141 | close();
142 | }
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/DeviceModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Mantas Palaima
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.modules;
18 |
19 | import java.io.BufferedReader;
20 | import java.io.FileReader;
21 | import java.io.IOException;
22 |
23 | import android.app.Activity;
24 | import android.os.Build;
25 | import android.support.annotation.NonNull;
26 | import android.util.DisplayMetrics;
27 |
28 | import io.palaima.debugdrawer.BaseDebugModule;
29 | import io.palaima.debugdrawer.DebugWidgetStore;
30 |
31 |
32 | /**
33 | * http://blog.csdn.net/vennl/article/details/7078738
34 | */
35 | public class DeviceModule extends BaseDebugModule {
36 |
37 | private String deviceMake;
38 |
39 | private String deviceModel;
40 |
41 | private String deviceCpu;
42 |
43 | private String deviceResolution;
44 |
45 | private String deviceDensity;
46 |
47 | private String systemVersion;
48 |
49 | private String androidApi;
50 |
51 | @NonNull
52 | @Override
53 | public String getName() {
54 | return "Device Info";
55 | }
56 |
57 | @Override
58 | public void onAttachActivity(Activity activity) {
59 | super.onAttachActivity(activity);
60 | DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
61 | String densityBucket = getDensityString(displayMetrics);
62 | deviceMake = truncateAt(Build.MANUFACTURER, 20);
63 | deviceModel = truncateAt(Build.MODEL, 20);
64 | String cpuName = getCpuName();
65 | if (cpuName != null) {
66 | deviceCpu = cpuName.split(" ")[0];
67 | } else {
68 | deviceCpu = "unknown";
69 | }
70 | deviceResolution = displayMetrics.heightPixels + "x" + displayMetrics.widthPixels;
71 | deviceDensity = displayMetrics.densityDpi + "dpi (" + densityBucket + ")";
72 | systemVersion = Build.VERSION.RELEASE;
73 | androidApi = String.valueOf(Build.VERSION.SDK_INT);
74 | }
75 |
76 | @Override
77 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
78 | return builder.addText("OEM", deviceMake)
79 | .addText("Device Model", deviceModel)
80 | .addText("Cpu", deviceCpu)
81 | .addText("Product", Build.PRODUCT)
82 | .addText("Resolution", deviceResolution)
83 | .addText("Density", deviceDensity)
84 | .addText("System Version", systemVersion)
85 | .addText("Android API", androidApi)
86 | .build();
87 | }
88 |
89 | private static String getCpuName() {
90 | try {
91 | FileReader fr = new FileReader("/proc/cpuinfo");
92 | BufferedReader br = new BufferedReader(fr);
93 | String text = br.readLine();
94 | String[] array = text.split(":\\s+", 2);
95 | return array[1];
96 | } catch (IOException e) {
97 | e.printStackTrace();
98 | }
99 | return null;
100 | }
101 |
102 | private static String truncateAt(String string, int length) {
103 | return string.length() > length ? string.substring(0, length) : string;
104 | }
105 |
106 | private static String getDensityString(DisplayMetrics displayMetrics) {
107 | switch (displayMetrics.densityDpi) {
108 | case DisplayMetrics.DENSITY_LOW:
109 | return "ldpi";
110 | case DisplayMetrics.DENSITY_MEDIUM:
111 | return "mdpi";
112 | case DisplayMetrics.DENSITY_HIGH:
113 | return "hdpi";
114 | case DisplayMetrics.DENSITY_XHIGH:
115 | return "xhdpi";
116 | case DisplayMetrics.DENSITY_XXHIGH:
117 | return "xxhdpi";
118 | case DisplayMetrics.DENSITY_XXXHIGH:
119 | return "xxxhdpi";
120 | case DisplayMetrics.DENSITY_TV:
121 | return "tvdpi";
122 | default:
123 | return String.valueOf(displayMetrics.densityDpi);
124 | }
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/github/simonpercic/oklog/core/RequestListActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.simonpercic.oklog.core;
2 |
3 | import java.util.List;
4 |
5 | import android.app.Activity;
6 | import android.content.ClipboardManager;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.graphics.Color;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.support.annotation.Nullable;
13 | import android.util.SparseArray;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.AdapterView;
18 | import android.widget.BaseAdapter;
19 | import android.widget.ListView;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import io.palaima.debugdrawer.R;
24 |
25 | /**
26 | * @author Kale
27 | * @date 2017/5/12
28 | */
29 | public class RequestListActivity extends Activity {
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.dd_request_list_activity);
35 |
36 | final List data = CustomLogManager.sRequestList;
37 |
38 | final ListView listview = (ListView) findViewById(R.id.listview);
39 | final LayoutInflater inflater = getLayoutInflater();
40 | final BaseAdapter adapter = new BaseAdapter() {
41 | @Override
42 | public int getCount() {
43 | return data.size();
44 | }
45 |
46 | @Override
47 | public Object getItem(int position) {
48 | return data.get(position);
49 | }
50 |
51 | @Override
52 | public long getItemId(int position) {
53 | return position;
54 | }
55 |
56 | @Override
57 | public View getView(int position, View convertView, ViewGroup parent) {
58 | if (convertView == null) {
59 | convertView = inflater.inflate(R.layout.dd_request_info_item, null);
60 | }
61 | TextView codeTv = ViewHolder.get(convertView, R.id.code_tv);
62 | TextView methodTv = ViewHolder.get(convertView, R.id.method_tv);
63 | TextView urlTv = ViewHolder.get(convertView, R.id.url_tv);
64 | TextView timeTv = ViewHolder.get(convertView, R.id.time_tv);
65 |
66 | RequestModel model = data.get(position);
67 | int code = model.code;
68 | codeTv.setText(String.valueOf(code));
69 | codeTv.setTextColor(code == 200 ? Color.GREEN : Color.RED);
70 | timeTv.setText(model.time);
71 | methodTv.setText(model.method);
72 | urlTv.setText(model.url);
73 | return convertView;
74 | }
75 | };
76 | listview.setAdapter(adapter);
77 |
78 | listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
79 | @Override
80 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
81 | Uri uri = Uri.parse(data.get(position).detailUrl);
82 | startActivity(new Intent(Intent.ACTION_VIEW, uri));
83 | }
84 | });
85 |
86 | listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
87 | @Override
88 | public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
89 | ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
90 | cmb.setText(data.get(position).detailUrl);
91 | Toast.makeText(RequestListActivity.this, "url已复制到剪切板~", Toast.LENGTH_SHORT).show();
92 | return true;
93 | }
94 | });
95 |
96 | listview.setSelection(data.size());
97 |
98 | findViewById(R.id.clear_btn).setOnClickListener(new View.OnClickListener() {
99 | @Override
100 | public void onClick(View v) {
101 | CustomLogManager.sRequestList.clear();
102 | adapter.notifyDataSetChanged();
103 | }
104 | });
105 | }
106 |
107 | private static class ViewHolder {
108 |
109 | // I added a generic return type to reduce the casting noise in client code
110 | @SuppressWarnings("unchecked")
111 | public static T get(View view, int id) {
112 | SparseArray viewHolder = (SparseArray) view.getTag();
113 | if (viewHolder == null) {
114 | viewHolder = new SparseArray<>();
115 | view.setTag(viewHolder);
116 | }
117 | View childView = viewHolder.get(id);
118 | if (childView == null) {
119 | childView = view.findViewById(id);
120 | viewHolder.put(id, childView);
121 | }
122 | return (T) childView;
123 | }
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/DebugWidgetStore.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.content.Context;
7 | import android.support.annotation.DrawableRes;
8 | import android.support.annotation.Nullable;
9 | import android.support.v7.view.ContextThemeWrapper;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.CompoundButton;
14 | import android.widget.ImageView;
15 | import android.widget.Switch;
16 | import android.widget.TextView;
17 |
18 | /**
19 | * @author Kale
20 | * @date 2016/4/30
21 | */
22 | public class DebugWidgetStore {
23 |
24 | private List widgets;
25 |
26 | public static final int DEFAULT_VIEW_ID = -1;
27 |
28 | public DebugWidgetStore(List widgets) {
29 | this.widgets = widgets;
30 | }
31 |
32 | public List getWidgets() {
33 | return widgets;
34 | }
35 |
36 | @Nullable
37 | public DebugWidget getDebugWidget(int viewId) {
38 | if (viewId == DEFAULT_VIEW_ID) {
39 | return null;
40 | }
41 | for (DebugWidget widget : widgets) {
42 | if (widget.id == viewId) {
43 | return widget;
44 | }
45 | }
46 | return null;
47 | }
48 |
49 | public DebugWidget getCurrentDebugWidget() {
50 | return widgets.get(widgets.size());
51 | }
52 |
53 | public static class Builder {
54 |
55 | private Context context;
56 |
57 | private List widgetList;
58 |
59 | Builder(Context context) {
60 | this.context = context;
61 | widgetList = new ArrayList<>();
62 | }
63 |
64 | public Builder addText(String title, int content) {
65 | return addText(title, String.valueOf(content), DEFAULT_VIEW_ID);
66 | }
67 |
68 | public Builder addText(String title, boolean content) {
69 | return addText(title, String.valueOf(content), DEFAULT_VIEW_ID);
70 | }
71 |
72 | public Builder addText(String title, int content, int viewId) {
73 | return addText(title, String.valueOf(content), viewId);
74 | }
75 |
76 | public Builder addText(String title, boolean content, int viewId) {
77 | return addText(title, String.valueOf(content), viewId);
78 | }
79 |
80 | public Builder addText(String title, String content) {
81 | return addText(title, content, DEFAULT_VIEW_ID);
82 | }
83 |
84 | public Builder addText(String title, String content, int viewId) {
85 | TextView textView = new TextView(new ContextThemeWrapper(context, R.style.Widget_DebugDrawer_Base_RowValue));
86 | textView.setText(String.format(" %s", content));
87 | widgetList.add(new DebugWidget(title, textView, viewId));
88 | return this;
89 | }
90 |
91 | public Builder addButton(String text, View.OnClickListener listener) {
92 | return addButton(text, listener, DEFAULT_VIEW_ID);
93 | }
94 |
95 | public Builder addButton(String text, View.OnClickListener listener, int viewId) {
96 | Button button = new Button(new ContextThemeWrapper(context, R.style.Widget_DebugDrawer_Base_RowWidget_Black));
97 | button.setText(text);
98 | button.setOnClickListener(listener);
99 | widgetList.add(new DebugWidget(null, button, viewId));
100 | return this;
101 | }
102 |
103 | public Builder addIconButton(String text, @DrawableRes int drawableId,
104 | View.OnClickListener listener) {
105 | return addIconButton(text, drawableId, listener, DEFAULT_VIEW_ID);
106 | }
107 |
108 | public Builder addIconButton(String text, @DrawableRes int drawableId,
109 | View.OnClickListener listener, int id) {
110 |
111 | View view = LayoutInflater.from(context).inflate(R.layout.dd_icon_button, null);
112 | ((ImageView) view.findViewById(R.id.icon_iv)).setImageResource(drawableId);
113 | Button button = (Button) view.findViewById(R.id.summary_btn);
114 | button.setText(text);
115 | button.setOnClickListener(listener);
116 | widgetList.add(new DebugWidget(null, view, id));
117 | return this;
118 | }
119 |
120 | public Builder addSwitch(String title, boolean checked,
121 | CompoundButton.OnCheckedChangeListener listener) {
122 | return addSwitch(title, checked, listener, DEFAULT_VIEW_ID);
123 | }
124 |
125 | public Builder addSwitch(String title, boolean checked,
126 | CompoundButton.OnCheckedChangeListener listener, int id) {
127 | Switch sw = new Switch(new ContextThemeWrapper(context, R.style.Widget_DebugDrawer_Base_RowWidget));
128 | sw.setChecked(checked);
129 | sw.setOnCheckedChangeListener(listener);
130 | widgetList.add(new DebugWidget(title, sw, id));
131 | return this;
132 | }
133 |
134 | public DebugWidgetStore build() {
135 | return new DebugWidgetStore(widgetList);
136 | }
137 |
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/SettingsModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 LemonLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.modules;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.content.pm.ResolveInfo;
22 | import android.net.Uri;
23 | import android.provider.Settings;
24 | import android.support.annotation.NonNull;
25 | import android.view.View;
26 | import android.widget.Toast;
27 |
28 | import io.palaima.debugdrawer.BaseDebugModule;
29 | import io.palaima.debugdrawer.DebugWidgetStore;
30 | import io.palaima.debugdrawer.R;
31 |
32 | public class SettingsModule extends BaseDebugModule {
33 |
34 | private Activity activity;
35 |
36 | @NonNull
37 | @Override
38 | public String getName() {
39 | return "Settings";
40 | }
41 |
42 | @Override
43 | public void onAttachActivity(Activity activity) {
44 | this.activity = activity;
45 | }
46 |
47 | @Override
48 | protected DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
49 | return builder
50 | .addIconButton("Wifi", R.drawable.wifi, new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
54 | }
55 | })
56 | .addIconButton("App Info", R.drawable.info, new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
60 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
61 | .setData(Uri.parse("package:" + activity.getPackageName()));
62 | activity.startActivity(intent);
63 | }
64 | })
65 | .addIconButton("Battery", R.drawable.energy, new View.OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 | // try to find an app to handle battery settings
69 | Intent batteryIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY)
70 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
71 | ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(batteryIntent, 0);
72 | if (resolveInfo != null) {
73 | activity.startActivity(batteryIntent);
74 | } else {
75 | Toast.makeText(activity, "No app found to handle power usage intent", Toast.LENGTH_SHORT).show();
76 | }
77 | }
78 | })
79 | .addIconButton("Location", R.drawable.location, new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | Intent locationIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
83 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
84 | activity.startActivity(locationIntent);
85 | }
86 | })
87 | .addIconButton("Developer Tools", R.drawable.tool, new View.OnClickListener() {
88 | @Override
89 | public void onClick(View v) {
90 | // open dev settings
91 | Intent devIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
92 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
93 | ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(devIntent, 0);
94 | if (resolveInfo != null) {
95 | activity.startActivity(devIntent);
96 | } else {
97 | Toast.makeText(activity, "Developer settings not available on device", Toast.LENGTH_SHORT).show();
98 | }
99 | }
100 | })
101 | .addIconButton("Settings", R.drawable.settings, new View.OnClickListener() {
102 | @Override
103 | public void onClick(View v) {
104 | // open android settings
105 | Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS)
106 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
107 | activity.startActivity(settingsIntent);
108 | }
109 | })
110 | .addIconButton("Uninstall", R.drawable.delete, new View.OnClickListener() {
111 | @Override
112 | public void onClick(View v) {
113 | // open dialog to uninstall app
114 | Uri packageURI = Uri.parse("package:" + activity.getPackageName());
115 | Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
116 | activity.startActivity(uninstallIntent);
117 | }
118 | })
119 | .build();
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/modules/BuildModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Mantas Palaima
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.modules;
18 |
19 | import android.app.Activity;
20 | import android.app.Dialog;
21 | import android.content.DialogInterface;
22 | import android.content.SharedPreferences;
23 | import android.content.pm.PackageInfo;
24 | import android.content.pm.PackageManager;
25 | import android.os.Bundle;
26 | import android.support.annotation.NonNull;
27 | import android.support.v4.app.DialogFragment;
28 | import android.support.v4.app.FragmentActivity;
29 | import android.support.v7.app.AlertDialog;
30 | import android.view.View;
31 | import android.widget.EditText;
32 | import android.widget.TextView;
33 | import android.widget.Toast;
34 |
35 | import io.palaima.debugdrawer.BaseDebugModule;
36 | import io.palaima.debugdrawer.DebugWidgetStore;
37 | import io.palaima.debugdrawer.R;
38 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
39 |
40 | import static io.palaima.debugdrawer.util.PackageManagerHook.KEY_CURRENT_VERSION_CODE;
41 | import static io.palaima.debugdrawer.util.PackageManagerHook.KEY_CURRENT_VERSION_NAME;
42 |
43 | public class BuildModule extends BaseDebugModule {
44 |
45 | private DebugWidgetStore store;
46 |
47 | private PackageInfo info;
48 |
49 | private static final int ID_VERSION_CODE = R.id.version_code_view_id, ID_VERSION_NAME = R.id.version_name_view_id;
50 |
51 | @NonNull
52 | @Override
53 | public String getName() {
54 | return "Build Information";
55 | }
56 |
57 | @Override
58 | public void onAttachActivity(Activity activity) {
59 | super.onAttachActivity(activity);
60 | try {
61 | info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
62 | } catch (PackageManager.NameNotFoundException e) {
63 | e.printStackTrace();
64 | }
65 | }
66 |
67 | @Override
68 | public DebugWidgetStore createWidgetStore(DebugWidgetStore.Builder builder) {
69 | store = builder
70 | .addText("Version", String.valueOf(info.versionCode), ID_VERSION_CODE)
71 | .addText("Name", info.versionName, ID_VERSION_NAME)
72 | .addText("Package", info.packageName)
73 | .addButton("modify version code/name", new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | PkgDialog dialog = new PkgDialog();
77 | dialog.show(((FragmentActivity) getActivity()).getSupportFragmentManager(), "pkgDialog");
78 | dialog.setWidgetStore(store);
79 | }
80 | })
81 | .build();
82 | return store;
83 | }
84 |
85 | public static class PkgDialog extends DialogFragment {
86 |
87 | private DebugWidgetStore widgetStore;
88 |
89 | private EditText codeEt;
90 |
91 | private EditText nameEt;
92 |
93 | @NonNull
94 | @Override
95 | public Dialog onCreateDialog(Bundle savedInstanceState) {
96 | return new AlertDialog.Builder(getActivity())
97 | .setTitle("Input new info")
98 | .setView(R.layout.dd_pkg_info_dialog)
99 | .setPositiveButton("submit", new DialogInterface.OnClickListener() {
100 | @Override
101 | public void onClick(DialogInterface dialog, int which) {
102 | SharedPreferences.Editor spEditor = DebugDrawerUtil.getSpEditor(getContext());
103 | spEditor.putInt(KEY_CURRENT_VERSION_CODE,
104 | Integer.valueOf(codeEt.getText().toString().trim())).apply();
105 | spEditor.putString(KEY_CURRENT_VERSION_NAME,
106 | nameEt.getText().toString().trim()).apply();
107 | Toast.makeText(getActivity(), "success~", Toast.LENGTH_SHORT).show();
108 | }
109 | })
110 | .create();
111 | }
112 |
113 | @Override
114 | public void onStart() {
115 | super.onStart();
116 | codeEt = (EditText) getDialog().findViewById(R.id.code_et);
117 | nameEt = (EditText) getDialog().findViewById(R.id.name_et);
118 |
119 | try {
120 | PackageInfo info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
121 | codeEt.setText(String.valueOf(info.versionCode));
122 | nameEt.setText(info.versionName);
123 | } catch (PackageManager.NameNotFoundException e) {
124 | e.printStackTrace();
125 | codeEt.setText("N/A");
126 | nameEt.setText("N/A");
127 | }
128 | }
129 |
130 | @Override
131 | public void onDismiss(DialogInterface dialog) {
132 | super.onDismiss(dialog);
133 | ((TextView) widgetStore.getDebugWidget(ID_VERSION_CODE).getView()).setText(codeEt.getText());
134 | ((TextView) widgetStore.getDebugWidget(ID_VERSION_NAME).getView()).setText(nameEt.getText());
135 | }
136 |
137 | public void setWidgetStore(DebugWidgetStore widgetStore) {
138 | this.widgetStore = widgetStore;
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/view/ScrimInsetsFrameLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer.view;
18 |
19 |
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Rect;
24 | import android.graphics.drawable.ColorDrawable;
25 | import android.graphics.drawable.Drawable;
26 | import android.support.v4.view.ViewCompat;
27 | import android.util.AttributeSet;
28 | import android.widget.FrameLayout;
29 |
30 | import io.palaima.debugdrawer.R;
31 |
32 |
33 | /**
34 | * A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the area above UI chrome
35 | * (status and navigation bars, overlay action bars).
36 | */
37 | public class ScrimInsetsFrameLayout extends FrameLayout {
38 |
39 | private Drawable insetForeground;
40 |
41 | private Rect insets;
42 |
43 | private Rect tempRect = new Rect();
44 |
45 | private OnInsetsCallback onInsetsCallback;
46 |
47 | private boolean enabled = true;
48 |
49 | public ScrimInsetsFrameLayout(Context context) {
50 | super(context);
51 | init(context, null, 0);
52 | }
53 |
54 | public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) {
55 | super(context, attrs);
56 | init(context, attrs, 0);
57 | }
58 |
59 | public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) {
60 | super(context, attrs, defStyle);
61 | init(context, attrs, defStyle);
62 | }
63 |
64 | private void init(Context context, AttributeSet attrs, int defStyle) {
65 | final TypedArray a = context.obtainStyledAttributes(attrs,
66 | R.styleable.DebugDrawerScrimInsetsView, defStyle, 0);
67 | if (a == null) {
68 | return;
69 | }
70 | insetForeground = a.getDrawable(R.styleable.DebugDrawerScrimInsetsView_dd_siv_insetForeground);
71 | a.recycle();
72 |
73 | setWillNotDraw(true);
74 | }
75 |
76 | @Override
77 | protected boolean fitSystemWindows(Rect insets) {
78 | this.insets = new Rect(insets);
79 | setWillNotDraw(insetForeground == null);
80 | ViewCompat.postInvalidateOnAnimation(this);
81 | if (onInsetsCallback != null) {
82 | onInsetsCallback.onInsetsChanged(insets);
83 | }
84 | return true; // consume insets
85 | }
86 |
87 | @Override
88 | public void draw(Canvas canvas) {
89 | super.draw(canvas);
90 |
91 | int width = getWidth();
92 | int height = getHeight();
93 | if (insets != null && insetForeground != null) {
94 | int sc = canvas.save();
95 | canvas.translate(getScrollX(), getScrollY());
96 |
97 | // Top
98 | tempRect.set(0, 0, width, insets.top);
99 | insetForeground.setBounds(tempRect);
100 | insetForeground.draw(canvas);
101 |
102 | // Bottom
103 | tempRect.set(0, height - insets.bottom, width, height);
104 | insetForeground.setBounds(tempRect);
105 | insetForeground.draw(canvas);
106 |
107 | // Left
108 | tempRect.set(0, insets.top, insets.left, height - insets.bottom);
109 | insetForeground.setBounds(tempRect);
110 | insetForeground.draw(canvas);
111 |
112 | // Right
113 | tempRect.set(width - insets.right, insets.top, width, height - insets.bottom);
114 | insetForeground.setBounds(tempRect);
115 | insetForeground.draw(canvas);
116 |
117 | canvas.restoreToCount(sc);
118 | }
119 | }
120 |
121 | @Override
122 | protected void onAttachedToWindow() {
123 | super.onAttachedToWindow();
124 | if (insetForeground != null) {
125 | insetForeground.setCallback(this);
126 | }
127 | }
128 |
129 | @Override
130 | protected void onDetachedFromWindow() {
131 | super.onDetachedFromWindow();
132 | if (insetForeground != null) {
133 | insetForeground.setCallback(null);
134 | }
135 | }
136 |
137 |
138 | public boolean isEnabled() {
139 | return enabled;
140 | }
141 |
142 | public void setEnabled(boolean enabled) {
143 | this.enabled = enabled;
144 | //setWillNotDraw(false);
145 | invalidate();
146 | }
147 |
148 |
149 | public Drawable getInsetForeground() {
150 | return insetForeground;
151 | }
152 |
153 | public void setInsetForeground(Drawable mInsetForeground) {
154 | this.insetForeground = mInsetForeground;
155 | }
156 |
157 | public void setInsetForeground(int mInsetForegroundColor) {
158 | this.insetForeground = new ColorDrawable(mInsetForegroundColor);
159 | }
160 |
161 | /**
162 | * Allows the calling container to specify a callback for custom processing when insets change (i.e. when
163 | * {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements based on
164 | * UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, remember to set
165 | * clipToPadding to false.
166 | */
167 | public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) {
168 | this.onInsetsCallback = onInsetsCallback;
169 | }
170 |
171 | public static interface OnInsetsCallback {
172 |
173 | public void onInsetsChanged(Rect insets);
174 | }
175 | }
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/DebugDrawer.java:
--------------------------------------------------------------------------------
1 | package io.palaima.debugdrawer;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import android.app.Activity;
10 | import android.app.Application;
11 | import android.os.Bundle;
12 | import android.support.annotation.CheckResult;
13 | import android.support.v4.util.ArrayMap;
14 | import android.view.ViewGroup;
15 |
16 | import com.amitshekhar.DebugDB;
17 | import com.github.moduth.blockcanary.BlockCanary;
18 | import com.github.moduth.blockcanary.BlockCanaryContext;
19 | import com.github.simonpercic.oklog.core.CustomLogManager;
20 | import com.github.simonpercic.oklog.core.LogDataConfig;
21 | import com.github.simonpercic.oklog3.OkLogInterceptor;
22 | import com.hugo.watcher.Watcher;
23 | import com.squareup.leakcanary.LeakCanary;
24 |
25 | import io.palaima.debugdrawer.util.DebugDrawerUtil;
26 | import io.palaima.debugdrawer.util.PackageManagerHook;
27 | import okhttp3.OkHttpClient;
28 |
29 | /**
30 | * @author Kale
31 | * @date 2017/5/9
32 | */
33 | public class DebugDrawer {
34 |
35 | private static Map sMap = new ArrayMap<>();
36 |
37 | public static OkHttpClient createOkLogHttpClient(OkHttpClient client) {
38 | if (!DebugDrawerUtil.hasClass("com.github.simonpercic.oklog3.OkLogInterceptor")) {
39 | return client;
40 | }
41 |
42 | // create an instance of OkLogInterceptor using a builder()
43 | OkLogInterceptor.Builder builder = OkLogInterceptor.builder();
44 | OkLogInterceptor okLogInterceptor = null;
45 | try {
46 | Method buildLogDataConfig = builder.getClass().getSuperclass().getDeclaredMethod("buildLogDataConfig");
47 | buildLogDataConfig.setAccessible(true);
48 | LogDataConfig cfg = (LogDataConfig) buildLogDataConfig.invoke(builder);
49 | CustomLogManager customLogManager = new CustomLogManager("http://responseecho-simonpercic.rhcloud.com", null, true, true, false, cfg);
50 | okLogInterceptor = builder.build();
51 | Field logManager = okLogInterceptor.getClass().getDeclaredField("logManager");
52 | logManager.setAccessible(true);
53 | logManager.set(okLogInterceptor, customLogManager);
54 | } catch (NoSuchMethodException e) {
55 | e.printStackTrace();
56 | } catch (InvocationTargetException e) {
57 | e.printStackTrace();
58 | } catch (IllegalAccessException e) {
59 | e.printStackTrace();
60 | } catch (NoSuchFieldException e) {
61 | e.printStackTrace();
62 | }
63 | return client.newBuilder()
64 | .addInterceptor(okLogInterceptor)
65 | .build();
66 | }
67 |
68 | public static void init(Application application, final Config cfg) {
69 | PackageManagerHook.hook(application); // hook pkgInfo
70 |
71 | if (DebugDrawerUtil.hasClass("com.amitshekhar.DebugDB")) {
72 | DebugDB.initialize(application);
73 | }
74 | if (DebugDrawerUtil.hasClass("com.hugo.watcher.Watcher")) {
75 | Watcher.getInstance().start(application);
76 | Watcher.getInstance().stop(application);
77 | }
78 | if (DebugDrawerUtil.hasClass("com.squareup.leakcanary.LeakCanary")
79 | && !LeakCanary.isInAnalyzerProcess(application)) {
80 | LeakCanary.install(application);
81 | }
82 | if (DebugDrawerUtil.hasClass("com.github.moduth.blockcanary.BlockCanary")) {
83 | BlockCanary.install(application, new BlockCanaryContext() {
84 | public int provideBlockThreshold() {
85 | return 500;
86 | }
87 |
88 | public boolean displayNotification() {
89 | return true;
90 | }
91 | }).start();
92 | }
93 |
94 | application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
95 | @Override
96 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
97 | }
98 |
99 | @Override
100 | public void onActivityStarted(Activity activity) {
101 | DebugWidgetsFrame widgetsLayout = sMap.get(activity);
102 | if (widgetsLayout == null && checkActivity(activity)) {
103 | DebugWidgetsFrame layout = new DebugWidgetsFrame(activity, cfg.getModules());
104 | sMap.put(activity, layout);
105 | }
106 | }
107 |
108 | @Override
109 | public void onActivityResumed(Activity activity) {
110 | sMap.get(activity).resume();
111 | }
112 |
113 | @Override
114 | public void onActivityPaused(Activity activity) {
115 | }
116 |
117 | @Override
118 | public void onActivityStopped(Activity activity) {
119 |
120 | }
121 |
122 | @Override
123 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
124 |
125 | }
126 |
127 | @Override
128 | public void onActivityDestroyed(Activity activity) {
129 | sMap.get(activity).destroy();
130 | sMap.remove(activity);
131 | }
132 | });
133 | }
134 |
135 | @CheckResult
136 | public static boolean checkActivity(Activity activity) {
137 | ViewGroup rootView = (ViewGroup) activity.findViewById(android.R.id.content);
138 | return rootView != null && rootView.getChildCount() != 0;
139 | }
140 |
141 | /**
142 | * Open the drawer
143 | */
144 | public static void openDrawer(Activity currentAct) {
145 | sMap.get(currentAct).openDrawer();
146 | }
147 |
148 | /**
149 | * close the drawer
150 | */
151 | public static void closeDrawer(Activity currentAct) {
152 | sMap.get(currentAct).closeDrawer();
153 | }
154 |
155 | /**
156 | * Get the current state of the drawer.
157 | * True if the drawer is currently open.
158 | */
159 | public static boolean isDrawerOpened(Activity currentAct) {
160 | return sMap.get(currentAct).isDrawerOpened();
161 | }
162 |
163 | public abstract static class Config {
164 |
165 | protected abstract List getModules();
166 |
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/util/NetworkController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 LemonLabs
3 | * Copyright (C) 2015 Mantas Palaima
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.palaima.debugdrawer.util;
19 |
20 | import java.lang.reflect.Field;
21 | import java.lang.reflect.InvocationTargetException;
22 | import java.lang.reflect.Method;
23 |
24 | import android.Manifest;
25 | import android.bluetooth.BluetoothAdapter;
26 | import android.content.BroadcastReceiver;
27 | import android.content.Context;
28 | import android.content.Intent;
29 | import android.content.IntentFilter;
30 | import android.content.pm.PackageManager;
31 | import android.net.ConnectivityManager;
32 | import android.net.NetworkInfo;
33 | import android.net.wifi.WifiManager;
34 | import android.support.annotation.Nullable;
35 |
36 | public class NetworkController {
37 |
38 | private enum BluetoothState {
39 | On, Off, Turning_On, Turning_Off, Unknown
40 | }
41 |
42 | interface OnNetworkChangedListener {
43 |
44 | void onChanged(NetworkChangeEvent event);
45 | }
46 |
47 | private static NetworkController instance;
48 |
49 | private WifiManager wifiManager;
50 |
51 | private ConnectivityManager connectivityManager;
52 |
53 | private BluetoothAdapter bluetoothAdapter;
54 |
55 | private NetworkReceiver receiver;
56 |
57 | private transient Context context;
58 |
59 | private OnNetworkChangedListener onNetworkChangedListener;
60 |
61 | public static NetworkController newInstance(Context context) {
62 | if (instance == null) {
63 | instance = new NetworkController(context.getApplicationContext());
64 | }
65 | return instance;
66 | }
67 |
68 | /**
69 | * Controller responsible for switching states related to networks.
70 | * E.g. wifi, mobile networks
71 | */
72 | private NetworkController(Context context) {
73 | this.context = context.getApplicationContext();
74 | wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
75 | connectivityManager = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
76 | bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
77 | }
78 |
79 | public void setOnNetworkChangedListener(OnNetworkChangedListener listener) {
80 | onNetworkChangedListener = listener;
81 | }
82 |
83 | /**
84 | * True if WiFi enabled
85 | */
86 | public boolean isWifiEnabled() {
87 | return wifiManager.isWifiEnabled();
88 | }
89 |
90 | /**
91 | * Set WiFi state
92 | */
93 | public void setWifiEnabled(boolean enabled) {
94 | wifiManager.setWifiEnabled(enabled);
95 | }
96 |
97 | /**
98 | * True if mobile network enabled
99 | */
100 | public boolean isMobileNetworkEnabled() {
101 | final NetworkInfo info = connectivityManager.getNetworkInfo(
102 | ConnectivityManager.TYPE_MOBILE);
103 | return (info != null && info.isConnected());
104 | }
105 |
106 | /**
107 | * http://stackoverflow.com/questions/11555366/enable-disable-data-connection-in-android-programmatically
108 | * Try to enabled/disable mobile network state using reflection.
109 | * Returns true if succeeded
110 | */
111 | public boolean setMobileNetworkEnabled(boolean enabled) {
112 | try {
113 | final Class conmanClass = Class.forName(connectivityManager.getClass().getName());
114 | final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
115 | iConnectivityManagerField.setAccessible(true);
116 | final Object iConnectivityManager = iConnectivityManagerField.get(connectivityManager);
117 | final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
118 | final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
119 | setMobileDataEnabledMethod.setAccessible(true);
120 | setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
121 | return true;
122 | } catch (ClassNotFoundException e) {
123 | } catch (InvocationTargetException e) {
124 | } catch (NoSuchMethodException e) {
125 | } catch (IllegalAccessException e) {
126 | } catch (NoSuchFieldException e) {
127 | }
128 | return false;
129 | }
130 |
131 | /**
132 | * @return True if bluetooth adapter is not null
133 | */
134 | public boolean isBluetoothAvailable() {
135 | return bluetoothAdapter != null;
136 | }
137 |
138 | /**
139 | * @return True if bluetooth is enabled
140 | */
141 | public boolean isBluetoothEnabled() {
142 | return isBluetoothAvailable() && hasBlueBoothPermission() && bluetoothAdapter.isEnabled();
143 | }
144 |
145 | private boolean hasBlueBoothPermission() {
146 | return context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED;
147 | }
148 |
149 | /**
150 | * Try to enable/disabled bluetooth. Returns false if immediate
151 | * error occurs
152 | */
153 | public boolean setBluetoothEnabled(boolean enabled) {
154 | return isBluetoothAvailable() && (enabled ? bluetoothAdapter.enable()
155 | : bluetoothAdapter.disable());
156 | }
157 |
158 |
159 | /**
160 | * Unregister network state broadcast receiver
161 | */
162 | public void unregisterReceiver() {
163 | try {
164 | context.unregisterReceiver(receiver);
165 | } catch (IllegalArgumentException e) {
166 | }
167 | }
168 |
169 | /**
170 | * Register network state broadcast receiver
171 | */
172 | public void registerReceiver() {
173 | if (receiver == null) {
174 | receiver = new NetworkReceiver(new Listener() {
175 | @Override
176 | public void post(NetworkChangeEvent event) {
177 | if (onNetworkChangedListener != null) {
178 | onNetworkChangedListener.onChanged(event);
179 | }
180 | }
181 | });
182 | }
183 | IntentFilter filter = new IntentFilter();
184 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
185 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
186 | context.registerReceiver(receiver, filter);
187 | }
188 |
189 | /**
190 | * Receiver that handles wifi, mobile networks and
191 | * Bluetooth connectivity change intents and sends
192 | * a NetworkChangeEvent using listener
193 | *
194 | */
195 | public static class NetworkReceiver extends BroadcastReceiver {
196 |
197 | @Nullable
198 | private final Listener listener;
199 |
200 | public NetworkReceiver(@Nullable Listener listener) {
201 | this.listener = listener;
202 | }
203 |
204 | @Override
205 | public void onReceive(Context context, Intent intent) {
206 | if (listener != null) {
207 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
208 |
209 | NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
210 | NetworkInfo mobileInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
211 | BluetoothAdapter bluetoothInfo = BluetoothAdapter.getDefaultAdapter();
212 |
213 | final NetworkChangeEvent networkChangeEvent = new NetworkChangeEvent(
214 | (wifiInfo != null) ? wifiInfo.getState() : NetworkInfo.State.UNKNOWN,
215 | (mobileInfo != null) ? mobileInfo.getState() : NetworkInfo.State.UNKNOWN,
216 | (bluetoothInfo != null) ? getBluetoothState(bluetoothInfo.getState()) : BluetoothState.Unknown);
217 |
218 | listener.post(networkChangeEvent);
219 | }
220 |
221 | }
222 |
223 | /**
224 | * Converts Bluetooth state representation to an Enum
225 | */
226 | private BluetoothState getBluetoothState(int state) {
227 | switch (state) {
228 | case BluetoothAdapter.STATE_ON:
229 | return BluetoothState.On;
230 | case BluetoothAdapter.STATE_OFF:
231 | return BluetoothState.Off;
232 | case BluetoothAdapter.STATE_TURNING_ON:
233 | return BluetoothState.Turning_On;
234 | case BluetoothAdapter.STATE_TURNING_OFF:
235 | return BluetoothState.Turning_Off;
236 | }
237 |
238 | return BluetoothState.Unknown;
239 | }
240 | }
241 |
242 | public static class NetworkChangeEvent {
243 |
244 | public final NetworkInfo.State wifiState;
245 |
246 | public final NetworkInfo.State mobileState;
247 |
248 | public final BluetoothState bluetoothState;
249 |
250 | public NetworkChangeEvent(NetworkInfo.State wifiState, NetworkInfo.State mobileState, BluetoothState bluetoothState) {
251 | this.wifiState = wifiState;
252 | this.mobileState = mobileState;
253 | this.bluetoothState = bluetoothState;
254 | }
255 | }
256 |
257 | public interface Listener {
258 |
259 | void post(NetworkChangeEvent event);
260 | }
261 |
262 | }
263 |
--------------------------------------------------------------------------------
/lib/src/main/java/io/palaima/debugdrawer/DebugWidgetsFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Mantas Palaima
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.palaima.debugdrawer;
18 |
19 | import java.util.List;
20 |
21 | import android.app.Activity;
22 | import android.os.Build;
23 | import android.support.annotation.NonNull;
24 | import android.support.v4.widget.DrawerLayout;
25 | import android.support.v7.view.ContextThemeWrapper;
26 | import android.view.Gravity;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.FrameLayout;
31 | import android.widget.GridLayout;
32 | import android.widget.ScrollView;
33 | import android.widget.TextView;
34 |
35 | import io.palaima.debugdrawer.util.UIUtils;
36 | import io.palaima.debugdrawer.view.ScrimInsetsFrameLayout;
37 |
38 | public class DebugWidgetsFrame {
39 |
40 | private ViewGroup rootView;
41 |
42 | private Activity activity;
43 |
44 | private DrawerLayout drawerLayout;
45 |
46 | private ScrollView sliderLayout;
47 |
48 | private int drawerGravity = Gravity.END;
49 |
50 | private List debugModules;
51 |
52 | private DrawerLayout.DrawerListener onDrawerListener;
53 |
54 | /**
55 | * Set the gravity for the drawer. START, LEFT | RIGHT, END
56 | */
57 | public DebugWidgetsFrame(Activity activity, List debugModules) {
58 | this.activity = activity;
59 | this.rootView = (ViewGroup) activity.findViewById(android.R.id.content);
60 | this.debugModules = debugModules;
61 | if (rootView == null || rootView.getChildCount() == 0) {
62 | throw new RuntimeException(
63 | "You have to set your layout for this activity with setContentView() first.");
64 | }
65 | init();
66 | }
67 |
68 | /**
69 | * Build and add the Drawer to your activity
70 | */
71 | private void init() {
72 | setDrawerLayout();
73 |
74 | //get the drawer root
75 | ScrimInsetsFrameLayout drawerContentRoot = (ScrimInsetsFrameLayout) drawerLayout.getChildAt(0);
76 |
77 | //get the content view
78 | View contentView = getContentView();
79 |
80 | //add the contentView to the drawer content frameLayout
81 | drawerContentRoot.addView(contentView, new FrameLayout.LayoutParams(
82 | ViewGroup.LayoutParams.MATCH_PARENT,
83 | ViewGroup.LayoutParams.MATCH_PARENT
84 | ));
85 |
86 | //add the drawerLayout to the root
87 | rootView.addView(drawerLayout, new ViewGroup.LayoutParams(
88 | ViewGroup.LayoutParams.MATCH_PARENT,
89 | ViewGroup.LayoutParams.MATCH_PARENT
90 | ));
91 |
92 | sliderLayout = (ScrollView) drawerLayout.findViewById(R.id.dd_slider_layout);
93 | setSliderLayout();
94 |
95 | GridLayout moduleGl = ((GridLayout) sliderLayout.findViewById(R.id.dd_module_gl));
96 | for (BaseDebugModule module : debugModules) {
97 | inflateModules(module, moduleGl);
98 | }
99 | activity = null;
100 | }
101 |
102 | private void setSliderLayout() {
103 | DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) sliderLayout.getLayoutParams();
104 | if (params != null) {
105 | // if we've set a custom gravity set it
106 | if (drawerGravity != 0) {
107 | params.gravity = drawerGravity;
108 | }
109 | // if this is a drawer from the right, change the margins :D
110 | params = processDrawerLayoutParams(params);
111 | // set the new layout params
112 | sliderLayout.setLayoutParams(params);
113 | }
114 | }
115 |
116 | private View getContentView() {
117 | View contentView = rootView.getChildAt(0);
118 | boolean alreadyInflated = contentView instanceof DrawerLayout;
119 |
120 | //only add the new layout if it wasn't done before
121 | if (!alreadyInflated) {
122 | // remove the contentView
123 | rootView.removeView(contentView);
124 | } else {
125 | //if it was already inflated we have to clean up again
126 | rootView.removeAllViews();
127 | }
128 | return contentView;
129 | }
130 |
131 | private void setDrawerLayout() {
132 | drawerLayout = (DrawerLayout) activity.getLayoutInflater()
133 | .inflate(R.layout.dd_debug_drawer, rootView, false);
134 | drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
135 | @Override
136 | public void onDrawerOpened(View drawerView) {
137 | super.onDrawerOpened(drawerView);
138 | for (BaseDebugModule module : debugModules) {
139 | module.onDrawerOpened();
140 | }
141 | }
142 | });
143 | drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
144 | @Override
145 | public void onDrawerSlide(View drawerView, float slideOffset) {
146 | if (onDrawerListener != null) {
147 | onDrawerListener.onDrawerSlide(drawerView, slideOffset);
148 | }
149 | }
150 |
151 | @Override
152 | public void onDrawerOpened(View drawerView) {
153 | if (onDrawerListener != null) {
154 | onDrawerListener.onDrawerOpened(drawerView);
155 | }
156 | }
157 |
158 | @Override
159 | public void onDrawerClosed(View drawerView) {
160 | if (onDrawerListener != null) {
161 | onDrawerListener.onDrawerClosed(drawerView);
162 | }
163 | }
164 |
165 | @Override
166 | public void onDrawerStateChanged(int newState) {
167 |
168 | }
169 | });
170 | }
171 |
172 | private void inflateModules(BaseDebugModule module, GridLayout gl) {
173 | module.setActivity(activity);
174 | View titleV = LayoutInflater.from(activity).inflate(R.layout.dd_module_title, null, false);
175 | ((TextView) titleV.findViewById(R.id.title_tv)).setText(module.getName());
176 | GridLayout.LayoutParams params = getSpanColParams(gl);
177 | params.setMargins(0, 20, 0, 3);
178 | gl.addView(titleV, params);
179 |
180 | DebugWidgetStore widgets = module.createWidgetStore(new DebugWidgetStore.Builder(activity));
181 | if (widgets == null) {
182 | gl.removeView(titleV);
183 | return;
184 | }
185 |
186 | for (DebugWidget widget : widgets.getWidgets()) {
187 | if (widget.title != null) {
188 | // add title widget
189 | TextView tv = new TextView(new ContextThemeWrapper(activity, R.style.Widget_DebugDrawer_Base_RowTitle));
190 | tv.setText(widget.title);
191 | gl.addView(tv);
192 |
193 | // add summary widget
194 | gl.addView(widget.view);
195 | } else {
196 | gl.addView(widget.view, getSpanColParams(gl));
197 | }
198 | }
199 | }
200 |
201 | @NonNull
202 | private GridLayout.LayoutParams getSpanColParams(GridLayout gl) {
203 | // http://bbs.csdn.net/topics/391853628
204 | // 行设置,第一个为参数为第几行,默认可不设置,第二个参数为跨行数,没有则表示不跨行
205 | GridLayout.Spec row = GridLayout.spec(GridLayout.UNDEFINED);
206 | // 列设置,第一个为参数为第几列,默认可不设置,第二个参数为跨列数,没有则表示不跨行
207 | GridLayout.Spec col = GridLayout.spec(GridLayout.UNDEFINED, gl.getColumnCount());
208 | GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
209 | params.width = GridLayout.LayoutParams.MATCH_PARENT;
210 | return params;
211 | }
212 |
213 | /**
214 | * helper to extend the layoutParams of the drawer
215 | */
216 | private DrawerLayout.LayoutParams processDrawerLayoutParams(DrawerLayout.LayoutParams params) {
217 | if (params != null) {
218 | if (drawerGravity != 0 && (drawerGravity == Gravity.RIGHT || drawerGravity == Gravity.END)) {
219 | params.rightMargin = 0;
220 | if (Build.VERSION.SDK_INT >= 17) {
221 | params.setMarginEnd(0);
222 | }
223 |
224 | params.leftMargin = activity.getResources().getDimensionPixelSize(R.dimen.dd_debug_drawer_margin);
225 | if (Build.VERSION.SDK_INT >= 17) {
226 | params.setMarginEnd(activity.getResources().getDimensionPixelSize(R.dimen.dd_debug_drawer_margin));
227 | }
228 | }
229 | params.width = UIUtils.getOptimalDrawerWidth(activity);
230 | }
231 |
232 | return params;
233 | }
234 |
235 | public void setDrawerListener(DrawerLayout.DrawerListener onDrawerListener) {
236 | this.onDrawerListener = onDrawerListener;
237 | }
238 |
239 |
240 | public void resume() {
241 | for (BaseDebugModule module : debugModules) {
242 | module.onActivityResume();
243 | }
244 | }
245 |
246 | public void destroy() {
247 | for (BaseDebugModule module : debugModules) {
248 | module.onActivityDestroy();
249 | }
250 | }
251 |
252 | /**
253 | * Open the drawer
254 | */
255 | public void openDrawer() {
256 | if (drawerLayout != null && sliderLayout != null) {
257 | if (drawerGravity != 0) {
258 | drawerLayout.openDrawer(drawerGravity);
259 | } else {
260 | drawerLayout.openDrawer(sliderLayout);
261 | }
262 | }
263 | }
264 |
265 | /**
266 | * close the drawer
267 | */
268 | public void closeDrawer() {
269 | if (drawerLayout != null) {
270 | if (drawerGravity != 0) {
271 | drawerLayout.closeDrawer(drawerGravity);
272 | } else {
273 | drawerLayout.closeDrawer(sliderLayout);
274 | }
275 | }
276 | }
277 |
278 | /**
279 | * Get the current state of the drawer.
280 | * True if the drawer is currently open.
281 | */
282 | public boolean isDrawerOpened() {
283 | return drawerLayout != null && sliderLayout != null && drawerLayout.isDrawerOpen(sliderLayout);
284 | }
285 |
286 | /**
287 | * Enable or disable interaction with all drawers.
288 | */
289 | public void setDrawerLockMode(int lockMode) {
290 | if (drawerLayout != null && sliderLayout != null) {
291 | drawerLayout.setDrawerLockMode(lockMode);
292 | }
293 | }
294 | }
295 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------