Skip to content

Commit fe8440d

Browse files
committed
add network engine
1 parent a4e81db commit fe8440d

133 files changed

Lines changed: 2266 additions & 245 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@
4646
android:theme="@style/AppTheme">
4747
<intent-filter>
4848
<action android:name="android.intent.action.MAIN" />
49-
5049
<category android:name="android.intent.category.LAUNCHER" />
5150
</intent-filter>
5251
</activity>
53-
<activity android:name="com.joe.commom_library.zxing.activity.CaptureActivity" />
54-
<activity android:name="com.joe.main.ui.AboutActivity" />
52+
<activity android:name="com.joe.main.ui.AboutActivity"></activity>
5553
</application>
5654

5755
</manifest>

app/src/main/java/com/joe/application/MyApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.joe.base.BaseApplication;
44
import com.joe.base.config.ModuleConfig;
5-
import com.joe.commom_library.utils.Utils;
5+
import com.joe.common.crash.CrashHandler;
6+
import com.joe.common.utils.Utils;
67

78
/**
89
* desc: MyApplication.java
@@ -13,7 +14,8 @@ public class MyApplication extends BaseApplication {
1314
@Override
1415
public void onCreate() {
1516
super.onCreate();
16-
Utils.init(this);
17+
Utils.init(this);//初始化工具类中上下文
18+
CrashHandler.init(this);//初始化全局异常捕获
1719
//初始化组件(靠前)
1820
ModuleConfig.getInstance().initModuleAhead(this);
1921
//....

commom_library/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ android {
3636
dependencies {
3737
api fileTree(include: ['*.jar'], dir: 'libs')
3838
def libs = rootProject.ext.dependencies
39-
api rootProject.ext.support["design"]
40-
api rootProject.ext.support["appcompat-v7"]
39+
api rootProject.ext.support.design
40+
api rootProject.ext.support.support_v4
41+
api rootProject.ext.support.card_view
4142
api project(':res_library')
4243
//阿里路由框架
4344
api libs.arouter_api
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.joe.commom_library" >
2+
package="com.joe.common">
33

4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
45
<uses-permission android:name="android.permission.VIBRATE" />
6+
<application>
7+
<provider
8+
android:name=".crash.CrashFileProvider"
9+
android:authorities="${applicationId}.crashfileprovider"
10+
android:exported="false"
11+
android:grantUriPermissions="true">
12+
<meta-data
13+
android:name="android.support.FILE_PROVIDER_PATHS"
14+
android:resource="@xml/file_paths" />
15+
</provider>
16+
17+
<activity android:name=".crash.CrashActivity" />
18+
<activity android:name=".zxing.activity.CaptureActivity" />
19+
</application>
520
</manifest>

commom_library/src/main/java/com/joe/commom_library/base/BaseDialog.java renamed to commom_library/src/main/java/com/joe/common/base/BaseDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.joe.commom_library.base;
1+
package com.joe.common.base;
22

33
import android.app.Dialog;
44
import android.content.Context;
@@ -16,7 +16,7 @@
1616
import android.widget.ImageView;
1717
import android.widget.TextView;
1818

19-
import com.joe.commom_library.R;
19+
import com.joe.common.R;
2020

2121
/**
2222
* desc : Dialog 基类

commom_library/src/main/java/com/joe/commom_library/base/BaseDialogFragment.java renamed to commom_library/src/main/java/com/joe/common/base/BaseDialogFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.joe.commom_library.base;
1+
package com.joe.common.base;
22

33
import android.app.Dialog;
44
import android.os.Bundle;

commom_library/src/main/java/com/joe/commom_library/base/BaseRecyclerViewAdapter.java renamed to commom_library/src/main/java/com/joe/common/base/BaseRecyclerViewAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.joe.commom_library.base;
1+
package com.joe.common.base;
22

33
import android.content.Context;
44
import android.support.annotation.IdRes;
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
package com.joe.common.crash;
2+
3+
import android.Manifest;
4+
import android.annotation.SuppressLint;
5+
import android.content.ClipData;
6+
import android.content.ClipboardManager;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.content.pm.PackageManager;
10+
import android.graphics.Bitmap;
11+
import android.graphics.Canvas;
12+
import android.net.Uri;
13+
import android.os.Build;
14+
import android.os.Bundle;
15+
import android.os.Environment;
16+
import android.support.annotation.NonNull;
17+
import android.support.v4.app.ActivityCompat;
18+
import android.support.v4.content.ContextCompat;
19+
import android.support.v4.content.FileProvider;
20+
import android.support.v7.app.AppCompatActivity;
21+
import android.util.Log;
22+
import android.view.MenuItem;
23+
import android.view.View;
24+
import android.widget.ImageView;
25+
import android.widget.PopupMenu;
26+
import android.widget.ScrollView;
27+
import android.widget.TextView;
28+
import android.widget.Toast;
29+
30+
import com.joe.common.R;
31+
import com.tbruyelle.rxpermissions2.RxPermissions;
32+
33+
import java.io.File;
34+
import java.io.FileNotFoundException;
35+
import java.io.FileOutputStream;
36+
import java.io.IOException;
37+
import java.text.SimpleDateFormat;
38+
39+
/**
40+
* desc: CrashActivity.java
41+
* author: Joe
42+
* created at: 2019/1/23 下午2:17
43+
*/
44+
public class CrashActivity extends AppCompatActivity {
45+
46+
public static final String CRASH_MODEL = "crash_model";
47+
@SuppressLint("SimpleDateFormat")
48+
private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
49+
private CrashModel model;
50+
51+
@Override
52+
protected void onCreate(Bundle savedInstanceState) {
53+
super.onCreate(savedInstanceState);
54+
setContentView(R.layout.activity_crash);
55+
model = getIntent().getParcelableExtra(CRASH_MODEL);
56+
if (model == null) {
57+
return;
58+
}
59+
TextView tv_packageName = findViewById(R.id.tv_packageName);
60+
TextView textMessage = findViewById(R.id.textMessage);
61+
TextView tv_className = findViewById(R.id.tv_className);
62+
TextView tv_methodName = findViewById(R.id.tv_methodName);
63+
TextView tv_lineNumber = findViewById(R.id.tv_lineNumber);
64+
TextView tv_exceptionType = findViewById(R.id.tv_exceptionType);
65+
TextView tv_fullException = findViewById(R.id.tv_fullException);
66+
TextView tv_time = findViewById(R.id.tv_time);
67+
TextView tv_model = findViewById(R.id.tv_model);
68+
TextView tv_brand = findViewById(R.id.tv_brand);
69+
TextView tv_version = findViewById(R.id.tv_version);
70+
ImageView iv_more = findViewById(R.id.iv_more);
71+
//
72+
tv_packageName.setText(model.getPackageName());
73+
textMessage.setText(model.getExceptionMsg());
74+
tv_className.setText(model.getFileName());
75+
tv_methodName.setText(model.getMethodName());
76+
tv_lineNumber.setText(String.valueOf(model.getLineNumber()));
77+
tv_exceptionType.setText(model.getExceptionType());
78+
tv_fullException.setText(model.getFullException());
79+
tv_time.setText(df.format(model.getTime()));
80+
81+
tv_model.setText(model.getDevice().getModel());
82+
tv_brand.setText(model.getDevice().getBrand());
83+
tv_version.setText(model.getDevice().getVersion());
84+
85+
iv_more.setOnClickListener(v -> {
86+
PopupMenu menu = new PopupMenu(CrashActivity.this, v);
87+
menu.inflate(R.menu.menu_more);
88+
menu.show();
89+
menu.setOnMenuItemClickListener(item -> {
90+
int id = item.getItemId();
91+
if (id == R.id.menu_copy_text) {
92+
String crashText = getShareText(model);
93+
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
94+
if (cm != null) {
95+
ClipData mClipData = ClipData.newPlainText("crash", crashText);
96+
cm.setPrimaryClip(mClipData);
97+
showToast("拷贝成功");
98+
}
99+
} else if (id == R.id.menu_share_text) {
100+
String crashText = getShareText(model);
101+
shareText(crashText);
102+
} else if (id == R.id.menu_share_image) {
103+
if (ContextCompat.checkSelfPermission(CrashActivity.this,
104+
Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED ||
105+
ContextCompat.checkSelfPermission(CrashActivity.this,
106+
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
107+
requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
108+
Manifest.permission.WRITE_EXTERNAL_STORAGE);
109+
} else {
110+
shareImage();
111+
}
112+
}
113+
return true;
114+
});
115+
116+
});
117+
118+
}
119+
120+
private String getShareText(CrashModel model) {
121+
StringBuilder builder = new StringBuilder();
122+
123+
builder.append("崩溃信息:")
124+
.append("\n")
125+
.append(model.getExceptionMsg())
126+
.append("\n");
127+
builder.append("\n");
128+
129+
builder.append("类名:")
130+
.append(model.getFileName()).append("\n");
131+
builder.append("\n");
132+
133+
builder.append("包名:")
134+
.append(model.getPackageName()).append("\n");
135+
builder.append("\n");
136+
137+
builder.append("方法:").append(model.getMethodName()).append("\n");
138+
builder.append("\n");
139+
140+
builder.append("行数:").append(model.getLineNumber()).append("\n");
141+
builder.append("\n");
142+
143+
builder.append("类型:").append(model.getExceptionType()).append("\n");
144+
builder.append("\n");
145+
146+
builder.append("时间:").append(df.format(model.getTime())).append("\n");
147+
builder.append("\n");
148+
149+
builder.append("设备名称:").append(model.getDevice().getModel()).append("\n");
150+
builder.append("\n");
151+
152+
builder.append("设备厂商:").append(model.getDevice().getBrand()).append("\n");
153+
builder.append("\n");
154+
155+
builder.append("系统版本:").append(model.getDevice().getVersion()).append("\n");
156+
builder.append("\n");
157+
158+
builder.append("全部信息:")
159+
.append("\n")
160+
.append(model.getFullException()).append("\n");
161+
162+
return builder.toString();
163+
}
164+
165+
private void shareText(String text) {
166+
Intent intent = new Intent(Intent.ACTION_SEND);
167+
intent.setType("text/plain");
168+
intent.putExtra(Intent.EXTRA_SUBJECT, "崩溃日志:");
169+
intent.putExtra(Intent.EXTRA_TEXT, text);
170+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
171+
startActivity(Intent.createChooser(intent, "分享到"));
172+
}
173+
174+
175+
@SuppressLint("CheckResult")
176+
private void requestPermission(String... permissions) {
177+
new RxPermissions(this).request(permissions)
178+
.subscribe(granted -> {
179+
if (granted) {
180+
// I can control the camera now
181+
} else {
182+
// Oups permission denied
183+
}
184+
});
185+
}
186+
187+
188+
public Bitmap getBitmapByView(ScrollView view) {
189+
if (view == null) return null;
190+
int height = 0;
191+
for (int i = 0; i < view.getChildCount(); i++) {
192+
height += view.getChildAt(i).getHeight();
193+
}
194+
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), height, Bitmap.Config.ARGB_8888);
195+
Canvas canvas = new Canvas(bitmap);
196+
canvas.drawRGB(255, 255, 255);
197+
view.draw(canvas);
198+
return bitmap;
199+
}
200+
201+
private File BitmapToFile(Bitmap bitmap) {
202+
if (bitmap == null) return null;
203+
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
204+
.getAbsolutePath();
205+
File imageFile = new File(path, "crash-" + df.format(model.getTime()) + ".jpg");
206+
try {
207+
FileOutputStream out = new FileOutputStream(imageFile);
208+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
209+
out.flush();
210+
out.close();
211+
bitmap.recycle();
212+
} catch (FileNotFoundException e) {
213+
e.printStackTrace();
214+
} catch (IOException e) {
215+
e.printStackTrace();
216+
}
217+
return imageFile;
218+
}
219+
220+
private void shareImage() {
221+
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
222+
showToast("未插入sd卡");
223+
return;
224+
}
225+
File file = BitmapToFile(getBitmapByView(findViewById(R.id.scrollView)));
226+
if (file == null || !file.exists()) {
227+
showToast("图片文件不存在");
228+
return;
229+
}
230+
231+
Intent intent = new Intent();
232+
intent.setAction(Intent.ACTION_SEND);
233+
intent.setType("image/*");
234+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
235+
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(),
236+
getApplicationContext().getPackageName() + ".crashfileprovider", file);
237+
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
238+
} else {
239+
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
240+
}
241+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
242+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
243+
startActivity(Intent.createChooser(intent, "分享图片"));
244+
}
245+
246+
private void showToast(String text) {
247+
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
248+
}
249+
250+
@Override
251+
public void onBackPressed() {
252+
this.finish();
253+
}
254+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.joe.common.crash;
2+
3+
import android.support.v4.content.FileProvider;
4+
5+
public class CrashFileProvider extends FileProvider {
6+
}

0 commit comments

Comments
 (0)