Skip to content

Commit 2638402

Browse files
committed
see 09/26 log
1 parent 137f633 commit 2638402

File tree

9 files changed

+81
-36
lines changed

9 files changed

+81
-36
lines changed

app/src/main/java/com/blankj/androidutilcode/UtilsApp.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.blankj.androidutilcode;
22

3+
import android.widget.Toast;
4+
35
import com.blankj.androidutilcode.base.BaseApplication;
46
import com.blankj.subutil.util.ThreadPoolUtils;
57
import com.blankj.utilcode.util.CrashUtils;
@@ -68,7 +70,13 @@ public void initLog() {
6870
}
6971

7072
private void initCrash() {
71-
CrashUtils.init();
73+
CrashUtils.init(new CrashUtils.OnCrashListener() {
74+
@Override
75+
public void onCrash(Throwable e) {
76+
LogUtils.d(e.getMessage());
77+
Toast.makeText(getInstance(), "炸了", Toast.LENGTH_LONG).show();
78+
}
79+
});
7280
}
7381

7482
private void initAssets() {

app/src/main/java/com/blankj/androidutilcode/base/rv/BaseViewHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public BaseViewHolder(View itemView) {
2222
}
2323

2424
@SuppressWarnings("unchecked")
25-
public <T extends View> T getView(@IdRes int viewId) {
25+
public <T extends View> T getView(@IdRes final int viewId) {
2626
View view = viewArray.get(viewId);
2727
if (view == null) {
2828
view = itemView.findViewById(viewId);

app/src/main/java/com/blankj/androidutilcode/base/rv/adapter/BaseAdapter.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public final int getItemViewType(int position) {
5858
}
5959
}
6060

61-
protected int getCustomViewType(int position) {
61+
protected int getCustomViewType(final int position) {
6262
return VIEW_TYPE_DEFAULT;
6363
}
6464

65-
protected abstract int bindLayout(int viewType);
65+
protected abstract int bindLayout(final int viewType);
6666

6767
@Override
6868
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@@ -91,7 +91,7 @@ public final void onBindViewHolder(BaseViewHolder holder, int position) {
9191
}
9292
}
9393

94-
protected void bindCustomViewHolder(BaseViewHolder holder, int position) {
94+
protected void bindCustomViewHolder(final BaseViewHolder holder, final int position) {
9595
final int dataPos = position - (mViewArray.get(VIEW_TYPE_HEADER) == null ? 0 : 1);
9696
holder.itemView.setOnClickListener(new View.OnClickListener() {
9797
@Override
@@ -110,8 +110,7 @@ public boolean onLongClick(View v) {
110110
bind(holder, mData.get(dataPos));
111111
}
112112

113-
protected abstract void bind(BaseViewHolder holder, M data);
114-
113+
protected abstract void bind(final BaseViewHolder holder, final M data);
115114

116115
@Override
117116
public int getItemCount() {
@@ -154,23 +153,23 @@ public void removeFooterView() {
154153
removeView(VIEW_TYPE_FOOTER);
155154
}
156155

157-
private void setView(int type, @NonNull View view) {
156+
private void setView(final int type, @NonNull final View view) {
158157
mViewArray.put(type, view);
159158
notifyDataSetChanged();
160159
}
161160

162-
private View getView(int type) {
161+
private View getView(final int type) {
163162
return mViewArray.get(type);
164163
}
165164

166-
private void removeView(int type) {
165+
private void removeView(final int type) {
167166
if (mViewArray.get(type) != null) {
168167
mViewArray.delete(type);
169168
notifyDataSetChanged();
170169
}
171170
}
172171

173-
private View inflateLayout(@LayoutRes int layoutId) {
172+
private View inflateLayout(@LayoutRes final int layoutId) {
174173
return mInflater.inflate(layoutId, mParent, false);
175174
}
176175

@@ -185,11 +184,11 @@ private int getExtraViewCount() {
185184
return extraViewCount;
186185
}
187186

188-
public void setOnItemClickListener(OnItemClickListener clickListener) {
187+
public void setOnItemClickListener(final OnItemClickListener clickListener) {
189188
mClickListener = clickListener;
190189
}
191190

192-
public void setOnItemLongClickListener(OnItemLongClickListener longClickListener) {
191+
public void setOnItemLongClickListener(final OnItemLongClickListener longClickListener) {
193192
mLongClickListener = longClickListener;
194193
}
195194

app/src/main/java/com/blankj/androidutilcode/base/rv/adapter/SingleAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public SingleAdapter(List<M> list, @LayoutRes int layoutId) {
2222
}
2323

2424
@Override
25-
protected int bindLayout(int viewType) {
25+
protected int bindLayout(final int viewType) {
2626
return mLayoutId;
2727
}
28+
2829
}

app/src/main/java/com/blankj/androidutilcode/base/rv/listener/OnItemClickListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
* </pre>
1212
*/
1313
public interface OnItemClickListener {
14-
void onItemClick(View view, int position);
14+
void onItemClick(final View view, final int position);
1515
}

app/src/main/java/com/blankj/androidutilcode/base/rv/listener/OnItemLongClickListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
* desc :
1111
* </pre>
1212
*/
13-
public interface OnItemLongClickListener{
14-
boolean onItemLongClick(View view, int position);
13+
public interface OnItemLongClickListener {
14+
boolean onItemLongClick(final View view, final int position);
1515
}

update_log.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
* 17/09/20 完善FragmentUtils
1+
* 17/09/26 完善ActivityUtils及Demo,发布1.9.1
2+
* 17/09/25 完善ActivityUtils及Demo
3+
* 17/09/24 完善ActivityUtils及Demo
4+
* 17/09/23 完善FragmentUtils
25
* 17/09/19 修复CrashUtils自定义路径错误
36
* 17/09/18 完善ImageUtils的Demo
47
* 17/09/17 完善ImageUtils的compress

utilcode/src/main/java/com/blankj/utilcode/util/CrashUtils.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.text.SimpleDateFormat;
1616
import java.util.Date;
1717
import java.util.Locale;
18+
import java.util.concurrent.ExecutorService;
19+
import java.util.concurrent.Executors;
1820

1921
/**
2022
* <pre>
@@ -26,11 +28,12 @@
2628
*/
2729
public final class CrashUtils {
2830

29-
private static boolean mInitialized;
30-
private static String defaultDir;
31-
private static String dir;
32-
private static String versionName;
33-
private static int versionCode;
31+
private static String defaultDir;
32+
private static String dir;
33+
private static String versionName;
34+
private static int versionCode;
35+
36+
private static ExecutorService sExecutor;
3437

3538
private static final String FILE_SEP = System.getProperty("file.separator");
3639
private static final Format FORMAT = new SimpleDateFormat("MM-dd HH-mm-ss", Locale.getDefault());
@@ -74,7 +77,10 @@ public void uncaughtException(final Thread t, final Throwable e) {
7477
String fileName = FORMAT.format(now) + ".txt";
7578
final String fullPath = (dir == null ? defaultDir : dir) + fileName;
7679
if (!createOrExistsFile(fullPath)) return;
77-
new Thread(new Runnable() {
80+
if (sExecutor == null) {
81+
sExecutor = Executors.newSingleThreadExecutor();
82+
}
83+
sExecutor.execute(new Runnable() {
7884
@Override
7985
public void run() {
8086
PrintWriter pw = null;
@@ -95,7 +101,7 @@ public void run() {
95101
}
96102
}
97103
}
98-
}).start();
104+
});
99105
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
100106
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
101107
}
@@ -110,46 +116,40 @@ private CrashUtils() {
110116
/**
111117
* 初始化
112118
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
113-
*
114-
* @return {@code true}: 初始化成功<br>{@code false}: 初始化失败
115119
*/
116-
public static boolean init() {
117-
return init("");
120+
public static void init() {
121+
init("");
118122
}
119123

120124
/**
121125
* 初始化
122126
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
123127
*
124128
* @param crashDir 崩溃文件存储目录
125-
* @return {@code true}: 初始化成功<br>{@code false}: 初始化失败
126129
*/
127-
public static boolean init(@NonNull final File crashDir) {
128-
return init(crashDir.getAbsolutePath());
130+
public static void init(@NonNull final File crashDir) {
131+
init(crashDir.getAbsolutePath());
129132
}
130133

131134
/**
132135
* 初始化
133136
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
134137
*
135138
* @param crashDir 崩溃文件存储目录
136-
* @return {@code true}: 初始化成功<br>{@code false}: 初始化失败
137139
*/
138-
public static boolean init(final String crashDir) {
140+
public static void init(final String crashDir) {
139141
if (isSpace(crashDir)) {
140142
dir = null;
141143
} else {
142144
dir = crashDir.endsWith(FILE_SEP) ? crashDir : crashDir + FILE_SEP;
143145
}
144-
if (mInitialized) return true;
145146
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
146147
&& Utils.getApp().getExternalCacheDir() != null)
147148
defaultDir = Utils.getApp().getExternalCacheDir() + FILE_SEP + "crash" + FILE_SEP;
148149
else {
149150
defaultDir = Utils.getApp().getCacheDir() + FILE_SEP + "crash" + FILE_SEP;
150151
}
151152
Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
152-
return mInitialized = true;
153153
}
154154

155155
private static boolean createOrExistsFile(final String filePath) {

utilcode/src/main/java/com/blankj/utilcode/util/Utils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,40 @@
1717
* time : 16/12/08
1818
* desc : Utils初始化相关
1919
* </pre>
20+
*          瓦瓦            十
21+
*         十齱龠己         亅瓦車己
22+
*         乙龍龠毋日丶      丶乙己毋毋丶
23+
*         十龠馬鬼車瓦      己十瓦毋毋
24+
*          鬼馬龠馬龠十    己己毋車毋瓦
25+
*          毋龠龠龍龠鬼乙丶丶乙車乙毋鬼車己
26+
*          乙龠龍龍鬼龍瓦 十瓦毋乙瓦龠瓦亅
27+
*           馬齱龍馬鬼十丶日己己己毋車乙丶
28+
*           己齱馬鬼車十十毋日乙己己乙乙
29+
*            車馬齱齱日乙毋瓦己乙瓦日亅
30+
*            亅車齺龖瓦乙車龖龍乙乙十
31+
*             日龠龠十亅車龍毋十十
32+
*             日毋己亅 己己十亅亅
33+
*            丶己十十乙  丶丶丶丶丶
34+
*            亅己十龍龖瓦  丶 丶 乙十
35+
*            亅己十龠龖毋 丶丶  丶己鬼鬼瓦亅
36+
*            十日十十日亅丶亅丶 丶十日毋鬼馬馬車乙
37+
*            十日乙十亅亅亅丶  十乙己毋鬼鬼鬼龍齺馬乙
38+
*            丶瓦己乙十十亅丶亅乙乙乙己毋鬼鬼鬼龍齱齺齺鬼十
39+
*             乙乙十十十亅乙瓦瓦己日瓦毋鬼鬼龠齱齱龍龍齱齱毋丶
40+
*             亅十十十十乙瓦車毋瓦瓦日車馬龠龍龍龍龍龍龠龠龠馬亅
41+
*              十十十十己毋車瓦瓦瓦瓦鬼馬龠龍龠龠龍龠龠龠馬龠車
42+
*               亅十十日毋瓦日日瓦鬼鬼鬼龠龠馬馬龠龍龍龠馬馬車
43+
*               亅亅亅乙瓦瓦毋車車車馬龍龠鬼鬼馬龠龍龍龠馬馬鬼
44+
*             丶丶乙亅亅乙車鬼鬼鬼毋車龍龍龠鬼馬馬龠龍齱齱龍馬鬼
45+
*            亅己十十己十日鬼鬼車瓦毋龠龍龠馬馬龠龠龠齱齺齺齱龠鬼
46+
*             亅乙乙乙十車馬車毋馬齱齱龍龠龠龠馬龠龍齱龍龠龠鬼瓦
47+
*                 丶毋龠鬼車瓦車馬龠龍龠龠龍齱齱龠馬馬鬼毋日
48+
*                 十乙己日十  丶己鬼龍齱齺齱龍馬馬馬車毋己
49+
*               丶十己乙亅丶      亅瓦馬龠龍龠龠馬毋瓦乙
50+
*              丶十十乙亅十        亅己瓦車馬龠鬼車瓦乙
51+
*              丶十乙十十丶         丶丶亅十瓦鬼車瓦己
52+
*               丶亅亅丶               亅日瓦日
53+
*                                     丶
2054
*/
2155
public final class Utils {
2256

0 commit comments

Comments
 (0)