├── .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 |