Skip to content

Commit

Permalink
升级 XToast 框架版本
Browse files Browse the repository at this point in the history
优化搜索输入框文本焦点
删除 Logcat 横屏限制
优化 Logcat 在竖屏显示效果
  • Loading branch information
getActivity committed Aug 5, 2021
1 parent c605246 commit 3454380
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 57 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 日志调试框架
# 日志查看框架

* 码云地址:[Gitee](https://gitee.com/getActivity/Logcat)
* 项目地址:[Github](https://github.com/getActivity/Logcat)[码云](https://gitee.com/getActivity/Logcat)

* [点击此处下载Demo](Logcat.apk)

Expand All @@ -10,11 +10,12 @@

```groovy
buildscript {
......
repositories {
maven { url 'https://jitpack.io' }
}
}
allprojects {
repositories {
// JitPack 远程仓库:https://jitpack.io
maven { url 'https://jitpack.io' }
}
}
Expand All @@ -25,7 +26,7 @@ allprojects {
```groovy
dependencies {
// 日志调试框架:https://github.com/getActivity/Logcat
debugImplementation 'com.github.getActivity:Logcat:9.6'
debugImplementation 'com.github.getActivity:Logcat:9.8'
}
```

Expand Down Expand Up @@ -100,6 +101,8 @@ dependencies {

* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)

* Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView)

* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)

#### 微信公众号:Android轮子哥
Expand Down
13 changes: 7 additions & 6 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 30
versionCode 96
versionName "9.6"
versionCode 98
versionName "9.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand All @@ -30,12 +30,13 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
debugImplementation project(':library')

// 谷歌兼容库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// AppCompat 库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
implementation 'androidx.appcompat:appcompat:1.3.0'
// Material 库:https://github.com/material-components/material-components-android
implementation 'com.google.android.material:material:1.3.0'

// 标题栏:https://github.com/getActivity/TitleBar
implementation 'com.github.getActivity:TitleBar:8.5'
implementation 'com.github.getActivity:TitleBar:8.6'

// 内存泄漏捕捉:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {
maven { url 'https://jitpack.io' }
mavenCentral()
google()
// noinspection JcenterRepositoryObsolete
jcenter()
}
dependencies {
Expand All @@ -24,6 +25,7 @@ allprojects {
maven { url 'https://jitpack.io' }
mavenCentral()
google()
// noinspection JcenterRepositoryObsolete
jcenter()
}
}
Expand Down
21 changes: 17 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@ android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 14
versionCode 96
versionName "9.6"
minSdkVersion 16
versionCode 98
versionName "9.8"
}

lintOptions {
abortOnError false
}

android.libraryVariants.all { variant ->
// aar 输出文件名配置
variant.outputs.all { output ->
outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
}
}
}

afterEvaluate {
// 排除 BuildConfig.class
generateReleaseBuildConfig.enabled = false
generateDebugBuildConfig.enabled = false
}

dependencies {
// 悬浮窗框架:https://github.com/getActivity/XToast
implementation 'com.github.getActivity:XToast:6.9'
implementation 'com.github.getActivity:XToast:8.1'
}

tasks.withType(Javadoc) {
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<activity
android:name=".LogcatActivity"
android:windowSoftInputMode="stateHidden"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleInstance"
android:screenOrientation="landscape" />
android:launchMode="singleInstance" />

</application>

Expand Down
15 changes: 9 additions & 6 deletions library/src/main/java/com/hjq/logcat/LogcatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
* time : 2020/01/24
* desc : Logcat 显示窗口
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public final class LogcatActivity extends Activity
implements TextWatcher, View.OnLongClickListener, View.OnClickListener,
CompoundButton.OnCheckedChangeListener, LogcatManager.Callback,
AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {

public static final Charset CHARSET_UTF_8 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? StandardCharsets.UTF_8 : Charset.forName("UTF-8");

private final static String[] ARRAY_LOG_LEVEL = {"Verbose", "Debug", "Info", "Warn", "Error"};

private final static String FILE_TYPE = "Logcat";
Expand Down Expand Up @@ -120,7 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void run() {
mListView.setSelection(mAdapter.getCount() - 1);
}
}, 1000);
}, 500);

initFilter();
}
Expand Down Expand Up @@ -352,8 +355,7 @@ private void initFilter() {
if (file.exists() && file.isFile()) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? StandardCharsets.UTF_8 : Charset.forName("UTF-8")));
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CHARSET_UTF_8));
String tag;
while ((tag = reader.readLine()) != null) {
mTagFilter.add(tag);
Expand Down Expand Up @@ -384,8 +386,7 @@ private void addFilter(String tag) {
if (!file.exists()) {
file.createNewFile();
}
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? StandardCharsets.UTF_8 : Charset.forName("UTF-8")));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), CHARSET_UTF_8));
for (String temp : mTagFilter) {
writer.write(temp + "\r\n");
}
Expand Down Expand Up @@ -437,7 +438,7 @@ private void saveLogToFile() {
if (!file.exists()) {
file.createNewFile();
}
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), Charset.forName("UTF-8")));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), CHARSET_UTF_8));
List<LogcatInfo> data = mAdapter.getData();
for (LogcatInfo info : data) {
writer.write(info.toString().replace("\n", "\r\n") + "\r\n\r\n");
Expand Down Expand Up @@ -476,6 +477,8 @@ private void toast(CharSequence text) {

@Override
public void onBackPressed() {
// 清除输入焦点
mSearchView.clearFocus();
// 移动到上一个任务栈
moveTaskToBack(false);
}
Expand Down
20 changes: 3 additions & 17 deletions library/src/main/java/com/hjq/logcat/LogcatAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ void removeItem(int position) {
notifyDataSetChanged();
}

void removeItem(LogcatInfo item) {
mDataSet.remove(item);
notifyDataSetChanged();
}

/**
* 清空当前数据
*/
Expand Down Expand Up @@ -172,23 +167,14 @@ private void onBindView(LogcatInfo info, int position) {
mLineView.setVisibility((position == getCount() - 1) ? View.GONE : View.VISIBLE);

if (mContentView.getLineCount() - MAX_LINE > 1) {

if (mExpandSet.get(position)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (mContentView.getMaxLines() != Integer.MAX_VALUE) {
mContentView.setMaxLines(Integer.MAX_VALUE);
mExpandView.setImageResource(R.drawable.logcat_ic_arrows_up);
}
} else {
if (mContentView.getMaxLines() != Integer.MAX_VALUE) {
mContentView.setMaxLines(Integer.MAX_VALUE);
mExpandView.setImageResource(R.drawable.logcat_ic_arrows_up);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (mContentView.getMaxLines() != MAX_LINE) {
mContentView.setMaxLines(MAX_LINE);
mExpandView.setImageResource(R.drawable.logcat_ic_arrows_down);
}
} else {
if (mContentView.getMaxLines() != MAX_LINE) {
mContentView.setMaxLines(MAX_LINE);
mExpandView.setImageResource(R.drawable.logcat_ic_arrows_down);
}
Expand Down
34 changes: 17 additions & 17 deletions library/src/main/res/layout/logcat_window_logcat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
android:id="@+id/iv_log_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:button="@drawable/logcat_bg_log_check"
android:checked="false" />

<ImageView
android:id="@+id/iv_log_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/logcat_ic_save" />

<TextView
android:id="@+id/tv_log_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/logcat_bg_log_frame"
android:drawableStart="@drawable/logcat_ic_filter"
android:drawableLeft="@drawable/logcat_ic_filter"
Expand All @@ -48,19 +48,19 @@
android:paddingBottom="8dp"
android:text="Verbose"
android:textColor="@android:color/white"
android:textSize="14sp" />
android:textSize="13sp" />

<FrameLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1">

<EditText
android:id="@+id/et_log_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/logcat_bg_log_frame"
android:cursorVisible="true"
android:drawableStart="@drawable/logcat_ic_search"
Expand All @@ -87,10 +87,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/logcat_ic_empty"
android:visibility="gone"
tools:visibility="visible" />
Expand All @@ -101,16 +101,16 @@
android:id="@+id/iv_log_clean"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/logcat_ic_clear" />

<ImageView
android:id="@+id/iv_log_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/logcat_ic_close" />

</LinearLayout>
Expand Down

0 comments on commit 3454380

Please sign in to comment.