alias) {
123 | this.alias = alias;
124 | }
125 |
126 | @Override
127 | public String toString() {
128 | return "ArtistsBeanX{" +
129 | "name='" + name + '\'' +
130 | ", id=" + id +
131 | ", picId=" + picId +
132 | ", img1v1Id=" + img1v1Id +
133 | ", briefDesc='" + briefDesc + '\'' +
134 | ", picUrl='" + picUrl + '\'' +
135 | ", img1v1Url='" + img1v1Url + '\'' +
136 | ", albumSize=" + albumSize +
137 | ", trans='" + trans + '\'' +
138 | ", musicSize=" + musicSize +
139 | ", alias=" + alias +
140 | '}';
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/framelib/src/main/java/com/example/framelib/utils/Tools/constant/RegexConstants.java:
--------------------------------------------------------------------------------
1 | package com.example.framelib.utils.Tools.constant;
2 |
3 | /**
4 | * Created by niko on 2018/2/2.
5 | * 正则相关常量
6 | */
7 | public final class RegexConstants {
8 |
9 | /**
10 | * 正则:手机号(简单)
11 | */
12 | public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
13 | /**
14 | * 正则:手机号(精确)
15 | * 移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188
16 | * 联通:130、131、132、145、155、156、175、176、185、186
17 | * 电信:133、153、173、177、180、181、189
18 | * 全球星:1349
19 | * 虚拟运营商:170
20 | */
21 | 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}$";
22 | /**
23 | * 正则:电话号码
24 | */
25 | public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
26 | /**
27 | * 正则:身份证号码15位
28 | */
29 | 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}$";
30 | /**
31 | * 正则:身份证号码18位
32 | */
33 | 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])$";
34 | /**
35 | * 正则:邮箱
36 | */
37 | public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
38 | /**
39 | * 正则:URL
40 | */
41 | public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
42 | /**
43 | * 正则:汉字
44 | */
45 | public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
46 | /**
47 | * 正则:用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位
48 | */
49 | public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?= 6 && length <= 20) {
84 | return true;
85 | }
86 | return false;
87 | }
88 |
89 | /**
90 | * 是否是电话号码
91 | * @param phone
92 | * @return
93 | */
94 | public static boolean isPhoneNumber(String phone) {
95 | if (isEmpty(phone)) {
96 | return false;
97 | }
98 | Pattern p = Pattern
99 | .compile("1[34578]\\d{9}$");
100 | Matcher m = p.matcher(phone);
101 | return m.matches();
102 | }
103 |
104 | /**
105 | * 是否是身份证号
106 | * @param idCard
107 | * @return
108 | */
109 | public static boolean isIdCard(String idCard) {
110 | if (isEmpty(idCard)) {
111 | return false;
112 | }
113 | String regExp = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[x|X|\\d]$";
114 | Pattern p = Pattern.compile(regExp);
115 | Matcher m = p.matcher(idCard);
116 | return m.find();
117 | }
118 |
119 | /**
120 | * 输入流转字符串
121 | * @param is
122 | * @return
123 | */
124 | public static String inputStream2String(InputStream is) {
125 | BufferedReader in = new BufferedReader(new InputStreamReader(is));
126 | StringBuffer buffer = new StringBuffer();
127 | String line = "";
128 | try {
129 | while ((line = in.readLine()) != null) {
130 | buffer.append(line);
131 | }
132 | } catch (IOException e) {
133 | e.printStackTrace();
134 | }
135 | return buffer.toString();
136 | }
137 |
138 | /**
139 | * 处理为加密字符
140 | * @param idCard
141 | * @return
142 | */
143 | public static String idCardDeal(String idCard) {
144 | StringBuffer sb = new StringBuffer(idCard);
145 | sb.replace(6, 16, "**********");
146 | return sb.toString();
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/framelib/src/main/java/com/example/framelib/basepopup/PopupWindowProxy.java:
--------------------------------------------------------------------------------
1 | package com.example.framelib.basepopup;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.util.AttributeSet;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.PopupWindow;
11 |
12 | /**
13 | * Created by niko on 2017/1/12.
14 | *
15 | * 与basePopupWindow强引用(或者说与PopupController强引用)
16 | */
17 |
18 | public class PopupWindowProxy extends PopupWindow {
19 | private final boolean isFixAndroidN = Build.VERSION.SDK_INT == 24;
20 | private final boolean isOverAndroidN = Build.VERSION.SDK_INT > 24;
21 |
22 |
23 | private PopupController mController;
24 |
25 | public PopupWindowProxy(Context context, PopupController mController) {
26 | super(context);
27 | this.mController = mController;
28 | }
29 |
30 | public PopupWindowProxy(Context context, AttributeSet attrs, PopupController mController) {
31 | super(context, attrs);
32 | this.mController = mController;
33 | }
34 |
35 | public PopupWindowProxy(Context context, AttributeSet attrs, int defStyleAttr, PopupController mController) {
36 | super(context, attrs, defStyleAttr);
37 | this.mController = mController;
38 | }
39 |
40 | public PopupWindowProxy(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, PopupController mController) {
41 | super(context, attrs, defStyleAttr, defStyleRes);
42 | this.mController = mController;
43 | }
44 |
45 | public PopupWindowProxy(PopupController mController) {
46 | this.mController = mController;
47 | }
48 |
49 | public PopupWindowProxy(View contentView, PopupController mController) {
50 | super(contentView);
51 | this.mController = mController;
52 | }
53 |
54 | public PopupWindowProxy(int width, int height, PopupController mController) {
55 | super(width, height);
56 | this.mController = mController;
57 | }
58 |
59 | public PopupWindowProxy(View contentView, int width, int height, PopupController mController) {
60 | super(contentView, width, height);
61 | this.mController = mController;
62 | }
63 |
64 | public PopupWindowProxy(View contentView, int width, int height, boolean focusable, PopupController mController) {
65 | super(contentView, width, height, focusable);
66 | this.mController = mController;
67 | }
68 |
69 |
70 | /**
71 | * fix showAsDropDown when android api ver is over N
72 | *
73 | * https://code.google.com/p/android/issues/detail?id=221001
74 | *
75 | * @param anchor
76 | * @param xoff
77 | * @param yoff
78 | * @param gravity
79 | */
80 | @Override
81 | public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
82 | if (isFixAndroidN && anchor != null) {
83 | int[] anchorLocation = new int[2];
84 | anchor.getLocationInWindow(anchorLocation);
85 | Activity activity = (Activity) anchor.getContext();
86 |
87 | xoff = anchorLocation[0] + xoff;
88 | yoff = anchorLocation[1] + anchor.getHeight() + yoff ;
89 |
90 | super.showAtLocation((activity).getWindow().getDecorView(), Gravity.NO_GRAVITY, xoff, yoff);
91 | } else {
92 | if (isOverAndroidN) {
93 | setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
94 | }
95 | super.showAsDropDown(anchor, xoff, yoff, gravity);
96 | }
97 | }
98 |
99 | @Override
100 | public void dismiss() {
101 | if (mController == null) return;
102 |
103 | boolean performDismiss = mController.onBeforeDismiss();
104 | if (!performDismiss) return;
105 | boolean dismissAtOnce = mController.callDismissAtOnce();
106 | if (dismissAtOnce) {
107 | callSuperDismiss();
108 | }
109 | }
110 |
111 | void callSuperDismiss() {
112 | super.dismiss();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/framelib/src/main/java/com/example/framelib/utils/permission/PermissionUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.framelib.utils.permission;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 | import android.support.v4.content.ContextCompat;
8 |
9 | import java.lang.reflect.InvocationTargetException;
10 | import java.lang.reflect.Method;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * description:
16 | * 处理权限请求的工具类
17 | *Created by Niko on 2016/4/27.
18 | */
19 | public class PermissionUtils {
20 | // 这个类里面所有的都是静态方法 所有不能让别人去new对象
21 | private PermissionUtils(){
22 | throw new UnsupportedOperationException("cannot be instantiated");
23 | }
24 |
25 | /**
26 | * 判断其是不是6.0以上的版本
27 | * Marshmallow 棉花糖 6.0
28 | * @return
29 | */
30 | public static boolean isOverMarshmallow(){
31 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
32 | }
33 |
34 | /**
35 | * 执行成功的方法
36 | */
37 | public static void executeSucceedMethod(Object reflectObject, int requestCode) {
38 | // 获取class中多有的方法
39 | Method[] methods = reflectObject.getClass().getDeclaredMethods();
40 |
41 | // 遍历找我们打了标记的方法
42 | for (Method method:methods){
43 | // 获取该方法上面有没有打这个成功的标记
44 | PermissionSucceed succeedMethod = method.getAnnotation(PermissionSucceed.class);
45 | if(succeedMethod != null){
46 | // 代表该方法打了标记
47 | // 并且我们的请求码必须 requestCode 一样
48 | int methodCode = succeedMethod.requestCode();
49 | if(methodCode == requestCode){
50 | // 这个就是我们要找的成功方法
51 | // 反射执行该方法
52 | executeMethod(reflectObject,method);
53 | }
54 | }
55 | }
56 | }
57 |
58 | /**
59 | * 反射执行该方法
60 | */
61 | private static void executeMethod(Object reflectObject, Method method) {
62 | // 反射执行方法 第一个是传该方法是属于哪个类 第二个参数是传参数
63 | try {
64 | method.setAccessible(true); // 允许执行私有方法
65 | method.invoke(reflectObject,new Object[]{});
66 | } catch (IllegalAccessException e) {
67 | e.printStackTrace();
68 | } catch (InvocationTargetException e) {
69 | e.printStackTrace();
70 | }
71 | }
72 |
73 | /**
74 | * 获取没有授予的权限
75 | * @param object Activity or Fragment
76 | * @return 没有授予过得权限
77 | */
78 | public static List getDeniedPermissions(Object object, String[] requestPermissions) {
79 | List deniedPermissions = new ArrayList<>();
80 | for (String requestPermission:requestPermissions){
81 | // 把没有授予过的权限加入到集合
82 | if(ContextCompat.checkSelfPermission(getActivity(object), requestPermission)
83 | == PackageManager.PERMISSION_DENIED){
84 | deniedPermissions.add(requestPermission);
85 | }
86 | }
87 | return deniedPermissions;
88 | }
89 |
90 | /**
91 | * 获取Context
92 | * @param object
93 | * @return
94 | */
95 | public static Activity getActivity(Object object) {
96 | if(object instanceof Activity){
97 | return (Activity)object;
98 | }
99 | if(object instanceof Fragment){
100 | return ((Fragment)object).getActivity();
101 | }
102 | return null;
103 | }
104 |
105 |
106 | /**
107 | * 执行失败的方法
108 | */
109 | public static void executeFailMethod(Object reflectObject, int requestCode) {
110 | // 获取class中多有的方法
111 | Method[] methods = reflectObject.getClass().getDeclaredMethods();
112 |
113 | // 遍历找我们打了标记的方法
114 | for (Method method:methods){
115 | // 获取该方法上面有没有打这个失败的标记
116 | PermissionFail failMethod = method.getAnnotation(PermissionFail.class);
117 | if(failMethod != null){
118 | // 代表该方法打了标记
119 | // 并且我们的请求码必须 requestCode 一样
120 | int methodCode = failMethod.requestCode();
121 | if(methodCode == requestCode){
122 | // 这个就是我们要找的成功方法
123 | // 反射执行该方法
124 | executeMethod(reflectObject,method);
125 | }
126 | }
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/framelib/src/main/java/com/example/framelib/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.framelib.fragment;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.example.framelib.pop.PopProgressDialog;
14 | import com.trello.rxlifecycle2.components.support.RxFragment;
15 |
16 |
17 | /**
18 | * Created by niko on 2017/1/11.
19 | */
20 |
21 | public abstract class BaseFragment extends RxFragment {
22 |
23 | public Context mContext;
24 | protected View mView;
25 | public Bundle mBundle=null;
26 | private PopProgressDialog mProgressDialog;
27 |
28 | public void onAttach(Context context) {
29 | super.onAttach(context);
30 | mContext = context;
31 | mBundle = getArguments();
32 | }
33 |
34 | @Nullable
35 | @Override
36 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
37 |
38 | /**
39 | * 缓存Fragment view
40 | */
41 | if (mView == null) {
42 | mView = setLayout(inflater, container);
43 | }
44 | /**
45 | * 缓存的view需要判断是否已被加过parent,
46 | * 如果有,则需要从parent删除,
47 | * 否则,会报错:view已有parent
48 | */
49 | ViewGroup parent = (ViewGroup) mView.getParent();
50 | if (parent != null) {
51 | parent.removeView(mView);
52 | }
53 | setupViews();
54 | return mView;
55 | }
56 |
57 |
58 | /**
59 | * 加载布局文件
60 | *
61 | * @param inflater LayoutInflater
62 | * @param container ViewGroup
63 | * @return View
64 | */
65 | protected abstract View setLayout(LayoutInflater inflater, ViewGroup container);
66 |
67 | /**
68 | * 给view赋值
69 | */
70 | protected abstract void setupViews();
71 |
72 |
73 | /**
74 | * 获得View
75 | * @param id
76 | * @param
77 | * @return
78 | */
79 | protected V findViewById(int id) {
80 | //noinspection unchecked
81 | if(mView!=null){
82 | return (V) mView.findViewById(id);
83 | }
84 | try {
85 | throw new Exception("请初始化fragment Layout");
86 | } catch (Exception e) {
87 | Log.e("TAG==>", "Exception: 主动抛出异常", e);
88 | }
89 | return null;
90 | }
91 |
92 |
93 |
94 | /**
95 | * 网络进度条启动
96 | */
97 | public void showProgressDialog(){
98 | showProgressDialog("加载中");
99 | }
100 |
101 |
102 |
103 | /**
104 | * 网络进度条启动
105 | * @param msg
106 | */
107 | public void showProgressDialog(String msg){
108 | if(mProgressDialog==null) {
109 | mProgressDialog = new PopProgressDialog((Activity) mContext);
110 | mProgressDialog.setPopupWindowFullScreen(true);
111 | mView.post(new Runnable(){
112 | @Override
113 | public void run() {
114 | mProgressDialog.showPopupWindow();
115 | }
116 | });
117 |
118 | }
119 | }
120 |
121 |
122 | /**
123 | * 网络进度条关闭
124 | */
125 | public void dismissProgressDialog(){
126 | if(mProgressDialog!=null){
127 | mProgressDialog.dismiss();
128 | }
129 | }
130 |
131 |
132 |
133 | /**
134 | * 跳转界面 bundle
135 | * @param mContext 当前跳转的界面
136 | * @param clazz 要跳转的界面
137 | * @param bundle 传值
138 | */
139 | public void skip(Context mContext, Class clazz, Bundle bundle) {
140 | Intent intent = new Intent(mContext, clazz);
141 | if(bundle!=null) {
142 | intent.putExtras(bundle);
143 | }
144 | mContext.startActivity(intent);
145 | }
146 |
147 | /**
148 | * 跳转界面带回调函数
149 | * @param mContext
150 | * @param clazz
151 | * @param bundle
152 | */
153 | public void skipForResult(Context mContext, Class clazz, Bundle bundle, int requestCode){
154 | Intent intent = new Intent(mContext, clazz);
155 | if(bundle!=null) {
156 | intent.putExtras(bundle);
157 | }
158 | startActivityForResult(intent,requestCode);
159 | }
160 |
161 |
162 | @Override
163 | public void onDestroy() {
164 | super.onDestroy();
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/niko/framemodel/net/RetrofitClient.java:
--------------------------------------------------------------------------------
1 | package com.example.niko.framemodel.net;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.IOException;
6 | import java.security.cert.CertificateException;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | import javax.net.ssl.SSLContext;
10 | import javax.net.ssl.SSLSocketFactory;
11 | import javax.net.ssl.TrustManager;
12 | import javax.net.ssl.X509TrustManager;
13 |
14 | import okhttp3.Interceptor;
15 | import okhttp3.OkHttpClient;
16 | import okhttp3.Response;
17 | import okhttp3.logging.HttpLoggingInterceptor;
18 | import retrofit2.Retrofit;
19 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
20 | import retrofit2.converter.gson.GsonConverterFactory;
21 |
22 | /**
23 | * 网络请求管理器
24 | * Created by niko on 2017/4/29.
25 | */
26 |
27 | public class RetrofitClient {
28 | private static RetrofitClient retrofitClient= null;
29 | private final static String hostPath = "http://music.163.com";
30 | private static ApiService apiService=null;
31 |
32 |
33 | private RetrofitClient(){
34 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
35 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
36 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
37 | .addInterceptor(new HttpInterceptor())
38 | .retryOnConnectionFailure(true)
39 | .connectTimeout(8, TimeUnit.SECONDS)
40 | .build();
41 |
42 | /**
43 | * Retrofit 初始化
44 | */
45 | Retrofit retrofit = new Retrofit.Builder().baseUrl(hostPath)
46 | .client(okHttpClient)
47 | .addConverterFactory(GsonConverterFactory.create())
48 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
49 | .build();
50 | apiService = retrofit.create(ApiService.class);
51 | }
52 |
53 | /**
54 | * 获得请求接口服务
55 | * @return
56 | */
57 | public static ApiService getApiService(){
58 | if(apiService==null){
59 | retrofitClient = new RetrofitClient();
60 | }
61 | return apiService;
62 | }
63 |
64 |
65 | /**
66 | * 文件上传下载
67 | * @param progresslistener
68 | * @return
69 | */
70 | public static ApiService getUploadOrDownloadService(final ProgressListener progresslistener){
71 |
72 | OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
73 | .addNetworkInterceptor(new Interceptor() {
74 | @Override
75 | public Response intercept(Chain chain) throws IOException {
76 | Response originalResponse = chain.proceed(chain.request());
77 | return originalResponse.newBuilder()
78 | .body(new ProgressResponseBody(originalResponse.body(),
79 | progresslistener)).build();
80 |
81 | }
82 | })
83 | .retryOnConnectionFailure(true)
84 | .connectTimeout(8, TimeUnit.SECONDS)
85 | .readTimeout(10, TimeUnit.SECONDS)
86 | .writeTimeout(10, TimeUnit.SECONDS);
87 | try {
88 | // Create a trust manager that does not validate certificate chains
89 | final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
90 | @Override
91 | public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
92 | }
93 |
94 | @Override
95 | public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
96 | }
97 |
98 | @Override
99 | public java.security.cert.X509Certificate[] getAcceptedIssuers() {
100 | return new java.security.cert.X509Certificate[0];
101 | }
102 | }};
103 | // Install the all-trusting trust manager
104 | final SSLContext sslContext = SSLContext.getInstance("TLS");
105 | sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
106 | // Create an ssl socket factory with our all-trusting manager
107 | final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
108 |
109 | okHttpClient.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
110 | } catch (Exception e) {
111 | e.printStackTrace();
112 | }
113 |
114 | OkHttpClient builder = okHttpClient.build();
115 |
116 |
117 | Retrofit retrofit = new Retrofit.Builder().baseUrl(hostPath) // "https://timgsa.baidu.com/"
118 | .client(builder)
119 | .addConverterFactory(GsonConverterFactory.create())
120 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
121 | .build();
122 |
123 | return retrofit.create(ApiService.class);
124 | }
125 |
126 |
127 |
128 |
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/framelib/src/main/java/com/example/framelib/utils/permission/PermissionHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.framelib.utils.permission;
2 |
3 | import android.app.Activity;
4 | import android.content.DialogInterface;
5 | import android.support.v4.app.ActivityCompat;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v7.app.AlertDialog;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by Niko on 2016/4/27.
13 | */
14 | public class PermissionHelper {
15 | // 1. 传什么参数
16 | // 1.1. Object Fragment or Activity 1.2. int 请求码 1.3.需要请求的权限 string[]
17 | private Object mObject;
18 | private int mRequestCode;
19 | private String[] mRequestPermission;
20 | private String mHint=null;
21 |
22 | private PermissionHelper(Object object){
23 | this.mObject = object;
24 | }
25 |
26 | /**
27 | * 权限请求
28 | * @param activity or Fragment
29 | * @param requestCode 请求码
30 | * @param permissions 申请的权限集
31 | * @param hint 提示信息 为null 或则为 “” 时 取消提示框
32 | */
33 | public static void requestPermission(Activity activity, int requestCode, String[] permissions, String hint){
34 | PermissionHelper.with(activity).requestCode(requestCode).
35 | requestPermission(permissions).setHint(hint).request();
36 | }
37 |
38 | public static void requestPermission(Fragment fragment, int requestCode, String[] permissions, String hint){
39 | PermissionHelper.with(fragment).requestCode(requestCode).
40 | requestPermission(permissions).setHint(hint).request();
41 | }
42 |
43 | // 2.2 链式的方式传
44 | // 传Activity
45 | public static PermissionHelper with(Activity activity){
46 | return new PermissionHelper(activity);
47 | }
48 |
49 | // 传Fragment
50 | public static PermissionHelper with(Fragment fragment){
51 | return new PermissionHelper(fragment);
52 | }
53 |
54 | // 添加一个请求码
55 | public PermissionHelper requestCode(int requestCode){
56 | this.mRequestCode = requestCode;
57 | return this;
58 | }
59 |
60 | // 添加请求的权限数组
61 | public PermissionHelper requestPermission(String... permissions){
62 | this.mRequestPermission = permissions;
63 | return this;
64 | }
65 | //设置提示信息
66 | private PermissionHelper setHint(String hint){
67 |
68 | this.mHint = hint;
69 | return this;
70 | }
71 |
72 | /**
73 | * 3.1 真正判断和发起请求权限
74 | */
75 | public void request() {
76 | // 3.2 首先判断当前的版本是不是6.0 及以上
77 | if(!PermissionUtils.isOverMarshmallow()){
78 | // 3.3 如果不是6.0以上 那么直接执行方法 反射获取执行方法
79 | // 执行什么方法并不确定 那么我们只能采用注解的方式给方法打一个标记,
80 | // 然后通过反射去执行。 注解 + 反射 执行Activity里面的callPhone
81 | PermissionUtils.executeSucceedMethod(mObject,mRequestCode);
82 | return;
83 | }
84 |
85 | // 3.3 如果是6.0以上 那么首先需要判断权限是否授予
86 | // 需要申请的权限中 获取没有授予过得权限
87 | List deniedPermissions = PermissionUtils.getDeniedPermissions(mObject,mRequestPermission);
88 |
89 | // 3.3.1 如果授予了 那么我们直接执行方法 反射获取执行方法
90 | if(deniedPermissions.size() == 0){
91 | // 全部都是授予过的
92 | PermissionUtils.executeSucceedMethod(mObject,mRequestCode);
93 | }else {
94 | warnHint(deniedPermissions);
95 | }
96 | }
97 |
98 |
99 | /**
100 | * 如果没有授予 那么我们就申请权限 申请权限
101 | */
102 | private void requestPermissions(List deniedPermissions){
103 | ActivityCompat.requestPermissions(PermissionUtils.getActivity(mObject),
104 | deniedPermissions.toArray(new String[deniedPermissions.size()]),
105 | mRequestCode);
106 | }
107 |
108 | /**
109 | * 警告提示
110 | */
111 | public void warnHint(final List deniedPermissions){
112 |
113 | if(mHint==null||mHint.equals("")){
114 | requestPermissions(deniedPermissions);
115 | return ;
116 | }
117 |
118 | AlertDialog.Builder builder = new AlertDialog.Builder(PermissionUtils.getActivity(mObject));
119 | builder.setTitle("权限提示");
120 | builder.setMessage(mHint);
121 | builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
122 | @Override
123 | public void onClick(DialogInterface dialog, int which) {
124 | requestPermissions(deniedPermissions);
125 | }
126 | });
127 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
128 | @Override
129 | public void onClick(DialogInterface dialog, int which) {
130 | }
131 | });
132 | builder.create();
133 | builder.show();
134 | }
135 |
136 |
137 | /**
138 | * 处理申请权限的回调
139 | */
140 | public static void requestPermissionsResult(Object object, int requestCode,
141 | String[] permissions) {
142 | // 再次获取没有授予的权限
143 | List deniedPermissions = PermissionUtils.getDeniedPermissions(object,permissions);
144 |
145 | if(deniedPermissions.size() == 0){
146 | // 权限用户都同意授予了
147 | PermissionUtils.executeSucceedMethod(object,requestCode);
148 | }else{
149 | // 你申请的权限中 有用户不同意的
150 | PermissionUtils.executeFailMethod(object,requestCode);
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/niko/framemodel/activity/RxjavaAndRetrofitActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.niko.framemodel.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.AppBarLayout;
5 | import android.support.design.widget.CoordinatorLayout;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.StaggeredGridLayoutManager;
8 | import android.support.v7.widget.Toolbar;
9 | import android.util.Log;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.ImageView;
13 |
14 | import com.example.framelib.activtiy.BaseActivity;
15 | import com.example.framelib.utils.Tools.StatusBarUtils;
16 | import com.example.niko.framemodel.R;
17 | import com.example.niko.framemodel.adapter.ImageRecyclerViewAdapter;
18 | import com.example.niko.framemodel.model.MusicModel;
19 | import com.example.niko.framemodel.model.TracksBean;
20 | import com.example.niko.framemodel.net.RetrofitClient;
21 | import com.jcodecraeer.xrecyclerview.ProgressStyle;
22 | import com.jcodecraeer.xrecyclerview.XRecyclerView;
23 |
24 | import java.util.concurrent.TimeUnit;
25 |
26 | import butterknife.BindView;
27 | import butterknife.ButterKnife;
28 | import io.reactivex.Observer;
29 | import io.reactivex.android.schedulers.AndroidSchedulers;
30 | import io.reactivex.disposables.Disposable;
31 | import io.reactivex.schedulers.Schedulers;
32 | import io.realm.Realm;
33 | import io.realm.RealmChangeListener;
34 | import io.realm.RealmResults;
35 | import retrofit2.Response;
36 |
37 | /**
38 | * Created by niko on 2017/3/17.
39 | */
40 |
41 | public class RxjavaAndRetrofitActivity extends BaseActivity {
42 |
43 |
44 | @BindView(R.id.toolbar)
45 | Toolbar toolbar;
46 | @BindView(R.id.appbar)
47 | AppBarLayout appbar;
48 | @BindView(R.id.recyclerview)
49 | XRecyclerView mRecyclerView;
50 | @BindView(R.id.main_content)
51 | CoordinatorLayout mainContent;
52 | @BindView(R.id.backdrop)
53 | ImageView backdrop;
54 | private ImageRecyclerViewAdapter adapter;
55 |
56 | @Override
57 | protected void setLayout() {
58 | setContentView(R.layout.ok_http_activity);
59 | ButterKnife.bind(this);
60 | }
61 |
62 | @Override
63 | protected void setupViews() {
64 | setSupportActionBar(toolbar);
65 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
66 |
67 | getSupportActionBar().setTitle("Realm数据库和网络请求");
68 |
69 | StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,
70 | StaggeredGridLayoutManager.VERTICAL);
71 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
72 |
73 | mRecyclerView.setLayoutManager(layoutManager);
74 | mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
75 | mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
76 | mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
77 | mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
78 | @Override
79 | public void onRefresh() {
80 | requestData();
81 | }
82 |
83 | @Override
84 | public void onLoadMore() {
85 |
86 | }
87 | });
88 | adapter = new ImageRecyclerViewAdapter(mContext);
89 |
90 | mRecyclerView.setAdapter(adapter);
91 | mRecyclerView.refresh();
92 | }
93 |
94 | @Override
95 | public boolean onOptionsItemSelected(MenuItem item) {
96 | switch (item.getItemId()){
97 |
98 | case android.R.id.home:
99 |
100 | finish();
101 | break;
102 | }
103 | return true;
104 | }
105 |
106 | public void requestData() {
107 |
108 | /**
109 | * Retrofit 网络请求Rxjava线程切换
110 | */
111 | RetrofitClient.getApiService().getMusic("58451795")
112 | .throttleFirst(500, TimeUnit.MILLISECONDS)//500毫秒内同样请求丢弃
113 | .subscribeOn(Schedulers.newThread())
114 | .observeOn(AndroidSchedulers.mainThread())
115 | .compose(this.>bindToLifecycle())
116 | .subscribe(new Observer>() {
117 | @Override
118 | public void onSubscribe(Disposable d) {
119 | Log.e("TAG", "onSubscribe");
120 |
121 | }
122 |
123 | @Override
124 | public void onNext(final Response value) {
125 |
126 |
127 | /**
128 | * 数据库存取代码
129 | */
130 | Realm.getDefaultInstance().executeTransactionAsync(new Realm.Transaction() {
131 | @Override
132 | public void execute(Realm realm) {
133 | realm.copyToRealmOrUpdate(value.body().getResult().getTracks());
134 | }
135 | });
136 |
137 | RealmResults tracksBeans = Realm.getDefaultInstance().where(TracksBean.class).findAllAsync();
138 | tracksBeans.addChangeListener(new RealmChangeListener>() {
139 | @Override
140 | public void onChange(RealmResults element) {
141 | adapter.setData(element);
142 | }
143 | });
144 | adapter.setData(tracksBeans);
145 |
146 | }
147 |
148 | @Override
149 | public void onError(Throwable e) {
150 | mRecyclerView.refreshComplete();
151 | e.printStackTrace();
152 | }
153 |
154 | @Override
155 | public void onComplete() {
156 | mRecyclerView.refreshComplete();
157 | Log.e("TAG", "onComplete");
158 | }
159 | });
160 |
161 |
162 | }
163 |
164 |
165 | @Override
166 | public void setStatusBar() {
167 | StatusBarUtils.with(this)
168 | .init();
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/niko/framemodel/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.niko.framemodel.activity;
2 |
3 |
4 | import android.Manifest;
5 | import android.app.Activity;
6 | import android.app.Application;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.annotation.NonNull;
10 | import android.util.Log;
11 | import android.widget.Button;
12 | import android.widget.Toast;
13 |
14 | import com.example.framelib.activtiy.BaseActivity;
15 | import com.example.framelib.pop.PopDownLoadProgress;
16 | import com.example.framelib.utils.Tools.SDCardUtils;
17 | import com.example.framelib.utils.Tools.StatusBarUtils;
18 | import com.example.framelib.utils.permission.PermissionFail;
19 | import com.example.framelib.utils.permission.PermissionHelper;
20 | import com.example.framelib.utils.permission.PermissionSucceed;
21 | import com.example.niko.framemodel.R;
22 | import com.example.niko.framemodel.config.Config;
23 | import com.example.niko.framemodel.net.ProgressListener;
24 | import com.example.niko.framemodel.net.RetrofitClient;
25 | import com.facebook.drawee.view.SimpleDraweeView;
26 | import com.jakewharton.rxbinding2.view.RxView;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.io.InputStream;
31 | import java.util.concurrent.TimeUnit;
32 |
33 | import butterknife.BindView;
34 | import butterknife.ButterKnife;
35 | import butterknife.OnClick;
36 | import io.reactivex.functions.Consumer;
37 | import okhttp3.ResponseBody;
38 | import retrofit2.Call;
39 | import retrofit2.Callback;
40 | import retrofit2.Response;
41 |
42 | public class MainActivity extends BaseActivity {
43 | public static final int REQUECT_CODE_SDCARD = 2;
44 | private static final int REQUECT_CODE_CALL_PHONE = 3;
45 | private String mApkUrl = "http://7xk9dj.com1.z0.glb.clouddn.com/BGAUpdateDemo_v1.0.1_debug.apk";
46 | private String image = "http://sw.bos.baidu.com/sw-search-sp/software/28e3e9a56da44/BaiduNetdisk_mac_2.2.0.dmg";
47 | @BindView(R.id.imageview)
48 | SimpleDraweeView mImageView;
49 | @BindView(R.id.btn_net)
50 | Button mBtnNet;
51 | @BindView(R.id.btn_1)
52 | Button btn1;
53 |
54 | @Override
55 | protected void setLayout() {
56 | setContentView(R.layout.activity_main);
57 | ButterKnife.bind(this);
58 | }
59 |
60 |
61 |
62 | @Override
63 | protected void setupViews() {
64 |
65 | /**
66 | * fresco 网络图片加载
67 | */
68 | Log.e("mImageView", (mImageView == null) + "");
69 | mImageView.setImageURI("http://f.hiphotos.baidu.com/image/pic/item/00e93901213fb80e0ee553d034d12f2eb9389484.jpg");
70 |
71 | RxView.clicks(mImageView)
72 | .throttleFirst(1, TimeUnit.SECONDS)
73 | .subscribe(new Consumer