├── .idea
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── luo
│ │ └── myapplication
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── luo
│ │ │ └── myapplication
│ │ │ ├── APP.java
│ │ │ ├── LoadingViewActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── NewsListActivity.java
│ │ │ └── model
│ │ │ ├── NewsList.java
│ │ │ └── PersonBean.java
│ └── res
│ │ ├── drawable
│ │ └── gif.gif
│ │ ├── layout
│ │ ├── activity_loading_view.xml
│ │ ├── activity_main.xml
│ │ ├── activity_news_list.xml
│ │ └── item_news_list.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── luo
│ └── myapplication
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── luo
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── luo
│ │ │ └── library
│ │ │ └── base
│ │ │ ├── base
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseAndroid.java
│ │ │ ├── BaseConfig.java
│ │ │ ├── BaseDb.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── BaseFragmentActivity.java
│ │ │ ├── BaseHttp.java
│ │ │ ├── BaseImage.java
│ │ │ └── BaseWebViewActivity.java
│ │ │ ├── utils
│ │ │ ├── GsonUtil.java
│ │ │ ├── SpUtils.java
│ │ │ └── UpdateManager.java
│ │ │ └── widget
│ │ │ ├── BaseDialog.java
│ │ │ ├── LoadingDialog.java
│ │ │ ├── NoScrollGridView.java
│ │ │ ├── NoScrollListview.java
│ │ │ ├── NumberProgressBar.java
│ │ │ ├── OnDoubleClickListener.java
│ │ │ ├── OnNoDoubleClickListener.java
│ │ │ └── StatusBarCompat.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_back.png
│ │ ├── ic_empty.png
│ │ ├── loading_dialog_progressbar.xml
│ │ ├── loading_progress.png
│ │ └── shape_loading_dialog.xml
│ │ ├── layout
│ │ ├── activity_base_web_view.xml
│ │ ├── base_dialog.xml
│ │ ├── dialog_loading.xml
│ │ ├── dialog_loadinggif.xml
│ │ └── titleview_layout.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── style.xml
│ └── test
│ └── java
│ └── luo
│ └── library
│ └── ExampleUnitTest.java
└── settings.gradle
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BaseAndroid
2 | BaseAndroid 是一个app基本库,每次创建一个app项目,基本都会用到一些内容,所以我把它集合起来,做成一个库的形式,方便导入使用。第一版,没什么经验,希望大家多多指出错误,提些建议,大胆的提 Issues吧。
3 |
目前版本的功能:
4 |
1、标题栏操作
5 |
2、BaseActivity BaseFramgent BaseFramgentActivity
6 |
3、常用操作
7 |
4、图片显示
8 |
5、网络请求
9 |
6、数据库操作
10 |
该库会根据大家需求陆续更新,希望大家支持下
11 |
集成进去的库目前有:
12 | compile 'org.xutils:xutils:3.3.40'
13 | compile 'com.github.bumptech.glide:glide:3.7.0'
14 | compile 'com.google.code.gson:gson:2.8.0'
15 | 项目中如果有上面用的库不需要再导入
16 |
17 | ## 导入方法
18 | Step 1. Add it in your root build.gradle at the end of repositories.
19 |
20 | ```java
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url 'https://jitpack.io' }
25 | }
26 | }
27 | ```
28 | Step 2. Add the dependency
29 |
30 | ```java
31 | dependencies {
32 | ...
33 | compile 'com.github.LuoGuoXin:BaseAndroid:1.0.5'
34 | }
35 | ```
36 |
37 | ## 更新说明
38 |
2017/03/15 修改版本更新功能,一行代码实现
39 |
2017/02/15 增加加载框,增加BaseWebViewActivity
40 |
2017/02/10 增加版本更新下载功能(通知栏显示进度条,下载完成提示安装)
41 |
2017/02/05 增加网络请求的设置参数、修改标题栏背景色的设置方式(看下面初始化示例)
42 |
43 | ## 使用示例
44 | 在Application里面加上
45 | ```java
46 | public class APP extends Application {
47 | @Override
48 | public void onCreate() {
49 | super.onCreate();
50 | x.Ext.init(this);
51 | x.Ext.setDebug(true);
52 |
53 | BaseAndroid.init(new BaseConfig()
54 | .setAppColor(R.color.colorPrimary)//app主调颜色,用于标题栏等背景颜色
55 | .setAppLogo(R.mipmap.ic_launcher)//app图标
56 | .setFailPicture(R.mipmap.ic_launcher)//加载加载失败和加载中显示的图
57 | .setCode(0)//网络请求成功返回的code数字,默认为1
58 | .setHttpCode("code")//网络请求返回的code字段名称,默认为code
59 | .setHttpMessage("msg")//网络请求返回的message字段名称,默认为message
60 | .setHttpResult("resp"));//网络请求返回的result字段名称,默认为result
61 | }
62 | }
63 | ```
64 | ```java
65 | //常用操作
66 | void init() {
67 | //设置标题栏标题,记得先在布局上面添加标题栏布局:
68 | setTitleText("标题");
69 |
70 | //设置显示标题栏右边的按钮
71 | setRightButtonText("编辑", new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | //右边按钮点击事件
75 | }
76 | });
77 |
78 | //打开网页,一个好用的webview
79 | Intent intent = new Intent(this, BaseWebViewActivity.class);
80 | intent.putExtra(BaseWebViewActivity.URL, "http://www.baidu.com");
81 | startActivity(intent);
82 |
83 | //隐藏返回箭头
84 | hideBack();
85 |
86 | //弹出Toast
87 | showToast("Toast");
88 |
89 | //弹出加载窗口
90 | startProgressDialog();
91 |
92 | //弹出加载窗口,自定义提示
93 | startProgressDialog("loading...");
94 |
95 | //隐藏加载窗口
96 | stopProgressDialog();
97 |
98 | //设置透明状态栏
99 | StatusBarCompat.translucentStatusBar(this);
100 |
101 | //设置状态栏颜色
102 | StatusBarCompat.setStatusBarColor(this, Color.BLUE);
103 |
104 | //获取 TextView 和 EditView 的内容
105 | TextView textView = new TextView(this);
106 | getStr(textView);
107 |
108 | //判断字符、TextView和EditView的内容是否为空
109 | isNull(textView);
110 |
111 | //打开一个Activity
112 | // openActivity(XX.class);
113 |
114 | //保存内容到 SharedPreferences,第一个参数为key,第二个参数为保存的内容
115 | putSp("key", "内容");
116 |
117 | //从SharedPreferences上获取数据,第一个参数为key,第二个参数为默认内容
118 | getSp("key", "");
119 |
120 | //清除SharedPreferences的数据
121 | clearSp();
122 |
123 |
124 | /**
125 | * 版本更新
126 | *
127 | * @param context
128 | * @param versionCode 版本号
129 | * @param url apk下载地址
130 | * @param updateMessage 更新内容
131 | * @param isForced 是否强制更新
132 | */
133 | BaseAndroid.checkUpdate(MainActivity.this,2,
134 | "http://f5.market.mi-img.com/download/AppStore/0f4a347f5ce5a7e01315dda1ec35944fa56431d44/luo.footprint.apk",
135 | "更新了XXX\n修复OOO", false);
136 |
137 | }
138 |
139 | //图片显示操作
140 | void image(){
141 | //显示正常的图片,本地:new File("/ssd/base.jpg");drawable:R.drawable.base
142 | //图片加载使用 Glide ,感觉还是挺流畅好用的
143 | BaseImage.getInstance().displayImage(MainActivity.this, "http://www.base.com/base.jpg", imageView);
144 |
145 | //显示圆角图片
146 | BaseImage.getInstance().displayRoundImage(MainActivity.this,"http://www.base.com/base.jpg", imageView);
147 |
148 | //显示圆形图片
149 | BaseImage.getInstance().displayCricleImage(MainActivity.this,"http://www.base.com/base.jpg", imageView);
150 | }
151 |
152 | //网络请求操作
153 | //封装了下,onSuccess里面返回的result是请求成功(code=1)里面的内容,onError是code不等于1时的内容,网络错误时,code为-1
154 | void http() {
155 | RequestParams params = new RequestParams("http://www.base");
156 | BaseHttp.get(params, new BaseHttp.BaseHttpCallback() {
157 | @Override
158 | public void onSuccess(String result) {
159 | PersonBean personBean = GsonUtil.GsonToBean(result, PersonBean.class);
160 | List list = GsonUtil.GsonToList(result, PersonBean.class);
161 | }
162 |
163 | @Override
164 | public void onError(int code, String message) {
165 | showToast(message);
166 | }
167 | });
168 | }
169 |
170 | //数据库操作
171 | void db() {
172 | BaseDb.initDb();
173 | //添加数据
174 | for (int i = 0; i < 5; i++) {
175 | PersonBean personBean = new PersonBean();
176 | personBean.setName("小罗" + i);
177 | personBean.setAge(25 + i);
178 | BaseDb.add(personBean);
179 | }
180 | //查找数据
181 | List list = BaseDb.find(PersonBean.class);
182 | LogUtil.i(GsonUtil.GsonString(list));
183 |
184 | //修改数据
185 | PersonBean bean = list.get(3);
186 | bean.setName("修改名字为小小罗");
187 | BaseDb.update(bean);
188 |
189 | //删除一条数据
190 | PersonBean personBean = list.get(2);
191 | BaseDb.delete(personBean);
192 | }
193 | ```
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.3"
6 |
7 | defaultConfig {
8 | applicationId "luo.myapplication"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:24.2.1'
31 | testCompile 'junit:junit:4.12'
32 | compile project(':library')
33 | compile 'org.byteam.superadapter:superadapter:3.6.6'
34 | // compile 'com.github.LuoGuoXin:BaseAndroid:1.0.4'
35 | compile 'com.android.support:recyclerview-v7:24.2.1'
36 | compile 'com.malinskiy:superrecyclerview:1.1.4'
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/luo/myapplication/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("luo.myapplication", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/APP.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
2 |
3 | import android.app.Application;
4 |
5 | import org.xutils.x;
6 |
7 | import luo.library.base.base.BaseAndroid;
8 | import luo.library.base.base.BaseConfig;
9 |
10 | /**
11 | * Created by Administrator on 2017/1/6.
12 | */
13 |
14 | public class APP extends Application {
15 | @Override
16 | public void onCreate() {
17 | super.onCreate();
18 | x.Ext.init(this);
19 | x.Ext.setDebug(true);
20 |
21 | BaseAndroid.init(new BaseConfig()
22 | .setAppColor(R.color.colorPrimary)//app主调颜色,用于标题栏等背景颜色
23 | .setAppLogo(R.mipmap.ic_launcher)//app图标
24 | .setFailPicture(R.mipmap.ic_launcher)//加载加载失败和加载中显示的图
25 | .setLoadingView(R.drawable.gif)//设置加载框的gif图
26 | .setCode(0)//网络请求成功返回的code数字,默认为1
27 | .setHttpCode("code")//网络请求返回的code字段名称,默认为code
28 | .setHttpMessage("message")//网络请求返回的message字段名称,默认为message
29 | .setHttpResult("response"));//网络请求返回的result字段名称,默认为result
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/LoadingViewActivity.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.view.View;
6 |
7 | import org.xutils.view.annotation.ContentView;
8 | import org.xutils.view.annotation.Event;
9 |
10 | import luo.library.base.base.BaseActivity;
11 |
12 | /**
13 | * 加载框使用示例
14 | */
15 | @ContentView(R.layout.activity_loading_view)
16 | public class LoadingViewActivity extends BaseActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setTitleText("加载框使用");
22 | }
23 |
24 | @Event({R.id.btn_load, R.id.btn_loadText, R.id.btn_loadgif})
25 | private void loadView(View view) {
26 | switch (view.getId()) {
27 | case R.id.btn_load://打开默认的加载框
28 | startProgressDialog();
29 | close();
30 | break;
31 | case R.id.btn_loadText://打开自定义文字的加载框
32 | startProgressDialog("正在下载...");
33 | close();
34 | break;
35 | case R.id.btn_loadgif://设置一张gif图片为加载框的布局,gif文件尽量小
36 | startGifProgressDialog();
37 | close();
38 | break;
39 | }
40 | }
41 |
42 | void close() {
43 | Handler handler = new Handler();
44 | handler.postDelayed(new Runnable() {
45 | @Override
46 | public void run() {
47 | stopProgressDialog();
48 | }
49 | }, 5000);//5秒后关闭加载框
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import org.xutils.common.util.LogUtil;
11 | import org.xutils.http.RequestParams;
12 | import org.xutils.view.annotation.ContentView;
13 | import org.xutils.view.annotation.Event;
14 |
15 | import java.util.List;
16 |
17 | import luo.library.base.base.BaseActivity;
18 | import luo.library.base.base.BaseAndroid;
19 | import luo.library.base.base.BaseDb;
20 | import luo.library.base.base.BaseHttp;
21 | import luo.library.base.base.BaseImage;
22 | import luo.library.base.base.BaseWebViewActivity;
23 | import luo.library.base.utils.GsonUtil;
24 | import luo.library.base.widget.StatusBarCompat;
25 | import luo.myapplication.model.PersonBean;
26 |
27 | @ContentView(R.layout.activity_main)
28 | public class MainActivity extends BaseActivity {
29 |
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setTitleText("BaseAndroid");
35 | hideBack();
36 |
37 | }
38 |
39 | @Event(R.id.btn_webview)
40 | private void webview(View view) {
41 | Intent intent = new Intent(this, BaseWebViewActivity.class);
42 | intent.putExtra(BaseWebViewActivity.URL, "http://www.baidu.com");
43 | startActivity(intent);
44 | }
45 |
46 | @Event(R.id.btn_loadingview)
47 | private void loadingView(View view) {
48 | openActivity(LoadingViewActivity.class);
49 | }
50 |
51 | @Event(R.id.btn_newsList)
52 | private void newsList(View view) {
53 | openActivity(NewsListActivity.class);
54 | }
55 |
56 | @Event(R.id.btn_update)
57 | private void update(View view) {
58 | BaseAndroid.checkUpdate(MainActivity.this, 2,
59 | "http://f5.market.mi-img.com/download/AppStore/0f4a347f5ce5a7e01315dda1ec35944fa56431d44/luo.footprint.apk", "更新了XXX\n修复OOO", true);
60 | }
61 |
62 | //常用操作
63 | void init() {
64 | //设置标题栏标题,记得先在布局上面添加标题栏布局:
65 | setTitleText("标题");
66 |
67 | //设置显示标题栏右边的按钮
68 | setRightButtonText("编辑", new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | //右边按钮点击事件
72 | }
73 | });
74 |
75 | //隐藏返回箭头
76 | hideBack();
77 |
78 | //弹出Toast
79 | showToast("Toast");
80 |
81 | //弹出加载窗口
82 | startProgressDialog();
83 |
84 | //弹出加载窗口,自定义提示
85 | startProgressDialog("loading...");
86 |
87 | //隐藏加载窗口
88 | stopProgressDialog();
89 |
90 | //设置透明状态栏
91 | StatusBarCompat.translucentStatusBar(this);
92 |
93 | //设置状态栏颜色
94 | StatusBarCompat.setStatusBarColor(this, Color.BLUE);
95 |
96 | //获取 TextView 和 EditView 的内容
97 | TextView textView = new TextView(this);
98 | getStr(textView);
99 |
100 | //判断字符、TextView和EditView的内容是否为空
101 | isNull(textView);
102 |
103 | //打开一个Activity
104 | // openActivity(XX.class);
105 |
106 | //保存内容到 SharedPreferences,第一个参数为key,第二个参数为保存的内容
107 | putSp("key", "内容");
108 |
109 | //从SharedPreferences上获取数据,第一个参数为key,第二个参数为默认内容
110 | getSp("key", "");
111 |
112 | //清除SharedPreferences的数据
113 | clearSp();
114 |
115 | //版本更新
116 | BaseAndroid.checkUpdate(MainActivity.this, 2, "http://f5.market.mi-img.com/download/AppStore/0f4a347f5ce5a7e01315dda1ec35944fa56431d44/luo.footprint.apk", "更新了XXX\n修复OOO", false);
117 |
118 | }
119 |
120 | //图片显示操作
121 | void image() {
122 | //显示正常的图片,本地:new File("/ssd/base.jpg");drawable:R.drawable.base
123 | //图片加载使用 Glide ,感觉还是挺流畅好用的
124 | ImageView imageView = new ImageView(this);
125 | BaseImage.getInstance().displayImage(MainActivity.this, "http://www.base.com/base.jpg", imageView);
126 |
127 | //显示圆角图片
128 | BaseImage.getInstance().displayRoundImage(MainActivity.this, "http://www.base.com/base.jpg", imageView);
129 |
130 | //显示圆形图片
131 | BaseImage.getInstance().displayCricleImage(MainActivity.this, "http://www.base.com/base.jpg", imageView);
132 | }
133 |
134 | //网络请求操作
135 | //封装了下,onSuccess里面返回的result是请求成功(code=1)里面的内容,onError是code不等于1时的内容,网络错误时,code为-1
136 | void http() {
137 | RequestParams params = new RequestParams("http://115.28.13.1/lovect/bannerAction");
138 | BaseHttp.get(params, new BaseHttp.BaseHttpCallback() {
139 | @Override
140 | public void onSuccess(String result) {
141 | LogUtil.i(result);
142 | // PersonBean personBean = GsonUtil.GsonToBean(result, PersonBean.class);
143 | // List list = GsonUtil.GsonToList(result, PersonBean.class);
144 | }
145 |
146 | @Override
147 | public void onError(int code, String message) {
148 | showToast(message);
149 | }
150 | });
151 | }
152 |
153 | //数据库操作
154 | void db() {
155 | BaseDb.initDb();
156 | //添加数据
157 | for (int i = 0; i < 5; i++) {
158 | PersonBean personBean = new PersonBean();
159 | personBean.setName("小罗" + i);
160 | personBean.setAge(25 + i);
161 | BaseDb.add(personBean);
162 | }
163 | //查找数据
164 | List list = BaseDb.find(PersonBean.class);
165 | LogUtil.i(GsonUtil.GsonString(list));
166 |
167 | //修改数据
168 | PersonBean bean = list.get(3);
169 | bean.setName("修改名字为小小罗");
170 | BaseDb.update(bean);
171 |
172 | //删除一条数据
173 | PersonBean personBean = list.get(2);
174 | BaseDb.delete(personBean);
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/NewsListActivity.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.widget.SwipeRefreshLayout;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.widget.ImageView;
7 |
8 | import com.malinskiy.superrecyclerview.OnMoreListener;
9 | import com.malinskiy.superrecyclerview.SuperRecyclerView;
10 |
11 | import org.byteam.superadapter.SuperAdapter;
12 | import org.byteam.superadapter.SuperViewHolder;
13 | import org.byteam.superadapter.animation.ScaleInAnimation;
14 | import org.xutils.http.RequestParams;
15 | import org.xutils.view.annotation.ContentView;
16 | import org.xutils.view.annotation.ViewInject;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import luo.library.base.base.BaseActivity;
22 | import luo.library.base.base.BaseHttp;
23 | import luo.library.base.base.BaseImage;
24 | import luo.library.base.utils.GsonUtil;
25 | import luo.myapplication.model.NewsList;
26 |
27 |
28 | /**
29 | * 网络请求示例
30 | */
31 | @ContentView(R.layout.activity_news_list)
32 | public class NewsListActivity extends BaseActivity {
33 |
34 | @ViewInject(R.id.recyclerView)
35 | SuperRecyclerView recyclerView;
36 | int page = 1;
37 | List lists = new ArrayList();
38 | SuperAdapter adapter;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setTitleText("新闻列表");
44 | init();
45 | http();
46 | }
47 |
48 | void init() {
49 | adapter = new SuperAdapter(NewsListActivity.this, lists, R.layout.item_news_list) {
50 |
51 | @Override
52 | public void onBind(SuperViewHolder holder, int viewType, int layoutPosition, NewsList item) {
53 | holder.setText(R.id.title, item.getT_title());
54 | ImageView imageView = holder.findViewById(R.id.image);
55 | String imgs[] = item.getP_file().split(",");
56 | BaseImage.getInstance().displayImage(NewsListActivity.this, imgs[0], imageView);
57 | }
58 | };
59 | adapter.enableLoadAnimation(300, new ScaleInAnimation());
60 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
61 | recyclerView.setAdapter(adapter);
62 | recyclerView.setRefreshingColorResources(android.R.color.holo_orange_light, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_red_light);
63 | recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
64 | @Override
65 | public void onRefresh() {
66 | page = 1;
67 | http();
68 | }
69 | });
70 | recyclerView.setupMoreListener(new OnMoreListener() {
71 | @Override
72 | public void onMoreAsked(int overallItemsCount, int itemsBeforeMore, int maxLastVisiblePosition) {
73 | page++;
74 | http();
75 | }
76 | }, 1);
77 | }
78 |
79 | void http() {
80 | RequestParams params = new RequestParams("http://www.zs21.cn/zswjk/queryTender");
81 | params.addQueryStringParameter("pageNo", String.valueOf(page));
82 | BaseHttp.get(params, new BaseHttp.BaseHttpCallback() {
83 | @Override
84 | public void onSuccess(String result) {
85 | lists = GsonUtil.GsonToList(result, NewsList.class);
86 | if (page == 1) {
87 | adapter.replaceAll(lists);
88 | } else {
89 | adapter.addAll(lists);
90 | }
91 | if (lists.size() == 0) {
92 | showToast("加载完毕");
93 | }
94 | }
95 |
96 | @Override
97 | public void onError(int code, String message) {
98 | showToast(message);
99 | }
100 | });
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/model/NewsList.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication.model;
2 |
3 | /**
4 | * Created by Administrator on 2017/2/16.
5 | */
6 |
7 | public class NewsList {
8 | private String t_title;
9 | private String p_file;
10 |
11 |
12 | public String getT_title() {
13 | return t_title;
14 | }
15 |
16 | public void setT_title(String t_title) {
17 | this.t_title = t_title;
18 | }
19 |
20 | public String getP_file() {
21 | return p_file;
22 | }
23 |
24 | public void setP_file(String p_file) {
25 | this.p_file = p_file;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/luo/myapplication/model/PersonBean.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication.model;
2 |
3 | import org.xutils.db.annotation.Column;
4 | import org.xutils.db.annotation.Table;
5 |
6 | /**
7 | * 数据库操作示例bean
8 | */
9 |
10 | @Table(name = "PersonBean")
11 | public class PersonBean {
12 | @Column(name = "id", isId = true)
13 | private int id;
14 |
15 | @Column(name = "name")
16 | private String name;
17 |
18 | @Column(name = "age")
19 | private int age;
20 |
21 | public int getId() {
22 | return id;
23 | }
24 |
25 | public void setId(int id) {
26 | this.id = id;
27 | }
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public void setName(String name) {
34 | this.name = name;
35 | }
36 |
37 | public int getAge() {
38 | return age;
39 | }
40 |
41 | public void setAge(int age) {
42 | this.age = age;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gif.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/drawable/gif.gif
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_loading_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_news_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_news_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuoGuoXin/BaseAndroid/36089042b8a09ecc8bd1bd2369f6b6492dd63725/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.12px
4 | 2.25px
5 | 4.5px
6 | 6.75px
7 | 9px
8 | 11.25px
9 | 13.5px
10 | 15.75px
11 | 18px
12 | 20.25px
13 | 22.5px
14 | 24.75px
15 | 27px
16 | 29.25px
17 | 31.5px
18 | 33.75px
19 | 36px
20 | 38.25px
21 | 40.5px
22 | 42.75px
23 | 45px
24 | 47.25px
25 | 49.5px
26 | 51.75px
27 | 54px
28 | 56.25px
29 | 58.5px
30 | 60.75px
31 | 63px
32 | 65.25px
33 | 67.5px
34 | 69.75px
35 | 72px
36 | 74.25px
37 | 76.5px
38 | 78.75px
39 | 81px
40 | 83.25px
41 | 85.5px
42 | 87.75px
43 | 90px
44 | 92.25px
45 | 94.5px
46 | 96.75px
47 | 99px
48 | 101.25px
49 | 103.5px
50 | 105.75px
51 | 108px
52 | 110.25px
53 | 112.5px
54 | 114.75px
55 | 117px
56 | 119.25px
57 | 121.5px
58 | 123.75px
59 | 126px
60 | 128.25px
61 | 130.5px
62 | 132.75px
63 | 135px
64 | 137.25px
65 | 139.5px
66 | 141.75px
67 | 144px
68 | 146.25px
69 | 148.5px
70 | 150.75px
71 | 153px
72 | 155.25px
73 | 157.5px
74 | 159.75px
75 | 162px
76 | 164.25px
77 | 166.5px
78 | 168.75px
79 | 171px
80 | 173.25px
81 | 175.5px
82 | 177.75px
83 | 180px
84 | 182.25px
85 | 184.5px
86 | 186.75px
87 | 189px
88 | 191.25px
89 | 193.5px
90 | 195.75px
91 | 198px
92 | 200.25px
93 | 202.5px
94 | 204.75px
95 | 207px
96 | 209.25px
97 | 211.5px
98 | 213.75px
99 | 216px
100 | 218.25px
101 | 220.5px
102 | 222.75px
103 | 225px
104 | 227.25px
105 | 229.5px
106 | 231.75px
107 | 234px
108 | 236.25px
109 | 238.5px
110 | 240.75px
111 | 243px
112 | 245.25px
113 | 247.5px
114 | 249.75px
115 | 252px
116 | 254.25px
117 | 256.5px
118 | 258.75px
119 | 261px
120 | 263.25px
121 | 265.5px
122 | 267.75px
123 | 270px
124 | 272.25px
125 | 274.5px
126 | 276.75px
127 | 279px
128 | 281.25px
129 | 283.5px
130 | 285.75px
131 | 288px
132 | 290.25px
133 | 292.5px
134 | 294.75px
135 | 297px
136 | 299.25px
137 | 301.5px
138 | 303.75px
139 | 306px
140 | 308.25px
141 | 310.5px
142 | 312.75px
143 | 315px
144 | 317.25px
145 | 319.5px
146 | 321.75px
147 | 324px
148 | 326.25px
149 | 328.5px
150 | 330.75px
151 | 333px
152 | 335.25px
153 | 337.5px
154 | 339.75px
155 | 342px
156 | 344.25px
157 | 346.5px
158 | 348.75px
159 | 351px
160 | 353.25px
161 | 355.5px
162 | 357.75px
163 | 360px
164 | 362.25px
165 | 364.5px
166 | 366.75px
167 | 369px
168 | 371.25px
169 | 373.5px
170 | 375.75px
171 | 378px
172 | 380.25px
173 | 382.5px
174 | 384.75px
175 | 387px
176 | 389.25px
177 | 391.5px
178 | 393.75px
179 | 396px
180 | 398.25px
181 | 400.5px
182 | 402.75px
183 | 405px
184 | 407.25px
185 | 409.5px
186 | 411.75px
187 | 414px
188 | 416.25px
189 | 418.5px
190 | 420.75px
191 | 423px
192 | 425.25px
193 | 427.5px
194 | 429.75px
195 | 432px
196 | 434.25px
197 | 436.5px
198 | 438.75px
199 | 441px
200 | 443.25px
201 | 445.5px
202 | 447.75px
203 | 450px
204 | 452.25px
205 | 454.5px
206 | 456.75px
207 | 459px
208 | 461.25px
209 | 463.5px
210 | 465.75px
211 | 468px
212 | 470.25px
213 | 472.5px
214 | 474.75px
215 | 477px
216 | 479.25px
217 | 481.5px
218 | 483.75px
219 | 486px
220 | 488.25px
221 | 490.5px
222 | 492.75px
223 | 495px
224 | 497.25px
225 | 499.5px
226 | 501.75px
227 | 504px
228 | 506.25px
229 | 508.5px
230 | 510.75px
231 | 513px
232 | 515.25px
233 | 517.5px
234 | 519.75px
235 | 522px
236 | 524.25px
237 | 526.5px
238 | 528.75px
239 | 531px
240 | 533.25px
241 | 535.5px
242 | 537.75px
243 | 540px
244 | 542.25px
245 | 544.5px
246 | 546.75px
247 | 549px
248 | 551.25px
249 | 553.5px
250 | 555.75px
251 | 558px
252 | 560.25px
253 | 562.5px
254 | 564.75px
255 | 567px
256 | 569.25px
257 | 571.5px
258 | 573.75px
259 | 576px
260 | 578.25px
261 | 580.5px
262 | 582.75px
263 | 585px
264 | 587.25px
265 | 589.5px
266 | 591.75px
267 | 594px
268 | 596.25px
269 | 598.5px
270 | 600.75px
271 | 603px
272 | 605.25px
273 | 607.5px
274 | 609.75px
275 | 612px
276 | 614.25px
277 | 616.5px
278 | 618.75px
279 | 621px
280 | 623.25px
281 | 625.5px
282 | 627.75px
283 | 630px
284 | 632.25px
285 | 634.5px
286 | 636.75px
287 | 639px
288 | 641.25px
289 | 643.5px
290 | 645.75px
291 | 648px
292 | 650.25px
293 | 652.5px
294 | 654.75px
295 | 657px
296 | 659.25px
297 | 661.5px
298 | 663.75px
299 | 666px
300 | 668.25px
301 | 670.5px
302 | 672.75px
303 | 675px
304 | 677.25px
305 | 679.5px
306 | 681.75px
307 | 684px
308 | 686.25px
309 | 688.5px
310 | 690.75px
311 | 693px
312 | 695.25px
313 | 697.5px
314 | 699.75px
315 | 702px
316 | 704.25px
317 | 706.5px
318 | 708.75px
319 | 711px
320 | 713.25px
321 | 715.5px
322 | 717.75px
323 | 720px
324 | 722.25px
325 | 724.5px
326 | 726.75px
327 | 729px
328 | 731.25px
329 | 733.5px
330 | 735.75px
331 | 738px
332 | 740.25px
333 | 742.5px
334 | 744.75px
335 | 747px
336 | 749.25px
337 | 751.5px
338 | 753.75px
339 | 756px
340 | 758.25px
341 | 760.5px
342 | 762.75px
343 | 765px
344 | 767.25px
345 | 769.5px
346 | 771.75px
347 | 774px
348 | 776.25px
349 | 778.5px
350 | 780.75px
351 | 783px
352 | 785.25px
353 | 787.5px
354 | 789.75px
355 | 792px
356 | 794.25px
357 | 796.5px
358 | 798.75px
359 | 801px
360 | 803.25px
361 | 805.5px
362 | 807.75px
363 | 810px
364 | 812.25px
365 | 814.5px
366 | 816.75px
367 | 819px
368 | 821.25px
369 | 823.5px
370 | 825.75px
371 | 828px
372 | 830.25px
373 | 832.5px
374 | 834.75px
375 | 837px
376 | 839.25px
377 | 841.5px
378 | 843.75px
379 | 846px
380 | 848.25px
381 | 850.5px
382 | 852.75px
383 | 855px
384 | 857.25px
385 | 859.5px
386 | 861.75px
387 | 864px
388 | 866.25px
389 | 868.5px
390 | 870.75px
391 | 873px
392 | 875.25px
393 | 877.5px
394 | 879.75px
395 | 882px
396 | 884.25px
397 | 886.5px
398 | 888.75px
399 | 891px
400 | 893.25px
401 | 895.5px
402 | 897.75px
403 | 900px
404 | 902.25px
405 | 904.5px
406 | 906.75px
407 | 909px
408 | 911.25px
409 | 913.5px
410 | 915.75px
411 | 918px
412 | 920.25px
413 | 922.5px
414 | 924.75px
415 | 927px
416 | 929.25px
417 | 931.5px
418 | 933.75px
419 | 936px
420 | 938.25px
421 | 940.5px
422 | 942.75px
423 | 945px
424 | 947.25px
425 | 949.5px
426 | 951.75px
427 | 954px
428 | 956.25px
429 | 958.5px
430 | 960.75px
431 | 963px
432 | 965.25px
433 | 967.5px
434 | 969.75px
435 | 972px
436 | 974.25px
437 | 976.5px
438 | 978.75px
439 | 981px
440 | 983.25px
441 | 985.5px
442 | 987.75px
443 | 990px
444 | 992.25px
445 | 994.5px
446 | 996.75px
447 | 999px
448 | 1001.25px
449 | 1003.5px
450 | 1005.75px
451 | 1008px
452 | 1010.25px
453 | 1012.5px
454 | 1014.75px
455 | 1017px
456 | 1019.25px
457 | 1021.5px
458 | 1023.75px
459 | 1026px
460 | 1028.25px
461 | 1030.5px
462 | 1032.75px
463 | 1035px
464 | 1037.25px
465 | 1039.5px
466 | 1041.75px
467 | 1044px
468 | 1046.25px
469 | 1048.5px
470 | 1050.75px
471 | 1053px
472 | 1055.25px
473 | 1057.5px
474 | 1059.75px
475 | 1062px
476 | 1064.25px
477 | 1066.5px
478 | 1068.75px
479 | 1071px
480 | 1073.25px
481 | 1075.5px
482 | 1077.75px
483 | 1080px
484 | 1082.25px
485 | 1084.5px
486 | 1086.75px
487 | 1089px
488 | 1091.25px
489 | 1093.5px
490 | 1095.75px
491 | 1098px
492 | 1100.25px
493 | 1102.5px
494 | 1104.75px
495 | 1107px
496 | 1109.25px
497 | 1111.5px
498 | 1113.75px
499 | 1116px
500 | 1118.25px
501 | 1120.5px
502 | 1122.75px
503 | 1125px
504 | 1127.25px
505 | 1129.5px
506 | 1131.75px
507 | 1134px
508 | 1136.25px
509 | 1138.5px
510 | 1140.75px
511 | 1143px
512 | 1145.25px
513 | 1147.5px
514 | 1149.75px
515 | 1152px
516 | 1154.25px
517 | 1156.5px
518 | 1158.75px
519 | 1161px
520 | 1163.25px
521 | 1165.5px
522 | 1167.75px
523 | 1170px
524 | 1172.25px
525 | 1174.5px
526 | 1176.75px
527 | 1179px
528 | 1181.25px
529 | 1183.5px
530 | 1185.75px
531 | 1188px
532 | 1190.25px
533 | 1192.5px
534 | 1194.75px
535 | 1197px
536 | 1199.25px
537 | 1201.5px
538 | 1203.75px
539 | 1206px
540 | 1208.25px
541 | 1210.5px
542 | 1212.75px
543 | 1215px
544 | 1217.25px
545 | 1219.5px
546 | 1221.75px
547 | 1224px
548 | 1226.25px
549 | 1228.5px
550 | 1230.75px
551 | 1233px
552 | 1235.25px
553 | 1237.5px
554 | 1239.75px
555 | 1242px
556 | 1244.25px
557 | 1246.5px
558 | 1248.75px
559 | 1251px
560 | 1253.25px
561 | 1255.5px
562 | 1257.75px
563 | 1260px
564 | 1262.25px
565 | 1264.5px
566 | 1266.75px
567 | 1269px
568 | 1271.25px
569 | 1273.5px
570 | 1275.75px
571 | 1278px
572 | 1280.25px
573 | 1282.5px
574 | 1284.75px
575 | 1287px
576 | 1289.25px
577 | 1291.5px
578 | 1293.75px
579 | 1296px
580 | 1298.25px
581 | 1300.5px
582 | 1302.75px
583 | 1305px
584 | 1307.25px
585 | 1309.5px
586 | 1311.75px
587 | 1314px
588 | 1316.25px
589 | 1318.5px
590 | 1320.75px
591 | 1323px
592 | 1325.25px
593 | 1327.5px
594 | 1329.75px
595 | 1332px
596 | 1334.25px
597 | 1336.5px
598 | 1338.75px
599 | 1341px
600 | 1343.25px
601 | 1345.5px
602 | 1347.75px
603 |
606 | 64dp
607 |
608 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.12px
4 | 2.25px
5 | 4.5px
6 | 6.75px
7 | 9px
8 | 11.25px
9 | 13.5px
10 | 15.75px
11 | 18px
12 | 20.25px
13 | 22.5px
14 | 24.75px
15 | 27px
16 | 29.25px
17 | 31.5px
18 | 33.75px
19 | 36px
20 | 38.25px
21 | 40.5px
22 | 42.75px
23 | 45px
24 | 47.25px
25 | 49.5px
26 | 51.75px
27 | 54px
28 | 56.25px
29 | 58.5px
30 | 60.75px
31 | 63px
32 | 65.25px
33 | 67.5px
34 | 69.75px
35 | 72px
36 | 74.25px
37 | 76.5px
38 | 78.75px
39 | 81px
40 | 83.25px
41 | 85.5px
42 | 87.75px
43 | 90px
44 | 92.25px
45 | 94.5px
46 | 96.75px
47 | 99px
48 | 101.25px
49 | 103.5px
50 | 105.75px
51 | 108px
52 | 110.25px
53 | 112.5px
54 | 114.75px
55 | 117px
56 | 119.25px
57 | 121.5px
58 | 123.75px
59 | 126px
60 | 128.25px
61 | 130.5px
62 | 132.75px
63 | 135px
64 | 137.25px
65 | 139.5px
66 | 141.75px
67 | 144px
68 | 146.25px
69 | 148.5px
70 | 150.75px
71 | 153px
72 | 155.25px
73 | 157.5px
74 | 159.75px
75 | 162px
76 | 164.25px
77 | 166.5px
78 | 168.75px
79 | 171px
80 | 173.25px
81 | 175.5px
82 | 177.75px
83 | 180px
84 | 182.25px
85 | 184.5px
86 | 186.75px
87 | 189px
88 | 191.25px
89 | 193.5px
90 | 195.75px
91 | 198px
92 | 200.25px
93 | 202.5px
94 | 204.75px
95 | 207px
96 | 209.25px
97 | 211.5px
98 | 213.75px
99 | 216px
100 | 218.25px
101 | 220.5px
102 | 222.75px
103 | 225px
104 | 227.25px
105 | 229.5px
106 | 231.75px
107 | 234px
108 | 236.25px
109 | 238.5px
110 | 240.75px
111 | 243px
112 | 245.25px
113 | 247.5px
114 | 249.75px
115 | 252px
116 | 254.25px
117 | 256.5px
118 | 258.75px
119 | 261px
120 | 263.25px
121 | 265.5px
122 | 267.75px
123 | 270px
124 | 272.25px
125 | 274.5px
126 | 276.75px
127 | 279px
128 | 281.25px
129 | 283.5px
130 | 285.75px
131 | 288px
132 | 290.25px
133 | 292.5px
134 | 294.75px
135 | 297px
136 | 299.25px
137 | 301.5px
138 | 303.75px
139 | 306px
140 | 308.25px
141 | 310.5px
142 | 312.75px
143 | 315px
144 | 317.25px
145 | 319.5px
146 | 321.75px
147 | 324px
148 | 326.25px
149 | 328.5px
150 | 330.75px
151 | 333px
152 | 335.25px
153 | 337.5px
154 | 339.75px
155 | 342px
156 | 344.25px
157 | 346.5px
158 | 348.75px
159 | 351px
160 | 353.25px
161 | 355.5px
162 | 357.75px
163 | 360px
164 | 362.25px
165 | 364.5px
166 | 366.75px
167 | 369px
168 | 371.25px
169 | 373.5px
170 | 375.75px
171 | 378px
172 | 380.25px
173 | 382.5px
174 | 384.75px
175 | 387px
176 | 389.25px
177 | 391.5px
178 | 393.75px
179 | 396px
180 | 398.25px
181 | 400.5px
182 | 402.75px
183 | 405px
184 | 407.25px
185 | 409.5px
186 | 411.75px
187 | 414px
188 | 416.25px
189 | 418.5px
190 | 420.75px
191 | 423px
192 | 425.25px
193 | 427.5px
194 | 429.75px
195 | 432px
196 | 434.25px
197 | 436.5px
198 | 438.75px
199 | 441px
200 | 443.25px
201 | 445.5px
202 | 447.75px
203 | 450px
204 | 452.25px
205 | 454.5px
206 | 456.75px
207 | 459px
208 | 461.25px
209 | 463.5px
210 | 465.75px
211 | 468px
212 | 470.25px
213 | 472.5px
214 | 474.75px
215 | 477px
216 | 479.25px
217 | 481.5px
218 | 483.75px
219 | 486px
220 | 488.25px
221 | 490.5px
222 | 492.75px
223 | 495px
224 | 497.25px
225 | 499.5px
226 | 501.75px
227 | 504px
228 | 506.25px
229 | 508.5px
230 | 510.75px
231 | 513px
232 | 515.25px
233 | 517.5px
234 | 519.75px
235 | 522px
236 | 524.25px
237 | 526.5px
238 | 528.75px
239 | 531px
240 | 533.25px
241 | 535.5px
242 | 537.75px
243 | 540px
244 | 542.25px
245 | 544.5px
246 | 546.75px
247 | 549px
248 | 551.25px
249 | 553.5px
250 | 555.75px
251 | 558px
252 | 560.25px
253 | 562.5px
254 | 564.75px
255 | 567px
256 | 569.25px
257 | 571.5px
258 | 573.75px
259 | 576px
260 | 578.25px
261 | 580.5px
262 | 582.75px
263 | 585px
264 | 587.25px
265 | 589.5px
266 | 591.75px
267 | 594px
268 | 596.25px
269 | 598.5px
270 | 600.75px
271 | 603px
272 | 605.25px
273 | 607.5px
274 | 609.75px
275 | 612px
276 | 614.25px
277 | 616.5px
278 | 618.75px
279 | 621px
280 | 623.25px
281 | 625.5px
282 | 627.75px
283 | 630px
284 | 632.25px
285 | 634.5px
286 | 636.75px
287 | 639px
288 | 641.25px
289 | 643.5px
290 | 645.75px
291 | 648px
292 | 650.25px
293 | 652.5px
294 | 654.75px
295 | 657px
296 | 659.25px
297 | 661.5px
298 | 663.75px
299 | 666px
300 | 668.25px
301 | 670.5px
302 | 672.75px
303 | 675px
304 | 677.25px
305 | 679.5px
306 | 681.75px
307 | 684px
308 | 686.25px
309 | 688.5px
310 | 690.75px
311 | 693px
312 | 695.25px
313 | 697.5px
314 | 699.75px
315 | 702px
316 | 704.25px
317 | 706.5px
318 | 708.75px
319 | 711px
320 | 713.25px
321 | 715.5px
322 | 717.75px
323 | 720px
324 | 722.25px
325 | 724.5px
326 | 726.75px
327 | 729px
328 | 731.25px
329 | 733.5px
330 | 735.75px
331 | 738px
332 | 740.25px
333 | 742.5px
334 | 744.75px
335 | 747px
336 | 749.25px
337 | 751.5px
338 | 753.75px
339 | 756px
340 | 758.25px
341 | 760.5px
342 | 762.75px
343 | 765px
344 | 767.25px
345 | 769.5px
346 | 771.75px
347 | 774px
348 | 776.25px
349 | 778.5px
350 | 780.75px
351 | 783px
352 | 785.25px
353 | 787.5px
354 | 789.75px
355 | 792px
356 | 794.25px
357 | 796.5px
358 | 798.75px
359 | 801px
360 | 803.25px
361 | 805.5px
362 | 807.75px
363 | 810px
364 | 812.25px
365 | 814.5px
366 | 816.75px
367 | 819px
368 | 821.25px
369 | 823.5px
370 | 825.75px
371 | 828px
372 | 830.25px
373 | 832.5px
374 | 834.75px
375 | 837px
376 | 839.25px
377 | 841.5px
378 | 843.75px
379 | 846px
380 | 848.25px
381 | 850.5px
382 | 852.75px
383 | 855px
384 | 857.25px
385 | 859.5px
386 | 861.75px
387 | 864px
388 | 866.25px
389 | 868.5px
390 | 870.75px
391 | 873px
392 | 875.25px
393 | 877.5px
394 | 879.75px
395 | 882px
396 | 884.25px
397 | 886.5px
398 | 888.75px
399 | 891px
400 | 893.25px
401 | 895.5px
402 | 897.75px
403 | 900px
404 | 902.25px
405 | 904.5px
406 | 906.75px
407 | 909px
408 | 911.25px
409 | 913.5px
410 | 915.75px
411 | 918px
412 | 920.25px
413 | 922.5px
414 | 924.75px
415 | 927px
416 | 929.25px
417 | 931.5px
418 | 933.75px
419 | 936px
420 | 938.25px
421 | 940.5px
422 | 942.75px
423 | 945px
424 | 947.25px
425 | 949.5px
426 | 951.75px
427 | 954px
428 | 956.25px
429 | 958.5px
430 | 960.75px
431 | 963px
432 | 965.25px
433 | 967.5px
434 | 969.75px
435 | 972px
436 | 974.25px
437 | 976.5px
438 | 978.75px
439 | 981px
440 | 983.25px
441 | 985.5px
442 | 987.75px
443 | 990px
444 | 992.25px
445 | 994.5px
446 | 996.75px
447 | 999px
448 | 1001.25px
449 | 1003.5px
450 | 1005.75px
451 | 1008px
452 | 1010.25px
453 | 1012.5px
454 | 1014.75px
455 | 1017px
456 | 1019.25px
457 | 1021.5px
458 | 1023.75px
459 | 1026px
460 | 1028.25px
461 | 1030.5px
462 | 1032.75px
463 | 1035px
464 | 1037.25px
465 | 1039.5px
466 | 1041.75px
467 | 1044px
468 | 1046.25px
469 | 1048.5px
470 | 1050.75px
471 | 1053px
472 | 1055.25px
473 | 1057.5px
474 | 1059.75px
475 | 1062px
476 | 1064.25px
477 | 1066.5px
478 | 1068.75px
479 | 1071px
480 | 1073.25px
481 | 1075.5px
482 | 1077.75px
483 | 1080px
484 | 1082.25px
485 | 1084.5px
486 | 1086.75px
487 | 1089px
488 | 1091.25px
489 | 1093.5px
490 | 1095.75px
491 | 1098px
492 | 1100.25px
493 | 1102.5px
494 | 1104.75px
495 | 1107px
496 | 1109.25px
497 | 1111.5px
498 | 1113.75px
499 | 1116px
500 | 1118.25px
501 | 1120.5px
502 | 1122.75px
503 | 1125px
504 | 1127.25px
505 | 1129.5px
506 | 1131.75px
507 | 1134px
508 | 1136.25px
509 | 1138.5px
510 | 1140.75px
511 | 1143px
512 | 1145.25px
513 | 1147.5px
514 | 1149.75px
515 | 1152px
516 | 1154.25px
517 | 1156.5px
518 | 1158.75px
519 | 1161px
520 | 1163.25px
521 | 1165.5px
522 | 1167.75px
523 | 1170px
524 | 1172.25px
525 | 1174.5px
526 | 1176.75px
527 | 1179px
528 | 1181.25px
529 | 1183.5px
530 | 1185.75px
531 | 1188px
532 | 1190.25px
533 | 1192.5px
534 | 1194.75px
535 | 1197px
536 | 1199.25px
537 | 1201.5px
538 | 1203.75px
539 | 1206px
540 | 1208.25px
541 | 1210.5px
542 | 1212.75px
543 | 1215px
544 | 1217.25px
545 | 1219.5px
546 | 1221.75px
547 | 1224px
548 | 1226.25px
549 | 1228.5px
550 | 1230.75px
551 | 1233px
552 | 1235.25px
553 | 1237.5px
554 | 1239.75px
555 | 1242px
556 | 1244.25px
557 | 1246.5px
558 | 1248.75px
559 | 1251px
560 | 1253.25px
561 | 1255.5px
562 | 1257.75px
563 | 1260px
564 | 1262.25px
565 | 1264.5px
566 | 1266.75px
567 | 1269px
568 | 1271.25px
569 | 1273.5px
570 | 1275.75px
571 | 1278px
572 | 1280.25px
573 | 1282.5px
574 | 1284.75px
575 | 1287px
576 | 1289.25px
577 | 1291.5px
578 | 1293.75px
579 | 1296px
580 | 1298.25px
581 | 1300.5px
582 | 1302.75px
583 | 1305px
584 | 1307.25px
585 | 1309.5px
586 | 1311.75px
587 | 1314px
588 | 1316.25px
589 | 1318.5px
590 | 1320.75px
591 | 1323px
592 | 1325.25px
593 | 1327.5px
594 | 1329.75px
595 | 1332px
596 | 1334.25px
597 | 1336.5px
598 | 1338.75px
599 | 1341px
600 | 1343.25px
601 | 1345.5px
602 | 1347.75px
603 |
604 | 16dp
605 | 16dp
606 |
607 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BaseAndroid
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/luo/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package luo.myapplication;
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() throws Exception {
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 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group = 'com.github.LuoGuoXin'
4 |
5 | android {
6 | compileSdkVersion 24
7 | buildToolsVersion "24.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 24
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile 'org.xutils:xutils:3.3.42'
28 | compile 'com.github.bumptech.glide:glide:3.7.0'
29 | compile 'com.google.code.gson:gson:2.8.0'
30 | compile 'com.android.support:support-fragment:24.2.1'
31 | compile 'com.android.support:appcompat-v7:24.2.1'
32 | }
33 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/luo/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package luo.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("luo.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.pm.ActivityInfo;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.view.Window;
11 | import android.view.WindowManager;
12 | import android.view.inputmethod.InputMethodManager;
13 | import android.widget.EditText;
14 | import android.widget.ImageView;
15 | import android.widget.LinearLayout;
16 | import android.widget.RelativeLayout;
17 | import android.widget.TextView;
18 | import android.widget.Toast;
19 |
20 | import org.xutils.x;
21 |
22 | import luo.library.R;
23 | import luo.library.base.utils.SpUtils;
24 | import luo.library.base.widget.LoadingDialog;
25 |
26 |
27 | public class BaseActivity extends AppCompatActivity {
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
33 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
34 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
35 | requestWindowFeature(Window.FEATURE_NO_TITLE);
36 | getSupportActionBar().hide();
37 | x.view().inject(this);
38 | }
39 |
40 | /**
41 | * 开启浮动加载进度条
42 | */
43 | public void startProgressDialog() {
44 | LoadingDialog.showDialogForLoading(this);
45 | }
46 |
47 | /**
48 | * 开启浮动加载进度条Gif
49 | */
50 | public void startGifProgressDialog() {
51 | LoadingDialog.showDialogForLoadingGif(this);
52 | }
53 |
54 | /**
55 | * 开启浮动加载进度条
56 | *
57 | * @param msg
58 | */
59 | public void startProgressDialog(String msg) {
60 | LoadingDialog.showDialogForLoading(this, msg, true);
61 | }
62 |
63 | /**
64 | * 停止浮动加载进度条
65 | */
66 | public void stopProgressDialog() {
67 | LoadingDialog.cancelDialogForLoading();
68 | }
69 |
70 | /**
71 | * 设置标题栏信息
72 | */
73 | public void setTitleText(String string) {
74 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
75 | relativeLayout.setBackgroundResource(BaseAndroid.getBaseConfig().getAppColor());
76 | LinearLayout backTv = (LinearLayout) findViewById(R.id.ly_base_back);
77 | backTv.setOnClickListener(new View.OnClickListener() {
78 |
79 | @Override
80 | public void onClick(View arg0) {
81 | finish();
82 | }
83 | });
84 | TextView titleTv = (TextView) findViewById(R.id.tv_base_titleText);
85 | titleTv.setText(string);
86 | }
87 |
88 | /**
89 | * 隐藏输入法
90 | */
91 | public void hideInput() {
92 | InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
93 | inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); //隐藏
94 | }
95 |
96 | /**
97 | * 隐藏后退
98 | */
99 | public void hideBack() {
100 | LinearLayout backTv = (LinearLayout) findViewById(R.id.ly_base_back);
101 | backTv.setVisibility(View.INVISIBLE);
102 | }
103 |
104 | /**
105 | * 设置标题栏右边按钮文字
106 | */
107 | public void setRightButtonText(String string, View.OnClickListener onClickListener) {
108 | TextView editTv = (TextView) findViewById(R.id.tv_base_edit);
109 | editTv.setVisibility(View.VISIBLE);
110 | editTv.setText(string);
111 | editTv.setOnClickListener(onClickListener);
112 | }
113 |
114 | /**
115 | * 设置右边图片
116 | */
117 | public void setRightImg(int bg, View.OnClickListener onClickListener) {
118 | ImageView imageView = (ImageView) findViewById(R.id.iv_right);
119 | imageView.setImageResource(bg);
120 | imageView.setOnClickListener(onClickListener);
121 | }
122 |
123 | /**
124 | * 标题栏背景设为透明
125 | */
126 | public void setBgNul() {
127 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
128 | relativeLayout.setBackgroundColor(Color.parseColor("#00000000"));
129 | }
130 |
131 | /**
132 | * 标题栏背景
133 | */
134 | public void setTitleViewBg(int bg) {
135 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
136 | relativeLayout.setBackgroundResource(bg);
137 | }
138 |
139 | /**
140 | * 弹出Toast
141 | */
142 | public void showToast(String string) {
143 | Toast.makeText(BaseActivity.this, string, Toast.LENGTH_SHORT).show();
144 | }
145 |
146 | /**
147 | * 获取EditView的文字
148 | */
149 | public String getStr(EditText editText) {
150 | return editText.getText().toString().trim();
151 | }
152 |
153 | /**
154 | * 获取TextView的文字
155 | */
156 | public String getStr(TextView textView) {
157 | return textView.getText().toString();
158 | }
159 |
160 | /**
161 | * 获取string的文字
162 | */
163 | public String getStr(int id) {
164 | return getResources().getString(id);
165 | }
166 |
167 | /**
168 | * 检查字符串是否是空对象或空字符串
169 | */
170 | public boolean isNull(String str) {
171 | if (null == str || "".equals(str) || "null".equalsIgnoreCase(str)) {
172 | return true;
173 | } else {
174 | return false;
175 | }
176 | }
177 |
178 | /**
179 | * 检查EditView是否是空对象或空字符串
180 | */
181 | public boolean isNull(EditText str) {
182 | if (null == str.getText().toString() || "".equals(str.getText().toString())
183 | || "null".equalsIgnoreCase(str.getText().toString())) {
184 | return true;
185 | } else {
186 | return false;
187 | }
188 | }
189 |
190 | /**
191 | * 检查TextView是否是空对象或空字符串
192 | */
193 | public boolean isNull(TextView str) {
194 | if (null == str.getText().toString() || "".equals(str.getText().toString())
195 | || "null".equalsIgnoreCase(str.getText().toString())) {
196 | return true;
197 | } else {
198 | return false;
199 | }
200 | }
201 |
202 |
203 | /**
204 | * 启动Activity
205 | */
206 | public void openActivity(Class> cls) {
207 | Intent intent = new Intent(this, cls);
208 | startActivity(intent);
209 | }
210 |
211 | /**
212 | * 保存sp数据
213 | *
214 | * @param key
215 | * @param object
216 | */
217 | public void putSp(String key, Object object) {
218 | SpUtils.put(BaseActivity.this, key, object);
219 | }
220 |
221 | /**
222 | * 清除Sp数据
223 | */
224 | public void clearSp() {
225 | SpUtils.clear(BaseActivity.this);
226 | }
227 |
228 | /**
229 | * 获取sp数据
230 | *
231 | * @param key
232 | * @param object
233 | * @return
234 | */
235 | public Object getSp(String key, Object object) {
236 | return SpUtils.get(BaseActivity.this, key, object);
237 | }
238 |
239 |
240 | }
241 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseAndroid.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 | import android.text.TextUtils;
6 |
7 | import java.io.File;
8 |
9 | import luo.library.base.utils.UpdateManager;
10 |
11 | /**
12 | *
13 | */
14 |
15 | public class BaseAndroid {
16 | public static BaseConfig baseConfig;
17 |
18 | public static void init(BaseConfig config) {
19 | baseConfig = config;
20 | }
21 |
22 | public static BaseConfig getBaseConfig() {
23 | if (baseConfig == null) {
24 | throw new IllegalArgumentException("请先调用init方法");
25 | }
26 | return baseConfig;
27 | }
28 |
29 | /**
30 | * 版本更新
31 | *
32 | * @param context
33 | * @param versionCode 版本号
34 | * @param url apk下载地址
35 | * @param updateMessage 更新内容
36 | * @param isForced 是否强制更新
37 | */
38 | public static void checkUpdate(Context context, int versionCode, String url, String updateMessage, boolean isForced) {
39 | if (versionCode > UpdateManager.getInstance().getVersionCode(context)) {
40 | int type = 0;//更新方式,0:引导更新,1:安装更新,2:强制更新
41 | if (UpdateManager.getInstance().isWifi(context)) {
42 | type = 1;
43 | }
44 | if (isForced) {
45 | type = 2;
46 | }
47 |
48 | //检测是否已下载
49 | String downLoadPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/";
50 | File dir = new File(downLoadPath);
51 | if (!dir.exists()) {
52 | dir.mkdir();
53 | }
54 | String fileName = url.substring(url.lastIndexOf("/") + 1, url.length());
55 | if (fileName == null && TextUtils.isEmpty(fileName) && !fileName.contains(".apk")) {
56 | fileName = context.getPackageName() + ".apk";
57 | }
58 | File file = new File(downLoadPath + fileName);
59 |
60 | //设置参数
61 | UpdateManager.getInstance().setType(type).setUrl(url).setUpdateMessage(updateMessage).setFileName(fileName).setIsDownload(file.exists());
62 | if (type == 1 && !file.exists()) {
63 | UpdateManager.getInstance().downloadFile(context);
64 | } else {
65 | UpdateManager.getInstance().showDialog(context);
66 | }
67 | }
68 |
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseConfig.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import luo.library.R;
4 |
5 | /**
6 | * 信息配置
7 | */
8 |
9 | public class BaseConfig {
10 | /**
11 | * app主颜色
12 | */
13 | private int appColor = R.color.base;
14 | /**
15 | * 加载框的gif图
16 | */
17 | private int loadingView = 0;
18 | /**
19 | * 网络请求成功返回的code码
20 | */
21 | private int code = 1;
22 | /**
23 | * 网络请求返回的code
24 | */
25 | private String httpCode = "code";
26 | /**
27 | * 网络请求返回的message
28 | */
29 | private String httpMessage = "message";
30 | /**
31 | * 网络请求返回的result
32 | */
33 | private String httpResult = "result";
34 | /**
35 | * APP图标
36 | */
37 | private int appLogo = R.drawable.ic_empty;
38 | /**
39 | * 图片加载中和加载失败显示的图
40 | */
41 | private int failPicture = R.drawable.ic_empty;
42 |
43 | public int getLoadingView() {
44 | return loadingView;
45 | }
46 |
47 | public BaseConfig setLoadingView(int loadingView) {
48 | this.loadingView = loadingView;
49 | return this;
50 | }
51 |
52 | public int getAppColor() {
53 | return appColor;
54 | }
55 |
56 | public BaseConfig setAppColor(int appColor) {
57 | this.appColor = appColor;
58 | return this;
59 | }
60 |
61 | public int getAppLogo() {
62 | return appLogo;
63 | }
64 |
65 | public BaseConfig setAppLogo(int appLogo) {
66 | this.appLogo = appLogo;
67 | return this;
68 | }
69 |
70 | public int getFailPicture() {
71 | return failPicture;
72 | }
73 |
74 | public BaseConfig setFailPicture(int failPicture) {
75 | this.failPicture = failPicture;
76 | return this;
77 | }
78 |
79 | public int getCode() {
80 | return code;
81 | }
82 |
83 | public BaseConfig setCode(int code) {
84 | this.code = code;
85 | return this;
86 | }
87 |
88 | public String getHttpCode() {
89 | return httpCode;
90 | }
91 |
92 | public BaseConfig setHttpCode(String httpCode) {
93 | this.httpCode = httpCode;
94 | return this;
95 | }
96 |
97 | public String getHttpMessage() {
98 | return httpMessage;
99 | }
100 |
101 | public BaseConfig setHttpMessage(String httpMessage) {
102 | this.httpMessage = httpMessage;
103 | return this;
104 | }
105 |
106 | public String getHttpResult() {
107 | return httpResult;
108 | }
109 |
110 | public BaseConfig setHttpResult(String httpResult) {
111 | this.httpResult = httpResult;
112 | return this;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseDb.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import org.xutils.DbManager;
4 | import org.xutils.ex.DbException;
5 | import org.xutils.x;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * 数据库操作
12 | */
13 |
14 | public class BaseDb {
15 | public static DbManager db;
16 |
17 | /**
18 | * 本地数据的初始化
19 | */
20 | public static void initDb() {
21 | DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
22 | .setDbName("xutils3_db") //设置数据库名
23 | .setDbVersion(1) //设置数据库版本
24 | .setDbOpenListener(new DbManager.DbOpenListener() {
25 | @Override
26 | public void onDbOpened(DbManager db) {
27 | db.getDatabase().enableWriteAheadLogging();
28 | //开启WAL, 对写入加速提升巨大(作者原话)
29 | }
30 | })
31 | .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
32 | @Override
33 | public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
34 | //数据库升级操作
35 | }
36 | });
37 | db = x.getDb(daoConfig);
38 | }
39 |
40 | /**
41 | * 添加数据
42 | */
43 | public static boolean add(Object entity) {
44 | try {
45 | db.save(entity);
46 | return true;
47 | } catch (DbException e) {
48 | e.printStackTrace();
49 | return false;
50 | }
51 | }
52 |
53 | /**
54 | * 删除数据
55 | */
56 | public static boolean delete(Object entity) {
57 | try {
58 | db.delete(entity);
59 | return true;
60 | } catch (DbException e) {
61 | e.printStackTrace();
62 | return false;
63 | }
64 | }
65 |
66 | /**
67 | * 修改数据
68 | */
69 | public static boolean update(Object entity) {
70 | try {
71 | db.update(entity);
72 | return true;
73 | } catch (DbException e) {
74 | e.printStackTrace();
75 | return false;
76 | }
77 | }
78 |
79 | /**
80 | * 查找数据
81 | */
82 | public static List find(Class cls) {
83 | List list = new ArrayList<>();
84 | try {
85 | list = db.findAll(cls);
86 | } catch (DbException e) {
87 | e.printStackTrace();
88 | }
89 | return list;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.EditText;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import org.xutils.x;
14 |
15 | import luo.library.base.utils.SpUtils;
16 | import luo.library.base.widget.LoadingDialog;
17 |
18 |
19 | public class BaseFragment extends Fragment {
20 |
21 | private boolean injected = false;
22 |
23 | @Override
24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
25 | injected = true;
26 | return x.view().inject(this, inflater, container);
27 | }
28 |
29 | @Override
30 | public void onViewCreated(View view, Bundle savedInstanceState) {
31 | super.onViewCreated(view, savedInstanceState);
32 | if (!injected) {
33 | x.view().inject(this, this.getView());
34 | }
35 | }
36 |
37 | /**
38 | * 开启浮动加载进度条
39 | */
40 | public void startProgressDialog() {
41 | LoadingDialog.showDialogForLoading(getActivity());
42 | }
43 |
44 | /**
45 | * 开启浮动加载进度条Gif
46 | */
47 | public void startGifProgressDialog() {
48 | LoadingDialog.showDialogForLoadingGif(getActivity());
49 | }
50 |
51 | /**
52 | * 开启浮动加载进度条
53 | *
54 | * @param msg
55 | */
56 | public void startProgressDialog(String msg) {
57 | LoadingDialog.showDialogForLoading(getActivity(), msg, true);
58 | }
59 |
60 | /**
61 | * 停止浮动加载进度条
62 | */
63 | public void stopProgressDialog() {
64 | LoadingDialog.cancelDialogForLoading();
65 | }
66 |
67 | /**
68 | * 弹出Toast
69 | */
70 | public void showToast(String string) {
71 | Toast.makeText(getActivity(), string, Toast.LENGTH_SHORT).show();
72 | }
73 |
74 | /**
75 | * 获取EditView的文字
76 | */
77 | public String getStr(EditText editText) {
78 | return editText.getText().toString().trim();
79 | }
80 |
81 | /**
82 | * 获取TextView的文字
83 | */
84 | public String getStr(TextView textView) {
85 | return textView.getText().toString();
86 | }
87 |
88 | /**
89 | * 获取string的文字
90 | */
91 | public String getStr(int id) {
92 | return getResources().getString(id);
93 | }
94 |
95 | /**
96 | * 检查字符串是否是空对象或空字符串
97 | */
98 | public boolean isNull(String str) {
99 | if (null == str || "".equals(str) || "null".equalsIgnoreCase(str)) {
100 | return true;
101 | } else {
102 | return false;
103 | }
104 | }
105 |
106 | /**
107 | * 检查EditView是否是空对象或空字符串
108 | */
109 | public boolean isNull(EditText str) {
110 | if (null == str.getText().toString() || "".equals(str.getText().toString())
111 | || "null".equalsIgnoreCase(str.getText().toString())) {
112 | return true;
113 | } else {
114 | return false;
115 | }
116 | }
117 |
118 | /**
119 | * 检查TextView是否是空对象或空字符串
120 | */
121 | public boolean isNull(TextView str) {
122 | if (null == str.getText().toString() || "".equals(str.getText().toString())
123 | || "null".equalsIgnoreCase(str.getText().toString())) {
124 | return true;
125 | } else {
126 | return false;
127 | }
128 | }
129 |
130 |
131 | /**
132 | * 启动Activity
133 | */
134 | public void openActivity(Class> cls) {
135 | Intent intent = new Intent(getActivity(), cls);
136 | startActivity(intent);
137 | }
138 |
139 | /**
140 | * 保存sp数据
141 | *
142 | * @param key
143 | * @param object
144 | */
145 | public void putSp(String key, Object object) {
146 | SpUtils.put(getActivity(), key, object);
147 | }
148 |
149 | /**
150 | * 清除Sp数据
151 | */
152 | public void clearSp() {
153 | SpUtils.clear(getActivity());
154 | }
155 |
156 | /**
157 | * 获取sp数据
158 | *
159 | * @param key
160 | * @param object
161 | * @return
162 | */
163 | public Object getSp(String key, Object object) {
164 | return SpUtils.get(getActivity(), key, object);
165 | }
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Intent;
4 | import android.content.pm.ActivityInfo;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.view.View;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 | import android.widget.EditText;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.RelativeLayout;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import org.xutils.x;
19 |
20 | import luo.library.R;
21 | import luo.library.base.utils.SpUtils;
22 | import luo.library.base.widget.LoadingDialog;
23 |
24 |
25 | public class BaseFragmentActivity extends FragmentActivity {
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
31 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
32 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
33 | requestWindowFeature(Window.FEATURE_NO_TITLE);
34 | x.view().inject(this);
35 | }
36 |
37 | /**
38 | * 开启浮动加载进度条
39 | */
40 | public void startProgressDialog() {
41 | LoadingDialog.showDialogForLoading(this);
42 | }
43 |
44 | /**
45 | * 开启浮动加载进度条Gif
46 | */
47 | public void startGifProgressDialog() {
48 | LoadingDialog.showDialogForLoadingGif(this);
49 | }
50 |
51 | /**
52 | * 开启浮动加载进度条
53 | *
54 | * @param msg
55 | */
56 | public void startProgressDialog(String msg) {
57 | LoadingDialog.showDialogForLoading(this, msg, true);
58 | }
59 |
60 | /**
61 | * 停止浮动加载进度条
62 | */
63 | public void stopProgressDialog() {
64 | LoadingDialog.cancelDialogForLoading();
65 | }
66 |
67 | /**
68 | * 设置标题栏信息
69 | */
70 | public void setTitleText(String string) {
71 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
72 | relativeLayout.setBackgroundResource(BaseAndroid.getBaseConfig().getAppColor());
73 | LinearLayout backTv = (LinearLayout) findViewById(R.id.ly_base_back);
74 | backTv.setOnClickListener(new View.OnClickListener() {
75 |
76 | @Override
77 | public void onClick(View arg0) {
78 | finish();
79 | }
80 | });
81 | TextView titleTv = (TextView) findViewById(R.id.tv_base_titleText);
82 | titleTv.setText(string);
83 | }
84 |
85 | /**
86 | * 隐藏后退
87 | */
88 | public void hideBack() {
89 | LinearLayout backTv = (LinearLayout) findViewById(R.id.ly_base_back);
90 | backTv.setVisibility(View.INVISIBLE);
91 | }
92 |
93 | /**
94 | * 设置标题栏右边按钮文字
95 | */
96 | public void setRightButtonText(String string, View.OnClickListener onClickListener) {
97 | TextView editTv = (TextView) findViewById(R.id.tv_base_edit);
98 | editTv.setVisibility(View.VISIBLE);
99 | editTv.setText(string);
100 | editTv.setOnClickListener(onClickListener);
101 | }
102 |
103 | /**
104 | * 设置右边图片
105 | */
106 | public void setRightImg(int bg, View.OnClickListener onClickListener) {
107 | ImageView imageView = (ImageView) findViewById(R.id.iv_right);
108 | imageView.setImageResource(bg);
109 | imageView.setOnClickListener(onClickListener);
110 | }
111 |
112 | /**
113 | * 标题栏背景设为透明
114 | */
115 | public void setBgNul() {
116 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
117 | relativeLayout.setBackgroundColor(Color.parseColor("#00000000"));
118 | }
119 |
120 | /**
121 | * 标题栏背景
122 | */
123 | public void setTitleViewBg(int bg) {
124 | RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.lay_bg);
125 | relativeLayout.setBackgroundResource(bg);
126 | }
127 |
128 | /**
129 | * 弹出Toast
130 | */
131 | public void showToast(String string) {
132 | Toast.makeText(BaseFragmentActivity.this, string, Toast.LENGTH_SHORT).show();
133 | }
134 |
135 | /**
136 | * 获取EditView的文字
137 | */
138 | public String getStr(EditText editText) {
139 | return editText.getText().toString().trim();
140 | }
141 |
142 | /**
143 | * 获取TextView的文字
144 | */
145 | public String getStr(TextView textView) {
146 | return textView.getText().toString();
147 | }
148 |
149 | /**
150 | * 获取string的文字
151 | */
152 | public String getStr(int id) {
153 | return getResources().getString(id);
154 | }
155 |
156 | /**
157 | * 检查字符串是否是空对象或空字符串
158 | */
159 | public boolean isNull(String str) {
160 | if (null == str || "".equals(str) || "null".equalsIgnoreCase(str)) {
161 | return true;
162 | } else {
163 | return false;
164 | }
165 | }
166 |
167 | /**
168 | * 检查EditView是否是空对象或空字符串
169 | */
170 | public boolean isNull(EditText str) {
171 | if (null == str.getText().toString() || "".equals(str.getText().toString())
172 | || "null".equalsIgnoreCase(str.getText().toString())) {
173 | return true;
174 | } else {
175 | return false;
176 | }
177 | }
178 |
179 | /**
180 | * 检查TextView是否是空对象或空字符串
181 | */
182 | public boolean isNull(TextView str) {
183 | if (null == str.getText().toString() || "".equals(str.getText().toString())
184 | || "null".equalsIgnoreCase(str.getText().toString())) {
185 | return true;
186 | } else {
187 | return false;
188 | }
189 | }
190 |
191 |
192 | /**
193 | * 启动Activity
194 | */
195 | public void openActivity(Class> cls) {
196 | Intent intent = new Intent(this, cls);
197 | startActivity(intent);
198 | }
199 |
200 | /**
201 | * 保存sp数据
202 | *
203 | * @param key
204 | * @param object
205 | */
206 | public void putSp(String key, Object object) {
207 | SpUtils.put(BaseFragmentActivity.this, key, object);
208 | }
209 |
210 | /**
211 | * 清除Sp数据
212 | */
213 | public void clearSp() {
214 | SpUtils.clear(BaseFragmentActivity.this);
215 | }
216 |
217 | /**
218 | * 获取sp数据
219 | *
220 | * @param key
221 | * @param object
222 | * @return
223 | */
224 | public Object getSp(String key, Object object) {
225 | return SpUtils.get(BaseFragmentActivity.this, key, object);
226 | }
227 |
228 |
229 | }
230 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseHttp.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 | import org.xutils.common.Callback;
9 | import org.xutils.http.HttpMethod;
10 | import org.xutils.http.RequestParams;
11 | import org.xutils.x;
12 |
13 | import java.io.InputStream;
14 | import java.security.KeyStore;
15 |
16 | import javax.net.ssl.KeyManagerFactory;
17 | import javax.net.ssl.SSLContext;
18 | import javax.net.ssl.SSLSocketFactory;
19 | import javax.net.ssl.TrustManagerFactory;
20 |
21 | /**
22 | * xutils3 网络请求封装
23 | */
24 |
25 | public class BaseHttp {
26 |
27 | private BaseHttp() {
28 |
29 | }
30 |
31 | public static void get(RequestParams params, BaseHttpCallback baseHttpCallback) {
32 | sendRequest(HttpMethod.GET, params, baseHttpCallback);
33 | }
34 |
35 | public static void get(Context context, RequestParams params, BaseHttpCallback baseHttpCallback) {
36 | sendRequest(context, HttpMethod.GET, params, baseHttpCallback);
37 | }
38 |
39 | public static void post(RequestParams params, BaseHttpCallback baseHttpCallback) {
40 | sendRequest(HttpMethod.POST, params, baseHttpCallback);
41 | }
42 |
43 | public static void post(Context context, RequestParams params, BaseHttpCallback baseHttpCallback) {
44 | sendRequest(context, HttpMethod.POST, params, baseHttpCallback);
45 | }
46 |
47 | public static void sendRequest(Context context, HttpMethod httpMethod, final RequestParams params, final BaseHttpCallback baseHttpCallback) {
48 | params.setSslSocketFactory(getSSLCertifcation(context));
49 | sendRequest(httpMethod, params, baseHttpCallback);
50 | }
51 |
52 | public static void sendRequest(HttpMethod httpMethod, final RequestParams params, final BaseHttpCallback baseHttpCallback) {
53 |
54 | x.http().request(httpMethod, params, new Callback.CommonCallback() {
55 | @Override
56 | public void onSuccess(String result) {
57 | String url[] = params.getUri().split("/");
58 | Log.i(url[url.length - 1], result);
59 | try {
60 | JSONObject jsonObject = new JSONObject(result);
61 | int code = jsonObject.getInt(BaseAndroid.getBaseConfig().getHttpCode());
62 | if (code == BaseAndroid.getBaseConfig().getCode()) {
63 | if (jsonObject.has(BaseAndroid.getBaseConfig().getHttpResult())) {
64 | baseHttpCallback.onSuccess(jsonObject.getString(BaseAndroid.getBaseConfig().getHttpResult()));
65 | } else {
66 | baseHttpCallback.onSuccess("");
67 | }
68 | } else {
69 | baseHttpCallback.onError(code, jsonObject.getString(BaseAndroid.getBaseConfig().getHttpMessage()));
70 | }
71 | } catch (JSONException e) {
72 | e.printStackTrace();
73 | }
74 | }
75 |
76 | @Override
77 | public void onError(Throwable ex, boolean isOnCallback) {
78 | baseHttpCallback.onError(-1, ex.getMessage());
79 | }
80 |
81 | @Override
82 | public void onCancelled(CancelledException cex) {
83 |
84 | }
85 |
86 | @Override
87 | public void onFinished() {
88 |
89 | }
90 | });
91 | }
92 |
93 | public interface BaseHttpCallback {
94 | void onSuccess(String result);
95 |
96 | void onError(int code, String message);
97 | }
98 |
99 |
100 | private final static String CLIENT_PRI_KEY = "client.bks";
101 | private final static String TRUSTSTORE_PUB_KEY = "truststore.bks";
102 | private final static String CLIENT_BKS_PASSWORD = "123456";
103 | private final static String TRUSTSTORE_BKS_PASSWORD = "123456";
104 | private final static String KEYSTORE_TYPE = "BKS";
105 | private final static String PROTOCOL_TYPE = "TLS";
106 | private final static String CERTIFICATE_FORMAT = "X509";
107 |
108 | public static SSLSocketFactory getSSLCertifcation(Context context) {
109 | SSLSocketFactory sslSocketFactory = null;
110 | try {
111 | // 服务器端需要验证的客户端证书,其实就是客户端的keystore
112 | KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE);// 客户端信任的服务器端证书
113 | KeyStore trustStore = KeyStore.getInstance(KEYSTORE_TYPE);//读取证书
114 | InputStream ksIn = context.getAssets().open(CLIENT_PRI_KEY);
115 | InputStream tsIn = context.getAssets().open(TRUSTSTORE_PUB_KEY);//加载证书
116 | keyStore.load(ksIn, CLIENT_BKS_PASSWORD.toCharArray());
117 | trustStore.load(tsIn, TRUSTSTORE_BKS_PASSWORD.toCharArray());
118 | ksIn.close();
119 | tsIn.close();
120 | //初始化SSLContext
121 | SSLContext sslContext = SSLContext.getInstance(PROTOCOL_TYPE);
122 | TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(CERTIFICATE_FORMAT);
123 | KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(CERTIFICATE_FORMAT);
124 | trustManagerFactory.init(trustStore);
125 | keyManagerFactory.init(keyStore, CLIENT_BKS_PASSWORD.toCharArray());
126 | sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
127 | sslSocketFactory = sslContext.getSocketFactory();
128 | } catch (Exception e) {
129 | e.printStackTrace();
130 | }
131 | return sslSocketFactory;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseImage.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.RectF;
10 | import android.net.Uri;
11 | import android.widget.ImageView;
12 |
13 | import com.bumptech.glide.Glide;
14 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
15 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
16 |
17 | import java.io.File;
18 |
19 | /**
20 | * 基本功能:图片加载工具
21 | */
22 | public class BaseImage {
23 |
24 | public static final String ANDROID_RESOURCE = "android.resource://";
25 | public static final String FOREWARD_SLASH = "/";
26 |
27 | private static class ImageLoaderHolder {
28 | private static final BaseImage INSTANCE = new BaseImage();
29 | }
30 |
31 | private BaseImage() {
32 | }
33 |
34 | public static final BaseImage getInstance() {
35 | return ImageLoaderHolder.INSTANCE;
36 | }
37 |
38 |
39 | //直接加载网络图片
40 | public void displayImage(Context context, String url, ImageView imageView) {
41 | Glide.with(context)
42 | .load(url)
43 | .centerCrop()
44 | .placeholder(BaseAndroid.getBaseConfig().getFailPicture())
45 | .error(BaseAndroid.getBaseConfig().getFailPicture())
46 | .crossFade()
47 | .thumbnail(0.1f)
48 | .into(imageView);
49 | }
50 |
51 | //加载SD卡图片
52 | public void displayImage(Context context, File file, ImageView imageView) {
53 | Glide.with(context)
54 | .load(file)
55 | .centerCrop()
56 | .crossFade()
57 | .into(imageView);
58 | }
59 |
60 | //加载SD卡图片并设置大小
61 | public void displayImage(Context context, File file, ImageView imageView, int width, int height) {
62 | Glide.with(context)
63 | .load(file)
64 | .override(width, height)
65 | .centerCrop()
66 | .into(imageView);
67 | }
68 |
69 | //加载网络图片并设置大小
70 | public void displayImage(Context context, String url, ImageView imageView, int width, int height) {
71 | Glide.with(context)
72 | .load(url)
73 | .centerCrop()
74 | .thumbnail(0.1f)
75 | .override(width, height)
76 | .crossFade()
77 | .into(imageView);
78 | }
79 |
80 | //加载drawable图片
81 | public void displayImage(Context context, int resId, ImageView imageView) {
82 | Glide.with(context)
83 | .load(resourceIdToUri(context, resId))
84 | .crossFade()
85 | .into(imageView);
86 | }
87 |
88 | //加载drawable图片显示为圆形图片
89 | public void displayCricleImage(Context context, int resId, ImageView imageView) {
90 | Glide.with(context)
91 | .load(resourceIdToUri(context, resId))
92 | .crossFade()
93 | .placeholder(BaseAndroid.getBaseConfig().getFailPicture())
94 | .error(BaseAndroid.getBaseConfig().getFailPicture())
95 | .transform(new GlideCircleTransform(context))
96 | .into(imageView);
97 | }
98 |
99 | //加载网络图片显示为圆形图片
100 | public void displayCricleImage(Context context, String url, ImageView imageView) {
101 | Glide.with(context)
102 | .load(url)
103 | //.centerCrop()//网友反馈,设置此属性可能不起作用,在有些设备上可能会不能显示为圆形。
104 | .thumbnail(0.1f)
105 | .placeholder(BaseAndroid.getBaseConfig().getFailPicture())
106 | .error(BaseAndroid.getBaseConfig().getFailPicture())
107 | .transform(new GlideCircleTransform(context))
108 | .crossFade()
109 | .into(imageView);
110 | }
111 |
112 | //加载SD卡图片显示为圆形图片
113 | public void displayCricleImage(Context context, File file, ImageView imageView) {
114 | Glide.with(context)
115 | .load(file)
116 | //.centerCrop()
117 | .transform(new GlideCircleTransform(context))
118 | .into(imageView);
119 | }
120 |
121 | //加载网络图片显示为圆角图片
122 | public void displayRoundImage(Context context, String url, ImageView imageView) {
123 | Glide.with(context)
124 | .load(url)
125 | //.centerCrop()
126 | .thumbnail(0.1f)
127 | .placeholder(BaseAndroid.getBaseConfig().getFailPicture())
128 | .error(BaseAndroid.getBaseConfig().getFailPicture())
129 | .transform(new GlideRoundTransform(context))
130 | .crossFade()
131 | .into(imageView);
132 | }
133 |
134 | //将资源ID转为Uri
135 | public Uri resourceIdToUri(Context context, int resourceId) {
136 | return Uri.parse(ANDROID_RESOURCE + context.getPackageName() + FOREWARD_SLASH + resourceId);
137 | }
138 |
139 | //基本功能:Glide显示为圆形图片
140 | public class GlideCircleTransform extends BitmapTransformation {
141 |
142 | public GlideCircleTransform(Context context) {
143 | super(context);
144 | }
145 |
146 | @Override
147 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
148 | return circleCrop(pool, toTransform);
149 | }
150 |
151 | private Bitmap circleCrop(BitmapPool pool, Bitmap source) {
152 | if (source == null) return null;
153 |
154 | int size = Math.min(source.getWidth(), source.getHeight());
155 | int x = (source.getWidth() - size) / 2;
156 | int y = (source.getHeight() - size) / 2;
157 |
158 | Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
159 |
160 | Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
161 | if (result == null) {
162 | result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
163 | }
164 |
165 | Canvas canvas = new Canvas(result);
166 | Paint paint = new Paint();
167 | paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
168 | paint.setAntiAlias(true);
169 | float r = size / 2f;
170 | canvas.drawCircle(r, r, r, paint);
171 | return result;
172 | }
173 |
174 | @Override
175 | public String getId() {
176 | return getClass().getName();
177 | }
178 | }
179 |
180 | //基本功能:Glide显示为圆角图片
181 | public class GlideRoundTransform extends BitmapTransformation {
182 |
183 | private float radius = 0f;
184 |
185 | public GlideRoundTransform(Context context) {
186 | this(context, 4);
187 | }
188 |
189 | public GlideRoundTransform(Context context, int dp) {
190 | super(context);
191 | this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
192 | }
193 |
194 | @Override
195 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
196 | return roundCrop(pool, toTransform);
197 | }
198 |
199 | private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
200 | if (source == null) return null;
201 |
202 | Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
203 | if (result == null) {
204 | result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
205 | }
206 |
207 | Canvas canvas = new Canvas(result);
208 | Paint paint = new Paint();
209 | paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
210 | paint.setAntiAlias(true);
211 | RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
212 | canvas.drawRoundRect(rectF, radius, radius, paint);
213 | return result;
214 | }
215 |
216 | @Override
217 | public String getId() {
218 | return getClass().getName() + Math.round(radius);
219 | }
220 | }
221 |
222 | }
223 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/base/BaseWebViewActivity.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.base;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.os.Message;
6 | import android.view.KeyEvent;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.webkit.GeolocationPermissions;
10 | import android.webkit.WebChromeClient;
11 | import android.webkit.WebSettings;
12 | import android.webkit.WebView;
13 | import android.webkit.WebViewClient;
14 |
15 | import luo.library.R;
16 | import luo.library.base.widget.NumberProgressBar;
17 |
18 | public class BaseWebViewActivity extends BaseActivity {
19 |
20 | WebView mWebView;
21 | NumberProgressBar progressBar;
22 | public static final String URL="url";
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_base_web_view);
28 |
29 | init();
30 | }
31 |
32 | void init() {
33 | setTitleText("正在加载...");
34 | mWebView = (WebView) findViewById(R.id.webView);
35 | progressBar = (NumberProgressBar) findViewById(R.id.progressBar);
36 | WebSettings mWebSettings = mWebView.getSettings();
37 | mWebSettings.setSupportZoom(true);
38 | mWebSettings.setLoadWithOverviewMode(true);
39 | mWebSettings.setUseWideViewPort(true);
40 | mWebSettings.setDefaultTextEncodingName("utf-8");
41 | mWebSettings.setLoadsImagesAutomatically(true);
42 |
43 | //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface
44 | mWebSettings.setJavaScriptEnabled(true);
45 |
46 | saveData(mWebSettings);
47 |
48 | newWin(mWebSettings);
49 |
50 | mWebView.setWebChromeClient(webChromeClient);
51 | mWebView.setWebViewClient(webViewClient);
52 | if (!isNull(getIntent().getStringExtra(URL))) {
53 | mWebView.loadUrl(getIntent().getStringExtra(URL));
54 | }
55 | }
56 |
57 | @Override
58 | public void onPause() {
59 | super.onPause();
60 | mWebView.onPause();
61 | mWebView.pauseTimers(); //小心这个!!!暂停整个 WebView 所有布局、解析、JS。
62 | }
63 |
64 | @Override
65 | public void onResume() {
66 | super.onResume();
67 | mWebView.onResume();
68 | mWebView.resumeTimers();
69 | }
70 |
71 | /**
72 | * 多窗口的问题
73 | */
74 | private void newWin(WebSettings mWebSettings) {
75 | //html中的_bank标签就是新建窗口打开,有时会打不开,需要加以下
76 | //然后 复写 WebChromeClient的onCreateWindow方法
77 | mWebSettings.setSupportMultipleWindows(false);
78 | mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
79 | }
80 |
81 | /**
82 | * HTML5数据存储
83 | */
84 | private void saveData(WebSettings mWebSettings) {
85 | //有时候网页需要自己保存一些关键数据,Android WebView 需要自己设置
86 | mWebSettings.setDomStorageEnabled(true);
87 | mWebSettings.setDatabaseEnabled(true);
88 | mWebSettings.setAppCacheEnabled(true);
89 | String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
90 | mWebSettings.setAppCachePath(appCachePath);
91 | }
92 |
93 | WebViewClient webViewClient = new WebViewClient() {
94 |
95 | /**
96 | * 多页面在同一个WebView中打开,就是不新建activity或者调用系统浏览器打开
97 | */
98 | @Override
99 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
100 | view.loadUrl(url);
101 | return true;
102 | }
103 |
104 | };
105 |
106 | WebChromeClient webChromeClient = new WebChromeClient() {
107 |
108 | @Override
109 | public void onProgressChanged(WebView view, int newProgress) {
110 | super.onProgressChanged(view, newProgress);
111 | if (newProgress == 100) {
112 | progressBar.setVisibility(View.GONE);
113 | } else {
114 | progressBar.setVisibility(View.VISIBLE);
115 | progressBar.setProgress(newProgress);
116 | }
117 | }
118 |
119 | @Override
120 | public void onReceivedTitle(WebView view, String title) {
121 | super.onReceivedTitle(view, title);
122 | setTitleText(title);
123 | }
124 |
125 | //=========HTML5定位==========================================================
126 | //需要先加入权限
127 | //
128 | //
129 | //
130 | @Override
131 | public void onReceivedIcon(WebView view, Bitmap icon) {
132 | super.onReceivedIcon(view, icon);
133 | }
134 |
135 | @Override
136 | public void onGeolocationPermissionsHidePrompt() {
137 | super.onGeolocationPermissionsHidePrompt();
138 | }
139 |
140 | @Override
141 | public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {
142 | callback.invoke(origin, true, false);//注意个函数,第二个参数就是是否同意定位权限,第三个是是否希望内核记住
143 | super.onGeolocationPermissionsShowPrompt(origin, callback);
144 | }
145 | //=========HTML5定位==========================================================
146 |
147 | //=========多窗口的问题==========================================================
148 | @Override
149 | public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
150 | WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
151 | transport.setWebView(view);
152 | resultMsg.sendToTarget();
153 | return true;
154 | }
155 | //=========多窗口的问题==========================================================
156 | };
157 |
158 | @Override
159 | public boolean onKeyDown(int keyCode, KeyEvent event) {
160 | if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
161 | mWebView.goBack();
162 | return true;
163 | }
164 |
165 | return super.onKeyDown(keyCode, event);
166 | }
167 |
168 | @Override
169 | protected void onDestroy() {
170 | super.onDestroy();
171 |
172 | if (mWebView != null) {
173 | mWebView.clearHistory();
174 | ((ViewGroup) mWebView.getParent()).removeView(mWebView);
175 | mWebView.loadUrl("about:blank");
176 | mWebView.stopLoading();
177 | mWebView.setWebChromeClient(null);
178 | mWebView.setWebViewClient(null);
179 | mWebView.destroy();
180 | mWebView = null;
181 | }
182 | }
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/library/src/main/java/luo/library/base/utils/GsonUtil.java:
--------------------------------------------------------------------------------
1 | package luo.library.base.utils;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.JsonArray;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonParser;
7 | import com.google.gson.reflect.TypeToken;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | public class GsonUtil {
14 | private static Gson gson = null;
15 |
16 | static {
17 | if (gson == null) {
18 | gson = new Gson();
19 | }
20 | }
21 |
22 | private GsonUtil() {
23 | }
24 |
25 | /**
26 | * 转成json
27 | *
28 | * @param object
29 | * @return
30 | */
31 | public static String GsonString(Object object) {
32 | String gsonString = null;
33 | if (gson != null) {
34 | gsonString = gson.toJson(object);
35 | }
36 | return gsonString;
37 | }
38 |
39 | /**
40 | * 转成bean
41 | *
42 | * @param gsonString
43 | * @param cls
44 | * @return
45 | */
46 | public static T GsonToBean(String gsonString, Class cls) {
47 | T t = null;
48 | if (gson != null) {
49 | t = gson.fromJson(gsonString, cls);
50 | }
51 | return t;
52 | }
53 |
54 | /**
55 | * 转成list
56 | *
57 | * @param gsonString
58 | * @param cls
59 | * @return
60 | */
61 | public static List GsonToList(String gsonString, Class cls) {
62 | Gson gson = new Gson();
63 | List list = new ArrayList();
64 | JsonArray array = new JsonParser().parse(gsonString).getAsJsonArray();
65 | for (final JsonElement elem : array) {
66 | list.add(gson.fromJson(elem, cls));
67 | }
68 | return list;
69 | }
70 |
71 | /**
72 | * 转成list中有map的
73 | *
74 | * @param gsonString
75 | * @return
76 | */
77 | public static List