Skip to content

Commit

Permalink
优化日志显示界面沉浸式效果
Browse files Browse the repository at this point in the history
修复没有注册前台服务权限导致在鸿蒙手机上崩溃的问题
修复在 Android 12 手机上面 PendingIntent 报错的问题
  • Loading branch information
getActivity committed Jan 28, 2022
1 parent 7e3c2e2 commit 62e3293
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 124 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -53,15 +53,15 @@ dependencyResolutionManagement {
```groovy
dependencies {
// 日志调试框架:https://github.com/getActivity/Logcat
debugImplementation 'com.github.getActivity:Logcat:10.0'
debugImplementation 'com.github.getActivity:Logcat:10.2'
}
```

#### AndroidX

* 如果项目是基于 **AndroidX** 包,请在项目 `gradle.properties` 文件中加入

```groovy
```text
# 表示将第三方库迁移到 AndroidX
android.enableJetifier = true
```
Expand Down Expand Up @@ -106,9 +106,24 @@ android.enableJetifier = true
</manifest>
```

#### 方向配置

* `LogcatActivity` 默认是跟随手机屏幕方向的,如果你需要固定竖屏方向,那么需要在你的清单文件中加入此配置:

```xml
<activity
android:name="com.hjq.logcat.LogcatActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateHidden"
tools:node="replace" />
```

#### 日志颜色个性化

* 在项目的 `values/color.xml` 中加入你喜欢的配色,例如
* 在项目的 `values/color.xml` 中加入你喜欢的配色,例如

```xml
<color name="logcat_level_verbose_color">#FFBBBBBB</color>
Expand All @@ -121,7 +136,7 @@ android.enableJetifier = true

#### 过滤日志

* 在项目的 `values/string.xml` 中加入你要过滤的日志 TAG,例如
* 在项目的 `values/string.xml` 中加入你要过滤的日志 TAG,例如

```xml
<string-array name="logcat_filter_list" tools:ignore="ExtraTranslation">
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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'
}
6 changes: 6 additions & 0 deletions app/src/main/java/com/hjq/logcat/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<!-- 解决 Android 5.1 及以上版本 Button 英文字符串自动变大写的问题 -->
<item name="android:textAllCaps">false</item>
</style>

<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@android:color/white</item>
<item name="android:windowLightStatusBar">true</item>
<!-- 解决 Android 5.1 及以上版本 Button 英文字符串自动变大写的问题 -->
<item name="android:textAllCaps">false</item>
</style>

</resources>
169 changes: 85 additions & 84 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,85 +1,86 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Logcat</string>

<!-- <string-array name="logcat_filter_list" tools:ignore="ExtraTranslation">-->
<!-- <item>ActivityThread</item>-->
<!-- <item>InputMethodManager</item>-->
<!-- <item>OpenGLRenderer</item>-->
<!-- <item>VideoCapabilities</item>-->
<!-- <item>ViewRootImpl</item>-->
<!-- <item>Settings</item>-->
<!-- <item>Looper</item>-->
<!-- <item>TextView</item>-->
<!-- <item>TypefaceUtils</item>-->
<!-- <item>MultiDex</item>-->
<!-- <item>AudioManager</item>-->
<!-- <item>ConnectivityManager</item>-->
<!-- <item>NetworkSecurityConfig</item>-->
<!-- <item>HwPolicyFactory:</item>-->
<!-- <item>HwWidgetFactory:</item>-->
<!-- <item>HwApiCacheMangerEx</item>-->
<!-- <item>HwWechatOptimizeImpl</item>-->
<!-- <item>HwSplineOverScrollerExImpl</item>-->
<!-- <item>HwAppInnerBoostImpl</item>-->
<!-- <item>HwCustConnectivityManagerImpl</item>-->
<!-- <item>HwApsImpl</item>-->
<!-- <item>HwPhoneWindow</item>-->
<!-- <item>HwAutofillHelper</item>-->
<!-- <item>hwbr_engine_mainprocess</item>-->
<!-- <item>hwbr_engine_hwbr_event</item>-->
<!-- <item>hwbr_engine_PathUtils</item>-->
<!-- <item>hwbr_engine_AwContents</item>-->
<!-- <item>hwbr_engine_cr_IMM</item>-->
<!-- <item>hwbr_engine_LibraryLoader</item>-->
<!-- <item>hwbr_engine_BrowserStartup</item>-->
<!-- <item>hwbr_engine_cr_WebContentsImpl</item>-->
<!-- <item>CrashReport</item>-->
<!-- <item>CrashReportInfo</item>-->
<!-- <item>CrashReport-Native</item>-->
<!-- <item>LeakCanary</item>-->
<!-- <item>Timeline</item>-->
<!-- <item>AssistStructure</item>-->
<!-- <item>EgretLoader</item>-->
<!-- <item>OverScrollerOptimization</item>-->
<!-- <item>HiTouch_PressGestureDetector</item>-->
<!-- <item>HiTouch_HiTouchSensor</item>-->
<!-- <item>FLTAG_SFM</item>-->
<!-- <item>FLTAG_FM</item>-->
<!-- <item>libEGL</item>-->
<!-- <item>AwareLog</item>-->
<!-- <item>AwareBitmapCacher</item>-->
<!-- <item>AwareAppScheduleManager</item>-->
<!-- <item>FeatureFactory</item>-->
<!-- <item>WebViewFactory</item>-->
<!-- <item>ConfigStore</item>-->
<!-- <item>mali_winsys</item>-->
<!-- <item>ZrHung.AppEyeUiProbe</item>-->
<!-- <item>chatty</item>-->
<!-- <item>stylus</item>-->
<!-- <item>libc</item>-->
<!-- <item>chromium</item>-->
<!-- <item>Perf</item>-->
<!-- <item>FeatureParser</item>-->
<!-- <item>Binder:intercep</item>-->
<!-- <item>cr_LibraryLoader</item>-->
<!-- <item>cr_BrowserStartup</item>-->
<!-- <item>DecorView</item>-->
<!-- <item>DecorView[]</item>-->
<!-- <item>ForceDarkHelper</item>-->
<!-- <item>skia</item>-->
<!-- <item>AdrenoGLES-0</item>-->
<!-- <item>ViewContentFactory</item>-->
<!-- <item>MiuiFrameworkFactory</item>-->
<!-- <item>MIUIInput</item>-->
<!-- <item>cr_media</item>-->
<!-- <item>cr_CachingUmaRecorder</item>-->
<!-- <item>TetheringManager</item>-->
<!-- <item>MiuiFreeDragHelper</item>-->
<!-- <item>MiuiFreeDragImpl</item>-->
<!-- <item>ContentProviderMonitor</item>-->
<!-- <item>ContentCatcher</item>-->
<!-- <item>ApplicationLoaders</item>-->
<!-- <item>RenderInspector</item>-->
<!-- </string-array>-->

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Logcat</string>

<!-- <string-array name="logcat_filter_list" tools:ignore="ExtraTranslation">-->
<!-- <item>ActivityThread</item>-->
<!-- <item>InputMethodManager</item>-->
<!-- <item>OpenGLRenderer</item>-->
<!-- <item>VideoCapabilities</item>-->
<!-- <item>ViewRootImpl</item>-->
<!-- <item>Settings</item>-->
<!-- <item>Looper</item>-->
<!-- <item>TextView</item>-->
<!-- <item>TypefaceUtils</item>-->
<!-- <item>MultiDex</item>-->
<!-- <item>AudioManager</item>-->
<!-- <item>ConnectivityManager</item>-->
<!-- <item>NetworkSecurityConfig</item>-->
<!-- <item>HwPolicyFactory:</item>-->
<!-- <item>HwWidgetFactory:</item>-->
<!-- <item>HwApiCacheMangerEx</item>-->
<!-- <item>HwWechatOptimizeImpl</item>-->
<!-- <item>HwSplineOverScrollerExImpl</item>-->
<!-- <item>HwAppInnerBoostImpl</item>-->
<!-- <item>HwCustConnectivityManagerImpl</item>-->
<!-- <item>HwApsImpl</item>-->
<!-- <item>HwPhoneWindow</item>-->
<!-- <item>HwAutofillHelper</item>-->
<!-- <item>hwbr_engine_mainprocess</item>-->
<!-- <item>hwbr_engine_hwbr_event</item>-->
<!-- <item>hwbr_engine_PathUtils</item>-->
<!-- <item>hwbr_engine_AwContents</item>-->
<!-- <item>hwbr_engine_cr_IMM</item>-->
<!-- <item>hwbr_engine_LibraryLoader</item>-->
<!-- <item>hwbr_engine_BrowserStartup</item>-->
<!-- <item>hwbr_engine_cr_WebContentsImpl</item>-->
<!-- <item>CrashReport</item>-->
<!-- <item>CrashReportInfo</item>-->
<!-- <item>CrashReport-Native</item>-->
<!-- <item>LeakCanary</item>-->
<!-- <item>Timeline</item>-->
<!-- <item>AssistStructure</item>-->
<!-- <item>EgretLoader</item>-->
<!-- <item>OverScrollerOptimization</item>-->
<!-- <item>HiTouch_PressGestureDetector</item>-->
<!-- <item>HiTouch_HiTouchSensor</item>-->
<!-- <item>FLTAG_SFM</item>-->
<!-- <item>FLTAG_FM</item>-->
<!-- <item>libEGL</item>-->
<!-- <item>AwareLog</item>-->
<!-- <item>AwareBitmapCacher</item>-->
<!-- <item>AwareAppScheduleManager</item>-->
<!-- <item>FeatureFactory</item>-->
<!-- <item>WebViewFactory</item>-->
<!-- <item>ConfigStore</item>-->
<!-- <item>mali_winsys</item>-->
<!-- <item>ZrHung.AppEyeUiProbe</item>-->
<!-- <item>chatty</item>-->
<!-- <item>stylus</item>-->
<!-- <item>libc</item>-->
<!-- <item>chromium</item>-->
<!-- <item>Perf</item>-->
<!-- <item>FeatureParser</item>-->
<!-- <item>Binder:intercep</item>-->
<!-- <item>cr_LibraryLoader</item>-->
<!-- <item>cr_BrowserStartup</item>-->
<!-- <item>DecorView</item>-->
<!-- <item>DecorView[]</item>-->
<!-- <item>ForceDarkHelper</item>-->
<!-- <item>skia</item>-->
<!-- <item>AdrenoGLES-0</item>-->
<!-- <item>ViewContentFactory</item>-->
<!-- <item>MiuiFrameworkFactory</item>-->
<!-- <item>MIUIInput</item>-->
<!-- <item>cr_media</item>-->
<!-- <item>cr_CachingUmaRecorder</item>-->
<!-- <item>TetheringManager</item>-->
<!-- <item>MiuiFreeDragHelper</item>-->
<!-- <item>MiuiFreeDragImpl</item>-->
<!-- <item>ContentProviderMonitor</item>-->
<!-- <item>ContentCatcher</item>-->
<!-- <item>ApplicationLoaders</item>-->
<!-- <item>RenderInspector</item>-->
<!-- </string-array>-->

</resources>
25 changes: 13 additions & 12 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- 解决 Android 5.1 及以上版本 Button 英文字符串自动变大写的问题 -->
<item name="android:textAllCaps">false</item>
</style>

<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- 解决 Android 5.1 及以上版本 Button 英文字符串自动变大写的问题 -->
<item name="android:textAllCaps">false</item>
</style>

</resources>
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {

defaultConfig {
minSdkVersion 16
versionCode 1000
versionName "10.0"
versionCode 1020
versionName "10.2"
}

lintOptions {
Expand Down
9 changes: 7 additions & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hjq.logcat">

<!-- 外部存储读写权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- 前台 Service 权限 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application>

<provider
Expand All @@ -15,9 +19,10 @@

<activity
android:name=".LogcatActivity"
android:windowSoftInputMode="stateHidden"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleInstance" />
android:launchMode="singleInstance"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateHidden" />

<service android:name=".LogcatService" />

Expand Down
Loading

0 comments on commit 62e3293

Please sign in to comment.