Skip to content

Commit eefb03f

Browse files
committed
see 09/18 log
1 parent 7e6ac7a commit eefb03f

25 files changed

+1282
-658
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
package="com.blankj.androidutilcode">
54

65
<!--bar-->
@@ -65,8 +64,7 @@
6564
</activity>
6665

6766
<!--core-->
68-
<activity
69-
android:name=".core.main.CoreUtilActivity" />
67+
<activity android:name=".core.main.CoreUtilActivity" />
7068
<activity android:name=".core.activity.ActivityActivity" />
7169
<activity android:name=".core.app.AppActivity" />
7270
<activity android:name=".core.bar.BarActivity" />
@@ -92,7 +90,12 @@
9290
<activity android:name=".core.screen.ScreenActivity" />
9391
<activity android:name=".core.sdcard.SDCardActivity" />
9492
<activity android:name=".core.snackbar.SnackbarActivity" />
95-
<activity android:name=".core.span.SpanActivity" />
93+
<activity android:name=".core.span.SpanActivity">
94+
<!--<intent-filter>-->
95+
<!--<action android:name="android.intent.action.MAIN" />-->
96+
<!--<category android:name="android.intent.category.LAUNCHER" />-->
97+
<!--</intent-filter>-->
98+
</activity>
9699
<activity android:name=".core.toast.ToastActivity" />
97100

98101
<provider
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package com.blankj.androidutilcode;
22

3-
import com.blankj.utilcode.util.Utils;
4-
5-
import java.io.File;
6-
73
/**
84
* <pre>
95
* author: Blankj
106
* blog : http://blankj.com
117
* time : 2017/05/10
12-
* desc :
8+
* desc : 配置常量
139
* </pre>
1410
*/
1511
public class Config {
12+
13+
public static final String FILE_SEP = System.getProperty("file.separator");
14+
public static final String LINE_SEP = System.getProperty("line.separator");
1615
public static final String PKG = "com.blankj.androidutilcode";
1716
public static final String TEST_PKG = "com.blankj.testinstall";
1817
public static final String GITHUB = "https://github.com/Blankj/AndroidUtilCode";
1918
public static final String BLOG = "http://www.jianshu.com/u/46702d5c6978";
19+
public static final String CACHE_PATH;
20+
public static final String TEST_APK_PATH;
2021

21-
private static String testApkPath;
22-
23-
public static String getTestApkPath() {
24-
if (testApkPath == null)
25-
testApkPath = Utils.getApp().getCacheDir().getAbsolutePath() + File.separatorChar + "apk" + File.separatorChar + "test_install.apk";
26-
return testApkPath;
22+
static {
23+
CACHE_PATH = UtilsApp.getInstance().getCacheDir().getAbsolutePath();
24+
TEST_APK_PATH = CACHE_PATH + FILE_SEP + "apk" + FILE_SEP + "test_install.apk";
2725
}
2826
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,20 @@ private void initCrash() {
7272
}
7373

7474
private void initAssets() {
75-
if (!FileUtils.isFileExists(com.blankj.androidutilcode.Config.getTestApkPath())) {
75+
if (!FileUtils.isFileExists(Config.TEST_APK_PATH)) {
7676
ThreadPoolUtils poolUtils = new ThreadPoolUtils(ThreadPoolUtils.SingleThread, 1);
7777
poolUtils.execute(new Runnable() {
7878
@Override
7979
public void run() {
8080
try {
81-
FileIOUtils.writeFileFromIS(Config.getTestApkPath(), getAssets().open("test_install"), false);
81+
FileIOUtils.writeFileFromIS(Config.TEST_APK_PATH, getAssets().open("test_install"), false);
8282
} catch (IOException e) {
8383
e.printStackTrace();
8484
}
8585
}
8686
});
87+
} else {
88+
LogUtils.d("test apk existed.");
8789
}
8890
}
8991
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.blankj.androidutilcode.base.rv;
2+
3+
import android.support.annotation.IdRes;
4+
import android.support.v7.widget.RecyclerView;
5+
import android.util.SparseArray;
6+
import android.view.View;
7+
8+
/**
9+
* <pre>
10+
* author: Blankj
11+
* blog : http://blankj.com
12+
* time : 2017/08/22
13+
* desc :
14+
* </pre>
15+
*/
16+
public class BaseViewHolder extends RecyclerView.ViewHolder {
17+
18+
private SparseArray<View> viewArray = new SparseArray<>();
19+
20+
public BaseViewHolder(View itemView) {
21+
super(itemView);
22+
}
23+
24+
@SuppressWarnings("unchecked")
25+
public <T extends View> T getView(@IdRes int viewId) {
26+
View view = viewArray.get(viewId);
27+
if (view == null) {
28+
view = itemView.findViewById(viewId);
29+
viewArray.put(viewId, view);
30+
}
31+
return (T) view;
32+
}
33+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package com.blankj.androidutilcode.base.rv;
2+
3+
import android.annotation.SuppressLint;
4+
import android.content.Context;
5+
import android.graphics.Canvas;
6+
import android.graphics.Rect;
7+
import android.graphics.drawable.Drawable;
8+
import android.support.annotation.DrawableRes;
9+
import android.support.annotation.NonNull;
10+
import android.support.v4.content.ContextCompat;
11+
import android.support.v4.view.ViewCompat;
12+
import android.support.v7.widget.RecyclerView;
13+
import android.view.View;
14+
import android.widget.LinearLayout;
15+
16+
/**
17+
* <pre>
18+
* author: Blankj
19+
* blog : http://blankj.com
20+
* time : 2017/08/17
21+
* desc :
22+
* </pre>
23+
*/
24+
public class RecycleViewDivider extends RecyclerView.ItemDecoration {
25+
26+
public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
27+
public static final int VERTICAL = LinearLayout.VERTICAL;
28+
29+
protected Drawable mDivider;
30+
31+
protected int mOrientation;
32+
33+
protected final Rect mBounds = new Rect();
34+
35+
public RecycleViewDivider(Context context, int orientation, @DrawableRes int resId) {
36+
this(context, orientation, ContextCompat.getDrawable(context, resId));
37+
}
38+
39+
public RecycleViewDivider(Context context, int orientation, @NonNull Drawable divider) {
40+
setOrientation(orientation);
41+
mDivider = divider;
42+
}
43+
44+
public void setOrientation(int orientation) {
45+
if (orientation != HORIZONTAL && orientation != VERTICAL) {
46+
throw new IllegalArgumentException(
47+
"Invalid orientation. It should be either HORIZONTAL or VERTICAL");
48+
}
49+
mOrientation = orientation;
50+
}
51+
52+
@Override
53+
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
54+
if (parent.getLayoutManager() == null) {
55+
return;
56+
}
57+
if (mOrientation == VERTICAL) {
58+
drawVertical(c, parent);
59+
} else {
60+
drawHorizontal(c, parent);
61+
}
62+
}
63+
64+
@SuppressLint("NewApi")
65+
protected void drawVertical(Canvas canvas, RecyclerView parent) {
66+
canvas.save();
67+
final int left;
68+
final int right;
69+
if (parent.getClipToPadding()) {
70+
left = parent.getPaddingLeft();
71+
right = parent.getWidth() - parent.getPaddingRight();
72+
canvas.clipRect(left, parent.getPaddingTop(), right,
73+
parent.getHeight() - parent.getPaddingBottom());
74+
} else {
75+
left = 0;
76+
right = parent.getWidth();
77+
}
78+
79+
final int childCount = parent.getChildCount();
80+
for (int i = 0; i < childCount; i++) {
81+
final View child = parent.getChildAt(i);
82+
parent.getDecoratedBoundsWithMargins(child, mBounds);
83+
final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
84+
final int top = bottom - mDivider.getIntrinsicHeight();
85+
mDivider.setBounds(left, top, right, bottom);
86+
mDivider.draw(canvas);
87+
}
88+
canvas.restore();
89+
}
90+
91+
@SuppressLint("NewApi")
92+
protected void drawHorizontal(Canvas canvas, RecyclerView parent) {
93+
canvas.save();
94+
final int top;
95+
final int bottom;
96+
if (parent.getClipToPadding()) {
97+
top = parent.getPaddingTop();
98+
bottom = parent.getHeight() - parent.getPaddingBottom();
99+
canvas.clipRect(parent.getPaddingLeft(), top,
100+
parent.getWidth() - parent.getPaddingRight(), bottom);
101+
} else {
102+
top = 0;
103+
bottom = parent.getHeight();
104+
}
105+
106+
final int childCount = parent.getChildCount();
107+
for (int i = 0; i < childCount; i++) {
108+
final View child = parent.getChildAt(i);
109+
parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
110+
final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
111+
final int left = right - mDivider.getIntrinsicWidth();
112+
mDivider.setBounds(left, top, right, bottom);
113+
mDivider.draw(canvas);
114+
}
115+
canvas.restore();
116+
}
117+
118+
@Override
119+
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
120+
if (mOrientation == VERTICAL) {
121+
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
122+
} else {
123+
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)