Skip to content

Commit

Permalink
优化细节
Browse files Browse the repository at this point in the history
  • Loading branch information
880634 committed Jan 30, 2020
1 parent 4bfffc9 commit 42a5288
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 41 deletions.
Binary file modified Logcat.apk
Binary file not shown.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#### 集成步骤

dependencies {
debugImplementation 'com.hjq:logcat:3.0'
debugImplementation 'com.hjq:logcat:3.2'
}

#### 使用方式

* 在 debug 模式下运行即可,在 release 正式打包的时不会自动集成

#### 截图欣赏

![](picture/1.jpg)
Expand All @@ -24,17 +28,32 @@

![](picture/6.jpg)

![](picture/7.jpg)

#### 日志颜色个性化

> 在项目的 `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>

#### 框架亮点

* 支持日志捕捉开关功能
* 只需集成,无需调用

* 日志长按可复制分享

* 支持日志内容拼接功能
* 长日志点击可收缩展开显示

* 支持日志内容收缩展开
* 日志搜索结果支持文本高亮

* 支持日志复制分享功能
* 多个相同 TAG 日志自动合并显示

* 支持日志搜索文本高亮
* 仅在 Debug 下集成,无需手动初始化

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

Expand Down
7 changes: 5 additions & 2 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 14
targetSdkVersion 28
versionCode 30
versionName "3.0"
versionCode 32
versionName "3.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -25,4 +25,7 @@ dependencies {

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

// 标题栏:https://github.com/getActivity/TitleBar
implementation 'com.hjq:titlebar:6.0'
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme"
tools:targetApi="n">

<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
Expand Down
77 changes: 76 additions & 1 deletion app/src/main/java/com/hjq/logcat/demo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,94 @@
package com.hjq.logcat.demo;

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;

public class MainActivity extends AppCompatActivity {
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

public class MainActivity extends AppCompatActivity implements OnTitleBarListener {

private TitleBar mTitleBar;
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mTitleBar = findViewById(R.id.tb_main_title);
mTitleBar.setOnTitleBarListener(this);

mWebView = findViewById(R.id.wv_main_web);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.loadUrl("https://github.com/getActivity/Logcat");
}

private class MyWebChromeClient extends WebChromeClient {

@Override
public void onReceivedTitle(WebView view, String title) {
mTitleBar.setTitle(title);
}
}

@Override
public void onLeftClick(View v) {

}

@Override
public void onTitleClick(View v) {
String url = mWebView.getUrl();
if (url != null && !"".equals(url)) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}

@Override
public void onRightClick(View v) {

}

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

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

@Override
protected void onDestroy() {
((ViewGroup) mWebView.getParent()).removeView(mWebView);
//清除历史记录
mWebView.clearHistory();
//停止加载
mWebView.stopLoading();
//加载一个空白页
mWebView.loadUrl("about:blank");
mWebView.setWebChromeClient(null);
mWebView.setWebViewClient(null);
//移除WebView所有的View对象
mWebView.removeAllViews();
//销毁此的WebView的内部状态
mWebView.destroy();
super.onDestroy();
}
}
43 changes: 43 additions & 0 deletions app/src/main/res/drawable/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="1024"
android:viewportHeight="1024">

<path
android:fillColor="#AED796"
android:pathData="M112 16h736v992H112z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M320 640h320v256H320z" />
<path
android:fillColor="#F48284"
android:pathData="M320 544h320v96H320z" />
<path
android:fillColor="#2B3139"
android:pathData="M896 128h-32V32a32 32 0 0 0-32-32H128a32 32 0 0 0-32 32v960a32 32 0 0 0 32
32h704a32 32 0 0 0 32-32V416h32a32 32 0 0 0 32-32V160a32 32 0 0 0-32-32z m-64
0H448a32 32 0 0 0-32 32v224a32 32 0 0 0 32 32h384v576H128V32h704v96zM560
720H400a16 16 0 1 0 0 32h160a16 16 0 1 0 0-32zM336 912h288a32 32 0 0 0
32-32V560a32 32 0 0 0-32-32h-32v-16a16 16 0 1 0-32 0v16h-32v-16a16 16 0 1 0-32
0v16h-32v-16a16 16 0 1 0-32 0v16h-32v-16a16 16 0 1 0-32 0v16h-32a32 32 0 0 0-32
32v320a32 32 0 0 0 32 32z m0-352h32v16a16 16 0 1 0 32 0v-16h32v16a16 16 0 1 0 32
0v-16h32v16a16 16 0 1 0 32 0v-16h32v16a16 16 0 1 0 32 0v-16h32v64H336v-64z m0
96h288v224H336V656z m224 128H400a16 16 0 1 0 0 32h160a16 16 0 1 0 0-32z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M448 160h448v224H448z" />
<path
android:fillColor="#2B3139"
android:pathData="M499.472 213.824h35.184v84.912h50.528V328h-85.712v-114.176zM654.8 211.104c34.704
0 57.888 24.944 57.888 59.792s-23.184 59.808-57.888
59.808-57.888-24.96-57.888-59.808 23.184-59.792 57.888-59.792z m0 91.152c8.96 0
22.704-5.904 22.704-31.344 0-25.424-13.744-31.344-22.704-31.344s-22.704
5.92-22.704 31.344 13.744 31.344 22.704 31.344zM811.264 316.336c-7.84 10.08-20
14.384-32.464 14.384-33.728 0-54.528-26.224-54.528-58.688 0-43.504 30.544-60.928
56.304-60.928 29.088 0 47.488 15.824 52.608
42.688h-33.744c-1.28-8.32-8.32-14.24-16.624-14.24-24.16 0-23.344 25.44-23.344
33.264 0 10.72 4.32 29.424 25.728 29.424 8.16 0 16.48-4.16
18.24-12.624h-15.52v-24.464h46.704V328h-22.24l-1.12-11.664z" />
</vector>
24 changes: 19 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/wv_main_web"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
tools:context=".MainActivity" />
android:orientation="vertical">

<com.hjq.bar.TitleBar
android:id="@+id/tb_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backButton="false"
app:title="Logcat" />

<WebView
android:id="@+id/wv_main_web"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
tools:context=".MainActivity" />

</LinearLayout>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 30
versionName "3.0"
versionCode 32
versionName "3.2"
}
}

Expand All @@ -26,7 +26,7 @@ publish {
userOrg = 'getactivity'
groupId = 'com.hjq'
artifactId = 'logcat'
version = '3.0'
version = '3.2'
description = 'This is to help developers quickly see the logging framework they want'
website = "https://github.com/getActivity/Logcat"
}
Expand Down
6 changes: 2 additions & 4 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

<activity
android:name=".InitActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleTop"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity
android:name=".LogcatActivity"
Expand Down
10 changes: 2 additions & 8 deletions library/src/main/java/com/hjq/logcat/FloatingWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ final class FloatingWindow extends XToast implements OnClickListener {

@Override
public void onClick(XToast toast, View view) {
postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getContext(), LogcatActivity.class);
startActivity(intent);
cancel();
}
}, 500);
startActivity(new Intent(getContext(), LogcatActivity.class));
cancel();
}
}
1 change: 1 addition & 0 deletions library/src/main/java/com/hjq/logcat/InitActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void hasPermission(List<String> granted, boolean all) {
LogcatConfig.init(getApplication());
FloatingLifecycle.with(getApplication(), new FloatingWindow(getApplication()).show());
finish();
}
Expand Down
1 change: 0 additions & 1 deletion library/src/main/java/com/hjq/logcat/InitProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public final class InitProvider extends ContentProvider {
public boolean onCreate() {
Context context = getContext();
if (context != null) {
LogcatConfig.init(context.getApplicationContext());
Intent intent = new Intent(context, InitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/hjq/logcat/LogcatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
mSwitchView.setOnCheckedChangeListener(this);
mSearchView.addTextChangedListener(this);

mSearchView.setText(LogcatConfig.getLogcatKeyword());
mSearchView.setText(LogcatConfig.getLogcatText());
setLogLevel(LogcatConfig.getLogcatLevel());

mLevelView.setOnClickListener(this);
Expand Down Expand Up @@ -209,7 +209,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
String keyword = s.toString().trim();
LogcatConfig.setLogcatKeyword(keyword);
LogcatConfig.setLogcatText(keyword);
mAdapter.setKeyword(keyword);
mAdapter.clearData();
for (LogcatInfo info : mLogData) {
Expand Down
15 changes: 8 additions & 7 deletions library/src/main/java/com/hjq/logcat/LogcatConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hjq.logcat;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

Expand All @@ -16,8 +17,8 @@ final class LogcatConfig {
/**
* 初始化
*/
static void init(Context context) {
sConfig = context.getSharedPreferences("logcat", Context.MODE_PRIVATE);
static void init(Application application) {
sConfig = application.getSharedPreferences("logcat", Context.MODE_PRIVATE);
}

/**
Expand All @@ -36,13 +37,13 @@ static void setLogcatLevel(String level) {
/**
* 搜索关键字
*/
private static final String LOGCAT_KEYWORD = "logcat_keyword";
private static final String LOGCAT_TEXT = "logcat_text";

static String getLogcatKeyword() {
return sConfig.getString(LOGCAT_KEYWORD, "");
static String getLogcatText() {
return sConfig.getString(LOGCAT_TEXT, "");
}

static void setLogcatKeyword(String keyword) {
sConfig.edit().putString(LOGCAT_KEYWORD, keyword).apply();
static void setLogcatText(String keyword) {
sConfig.edit().putString(LOGCAT_TEXT, keyword).apply();
}
}
3 changes: 3 additions & 0 deletions library/src/main/res/layout/logcat_window_logcat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@
android:layout_height="match_parent"
android:background="#2b2b2b"
android:dividerHeight="0px"
android:fadeScrollbars="true"
android:scrollbarSize="1dp"
android:scrollbarThumbVertical="@color/logcat_scrollbar_thumb_color"
android:scrollbars="vertical"
android:verticalScrollbarPosition="left"
tools:listitem="@layout/logcat_item_logcat" />

</LinearLayout>
Binary file modified picture/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified picture/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added picture/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 42a5288

Please sign in to comment.