├── .gitignore
├── LICENSE
├── README.md
├── Screenshot
├── Screenshot_2014-10-28-16-00-35.png
└── Screenshot_2014-10-28-16-01-07.png
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── xposed_init
│ ├── ic_launcher-web.png
│ ├── java
│ └── com
│ │ └── fei_ke
│ │ └── crashreport
│ │ ├── CrashReportReceiver.java
│ │ ├── Hook.java
│ │ ├── MakeCrash.java
│ │ ├── Utils.java
│ │ ├── db
│ │ ├── CrashInfo.java
│ │ ├── DBInfo.java
│ │ ├── RecordDBOpenHelper.java
│ │ └── RecordDao.java
│ │ └── ui
│ │ ├── CrashDialog.java
│ │ ├── MainActivity.java
│ │ ├── RecordAdapter.java
│ │ ├── RecordItemView.java
│ │ ├── SwipeDismissListViewTouchListener.java
│ │ └── SwipeDismissTouchListener.java
│ └── res
│ ├── drawable
│ ├── ic_launcher_background.xml
│ └── ic_notification_small.xml
│ ├── layout
│ ├── activity_main.xml
│ └── view_record_item.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── values-w820dp
│ └── dimens.xml
│ ├── values-zh
│ └── strings.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | /local.properties
2 | /.idea
3 | .DS_Store
4 | /build
5 |
6 | # Built application files
7 | *.apk
8 | *.ap_
9 |
10 | # Files for the Dalvik VM
11 | *.dex
12 |
13 | # Java class files
14 | *.class
15 |
16 | # Generated files
17 | bin/
18 | gen/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 | *.iml
27 |
28 | # Proguard folder generated by Eclipse
29 | proguard/
30 |
31 | # Log Files
32 | *.log
33 |
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | CrashReport
2 | ===========
3 |
4 | Xposed模块,截取程序崩溃日志进行弹窗显示。
5 |
6 | 
7 |
8 | 
9 |
--------------------------------------------------------------------------------
/Screenshot/Screenshot_2014-10-28-16-00-35.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/Screenshot/Screenshot_2014-10-28-16-00-35.png
--------------------------------------------------------------------------------
/Screenshot/Screenshot_2014-10-28-16-01-07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/Screenshot/Screenshot_2014-10-28-16-01-07.png
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 |
6 | defaultConfig {
7 | applicationId "com.fei_ke.crashreport"
8 | minSdkVersion 23
9 | targetSdkVersion 29
10 | versionCode 7
11 | versionName "1.6"
12 | }
13 |
14 | signingConfigs {
15 | release {
16 | storeFile file(STORE_FILE_PATH)
17 | storePassword STORE_PASSWORD
18 | keyAlias KEY_ALIAS
19 | keyPassword KEY_PASSWORD
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | signingConfig signingConfigs.release
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | compileOnly 'de.robv.android.xposed:api:82'
35 | implementation 'com.j256.ormlite:ormlite-android:4.48'
36 | }
37 |
--------------------------------------------------------------------------------
/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:\FEi\android-sdk-windows/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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
38 |
41 |
44 |
45 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/assets/xposed_init:
--------------------------------------------------------------------------------
1 | com.fei_ke.crashreport.Hook
2 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/CrashReportReceiver.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport;
2 |
3 | import com.fei_ke.crashreport.db.CrashInfo;
4 | import com.fei_ke.crashreport.db.RecordDao;
5 | import com.fei_ke.crashreport.ui.CrashDialog;
6 |
7 | import android.app.Notification;
8 | import android.app.NotificationChannel;
9 | import android.app.NotificationManager;
10 | import android.app.PendingIntent;
11 | import android.content.BroadcastReceiver;
12 | import android.content.Context;
13 | import android.content.Intent;
14 | import android.content.pm.ApplicationInfo;
15 | import android.content.pm.PackageInfo;
16 | import android.content.pm.PackageManager;
17 | import android.graphics.Bitmap;
18 | import android.os.Build;
19 | import android.preference.PreferenceManager;
20 |
21 | import java.util.Locale;
22 |
23 | /**
24 | * Receiver for crash info
25 | * Created by fei-ke on 2014/10/26.
26 | */
27 | public class CrashReportReceiver extends BroadcastReceiver {
28 | public static final String EXTRA_NAME_CRASH_MESSAGE = "crash_message";
29 | public static final String EXTRA_NAME_CRASH_DETAIL = "crash_detail";
30 | public static final String EXTRA_NAME_PACKAGE_NAME = "pkg_name";
31 | public static final String ACTION_REPORT_CRASH = "com.fei_ke.crashreport.action.REPORT_CRASH";
32 |
33 | public static Intent getCrashBroadCastIntent(String pkgName, String message, String stackTrace) {
34 | Intent intent = new Intent(ACTION_REPORT_CRASH);
35 | intent.setPackage(BuildConfig.APPLICATION_ID);
36 | intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
37 | intent.putExtra(EXTRA_NAME_CRASH_MESSAGE, message);
38 | intent.putExtra(EXTRA_NAME_CRASH_DETAIL, stackTrace);
39 | intent.putExtra(EXTRA_NAME_PACKAGE_NAME, pkgName);
40 |
41 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
42 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
43 | }
44 | return intent;
45 | }
46 |
47 | @Override
48 | public void onReceive(final Context context, Intent intent) {
49 | if (ACTION_REPORT_CRASH.equals(intent.getAction())) {
50 | String packageName = intent.getStringExtra(EXTRA_NAME_PACKAGE_NAME);
51 | final String exceptionDetail = intent.getStringExtra(EXTRA_NAME_CRASH_DETAIL);
52 | final String exceptionMessage = intent.getStringExtra(EXTRA_NAME_CRASH_MESSAGE);
53 |
54 | StringBuilder crashInfoBuilder = new StringBuilder();
55 |
56 | //version info
57 | try {
58 | PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
59 | crashInfoBuilder.append(String.format(Locale.getDefault(),"Version: %s (%d)", info.versionName, info.versionCode))
60 | .append("\n\n");
61 | } catch (PackageManager.NameNotFoundException e) {
62 | e.printStackTrace();
63 | return;
64 | }
65 |
66 | crashInfoBuilder.append(exceptionDetail);
67 |
68 | //存到数据库
69 | CrashInfo crashInfo = new CrashInfo();
70 | crashInfo.setPackageName(packageName);
71 | crashInfo.setStampTime((int) (System.currentTimeMillis() / 1000));
72 | crashInfo.setCrashInfo(crashInfoBuilder.toString());
73 | crashInfo.setSimpleInfo(exceptionMessage);
74 |
75 | RecordDao recordDao = new RecordDao(context);
76 | recordDao.insert(crashInfo);
77 |
78 | if (PreferenceManager.getDefaultSharedPreferences(context)
79 | .getBoolean("show_notification", true)) {
80 | notifyBroadcast(context, crashInfo);
81 | }
82 | }
83 | }
84 |
85 | private void notifyBroadcast(Context context, CrashInfo crashInfo) {
86 | String packageName = crashInfo.getPackageName();
87 | final Bitmap icon;
88 | final String appName;
89 | try {
90 | PackageManager packageManager = context.getPackageManager();
91 | ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0);
92 | icon = Utils.drawableToBitmap(packageManager.getApplicationIcon(info));
93 | appName = packageManager.getApplicationLabel(info).toString();
94 | } catch (PackageManager.NameNotFoundException e) {
95 | e.printStackTrace();
96 | return;
97 | }
98 |
99 | final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
100 | if (nm == null) return;
101 |
102 | final Notification.Builder builder;
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
104 | nm.createNotificationChannel(new NotificationChannel(packageName, appName, NotificationManager.IMPORTANCE_HIGH));
105 | builder = new Notification.Builder(context, packageName);
106 | } else {
107 | builder = new Notification.Builder(context);
108 | }
109 |
110 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
111 | builder.setPriority(Notification.PRIORITY_HIGH);
112 | }
113 |
114 | Notification notification = builder.setLargeIcon(icon)
115 | .setSmallIcon(R.drawable.ic_notification_small)
116 | .setAutoCancel(true)
117 | .setContentIntent(PendingIntent.getActivity(context, 0,
118 | CrashDialog.createIntent(context, crashInfo), PendingIntent.FLAG_UPDATE_CURRENT))
119 | .setContentTitle(appName)
120 | .setContentText(crashInfo.getSimpleInfo())
121 | .setTicker(crashInfo.getSimpleInfo())
122 | .getNotification();
123 |
124 | nm.notify(crashInfo.getStampTime(), notification);
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/Hook.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.pm.ApplicationInfo;
6 |
7 | import de.robv.android.xposed.IXposedHookLoadPackage;
8 | import de.robv.android.xposed.XC_MethodHook;
9 | import de.robv.android.xposed.XposedBridge;
10 | import de.robv.android.xposed.XposedHelpers;
11 | import de.robv.android.xposed.callbacks.XC_LoadPackage;
12 |
13 | public class Hook implements IXposedHookLoadPackage {
14 | @Override
15 | public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam)
16 | throws Throwable {
17 | if (loadPackageParam.packageName.equals("android")) {
18 | Class> classAppError = XposedHelpers.findClass("com.android.server.am.AppErrors", loadPackageParam.classLoader);
19 | XposedBridge.hookAllMethods(classAppError, "crashApplicationInner", new XC_MethodHook() {
20 | @Override
21 | protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
22 | Object processRecord = param.args[0];
23 | ApplicationInfo info = (ApplicationInfo) XposedHelpers.getObjectField(processRecord, "info");
24 | String packageName = info.packageName;
25 |
26 | Object crashInfo = param.args[1];
27 | String message = (String) XposedHelpers.getObjectField(crashInfo, "exceptionMessage");
28 | String stackTrace = (String) XposedHelpers.getObjectField(crashInfo, "stackTrace");
29 |
30 | Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
31 |
32 | Intent intent = CrashReportReceiver.getCrashBroadCastIntent(packageName, message, stackTrace);
33 | context.sendBroadcast(intent);
34 | }
35 | });
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/MakeCrash.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport;
2 |
3 | import android.app.IntentService;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | public class MakeCrash extends IntentService {
8 | public static void makeCrash(Context context) {
9 | context.startService(new Intent(context, MakeCrash.class));
10 | }
11 |
12 | public MakeCrash() {
13 | super("test");
14 | }
15 |
16 | @Override
17 | protected void onHandleIntent(Intent intent) {
18 | throw new RuntimeException("test crash");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/Utils.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.drawable.BitmapDrawable;
6 | import android.graphics.drawable.Drawable;
7 |
8 | public class Utils {
9 | public static String getExceptionDetail(Throwable t) {
10 | if (t == null) return "";
11 |
12 | StringBuilder err = new StringBuilder();
13 | err.append(t.toString());
14 | err.append("\n");
15 |
16 | StackTraceElement[] stack = t.getStackTrace();
17 | if (stack != null) {
18 | for (StackTraceElement aStack : stack) {
19 | err.append("\tat ");
20 | err.append(aStack.toString());
21 | err.append("\n");
22 | }
23 |
24 | }
25 | Throwable cause = t.getCause();
26 | if (cause != null) {
27 | err.append("Caused by: ");
28 | String causeString = getExceptionDetail(cause);
29 | err.append(causeString);
30 | }
31 | return err.toString();
32 | }
33 |
34 | public static Bitmap drawableToBitmap(Drawable drawable) {
35 | Bitmap bitmap = null;
36 | if (drawable instanceof BitmapDrawable) {
37 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
38 | if (bitmapDrawable.getBitmap() != null) {
39 | return bitmapDrawable.getBitmap();
40 | }
41 | }
42 | if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
43 | // Single color bitmap will be created of 1x1 pixel
44 | bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
45 | } else {
46 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
47 | }
48 |
49 | Canvas canvas = new Canvas(bitmap);
50 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
51 | drawable.draw(canvas);
52 | return bitmap;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/db/CrashInfo.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.db;
2 |
3 | import com.j256.ormlite.field.DatabaseField;
4 | import com.j256.ormlite.table.DatabaseTable;
5 |
6 | /**
7 | * 崩溃信息
8 | */
9 | @DatabaseTable(tableName = "record")
10 | public class CrashInfo {
11 | //--------表结构
12 | @DatabaseField(generatedId = true)
13 | private int _id;
14 | @DatabaseField
15 | private String packageName;
16 |
17 | @DatabaseField
18 | private String crashInfo;
19 |
20 | @DatabaseField
21 | private String simpleInfo;
22 |
23 | @DatabaseField
24 | private int stampTime;
25 |
26 | public int getId() {
27 | return _id;
28 | }
29 |
30 | public void setId(int _id) {
31 | this._id = _id;
32 | }
33 |
34 | public String getPackageName() {
35 | return packageName;
36 | }
37 |
38 | public void setPackageName(String packageName) {
39 | this.packageName = packageName;
40 | }
41 |
42 | public CrashInfo() {
43 | }
44 |
45 | public String getCrashInfo() {
46 | return crashInfo;
47 | }
48 |
49 | public void setCrashInfo(String crashInfo) {
50 | this.crashInfo = crashInfo;
51 | }
52 |
53 | public String getSimpleInfo() {
54 | return simpleInfo;
55 | }
56 |
57 | public void setSimpleInfo(String simpleInfo) {
58 | this.simpleInfo = simpleInfo;
59 | }
60 |
61 | public int getStampTime() {
62 | return stampTime;
63 | }
64 |
65 | public void setStampTime(int stampTime) {
66 | this.stampTime = stampTime;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/db/DBInfo.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.db;
2 |
3 | /**
4 | */
5 | public class DBInfo {
6 |
7 | public static final String DB_NAME = "crash_record";
8 | public static final String TABLE_NAME = "record";
9 | public static final int VERSION = 1;
10 |
11 | public static final String CREATE_TABLE = "create table " + TABLE_NAME +
12 | "(_id Integer,timestamp text,package_name text,crash_info text,simple_info text)";
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/db/RecordDBOpenHelper.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.db;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 |
6 | import com.j256.ormlite.android.AndroidConnectionSource;
7 | import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
8 | import com.j256.ormlite.dao.Dao;
9 | import com.j256.ormlite.support.ConnectionSource;
10 | import com.j256.ormlite.table.TableUtils;
11 |
12 | import java.sql.SQLException;
13 |
14 | /**
15 | */
16 | public class RecordDBOpenHelper extends OrmLiteSqliteOpenHelper {
17 |
18 |
19 | public RecordDBOpenHelper(Context context, String databaseName, SQLiteDatabase.CursorFactory factory, int databaseVersion) {
20 | super(context, databaseName, factory, databaseVersion);
21 | }
22 |
23 | @Override
24 | public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
25 | try {
26 | TableUtils.createTable(connectionSource, CrashInfo.class);
27 | } catch (SQLException e) {
28 | e.printStackTrace();
29 | }
30 | }
31 |
32 | @Override
33 | public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
34 | try {
35 | TableUtils.dropTable(connectionSource, CrashInfo.class, true);
36 | } catch (SQLException e) {
37 | e.printStackTrace();
38 | }
39 | onCreate(database, connectionSource);
40 | }
41 |
42 | public Dao getRecordDao() {
43 | ConnectionSource connectionSource = new AndroidConnectionSource(this);
44 | Dao dao = null;
45 | try {
46 | dao = getDao(CrashInfo.class);
47 | } catch (SQLException e) {
48 | e.printStackTrace();
49 | }
50 | // try {
51 | // dao = BaseDaoImpl.createDao(connectionSource, CrashInfo.class);
52 | // } catch (SQLException e) {
53 | // e.printStackTrace();
54 | // }
55 | return dao;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/db/RecordDao.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.db;
2 |
3 | import android.content.Context;
4 |
5 | import com.j256.ormlite.dao.Dao;
6 |
7 | import java.sql.SQLException;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | */
13 | public class RecordDao {
14 | private Dao dao;
15 |
16 | public RecordDao(Context context) {
17 | RecordDBOpenHelper openHelper = new RecordDBOpenHelper(context, DBInfo.DB_NAME, null, DBInfo.VERSION);
18 | dao = openHelper.getRecordDao();
19 | }
20 |
21 | public List getAll() {
22 | try {
23 | return dao.queryBuilder().orderBy("stampTime", false).query();
24 | } catch (SQLException e) {
25 | e.printStackTrace();
26 | }
27 | return new ArrayList();
28 | }
29 |
30 | public int insert(CrashInfo crashInfo) {
31 | try {
32 | return dao.create(crashInfo);
33 | } catch (SQLException e) {
34 | e.printStackTrace();
35 | }
36 | return -1;
37 | }
38 |
39 | public int delete(CrashInfo crashInfo) {
40 | return delete(crashInfo.getId());
41 | }
42 |
43 | public int delete(int id) {
44 | try {
45 | return dao.deleteById(id);
46 | } catch (SQLException e) {
47 | e.printStackTrace();
48 | }
49 | return -1;
50 | }
51 |
52 | public int clear() {
53 | try {
54 | return dao.deleteBuilder().delete();
55 | } catch (SQLException e) {
56 | e.printStackTrace();
57 | return 0;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/CrashDialog.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.ui;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.app.Service;
6 | import android.content.ClipData;
7 | import android.content.ClipboardManager;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.pm.ApplicationInfo;
12 | import android.content.pm.PackageManager;
13 | import android.graphics.Bitmap;
14 | import android.graphics.drawable.BitmapDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.os.Bundle;
17 | import android.view.WindowManager;
18 |
19 | import com.fei_ke.crashreport.Utils;
20 | import com.fei_ke.crashreport.db.CrashInfo;
21 | import com.fei_ke.crashreport.R;
22 |
23 | /**
24 | */
25 | public class CrashDialog extends Activity {
26 | private static final String CRASH_INFO = "crash_info";
27 | private static final String PACKAGE_NAME = "package_name";
28 |
29 | public static void show(Context context, CrashInfo crashInfo) {
30 | context.startActivity(createIntent(context, crashInfo));
31 | }
32 |
33 | public static Intent createIntent(Context context, CrashInfo crashInfo) {
34 | Intent intent = new Intent(context, CrashDialog.class);
35 | //ensure every intent is unique
36 | intent.setAction("dummy_action." + crashInfo.getStampTime());
37 | intent.putExtra(CRASH_INFO, crashInfo.getCrashInfo());
38 | intent.putExtra(PACKAGE_NAME, crashInfo.getPackageName());
39 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
40 | return intent;
41 | }
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
47 | String packageName = getIntent().getStringExtra(PACKAGE_NAME);
48 | String crashInfo = getIntent().getStringExtra(CRASH_INFO);
49 | showDialog(this, packageName, crashInfo);
50 | }
51 |
52 | private void showDialog(final Context context, final String packageName, final String exceptionDetail) {
53 | Drawable icon = null;
54 | String appName = null;
55 | try {
56 | PackageManager packageManager = context.getPackageManager();
57 | ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0);
58 | icon = packageManager.getApplicationIcon(info);
59 | appName = packageManager.getApplicationLabel(info).toString();
60 | } catch (PackageManager.NameNotFoundException e) {
61 | appName = packageName;
62 | e.printStackTrace();
63 | }
64 |
65 |
66 | final String title = getString(R.string.crash_report_title, appName != null ? appName : "");
67 | final AlertDialog alertDialog = new AlertDialog.Builder(context)
68 | .setTitle(title)
69 | .setMessage(exceptionDetail)
70 | .setNegativeButton(R.string.action_cancel, null)
71 | .setNeutralButton(R.string.action_confirm, new DialogInterface.OnClickListener() {
72 | @Override
73 | public void onClick(DialogInterface dialog, int which) {
74 | ClipboardManager cm = (ClipboardManager) context.getSystemService(Service.CLIPBOARD_SERVICE);
75 | cm.setPrimaryClip(ClipData.newPlainText(null, exceptionDetail));
76 | }
77 | })
78 | .setPositiveButton(R.string.action_send, new DialogInterface.OnClickListener() {
79 | @Override
80 | public void onClick(DialogInterface dialog, int which) {
81 | Intent target = new Intent(Intent.ACTION_SEND);
82 | target.setType("text/plain");
83 | target.putExtra(Intent.EXTRA_SUBJECT, title);
84 | target.putExtra(Intent.EXTRA_TEXT, exceptionDetail);
85 |
86 | Intent shareIntent = Intent.createChooser(target, getString(R.string.action_send));
87 | shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
88 | context.startActivity(shareIntent);
89 | }
90 | })
91 | .create();
92 | if (icon != null) {
93 | int dstWidth = context.getResources().getDimensionPixelSize(R.dimen.icon_size);
94 | icon = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(Utils.drawableToBitmap(icon), dstWidth, dstWidth, true));
95 | alertDialog.setIcon(icon);
96 | }
97 | alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
98 | @Override
99 | public void onDismiss(DialogInterface dialog) {
100 | finish();
101 | }
102 | });
103 | alertDialog.show();
104 | }
105 |
106 | @Override
107 | public void finish() {
108 | super.finish();
109 | overridePendingTransition(0, 0);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.ui;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.preference.PreferenceManager;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.AdapterView;
10 | import android.widget.ListView;
11 |
12 | import com.fei_ke.crashreport.MakeCrash;
13 | import com.fei_ke.crashreport.db.CrashInfo;
14 | import com.fei_ke.crashreport.R;
15 | import com.fei_ke.crashreport.db.RecordDao;
16 |
17 | import java.util.Collections;
18 | import java.util.List;
19 |
20 |
21 | public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
22 | private ListView listView;
23 | private RecordAdapter mRecordAdapter;
24 | private RecordDao recordDao;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | recordDao = new RecordDao(this);
32 |
33 | listView = (ListView) findViewById(R.id.listView);
34 |
35 | mRecordAdapter = new RecordAdapter();
36 | listView.setAdapter(mRecordAdapter);
37 | listView.setOnItemClickListener(this);
38 |
39 | SwipeDismissListViewTouchListener touchListener =
40 | new SwipeDismissListViewTouchListener(
41 | listView,
42 | new SwipeDismissListViewTouchListener.DismissCallbacks() {
43 | @Override
44 | public boolean canDismiss(int position) {
45 | return true;
46 | }
47 |
48 | @Override
49 | public void onDismiss(ListView listView, int[] reverseSortedPositions) {
50 | for (int position : reverseSortedPositions) {
51 | recordDao.delete((int) mRecordAdapter.getItemId(position));
52 | mRecordAdapter.remove(position);
53 | }
54 | mRecordAdapter.notifyDataSetChanged();
55 | }
56 | });
57 | listView.setOnTouchListener(touchListener);
58 | // Setting this scroll listener is required to ensure that during ListView scrolling,
59 | // we don't look for swipes.
60 | listView.setOnScrollListener(touchListener.makeScrollListener());
61 |
62 | }
63 |
64 | @Override
65 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
66 | CrashInfo crashInfo = mRecordAdapter.getItem(position);
67 | CrashDialog.show(this, crashInfo);
68 | }
69 |
70 | @Override
71 | protected void onResume() {
72 | super.onResume();
73 | List crashInfos = recordDao.getAll();
74 | mRecordAdapter.update(crashInfos);
75 | }
76 |
77 | @Override
78 | public boolean onCreateOptionsMenu(Menu menu) {
79 | getMenuInflater().inflate(R.menu.menu_main, menu);
80 | boolean showNotification = PreferenceManager.getDefaultSharedPreferences(this)
81 | .getBoolean("show_notification", true);
82 | menu.findItem(R.id.action_show_notification).setChecked(showNotification);
83 | return true;
84 | }
85 |
86 | @Override
87 | public boolean onOptionsItemSelected(MenuItem item) {
88 | int id = item.getItemId();
89 | if (id == R.id.action_show_notification) {
90 | item.setChecked(!item.isChecked());
91 | PreferenceManager.getDefaultSharedPreferences(this).edit()
92 | .putBoolean("show_notification", item.isChecked())
93 | .apply();
94 | } else if (id == R.id.action_clear) {
95 | clear();
96 | } else if (id == R.id.action_make_crash) {
97 | MakeCrash.makeCrash(this);
98 | } else if (id == android.R.id.home) {
99 | finish();
100 | }
101 |
102 | return super.onOptionsItemSelected(item);
103 | }
104 |
105 | private void clear() {
106 | recordDao.clear();
107 | mRecordAdapter.update(Collections.emptyList());
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/RecordAdapter.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.ui;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 | import android.widget.BaseAdapter;
6 |
7 | import com.fei_ke.crashreport.db.CrashInfo;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | */
14 | public class RecordAdapter extends BaseAdapter {
15 | private List mData = new ArrayList();
16 |
17 | @Override
18 | public int getCount() {
19 | return mData == null ? 0 : mData.size();
20 | }
21 |
22 | @Override
23 | public CrashInfo getItem(int position) {
24 | return mData.get(position);
25 | }
26 |
27 | @Override
28 | public long getItemId(int position) {
29 | return getItem(position).getId();
30 | }
31 |
32 | @Override
33 | public View getView(int position, View convertView, ViewGroup parent) {
34 | RecordItemView recordItemView = null;
35 | if (convertView == null) {
36 | recordItemView = new RecordItemView(parent.getContext());
37 | } else {
38 | recordItemView = (RecordItemView) convertView;
39 | }
40 | recordItemView.bindValue(getItem(position));
41 | return recordItemView;
42 | }
43 |
44 | public void update(List crashInfos) {
45 | mData.clear();
46 | mData.addAll(crashInfos);
47 | notifyDataSetChanged();
48 | }
49 |
50 | public void remove(int position) {
51 | mData.remove(position);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/RecordItemView.java:
--------------------------------------------------------------------------------
1 | package com.fei_ke.crashreport.ui;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.pm.ApplicationInfo;
6 | import android.content.pm.PackageManager;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.Build;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.widget.FrameLayout;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 |
15 | import com.fei_ke.crashreport.db.CrashInfo;
16 | import com.fei_ke.crashreport.R;
17 |
18 | import java.text.SimpleDateFormat;
19 | import java.util.Date;
20 |
21 | /**
22 | */
23 | public class RecordItemView extends FrameLayout {
24 | TextView
25 | textViewAppName,
26 | textViewSimpleInfo,
27 | textViewDate;
28 | ImageView imageViewIcon;
29 |
30 | public RecordItemView(Context context) {
31 | super(context);
32 | init();
33 | }
34 |
35 |
36 | public RecordItemView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | init();
39 | }
40 |
41 | public RecordItemView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | init();
44 | }
45 |
46 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
47 | public RecordItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
48 | super(context, attrs, defStyleAttr, defStyleRes);
49 | init();
50 | }
51 |
52 | private void init() {
53 | View view = View.inflate(getContext(), R.layout.view_record_item, this);
54 | textViewAppName = (TextView) view.findViewById(R.id.textViewAppName);
55 | textViewSimpleInfo = (TextView) view.findViewById(R.id.textViewSimpleInfo);
56 | textViewDate = (TextView) view.findViewById(R.id.textViewDate);
57 | imageViewIcon = (ImageView) view.findViewById(R.id.imageViewIcon);
58 | }
59 |
60 | public void bindValue(CrashInfo crashInfo) {
61 | Drawable icon = null;
62 | String appName = null;
63 | String packageName = crashInfo.getPackageName();
64 | try {
65 | Context context = getContext();
66 | PackageManager packageManager = context.getPackageManager();
67 | icon = packageManager.getApplicationIcon(packageName);
68 | ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0);
69 | appName = packageManager.getApplicationLabel(info).toString();
70 | } catch (PackageManager.NameNotFoundException e) {
71 | appName = packageName;
72 | e.printStackTrace();
73 | }
74 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
75 | textViewAppName.setText(appName);
76 | imageViewIcon.setImageDrawable(icon);
77 | textViewSimpleInfo.setText(crashInfo.getSimpleInfo());
78 |
79 | Date date = new Date();
80 | date.setTime((long) crashInfo.getStampTime() * 1000);
81 | textViewDate.setText(sdf.format(date));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/SwipeDismissListViewTouchListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fei_ke.crashreport.ui;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.animation.ValueAnimator;
22 | import android.graphics.Rect;
23 | import android.os.SystemClock;
24 | import android.view.MotionEvent;
25 | import android.view.VelocityTracker;
26 | import android.view.View;
27 | import android.view.ViewConfiguration;
28 | import android.view.ViewGroup;
29 | import android.widget.AbsListView;
30 | import android.widget.ListView;
31 |
32 | import java.util.ArrayList;
33 | import java.util.Collections;
34 | import java.util.List;
35 |
36 | /**
37 | * A {@link android.view.View.OnTouchListener} that makes the list items in a {@link android.widget.ListView}
38 | * dismissable. {@link android.widget.ListView} is given special treatment because by default it handles touches
39 | * for its list items... i.e. it's in charge of drawing the pressed state (the list selector),
40 | * handling list item clicks, etc.
41 | *
42 | * After creating the listener, the caller should also call
43 | * {@link android.widget.ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}, passing
44 | * in the scroll listener returned by {@link #makeScrollListener()}. If a scroll listener is
45 | * already assigned, the caller should still pass scroll changes through to this listener. This will
46 | * ensure that this {@link SwipeDismissListViewTouchListener} is paused during list view
47 | * scrolling.
48 | *
49 | * Example usage:
50 | *
51 | *
52 | * SwipeDismissListViewTouchListener touchListener =
53 | * new SwipeDismissListViewTouchListener(
54 | * listView,
55 | * new SwipeDismissListViewTouchListener.OnDismissCallback() {
56 | * public void onDismiss(ListView listView, int[] reverseSortedPositions) {
57 | * for (int position : reverseSortedPositions) {
58 | * adapter.remove(adapter.getItem(position));
59 | * }
60 | * adapter.notifyDataSetChanged();
61 | * }
62 | * });
63 | * listView.setOnTouchListener(touchListener);
64 | * listView.setOnScrollListener(touchListener.makeScrollListener());
65 | *
66 | *
67 | * This class Requires API level 12 or later due to use of {@link
68 | * android.view.ViewPropertyAnimator}.
69 | *
70 | * For a generalized {@link android.view.View.OnTouchListener} that makes any view dismissable,
71 | * see {@link SwipeDismissTouchListener}.
72 | *
73 | * @see SwipeDismissTouchListener
74 | */
75 | public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
76 | // Cached ViewConfiguration and system-wide constant values
77 | private int mSlop;
78 | private int mMinFlingVelocity;
79 | private int mMaxFlingVelocity;
80 | private long mAnimationTime;
81 |
82 | // Fixed properties
83 | private ListView mListView;
84 | private DismissCallbacks mCallbacks;
85 | private int mViewWidth = 1; // 1 and not 0 to prevent dividing by zero
86 |
87 | // Transient properties
88 | private List mPendingDismisses = new ArrayList();
89 | private int mDismissAnimationRefCount = 0;
90 | private float mDownX;
91 | private float mDownY;
92 | private boolean mSwiping;
93 | private int mSwipingSlop;
94 | private VelocityTracker mVelocityTracker;
95 | private int mDownPosition;
96 | private View mDownView;
97 | private boolean mPaused;
98 |
99 | /**
100 | * The callback interface used by {@link SwipeDismissListViewTouchListener} to inform its client
101 | * about a successful dismissal of one or more list item positions.
102 | */
103 | public interface DismissCallbacks {
104 | /**
105 | * Called to determine whether the given position can be dismissed.
106 | */
107 | boolean canDismiss(int position);
108 |
109 | /**
110 | * Called when the user has indicated they she would like to dismiss one or more list item
111 | * positions.
112 | *
113 | * @param listView The originating {@link android.widget.ListView}.
114 | * @param reverseSortedPositions An array of positions to dismiss, sorted in descending
115 | * order for convenience.
116 | */
117 | void onDismiss(ListView listView, int[] reverseSortedPositions);
118 | }
119 |
120 | /**
121 | * Constructs a new swipe-to-dismiss touch listener for the given list view.
122 | *
123 | * @param listView The list view whose items should be dismissable.
124 | * @param callbacks The callback to trigger when the user has indicated that she would like to
125 | * dismiss one or more list items.
126 | */
127 | public SwipeDismissListViewTouchListener(ListView listView, DismissCallbacks callbacks) {
128 | ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
129 | mSlop = vc.getScaledTouchSlop();
130 | mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
131 | mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
132 | mAnimationTime = listView.getContext().getResources().getInteger(
133 | android.R.integer.config_shortAnimTime);
134 | mListView = listView;
135 | mCallbacks = callbacks;
136 | }
137 |
138 | /**
139 | * Enables or disables (pauses or resumes) watching for swipe-to-dismiss gestures.
140 | *
141 | * @param enabled Whether or not to watch for gestures.
142 | */
143 | public void setEnabled(boolean enabled) {
144 | mPaused = !enabled;
145 | }
146 |
147 | /**
148 | * Returns an {@link android.widget.AbsListView.OnScrollListener} to be added to the {@link
149 | * android.widget.ListView} using {@link android.widget.ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}.
150 | * If a scroll listener is already assigned, the caller should still pass scroll changes through
151 | * to this listener. This will ensure that this {@link SwipeDismissListViewTouchListener} is
152 | * paused during list view scrolling.
153 | *
154 | * @see SwipeDismissListViewTouchListener
155 | */
156 | public AbsListView.OnScrollListener makeScrollListener() {
157 | return new AbsListView.OnScrollListener() {
158 | @Override
159 | public void onScrollStateChanged(AbsListView absListView, int scrollState) {
160 | setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
161 | }
162 |
163 | @Override
164 | public void onScroll(AbsListView absListView, int i, int i1, int i2) {
165 | }
166 | };
167 | }
168 |
169 | @Override
170 | public boolean onTouch(View view, MotionEvent motionEvent) {
171 | if (mViewWidth < 2) {
172 | mViewWidth = mListView.getWidth();
173 | }
174 |
175 | switch (motionEvent.getActionMasked()) {
176 | case MotionEvent.ACTION_DOWN: {
177 | if (mPaused) {
178 | return false;
179 | }
180 |
181 | // TODO: ensure this is a finger, and set a flag
182 |
183 | // Find the child view that was touched (perform a hit test)
184 | Rect rect = new Rect();
185 | int childCount = mListView.getChildCount();
186 | int[] listViewCoords = new int[2];
187 | mListView.getLocationOnScreen(listViewCoords);
188 | int x = (int) motionEvent.getRawX() - listViewCoords[0];
189 | int y = (int) motionEvent.getRawY() - listViewCoords[1];
190 | View child;
191 | for (int i = 0; i < childCount; i++) {
192 | child = mListView.getChildAt(i);
193 | child.getHitRect(rect);
194 | if (rect.contains(x, y)) {
195 | mDownView = child;
196 | break;
197 | }
198 | }
199 |
200 | if (mDownView != null) {
201 | mDownX = motionEvent.getRawX();
202 | mDownY = motionEvent.getRawY();
203 | mDownPosition = mListView.getPositionForView(mDownView);
204 | if (mCallbacks.canDismiss(mDownPosition)) {
205 | mVelocityTracker = VelocityTracker.obtain();
206 | mVelocityTracker.addMovement(motionEvent);
207 | } else {
208 | mDownView = null;
209 | }
210 | }
211 | return false;
212 | }
213 |
214 | case MotionEvent.ACTION_CANCEL: {
215 | if (mVelocityTracker == null) {
216 | break;
217 | }
218 |
219 | if (mDownView != null && mSwiping) {
220 | // cancel
221 | mDownView.animate()
222 | .translationX(0)
223 | .alpha(1)
224 | .setDuration(mAnimationTime)
225 | .setListener(null);
226 | }
227 | mVelocityTracker.recycle();
228 | mVelocityTracker = null;
229 | mDownX = 0;
230 | mDownY = 0;
231 | mDownView = null;
232 | mDownPosition = ListView.INVALID_POSITION;
233 | mSwiping = false;
234 | break;
235 | }
236 |
237 | case MotionEvent.ACTION_UP: {
238 | if (mVelocityTracker == null) {
239 | break;
240 | }
241 |
242 | float deltaX = motionEvent.getRawX() - mDownX;
243 | mVelocityTracker.addMovement(motionEvent);
244 | mVelocityTracker.computeCurrentVelocity(1000);
245 | float velocityX = mVelocityTracker.getXVelocity();
246 | float absVelocityX = Math.abs(velocityX);
247 | float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
248 | boolean dismiss = false;
249 | boolean dismissRight = false;
250 | if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
251 | dismiss = true;
252 | dismissRight = deltaX > 0;
253 | } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
254 | && absVelocityY < absVelocityX && mSwiping) {
255 | // dismiss only if flinging in the same direction as dragging
256 | dismiss = (velocityX < 0) == (deltaX < 0);
257 | dismissRight = mVelocityTracker.getXVelocity() > 0;
258 | }
259 | if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
260 | // dismiss
261 | final View downView = mDownView; // mDownView gets null'd before animation ends
262 | final int downPosition = mDownPosition;
263 | ++mDismissAnimationRefCount;
264 | mDownView.animate()
265 | .translationX(dismissRight ? mViewWidth : -mViewWidth)
266 | .alpha(0)
267 | .setDuration(mAnimationTime)
268 | .setListener(new AnimatorListenerAdapter() {
269 | @Override
270 | public void onAnimationEnd(Animator animation) {
271 | performDismiss(downView, downPosition);
272 | }
273 | });
274 | } else {
275 | // cancel
276 | mDownView.animate()
277 | .translationX(0)
278 | .alpha(1)
279 | .setDuration(mAnimationTime)
280 | .setListener(null);
281 | }
282 | mVelocityTracker.recycle();
283 | mVelocityTracker = null;
284 | mDownX = 0;
285 | mDownY = 0;
286 | mDownView = null;
287 | mDownPosition = ListView.INVALID_POSITION;
288 | mSwiping = false;
289 | break;
290 | }
291 |
292 | case MotionEvent.ACTION_MOVE: {
293 | if (mVelocityTracker == null || mPaused) {
294 | break;
295 | }
296 |
297 | mVelocityTracker.addMovement(motionEvent);
298 | float deltaX = motionEvent.getRawX() - mDownX;
299 | float deltaY = motionEvent.getRawY() - mDownY;
300 | if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
301 | mSwiping = true;
302 | mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
303 | mListView.requestDisallowInterceptTouchEvent(true);
304 |
305 | // Cancel ListView's touch (un-highlighting the item)
306 | MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
307 | cancelEvent.setAction(MotionEvent.ACTION_CANCEL |
308 | (motionEvent.getActionIndex()
309 | << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
310 | mListView.onTouchEvent(cancelEvent);
311 | cancelEvent.recycle();
312 | }
313 |
314 | if (mSwiping) {
315 | mDownView.setTranslationX(deltaX - mSwipingSlop);
316 | mDownView.setAlpha(Math.max(0f, Math.min(1f,
317 | 1f - 2f * Math.abs(deltaX) / mViewWidth)));
318 | return true;
319 | }
320 | break;
321 | }
322 | }
323 | return false;
324 | }
325 |
326 | class PendingDismissData implements Comparable {
327 | public int position;
328 | public View view;
329 |
330 | public PendingDismissData(int position, View view) {
331 | this.position = position;
332 | this.view = view;
333 | }
334 |
335 | @Override
336 | public int compareTo(PendingDismissData other) {
337 | // Sort by descending position
338 | return other.position - position;
339 | }
340 | }
341 |
342 | private void performDismiss(final View dismissView, final int dismissPosition) {
343 | // Animate the dismissed list item to zero-height and fire the dismiss callback when
344 | // all dismissed list item animations have completed. This triggers layout on each animation
345 | // frame; in the future we may want to do something smarter and more performant.
346 |
347 | final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
348 | final int originalHeight = dismissView.getHeight();
349 |
350 | ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
351 |
352 | animator.addListener(new AnimatorListenerAdapter() {
353 | @Override
354 | public void onAnimationEnd(Animator animation) {
355 | --mDismissAnimationRefCount;
356 | if (mDismissAnimationRefCount == 0) {
357 | // No active animations, process all pending dismisses.
358 | // Sort by descending position
359 | Collections.sort(mPendingDismisses);
360 |
361 | int[] dismissPositions = new int[mPendingDismisses.size()];
362 | for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
363 | dismissPositions[i] = mPendingDismisses.get(i).position;
364 | }
365 | mCallbacks.onDismiss(mListView, dismissPositions);
366 |
367 | // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
368 | // animation with a stale position
369 | mDownPosition = ListView.INVALID_POSITION;
370 |
371 | ViewGroup.LayoutParams lp;
372 | for (PendingDismissData pendingDismiss : mPendingDismisses) {
373 | // Reset view presentation
374 | pendingDismiss.view.setAlpha(1f);
375 | pendingDismiss.view.setTranslationX(0);
376 | lp = pendingDismiss.view.getLayoutParams();
377 | lp.height = originalHeight;
378 | pendingDismiss.view.setLayoutParams(lp);
379 | }
380 |
381 | // Send a cancel event
382 | long time = SystemClock.uptimeMillis();
383 | MotionEvent cancelEvent = MotionEvent.obtain(time, time,
384 | MotionEvent.ACTION_CANCEL, 0, 0, 0);
385 | mListView.dispatchTouchEvent(cancelEvent);
386 |
387 | mPendingDismisses.clear();
388 | }
389 | }
390 | });
391 |
392 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
393 | @Override
394 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
395 | lp.height = (Integer) valueAnimator.getAnimatedValue();
396 | dismissView.setLayoutParams(lp);
397 | }
398 | });
399 |
400 | mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
401 | animator.start();
402 | }
403 | }
404 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fei_ke/crashreport/ui/SwipeDismissTouchListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fei_ke.crashreport.ui;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.animation.ValueAnimator;
22 | import android.view.MotionEvent;
23 | import android.view.VelocityTracker;
24 | import android.view.View;
25 | import android.view.ViewConfiguration;
26 | import android.view.ViewGroup;
27 |
28 | /**
29 | * A {@link android.view.View.OnTouchListener} that makes any {@link android.view.View} dismissable when the
30 | * user swipes (drags her finger) horizontally across the view.
31 | *
32 | * For {@link android.widget.ListView} list items that don't manage their own touch events
33 | * (i.e. you're using
34 | * {@link android.widget.ListView#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener)}
35 | * or an equivalent listener on {@link android.app.ListActivity} or
36 | * {@link android.app.ListFragment}, use {@link SwipeDismissListViewTouchListener} instead.
37 | *
38 | * Example usage:
39 | *
40 | *
41 | * view.setOnTouchListener(new SwipeDismissTouchListener(
42 | * view,
43 | * null, // Optional token/cookie object
44 | * new SwipeDismissTouchListener.OnDismissCallback() {
45 | * public void onDismiss(View view, Object token) {
46 | * parent.removeView(view);
47 | * }
48 | * }));
49 | *
50 | *
51 | * This class Requires API level 12 or later due to use of {@link
52 | * android.view.ViewPropertyAnimator}.
53 | *
54 | * @see SwipeDismissListViewTouchListener
55 | */
56 | public class SwipeDismissTouchListener implements View.OnTouchListener {
57 | // Cached ViewConfiguration and system-wide constant values
58 | private int mSlop;
59 | private int mMinFlingVelocity;
60 | private int mMaxFlingVelocity;
61 | private long mAnimationTime;
62 |
63 | // Fixed properties
64 | private View mView;
65 | private DismissCallbacks mCallbacks;
66 | private int mViewWidth = 1; // 1 and not 0 to prevent dividing by zero
67 |
68 | // Transient properties
69 | private float mDownX;
70 | private float mDownY;
71 | private boolean mSwiping;
72 | private int mSwipingSlop;
73 | private Object mToken;
74 | private VelocityTracker mVelocityTracker;
75 | private float mTranslationX;
76 |
77 | /**
78 | * The callback interface used by {@link SwipeDismissTouchListener} to inform its client
79 | * about a successful dismissal of the view for which it was created.
80 | */
81 | public interface DismissCallbacks {
82 | /**
83 | * Called to determine whether the view can be dismissed.
84 | */
85 | boolean canDismiss(Object token);
86 |
87 | /**
88 | * Called when the user has indicated they she would like to dismiss the view.
89 | *
90 | * @param view The originating {@link android.view.View} to be dismissed.
91 | * @param token The optional token passed to this object's constructor.
92 | */
93 | void onDismiss(View view, Object token);
94 | }
95 |
96 | /**
97 | * Constructs a new swipe-to-dismiss touch listener for the given view.
98 | *
99 | * @param view The view to make dismissable.
100 | * @param token An optional token/cookie object to be passed through to the callback.
101 | * @param callbacks The callback to trigger when the user has indicated that she would like to
102 | * dismiss this view.
103 | */
104 | public SwipeDismissTouchListener(View view, Object token, DismissCallbacks callbacks) {
105 | ViewConfiguration vc = ViewConfiguration.get(view.getContext());
106 | mSlop = vc.getScaledTouchSlop();
107 | mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
108 | mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
109 | mAnimationTime = view.getContext().getResources().getInteger(
110 | android.R.integer.config_shortAnimTime);
111 | mView = view;
112 | mToken = token;
113 | mCallbacks = callbacks;
114 | }
115 |
116 | @Override
117 | public boolean onTouch(View view, MotionEvent motionEvent) {
118 | // offset because the view is translated during swipe
119 | motionEvent.offsetLocation(mTranslationX, 0);
120 |
121 | if (mViewWidth < 2) {
122 | mViewWidth = mView.getWidth();
123 | }
124 |
125 | switch (motionEvent.getActionMasked()) {
126 | case MotionEvent.ACTION_DOWN: {
127 | // TODO: ensure this is a finger, and set a flag
128 | mDownX = motionEvent.getRawX();
129 | mDownY = motionEvent.getRawY();
130 | if (mCallbacks.canDismiss(mToken)) {
131 | mVelocityTracker = VelocityTracker.obtain();
132 | mVelocityTracker.addMovement(motionEvent);
133 | }
134 | return false;
135 | }
136 |
137 | case MotionEvent.ACTION_UP: {
138 | if (mVelocityTracker == null) {
139 | break;
140 | }
141 |
142 | float deltaX = motionEvent.getRawX() - mDownX;
143 | mVelocityTracker.addMovement(motionEvent);
144 | mVelocityTracker.computeCurrentVelocity(1000);
145 | float velocityX = mVelocityTracker.getXVelocity();
146 | float absVelocityX = Math.abs(velocityX);
147 | float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
148 | boolean dismiss = false;
149 | boolean dismissRight = false;
150 | if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
151 | dismiss = true;
152 | dismissRight = deltaX > 0;
153 | } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
154 | && absVelocityY < absVelocityX
155 | && absVelocityY < absVelocityX && mSwiping) {
156 | // dismiss only if flinging in the same direction as dragging
157 | dismiss = (velocityX < 0) == (deltaX < 0);
158 | dismissRight = mVelocityTracker.getXVelocity() > 0;
159 | }
160 | if (dismiss) {
161 | // dismiss
162 | mView.animate()
163 | .translationX(dismissRight ? mViewWidth : -mViewWidth)
164 | .alpha(0)
165 | .setDuration(mAnimationTime)
166 | .setListener(new AnimatorListenerAdapter() {
167 | @Override
168 | public void onAnimationEnd(Animator animation) {
169 | performDismiss();
170 | }
171 | });
172 | } else if (mSwiping) {
173 | // cancel
174 | mView.animate()
175 | .translationX(0)
176 | .alpha(1)
177 | .setDuration(mAnimationTime)
178 | .setListener(null);
179 | }
180 | mVelocityTracker.recycle();
181 | mVelocityTracker = null;
182 | mTranslationX = 0;
183 | mDownX = 0;
184 | mDownY = 0;
185 | mSwiping = false;
186 | break;
187 | }
188 |
189 | case MotionEvent.ACTION_CANCEL: {
190 | if (mVelocityTracker == null) {
191 | break;
192 | }
193 |
194 | mView.animate()
195 | .translationX(0)
196 | .alpha(1)
197 | .setDuration(mAnimationTime)
198 | .setListener(null);
199 | mVelocityTracker.recycle();
200 | mVelocityTracker = null;
201 | mTranslationX = 0;
202 | mDownX = 0;
203 | mDownY = 0;
204 | mSwiping = false;
205 | break;
206 | }
207 |
208 | case MotionEvent.ACTION_MOVE: {
209 | if (mVelocityTracker == null) {
210 | break;
211 | }
212 |
213 | mVelocityTracker.addMovement(motionEvent);
214 | float deltaX = motionEvent.getRawX() - mDownX;
215 | float deltaY = motionEvent.getRawY() - mDownY;
216 | if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
217 | mSwiping = true;
218 | mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
219 | mView.getParent().requestDisallowInterceptTouchEvent(true);
220 |
221 | // Cancel listview's touch
222 | MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
223 | cancelEvent.setAction(MotionEvent.ACTION_CANCEL |
224 | (motionEvent.getActionIndex() <<
225 | MotionEvent.ACTION_POINTER_INDEX_SHIFT));
226 | mView.onTouchEvent(cancelEvent);
227 | cancelEvent.recycle();
228 | }
229 |
230 | if (mSwiping) {
231 | mTranslationX = deltaX;
232 | mView.setTranslationX(deltaX - mSwipingSlop);
233 | // TODO: use an ease-out interpolator or such
234 | mView.setAlpha(Math.max(0f, Math.min(1f,
235 | 1f - 2f * Math.abs(deltaX) / mViewWidth)));
236 | return true;
237 | }
238 | break;
239 | }
240 | }
241 | return false;
242 | }
243 |
244 | private void performDismiss() {
245 | // Animate the dismissed view to zero-height and then fire the dismiss callback.
246 | // This triggers layout on each animation frame; in the future we may want to do something
247 | // smarter and more performant.
248 |
249 | final ViewGroup.LayoutParams lp = mView.getLayoutParams();
250 | final int originalHeight = mView.getHeight();
251 |
252 | ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
253 |
254 | animator.addListener(new AnimatorListenerAdapter() {
255 | @Override
256 | public void onAnimationEnd(Animator animation) {
257 | mCallbacks.onDismiss(mView, mToken);
258 | // Reset view presentation
259 | mView.setAlpha(1f);
260 | mView.setTranslationX(0);
261 | lp.height = originalHeight;
262 | mView.setLayoutParams(lp);
263 | }
264 | });
265 |
266 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
267 | @Override
268 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
269 | lp.height = (Integer) valueAnimator.getAnimatedValue();
270 | mView.setLayoutParams(lp);
271 | }
272 | });
273 |
274 | animator.start();
275 | }
276 | }
277 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notification_small.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_record_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
40 |
41 |
48 |
49 |
50 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CrashReporter
4 | Hello world!
5 | 设置
6 | 清除
7 | 显示通知
8 | 测试异常
9 | %s 错误报告
10 | 取消
11 | 复制
12 | 发送
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 50dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CrashReporter
4 | Hello world!
5 | Settings
6 | Clear
7 | Show Notification
8 | Make Crash
9 | %s Crash Reporter
10 | Cancel
11 | Copy
12 | Send
13 |
14 |
15 | - android
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | STORE_FILE_PATH=store_file_path
20 | STORE_PASSWORD=store_password
21 | KEY_ALIAS=alias
22 | KEY_PASSWORD=kay_pass
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fei-ke/CrashReport/152019028d617cf2bd626a7b42bdfc15a81d59a6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 21 21:49:39 CST 2019
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------