├── .idea
├── .name
├── dictionaries
│ └── Mike.xml
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── gn
│ │ │ └── mylogcat
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── gn
│ │ │ └── mylogcat
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── gn
│ │ └── mylogcat
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── mylogcatlibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ └── icon.png
│ │ │ ├── values
│ │ │ │ ├── themes.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-v14
│ │ │ │ └── themes.xml
│ │ │ ├── values-v21
│ │ │ │ └── themes.xml
│ │ │ └── layout
│ │ │ │ ├── log.xml
│ │ │ │ ├── entry.xml
│ │ │ │ ├── filter_dialog.xml
│ │ │ │ └── prefs.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── gn
│ │ │ │ └── logcatlibrary
│ │ │ │ ├── SaveService.java
│ │ │ │ ├── ALogcatApplication.java
│ │ │ │ ├── SaveReceiver.java
│ │ │ │ ├── ShareReceiver.java
│ │ │ │ ├── Intent.java
│ │ │ │ ├── Textsize.java
│ │ │ │ ├── BackgroundColor.java
│ │ │ │ ├── Buffer.java
│ │ │ │ ├── LogEntry.java
│ │ │ │ ├── Lock.java
│ │ │ │ ├── Level.java
│ │ │ │ ├── ShareService.java
│ │ │ │ ├── LogEntryAdapter.java
│ │ │ │ ├── LogSaver.java
│ │ │ │ ├── LogDumper.java
│ │ │ │ ├── Format.java
│ │ │ │ ├── PrefsActivity.java
│ │ │ │ ├── Prefs.java
│ │ │ │ ├── Logcat.java
│ │ │ │ ├── FilterDialog.java
│ │ │ │ └── LogActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── gn
│ │ │ └── logcatlibrary
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── gn
│ │ └── logcatlibrary
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | MyLogCat
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mylogcatlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':mylogcatlibrary'
2 |
--------------------------------------------------------------------------------
/.idea/dictionaries/Mike.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyLogCat
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/mylogcatlibrary/src/main/res/drawable/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaoneng102/MyLogCat/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/values-v14/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/values-v21/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/layout/log.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/layout/entry.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/gn/mylogcat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.gn.mylogcat;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/mylogcatlibrary/src/test/java/com/gn/logcatlibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/gn/mylogcat/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.gn.mylogcat;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/androidTest/java/com/gn/logcatlibrary/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/SaveService.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.IntentService;
4 | import android.content.Intent;
5 |
6 | public class SaveService extends IntentService {
7 | public SaveService() {
8 | super("saveService");
9 | }
10 |
11 | @Override
12 | protected void onHandleIntent(Intent intent) {
13 | //Log.d("alogcat", "handling intent");
14 |
15 | LogSaver saver = new LogSaver(this);
16 | saver.save();
17 |
18 | Lock.release();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MyLogCat
2 | ======
3 | MyLogCat 是在安卓手机上查看日志的库,这种实时查看日志的方式,可以快速定位测试人员或者用户反馈的错误问题。
4 |
5 | ## 特点:
6 | 1. 支持Androd 2.3以上系统
7 | 2. 无需root权限
8 | 3. 不同级别的日志显示不同的颜色
9 | 4. 可以过滤各种层级的log日志
10 | 5. 根据正则去匹配tag的日志
11 | 6. 保存,分享,清空当前输出日志
12 |
13 | ## 使用:
14 | ```
15 | dependencies {
16 | compile 'com.gn.logcatlibrary:mylogcatlibrary:1.0.2'
17 | }
18 | ```
19 |
20 | ## 原理:
21 |
22 | 请参见源码https://code.google.com/archive/p/alogcat/
23 |
24 |
25 | ## 支持:
26 | 任何问题可以在项目中提交bug报告,也可以发送邮件到gaoneng1850@gmail.com
27 |
28 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/ALogcatApplication.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.Application;
4 | import android.os.StrictMode;
5 |
6 | public class ALogcatApplication extends Application {
7 | private static final boolean DEBUG = false;
8 |
9 | @Override
10 | public void onCreate() {
11 | super.onCreate();
12 | if (DEBUG) {
13 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
14 | .detectAll().penaltyLog().build());
15 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
16 | .detectAll().penaltyLog().penaltyDeath().build());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/SaveReceiver.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | public class SaveReceiver extends BroadcastReceiver {
8 |
9 | @Override
10 | public void onReceive(Context context, Intent intent) {
11 | //Log.d("alogcat", "received intent for save");
12 |
13 | com.gn.logcatlibrary.Intent.handleExtras(context, intent);
14 |
15 | Lock.acquire(context);
16 |
17 | Intent svcIntent = new Intent(context, SaveService.class);
18 | context.startService(svcIntent);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/ShareReceiver.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | public class ShareReceiver extends BroadcastReceiver {
8 |
9 | @Override
10 | public void onReceive(Context context, Intent intent) {
11 | //Log.d("alogcat", "received intent for share");
12 |
13 | com.gn.logcatlibrary.Intent.handleExtras(context, intent);
14 |
15 | Lock.acquire(context);
16 |
17 | Intent svcIntent = new Intent(context, ShareService.class);
18 | context.startService(svcIntent);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/mylogcatlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Tue Mar 08 16:55:00 CST 2016
16 | systemProp.http.proxyHost=127.0.0.1
17 | systemProp.http.proxyPort=1080
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.demos.mylogcat"
9 | minSdkVersion 9
10 | targetSdkVersion 21
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | lintOptions {
21 | abortOnError false
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:appcompat-v7:22.1.0'
30 | // debugCompile project (':mylogcatlibrary')
31 | compile 'com.gn.logcatlibrary:mylogcatlibrary:1.0.1'
32 | }
33 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Intent.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 |
5 | public class Intent {
6 | static final String START_INTENT = "org.jtb.alogcat.intent.START";
7 | static final String SAVE_INTENT = "org.jtb.alogcat.intent.SAVE";
8 | static final String SHARE_INTENT = "org.jtb.alogcat.intent.SHARE";
9 |
10 | static final String EXTRA_FILTER = "FILTER";
11 | static final String EXTRA_LEVEL = "LEVEL";
12 | static final String EXTRA_FREQUENCY = "FREQUENCY";
13 | static final String EXTRA_START_RECORD = "START_WRITE";
14 | static final String EXTRA_STOP_RECORD = "STOP_WRITE";
15 |
16 | static void handleExtras(Context context, android.content.Intent intent) {
17 | Prefs prefs = new Prefs(context);
18 | String filter = intent.getStringExtra(EXTRA_FILTER);
19 | if (filter != null) {
20 | prefs.setFilter(filter);
21 | }
22 | String l = intent.getStringExtra(EXTRA_LEVEL);
23 | if (l != null) {
24 | Level level = Level.valueOf(l);
25 | prefs.setLevel(level);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Textsize.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.util.SparseArray;
5 |
6 | public enum Textsize {
7 | SMALL(8, R.string.small_title),
8 | MEDIUM(10, R.string.medium_title),
9 | LARGE(12, R.string.large_title);
10 |
11 | private static Textsize[] byOrder = new Textsize[3];
12 |
13 | static {
14 | byOrder[0] = SMALL;
15 | byOrder[1] = MEDIUM;
16 | byOrder[2] = LARGE;
17 | }
18 |
19 | private static final SparseArray VALUE_MAP = new SparseArray();
20 |
21 | static {
22 | VALUE_MAP.put(SMALL.mValue, SMALL);
23 | VALUE_MAP.put(MEDIUM.mValue, MEDIUM);
24 | VALUE_MAP.put(LARGE.mValue, LARGE);
25 | }
26 |
27 | private Integer mValue;
28 | private int mTitleId;
29 |
30 | private Textsize(Integer value, int titleId) {
31 | mValue = value;
32 | mTitleId = titleId;
33 | }
34 |
35 | public String getTitle(Context context) {
36 | return context.getResources().getString(mTitleId);
37 | }
38 |
39 | public static Textsize getByOrder(int order) {
40 | return byOrder[order];
41 | }
42 |
43 | public Integer getValue() {
44 | return mValue;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/BackgroundColor.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /**
10 | * 背景色枚举类
11 | */
12 | public enum BackgroundColor {
13 | BLACK(R.string.black_title, "#000000"), WHITE(R.string.white_title,
14 | "#ffffff"), GRAY(R.string.gray_title, "#bbbbbb");
15 |
16 | private static final Map byHexColor;
17 |
18 | static {
19 | byHexColor = new HashMap() {
20 | {
21 | put("#000000", BLACK);
22 | put("#ffffff", WHITE);
23 | put("#bbbbbb", GRAY);
24 | }
25 | };
26 | }
27 |
28 | private String mHexColor;
29 | private int mId;
30 |
31 | private BackgroundColor(int id, String hexColor) {
32 | mId = id;
33 | mHexColor = hexColor;
34 | }
35 |
36 | public static BackgroundColor valueOfHexColor(String hexColor) {
37 | return byHexColor.get(hexColor);
38 | }
39 |
40 | public int getColor() {
41 | return Color.parseColor(mHexColor);
42 | }
43 |
44 | public String getTitle(Context context) {
45 | return context.getResources().getString(mId);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Buffer.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.HashMap;
6 |
7 | public enum Buffer {
8 | MAIN("main", R.string.main_title),
9 | EVENTS("events", R.string.events_title),
10 | RADIO("radio", R.string.radio_title);
11 |
12 | private static Buffer[] byOrder = new Buffer[3];
13 |
14 | static {
15 | byOrder[0] = MAIN;
16 | byOrder[1] = EVENTS;
17 | byOrder[2] = RADIO;
18 | }
19 |
20 | private static final HashMap VALUE_MAP = new HashMap();
21 |
22 | static {
23 | VALUE_MAP.put(MAIN.mValue, MAIN);
24 | VALUE_MAP.put(EVENTS.mValue, EVENTS);
25 | VALUE_MAP.put(RADIO.mValue, RADIO);
26 | }
27 |
28 | private String mValue;
29 | private int mTitleId;
30 |
31 | private Buffer(String value, int titleId) {
32 | mValue = value;
33 | mTitleId = titleId;
34 | }
35 |
36 | public String getTitle(Context context) {
37 | return context.getResources().getString(mTitleId);
38 | }
39 |
40 | public static final Buffer byValue(String value) {
41 | return VALUE_MAP.get(value);
42 | }
43 |
44 | public static Buffer getByOrder(int order) {
45 | return byOrder[order];
46 | }
47 |
48 | public String getValue() {
49 | return mValue;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/LogEntry.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | /**
4 | * 日志输出的实体类
5 | */
6 | public class LogEntry {
7 | private Level level = Level.V;
8 | private String text = null;
9 | private Integer hash = null;
10 |
11 | public LogEntry(String text, Level level) {
12 | this.text = text;
13 | this.level = level;
14 | }
15 |
16 | public Level getLevel() {
17 | return level;
18 | }
19 |
20 | public String getText() {
21 | return text;
22 | }
23 |
24 | @Override
25 | public int hashCode() {
26 | if (hash == null) {
27 | final int prime = 31;
28 | int result = 1;
29 | result = prime * result + ((level == null) ? 0 : level.hashCode());
30 | result = prime * result + ((text == null) ? 0 : text.hashCode());
31 | hash = result;
32 | }
33 |
34 | return hash;
35 | }
36 |
37 | @Override
38 | public boolean equals(Object obj) {
39 | if (this == obj)
40 | return true;
41 | if (obj == null)
42 | return false;
43 | if (getClass() != obj.getClass())
44 | return false;
45 | LogEntry other = (LogEntry) obj;
46 | if (level != other.level)
47 | return false;
48 | if (text == null) {
49 | if (other.text != null)
50 | return false;
51 | } else if (!text.equals(other.text))
52 | return false;
53 | return true;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Lock.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.os.PowerManager;
5 | import android.os.PowerManager.WakeLock;
6 | import android.util.Log;
7 |
8 | public class Lock {
9 | private static PowerManager.WakeLock lock;
10 |
11 | private static PowerManager.WakeLock getLock(Context context) {
12 | if (lock == null) {
13 | PowerManager mgr = (PowerManager) context
14 | .getSystemService(Context.POWER_SERVICE);
15 |
16 | lock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "org.jtb.alogcat.lock");
17 | lock.setReferenceCounted(true);
18 | }
19 | return lock;
20 | }
21 |
22 | public static synchronized void acquire(Context context) {
23 | WakeLock wakeLock = getLock(context);
24 | if (!wakeLock.isHeld()) {
25 | wakeLock.acquire();
26 | //Log.d("alogcat", "wake lock acquired");
27 | }
28 | }
29 |
30 | public static synchronized void release() {
31 | if (lock == null) {
32 | Log
33 | .w(Lock.class.getSimpleName(),
34 | "release attempted, but wake lock was null");
35 | } else {
36 | if (lock.isHeld()) {
37 | lock.release();
38 | //Log.d("alogcat", "wake lock released");
39 | } else {
40 | Log.w("alogcat",
41 | "release attempted, but wake lock was not held");
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Level.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 |
6 | public enum Level {
7 | V(0, "#121212", R.string.verbose_title), D(1, "#00006C",
8 | R.string.debug_title), I(2, "#20831B", R.string.info_title), W(3,
9 | "#FD7916", R.string.warn_title), E(4, "#FD0010",
10 | R.string.error_title), F(5, "#ff0066", R.string.fatal_title);
11 |
12 | private static Level[] byOrder = new Level[6];
13 |
14 | static {
15 | byOrder[0] = V;
16 | byOrder[1] = D;
17 | byOrder[2] = I;
18 | byOrder[3] = W;
19 | byOrder[4] = E;
20 | byOrder[5] = F;
21 | }
22 |
23 | private String mHexColor;
24 | private int mColor;
25 | private int mValue;
26 | private int mTitleId;
27 |
28 | private Level(int value, String hexColor, int titleId) {
29 | mValue = value;
30 | mHexColor = hexColor;
31 | mColor = Color.parseColor(hexColor);
32 | mTitleId = titleId;
33 | }
34 |
35 | public String getHexColor() {
36 | return mHexColor;
37 | }
38 |
39 | public int getColor() {
40 | return mColor;
41 | }
42 |
43 | public int getValue() {
44 | return mValue;
45 | }
46 |
47 | public static Level getByOrder(int value) {
48 | return byOrder[value];
49 | }
50 |
51 | public String getTitle(Context context) {
52 | return context.getResources().getString(mTitleId);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/ShareService.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.IntentService;
4 | import android.content.Intent;
5 | import android.text.Html;
6 |
7 | import java.util.Date;
8 |
9 | public class ShareService extends IntentService {
10 | public ShareService() {
11 | super("saveService");
12 | }
13 |
14 | @Override
15 | protected void onHandleIntent(Intent intent) {
16 | //Log.d("alogcat", "handling intent: " + intent.getAction());
17 |
18 | Prefs prefs = new Prefs(this);
19 |
20 | LogDumper dumper = new LogDumper(this);
21 | boolean html = prefs.isShareHtml();
22 | String content = dumper.dump(html);
23 |
24 | Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
25 |
26 | // emailIntent.setType("message/rfc822");
27 | if (html) {
28 | shareIntent.setType("text/html");
29 | } else {
30 | shareIntent.setType("text/plain");
31 | }
32 |
33 | shareIntent.putExtra(
34 | android.content.Intent.EXTRA_SUBJECT,
35 | "Android Log: "
36 | + LogActivity.LOG_DATE_FORMAT.format(new Date()));
37 | shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
38 | html ? Html.fromHtml(content) : content);
39 | Intent chooserIntent = Intent
40 | .createChooser(shareIntent, "Share Android Log ...");
41 | chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
42 | startActivity(chooserIntent);
43 |
44 | Lock.release();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gn/mylogcat/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.gn.mylogcat;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 | public static final String TAG = "MainActivity";
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 | Log.v(TAG, "onCreate()");
16 | }
17 |
18 | @Override
19 | protected void onStart() {
20 | super.onStart();
21 | Log.d(TAG, "onStart()");
22 | }
23 |
24 | @Override
25 | protected void onResume() {
26 | super.onResume();
27 | Log.i(TAG, "onResume()");
28 | }
29 |
30 | @Override
31 | protected void onPause() {
32 | super.onPause();
33 | Log.w(TAG, "onPause()");
34 | }
35 |
36 | @Override
37 | protected void onStop() {
38 | super.onStop();
39 | Log.e(TAG, "onStop()");
40 | }
41 |
42 | @Override
43 | protected void onDestroy() {
44 | super.onDestroy();
45 | Log.wtf(TAG, "onDestroy()");
46 | }
47 |
48 | @Override
49 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
50 | super.onSaveInstanceState(outState, outPersistentState);
51 | Log.d(TAG, "onSaveInstanceState()");
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - Verbose
5 | - Debug
6 | - Information
7 | - Warning
8 | - Error
9 | - Fatal
10 |
11 |
12 | - V
13 | - D
14 | - I
15 | - W
16 | - E
17 | - F
18 |
19 |
20 | - Brief
21 | - Process
22 | - Tag
23 | - Thread
24 | - Thread Time
25 | - Time
26 | - Long
27 | - Raw
28 |
29 |
30 | - BRIEF
31 | - PROCESS
32 | - TAG
33 | - THREAD
34 | - THREADTIME
35 | - TIME
36 | - LONG
37 | - RAW
38 |
39 |
40 | - Main
41 | - Events
42 | - Radio
43 |
44 |
45 | - MAIN
46 | - EVENTS
47 | - RADIO
48 |
49 |
50 | - Small
51 | - Medium (default)
52 | - Large
53 |
54 |
55 | - SMALL
56 | - MEDIUM
57 | - LARGE
58 |
59 |
60 | - White
61 | - Gray
62 | - Black
63 |
64 |
65 | - WHITE
66 | - GRAY
67 | - BLACK
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/LogEntryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.Activity;
4 | import android.util.TypedValue;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ArrayAdapter;
9 | import android.widget.TextView;
10 |
11 | import java.util.Collections;
12 | import java.util.List;
13 |
14 | public class LogEntryAdapter extends ArrayAdapter {
15 | private Activity mActivity;
16 | private List entries;
17 | private Prefs mPrefs;
18 |
19 | public LogEntryAdapter(Activity activity, int resourceId,
20 | List entries) {
21 | super(activity, resourceId, entries);
22 | this.mActivity = activity;
23 | this.entries = entries;
24 | this.mPrefs = new Prefs(activity);
25 | }
26 |
27 | @Override
28 | public View getView(int position, View convertView, ViewGroup parent) {
29 | LogEntry entry = entries.get(position);
30 | TextView tv;
31 | if (convertView == null) {
32 | LayoutInflater inflater = mActivity.getLayoutInflater();
33 | tv = (TextView) inflater.inflate(R.layout.entry, null);
34 | } else {
35 | tv = (TextView) convertView;
36 | }
37 |
38 | tv.setText(entry.getText());
39 | tv.setTextColor(entry.getLevel().getColor());
40 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mPrefs.getTextsize()
41 | .getValue());
42 |
43 | return tv;
44 | }
45 |
46 | public void remove(int position) {
47 | LogEntry entry = entries.get(position);
48 | remove(entry);
49 | }
50 |
51 | public boolean areAllItemsEnabled() {
52 | return false;
53 | }
54 |
55 | public boolean isEnabled(int position) {
56 | return false;
57 | }
58 |
59 | public LogEntry get(int position) {
60 | return entries.get(position);
61 | }
62 |
63 | public List getEntries() {
64 | return Collections.unmodifiableList(entries);
65 | }
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/LogSaver.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 | import android.util.Log;
6 |
7 | import java.io.BufferedWriter;
8 | import java.io.File;
9 | import java.io.FileWriter;
10 | import java.io.IOException;
11 | import java.text.SimpleDateFormat;
12 | import java.util.Date;
13 | import java.util.concurrent.Executor;
14 | import java.util.concurrent.Executors;
15 |
16 | public class LogSaver {
17 | static final SimpleDateFormat LOG_FILE_FORMAT = new SimpleDateFormat(
18 | "yyyy-MM-dd-HH-mm-ssZ");
19 | private static final Executor EX = Executors.newSingleThreadExecutor();
20 |
21 | private Context mContext;
22 | private Prefs mPrefs;
23 | private LogDumper mLogDumper;
24 |
25 | public LogSaver(Context context) {
26 | mContext = context;
27 | mPrefs = new Prefs(mContext);
28 |
29 | mLogDumper = new LogDumper(mContext);
30 | }
31 |
32 | public File save() {
33 | final File path = new File(Environment.getExternalStorageDirectory(),
34 | "alogcat");
35 | final File file = new File(path + "/alogcat."
36 | + LOG_FILE_FORMAT.format(new Date()) + ".txt");
37 |
38 | String msg = "saving log to: " + file.toString();
39 | //Log.d("alogcat", msg);
40 |
41 | EX.execute(new Runnable() {
42 | public void run() {
43 | String dump = mLogDumper.dump(false);
44 |
45 | if (!path.exists()) {
46 | path.mkdir();
47 | }
48 |
49 | BufferedWriter bw = null;
50 | try {
51 | file.createNewFile();
52 | bw = new BufferedWriter(new FileWriter(file), 1024);
53 | bw.write(dump);
54 | } catch (IOException e) {
55 | Log.e("alogcat", "error saving log", e);
56 | } finally {
57 | if (bw != null) {
58 | try {
59 | bw.close();
60 | } catch (IOException e) {
61 | Log.e("alogcat", "error closing log", e);
62 | }
63 | }
64 | }
65 | }
66 | });
67 |
68 | return file;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/layout/filter_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
20 |
31 |
32 |
45 |
46 |
47 |
53 |
54 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/LogDumper.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.util.Log;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.IOException;
9 | import java.io.InputStreamReader;
10 | import java.util.regex.Pattern;
11 |
12 | public class LogDumper {
13 | private Prefs mPrefs;
14 |
15 | public LogDumper(Context context) {
16 | mPrefs = new Prefs(context);
17 | }
18 |
19 | public String dump(boolean html) {
20 | StringBuilder sb = new StringBuilder();
21 | BufferedReader br = null;
22 | Process p = null;
23 |
24 | try {
25 | p = Runtime.getRuntime().exec(
26 | new String[] { "logcat", "-d", "-v",
27 | mPrefs.getFormat().getValue(), "-b",
28 | mPrefs.getBuffer().getValue(),
29 | "*:" + mPrefs.getLevel() });
30 |
31 | br = new BufferedReader(new InputStreamReader(p.getInputStream()),
32 | 1024);
33 |
34 | String line;
35 | Pattern filterPattern = mPrefs.getFilterPattern();
36 | Format format = mPrefs.getFormat();
37 |
38 | Level lastLevel = Level.V;
39 |
40 | while ((line = br.readLine()) != null) {
41 | if (filterPattern != null
42 | && !filterPattern.matcher(line).find()) {
43 | continue;
44 | }
45 |
46 | if (!html) {
47 | sb.append(line);
48 | sb.append('\n');
49 | } else {
50 | Level level = format.getLevel(line);
51 | if (level == null) {
52 | level = lastLevel;
53 | } else {
54 | lastLevel = level;
55 | }
56 | sb.append("");
58 | sb.append(TextUtils.htmlEncode(line));
59 | sb.append("
\n");
60 |
61 | }
62 | }
63 | String s = sb.toString();
64 | return s;
65 | } catch (IOException e) {
66 | Log.e("alogcat", "error reading log", e);
67 | return null;
68 | } finally {
69 | if (br != null) {
70 | try {
71 | br.close();
72 | } catch (IOException e) {
73 | Log.e("alogcat", "error closing stream", e);
74 | }
75 | }
76 | if (p != null) {
77 | p.destroy();
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Format.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.HashMap;
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | public enum Format {
10 | BRIEF("brief", R.string.brief_title, Pattern.compile("^([VDIWEF])/")),
11 | PROCESS("process", R.string.process_title, Pattern.compile("^([VDIWEF])\\(")),
12 | TAG("tag", R.string.tag_title, Pattern.compile("^([VDIWEF])/")),
13 | THREAD("thread", R.string.thread_title, Pattern.compile("^([VDIWEF])\\(")),
14 | TIME("time", R.string.time_title, Pattern.compile(" ([VDIWEF])/")),
15 | THREADTIME("threadtime", R.string.threadtime_title, Pattern.compile(" ([VDIWEF]) ")),
16 | LONG("long", R.string.long_title, Pattern.compile("([VDIWEF])/")),
17 | RAW("raw", R.string.raw_title, null);
18 |
19 | private static Format[] byOrder = new Format[8];
20 |
21 | static {
22 | byOrder[0] = BRIEF;
23 | byOrder[1] = PROCESS;
24 | byOrder[2] = TAG;
25 | byOrder[3] = THREAD;
26 | byOrder[4] = TIME;
27 | byOrder[5] = THREADTIME;
28 | byOrder[6] = LONG;
29 | byOrder[7] = RAW;
30 | }
31 |
32 | private static final HashMap VALUE_MAP = new HashMap();
33 |
34 | static {
35 | VALUE_MAP.put(BRIEF.mValue, BRIEF);
36 | VALUE_MAP.put(PROCESS.mValue, PROCESS);
37 | VALUE_MAP.put(TAG.mValue, TAG);
38 | VALUE_MAP.put(THREAD.mValue, THREAD);
39 | VALUE_MAP.put(THREADTIME.mValue, THREAD);
40 | VALUE_MAP.put(TIME.mValue, TIME);
41 | VALUE_MAP.put(RAW.mValue, RAW);
42 | VALUE_MAP.put(LONG.mValue, LONG);
43 | }
44 |
45 | private String mValue;
46 | private int mTitleId;
47 | private Pattern mLevelPattern;
48 |
49 | private Format(String value, int titleId, Pattern levelPattern) {
50 | mValue = value;
51 | mTitleId = titleId;
52 | mLevelPattern = levelPattern;
53 | }
54 |
55 | public String getTitle(Context context) {
56 | return context.getResources().getString(mTitleId);
57 | }
58 |
59 | public static final Format byValue(String value) {
60 | return VALUE_MAP.get(value);
61 | }
62 |
63 | public Level getLevel(String line) {
64 | if (mLevelPattern == null) {
65 | return null;
66 | }
67 | Matcher m = mLevelPattern.matcher(line);
68 | if (m.find()) {
69 | return Level.valueOf(m.group(1));
70 | }
71 | return null;
72 | }
73 |
74 | public static Format getByOrder(int order) {
75 | return byOrder[order];
76 | }
77 |
78 | public String getValue() {
79 | return mValue;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyLogcatLibrary
3 | aLogcat (paused)
4 | aLogcat - Preferences
5 | Cancel
6 | Okay
7 | Fatal
8 | Error
9 | Warning
10 | Information
11 | Verbose
12 | Debug
13 | Filter (%s)
14 | Log Filter
15 | Filter
16 | A log filter can be a simple substring or a Java-conforming regular expression.
17 | Invalid regular expression
18 | Clear
19 | Brief
20 | Process
21 | Tag
22 | Thread
23 | Raw
24 | Time
25 | Long
26 | Reading logs, please wait.
27 | Share
28 | Play
29 | Pause
30 | Top
31 | Bottom
32 | Main
33 | Events
34 | Radio
35 | Small
36 | Medium
37 | Large
38 | Clear
39 | Save
40 | Preferences
41 | Saving log to: %s, please wait
42 | Thread Time
43 | Black
44 | White
45 | Gray
46 | Apply as regular expression?
47 |
48 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/res/layout/prefs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
13 |
14 |
21 |
22 |
29 |
30 |
37 |
38 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
60 |
61 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/PrefsActivity.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.Activity;
4 | import android.content.SharedPreferences;
5 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
6 | import android.os.Bundle;
7 | import android.preference.ListPreference;
8 | import android.preference.PreferenceActivity;
9 |
10 | public class PrefsActivity extends PreferenceActivity implements
11 | OnSharedPreferenceChangeListener {
12 | private ListPreference mLevelPreference;
13 | private ListPreference mFormatPreference;
14 | private ListPreference mBufferPreference;
15 | private ListPreference mTextsizePreference;
16 | private ListPreference mBackgroundColorPreference;
17 |
18 | private Prefs mPrefs;
19 |
20 | @Override
21 | public void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | addPreferencesFromResource(R.layout.prefs);
24 |
25 | mPrefs = new Prefs(this);
26 |
27 | mLevelPreference = (ListPreference) getPreferenceScreen()
28 | .findPreference(Prefs.LEVEL_KEY);
29 | mFormatPreference = (ListPreference) getPreferenceScreen()
30 | .findPreference(Prefs.FORMAT_KEY);
31 | mBufferPreference = (ListPreference) getPreferenceScreen()
32 | .findPreference(Prefs.BUFFER_KEY);
33 | mTextsizePreference = (ListPreference) getPreferenceScreen()
34 | .findPreference(Prefs.TEXTSIZE_KEY);
35 | mBackgroundColorPreference = (ListPreference) getPreferenceScreen()
36 | .findPreference(Prefs.BACKGROUND_COLOR_KEY);
37 |
38 | setResult(Activity.RESULT_OK);
39 | }
40 |
41 | private void setLevelTitle() {
42 | mLevelPreference.setTitle("Level? (" + mPrefs.getLevel().getTitle(this) + ")");
43 | }
44 |
45 | private void setFormatTitle() {
46 | mFormatPreference.setTitle("Format? (" + mPrefs.getFormat().getTitle(this) + ")");
47 | }
48 |
49 | private void setBufferTitle() {
50 | mBufferPreference.setTitle("Buffer? (" + mPrefs.getBuffer().getTitle(this) + ")");
51 | }
52 |
53 | private void setTextsizeTitle() {
54 | mTextsizePreference.setTitle("Text Size? (" + mPrefs.getTextsize().getTitle(this) + ")");
55 | }
56 |
57 | private void setBackgroundColorTitle() {
58 | mBackgroundColorPreference.setTitle("Background Color? (" + mPrefs.getBackgroundColor().getTitle(this) + ")");
59 | }
60 |
61 | @Override
62 | protected void onResume() {
63 | super.onResume();
64 |
65 | setLevelTitle();
66 | setFormatTitle();
67 | setBufferTitle();
68 | setTextsizeTitle();
69 | setBackgroundColorTitle();
70 |
71 | getPreferenceScreen().getSharedPreferences()
72 | .registerOnSharedPreferenceChangeListener(this);
73 | }
74 |
75 | @Override
76 | protected void onPause() {
77 | super.onPause();
78 | getPreferenceScreen().getSharedPreferences()
79 | .unregisterOnSharedPreferenceChangeListener(this);
80 | }
81 |
82 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
83 | String key) {
84 | if (key.equals(Prefs.LEVEL_KEY)) {
85 | setLevelTitle();
86 | } else if (key.equals(Prefs.FORMAT_KEY)) {
87 | setFormatTitle();
88 | } else if (key.equals(Prefs.BUFFER_KEY)) {
89 | setBufferTitle();
90 | } else if (key.equals(Prefs.TEXTSIZE_KEY)) {
91 | setTextsizeTitle();
92 | } else if (key.equals(Prefs.BACKGROUND_COLOR_KEY)) {
93 | setBackgroundColorTitle();
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/mylogcatlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | // 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
5 | version = "1.0.1"
6 | android {
7 | compileSdkVersion 23
8 | buildToolsVersion "23.0.2"
9 | resourcePrefix "gn"
10 |
11 | defaultConfig {
12 | minSdkVersion 9
13 | targetSdkVersion 23
14 | versionCode 1
15 | versionName version
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | lintOptions {
25 | abortOnError false
26 | }
27 |
28 | }
29 |
30 | dependencies {
31 | compile fileTree(dir: 'libs', include: ['*.jar'])
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.android.support:support-v4:23.1.1'
34 | }
35 |
36 | def siteUrl = 'https://github.com/gaoneng102/MyLogCat' // 项目的主页
37 | def gitUrl = 'https://github.com/gaoneng102/MyLogCat.git' // Git仓库的url
38 |
39 | group = "com.gn.logcatlibrary" // Maven Group ID for the artifact,一般填你唯一的包名
40 |
41 | install {
42 | repositories.mavenInstaller {
43 | // This generates POM.xml with proper parameters
44 | pom {
45 | project {
46 | packaging 'aar'
47 | // Add your description here
48 | name 'Android Logcat library for app' //项目描述
49 | url siteUrl
50 | // Set your license
51 | licenses {
52 | license {
53 | name 'The Apache Software License, Version 2.0'
54 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
55 | }
56 | }
57 | developers {
58 | developer {
59 | id 'gaoneng102' //填写开发者基本信息
60 | name 'gaoneng'
61 | email 'gaoneng1850@gmail.com'
62 | }
63 | }
64 | scm {
65 | connection gitUrl
66 | developerConnection gitUrl
67 | url siteUrl
68 | }
69 | }
70 | }
71 | }
72 | }
73 | task sourcesJar(type: Jar) {
74 | from android.sourceSets.main.java.srcDirs
75 | classifier = 'sources'
76 | }
77 | task javadoc(type: Javadoc) {
78 | source = android.sourceSets.main.java.srcDirs
79 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
80 | }
81 | task javadocJar(type: Jar, dependsOn: javadoc) {
82 | classifier = 'javadoc'
83 | from javadoc.destinationDir
84 | }
85 | artifacts {
86 | archives javadocJar
87 | archives sourcesJar
88 | }
89 | Properties properties = new Properties()
90 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
91 | bintray {
92 | user = properties.getProperty("bintray.user")
93 | key = properties.getProperty("bintray.apikey")
94 | configurations = ['archives']
95 | pkg {
96 | repo = "maven" //发布到Bintray的那个仓库里,默认账户有四个库,我们这里上传到maven库
97 | name = "logcatlibrary" //发布到Bintray上的项目名字
98 | websiteUrl = siteUrl
99 | vcsUrl = gitUrl
100 | licenses = ["Apache-2.0"]
101 | publish = true
102 | }
103 | }
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Prefs.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.content.SharedPreferences.Editor;
6 | import android.preference.PreferenceManager;
7 | import android.util.Log;
8 |
9 | import java.util.regex.Pattern;
10 | import java.util.regex.PatternSyntaxException;
11 |
12 | /**
13 | * 保存个人偏好设置
14 | */
15 | public class Prefs {
16 | public static final String LEVEL_KEY = "level";
17 | public static final String FORMAT_KEY = "format";
18 | public static final String BUFFER_KEY = "buffer";
19 | public static final String TEXTSIZE_KEY = "textsize";
20 | public static final String BACKGROUND_COLOR_KEY = "backgroundColor";
21 | public static final String FILTER_PATTERN_KEY = "filterPattern";
22 | public static final String SHARE_HTML_KEY = "shareHtml";
23 | public static final String KEEP_SCREEN_ON_KEY = "keepScreenOn";
24 |
25 | private SharedPreferences sharedPrefs = null;
26 |
27 | public Prefs(Context context) {
28 | sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
29 | }
30 |
31 | private String getString(String key, String def) {
32 | String s = sharedPrefs.getString(key, def);
33 | return s;
34 | }
35 |
36 | private void setString(String key, String val) {
37 | Editor e = sharedPrefs.edit();
38 | e.putString(key, val);
39 | e.commit();
40 | }
41 |
42 | private boolean getBoolean(String key, boolean def) {
43 | boolean b = sharedPrefs.getBoolean(key, def);
44 | return b;
45 | }
46 |
47 | private void setBoolean(String key, boolean val) {
48 | Editor e = sharedPrefs.edit();
49 | e.putBoolean(key, val);
50 | e.commit();
51 | }
52 |
53 | public Level getLevel() {
54 | return Level.valueOf(getString(LEVEL_KEY, "V"));
55 | }
56 |
57 | public void setLevel(Level level) {
58 | setString(LEVEL_KEY, level.toString());
59 | }
60 |
61 | public Format getFormat() {
62 | String f = getString(FORMAT_KEY, "BRIEF");
63 |
64 | // UPGRADE
65 | // can remove at some point
66 |
67 | if (!f.equals(f.toUpperCase())) {
68 | f = f.toUpperCase();
69 | setString(FORMAT_KEY, f);
70 | }
71 |
72 | return Format.valueOf(f);
73 | }
74 |
75 | public void setFormat(Format format) {
76 | setString(FORMAT_KEY, format.toString());
77 | }
78 |
79 | public Buffer getBuffer() {
80 | return Buffer.valueOf(getString(BUFFER_KEY, "MAIN"));
81 | }
82 |
83 | public void setBuffer(Buffer buffer) {
84 | setString(BUFFER_KEY, buffer.toString());
85 | }
86 |
87 | public Textsize getTextsize() {
88 | return Textsize.valueOf(getString(TEXTSIZE_KEY, "MEDIUM"));
89 | }
90 |
91 | public void setTextsize(Textsize textsize) {
92 | setString(TEXTSIZE_KEY, textsize.toString());
93 | }
94 |
95 | public String getFilter() {
96 | return getString("filter", null);
97 | }
98 |
99 | public Pattern getFilterPattern() {
100 | if (!isFilterPattern()) {
101 | return null;
102 | }
103 |
104 | String p = getString("filter", null);
105 | if (p == null) {
106 | return null;
107 | }
108 | try {
109 | return Pattern.compile(p, Pattern.CASE_INSENSITIVE);
110 | } catch (PatternSyntaxException e) {
111 | setString("filter", null);
112 | Log.w("alogcat", "invalid filter pattern found, cleared");
113 | return null;
114 | }
115 | }
116 |
117 | public void setFilter(String filter) {
118 | setString("filter", filter);
119 | }
120 |
121 | public BackgroundColor getBackgroundColor() {
122 | String c = getString(BACKGROUND_COLOR_KEY, "WHITE");
123 | BackgroundColor bc;
124 |
125 | try {
126 | bc = BackgroundColor.valueOf(c);
127 | } catch (IllegalArgumentException iae) {
128 | bc = BackgroundColor.valueOfHexColor(c);
129 | }
130 | if (bc == null) {
131 | return BackgroundColor.WHITE;
132 | }
133 |
134 | return bc;
135 | }
136 |
137 | public boolean isShareHtml() {
138 | boolean b = getBoolean(SHARE_HTML_KEY, false);
139 | return b;
140 | }
141 |
142 | public boolean isKeepScreenOn() {
143 | boolean b = getBoolean(KEEP_SCREEN_ON_KEY, false);
144 | return b;
145 | }
146 |
147 | public void setKeepScreenOn(boolean keep) {
148 | setBoolean(KEEP_SCREEN_ON_KEY, keep);
149 | }
150 |
151 | public boolean isFilterPattern() {
152 | return getBoolean(FILTER_PATTERN_KEY, false);
153 | }
154 |
155 | public void setFilterPattern(boolean filterPattern) {
156 | setBoolean(FILTER_PATTERN_KEY, filterPattern);
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/Logcat.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.util.Log;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStreamReader;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.concurrent.Executors;
14 | import java.util.concurrent.ScheduledExecutorService;
15 | import java.util.concurrent.TimeUnit;
16 | import java.util.regex.Pattern;
17 |
18 | public class Logcat {
19 | private static final long CAT_DELAY = 1;
20 |
21 | private Level mLevel = null;
22 | private String mFilter = null;
23 | private Pattern mFilterPattern = null;
24 | private boolean mRunning = false;
25 | private BufferedReader mReader = null;
26 | private boolean mIsFilterPattern;
27 | private Handler mHandler;
28 | private Buffer mBuffer;
29 | private Process logcatProc;
30 | private Context mContext;
31 | private ArrayList mLogCache = new ArrayList();
32 | private boolean mPlay = true;
33 | private long lastCat = -1;
34 | private Runnable catRunner = new Runnable() {
35 |
36 | @Override
37 | public void run() {
38 | if (!mPlay) {
39 | return;
40 | }
41 | long now = System.currentTimeMillis();
42 | if (now < lastCat + CAT_DELAY) {
43 | return;
44 | }
45 | lastCat = now;
46 | cat();
47 | }
48 | };
49 | private ScheduledExecutorService EX;
50 |
51 | Format mFormat;
52 |
53 | public Logcat(Context context, Handler handler) {
54 | mContext = context;
55 | mHandler = handler;
56 |
57 | Prefs prefs = new Prefs(mContext);
58 |
59 | mLevel = prefs.getLevel();
60 | mIsFilterPattern = prefs.isFilterPattern();
61 | mFilter = prefs.getFilter();
62 | mFilterPattern = prefs.getFilterPattern();
63 | mFormat = prefs.getFormat();
64 | mBuffer = prefs.getBuffer();
65 | }
66 |
67 | public void start() {
68 | // Log.d("alogcat", "starting ...");
69 | stop();
70 |
71 | mRunning = true;
72 |
73 | EX = Executors.newScheduledThreadPool(1);
74 | EX.scheduleAtFixedRate(catRunner, CAT_DELAY, CAT_DELAY,
75 | TimeUnit.SECONDS);
76 |
77 | try {
78 | Message m = Message.obtain(mHandler, LogActivity.CLEAR_WHAT);
79 | mHandler.sendMessage(m);
80 |
81 | List progs = new ArrayList();
82 |
83 | progs.add("logcat");
84 | progs.add("-v");
85 | progs.add(mFormat.getValue());
86 | if (mBuffer != Buffer.MAIN) {
87 | progs.add("-b");
88 | progs.add(mBuffer.getValue());
89 | }
90 | progs.add("*:" + mLevel);
91 |
92 | logcatProc = Runtime.getRuntime()
93 | .exec(progs.toArray(new String[0]));
94 |
95 | mReader = new BufferedReader(new InputStreamReader(
96 | logcatProc.getInputStream()), 1024);
97 |
98 | String line;
99 | while (mRunning && (line = mReader.readLine()) != null) {
100 | if (!mRunning) {
101 | break;
102 | }
103 | if (line.length() == 0) {
104 | continue;
105 | }
106 | if (mIsFilterPattern) {
107 | if (mFilterPattern != null
108 | && !mFilterPattern.matcher(line).find()) {
109 | continue;
110 | }
111 | } else {
112 | if (mFilter != null
113 | && !line.toLowerCase().contains(
114 | mFilter.toLowerCase())) {
115 | continue;
116 | }
117 | }
118 | synchronized (mLogCache) {
119 | mLogCache.add(line);
120 | }
121 | }
122 | } catch (IOException e) {
123 | Log.e("alogcat", "error reading log", e);
124 | return;
125 | } finally {
126 | // Log.d("alogcat", "stopped");
127 |
128 | if (logcatProc != null) {
129 | logcatProc.destroy();
130 | logcatProc = null;
131 | }
132 | if (mReader != null) {
133 | try {
134 | mReader.close();
135 | mReader = null;
136 | } catch (IOException e) {
137 | Log.e("alogcat", "error closing stream", e);
138 | }
139 | }
140 | }
141 | }
142 |
143 | private void cat() {
144 | Message m;
145 |
146 | if (mLogCache.size() > 0) {
147 | synchronized (mLogCache) {
148 | if (mLogCache.size() > 0) {
149 | m = Message.obtain(mHandler, LogActivity.CAT_WHAT);
150 | m.obj = mLogCache.clone();
151 | mLogCache.clear();
152 | mHandler.sendMessage(m);
153 | }
154 | }
155 | }
156 | }
157 |
158 | public void stop() {
159 | // Log.d("alogcat", "stopping ...");
160 | mRunning = false;
161 |
162 | if (EX != null && !EX.isShutdown()) {
163 | EX.shutdown();
164 | EX = null;
165 | }
166 | }
167 |
168 | public boolean isRunning() {
169 | return mRunning;
170 | }
171 |
172 | public boolean isPlay() {
173 | return mPlay;
174 | }
175 |
176 | public void setPlay(boolean play) {
177 | mPlay = play;
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/FilterDialog.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.CheckBox;
8 | import android.widget.CompoundButton;
9 | import android.widget.EditText;
10 | import android.widget.TextView;
11 |
12 | import java.util.regex.Pattern;
13 | import java.util.regex.PatternSyntaxException;
14 |
15 | public class FilterDialog extends AlertDialog {
16 | private boolean mError = false;
17 | private Prefs mPrefs;
18 | private LogActivity mLogActivity;
19 |
20 | @Override
21 | public void dismiss() {
22 | if (!mError) {
23 | super.dismiss();
24 | }
25 | }
26 |
27 | public FilterDialog(LogActivity logActivity) {
28 | super(logActivity);
29 |
30 | mLogActivity = logActivity;
31 | mPrefs = new Prefs(mLogActivity);
32 |
33 | LayoutInflater factory = LayoutInflater.from(mLogActivity);
34 | final View view = factory.inflate(R.layout.filter_dialog, null);
35 |
36 | final EditText filterEdit = (EditText) view
37 | .findViewById(R.id.filter_edit);
38 | filterEdit.setText(mPrefs.getFilter());
39 |
40 | final TextView patternErrorText = (TextView) view.findViewById(R.id.pattern_error_text);
41 | patternErrorText.setVisibility(View.GONE);
42 |
43 | final CheckBox patternCheckBox = (CheckBox) view
44 | .findViewById(R.id.pattern_checkbox);
45 | patternCheckBox.setChecked(mPrefs.isFilterPattern());
46 | CompoundButton.OnCheckedChangeListener occl = new CompoundButton.OnCheckedChangeListener() {
47 |
48 | public void onCheckedChanged(CompoundButton buttonView,
49 | boolean isChecked) {
50 | if (!isChecked) {
51 | patternErrorText.setVisibility(View.GONE);
52 | mError = false;
53 | }
54 | }
55 |
56 | };
57 | patternCheckBox.setOnCheckedChangeListener(occl);
58 |
59 | setView(view);
60 | setTitle(R.string.filter_dialog_title);
61 |
62 | setButton(BUTTON_POSITIVE, mLogActivity.getResources().getString(R.string.ok),
63 | new DialogInterface.OnClickListener() {
64 | public void onClick(DialogInterface dialog, int which) {
65 | FilterDialog fd = (FilterDialog) dialog;
66 | String f = filterEdit.getText().toString();
67 | if (patternCheckBox.isChecked()) {
68 | try {
69 | Pattern.compile(f);
70 | } catch (PatternSyntaxException e) {
71 | patternErrorText.setVisibility(View.VISIBLE);
72 | fd.mError = true;
73 | return;
74 | }
75 | }
76 |
77 | fd.mError = false;
78 | patternErrorText.setVisibility(View.GONE);
79 |
80 | mPrefs.setFilter(filterEdit.getText().toString());
81 | mPrefs.setFilterPattern(patternCheckBox.isChecked());
82 |
83 | mLogActivity.setFilterMenu();
84 | mLogActivity.dismissDialog(LogActivity.FILTER_DIALOG);
85 | mLogActivity.reset();
86 | }
87 | });
88 | setButton(BUTTON_NEUTRAL, mLogActivity.getResources().getString(R.string.clear),
89 | new DialogInterface.OnClickListener() {
90 | public void onClick(DialogInterface dialog, int which) {
91 | FilterDialog fd = (FilterDialog) dialog;
92 |
93 | mPrefs.setFilter(null);
94 | filterEdit.setText(null);
95 |
96 | mPrefs.setFilterPattern(false);
97 | patternCheckBox.setChecked(false);
98 |
99 | fd.mError = false;
100 |
101 | mLogActivity.setFilterMenu();
102 | mLogActivity.dismissDialog(LogActivity.FILTER_DIALOG);
103 | mLogActivity.reset();
104 | }
105 | });
106 | setButton(BUTTON_NEGATIVE, mLogActivity.getResources().getString(R.string.cancel),
107 | new DialogInterface.OnClickListener() {
108 | public void onClick(DialogInterface dialog, int which) {
109 | FilterDialog fd = (FilterDialog) dialog;
110 |
111 | filterEdit.setText(mPrefs.getFilter());
112 | patternCheckBox.setChecked(mPrefs.isFilterPattern());
113 |
114 | fd.mError = false;
115 | mLogActivity.dismissDialog(LogActivity.FILTER_DIALOG);
116 | }
117 | });
118 |
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Android Lint
46 |
47 |
48 | Assignment issues
49 |
50 |
51 | Assignment issuesGroovy
52 |
53 |
54 | Class metrics
55 |
56 |
57 | Class structure
58 |
59 |
60 | Code style issues
61 |
62 |
63 | Control FlowGroovy
64 |
65 |
66 | Control flow issues
67 |
68 |
69 | Declaration redundancy
70 |
71 |
72 | Error handling
73 |
74 |
75 | Finalization issues
76 |
77 |
78 | General
79 |
80 |
81 | Gradle
82 |
83 |
84 | Groovy
85 |
86 |
87 | Inheritance issues
88 |
89 |
90 | Internationalization issues
91 |
92 |
93 | J2ME issues
94 |
95 |
96 | JUnit issues
97 |
98 |
99 | Java language level migration aids
100 |
101 |
102 | Javadoc issues
103 |
104 |
105 | Language Injection
106 |
107 |
108 | Logging issues
109 |
110 |
111 | Maven
112 |
113 |
114 | Method MetricsGroovy
115 |
116 |
117 | Method metrics
118 |
119 |
120 | Numeric issues
121 |
122 |
123 | Packaging issues
124 |
125 |
126 | Pattern Validation
127 |
128 |
129 | Performance issues
130 |
131 |
132 | Potentially confusing code constructsGroovy
133 |
134 |
135 | Probable bugs
136 |
137 |
138 | Probable bugsGradle
139 |
140 |
141 | Properties Files
142 |
143 |
144 | Serialization issues
145 |
146 |
147 | Threading issues
148 |
149 |
150 | Threading issuesGroovy
151 |
152 |
153 | Validity issuesGroovy
154 |
155 |
156 | XML
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 | 1.7
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/mylogcatlibrary/src/main/java/com/gn/logcatlibrary/LogActivity.java:
--------------------------------------------------------------------------------
1 | package com.gn.logcatlibrary;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.Dialog;
5 | import android.app.ListActivity;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.os.Environment;
9 | import android.os.Handler;
10 | import android.os.Message;
11 | import android.support.v4.view.MenuItemCompat;
12 | import android.text.Html;
13 | import android.text.TextUtils;
14 | import android.util.Log;
15 | import android.view.ContextMenu;
16 | import android.view.ContextMenu.ContextMenuInfo;
17 | import android.view.Menu;
18 | import android.view.MenuItem;
19 | import android.view.View;
20 | import android.view.WindowManager;
21 | import android.widget.AbsListView;
22 | import android.widget.ListView;
23 | import android.widget.Toast;
24 |
25 | import java.io.BufferedWriter;
26 | import java.io.File;
27 | import java.io.FileWriter;
28 | import java.io.IOException;
29 | import java.text.SimpleDateFormat;
30 | import java.util.ArrayList;
31 | import java.util.Date;
32 | import java.util.List;
33 | import java.util.concurrent.Executor;
34 | import java.util.concurrent.Executors;
35 |
36 | public class LogActivity extends ListActivity {
37 | static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat(
38 | "MMM d, yyyy HH:mm:ss ZZZZ");
39 | private static final Executor EX = Executors.newCachedThreadPool();
40 |
41 | static final int FILTER_DIALOG = 1;
42 |
43 | private static final int PREFS_REQUEST = 1;
44 |
45 | private static final int MENU_FILTER = 1;
46 | private static final int MENU_SHARE = 5;
47 | private static final int MENU_PLAY = 6;
48 | private static final int MENU_CLEAR = 8;
49 | private static final int MENU_SAVE = 9;
50 | private static final int MENU_PREFS = 10;
51 | private static final int MENU_JUMP_TOP = 11;
52 | private static final int MENU_JUMP_BOTTOM = 12;
53 |
54 | static final int WINDOW_SIZE = 1000;
55 |
56 | static final int CAT_WHAT = 0;
57 | static final int CLEAR_WHAT = 2;
58 |
59 | private AlertDialog mFilterDialog;
60 |
61 | private ListView mLogList;
62 | private LogEntryAdapter mLogEntryAdapter;
63 | private MenuItem mPlayItem;
64 | private MenuItem mFilterItem;
65 |
66 | private Level mLastLevel = Level.V;
67 | private Logcat mLogcat;
68 | private Prefs mPrefs;
69 | private LogActivity mThis;
70 | private boolean mPlay = true;
71 |
72 | private Handler mHandler = new Handler() {
73 | @Override
74 | public void handleMessage(Message msg) {
75 | switch (msg.what) {
76 | case CAT_WHAT:
77 | final List lines = (List) msg.obj;
78 | cat(lines);
79 | break;
80 | case CLEAR_WHAT:
81 | mLogEntryAdapter.clear();
82 | break;
83 | }
84 | }
85 | };
86 |
87 | private void jumpTop() {
88 | pauseLog();
89 | mLogList.post(new Runnable() {
90 | public void run() {
91 | mLogList.setSelection(0);
92 | }
93 | });
94 | }
95 |
96 | private void jumpBottom() {
97 | playLog();
98 | mLogList.setSelection(mLogEntryAdapter.getCount() - 1);
99 | }
100 |
101 | private void cat(final String s) {
102 | if (mLogEntryAdapter.getCount() > WINDOW_SIZE) {
103 | mLogEntryAdapter.remove(0);
104 | }
105 |
106 | Format format = mLogcat.mFormat;
107 | Level level = format.getLevel(s);
108 | if (level == null) {
109 | level = mLastLevel;
110 | } else {
111 | mLastLevel = level;
112 | }
113 |
114 | final LogEntry entry = new LogEntry(s, level);
115 | mLogEntryAdapter.add(entry);
116 | }
117 |
118 | private void cat(List lines) {
119 | for (String line : lines) {
120 | cat(line);
121 | }
122 | jumpBottom();
123 | }
124 |
125 | @Override
126 | public void onCreate(Bundle savedInstanceState) {
127 | super.onCreate(savedInstanceState);
128 | setContentView(R.layout.log);
129 | getWindow().setTitle(getResources().getString(R.string.app_name));
130 |
131 | mThis = this;
132 | mPrefs = new Prefs(this);
133 |
134 | mLogList = (ListView) findViewById(android.R.id.list);
135 | mLogList.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
136 |
137 | @Override
138 | public void onCreateContextMenu(ContextMenu menu, View v,
139 | ContextMenuInfo menuInfo) {
140 | MenuItem jumpTopItem = menu.add(0, MENU_JUMP_TOP, 0,
141 | R.string.jump_start_menu);
142 | jumpTopItem.setIcon(android.R.drawable.ic_media_previous);
143 |
144 | MenuItem jumpBottomItem = menu.add(0, MENU_JUMP_BOTTOM, 0,
145 | R.string.jump_end_menu);
146 | jumpBottomItem.setIcon(android.R.drawable.ic_media_next);
147 | }
148 | });
149 | mLogList.setOnScrollListener(new AbsListView.OnScrollListener() {
150 |
151 | @Override
152 | public void onScrollStateChanged(AbsListView view, int scrollState) {
153 | pauseLog();
154 | }
155 |
156 | @Override
157 | public void onScroll(AbsListView view, int firstVisibleItem,
158 | int visibleItemCount, int totalItemCount) {
159 | }
160 | });
161 |
162 | // Log.v("alogcat", "created");
163 | }
164 |
165 | @Override
166 | protected void onNewIntent(Intent intent) {
167 | // Log.i("alogcat", "new intent: " + intent);
168 | if (intent == null) {
169 | return;
170 | }
171 | if (intent.getAction() == null) {
172 | return;
173 | }
174 | setIntent(intent);
175 | if (intent.getAction().equals(com.gn.logcatlibrary.Intent.START_INTENT)) {
176 | com.gn.logcatlibrary.Intent.handleExtras(this, intent);
177 | }
178 | }
179 |
180 | @Override
181 | public void onStart() {
182 | super.onStart();
183 | // Log.v("alogcat", "started");
184 | }
185 |
186 | private void init() {
187 | BackgroundColor bc = mPrefs.getBackgroundColor();
188 | int color = bc.getColor();
189 | mLogList.setBackgroundColor(color);
190 | mLogList.setCacheColorHint(color);
191 |
192 | mLogEntryAdapter = new LogEntryAdapter(this, R.layout.entry,
193 | new ArrayList(WINDOW_SIZE));
194 | setListAdapter(mLogEntryAdapter);
195 | reset();
196 | setKeepScreenOn();
197 | }
198 |
199 | @Override
200 | public void onResume() {
201 | //Debug.startMethodTracing("alogcat");
202 | super.onResume();
203 | onNewIntent(getIntent());
204 | init();
205 | // Log.v("alogcat", "resumed");
206 | }
207 |
208 | @Override
209 | public void onPause() {
210 | super.onPause();
211 | // Log.v("alogcat", "paused");
212 |
213 | //Debug.stopMethodTracing();
214 | }
215 |
216 | @Override
217 | public void onStop() {
218 | super.onStop();
219 | if (mLogcat != null) {
220 | mLogcat.stop();
221 | }
222 | }
223 |
224 | @Override
225 | public void onDestroy() {
226 | super.onDestroy();
227 | // Log.v("alogcat", "destroyed");
228 | }
229 |
230 | @Override
231 | protected void onSaveInstanceState(Bundle b) {
232 | Log.v("alogcat", "save instance");
233 | }
234 |
235 | @Override
236 | protected void onRestoreInstanceState(Bundle b) {
237 | Log.v("alogcat", "restore instance");
238 | }
239 |
240 | public void reset() {
241 | Toast.makeText(this, R.string.reading_logs, Toast.LENGTH_SHORT).show();
242 | mLastLevel = Level.V;
243 |
244 | if (mLogcat != null) {
245 | mLogcat.stop();
246 | }
247 |
248 | mPlay = true;
249 |
250 | EX.execute(new Runnable() {
251 | public void run() {
252 | mLogcat = new Logcat(mThis, mHandler);
253 | mLogcat.start();
254 | }
255 | });
256 | }
257 |
258 | @Override
259 | public boolean onCreateOptionsMenu(Menu menu) {
260 | super.onCreateOptionsMenu(menu);
261 |
262 | // TODO: maybe this should be in a menu.xml file. ;)
263 | mPlayItem = menu.add(0, MENU_PLAY, 0, R.string.pause_menu);
264 | mPlayItem.setIcon(android.R.drawable.ic_media_pause);
265 | MenuItemCompat.setShowAsAction(mPlayItem,
266 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
267 | setPlayMenu();
268 |
269 | mFilterItem = menu.add(
270 | 0,
271 | MENU_FILTER,
272 | 0,
273 | getResources().getString(R.string.filter_menu,
274 | mPrefs.getFilter()));
275 | mFilterItem.setIcon(android.R.drawable.ic_menu_search);
276 | MenuItemCompat.setShowAsAction(mFilterItem,
277 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
278 | | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
279 | setFilterMenu();
280 |
281 | MenuItem clearItem = menu.add(0, MENU_CLEAR, 0, R.string.clear_menu);
282 | clearItem.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
283 | MenuItemCompat.setShowAsAction(clearItem,
284 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
285 |
286 | MenuItem shareItem = menu.add(0, MENU_SHARE, 0, R.string.share_menu);
287 | shareItem.setIcon(android.R.drawable.ic_menu_share);
288 | MenuItemCompat.setShowAsAction(shareItem,
289 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
290 |
291 | MenuItem saveItem = menu.add(0, MENU_SAVE, 0, R.string.save_menu);
292 | saveItem.setIcon(android.R.drawable.ic_menu_save);
293 | MenuItemCompat.setShowAsAction(saveItem,
294 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
295 |
296 | MenuItem prefsItem = menu.add(0, MENU_PREFS, 0, getResources()
297 | .getString(R.string.prefs_menu));
298 | prefsItem.setIcon(android.R.drawable.ic_menu_preferences);
299 | MenuItemCompat.setShowAsAction(prefsItem,
300 | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
301 |
302 | return true;
303 | }
304 |
305 | @Override
306 | public boolean onPrepareOptionsMenu(Menu menu) {
307 | return true;
308 | }
309 |
310 | public void setPlayMenu() {
311 | if (mPlayItem == null) {
312 | return;
313 | }
314 | if (mPlay) {
315 | mPlayItem.setTitle(R.string.pause_menu);
316 | mPlayItem.setIcon(android.R.drawable.ic_media_pause);
317 | } else {
318 | mPlayItem.setTitle(R.string.play_menu);
319 | mPlayItem.setIcon(android.R.drawable.ic_media_play);
320 | }
321 | }
322 |
323 | void setFilterMenu() {
324 | if (mFilterItem == null) {
325 | return;
326 | }
327 | int filterMenuId;
328 | String filter = mPrefs.getFilter();
329 | if (filter == null || filter.length() == 0) {
330 | filterMenuId = R.string.filter_menu_empty;
331 | } else {
332 | filterMenuId = R.string.filter_menu;
333 | }
334 | mFilterItem.setTitle(getResources().getString(filterMenuId, filter));
335 | }
336 |
337 | @Override
338 | public boolean onOptionsItemSelected(MenuItem item) {
339 | switch (item.getItemId()) {
340 | case MENU_FILTER:
341 | showDialog(FILTER_DIALOG);
342 | return true;
343 | case MENU_SHARE:
344 | share();
345 | return true;
346 | case MENU_SAVE:
347 | File f = save();
348 | String msg = getResources().getString(R.string.saving_log,
349 | f.toString());
350 | Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
351 | return true;
352 | case MENU_PLAY:
353 | if (mPlay) {
354 | pauseLog();
355 | } else {
356 | jumpBottom();
357 | }
358 | return true;
359 | case MENU_CLEAR:
360 | clear();
361 | reset();
362 | return true;
363 | case MENU_PREFS:
364 | Intent intent = new Intent(this, PrefsActivity.class);
365 | startActivityForResult(intent, PREFS_REQUEST);
366 | return true;
367 | default:
368 | return super.onOptionsItemSelected(item);
369 | }
370 | }
371 |
372 | @Override
373 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
374 | switch (requestCode) {
375 | case PREFS_REQUEST:
376 | setKeepScreenOn();
377 | break;
378 | }
379 | }
380 |
381 | private void setKeepScreenOn() {
382 | if (mPrefs.isKeepScreenOn()) {
383 | getWindow()
384 | .addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
385 | } else {
386 | getWindow().clearFlags(
387 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
388 | }
389 |
390 | }
391 |
392 | @Override
393 | public boolean onContextItemSelected(MenuItem item) {
394 | switch (item.getItemId()) {
395 | case MENU_JUMP_TOP:
396 | Toast.makeText(this, "Jumping to top of log ...",
397 | Toast.LENGTH_SHORT).show();
398 | jumpTop();
399 | return true;
400 | case MENU_JUMP_BOTTOM:
401 | Toast.makeText(this, "Jumping to bottom of log ...",
402 | Toast.LENGTH_SHORT).show();
403 | jumpBottom();
404 | return true;
405 | default:
406 | return super.onContextItemSelected(item);
407 | }
408 | }
409 |
410 | private void clear() {
411 | try {
412 | Runtime.getRuntime().exec(new String[] { "logcat", "-c" });
413 | } catch (IOException e) {
414 | Log.e("alogcat", "error clearing log", e);
415 | } finally {
416 | }
417 | }
418 |
419 | private String dump(boolean html) {
420 | StringBuilder sb = new StringBuilder();
421 | Level lastLevel = Level.V;
422 |
423 | // make copy to avoid CME
424 | List entries = new ArrayList(
425 | mLogEntryAdapter.getEntries());
426 |
427 | for (LogEntry le : entries) {
428 | if (!html) {
429 | sb.append(le.getText());
430 | sb.append('\n');
431 | } else {
432 | Level level = le.getLevel();
433 | if (level == null) {
434 | level = lastLevel;
435 | } else {
436 | lastLevel = level;
437 | }
438 | sb.append("");
441 | sb.append(TextUtils.htmlEncode(le.getText()));
442 | sb.append("
\n");
443 | }
444 | }
445 |
446 | return sb.toString();
447 | }
448 |
449 | private void share() {
450 | EX.execute(new Runnable() {
451 | public void run() {
452 | boolean html = mPrefs.isShareHtml();
453 | String content = dump(html);
454 |
455 | Intent shareIntent = new Intent(
456 | android.content.Intent.ACTION_SEND);
457 |
458 | // emailIntent.setType("message/rfc822");
459 | if (html) {
460 | shareIntent.setType("text/html");
461 | } else {
462 | shareIntent.setType("text/plain");
463 | }
464 |
465 | shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
466 | "Android Log: " + LOG_DATE_FORMAT.format(new Date()));
467 | shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
468 | html ? Html.fromHtml(content) : content);
469 | startActivity(Intent.createChooser(shareIntent,
470 | "Share Android Log ..."));
471 | }
472 | });
473 |
474 | }
475 |
476 | private File save() {
477 | final File path = new File(Environment.getExternalStorageDirectory(),
478 | "alogcat");
479 | final File file = new File(path + File.separator + "alogcat."
480 | + LogSaver.LOG_FILE_FORMAT.format(new Date()) + ".txt");
481 |
482 | // String msg = "saving log to: " + file.toString();
483 | // Log.d("alogcat", msg);
484 |
485 | EX.execute(new Runnable() {
486 | public void run() {
487 | String content = dump(false);
488 |
489 | if (!path.exists()) {
490 | path.mkdir();
491 | }
492 |
493 | BufferedWriter bw = null;
494 | try {
495 | file.createNewFile();
496 | bw = new BufferedWriter(new FileWriter(file), 1024);
497 | bw.write(content);
498 | } catch (IOException e) {
499 | Log.e("alogcat", "error saving log", e);
500 | } finally {
501 | if (bw != null) {
502 | try {
503 | bw.close();
504 | } catch (IOException e) {
505 | Log.e("alogcat", "error closing log", e);
506 | }
507 | }
508 | }
509 | }
510 | });
511 |
512 | return file;
513 | }
514 |
515 | protected Dialog onCreateDialog(int id) {
516 | switch (id) {
517 | case FILTER_DIALOG:
518 | mFilterDialog = new FilterDialog(this);
519 | return mFilterDialog;
520 | }
521 | return null;
522 | }
523 |
524 | private void pauseLog() {
525 | if (!mPlay) {
526 | return;
527 | }
528 | getWindow()
529 | .setTitle(getResources().getString(R.string.app_name_paused));
530 | if (mLogcat != null) {
531 | mLogcat.setPlay(false);
532 | mPlay = false;
533 | }
534 | setPlayMenu();
535 | }
536 |
537 | private void playLog() {
538 | if (mPlay) {
539 | return;
540 | }
541 | getWindow().setTitle(getResources().getString(R.string.app_name));
542 | if (mLogcat != null) {
543 | mLogcat.setPlay(true);
544 | mPlay = true;
545 | } else {
546 | reset();
547 | }
548 | setPlayMenu();
549 | }
550 | }
551 |
--------------------------------------------------------------------------------