10 | * author: Blankj 11 | * blog : http://blankj.com 12 | * time : 2017/03/13 13 | * desc : 存储相关常量 14 | *15 | */ 16 | public final class MemoryConstants { 17 | 18 | /** 19 | * Byte与Byte的倍数 20 | */ 21 | public static final int BYTE = 1; 22 | /** 23 | * KB与Byte的倍数 24 | */ 25 | public static final int KB = 1024; 26 | /** 27 | * MB与Byte的倍数 28 | */ 29 | public static final int MB = 1048576; 30 | /** 31 | * GB与Byte的倍数 32 | */ 33 | public static final int GB = 1073741824; 34 | 35 | @IntDef({BYTE, KB, MB, GB}) 36 | @Retention(RetentionPolicy.SOURCE) 37 | public @interface Unit { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_rv.xml: -------------------------------------------------------------------------------- 1 | 2 |
10 | * author: Blankj 11 | * blog : http://blankj.com 12 | * time : 2017/03/13 13 | * desc : 时间相关常量 14 | *15 | */ 16 | public final class TimeConstants { 17 | 18 | /** 19 | * 秒与毫秒的倍数 20 | */ 21 | public static final int MSEC = 1; 22 | /** 23 | * 秒与毫秒的倍数 24 | */ 25 | public static final int SEC = 1000; 26 | /** 27 | * 分与毫秒的倍数 28 | */ 29 | public static final int MIN = 60000; 30 | /** 31 | * 时与毫秒的倍数 32 | */ 33 | public static final int HOUR = 3600000; 34 | /** 35 | * 天与毫秒的倍数 36 | */ 37 | public static final int DAY = 86400000; 38 | 39 | @IntDef({MSEC, SEC, MIN, HOUR, DAY}) 40 | @Retention(RetentionPolicy.SOURCE) 41 | public @interface Unit { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/hankkin/hbase/HApplication.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.hbase; 2 | 3 | import android.app.Application; 4 | 5 | import com.hankkin.xlibrary.utils.Utils; 6 | import com.luck.picture.lib.compress.Luban; 7 | import com.luck.picture.lib.model.FunctionConfig; 8 | import com.luck.picture.lib.model.FunctionOptions; 9 | import com.luck.picture.lib.model.PictureConfig; 10 | 11 | /** 12 | * Created by hankkin on 2017/4/5. 13 | */ 14 | 15 | public class HApplication extends Application { 16 | 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | Utils.init(this); 21 | initPickerImg(); 22 | } 23 | 24 | private void initPickerImg() { 25 | FunctionOptions options = new FunctionOptions.Builder() 26 | .setType(FunctionConfig.TYPE_IMAGE) 27 | .setCompress(true) 28 | .setGrade(Luban.CUSTOM_GEAR) 29 | .setSelectMode(FunctionConfig.MODE_MULTIPLE) 30 | .create(); 31 | PictureConfig.getInstance().init(options); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /hlibrary/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 |
7 | * author: Blankj 8 | * blog : http://blankj.com 9 | * time : 16/12/08 10 | * desc : Utils初始化相关 11 | *12 | */ 13 | public final class Utils { 14 | 15 | private static Context context; 16 | private static SPUtils spUtils; 17 | 18 | private Utils() { 19 | throw new UnsupportedOperationException("u can't instantiate me..."); 20 | } 21 | 22 | /** 23 | * 初始化工具类 24 | * 25 | * @param context 上下文 26 | */ 27 | public static void init(Context context) { 28 | Utils.context = context.getApplicationContext(); 29 | spUtils = new SPUtils("utilcode"); 30 | } 31 | 32 | /** 33 | * 获取ApplicationContext 34 | * 35 | * @return ApplicationContext 36 | */ 37 | public static Context getContext() { 38 | if (context != null) return context; 39 | throw new NullPointerException("u should init first"); 40 | } 41 | 42 | public static SPUtils getSpUtils() { 43 | return spUtils; 44 | } 45 | } -------------------------------------------------------------------------------- /hlibrary/src/main/java/com/hankkin/xlibrary/http/HttpResultSubscriber.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.xlibrary.http; 2 | 3 | 4 | import java.net.ConnectException; 5 | import java.net.SocketException; 6 | import java.util.concurrent.TimeoutException; 7 | 8 | import rx.Subscriber; 9 | 10 | 11 | /** 12 | * Created by hankkin on 2017/10/10. 13 | * Blog: http://hankkin.cn 14 | * Mail: 1019283569@qq.com 15 | */ 16 | 17 | public abstract class HttpResultSubscriber
8 | * author: Blankj 9 | * blog : http://blankj.com 10 | * time : 2016/10/9 11 | * desc : 关闭相关工具类 12 | *13 | */ 14 | public final class CloseUtils { 15 | 16 | private CloseUtils() { 17 | throw new UnsupportedOperationException("u can't instantiate me..."); 18 | } 19 | 20 | /** 21 | * 关闭IO 22 | * 23 | * @param closeables closeables 24 | */ 25 | public static void closeIO(Closeable... closeables) { 26 | if (closeables == null) return; 27 | for (Closeable closeable : closeables) { 28 | if (closeable != null) { 29 | try { 30 | closeable.close(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | } 37 | 38 | /** 39 | * 安静关闭IO 40 | * 41 | * @param closeables closeables 42 | */ 43 | public static void closeIOQuietly(Closeable... closeables) { 44 | if (closeables == null) return; 45 | for (Closeable closeable : closeables) { 46 | if (closeable != null) { 47 | try { 48 | closeable.close(); 49 | } catch (IOException ignored) { 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hlibrary/src/main/java/com/hankkin/xlibrary/widget/view/indicators/SemiCircleSpinIndicator.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.xlibrary.widget.view.indicators; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.graphics.RectF; 7 | 8 | import com.hankkin.xlibrary.widget.view.Indicator; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created by Jack on 2015/10/20. 14 | */ 15 | public class SemiCircleSpinIndicator extends Indicator { 16 | 17 | private float degress; 18 | 19 | @Override 20 | public void draw(Canvas canvas, Paint paint) { 21 | canvas.rotate(degress,centerX(),centerY()); 22 | RectF rectF=new RectF(0,0,getWidth(),getHeight()); 23 | canvas.drawArc(rectF,-60,120,false,paint); 24 | } 25 | 26 | @Override 27 | public ArrayList
15 | * author: Blankj 16 | * blog : http://blankj.com 17 | * time : 2016/9/28 18 | * desc : 判空相关工具类 19 | *20 | */ 21 | public final class EmptyUtils { 22 | 23 | private EmptyUtils() { 24 | throw new UnsupportedOperationException("u can't instantiate me..."); 25 | } 26 | 27 | /** 28 | * 判断对象是否为空 29 | * 30 | * @param obj 对象 31 | * @return {@code true}: 为空
7 | * author: Blankj 8 | * blog : http://blankj.com 9 | * time : 2016/9/27 10 | * desc : 清除相关工具类 11 | *12 | */ 13 | public final class CleanUtils { 14 | 15 | private CleanUtils() { 16 | throw new UnsupportedOperationException("u can't instantiate me..."); 17 | } 18 | 19 | /** 20 | * 清除内部缓存 21 | *
/data/data/com.xxx.xxx/cache
22 | * 23 | * @return {@code true}: 清除成功/data/data/com.xxx.xxx/files
32 | * 33 | * @return {@code true}: 清除成功/data/data/com.xxx.xxx/databases
42 | * 43 | * @return {@code true}: 清除成功/data/data/com.xxx.xxx/databases/dbName
52 | * 53 | * @param dbName 数据库名称 54 | * @return {@code true}: 清除成功/data/data/com.xxx.xxx/shared_prefs
63 | * 64 | * @return {@code true}: 清除成功/storage/emulated/0/android/data/com.xxx.xxx/cache
73 | * 74 | * @return {@code true}: 清除成功5 | * author: Blankj 6 | * blog : http://blankj.com 7 | * time : 2017/03/13 8 | * desc : 正则相关常量 9 | *10 | */ 11 | public final class RegexConstants { 12 | 13 | /** 14 | * 正则:手机号(简单) 15 | */ 16 | public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$"; 17 | /** 18 | * 正则:手机号(精确) 19 | *
移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188
20 | *联通:130、131、132、145、155、156、175、176、185、186
21 | *电信:133、153、173、177、180、181、189
22 | *全球星:1349
23 | *虚拟运营商:170
24 | */ 25 | public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$"; 26 | /** 27 | * 正则:电话号码 28 | */ 29 | public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}"; 30 | /** 31 | * 正则:身份证号码15位 32 | */ 33 | public static final String REGEX_ID_CARD15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"; 34 | /** 35 | * 正则:身份证号码18位 36 | */ 37 | public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"; 38 | /** 39 | * 正则:邮箱 40 | */ 41 | public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; 42 | /** 43 | * 正则:URL 44 | */ 45 | public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*"; 46 | /** 47 | * 正则:汉字 48 | */ 49 | public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$"; 50 | /** 51 | * 正则:用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位 52 | */ 53 | public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(? 12 | * author: Blankj 13 | * blog : http://blankj.com 14 | * time : 2016/8/2 15 | * desc : 键盘相关工具类 16 | * 17 | */ 18 | public final class KeyboardUtils { 19 | 20 | private KeyboardUtils() { 21 | throw new UnsupportedOperationException("u can't instantiate me..."); 22 | } 23 | 24 | /** 25 | * 避免输入法面板遮挡 26 | *在manifest.xml中activity中设置
27 | *android:windowSoftInputMode="adjustPan"
28 | */ 29 | 30 | /** 31 | * 动态隐藏软键盘 32 | * 33 | * @param activity activity 34 | */ 35 | public static void hideSoftInput(Activity activity) { 36 | View view = activity.getCurrentFocus(); 37 | if (view == null) view = new View(activity); 38 | InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 39 | if (imm == null) return; 40 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 41 | } 42 | 43 | /** 44 | * 动态隐藏软键盘 45 | * 46 | * @param context 上下文 47 | * @param view 视图 48 | */ 49 | public static void hideSoftInput(Context context, View view) { 50 | InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 51 | if (imm == null) return; 52 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 53 | } 54 | 55 | /** 56 | * 点击屏幕空白区域隐藏软键盘 57 | *根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘
58 | *需重写dispatchTouchEvent
59 | *参照以下注释代码
60 | */ 61 | public static void clickBlankArea2HideSoftInput() { 62 | Log.d("tips", "U should copy the following code."); 63 | /* 64 | @Override 65 | public boolean dispatchTouchEvent(MotionEvent ev) { 66 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 67 | View v = getCurrentFocus(); 68 | if (isShouldHideKeyboard(v, ev)) { 69 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 70 | imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 71 | } 72 | } 73 | return super.dispatchTouchEvent(ev); 74 | } 75 | 76 | // 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘 77 | private boolean isShouldHideKeyboard(View v, MotionEvent event) { 78 | if (v != null && (v instanceof EditText)) { 79 | int[] l = {0, 0}; 80 | v.getLocationInWindow(l); 81 | int left = l[0], 82 | top = l[1], 83 | bottom = top + v.getHeight(), 84 | right = left + v.getWidth(); 85 | return !(event.getX() > left && event.getX() < right 86 | && event.getY() > top && event.getY() < bottom); 87 | } 88 | return false; 89 | } 90 | */ 91 | } 92 | 93 | /** 94 | * 动态显示软键盘 95 | * 96 | * @param edit 输入框 97 | */ 98 | public static void showSoftInput(EditText edit) { 99 | edit.setFocusable(true); 100 | edit.setFocusableInTouchMode(true); 101 | edit.requestFocus(); 102 | InputMethodManager imm = (InputMethodManager) Utils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 103 | if (imm == null) return; 104 | imm.showSoftInput(edit, 0); 105 | } 106 | 107 | /** 108 | * 切换键盘显示与否状态 109 | */ 110 | public static void toggleSoftInput() { 111 | InputMethodManager imm = (InputMethodManager) Utils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 112 | if (imm == null) return; 113 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 114 | } 115 | } -------------------------------------------------------------------------------- /hlibrary/src/main/java/com/hankkin/xlibrary/other/PickerManager.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.xlibrary.other; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.gson.Gson; 6 | import com.hankkin.xlibrary.bean.JsonBean; 7 | 8 | import org.json.JSONArray; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created by hankkin on 2017/4/5. 14 | */ 15 | 16 | public class PickerManager { 17 | 18 | private static PickerManager instance = null; 19 | public static PickerManager getInstance(){ 20 | if (instance == null){ 21 | synchronized (PickerManager.class){ 22 | if (instance == null){ 23 | instance = new PickerManager(); 24 | } 25 | } 26 | } 27 | return instance; 28 | } 29 | 30 | private ArrayList18 | * author: Blankj 19 | * blog : http://blankj.com 20 | * time : 2016/9/23 21 | * desc : Activity相关工具类 22 | *23 | */ 24 | public final class ActivityUtils { 25 | 26 | private ActivityUtils() { 27 | throw new UnsupportedOperationException("u can't instantiate me..."); 28 | } 29 | 30 | /** 31 | * 判断是否存在Activity 32 | * 33 | * @param packageName 包名 34 | * @param className activity全路径类名 35 | * @return {@code true}: 是