Skip to content

Commit e4275f7

Browse files
committed
add utils repo
0 parents  commit e4275f7

13 files changed

+830
-0
lines changed

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
15+
# Gradle files
16+
.gradle/
17+
build/
18+
gradle/
19+
gradlew
20+
gradlew.bat
21+
22+
# Local configuration file (sdk path, etc)
23+
local.properties
24+
25+
# Proguard folder generated by Eclipse
26+
proguard/
27+
28+
# Log Files
29+
*.log
30+
31+
# OS X
32+
.DS_Store
33+
.AppleDouble
34+
.LSOverride
35+
36+
# Windows image file caches
37+
Thumbs.db
38+
ehthumbs.db
39+
40+
## IntelliJ
41+
*.iml
42+
*.hprof
43+
.idea/
44+
45+
# https://intellij-support.jetbrains.com/entries/23393067
46+
# User-specific stuff:
47+
.idea/workspace.xml
48+
.idea/tasks.xml
49+
.idea/dictionaries
50+
.idea/misc.xml
51+
.idea/modules.xml
52+
53+
# Sensitive or high-churn files:
54+
.idea/dataSources.ids
55+
.idea/dataSources.xml
56+
.idea/sqlDataSources.xml
57+
.idea/dynamic.xml
58+
.idea/uiDesigner.xml
59+
60+
# Gradle:
61+
.idea/gradle.xml
62+
.idea/libraries
63+
64+
## File-based project format:
65+
*.ipr
66+
*.iws

build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:1.3.1'
8+
}
9+
}
10+
11+
apply plugin: 'com.android.library'
12+
13+
android {
14+
compileSdkVersion 23
15+
buildToolsVersion "23.0.0"
16+
17+
defaultConfig {
18+
minSdkVersion 15
19+
targetSdkVersion 23
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
24+
buildTypes {
25+
release {
26+
minifyEnabled false
27+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28+
}
29+
}
30+
31+
lintOptions {
32+
checkReleaseBuilds false
33+
// Or, if you prefer, you can continue to check for errors in release builds,
34+
// but continue the build even when errors are found:
35+
abortOnError false
36+
disable 'InvalidPackage'
37+
38+
}
39+
compileOptions {
40+
sourceCompatibility JavaVersion.VERSION_1_7
41+
targetCompatibility JavaVersion.VERSION_1_7
42+
}
43+
}
44+
45+
dependencies {
46+
compile 'com.android.support:recyclerview-v7:23.0.0'
47+
}

src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest package="info.anodsplace.android">
2+
3+
</manifest>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package info.anodsplace.android.log;
2+
3+
import android.util.Log;
4+
5+
6+
import java.util.IllegalFormatException;
7+
import java.util.Locale;
8+
9+
10+
/**
11+
* @author alex
12+
* @date 2015-05-11
13+
*/
14+
public class AppLog {
15+
16+
private static final String TAG = "AppLog";
17+
public static boolean DEBUG;
18+
static volatile AppLog singleton = null;
19+
20+
private Listener mListener;
21+
22+
public static AppLog instance() {
23+
if (singleton == null) {
24+
synchronized (AppLog.class) {
25+
if (singleton == null) {
26+
singleton = new AppLog();
27+
}
28+
}
29+
}
30+
return singleton;
31+
}
32+
33+
public static void setDebug(boolean buildConfigDebug, String loggableTag) {
34+
DEBUG = buildConfigDebug ? buildConfigDebug : Log.isLoggable(loggableTag, Log.DEBUG);
35+
}
36+
37+
public static void d(String msg) {
38+
if (DEBUG) Log.d(TAG, format(msg));
39+
}
40+
41+
public static void d(final String msg, final Object... params) {
42+
if (DEBUG) Log.d(TAG, format(msg, params));
43+
}
44+
45+
public static void v(String msg) {
46+
Log.v(TAG, format(msg));
47+
}
48+
49+
public static void e(String msg) {
50+
Log.e(TAG, format(msg));
51+
}
52+
53+
public static void e(String msg, Throwable tr) {
54+
Log.e(TAG, format(msg), tr);
55+
instance().notifyExcpetion(tr);
56+
}
57+
58+
public static void e(Throwable tr) {
59+
Log.e(TAG, tr.getMessage(), tr);
60+
instance().notifyExcpetion(tr);
61+
}
62+
63+
/*
64+
public static void e(RetrofitError error) {
65+
e("RetrofitError: " + error.getClass().getSimpleName() + ": " + error.getMessage(), error.getCause());
66+
instance().notifyExcpetion(error.getCause());
67+
}
68+
*/
69+
70+
public static void e(String msg, final Object... params) {
71+
Log.e(TAG, format(msg, params));
72+
}
73+
74+
public static void w(String msg) {
75+
Log.v(TAG, format(msg));
76+
}
77+
78+
public static void v(String msg, final Object... params) {
79+
Log.v(TAG, format(msg, params));
80+
}
81+
82+
private static String format(final String msg, final Object... array) {
83+
String formatted;
84+
if (array == null || array.length == 0) {
85+
formatted = msg;
86+
} else {
87+
try {
88+
formatted = String.format(Locale.US, msg, array);
89+
} catch (IllegalFormatException ex) {
90+
e("IllegalFormatException: formatString='%s' numArgs=%d", msg, array.length);
91+
formatted = msg + " (An error occurred while formatting the message.)";
92+
}
93+
}
94+
final StackTraceElement[] stackTrace = new Throwable().fillInStackTrace().getStackTrace();
95+
String string = "<unknown>";
96+
for (int i = 2; i < stackTrace.length; ++i) {
97+
final String className = stackTrace[i].getClassName();
98+
if (!className.equals(AppLog.class.getName())) {
99+
final String substring = className.substring(1 + className.lastIndexOf(46));
100+
string = substring.substring(1 + substring.lastIndexOf(36)) + "." + stackTrace[i].getMethodName();
101+
break;
102+
}
103+
}
104+
return String.format(Locale.US, "[%d] %s: %s", Thread.currentThread().getId(), string, formatted);
105+
}
106+
107+
public void setListener(Listener listener) {
108+
this.mListener = listener;
109+
}
110+
111+
private void notifyExcpetion(Throwable tr) {
112+
if (mListener != null) {
113+
mListener.onLogException(tr);
114+
}
115+
}
116+
117+
public interface Listener {
118+
void onLogException(Throwable tr);
119+
}
120+
121+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package info.anodsplace.android.widget.recyclerview;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.ViewGroup;
5+
6+
public class AdapterWrapper extends RecyclerView.Adapter {
7+
8+
protected final RecyclerView.Adapter mAdapter;
9+
10+
public AdapterWrapper(RecyclerView.Adapter adapter) {
11+
super.setHasStableIds(adapter.hasStableIds());
12+
mAdapter = adapter;
13+
mAdapter.registerAdapterDataObserver(new ForwardingDataSetObserver());
14+
}
15+
16+
@Override
17+
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
18+
return mAdapter.onCreateViewHolder(parent, viewType);
19+
}
20+
21+
@Override
22+
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
23+
mAdapter.onBindViewHolder(holder, position);
24+
}
25+
26+
@Override
27+
public int getItemViewType(int position) {
28+
return mAdapter.getItemViewType(position);
29+
}
30+
31+
@Override
32+
public void onViewRecycled(RecyclerView.ViewHolder holder) {
33+
mAdapter.onViewRecycled(holder);
34+
}
35+
36+
@Override
37+
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
38+
mAdapter.onViewAttachedToWindow(holder);
39+
}
40+
41+
@Override
42+
public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
43+
mAdapter.onViewDetachedFromWindow(holder);
44+
}
45+
46+
47+
@Override
48+
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
49+
mAdapter.onAttachedToRecyclerView(recyclerView);
50+
}
51+
52+
@Override
53+
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
54+
mAdapter.onDetachedFromRecyclerView(recyclerView);
55+
}
56+
57+
@Override
58+
public long getItemId(int position) {
59+
return mAdapter.getItemId(position);
60+
}
61+
62+
@Override
63+
public int getItemCount() {
64+
return mAdapter.getItemCount();
65+
}
66+
67+
private class ForwardingDataSetObserver extends RecyclerView.AdapterDataObserver {
68+
69+
@Override
70+
public void onChanged() {
71+
notifyDataSetChanged();
72+
}
73+
74+
@Override
75+
public void onItemRangeChanged(int positionStart, int itemCount) {
76+
notifyItemRangeChanged(positionStart, itemCount);
77+
}
78+
79+
@Override
80+
public void onItemRangeInserted(int positionStart, int itemCount) {
81+
notifyItemRangeInserted(positionStart, itemCount);
82+
}
83+
84+
@Override
85+
public void onItemRangeRemoved(int positionStart, int itemCount) {
86+
notifyItemRangeRemoved(positionStart, itemCount);
87+
}
88+
89+
@Override
90+
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
91+
notifyItemMoved(fromPosition, toPosition);
92+
}
93+
}
94+
95+
}

0 commit comments

Comments
 (0)