Skip to content

Commit

Permalink
适配 Android 11
Browse files Browse the repository at this point in the history
  • Loading branch information
getActivity committed Oct 11, 2020
1 parent eefd143 commit c7b92f3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 49 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#### 集成步骤

dependencies {
debugImplementation 'com.hjq:logcat:8.2'
}
```groovy
dependencies {
debugImplementation 'com.hjq:logcat:8.6'
}
```

#### 使用方式

Expand Down Expand Up @@ -40,12 +42,14 @@

> 在项目的 `values/color.xml` 中加入你喜欢的配色,例如
<color name="logcat_level_verbose_color">#FFBBBBBB</color>
<color name="logcat_level_debug_color">#FF33B5E5</color>
<color name="logcat_level_info_color">#FF99CC00</color>
<color name="logcat_level_warn_color">#FFFFBB33</color>
<color name="logcat_level_error_color">#FFFF4444</color>
<color name="logcat_level_other_color">#FFFFFFFF</color>
```xml
<color name="logcat_level_verbose_color">#FFBBBBBB</color>
<color name="logcat_level_debug_color">#FF33B5E5</color>
<color name="logcat_level_info_color">#FF99CC00</color>
<color name="logcat_level_warn_color">#FFFFBB33</color>
<color name="logcat_level_error_color">#FFFF4444</color>
<color name="logcat_level_other_color">#FFFFFFFF</color>
```

#### 框架亮点

Expand All @@ -67,7 +71,7 @@

#### 作者的其他开源项目

* 架构工程[AndroidProject](https://github.com/getActivity/AndroidProject)
* 安卓架构[AndroidProject](https://github.com/getActivity/AndroidProject)

* 网络框架:[EasyHttp](https://github.com/getActivity/EasyHttp)

Expand Down
17 changes: 9 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 30

defaultConfig {
applicationId "com.hjq.logcat.demo"
minSdkVersion 14
targetSdkVersion 28
versionCode 82
versionName "8.2"
targetSdkVersion 30
versionCode 86
versionName "8.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -23,11 +23,12 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
debugImplementation project(':library')

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
// 谷歌兼容库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'com.google.android.material:material:1.3.0-alpha02'

// 标题栏:https://github.com/getActivity/TitleBar
implementation 'com.hjq:titlebar:6.5'
implementation 'com.hjq:titlebar:8.0'
// 内存泄漏捕捉:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
}
11 changes: 6 additions & 5 deletions app/src/main/java/com/hjq/logcat/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;

import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

Expand Down Expand Up @@ -62,21 +63,21 @@ public void onRightClick(View v) {

@Override
public void onResume() {
super.onResume();
mWebView.onResume();
mWebView.resumeTimers();
super.onResume();
}

@Override
public void onPause() {
super.onPause();
mWebView.onPause();
mWebView.pauseTimers();
super.onPause();
}

@Override
protected void onDestroy() {
((ViewGroup) mWebView.getParent()).removeView(mWebView);
super.onDestroy();
//清除历史记录
mWebView.clearHistory();
//停止加载
Expand All @@ -89,6 +90,6 @@ protected void onDestroy() {
mWebView.removeAllViews();
//销毁此的WebView的内部状态
mWebView.destroy();
super.onDestroy();
((ViewGroup) mWebView.getParent()).removeView(mWebView);
}
}
14 changes: 7 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ android {

resourcePrefix "logcat_"

compileSdkVersion 26
compileSdkVersion 30

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 82
versionName "8.2"
targetSdkVersion 30
versionCode 86
versionName "8.6"
}
}

dependencies {
// 权限请求框架:https://github.com/getActivity/XXPermissions
implementation 'com.hjq:xxpermissions:6.5'
implementation 'com.hjq:xxpermissions:8.8'
// 悬浮窗框架:https://github.com/getActivity/XToast
implementation 'com.hjq:xtoast:5.5'
implementation 'com.hjq:xtoast:6.0'
}

publish {
userOrg = 'getactivity'
groupId = 'com.hjq'
artifactId = 'logcat'
version = '8.2'
version = '8.6'
description = 'This is to help developers quickly see the logging framework they want'
website = "https://github.com/getActivity/Logcat"
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package="com.hjq.logcat">

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

Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/hjq/logcat/ChooseWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ChooseWindow extends XToast implements AdapterView.OnItemClickListen
super(activity);
setView(R.layout.logcat_window_choose);
setGravity(Gravity.CENTER);
removeWindowFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
clearWindowFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

ListView listView = (ListView) findViewById(R.id.lv_choose_list);
mAdapter = new ChooseAdapter();
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/java/com/hjq/logcat/FloatingLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (activity instanceof LogcatActivity) {
return;
}
new FloatingWindow(activity).show();
new FloatingWindow(activity)
.show();
}

@Override
Expand Down
36 changes: 20 additions & 16 deletions library/src/main/java/com/hjq/logcat/LogcatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,19 @@ public void onSelected(final int location) {
break;
case 3:
XXPermissions.with(LogcatActivity.this)
.permission(Permission.Group.STORAGE)
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
.request(new OnPermission() {
@Override
public void hasPermission(List<String> granted, boolean isAll) {
addFilter(mAdapter.getItem(position).getTag());
public void hasPermission(List<String> granted, boolean all) {
if (all) {
addFilter(mAdapter.getItem(position).getTag());
}
}

@Override
public void noPermission(List<String> denied, boolean quick) {
if (quick) {
XXPermissions.startPermissionActivity(LogcatActivity.this);
public void noPermission(List<String> denied, boolean never) {
if (never) {
XXPermissions.startPermissionActivity(LogcatActivity.this, denied);
toast("请授予存储权限之后再操作");
}
}
Expand Down Expand Up @@ -224,17 +226,19 @@ public boolean onLongClick(View v) {
public void onClick(View v) {
if (v == mSaveView) {
XXPermissions.with(this)
.permission(Permission.Group.STORAGE)
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
.request(new OnPermission() {
@Override
public void hasPermission(List<String> granted, boolean isAll) {
saveLogToFile();
public void hasPermission(List<String> granted, boolean all) {
if (all) {
saveLogToFile();
}
}

@Override
public void noPermission(List<String> denied, boolean quick) {
if (quick) {
XXPermissions.startPermissionActivity(LogcatActivity.this);
public void noPermission(List<String> denied, boolean never) {
if (never) {
XXPermissions.startPermissionActivity(LogcatActivity.this, denied);
toast("请授予存储权限之后再操作");
}
}
Expand Down Expand Up @@ -385,7 +389,7 @@ public void run() {
*/
private void initFilter() {
File file = new File(LOG_DIRECTORY, LOGCAT_TAG_FILTER_FILE);
if (file.exists() && file.isFile() && XXPermissions.hasPermission(this, Permission.Group.STORAGE)) {
if (file.exists() && file.isFile() && XXPermissions.hasPermission(this, Permission.MANAGE_EXTERNAL_STORAGE)) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
Expand Down Expand Up @@ -514,19 +518,19 @@ public void onBackPressed() {

@Override
protected void onResume() {
LogcatManager.resume();
super.onResume();
LogcatManager.resume();
}

@Override
protected void onPause() {
LogcatManager.pause();
super.onPause();
LogcatManager.pause();
}

@Override
protected void onDestroy() {
LogcatManager.destroy();
super.onDestroy();
LogcatManager.destroy();
}
}
3 changes: 2 additions & 1 deletion library/src/main/res/layout/logcat_window_logcat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
android:layout_gravity="end|bottom"
android:layout_margin="20dp"
android:background="@drawable/logcat_bg_log_roll"
android:src="@drawable/logcat_ic_down" />
android:src="@drawable/logcat_ic_down"
android:translationZ="10dp" />
</FrameLayout>

</LinearLayout>

0 comments on commit c7b92f3

Please sign in to comment.