From 62e3293013608a89998eb279b7fbc33a4a85d366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Android=20=E8=BD=AE=E5=AD=90=E5=93=A5?= Date: Fri, 28 Jan 2022 14:29:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=95=8C=E9=9D=A2=E6=B2=89=E6=B5=B8=E5=BC=8F=E6=95=88?= =?UTF-8?q?=E6=9E=9C=20=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=89=8D=E5=8F=B0=E6=9C=8D=E5=8A=A1=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=9C=A8=E9=B8=BF=E8=92=99=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E4=B8=8A=E5=B4=A9=E6=BA=83=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=20Android=2012=20=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E4=B8=8A=E9=9D=A2=20PendingIntent=20=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 ++- app/build.gradle | 8 +- .../com/hjq/logcat/demo/MainActivity.java | 6 + .../res/{values-v21 => values-v23}/styles.xml | 28 +-- app/src/main/res/values/strings.xml | 169 +++++++++--------- app/src/main/res/values/styles.xml | 25 +-- library/build.gradle | 4 +- library/src/main/AndroidManifest.xml | 9 +- .../java/com/hjq/logcat/ChooseWindow.java | 8 +- .../java/com/hjq/logcat/LogcatActivity.java | 4 + .../java/com/hjq/logcat/LogcatService.java | 9 +- 11 files changed, 171 insertions(+), 124 deletions(-) rename app/src/main/res/{values-v21 => values-v23}/styles.xml (75%) diff --git a/README.md b/README.md index 2e699a4..3af6cb8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ * 项目地址:[Github](https://github.com/getActivity/Logcat)、[码云](https://gitee.com/getActivity/Logcat) -* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Logcat/releases/download/10.0/Logcat.apk) +* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Logcat/releases/download/10.2/Logcat.apk) ![](picture/demo_code.png) @@ -53,7 +53,7 @@ dependencyResolutionManagement { ```groovy dependencies { // 日志调试框架:https://github.com/getActivity/Logcat - debugImplementation 'com.github.getActivity:Logcat:10.0' + debugImplementation 'com.github.getActivity:Logcat:10.2' } ``` @@ -61,7 +61,7 @@ dependencies { * 如果项目是基于 **AndroidX** 包,请在项目 `gradle.properties` 文件中加入 -```groovy +```text # 表示将第三方库迁移到 AndroidX android.enableJetifier = true ``` @@ -106,9 +106,24 @@ android.enableJetifier = true ``` +#### 方向配置 + +* `LogcatActivity` 默认是跟随手机屏幕方向的,如果你需要固定竖屏方向,那么需要在你的清单文件中加入此配置: + +```xml + +``` + #### 日志颜色个性化 -* 在项目的 `values/color.xml` 中加入你喜欢的配色,例如 +* 在项目的 `values/color.xml` 中加入你喜欢的配色,例如: ```xml #FFBBBBBB @@ -121,7 +136,7 @@ android.enableJetifier = true #### 过滤日志 -* 在项目的 `values/string.xml` 中加入你要过滤的日志 TAG,例如 +* 在项目的 `values/string.xml` 中加入你要过滤的日志 TAG,例如: ```xml diff --git a/app/build.gradle b/app/build.gradle index 7f362ce..71a9b04 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.hjq.logcat.demo" minSdkVersion 16 targetSdkVersion 31 - versionCode 1000 - versionName "10.0" + versionCode 1020 + versionName "10.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -65,8 +65,8 @@ dependencies { implementation 'com.github.getActivity:TitleBar:9.3' // 吐司框架:https://github.com/getActivity/ToastUtils - implementation 'com.github.getActivity:ToastUtils:10.0' + implementation 'com.github.getActivity:ToastUtils:10.2' // 内存泄漏捕捉:https://github.com/square/leakcanary - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1' } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/logcat/demo/MainActivity.java b/app/src/main/java/com/hjq/logcat/demo/MainActivity.java index f8ef1d3..561043a 100644 --- a/app/src/main/java/com/hjq/logcat/demo/MainActivity.java +++ b/app/src/main/java/com/hjq/logcat/demo/MainActivity.java @@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity; import android.view.ViewGroup; import android.webkit.WebChromeClient; +import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -30,6 +31,11 @@ protected void onCreate(Bundle savedInstanceState) { mWebView = findViewById(R.id.wv_main_web); mWebView.setWebViewClient(new WebViewClient()); mWebView.setWebChromeClient(new MyWebChromeClient()); + + if (!String.valueOf(System.currentTimeMillis()).endsWith("1")) { + mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + } + mWebView.loadUrl("https://github.com/getActivity/Logcat"); if (NotificationManagerCompat.from(this).areNotificationsEnabled()) { diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v23/styles.xml similarity index 75% rename from app/src/main/res/values-v21/styles.xml rename to app/src/main/res/values-v23/styles.xml index 5b93a18..119e759 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v23/styles.xml @@ -1,14 +1,16 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d400876..cd5effc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,85 +1,86 @@ - - Logcat - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Logcat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9f4db37..f43ca09 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,13 +1,14 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index d80bd6f..55d155a 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion 16 - versionCode 1000 - versionName "10.0" + versionCode 1020 + versionName "10.2" } lintOptions { diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 3136b67..bc502a3 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,3 +1,4 @@ + @@ -5,6 +6,9 @@ + + + + android:launchMode="singleInstance" + android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:windowSoftInputMode="stateHidden" /> diff --git a/library/src/main/java/com/hjq/logcat/ChooseWindow.java b/library/src/main/java/com/hjq/logcat/ChooseWindow.java index 0d990b1..c16eea2 100644 --- a/library/src/main/java/com/hjq/logcat/ChooseWindow.java +++ b/library/src/main/java/com/hjq/logcat/ChooseWindow.java @@ -1,6 +1,7 @@ package com.hjq.logcat; import android.app.Activity; +import android.os.Build; import android.view.Gravity; import android.view.View; import android.view.WindowManager; @@ -19,7 +20,8 @@ * time : 2020/01/24 * desc : 列表选择类 */ -final class ChooseWindow extends XToast implements AdapterView.OnItemClickListener, XToast.OnClickListener { +final class ChooseWindow extends XToast implements + AdapterView.OnItemClickListener, XToast.OnClickListener { private final ChooseAdapter mAdapter; private OnListener mListener; @@ -28,6 +30,10 @@ final class ChooseWindow extends XToast implements AdapterView.OnI super(activity); setContentView(R.layout.logcat_window_choose); setGravity(Gravity.CENTER); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // 设置沉浸式状态栏 + addWindowFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } clearWindowFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); ListView listView = findViewById(R.id.lv_choose_list); diff --git a/library/src/main/java/com/hjq/logcat/LogcatActivity.java b/library/src/main/java/com/hjq/logcat/LogcatActivity.java index 8f0afe0..bd7f603 100644 --- a/library/src/main/java/com/hjq/logcat/LogcatActivity.java +++ b/library/src/main/java/com/hjq/logcat/LogcatActivity.java @@ -455,6 +455,10 @@ private void refreshLayout() { if (window != null) { // 在竖屏的状态下显示状态栏和导航栏 window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // 实现状态栏图标和文字颜色为亮色 + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (window != null) { diff --git a/library/src/main/java/com/hjq/logcat/LogcatService.java b/library/src/main/java/com/hjq/logcat/LogcatService.java index 9ec02c8..14ae13b 100644 --- a/library/src/main/java/com/hjq/logcat/LogcatService.java +++ b/library/src/main/java/com/hjq/logcat/LogcatService.java @@ -29,7 +29,14 @@ public IBinder onBind(Intent intent) { @Override public int onStartCommand(Intent intent, int flags, int startId) { Intent notificationIntent = new Intent(this, LogcatActivity.class); - PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); + int pendingIntentFlag = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + // Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. + // Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. + // if it needs to be used with inline replies or bubbles. + pendingIntentFlag = PendingIntent.FLAG_MUTABLE; + } + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, pendingIntentFlag); String applicationName = getApplicationName(); if (TextUtils.isEmpty(applicationName)) {