在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:PLib开源软件地址:https://gitee.com/pocketdigi/PLib开源软件介绍:项目已迁移至github https://github.com/pocketdigi/PLibPLibPLib是一个Android应用开发库,集成了流行的开源库,整合一些Util,可以帮助开发者更快开发应用.仅支持Android Studio。v1.6 开始移除Volley,网络请求使用OKHttp封装,简单高效。 整合开源库:1.AndroidAnonations 功能:1.OKHttp3封装,可以很容易用一两行代码实现post,get请求,上传下载文件 使用方法有两种:一、下载Demo模板项目:参考Demo项目,导入Android Studio,Rebuild Project,改包名,直接使用。Demo包含的内容: 1、PageManagerDemo项目使用单Activity架构,UI使用Fragment展示,通过PageManger控制。 2、Http接口数据获取,Android DataBinding框架使用3、友盟统计集成4、其他一些小功能二、作为子模块加到现有项目#####1、切到项目(仅支持Android Studio项目)根目录下,添加子模块 // Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir} ####3、修改项目的settings.gradle include ':app', ':plib' 将plib模块加进来####4、修改app模块的build.gradle apply plugin: 'com.neenbedankt.android-apt'def AAVersion = '4.0.0'dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':plib') apt "org.androidannotations:androidannotations:$AAVersion" compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:cardview-v7:23.2.1' compile 'com.android.support:recyclerview-v7:23.2.1'}apt { arguments { resourcePackageName android.defaultConfig.applicationId androidManifestFile variant.outputs[0].processResources.manifestFile }} 完成后,可以使用标准的AndroidAnnotations注解开发。Application继承PApplication,Activity继承PFragmentActivity. ###网络请求####v1.6开始不再使用volley,而是通过封装OKHttp实现网络请求. GET: PRequest<String> request=new PRequest<>("http://git.oschina.net/pocketdigi/PLib/raw/master/README.md", listener,String.class);PHttp.getInstance().addRequest(request); listener 是 PResponseListener<String> 的实例,如果PResponseListener的泛型是String,则直接不处理返回字符串,如果是其他类型,则通过GSON转换成对象。 POST: public static void post(PResponseListener<String> listener) { PRequest<String> request=new PRequest<>(PRequest.POST, API_PREFIX+"add", listener,String.class); request.addParam("p1","value1"); request.addParam("p2","value2"); PHttp.getInstance().addRequest(request); } POST Json public static void postObject(Person person,PResponseListener<String> listener) { PRequest<String> request=new PRequest<>(PRequest.POST, API_PREFIX+"add", listener,String.class); request.setPostObject(person); PHttp.getInstance().addRequest(request); } 通过Gson将对象转成json放在request body里发送上传 public static PUploadRequest upload(String filePath,UploadListener<String> listener) { PUploadRequest<String> request=new PUploadRequest<>(API_PREFIX+"upload","file",filePath, listener,String.class); PHttp.getInstance().addRequest(request); return request; } 下载 public static PDownFileRequest downloadFile(String url, String savePath, DownProgressListener listener) { PDownFileRequest pDownFileRequest = new PDownFileRequest(url, savePath,listener); PHttp.getInstance().addRequest(pDownFileRequest); return pDownFileRequest; } ###常用Util1.SharedPreference封装 |
请发表评论