diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 000000000..3c6e8ac04 --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,11 @@ +Please complete the following informations. +> Expected behavior and actual behavior. +> Steps to reproduce the problem. +> Android or iOS? OS version? Brand? +> More informations such as error messages and stack traces are welcomed. + +请补充如下信息。 +> 期望的表现和实际的表现。(如有) +> 问题重现的步骤。(如有) +> Android 还是 iOS?系统版本是多少?手机品牌是什么?(如有) +> 其他的错误信息和堆栈信息如果有也可以一并提供出来。(如有) diff --git a/Android/adb/src/main/AndroidManifest.xml b/Android/adb/src/main/AndroidManifest.xml index fddb585c0..36d28b18e 100644 --- a/Android/adb/src/main/AndroidManifest.xml +++ b/Android/adb/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/Android/adb/upload.sh b/Android/adb/upload.sh new file mode 100644 index 000000000..d220f4318 --- /dev/null +++ b/Android/adb/upload.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +echo -n "please enter bintray userid ->" +read userid_bintray +echo -n "please enter bintray apikey ->" +read apikey_bintray +../gradlew clean build bintrayUpload -PbintrayUser=${userid_bintray} -PbintrayKey=${apikey_bintray} -PdryRun=false \ No newline at end of file diff --git a/Android/app/build.gradle b/Android/app/build.gradle index 43117c866..4e842c219 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'com.android.application' -apply plugin: 'com.doraemon.compiler.plugin' +apply from: 'doraemonkit.gradle' android { compileSdkVersion 26 diff --git a/Android/app/doraemonkit.gradle b/Android/app/doraemonkit.gradle new file mode 100644 index 000000000..013001f07 --- /dev/null +++ b/Android/app/doraemonkit.gradle @@ -0,0 +1,18 @@ +ext { + // 很多app都会有自己的打包开关,来区分线上包和测试包,可以通过给applyPlugin赋值来区分测试包和线上包 + // 线上包不会接入DoraemonKit,测试包会自动接入 + applyPlugin = true +} +if (applyPlugin) { + // 引用插件,插件会在编译期把DoraemonKit.install方法插入Application中,前提是用户必须实现自己的Application + apply plugin: 'com.doraemon.compiler.plugin' + // 这里引用正常库 + dependencies { + implementation project(":doraemonkit") + } +} else { + // 引用no-op的库 + dependencies { + implementation project(":doraemonkit-no-op") + } +} \ No newline at end of file diff --git a/Android/app/src/main/AndroidManifest.xml b/Android/app/src/main/AndroidManifest.xml index 497f25c3b..3b16f30e6 100644 --- a/Android/app/src/main/AndroidManifest.xml +++ b/Android/app/src/main/AndroidManifest.xml @@ -5,10 +5,10 @@ @@ -20,6 +20,7 @@ + \ No newline at end of file diff --git a/Android/app/src/main/java/com/didichuxing/doraemondemo/App.java b/Android/app/src/main/java/com/didichuxing/doraemondemo/App.java index df62be83f..5d4cf85bc 100644 --- a/Android/app/src/main/java/com/didichuxing/doraemondemo/App.java +++ b/Android/app/src/main/java/com/didichuxing/doraemondemo/App.java @@ -1,6 +1,7 @@ package com.didichuxing.doraemondemo; import android.app.Application; +import android.content.Context; import android.content.Intent; import android.os.StrictMode; @@ -13,13 +14,14 @@ public class App extends Application { private static final String TAG = "App"; + @Override public void onCreate() { super.onCreate(); DoraemonKit.install(this); DoraemonKit.setWebDoorCallback(new WebDoorManager.WebDoorCallback() { @Override - public void overrideUrlLoading(String url) { + public void overrideUrlLoading(Context context, String url) { Intent intent = new Intent(App.this, WebViewActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(WebViewActivity.KEY_URL, url); diff --git a/Android/app/src/main/java/com/didichuxing/doraemondemo/MainActivity.java b/Android/app/src/main/java/com/didichuxing/doraemondemo/MainActivity.java index e4daa0f0a..b253c5234 100644 --- a/Android/app/src/main/java/com/didichuxing/doraemondemo/MainActivity.java +++ b/Android/app/src/main/java/com/didichuxing/doraemondemo/MainActivity.java @@ -1,13 +1,20 @@ package com.didichuxing.doraemondemo; +import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; +import android.widget.Toast; +import com.didichuxing.doraemonkit.DoraemonKit; +import com.didichuxing.doraemonkit.kit.network.NetworkManager; import com.didichuxing.doraemonkit.kit.network.common.CommonHeaders; import com.didichuxing.doraemonkit.kit.network.common.CommonInspectorRequest; import com.didichuxing.doraemonkit.kit.network.common.CommonInspectorResponse; import com.didichuxing.doraemonkit.kit.network.common.NetworkPrinterHelper; +import com.didichuxing.doraemonkit.kit.timecounter.TimeCounterManager; +import com.didichuxing.doraemonkit.ui.realtime.RealTimeChartPage; +import com.didichuxing.doraemonkit.ui.realtime.datasource.DataSourceFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -26,27 +33,76 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListener { + + private OkHttpClient okHttpClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn_test_urlconnection).setOnClickListener(this); findViewById(R.id.btn_test_okhttp).setOnClickListener(this); + findViewById(R.id.btn_test_custom).setOnClickListener(this); findViewById(R.id.btn_test_crash).setOnClickListener(this); + findViewById(R.id.btn_show_hide_icon).setOnClickListener(this); + findViewById(R.id.btn_time_count).setOnClickListener(this); + okHttpClient = new OkHttpClient().newBuilder().build(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_test_urlconnection: - requestByPost("http://apis.baidu.com/txapi/weixin/wxhot?num=10&page=1&word=%E7%9B%97%E5%A2%93%E7%AC%94%E8%AE%B0"); + if (!NetworkManager.isActive()) { + String title = getString(com.didichuxing.doraemonkit.R.string.dk_kit_network_monitor); + int type = DataSourceFactory.TYPE_NETWORK; + NetworkManager.get().startMonitor(); + RealTimeChartPage.openChartPage(title, type, RealTimeChartPage.DEFAULT_REFRESH_INTERVAL, null); + Toast.makeText(this, "click again", Toast.LENGTH_SHORT).show(); + return; + } + requestByGet("http://apis.baidu.com/txapi/weixin/wxhot?num=10&page=1&word=%E7%9B%97%E5%A2%93%E7%AC%94%E8%AE%B0"); break; case R.id.btn_test_okhttp: + if (!NetworkManager.isActive()) { + String title = getString(com.didichuxing.doraemonkit.R.string.dk_kit_network_monitor); + int type = DataSourceFactory.TYPE_NETWORK; + NetworkManager.get().startMonitor(); + RealTimeChartPage.openChartPage(title, type, RealTimeChartPage.DEFAULT_REFRESH_INTERVAL, null); + Toast.makeText(this, "click again", Toast.LENGTH_SHORT).show(); + return; + } requestByOkHttp(); break; + case R.id.btn_test_custom: + if (!NetworkManager.isActive()) { + String title = getString(com.didichuxing.doraemonkit.R.string.dk_kit_network_monitor); + int type = DataSourceFactory.TYPE_NETWORK; + NetworkManager.get().startMonitor(); + RealTimeChartPage.openChartPage(title, type, RealTimeChartPage.DEFAULT_REFRESH_INTERVAL, null); + Toast.makeText(this, "click again", Toast.LENGTH_SHORT).show(); + return; + } + requestByCustom("http://apis.baidu.com/txapi/weixin/wxhot?num=10&page=1&word=%E7%9B%97%E5%A2%93%E7%AC%94%E8%AE%B0"); + break; case R.id.btn_test_crash: testCrash().length(); break; + case R.id.btn_time_count: + // no-op版本未提供该方法,这里只是方便测试 + if (!TimeCounterManager.get().isRunning()) { + TimeCounterManager.get().start(); + Toast.makeText(this, "click again", Toast.LENGTH_SHORT).show(); + return; + } + startActivity(new Intent(this, TestActivity.class)); + break; + case R.id.btn_show_hide_icon: + if (DoraemonKit.isShow()) { + DoraemonKit.hide(); + } else { + DoraemonKit.show(); + } + break; default: break; } @@ -124,10 +180,9 @@ public void run() { } public void requestByOkHttp() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); Request request = new Request.Builder().get().url("http://www.roundsapp.com/post") .addHeader("testHead", "hahahah").build(); - Call call = client.newCall(request); + Call call = okHttpClient.newCall(request); //异步调用并设置回调函数 call.enqueue(new Callback() { @Override @@ -149,7 +204,7 @@ public void onResponse(Call call, Response response) throws IOException { * {@link NetworkPrinterHelper#updateResponse(CommonInspectorResponse)} * {@link NetworkPrinterHelper#updateResponseBody(int, String)} */ - public void request(String url) { + public void requestByCustom(String url) { // obtain id for this request final int id = NetworkPrinterHelper.obtainRequestId(); diff --git a/Android/app/src/main/java/com/didichuxing/doraemondemo/TestActivity.java b/Android/app/src/main/java/com/didichuxing/doraemondemo/TestActivity.java new file mode 100644 index 000000000..87b9a48be --- /dev/null +++ b/Android/app/src/main/java/com/didichuxing/doraemondemo/TestActivity.java @@ -0,0 +1,15 @@ +package com.didichuxing.doraemondemo; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; + +/** + * @desc: + */ +public class TestActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } +} diff --git a/Android/app/src/main/res/layout/activity_main.xml b/Android/app/src/main/res/layout/activity_main.xml index 7f66b56a0..2993d28ee 100644 --- a/Android/app/src/main/res/layout/activity_main.xml +++ b/Android/app/src/main/res/layout/activity_main.xml @@ -1,27 +1,46 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:context="com.didichuxing.doraemondemo.MainActivity">