actionInternalCodeMap){
19 | this.actionOuterCodeMap = actionOuterCodeMap;
20 | this.actionInternalCodeMap = actionInternalCodeMap;
21 | }
22 |
23 | public ServerOuterCodeMessage startCheckOuterCode(String url,int outerCode){
24 | return new ServerOuterCodeMessage(url,System.currentTimeMillis(),outerCode,actionOuterCodeMap.get(outerCode));
25 | }
26 |
27 | public ServerInternalCodeMessage startCheckInternalCode(String url,E e){
28 | return new ServerInternalCodeMessage(url,System.currentTimeMillis(),e,actionInternalCodeMap.get(e));
29 | }
30 |
31 | /**
32 | * 服务器外码封装类
33 | */
34 | public class ServerOuterCodeMessage {
35 |
36 | //记录url地址
37 | private String url;
38 | //记录处理的时间
39 | private long handlerTime;
40 | //记录外码
41 | private int outerCode;
42 | //记录外对应的状态
43 | private T handlerResult;
44 |
45 | public ServerOuterCodeMessage(String url, long handlerTime, int outerCode, T handlerResult) {
46 | this.url = url;
47 | this.handlerTime = handlerTime;
48 | this.outerCode = outerCode;
49 | this.handlerResult = handlerResult;
50 | }
51 |
52 | public String getUrl() {
53 | return url;
54 | }
55 |
56 | public void setUrl(String url) {
57 | this.url = url;
58 | }
59 |
60 | public long getHandlerTime() {
61 | return handlerTime;
62 | }
63 |
64 | public void setHandlerTime(long handlerTime) {
65 | this.handlerTime = handlerTime;
66 | }
67 |
68 | public int getOuterCode() {
69 | return outerCode;
70 | }
71 |
72 | public void setOuterCode(int outerCode) {
73 | this.outerCode = outerCode;
74 | }
75 |
76 | public T getHandlerResult() {
77 | return handlerResult;
78 | }
79 |
80 | public void setHandlerResult(T handlerResult) {
81 | this.handlerResult = handlerResult;
82 | }
83 | }
84 |
85 | /**
86 | * 服务器内码封装类
87 | */
88 | public class ServerInternalCodeMessage{
89 |
90 | //记录url地址
91 | private String url;
92 | //记录处理的时间
93 | private long handlerTime;
94 | //记录内码
95 | private E internalCode;
96 | //记录内码的状态
97 | private F handlerResult;
98 |
99 | public ServerInternalCodeMessage(String url, long handlerTime, E internalCode, F handlerResult) {
100 | this.url = url;
101 | this.handlerTime = handlerTime;
102 | this.internalCode = internalCode;
103 | this.handlerResult = handlerResult;
104 | }
105 |
106 | public String getUrl() {
107 | return url;
108 | }
109 |
110 | public void setUrl(String url) {
111 | this.url = url;
112 | }
113 |
114 | public long getHandlerTime() {
115 | return handlerTime;
116 | }
117 |
118 | public void setHandlerTime(long handlerTime) {
119 | this.handlerTime = handlerTime;
120 | }
121 |
122 | public E getInternalCode() {
123 | return internalCode;
124 | }
125 |
126 | public void setInternalCode(E internalCode) {
127 | this.internalCode = internalCode;
128 | }
129 |
130 | public F getHandlerResult() {
131 | return handlerResult;
132 | }
133 |
134 | public void setHandlerResult(F handlerResult) {
135 | this.handlerResult = handlerResult;
136 | }
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/net/ReturnCodeHandler.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.net;
2 |
3 | public class ReturnCodeHandler{
4 | private ReturnCode returnCode;
5 |
6 | public ReturnCodeHandler(ReturnCode returnCode){
7 | this.returnCode = returnCode;
8 | }
9 |
10 | public void checkOuterCode(String url,int outerCode,OuterCodeHandlerCallback outerCodeHandlerCallback){
11 | outerCodeHandlerCallback.outerCodeHandlerCallback(returnCode.startCheckOuterCode(url,outerCode));
12 | }
13 |
14 | public void checkInternalCode(String url,Object internalCode,InternalCodeHandlerCallback internalCodeHandlerCallback){
15 | internalCodeHandlerCallback.internalCodeHandlerCallback(returnCode.startCheckInternalCode(url,internalCode));
16 | }
17 |
18 | public interface OuterCodeHandlerCallback{
19 | void outerCodeHandlerCallback(ReturnCode.ServerOuterCodeMessage serverOuterCodeMessage);
20 | }
21 |
22 | public interface InternalCodeHandlerCallback{
23 | void internalCodeHandlerCallback(ReturnCode.ServerInternalCodeMessage serverInternalCodeMessage);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/save/key_value/BaseKeyValueHelper.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.save.key_value;
2 |
3 | /**
4 | * SharedPreference或者MMKV的抽象层
5 | */
6 | public abstract class BaseKeyValueHelper {
7 |
8 | private String name;
9 |
10 | public BaseKeyValueHelper(String name){
11 | this.name = name;
12 | }
13 |
14 | //存储获取非加密数据
15 | public abstract void save(String key,Object value);
16 | public abstract Object getValue(String key,Object defaultValue);
17 |
18 | //存储获取加密数据
19 | public abstract void safeSave(String encryptionString,String key,Object value);
20 | public abstract Object safeGetValue(String encryptionString,String key,Object defaultValue);
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/save/key_value/MMKVHelper.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.save.key_value;
2 |
3 | import com.tencent.mmkv.MMKV;
4 |
5 | public class MMKVHelper extends BaseKeyValueHelper {
6 |
7 | private MMKV mmkv;
8 |
9 | public MMKVHelper(String name) {
10 | super(name);
11 | mmkv = MMKV.mmkvWithID(name);
12 | }
13 |
14 | @Override
15 | public void save(String key, Object value) {
16 | if (value instanceof String) {
17 | mmkv.encode(key,(String)value);
18 | } else if (value instanceof Integer) {
19 | mmkv.encode(key,(Integer) value);
20 | } else if (value instanceof Boolean) {
21 | mmkv.encode(key,(Boolean) value);
22 | } else if (value instanceof Float) {
23 | mmkv.encode(key,(Float) value);
24 | } else if (value instanceof Long) {
25 | mmkv.encode(key,(Long) value);
26 | } else {
27 | mmkv.encode(key,(String)value);
28 | }
29 | }
30 |
31 | @Override
32 | public Object getValue(String key, Object defaultValue) {
33 | Object value;
34 | if (defaultValue instanceof String) {
35 | value = mmkv.decodeString(key);
36 | if(value == null) value = defaultValue;
37 | } else if (defaultValue instanceof Integer) {
38 | value = mmkv.getInt(key, (Integer) defaultValue);
39 | } else if (defaultValue instanceof Boolean) {
40 | value = mmkv.getBoolean(key, (Boolean) defaultValue);
41 | } else if (defaultValue instanceof Float) {
42 | value = mmkv.getFloat(key, (Float) defaultValue );
43 | } else if (defaultValue instanceof Long) {
44 | value = mmkv.getLong(key, (Long) defaultValue);
45 | } else {
46 | value = mmkv.getString(key, (String) defaultValue);
47 | }
48 | return value;
49 | }
50 |
51 | @Override
52 | public void safeSave(String encryptionString, String key, Object value) {
53 | save(encryptionString + key,value);
54 | }
55 |
56 | @Override
57 | public Object safeGetValue(String encryptionString, String key, Object defaultValue) {
58 | return getValue(encryptionString + key,defaultValue);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/save/key_value/SharePreferenceHelper.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.save.key_value;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | public class SharePreferenceHelper extends BaseKeyValueHelper {
7 |
8 | private SharedPreferences sharedPreferences;
9 | /*
10 | * 保存手机里面的名字
11 | */private SharedPreferences.Editor editor;
12 |
13 |
14 | public SharePreferenceHelper(Context context, String fileName) {
15 | super(fileName);
16 | sharedPreferences = context.getSharedPreferences(fileName,
17 | Context.MODE_PRIVATE);
18 | editor = sharedPreferences.edit();
19 | }
20 |
21 | @Override
22 | public void save(String key, Object value) {
23 | if (value instanceof String) {
24 | editor.putString(key, (String) value);
25 | } else if (value instanceof Integer) {
26 | editor.putInt(key, (Integer) value);
27 | } else if (value instanceof Boolean) {
28 | editor.putBoolean(key, (Boolean) value);
29 | } else if (value instanceof Float) {
30 | editor.putFloat(key, (Float) value);
31 | } else if (value instanceof Long) {
32 | editor.putLong(key, (Long) value);
33 | } else {
34 | editor.putString(key, value.toString());
35 | }
36 | editor.commit();
37 | }
38 |
39 | @Override
40 | public Object getValue(String key, Object defaultObject) {
41 | if (defaultObject instanceof String) {
42 | return sharedPreferences.getString(key, (String) defaultObject);
43 | } else if (defaultObject instanceof Integer) {
44 | return sharedPreferences.getInt(key, (Integer) defaultObject);
45 | } else if (defaultObject instanceof Boolean) {
46 | return sharedPreferences.getBoolean(key, (Boolean) defaultObject);
47 | } else if (defaultObject instanceof Float) {
48 | return sharedPreferences.getFloat(key, (Float) defaultObject);
49 | } else if (defaultObject instanceof Long) {
50 | return sharedPreferences.getLong(key, (Long) defaultObject);
51 | } else {
52 | return sharedPreferences.getString(key, null);
53 | }
54 | }
55 |
56 | @Override
57 | public void safeSave(String encryptionString, String key, Object value) {
58 | save(encryptionString + key, value);
59 | }
60 |
61 | @Override
62 | public Object safeGetValue(String encryptionString, String key, Object defaultObject) {
63 | String newKey = encryptionString + key;
64 | return getValue(newKey, defaultObject);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/BaseMvpActivity.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.ellen.basequickandroid.base.BaseActivity;
7 | import com.ellen.basequickandroid.structure.mvp.basemvp.BasePresenter;
8 |
9 | public abstract class BaseMvpActivity extends BaseActivity {
10 | protected P mPresenter;
11 |
12 | @Override
13 | protected void onCreate(@Nullable Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | initMVP();
16 | }
17 |
18 | protected abstract void initMVP();
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/basemvp/BaseModel.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.basemvp;
2 |
3 | public interface BaseModel {
4 | }
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/basemvp/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.basemvp;
2 |
3 | public class BasePresenter {
4 |
5 | //Model层
6 | public M mModel;
7 | //View层
8 | public V mView;
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/basemvp/BaseView.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.basemvp;
2 |
3 | //View层
4 | public interface BaseView{
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/demo/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.demo.login;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.widget.Button;
6 |
7 | import com.ellen.basequickandroid.R;
8 | import com.ellen.basequickandroid.base.BaseActivity;
9 | import com.ellen.basequickandroid.base.BaseToast;
10 | import com.ellen.basequickandroid.dialog.AutoToast;
11 | import com.ellen.basequickandroid.structure.mvp.BaseMvpActivity;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import butterknife.OnClick;
16 |
17 | public class LoginActivity extends BaseMvpActivity implements LoginAgreement.LoginAgreementView, BaseActivity.ButterKnifeInterface {
18 |
19 | @BindView(R.id.bt)
20 | Button btLogin;
21 |
22 | @OnClick(R.id.bt)
23 | void onClick(View view){
24 | login("ellen","1234");
25 | AutoToast autoToast = new AutoToast(this);
26 | autoToast.show();
27 | }
28 |
29 | @Override
30 | protected void setStatus() {
31 |
32 | }
33 |
34 | @Override
35 | protected int setLayoutId() {
36 | return R.layout.activity_login;
37 | }
38 |
39 | @Override
40 | protected void initView() {
41 |
42 | }
43 |
44 | @Override
45 | protected void initData() {
46 |
47 | }
48 |
49 | @Override
50 | protected void destory() {
51 |
52 | }
53 |
54 | @Override
55 | protected Boolean isSetVerticalScreen() {
56 | return null;
57 | }
58 |
59 | @Override
60 | public void login(String account, String password) {
61 | if(checkAccountPassword(account,password)){
62 | mPresenter.login(account,password);
63 | }
64 | }
65 |
66 | @Override
67 | public boolean checkAccountPassword(String account, String password) {
68 | return true;
69 | }
70 |
71 | @Override
72 | public void loginSuccess(String json) {
73 | btLogin.setText("登陆成功");
74 | }
75 |
76 | @Override
77 | public void loginFailure(String errMessage) {
78 | btLogin.setText("登陆失败");
79 | }
80 |
81 | @Override
82 | public void initButterKnife() {
83 | ButterKnife.bind(this);
84 | }
85 |
86 | @Override
87 | protected void initMVP() {
88 | mPresenter = new LoginPresenter();
89 | mPresenter.mModel = new LoginModel();
90 | mPresenter.mView = this;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/demo/login/LoginAgreement.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.demo.login;
2 |
3 | import com.ellen.basequickandroid.structure.mvp.basemvp.BaseModel;
4 | import com.ellen.basequickandroid.structure.mvp.basemvp.BasePresenter;
5 | import com.ellen.basequickandroid.structure.mvp.basemvp.BaseView;
6 |
7 | public interface LoginAgreement {
8 |
9 | //协议化M层
10 | interface LoginAgreementModel extends BaseModel{
11 | boolean login(String account,String password);
12 | }
13 |
14 | //协议化View层
15 | interface LoginAgreementView extends BaseView{
16 | //登陆的时候回调
17 | void login(String account,String password);
18 | //验证账号密码的规范
19 | boolean checkAccountPassword(String account,String password);
20 | //登陆成功回调,json为服务器返回的Json
21 | void loginSuccess(String json);
22 | //登陆失败回调,errMessage为错误信息
23 | void loginFailure(String errMessage);
24 | }
25 |
26 | abstract class LoginAgreementPresenter extends BasePresenter{
27 | protected abstract void login(String account,String password);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/demo/login/LoginModel.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.demo.login;
2 |
3 | public class LoginModel implements LoginAgreement.LoginAgreementModel {
4 |
5 | @Override
6 | public boolean login(String account, String password) {
7 | return true;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/structure/mvp/demo/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.structure.mvp.demo.login;
2 |
3 | import io.reactivex.Observable;
4 | import io.reactivex.ObservableEmitter;
5 | import io.reactivex.ObservableOnSubscribe;
6 | import io.reactivex.Observer;
7 | import io.reactivex.android.schedulers.AndroidSchedulers;
8 | import io.reactivex.disposables.Disposable;
9 | import io.reactivex.schedulers.Schedulers;
10 |
11 | public class LoginPresenter extends LoginAgreement.LoginAgreementPresenter {
12 |
13 | @Override
14 | protected void login(final String account, final String password) {
15 |
16 | Observable.create(new ObservableOnSubscribe() {
17 | @Override
18 | public void subscribe(ObservableEmitter emitter) throws Exception {
19 | emitter.onNext(mModel.login(account,password));
20 | emitter.onComplete();
21 | }
22 | }).subscribeOn(Schedulers.io())
23 | .observeOn(AndroidSchedulers.mainThread())
24 | .subscribe(new Observer() {
25 | @Override
26 | public void onSubscribe(Disposable d) {
27 |
28 | }
29 |
30 | @Override
31 | public void onNext(Boolean value) {
32 | if(value){
33 | //完成登陆
34 | mView.loginSuccess("");
35 | }else {
36 | //失败登陆
37 | mView.loginFailure("sdsd");
38 | }
39 | }
40 |
41 | @Override
42 | public void onError(Throwable e) {
43 |
44 | }
45 |
46 | @Override
47 | public void onComplete() {
48 |
49 | }
50 | });
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/BaseLog.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.util.Log;
4 |
5 | public class BaseLog {
6 |
7 | private static boolean isLog = false;
8 |
9 | public static boolean isIsLog() {
10 | return isLog;
11 | }
12 |
13 | public static void setIsLog(boolean isLog) {
14 | BaseLog.isLog = isLog;
15 | }
16 |
17 | public static void e(String tag,String cotent){
18 | if(isIsLog()){
19 | Log.e(tag,cotent);
20 | }
21 | }
22 |
23 | public static void d(String tag,String content){
24 | if(isIsLog()){
25 | Log.d(tag,content);
26 | }
27 | }
28 |
29 | public static void i(String tag,String content){
30 | if(isIsLog()){
31 | Log.i(tag,content);
32 | }
33 | }
34 |
35 | public static void v(String tag,String content){
36 | if(isIsLog()){
37 | Log.v(tag,content);
38 | }
39 | }
40 |
41 | public static void w(String tag,String content){
42 | if(isIsLog()){
43 | Log.w(tag,content);
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/BitmapUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.drawable.Drawable;
10 | import android.net.Uri;
11 |
12 | import java.io.File;
13 | import java.io.FileNotFoundException;
14 | import java.io.FileOutputStream;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 |
18 | /**
19 | *
20 | * 1.将Drawable转化为Bitmap
21 | * 2.获取到纯色Bitmap
22 | *
23 | */
24 | public class BitmapUtils {
25 |
26 | //Drawable -> Bitmap
27 | public static Bitmap drawableToBitmap(Drawable drawable) {
28 | // 取 drawable 的长宽
29 | int w = drawable.getIntrinsicWidth();
30 | int h = drawable.getIntrinsicHeight();
31 | // 取 drawable 的颜色格式
32 | Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
33 | : Bitmap.Config.RGB_565;
34 | // 建立对应 bitmap
35 | Bitmap bitmap = Bitmap.createBitmap(w, h, config);
36 | // 建立对应 bitmap 的画布
37 | Canvas canvas = new Canvas(bitmap);
38 | drawable.setBounds(0, 0, w, h);
39 | // 把 drawable 内容画到画布中
40 | drawable.draw(canvas);
41 | return bitmap;
42 | }
43 |
44 | //获取到纯色Bitmap
45 | public static Bitmap getColorBitmap(int width,int height,String colorString){
46 | Bitmap bitmap = Bitmap.createBitmap(width, height,
47 | Bitmap.Config.ARGB_8888);
48 | bitmap.eraseColor(Color.parseColor(colorString));//填充颜色
49 | return bitmap;
50 | }
51 |
52 | //通过本地地址获取到Bitmap
53 | public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) {
54 | BitmapFactory.Options options = new BitmapFactory.Options();
55 | options.inJustDecodeBounds = true;
56 | options.inPreferredConfig = Bitmap.Config.ARGB_8888;
57 | BitmapFactory.decodeFile(filePath, options);
58 | int inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
59 | options.inSampleSize = inSampleSize;
60 | options.inJustDecodeBounds = false;
61 | return BitmapFactory.decodeFile(filePath, options);
62 | }
63 |
64 | public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
65 | // Raw height and width of image
66 | final int height = options.outHeight;
67 | final int width = options.outWidth;
68 | int inSampleSize = 1;
69 |
70 | if (height > reqHeight || width > reqWidth) {
71 |
72 | final int halfHeight = height / 2;
73 | final int halfWidth = width / 2;
74 |
75 | // Calculate the largest inSampleSize value that is a power of 2 and keeps both
76 | // height and width larger than the requested height and width.
77 | while ((halfHeight / inSampleSize) >= reqHeight
78 | && (halfWidth / inSampleSize) >= reqWidth) {
79 | inSampleSize *= 2;
80 | }
81 | }
82 |
83 | return inSampleSize;
84 | }
85 |
86 | //保存Bitmap到本地
87 | public static String saveBitmap(Bitmap bm, String filePath) {
88 | File f = new File(filePath);
89 | if (f.exists()) {
90 | f.delete();
91 | }
92 | try {
93 | FileOutputStream out = new FileOutputStream(f);
94 | bm.compress(Bitmap.CompressFormat.PNG, 90, out);
95 | out.flush();
96 | out.close();
97 | return f.getPath();
98 | } catch (FileNotFoundException e) {
99 | e.printStackTrace();
100 | } catch (IOException e) {
101 | e.printStackTrace();
102 | }
103 | // System.out.println("保存文件--->" + f.getAbsolutePath());
104 | return filePath;
105 | }
106 |
107 | public static Bitmap getThumbnailByPath(String path, int size, Context context) throws IOException {
108 | Uri userPickedUri = Uri.fromFile(new File(path));
109 | return getThumbnailByUri(userPickedUri,size,context);
110 | }
111 |
112 | //得到本地图片对应的缩图
113 | public static Bitmap getThumbnailByUri(Uri uri, int size, Context context) throws IOException {
114 | InputStream input = context.getContentResolver().openInputStream(uri);
115 | //配置BitmapFactory.Options,inJustDecodeBounds设为true,以获取图片的宽高
116 | BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
117 | onlyBoundsOptions.inJustDecodeBounds = true;
118 | onlyBoundsOptions.inDither=true;//optional
119 | onlyBoundsOptions.inPreferredConfig=Bitmap.Config.ARGB_8888;//optional
120 |
121 | //计算inSampleSize缩放比例
122 | BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
123 | input.close();
124 | if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
125 | return null;
126 | int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth;
127 | double ratio = (originalSize > size) ? (originalSize / size) : 1.0;
128 | //获取到缩放比例后,再次设置BitmapFactory.Options,获取图片缩略图
129 | BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
130 | bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio);
131 | bitmapOptions.inDither=true;//optional
132 | bitmapOptions.inPreferredConfig=Bitmap.Config.ARGB_8888;//optional
133 | input = context.getContentResolver().openInputStream(uri);
134 | Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
135 | input.close();
136 | return bitmap;
137 | }
138 |
139 | /**
140 | * 将double的比例采用近似值的方式转为int
141 | * @param ratio
142 | * @return
143 | */
144 | private static int getPowerOfTwoForSampleRatio(double ratio){
145 | int k = Integer.highestOneBit((int)Math.floor(ratio));
146 | if(k==0) return 1;
147 | else return k;
148 | }
149 |
150 | }
151 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/ContentProviderUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.provider.MediaStore;
6 |
7 | import com.ellen.basequickandroid.util.collectionutil.ArrangeInterface;
8 |
9 | import java.io.File;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * 内容提供者工具类
15 | * 1.获取本地所有的图片
16 | * 2.获取本地所有的视频
17 | * 3.获取本地所有的音频
18 | *
19 | * 使用之前请申请文件读写权限
20 | */
21 | public class ContentProviderUtils {
22 |
23 | //通过内容提供者获取本地所有图片的地址集合
24 | public static List getIamgePathList(Context context) {
25 | Cursor cur = context.getContentResolver()
26 | .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
27 | new String[]{MediaStore.Images.Media.DATA},
28 | "",
29 | new String[]{},
30 | MediaStore.Images.Media.DATE_MODIFIED + " DESC");
31 | List imagePathList = new ArrayList<>(cur.getCount());
32 | if (cur.moveToFirst()) {
33 | while (!cur.isAfterLast()) {
34 | //过滤掉空的图片
35 | if (new File(cur.getString(0)).exists()) {
36 | imagePathList.add(cur.getString(0));
37 | }
38 | cur.moveToNext();
39 | }
40 | }
41 | cur.close();
42 | return imagePathList;
43 | }
44 |
45 | //通过内容提供者获取本地所有的图片地址集合
46 | public static List getVideoPathList(Context context) {
47 | String[] projection = new String[]{
48 | MediaStore.Video.Media.DATA,
49 | MediaStore.Video.Media.DURATION
50 | };
51 | Cursor cursor = context.getContentResolver().query(
52 | MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null,
53 | null, null);
54 | List videoPathList = new ArrayList<>(cursor.getCount());
55 | while (cursor.moveToNext()) {
56 | String path = cursor
57 | .getString(cursor
58 | .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
59 | long duration = cursor
60 | .getInt(cursor
61 | .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
62 | if (duration > 0) {
63 | //过滤掉时长为0的视频
64 | videoPathList.add(path);
65 | }
66 | }
67 | cursor.close();
68 | return videoPathList;
69 | }
70 |
71 | public static List getMusicPathList(Context context) {
72 | List musicList = new ArrayList<>();
73 | Cursor c = null;
74 | c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null,
75 | MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
76 |
77 | while (c.moveToNext()) {
78 | String path = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));// 路径
79 | String name = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)); // 歌曲名
80 | String album = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); // 专辑
81 | String artist = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); // 作者
82 | long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));// 大小
83 | int duration = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));// 时长
84 | int musicId = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));// 歌曲的id
85 | int albumId = c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
86 | if (duration != 0) {
87 | Music music = new Music();
88 | music.setPath(path);
89 | music.setName(name);
90 | music.setAlbum(album);
91 | music.setArtist(artist);
92 | music.setSize(size);
93 | music.setDuration(duration);
94 | music.setMusicId(musicId);
95 | music.setAlbumId(albumId);
96 | musicList.add(music);
97 | }
98 | }
99 | return musicList;
100 | }
101 |
102 |
103 | public static class Music implements ArrangeInterface {
104 |
105 | private String name;
106 | private String path;
107 | private String album;
108 | private long size;
109 | private int musicId;
110 | private String artist;
111 |
112 | public String getArtist() {
113 | return artist;
114 | }
115 |
116 | public void setArtist(String artist) {
117 | this.artist = artist;
118 | }
119 |
120 | public long getDuration() {
121 | return duration;
122 | }
123 |
124 | public void setDuration(long duration) {
125 | this.duration = duration;
126 | }
127 |
128 | private long duration;
129 |
130 | public String getAlbum() {
131 | return album;
132 | }
133 |
134 | public void setAlbum(String album) {
135 | this.album = album;
136 | }
137 |
138 | public long getSize() {
139 | return size;
140 | }
141 |
142 | public void setSize(long size) {
143 | this.size = size;
144 | }
145 |
146 | public int getMusicId() {
147 | return musicId;
148 | }
149 |
150 | public void setMusicId(int musicId) {
151 | this.musicId = musicId;
152 | }
153 |
154 | public int getAlbumId() {
155 | return albumId;
156 | }
157 |
158 | public void setAlbumId(int albumId) {
159 | this.albumId = albumId;
160 | }
161 |
162 | private int albumId;
163 |
164 | public String getPath() {
165 | return path;
166 | }
167 |
168 | public void setPath(String path) {
169 | this.path = path;
170 | }
171 |
172 | public String getName() {
173 | return name;
174 | }
175 |
176 | public void setName(String name) {
177 | this.name = name;
178 | }
179 |
180 | @Override
181 | public boolean identical(Music music) {
182 | return this.getArtist().equals(music.getArtist());
183 | }
184 | }
185 |
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/ImageChooseUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 | import android.os.Build;
8 | import android.provider.MediaStore;
9 | import android.support.annotation.Nullable;
10 | import android.support.v4.content.FileProvider;
11 |
12 | import java.io.File;
13 | import java.lang.ref.WeakReference;
14 |
15 | /**
16 | *
17 | * 提示,在使用之前一定要获取文件读写权限。
18 | *
19 | * 手机图片选择工具类
20 | * 1.选择相册图片
21 | * 2.选择使用相机进行拍摄(适配Android N)
22 | *
23 | * 使用前请配置:
24 | * 【1】在AndroidManifest.xml中配置
25 | *
30 | *
33 | *
34 | *
35 | * 【2】在res下新建一个xml文件夹,并且配置一个file_paths.xml文件
36 | *
37 | *
38 | *
39 | *
40 | *
41 | */
42 | public class ImageChooseUtils {
43 |
44 | private WeakReference activityWeakReference;
45 | private WeakReference contextWeakReference;
46 | private ChooseImageCallback chooseImageCallback;
47 | private int requestCode;
48 | private String chooseImagePath;
49 | private boolean isChooseSystemAlbum = false;
50 |
51 | public ImageChooseUtils(Context context,Activity activity,ChooseImageCallback chooseImageCallback){
52 | activityWeakReference = new WeakReference<>(activity);
53 | contextWeakReference = new WeakReference<>(context);
54 | this.chooseImageCallback = chooseImageCallback;
55 | }
56 |
57 | //调用系统相机
58 | public void toCameraActivity(String imageName,String authority,int requestCode) {
59 | this.requestCode = requestCode;
60 | Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
61 | File file = new File(contextWeakReference.get().getExternalCacheDir(), imageName + ".png");
62 | chooseImagePath = file.getAbsolutePath();
63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
64 | openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
65 | FileProvider.getUriForFile(contextWeakReference.get(), authority, file));
66 | } else {
67 | openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
68 | }
69 | activityWeakReference.get().startActivityForResult(openCameraIntent, requestCode);
70 | }
71 |
72 | //调用系统相册
73 | public void toSystemAlbum(int requestCode){
74 | this.requestCode = requestCode;
75 | isChooseSystemAlbum = true;
76 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
77 | photoPickerIntent.setType("image/*");
78 | activityWeakReference.get().startActivityForResult(photoPickerIntent, requestCode);
79 | }
80 |
81 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
82 | if(this.requestCode == requestCode){
83 | if(resultCode == Activity.RESULT_OK){
84 | if(isChooseSystemAlbum){
85 | //这里是选择了系统相册的逻辑
86 | Uri uri = data.getData();
87 | chooseImagePath = UriUtils.getRealFilePath(contextWeakReference.get(),uri);
88 | chooseImageCallback.successs(chooseImagePath);
89 | }else {
90 | //这里是选择了相机的逻辑
91 | chooseImageCallback.successs(chooseImagePath);
92 | }
93 | }else {
94 | chooseImageCallback.failure();
95 | }
96 | }
97 | }
98 |
99 | public interface ChooseImageCallback{
100 | void successs(String path);
101 | void failure();
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/PermissionUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.pm.PackageManager;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 | import android.support.v4.app.ActivityCompat;
10 |
11 | import java.lang.ref.WeakReference;
12 | import java.util.ArrayList;
13 | import java.util.Arrays;
14 | import java.util.List;
15 |
16 | //权限申请工具类
17 | public class PermissionUtils {
18 |
19 | private int requestCode;
20 | private List permissionList;
21 | private WeakReference weakReferenceActivity;
22 | private WeakReference weakReferenceContext;
23 | private PermissionCallback permissionCallback;
24 |
25 | public PermissionUtils(Activity activity, Context context){
26 | weakReferenceActivity = new WeakReference<>(activity);
27 | weakReferenceContext = new WeakReference<>(context);
28 | }
29 |
30 | /**
31 | *
32 | * @param permissionString
33 | * @return false:具有该权限
34 | */
35 | private boolean checkPermission(String permissionString){
36 | boolean falg = false;
37 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
38 | if (ActivityCompat.checkSelfPermission(weakReferenceContext.get(), permissionString) != PackageManager.PERMISSION_GRANTED) {
39 | falg = true;
40 | }
41 | }else {
42 | falg = false;
43 | }
44 | return falg;
45 | }
46 |
47 | public void checkPermissions(String[] permissionArray,int requestCode,PermissionCallback permissionCallback){
48 | this.permissionList = Arrays.asList(permissionArray);
49 | this.requestCode = requestCode;
50 | this.permissionCallback = permissionCallback;
51 | boolean falg = false;
52 | for(String permissionString:permissionList){
53 | falg = checkPermission(permissionString);
54 | if(falg){
55 | break;
56 | }
57 | }
58 |
59 | //申请权限
60 | if(falg) {
61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
62 | weakReferenceActivity.get().requestPermissions(permissionArray,requestCode);
63 | }
64 | }else {
65 | this.permissionCallback.success();
66 | }
67 | }
68 |
69 | public void checkPermissions(List permissionList,int requestCode,PermissionCallback permissionCallback){
70 | this.permissionList = permissionList;
71 | this.requestCode = requestCode;
72 | this.permissionCallback = permissionCallback;
73 | boolean falg = false;
74 | for(String permissionString:permissionList){
75 | falg = checkPermission(permissionString);
76 | if(falg){
77 | break;
78 | }
79 | }
80 |
81 | //申请权限
82 | if(falg) {
83 | String[] permissionArray = new String[permissionList.size()];
84 | permissionList.toArray(permissionArray);
85 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
86 | weakReferenceActivity.get().requestPermissions(permissionArray,requestCode);
87 | }
88 | }else {
89 | this.permissionCallback.success();
90 | }
91 | }
92 |
93 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
94 | if(this.requestCode == requestCode){
95 | int sum = 0;
96 | for (int i = 0; i < permissions.length; i++) {
97 | if(grantResults[i] == 0){
98 | sum++;
99 | }
100 | }
101 | if(sum == this.permissionList.size()){
102 | //成功
103 | permissionCallback.success();
104 | }else {
105 | //失败
106 | permissionCallback.failure();
107 | }
108 | }
109 | }
110 |
111 | //检测文件读写权限
112 | public void startCheckFileReadWritePermission(int requestCode,PermissionCallback permissionCallback){
113 | List permissionList = new ArrayList<>();
114 | permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
115 | permissionList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
116 | checkPermissions(permissionList,requestCode,permissionCallback);
117 | }
118 |
119 |
120 | public interface PermissionCallback{
121 | void success();
122 | void failure();
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | public class ToastUtils {
7 |
8 | public static void toast(Context context,String contetnt){
9 | Toast.makeText(context,contetnt,Toast.LENGTH_SHORT).show();
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/UriUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.content.ContentResolver;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.net.Uri;
7 | import android.provider.MediaStore;
8 |
9 | public class UriUtils {
10 |
11 | public static String getRealFilePath(final Context context, final Uri uri ) {
12 | if ( null == uri ) return null;
13 | final String scheme = uri.getScheme();
14 | String data = null;
15 | if ( scheme == null )
16 | data = uri.getPath();
17 | else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
18 | data = uri.getPath();
19 | } else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
20 | Cursor cursor = context.getContentResolver().query( uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null );
21 | if ( null != cursor ) {
22 | if ( cursor.moveToFirst() ) {
23 | int index = cursor.getColumnIndex( MediaStore.Images.ImageColumns.DATA );
24 | if ( index > -1 ) {
25 | data = cursor.getString( index );
26 | }
27 | }
28 | cursor.close();
29 | }
30 | }
31 | return data;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/WebViewSetttingUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util;
2 |
3 | import android.webkit.WebView;
4 |
5 | public class WebViewSetttingUtils {
6 |
7 | public static void loadUrl(WebView webView,String url){
8 | //通过WebView的WebSetting类设置能够执行JavaScript的脚本
9 | webView.getSettings().setJavaScriptEnabled(true);
10 | webView.loadUrl(url);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/collectionutil/ArrangeInterface.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.collectionutil;
2 |
3 | public interface ArrangeInterface {
4 | boolean identical(T t);
5 | }
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/collectionutil/CollectionUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.collectionutil;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class CollectionUtils {
7 |
8 | //对某个集合进行排序
9 | public static List sort(List eList) {
10 | List copyList = new ArrayList<>();
11 | for(E e:eList){
12 | copyList.add(e);
13 | }
14 | E e = eList.get(0);
15 | if (!(e instanceof CompareableInterface)) {
16 | //抛出异常 -> 说明它没有实现比较器接口
17 | throw new CompareableException("", "your class Not Implemented CompareableInterface");
18 | }
19 | //使用冒泡排序进行排序
20 | for (int i = 0; i < copyList.size(); i++) {
21 | for (int j = i + 1; j < copyList.size(); j++) {
22 | CompareableInterface iCompareable = (CompareableInterface) copyList.get(i);
23 | if (iCompareable.compareTo(copyList.get(j)) >= 0) {
24 | E e1 = copyList.get(i);
25 | copyList.set(i, copyList.get(j));
26 | copyList.set(j, e1);
27 | }
28 | }
29 | }
30 | return copyList;
31 | }
32 |
33 | //对某个集合进行整理算法
34 | public static List> arrange(List eList){
35 | E e = eList.get(0);
36 | if (!(e instanceof ArrangeInterface)) {
37 | //抛出异常 -> 说明它没有实现归类整理器接口
38 | throw new CompareableException("", "your class Not Implemented ArrangeInterface");
39 | }
40 | if(eList == null || eList.size() == 0){
41 | //执行这里说明无法进行整理归类
42 | return null;
43 | }
44 | List copyList = new ArrayList<>();
45 | List> listList = new ArrayList<>();
46 | for(E e1:eList){
47 | copyList.add(e1);
48 | }
49 | for(int i = 0;i < eList.size();i++){
50 | boolean isAddList = true;
51 | for(List list:listList){
52 | E eCompare = list.get(0);
53 | ArrangeInterface arrangeInterface = (ArrangeInterface) eList.get(i);
54 | boolean falg = arrangeInterface.identical(eCompare);
55 | if(falg){
56 | //是相同的
57 | list.add(eList.get(i));
58 | isAddList = false;
59 | break;
60 | }
61 | }
62 | if(isAddList){
63 | List eList1 = new ArrayList<>();
64 | eList1.add(eList.get(i));
65 | listList.add(eList1);
66 | }
67 | }
68 | return listList;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/collectionutil/CompareableException.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.collectionutil;
2 |
3 | public class CompareableException extends RuntimeException{
4 |
5 | private String errorCode;
6 | private String errorMessage;
7 |
8 | public CompareableException(String errorCode,String errorMessage){
9 | this.errorCode = errorCode;
10 | this.errorMessage = errorMessage;
11 | }
12 |
13 | @Override
14 | public String getMessage() {
15 | return errorCode+""+errorMessage;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/collectionutil/CompareableInterface.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.collectionutil;
2 |
3 | //用于比较器
4 | public interface CompareableInterface {
5 | //比较二者的大小 0 相同,正值代表外面大于里面,负值代表里面大于外面
6 | int compareTo(T t);
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/statusutil/OSUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.statusutil;
2 |
3 | import android.os.Build;
4 | import android.text.TextUtils;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 |
10 | public class OSUtils {
11 |
12 | public static final String ROM_MIUI = "MIUI";
13 | public static final String ROM_EMUI = "EMUI";
14 | public static final String ROM_FLYME = "FLYME";
15 | public static final String ROM_OPPO = "OPPO";
16 | public static final String ROM_SMARTISAN = "SMARTISAN";
17 | public static final String ROM_VIVO = "VIVO";
18 | public static final String ROM_QIKU = "QIKU";
19 |
20 | private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name";
21 | private static final String KEY_VERSION_EMUI = "ro.build.version.emui";
22 | private static final String KEY_VERSION_OPPO = "ro.build.version.opporom";
23 | private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version";
24 | private static final String KEY_VERSION_VIVO = "ro.vivo.os.version";
25 |
26 | private static String sName;
27 | private static String sVersion;
28 |
29 | public static boolean isEmui() {
30 | return check(ROM_EMUI);
31 | }
32 |
33 | public static boolean isMiui() {
34 | return check(ROM_MIUI);
35 | }
36 |
37 | public static boolean isVivo() {
38 | return check(ROM_VIVO);
39 | }
40 |
41 | public static boolean isOppo() {
42 | return check(ROM_OPPO);
43 | }
44 |
45 | public static boolean isFlyme() {
46 | return check(ROM_FLYME);
47 | }
48 |
49 | public static boolean is360() {
50 | return check(ROM_QIKU) || check("360");
51 | }
52 |
53 | public static boolean isSmartisan() {
54 | return check(ROM_SMARTISAN);
55 | }
56 |
57 | public static String getName() {
58 | if (sName == null) {
59 | check("");
60 | }
61 | return sName;
62 | }
63 |
64 | public static String getVersion() {
65 | if (sVersion == null) {
66 | check("");
67 | }
68 | return sVersion;
69 | }
70 |
71 | public static boolean check(String rom) {
72 | if (sName != null) {
73 | return sName.equals(rom);
74 | }
75 |
76 | if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) {
77 | sName = ROM_MIUI;
78 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) {
79 | sName = ROM_EMUI;
80 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) {
81 | sName = ROM_OPPO;
82 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) {
83 | sName = ROM_VIVO;
84 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) {
85 | sName = ROM_SMARTISAN;
86 | } else {
87 | sVersion = Build.DISPLAY;
88 | if (sVersion.toUpperCase().contains(ROM_FLYME)) {
89 | sName = ROM_FLYME;
90 | } else {
91 | sVersion = Build.UNKNOWN;
92 | sName = Build.MANUFACTURER.toUpperCase();
93 | }
94 | }
95 | return sName.equals(rom);
96 | }
97 |
98 | public static String getProp(String name) {
99 | String line = null;
100 | BufferedReader input = null;
101 | try {
102 | Process p = Runtime.getRuntime().exec("getprop " + name);
103 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
104 | line = input.readLine();
105 | input.close();
106 | } catch (IOException ex) {
107 | return null;
108 | } finally {
109 | if (input != null) {
110 | try {
111 | input.close();
112 | } catch (IOException e) {
113 | e.printStackTrace();
114 | }
115 | }
116 | }
117 | return line;
118 | }
119 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/statusutil/StatusUtils.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.statusutil;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.annotation.TargetApi;
5 | import android.app.Activity;
6 | import android.content.Context;
7 | import android.graphics.Color;
8 | import android.os.Build;
9 | import android.support.annotation.IntDef;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.Window;
13 | import android.view.WindowManager;
14 |
15 | import java.lang.annotation.Retention;
16 | import java.lang.annotation.RetentionPolicy;
17 | import java.lang.reflect.Field;
18 | import java.lang.reflect.Method;
19 |
20 | /**
21 | * 负责修改状态栏的工具类
22 | */
23 | public class StatusUtils {
24 | public final static int TYPE_MIUI = 0;
25 | public final static int TYPE_FLYME = 1;
26 | public final static int TYPE_M = 3;//6.0
27 |
28 | @IntDef({TYPE_MIUI,
29 | TYPE_FLYME,
30 | TYPE_M})
31 | @Retention(RetentionPolicy.SOURCE)
32 | @interface ViewType {
33 | }
34 |
35 | //设置全屏
36 | public static void setFullScreen(Activity activity){
37 | activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
38 | activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
39 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
40 | }
41 |
42 | /**
43 | * 修改状态栏颜色,支持4.4以上版本
44 | *
45 | * @param colorId 颜色
46 | */
47 | public static void setStatusBarColor(Activity activity, int colorId) {
48 |
49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
50 | Window window = activity.getWindow();
51 | window.setStatusBarColor(colorId);
52 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
53 | //使用SystemBarTintManager,需要先将状态栏设置为透明
54 | setTranslucentStatus(activity);
55 | SystemBarTintManager systemBarTintManager = new SystemBarTintManager(activity);
56 | systemBarTintManager.setStatusBarTintEnabled(true);//显示状态栏
57 | systemBarTintManager.setStatusBarTintColor(colorId);//设置状态栏颜色
58 | }
59 | }
60 |
61 | /**
62 | * 设置状态栏透明
63 | */
64 | @TargetApi(19)
65 | public static void setTranslucentStatus(Activity activity) {
66 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
67 | //5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
68 | Window window = activity.getWindow();
69 | View decorView = window.getDecorView();
70 | //两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
71 | int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
72 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
73 | decorView.setSystemUiVisibility(option);
74 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
75 | window.setStatusBarColor(Color.TRANSPARENT);
76 | //导航栏颜色也可以正常设置
77 | //window.setNavigationBarColor(Color.TRANSPARENT);
78 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
79 | Window window = activity.getWindow();
80 | WindowManager.LayoutParams attributes = window.getAttributes();
81 | int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
82 | attributes.flags |= flagTranslucentStatus;
83 | //int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
84 | //attributes.flags |= flagTranslucentNavigation;
85 | window.setAttributes(attributes);
86 | }
87 | }
88 |
89 |
90 | /**
91 | * 代码实现android:fitsSystemWindows
92 | *
93 | * @param activity
94 | */
95 | public static void setRootViewFitsSystemWindows(Activity activity, boolean fitSystemWindows) {
96 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
97 | ViewGroup winContent = (ViewGroup) activity.findViewById(android.R.id.content);
98 | if (winContent.getChildCount() > 0) {
99 | ViewGroup rootView = (ViewGroup) winContent.getChildAt(0);
100 | if (rootView != null) {
101 | rootView.setFitsSystemWindows(fitSystemWindows);
102 | }
103 | }
104 | }
105 |
106 | }
107 |
108 |
109 | /**
110 | * 设置状态栏深色浅色切换
111 | */
112 | public static boolean setStatusBarDarkTheme(Activity activity, boolean dark) {
113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
114 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
115 | setStatusBarFontIconDark(activity, TYPE_M, dark);
116 | } else if (OSUtils.isMiui()) {
117 | setStatusBarFontIconDark(activity, TYPE_MIUI, dark);
118 | } else if (OSUtils.isFlyme()) {
119 | setStatusBarFontIconDark(activity, TYPE_FLYME, dark);
120 | } else {//其他情况
121 | return false;
122 | }
123 |
124 | return true;
125 | }
126 | return false;
127 | }
128 |
129 | /**
130 | * 设置 状态栏深色浅色切换
131 | */
132 | public static boolean setStatusBarFontIconDark(Activity activity, @ViewType int type, boolean dark) {
133 | switch (type) {
134 | case TYPE_MIUI:
135 | return setMiuiUI(activity, dark);
136 | case TYPE_FLYME:
137 | return setFlymeUI(activity, dark);
138 | case TYPE_M:
139 | default:
140 | return setCommonUI(activity,dark);
141 | }
142 | }
143 |
144 | //设置6.0 状态栏深色浅色切换
145 | public static boolean setCommonUI(Activity activity, boolean dark) {
146 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
147 | View decorView = activity.getWindow().getDecorView();
148 | if (decorView != null) {
149 | int vis = decorView.getSystemUiVisibility();
150 | if (dark) {
151 | vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
152 | } else {
153 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
154 | }
155 | if (decorView.getSystemUiVisibility() != vis) {
156 | decorView.setSystemUiVisibility(vis);
157 | }
158 | return true;
159 | }
160 | }
161 | return false;
162 |
163 | }
164 |
165 | //设置Flyme 状态栏深色浅色切换
166 | public static boolean setFlymeUI(Activity activity, boolean dark) {
167 | try {
168 | Window window = activity.getWindow();
169 | WindowManager.LayoutParams lp = window.getAttributes();
170 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
171 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
172 | darkFlag.setAccessible(true);
173 | meizuFlags.setAccessible(true);
174 | int bit = darkFlag.getInt(null);
175 | int value = meizuFlags.getInt(lp);
176 | if (dark) {
177 | value |= bit;
178 | } else {
179 | value &= ~bit;
180 | }
181 | meizuFlags.setInt(lp, value);
182 | window.setAttributes(lp);
183 | return true;
184 | } catch (Exception e) {
185 | e.printStackTrace();
186 | return false;
187 | }
188 | }
189 |
190 | //设置MIUI 状态栏深色浅色切换
191 | public static boolean setMiuiUI(Activity activity, boolean dark) {
192 | try {
193 | Window window = activity.getWindow();
194 | Class> clazz = activity.getWindow().getClass();
195 | @SuppressLint("PrivateApi") Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
196 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
197 | int darkModeFlag = field.getInt(layoutParams);
198 | Method extraFlagField = clazz.getDeclaredMethod("setExtraFlags", int.class, int.class);
199 | extraFlagField.setAccessible(true);
200 | if (dark) { //状态栏亮色且黑色字体
201 | extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
202 | } else {
203 | extraFlagField.invoke(window, 0, darkModeFlag);
204 | }
205 | return true;
206 | } catch (Exception e) {
207 | e.printStackTrace();
208 | return false;
209 | }
210 | }
211 | //获取状态栏高度
212 | public static int getStatusBarHeight(Context context) {
213 | int result = 0;
214 | int resourceId = context.getResources().getIdentifier(
215 | "status_bar_height", "dimen", "android");
216 | if (resourceId > 0) {
217 | result = context.getResources().getDimensionPixelSize(resourceId);
218 | }
219 | return result;
220 | }
221 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/basequickandroid/util/statusutil/SystemBarTintManager.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid.util.statusutil;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.annotation.TargetApi;
5 | import android.app.Activity;
6 | import android.content.Context;
7 | import android.content.res.Configuration;
8 | import android.content.res.Resources;
9 | import android.content.res.TypedArray;
10 | import android.graphics.drawable.Drawable;
11 | import android.os.Build;
12 | import android.util.DisplayMetrics;
13 | import android.util.TypedValue;
14 | import android.view.Gravity;
15 | import android.view.View;
16 | import android.view.ViewConfiguration;
17 | import android.view.ViewGroup;
18 | import android.view.Window;
19 | import android.view.WindowManager;
20 | import android.widget.FrameLayout.LayoutParams;
21 |
22 | import java.lang.reflect.Method;
23 |
24 | /**
25 | * Class to manage status and navigation bar tint effects when using KitKat
26 | * translucent system UI modes.
27 | *
28 | */
29 | public class SystemBarTintManager {
30 |
31 | static {
32 | // Android allows a system property to override the presence of the navigation bar.
33 | // Used by the emulator.
34 | // See https://github.com/android/platform_frameworks_base/blob/master/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#L1076
35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
36 | try {
37 | Class c = Class.forName("android.os.SystemProperties");
38 | Method m = c.getDeclaredMethod("get", String.class);
39 | m.setAccessible(true);
40 | sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
41 | } catch (Throwable e) {
42 | sNavBarOverride = null;
43 | }
44 | }
45 | }
46 |
47 |
48 | /**
49 | * The default system bar tint color value.
50 | */
51 | public static final int DEFAULT_TINT_COLOR = 0x99000000;
52 |
53 | private static String sNavBarOverride;
54 |
55 | private final SystemBarConfig mConfig;
56 | private boolean mStatusBarAvailable;
57 | private boolean mNavBarAvailable;
58 | private boolean mStatusBarTintEnabled;
59 | private boolean mNavBarTintEnabled;
60 | private View mStatusBarTintView;
61 | private View mNavBarTintView;
62 |
63 | /**
64 | * Constructor. Call this in the host activity onCreate method after its
65 | * content view has been set. You should always create new instances when
66 | * the host activity is recreated.
67 | *
68 | * @param activity The host activity.
69 | */
70 | @SuppressLint("ResourceType")
71 | @TargetApi(19)
72 | public SystemBarTintManager(Activity activity) {
73 |
74 | Window win = activity.getWindow();
75 | ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();
76 |
77 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
78 | // check theme attrs
79 | int[] attrs = {android.R.attr.windowTranslucentStatus,
80 | android.R.attr.windowTranslucentNavigation};
81 | TypedArray a = activity.obtainStyledAttributes(attrs);
82 | try {
83 | mStatusBarAvailable = a.getBoolean(0, false);
84 | mNavBarAvailable = a.getBoolean(1, false);
85 | } finally {
86 | a.recycle();
87 | }
88 |
89 | // check window flags
90 | WindowManager.LayoutParams winParams = win.getAttributes();
91 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
92 | if ((winParams.flags & bits) != 0) {
93 | mStatusBarAvailable = true;
94 | }
95 | bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
96 | if ((winParams.flags & bits) != 0) {
97 | mNavBarAvailable = true;
98 | }
99 | }
100 |
101 | mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
102 | // device might not have virtual navigation keys
103 | if (!mConfig.hasNavigtionBar()) {
104 | mNavBarAvailable = false;
105 | }
106 |
107 | if (mStatusBarAvailable) {
108 | setupStatusBarView(activity, decorViewGroup);
109 | }
110 | if (mNavBarAvailable) {
111 | setupNavBarView(activity, decorViewGroup);
112 | }
113 |
114 | }
115 |
116 | /**
117 | * Enable tinting of the system status bar.
118 | *
119 | * If the platform is running Jelly Bean or earlier, or translucent system
120 | * UI modes have not been enabled in either the theme or via window flags,
121 | * then this method does nothing.
122 | *
123 | * @param enabled True to enable tinting, false to disable it (default).
124 | */
125 | public void setStatusBarTintEnabled(boolean enabled) {
126 | mStatusBarTintEnabled = enabled;
127 | if (mStatusBarAvailable) {
128 | mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
129 | }
130 | }
131 |
132 | /**
133 | * Enable tinting of the system navigation bar.
134 | *
135 | * If the platform does not have soft navigation keys, is running Jelly Bean
136 | * or earlier, or translucent system UI modes have not been enabled in either
137 | * the theme or via window flags, then this method does nothing.
138 | *
139 | * @param enabled True to enable tinting, false to disable it (default).
140 | */
141 | public void setNavigationBarTintEnabled(boolean enabled) {
142 | mNavBarTintEnabled = enabled;
143 | if (mNavBarAvailable) {
144 | mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
145 | }
146 | }
147 |
148 | /**
149 | * Apply the specified color tint to all system UI bars.
150 | *
151 | * @param color The color of the background tint.
152 | */
153 | public void setTintColor(int color) {
154 | setStatusBarTintColor(color);
155 | setNavigationBarTintColor(color);
156 | }
157 |
158 | /**
159 | * Apply the specified drawable or color resource to all system UI bars.
160 | *
161 | * @param res The identifier of the resource.
162 | */
163 | public void setTintResource(int res) {
164 | setStatusBarTintResource(res);
165 | setNavigationBarTintResource(res);
166 | }
167 |
168 | /**
169 | * Apply the specified drawable to all system UI bars.
170 | *
171 | * @param drawable The drawable to use as the background, or null to remove it.
172 | */
173 | public void setTintDrawable(Drawable drawable) {
174 | setStatusBarTintDrawable(drawable);
175 | setNavigationBarTintDrawable(drawable);
176 | }
177 |
178 | /**
179 | * Apply the specified alpha to all system UI bars.
180 | *
181 | * @param alpha The alpha to use
182 | */
183 | public void setTintAlpha(float alpha) {
184 | setStatusBarAlpha(alpha);
185 | setNavigationBarAlpha(alpha);
186 | }
187 |
188 | /**
189 | * Apply the specified color tint to the system status bar.
190 | *
191 | * @param color The color of the background tint.
192 | */
193 | public void setStatusBarTintColor(int color) {
194 | if (mStatusBarAvailable) {
195 | mStatusBarTintView.setBackgroundColor(color);
196 | }
197 | }
198 |
199 | /**
200 | * Apply the specified drawable or color resource to the system status bar.
201 | *
202 | * @param res The identifier of the resource.
203 | */
204 | public void setStatusBarTintResource(int res) {
205 | if (mStatusBarAvailable) {
206 | mStatusBarTintView.setBackgroundResource(res);
207 | }
208 | }
209 |
210 | /**
211 | * Apply the specified drawable to the system status bar.
212 | *
213 | * @param drawable The drawable to use as the background, or null to remove it.
214 | */
215 | @SuppressWarnings("deprecation")
216 | public void setStatusBarTintDrawable(Drawable drawable) {
217 | if (mStatusBarAvailable) {
218 | mStatusBarTintView.setBackgroundDrawable(drawable);
219 | }
220 | }
221 |
222 | /**
223 | * Apply the specified alpha to the system status bar.
224 | *
225 | * @param alpha The alpha to use
226 | */
227 | @TargetApi(11)
228 | public void setStatusBarAlpha(float alpha) {
229 | if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
230 | mStatusBarTintView.setAlpha(alpha);
231 | }
232 | }
233 |
234 | /**
235 | * Apply the specified color tint to the system navigation bar.
236 | *
237 | * @param color The color of the background tint.
238 | */
239 | public void setNavigationBarTintColor(int color) {
240 | if (mNavBarAvailable) {
241 | mNavBarTintView.setBackgroundColor(color);
242 | }
243 | }
244 |
245 | /**
246 | * Apply the specified drawable or color resource to the system navigation bar.
247 | *
248 | * @param res The identifier of the resource.
249 | */
250 | public void setNavigationBarTintResource(int res) {
251 | if (mNavBarAvailable) {
252 | mNavBarTintView.setBackgroundResource(res);
253 | }
254 | }
255 |
256 | /**
257 | * Apply the specified drawable to the system navigation bar.
258 | *
259 | * @param drawable The drawable to use as the background, or null to remove it.
260 | */
261 | @SuppressWarnings("deprecation")
262 | public void setNavigationBarTintDrawable(Drawable drawable) {
263 | if (mNavBarAvailable) {
264 | mNavBarTintView.setBackgroundDrawable(drawable);
265 | }
266 | }
267 |
268 | /**
269 | * Apply the specified alpha to the system navigation bar.
270 | *
271 | * @param alpha The alpha to use
272 | */
273 | @TargetApi(11)
274 | public void setNavigationBarAlpha(float alpha) {
275 | if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
276 | mNavBarTintView.setAlpha(alpha);
277 | }
278 | }
279 |
280 | /**
281 | * Get the system bar configuration.
282 | *
283 | * @return The system bar configuration for the current device configuration.
284 | */
285 | public SystemBarConfig getConfig() {
286 | return mConfig;
287 | }
288 |
289 | /**
290 | * Is tinting enabled for the system status bar?
291 | *
292 | * @return True if enabled, False otherwise.
293 | */
294 | public boolean isStatusBarTintEnabled() {
295 | return mStatusBarTintEnabled;
296 | }
297 |
298 | /**
299 | * Is tinting enabled for the system navigation bar?
300 | *
301 | * @return True if enabled, False otherwise.
302 | */
303 | public boolean isNavBarTintEnabled() {
304 | return mNavBarTintEnabled;
305 | }
306 |
307 | private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
308 | mStatusBarTintView = new View(context);
309 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
310 | params.gravity = Gravity.TOP;
311 | if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
312 | params.rightMargin = mConfig.getNavigationBarWidth();
313 | }
314 | mStatusBarTintView.setLayoutParams(params);
315 | mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
316 | mStatusBarTintView.setVisibility(View.GONE);
317 | decorViewGroup.addView(mStatusBarTintView);
318 | }
319 |
320 | private void setupNavBarView(Context context, ViewGroup decorViewGroup) {
321 | mNavBarTintView = new View(context);
322 | LayoutParams params;
323 | if (mConfig.isNavigationAtBottom()) {
324 | params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());
325 | params.gravity = Gravity.BOTTOM;
326 | } else {
327 | params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);
328 | params.gravity = Gravity.RIGHT;
329 | }
330 | mNavBarTintView.setLayoutParams(params);
331 | mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
332 | mNavBarTintView.setVisibility(View.GONE);
333 | decorViewGroup.addView(mNavBarTintView);
334 | }
335 |
336 | /**
337 | * Class which describes system bar sizing and other characteristics for the current
338 | * device configuration.
339 | *
340 | */
341 | public static class SystemBarConfig {
342 |
343 | private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";
344 | private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height";
345 | private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape";
346 | private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width";
347 | private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
348 |
349 | private final boolean mTranslucentStatusBar;
350 | private final boolean mTranslucentNavBar;
351 | private final int mStatusBarHeight;
352 | private final int mActionBarHeight;
353 | private final boolean mHasNavigationBar;
354 | private final int mNavigationBarHeight;
355 | private final int mNavigationBarWidth;
356 | private final boolean mInPortrait;
357 | private final float mSmallestWidthDp;
358 |
359 | private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) {
360 | Resources res = activity.getResources();
361 | mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
362 | mSmallestWidthDp = getSmallestWidthDp(activity);
363 | mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME);
364 | mActionBarHeight = getActionBarHeight(activity);
365 | mNavigationBarHeight = getNavigationBarHeight(activity);
366 | mNavigationBarWidth = getNavigationBarWidth(activity);
367 | mHasNavigationBar = (mNavigationBarHeight > 0);
368 | mTranslucentStatusBar = translucentStatusBar;
369 | mTranslucentNavBar = traslucentNavBar;
370 | }
371 |
372 | @TargetApi(14)
373 | private int getActionBarHeight(Context context) {
374 | int result = 0;
375 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
376 | TypedValue tv = new TypedValue();
377 | context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
378 | result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
379 | }
380 | return result;
381 | }
382 |
383 | @TargetApi(14)
384 | private int getNavigationBarHeight(Context context) {
385 | Resources res = context.getResources();
386 | int result = 0;
387 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
388 | if (hasNavBar(context)) {
389 | String key;
390 | if (mInPortrait) {
391 | key = NAV_BAR_HEIGHT_RES_NAME;
392 | } else {
393 | key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
394 | }
395 | return getInternalDimensionSize(res, key);
396 | }
397 | }
398 | return result;
399 | }
400 |
401 | @TargetApi(14)
402 | private int getNavigationBarWidth(Context context) {
403 | Resources res = context.getResources();
404 | int result = 0;
405 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
406 | if (hasNavBar(context)) {
407 | return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME);
408 | }
409 | }
410 | return result;
411 | }
412 |
413 | @TargetApi(14)
414 | private boolean hasNavBar(Context context) {
415 | Resources res = context.getResources();
416 | int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
417 | if (resourceId != 0) {
418 | boolean hasNav = res.getBoolean(resourceId);
419 | // check override flag (see static block)
420 | if ("1".equals(sNavBarOverride)) {
421 | hasNav = false;
422 | } else if ("0".equals(sNavBarOverride)) {
423 | hasNav = true;
424 | }
425 | return hasNav;
426 | } else { // fallback
427 | return !ViewConfiguration.get(context).hasPermanentMenuKey();
428 | }
429 | }
430 |
431 | private int getInternalDimensionSize(Resources res, String key) {
432 | int result = 0;
433 | int resourceId = res.getIdentifier(key, "dimen", "android");
434 | if (resourceId > 0) {
435 | result = res.getDimensionPixelSize(resourceId);
436 | }
437 | return result;
438 | }
439 |
440 | @SuppressLint("NewApi")
441 | private float getSmallestWidthDp(Activity activity) {
442 | DisplayMetrics metrics = new DisplayMetrics();
443 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
444 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
445 | } else {
446 | // TODO this is not correct, but we don't really care pre-kitkat
447 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
448 | }
449 | float widthDp = metrics.widthPixels / metrics.density;
450 | float heightDp = metrics.heightPixels / metrics.density;
451 | return Math.min(widthDp, heightDp);
452 | }
453 |
454 | /**
455 | * Should a navigation bar appear at the bottom of the screen in the current
456 | * device configuration? A navigation bar may appear on the right side of
457 | * the screen in certain configurations.
458 | *
459 | * @return True if navigation should appear at the bottom of the screen, False otherwise.
460 | */
461 | public boolean isNavigationAtBottom() {
462 | return (mSmallestWidthDp >= 600 || mInPortrait);
463 | }
464 |
465 | /**
466 | * Get the height of the system status bar.
467 | *
468 | * @return The height of the status bar (in pixels).
469 | */
470 | public int getStatusBarHeight() {
471 | return mStatusBarHeight;
472 | }
473 |
474 | /**
475 | * Get the height of the action bar.
476 | *
477 | * @return The height of the action bar (in pixels).
478 | */
479 | public int getActionBarHeight() {
480 | return mActionBarHeight;
481 | }
482 |
483 | /**
484 | * Does this device have a system navigation bar?
485 | *
486 | * @return True if this device uses soft key navigation, False otherwise.
487 | */
488 | public boolean hasNavigtionBar() {
489 | return mHasNavigationBar;
490 | }
491 |
492 | /**
493 | * Get the height of the system navigation bar.
494 | *
495 | * @return The height of the navigation bar (in pixels). If the device does not have
496 | * soft navigation keys, this will always return 0.
497 | */
498 | public int getNavigationBarHeight() {
499 | return mNavigationBarHeight;
500 | }
501 |
502 | /**
503 | * Get the width of the system navigation bar when it is placed vertically on the screen.
504 | *
505 | * @return The width of the navigation bar (in pixels). If the device does not have
506 | * soft navigation keys, this will always return 0.
507 | */
508 | public int getNavigationBarWidth() {
509 | return mNavigationBarWidth;
510 | }
511 |
512 | /**
513 | * Get the layout inset for any system UI that appears at the top of the screen.
514 | *
515 | * @param withActionBar True to include the height of the action bar, False otherwise.
516 | * @return The layout inset (in pixels).
517 | */
518 | public int getPixelInsetTop(boolean withActionBar) {
519 | return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0);
520 | }
521 |
522 | /**
523 | * Get the layout inset for any system UI that appears at the bottom of the screen.
524 | *
525 | * @return The layout inset (in pixels).
526 | */
527 | public int getPixelInsetBottom() {
528 | if (mTranslucentNavBar && isNavigationAtBottom()) {
529 | return mNavigationBarHeight;
530 | } else {
531 | return 0;
532 | }
533 | }
534 |
535 | /**
536 | * Get the layout inset for any system UI that appears at the right of the screen.
537 | *
538 | * @return The layout inset (in pixels).
539 | */
540 | public int getPixelInsetRight() {
541 | if (mTranslucentNavBar && !isNavigationAtBottom()) {
542 | return mNavigationBarWidth;
543 | } else {
544 | return 0;
545 | }
546 | }
547 |
548 | }
549 |
550 | }
551 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/FragmentReplace/FragmentPlace.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.FragmentReplace;
2 |
3 | public class FragmentPlace {
4 |
5 | // 复制以下代码到你的Activity即可
6 | // private void replaceFragment(String tag) {
7 | // tvTitle.setText(tag);
8 | // if (currentFragment != null) {
9 | // getSupportFragmentManager().beginTransaction().hide(currentFragment).commit();
10 | // }
11 | // currentFragment = (BaseFragment) getSupportFragmentManager().findFragmentByTag(tag);
12 | // if (currentFragment == null) {
13 | // switch (tag) {
14 | // case "首页":
15 | // currentFragment = new HomeFragment();
16 | // break;
17 | // case "新闻":
18 | // currentFragment = new NewsFragment();
19 | // break;
20 | // case "更多":
21 | // currentFragment = new MoreFragment();
22 | // break;
23 | // }
24 | // getSupportFragmentManager().beginTransaction().add(R.id.fl_main, currentFragment, tag).commit();
25 | // }else {
26 | // getSupportFragmentManager().beginTransaction().show(currentFragment).commit();
27 | // }
28 | // }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/Builder/Builder.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.Builder;
2 |
3 | public interface Builder {
4 |
5 | Builder builderBoard(String mBoard);
6 | Builder builderDisplay(String mDisplay);
7 | Builder builderOS(String mOS);
8 | Computer build();
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/Builder/Computer.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.Builder;
2 |
3 | public class Computer {
4 |
5 | protected String mBoard;
6 | protected String mDisplay;
7 | protected String mOS;
8 |
9 | public void setmBoard(String mBoard) {
10 | this.mBoard = mBoard;
11 | }
12 |
13 | public void setmDisplay(String mDisplay) {
14 | this.mDisplay = mDisplay;
15 | }
16 |
17 | public void setmOS(String mOS) {
18 | this.mOS = mOS;
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return "Computer{" +
24 | "mBoard='" + mBoard + '\'' +
25 | ", mDisplay='" + mDisplay + '\'' +
26 | ", mOS='" + mOS + '\'' +
27 | '}';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/Builder/MacBuilder.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.Builder;
2 |
3 | public class MacBuilder implements Builder{
4 |
5 | private Computer macComputer = new Computer();
6 |
7 | @Override
8 | public Builder builderBoard(String mBoard) {
9 | macComputer.setmBoard(mBoard);
10 | return this;
11 | }
12 |
13 | @Override
14 | public Builder builderDisplay(String mDisplay) {
15 | macComputer.setmDisplay(mDisplay);
16 | return this;
17 | }
18 |
19 | @Override
20 | public Builder builderOS(String mOS) {
21 | macComputer.setmOS(mOS);
22 | return this;
23 | }
24 |
25 | @Override
26 | public Computer build() {
27 | return macComputer;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/SingleInstace/DCLModeSingleInstance.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.SingleInstace;
2 |
3 | /**
4 | * 双重检测锁机制,线程安全的
5 | */
6 | public class DCLModeSingleInstance {
7 |
8 | private static volatile DCLModeSingleInstance singleInstance = null;
9 |
10 | private DCLModeSingleInstance(){
11 |
12 | }
13 |
14 | public static DCLModeSingleInstance getInstance(){
15 | if(singleInstance == null){
16 | synchronized (DCLModeSingleInstance.class){
17 | if(singleInstance == null){
18 | singleInstance = new DCLModeSingleInstance();
19 | }
20 | }
21 | }
22 | return singleInstance;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/SingleInstace/HungryModeSingleInstance.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.SingleInstace;
2 |
3 | /**
4 | * 饿汉式单例模式,线程安全的
5 | */
6 | public class HungryModeSingleInstance {
7 |
8 | //在项目运行是就存在单例对象
9 | private static HungryModeSingleInstance singleInstance = new HungryModeSingleInstance();
10 |
11 | private HungryModeSingleInstance(){
12 |
13 | }
14 |
15 | public static HungryModeSingleInstance getInstance(){
16 | return singleInstance;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/SingleInstace/LazybonesModeSingleInstace.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.SingleInstace;
2 |
3 | /**
4 | * 懒汉单例模式,容易出现线程安全问题
5 | */
6 | public class LazybonesModeSingleInstace {
7 |
8 | private static LazybonesModeSingleInstace singleInstace = null;
9 |
10 | private LazybonesModeSingleInstace(){}
11 |
12 |
13 | public static LazybonesModeSingleInstace getInstace(){
14 | if(singleInstace == null) {
15 | //当获取单例的时候才进行创建
16 | singleInstace = new LazybonesModeSingleInstace();
17 | }
18 | return singleInstace;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/SingleInstace/StaticCodePieceSingleInstace.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.SingleInstace;
2 |
3 | /**
4 | * 静态代码块单例模式,线程安全的,还有个枚举的,就不写了
5 | */
6 | public class StaticCodePieceSingleInstace {
7 |
8 | private static StaticCodePieceSingleInstace singleInstace = null;
9 |
10 | static {
11 | singleInstace = new StaticCodePieceSingleInstace();
12 | }
13 |
14 | private StaticCodePieceSingleInstace(){
15 |
16 | }
17 |
18 | public static StaticCodePieceSingleInstace getInstance(){
19 | return singleInstace;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Java23_Design_Patterns/SingleInstace/StaticInnerClassSingleInstace.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Java23_Design_Patterns.SingleInstace;
2 |
3 | /**
4 | * 静态内部类的方式,线程安全的
5 | */
6 | public class StaticInnerClassSingleInstace {
7 |
8 |
9 | // 私有构造
10 | private StaticInnerClassSingleInstace() {}
11 |
12 | // 静态内部类
13 | private static class InnerObject{
14 | private static StaticInnerClassSingleInstace single = new StaticInnerClassSingleInstace();
15 | }
16 |
17 | public static StaticInnerClassSingleInstace getInstance() {
18 | return InnerObject.single;
19 | }
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/LibraryUseDemo/RxJava/RxJavaDemo.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.LibraryUseDemo.RxJava;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.util.Log;
7 |
8 | import java.util.function.Consumer;
9 |
10 | import io.reactivex.Observable;
11 | import io.reactivex.ObservableEmitter;
12 | import io.reactivex.ObservableOnSubscribe;
13 | import io.reactivex.Observer;
14 | import io.reactivex.android.schedulers.AndroidSchedulers;
15 | import io.reactivex.disposables.Disposable;
16 | import io.reactivex.schedulers.Schedulers;
17 |
18 | import static android.content.ContentValues.TAG;
19 | import static java.lang.Thread.sleep;
20 |
21 | public class RxJavaDemo {
22 |
23 |
24 |
25 | // Observable.create(new ObservableOnSubscribe() {
26 | // @Override
27 | // public void subscribe(ObservableEmitter emitter) throws Exception {
28 | // for (int i=0;i() {
49 | // @Override
50 | // public void accept(Drawable drawable) throws Exception {
51 | // //回调后在UI界面上展示出来
52 | // }
53 | // });
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Serach/Serach.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Serach;
2 |
3 | //查找算法归类
4 | public class Serach {
5 |
6 | /*
7 | * 循环实现二分查找算法arr 已排好序的数组x 需要查找的数-1 无法查到数据
8 | */
9 | public static int binarySearch(int[] arr, int x) {
10 | int low = 0;
11 | int high = arr.length-1;
12 | while(low <= high) {
13 | int middle = (low + high)/2;
14 | if(x == arr[middle]) {
15 | return middle;
16 | }else if(x dataset[endIndex]||beginIndex>endIndex){
29 | return -1;
30 | }
31 | if(data dataset[midIndex]){
34 | return binarySearch(dataset,data,midIndex+1,endIndex);
35 | }else {
36 | return midIndex;
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ellen/example/Sort/Sort.java:
--------------------------------------------------------------------------------
1 | package com.ellen.example.Sort;
2 |
3 | //排序算法归类
4 | public class Sort {
5 |
6 | //冒泡排序范例
7 | public static void maoPaoSort(int[] array){
8 | for(int i=0;iarray[j]) {
11 | int temp = array[i];
12 | array[i] = array[j];
13 | array[j] = temp;
14 | }
15 | }
16 | }
17 | }
18 |
19 | //选择排序范例
20 | public static void chooseSort(int[] array){
21 | for(int i=0;i
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple_effect.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
20 |
21 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_wait.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recycler_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recycler_view1.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/toast_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 | #ffffff
8 | #808A87
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BaseQuickAndroid
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ellen/basequickandroid/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ellen.basequickandroid;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.3.2'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | maven { url 'https://jitpack.io' }
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ellen2018/BaseQuickAndroid/429e1fc6cc06b9260a7370a68315e2e9698f5266/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 17 10:36:42 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------