• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PLib: Android开发库

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

PLib

开源软件地址:

https://gitee.com/pocketdigi/PLib

开源软件介绍:

项目已迁移至github https://github.com/pocketdigi/PLib

PLib

PLib是一个Android应用开发库,集成了流行的开源库,整合一些Util,可以帮助开发者更快开发应用.仅支持Android Studio。v1.6 开始移除Volley,网络请求使用OKHttp封装,简单高效。

整合开源库:

1.AndroidAnonations
2.gson
3.eventbus
4.fresco
5.OKHttp3

功能:

1.OKHttp3封装,可以很容易用一两行代码实现post,get请求,上传下载文件
2.SharedPreference封装,一行代码实现保存读取配置
3.Toast封装
4.Log封装
5.其他一些常用Utils(md5,DES,日期处理,字符串处理,图片处理,网络判断,首次运行检测,版本号比较等)
6.CarouselViewPager 轮播幻灯片
7.BoldTextView 加粗的TextView...

使用方法有两种:

一、下载Demo模板项目:

参考Demo项目,导入Android Studio,Rebuild Project,改包名,直接使用。Demo包含的内容:

1、PageManager

Demo项目使用单Activity架构,UI使用Fragment展示,通过PageManger控制。

2、Http接口数据获取,Android DataBinding框架使用
3、友盟统计集成
4、其他一些小功能

二、作为子模块加到现有项目

#####1、切到项目(仅支持Android Studio项目)根目录下,添加子模块
git submodule add -b v1.5 https://git.oschina.net/pocketdigi/PLib.git plib
#####2、修改项目的build.gradle

// 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封装
使用SharedPreference可以串联:
PreferenceManager.getDefaultManager().putBoolean(KEY1,Value1).putString(KEY2,Value2).commit();最后加Commit()方法即可保存,支持指定保存的文件
2.Toast封装
Toast封装后,支持在非UI线程直接调用:
PToast.show(message);
3.Log封装
PLog类支持更多的参数类型,如Tag可以直接传入Object,会取object的类名作tag,Message支持基本类型.
其他
md5,DES,日期处理,字符串处理,图片处理,网络判断,首次运行检测等


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap