Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit f6fa836

Browse files
committed
add library
1 parent 89a70ad commit f6fa836

File tree

13 files changed

+572
-0
lines changed

13 files changed

+572
-0
lines changed

commonLibrary/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

commonLibrary/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
6+
defaultConfig {
7+
minSdkVersion rootProject.ext.minSdkVersion
8+
targetSdkVersion rootProject.ext.targetSdkVersion
9+
versionCode rootProject.ext.versionCode
10+
versionName rootProject.ext.versionName
11+
}
12+
}
13+
14+
dependencies {
15+
provided "com.android.support:appcompat-v7:$supportLibraryVersion"
16+
provided "com.android.support:design:$supportLibraryVersion"
17+
compile "com.github.mukeshsolanki:MarkdownView-Android:$markdownViewVersion"
18+
compile("com.google.android:flexbox:$flexboxVersion", {
19+
exclude group: 'com.android.support'
20+
})
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
package="com.common">
4+
5+
<application android:allowBackup="true" android:label="@string/app_name"
6+
android:supportsRtl="true">
7+
8+
</application>
9+
10+
</manifest>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.common.util;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
/**
7+
* by y on 2017/5/18
8+
*/
9+
10+
public class SPUtils {
11+
private SPUtils() {
12+
}
13+
14+
private static final String SHAREDPREFERENCES_NAME = "codeKK";
15+
private static SharedPreferences sharedPreferences;
16+
17+
public static final String IS_OP_TAG = "op_tag";
18+
public static final String IS_OP_URL_WEB = "op_tvWeb";
19+
public static final String IS_OPA_TAG = "opa_tag";
20+
public static final String IS_OPA_URL_WEB = "opa_web";
21+
public static final String IS_BLOG_TAG = "blog_tag";
22+
23+
private static void initSharePreferences(Context context) {
24+
sharedPreferences = context.getSharedPreferences(SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE);
25+
}
26+
27+
public static void init(Context context) {
28+
initSharePreferences(context.getApplicationContext());
29+
}
30+
31+
public static boolean isNull() {
32+
return sharedPreferences == null;
33+
}
34+
35+
public static boolean getBoolean(String key, boolean defaultValue) {
36+
if (isNull()) {
37+
return defaultValue;
38+
}
39+
return sharedPreferences.getBoolean(key, defaultValue);
40+
}
41+
42+
public static void setBoolean(String key, boolean value) {
43+
if (isNull()) {
44+
return;
45+
}
46+
sharedPreferences.edit().putBoolean(key, value).apply();
47+
}
48+
49+
public static String getString(String key, String defaultValue) {
50+
if (isNull()) {
51+
return defaultValue;
52+
}
53+
return sharedPreferences.getString(key, defaultValue);
54+
}
55+
56+
public static void setString(String key, String value) {
57+
if (isNull()) {
58+
return;
59+
}
60+
sharedPreferences.edit().putString(key, value).apply();
61+
}
62+
63+
public static void clearAll() {
64+
if (isNull()) {
65+
return;
66+
}
67+
sharedPreferences.edit().clear().apply();
68+
}
69+
70+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.common.widget;
2+
3+
import android.content.Context;
4+
import android.support.v4.widget.DrawerLayout;
5+
import android.util.AttributeSet;
6+
7+
/**
8+
* by y on 2017/5/20.
9+
*/
10+
11+
public class CustomDrawerLayout extends DrawerLayout {
12+
13+
public CustomDrawerLayout(Context context) {
14+
super(context);
15+
}
16+
17+
public CustomDrawerLayout(Context context, AttributeSet attrs) {
18+
super(context, attrs);
19+
}
20+
21+
public CustomDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
22+
super(context, attrs, defStyle);
23+
}
24+
25+
@Override
26+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27+
widthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
28+
heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY);
29+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
30+
}
31+
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.common.widget;
2+
3+
import android.content.Context;
4+
import android.support.v4.content.ContextCompat;
5+
import android.support.v7.widget.AppCompatTextView;
6+
import android.util.AttributeSet;
7+
import android.view.Gravity;
8+
import android.view.ViewGroup;
9+
10+
import com.common.R;
11+
import com.google.android.flexbox.FlexboxLayout;
12+
13+
14+
/**
15+
* by y on 2017/5/18
16+
*/
17+
18+
public class FlowText extends AppCompatTextView {
19+
public FlowText(Context context) {
20+
super(context);
21+
init();
22+
}
23+
24+
public FlowText(Context context, AttributeSet attrs) {
25+
super(context, attrs);
26+
init();
27+
}
28+
29+
public FlowText(Context context, AttributeSet attrs, int defStyleAttr) {
30+
super(context, attrs, defStyleAttr);
31+
init();
32+
}
33+
34+
private void init() {
35+
setPadding(18, 10, 18, 10);
36+
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
37+
params.leftMargin = 10;
38+
params.bottomMargin = 10;
39+
setGravity(Gravity.CENTER);
40+
setTextSize(10);
41+
setTextColor(ContextCompat.getColor(getContext(), R.color.colorWhite));
42+
setLayoutParams(params);
43+
setBackgroundResource(R.drawable.shape_tag);
44+
}
45+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.common.widget;
2+
3+
import android.content.Context;
4+
import android.support.v7.widget.GridLayoutManager;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.support.v7.widget.StaggeredGridLayoutManager;
8+
import android.util.AttributeSet;
9+
10+
/**
11+
* by y on 2017/5/16
12+
*/
13+
14+
public class LoadMoreRecyclerView extends RecyclerView {
15+
16+
17+
private LAYOUT_MANAGER_TYPE layoutManagerType;
18+
private int[] lastPositions;
19+
private int lastVisibleItemPosition;
20+
private LoadMoreListener loadingListener;
21+
22+
public LoadMoreRecyclerView(Context context) {
23+
super(context);
24+
}
25+
26+
27+
public LoadMoreRecyclerView(Context context, AttributeSet attrs) {
28+
super(context, attrs);
29+
}
30+
31+
32+
public LoadMoreRecyclerView(Context context, AttributeSet attrs, int defStyle) {
33+
super(context, attrs, defStyle);
34+
}
35+
36+
public void setLoadingListener(LoadMoreListener loadingListener) {
37+
this.loadingListener = loadingListener;
38+
}
39+
40+
@Override
41+
public void onScrolled(int dx, int dy) {
42+
super.onScrolled(dx, dy);
43+
44+
LayoutManager layoutManager = getLayoutManager();
45+
if (layoutManagerType == null) {
46+
if (layoutManager instanceof GridLayoutManager) {
47+
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
48+
} else if (layoutManager instanceof LinearLayoutManager) {
49+
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
50+
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
51+
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
52+
} else {
53+
throw new RuntimeException(
54+
"Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
55+
}
56+
}
57+
switch (layoutManagerType) {
58+
case LINEAR:
59+
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
60+
break;
61+
case GRID:
62+
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
63+
break;
64+
case STAGGERED_GRID:
65+
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
66+
if (lastPositions == null) {
67+
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
68+
}
69+
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
70+
lastVisibleItemPosition = findMax(lastPositions);
71+
break;
72+
}
73+
}
74+
75+
@Override
76+
public void onScrollStateChanged(int state) {
77+
super.onScrollStateChanged(state);
78+
LayoutManager layoutManager = getLayoutManager();
79+
int visibleItemCount = layoutManager.getChildCount();
80+
int totalItemCount = layoutManager.getItemCount();
81+
if (loadingListener != null && visibleItemCount > 0 && state == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition == totalItemCount - 1) {
82+
loadingListener.onLoadMore();
83+
}
84+
}
85+
86+
private int findMax(int[] lastPositions) {
87+
int max = lastPositions[0];
88+
for (int value : lastPositions) {
89+
if (value > max) {
90+
max = value;
91+
}
92+
}
93+
return max;
94+
}
95+
96+
private enum LAYOUT_MANAGER_TYPE {
97+
LINEAR,
98+
GRID,
99+
STAGGERED_GRID
100+
}
101+
102+
public interface LoadMoreListener {
103+
void onLoadMore();
104+
}
105+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.common.widget;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.webkit.WebChromeClient;
6+
import android.webkit.WebView;
7+
import android.widget.ProgressBar;
8+
9+
import com.mukesh.MarkdownView;
10+
11+
/**
12+
* by y on 2017/5/17
13+
*/
14+
15+
public class SimpleMarkdownView extends MarkdownView {
16+
17+
private ProgressBar progressbar;
18+
private boolean isLoading = false;
19+
20+
public SimpleMarkdownView(Context context) {
21+
super(context);
22+
init();
23+
}
24+
25+
public SimpleMarkdownView(Context context, AttributeSet attrs) {
26+
super(context, attrs);
27+
init();
28+
}
29+
30+
public SimpleMarkdownView(Context context, AttributeSet attrs, int defStyleAttr) {
31+
super(context, attrs, defStyleAttr);
32+
init();
33+
}
34+
35+
private void init() {
36+
37+
progressbar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);
38+
progressbar.setLayoutParams(new WebView.LayoutParams(WebView.LayoutParams.MATCH_PARENT, 26, 0, 0));
39+
addView(progressbar);
40+
setWebChromeClient(
41+
new WebChromeClient() {
42+
@Override
43+
public void onProgressChanged(WebView view, int newProgress) {
44+
super.onProgressChanged(view, newProgress);
45+
newProgressBar(newProgress);
46+
}
47+
});
48+
}
49+
50+
public boolean isLoading() {
51+
return isLoading;
52+
}
53+
54+
55+
private void newProgressBar(int newProgress) {
56+
if (newProgress == 100) {
57+
progressbar.setVisibility(GONE);
58+
isLoading = true;
59+
} else {
60+
if (progressbar.getVisibility() == GONE) {
61+
progressbar.setVisibility(VISIBLE);
62+
}
63+
isLoading = false;
64+
progressbar.setProgress(newProgress);
65+
}
66+
}
67+
68+
@Override
69+
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
70+
if (progressbar != null) {
71+
WebView.LayoutParams lp = (WebView.LayoutParams) progressbar.getLayoutParams();
72+
lp.x = l;
73+
lp.y = t;
74+
progressbar.setLayoutParams(lp);
75+
}
76+
super.onScrollChanged(l, t, oldl, oldt);
77+
}
78+
}

0 commit comments

Comments
 (0)