Android实用框架采用MVC设计模式,多个项目经验总结,持续完善中
包括:
1,OKhttp简单封装
2,Orm 数据库
3,Universal-Image-Loader
4,EventBus
5,YHRecyclerView 下拉,上拉
6,BindView 控件绑定
7,YHGlide 图片框架
8,YHWebView 自定义View
9,BindView 控件绑定
10,YHVideoPlayer 视频播放器
注,需要在AndroidManifest.xml 中声明如下权限
<uses-permissionandroid:name="android.permission.INTERNET" />
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>- Gradle
compile'org.yh.yhframe:YhLibraryForAndroid:last_version'- Maven
<dependency>
<groupId>org.yh.yhframe</groupId>
<artifactId>YhLibraryForAndroid</artifactId>
<version>1.0.2</version>
<type>pom</type>
</dependency>1.BaseActiciy所有Acticiy的基类2.BaseFragment所有Fragment的基类1.PreferenceUtils.java对SharedPreferences的封装2.CipherUtils.java对常用加密方法进行整理3.Constants.java全局常量4.CrashHandler.java异常捕捉5.DensityUtils.java系统屏幕的一些操作6.FileUtils.java文件与流处理工具类7.ImageUtils.java图片工具类8.JsonUitl.javajson数据基于Gson9.LogUtils.javaLog日志工具类10.NetWorkUtils.java网络工具类11.StringUtils.java字符串操作12.SystemUtils.java系统信息工具包13.ViewUtils.java系统界面工具类(截屏)
14.YHViewInject.java侵入式View的调用工具类15.AnnotateUtil.java注解工具类(Viewid绑定)
16.YHImageViewRoundOval.java实现圆形、圆角,椭圆等自定义图片View1.YhToolbar标题栏
<includelayout="@layout/basetitle"/>
https://github.com/android-coco/AgentWeb2.YHWebView继承WebViewHTML5WebViewCustomADextendsBaseActiciy
{
//....
}
https://github.com/android-coco/LoadingBar3.YHLoadingBar//默认样式 loading将会覆盖在parent的内容上面YHLoadingBar.make(parent).show();
//自定义样式//提供两种形式,loadingView更简便,loadingFactory自由度更高YHLoadingBar.make(parent,loadingView).show();
YHLoadingBar.make(parent,loadingFactory).show();
//完全自定义YHLoadingBar.make(parent,loadingFactory)
.setOnClickListener(clickListener)//点击事件
.setOnLoadingBarListener(loadingBarListener)//当loadingbar取消的时候回调
.show();
//取消LoadingYHLoadingBar.cancel(parent);
4.YHLoadingDialog//默认样式YHLoadingDialog.make(context).show();
//自定义样式YHLoadingDialog.make(context, dialogFactory).show();
//完全自定义YHLoadingDialog.make(context, dialogFactory)
.setMessage(message)//提示消息
.setCancelable(cancelable)
.show();
//设置更多属性Dialogdialog = YHLoadingDialog.make(context, dialogFactory)
.setMessage(message)//提示消息
.setCancelable(cancelable)
.create();
dialog.setOnCancelListener(cancelListener);
dialog.set...
dialog.show();
//取消LoadingYHLoadingDialog.cancel();
5.自定义FactorypublicclassCustomLoadingFactoryimplementsI_LoadingFactory {
@OverridepublicViewonCreateView(ViewGroupparent) {
ViewloadingView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_custom, parent,false);
returnloadingView;
}
}
全局配置//自定义样式并应用于全局YHLoadingConfig.setFactory(loadingFactory,dialogFactory);
资源释放其实YHLoadingBar在cancel的时候已经释放掉了,可以不用手动释放,但是这里也提供释放的方法,根据自己需要选择在ActivityonDestroy调用,个人建议在BaseActivity,资源释放只会释放无效的资源YHLoadingBar.release();
16.布局中加入
<org.yh.library.view.YHImageViewRoundOvalandroid:id="@+id/img1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:src="@drawable/img_default"/>
...
@BindView(id = R.id.img1)
privateYHImageViewRoundOvalimg1;
// public static final int TYPE_CIRCLE = 0;// 圆形// public static final int TYPE_ROUND = 1;// 圆角矩形// public static final int TYPE_OVAL = 2;//椭圆形img1.setType(YHImageViewRoundOval.TYPE_ROUND);
img1.setRoundRadius(20);//矩形凹行大小img1.setType(ZQImageViewRoundOval.TYPE_OVAL);
img1.setRoundRadius(45);// 圆角大小1.YhDBManager.java2.Constants.Config.yhDBManagerConstants.Config.yhDBManager = YhDBManager.getInstance(mInstance,"yh.db",true);
Constants.Config.yhDBManager.insertAll(mAdapter.getDatas());ActivityextendsBaseActiciyrequestRunTimePermission(newString[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, newI_PermissionListener()
{
@OverridepublicvoidonSuccess()//所有权限OK
{
YHViewInject.create().showTips("授权成功");
//直接执行相应操作了
}
@OverridepublicvoidonGranted(List<String> grantedPermission)//部分权限OK
{
}
@OverridepublicvoidonFailure(List<String> deniedPermission)//全部拒绝
{
YHViewInject.create().showTips("拒绝授权列表:" + Constants.initPermissionNames().get(deniedPermission.get(0)));
}
});
FragmentextendsBaseFragmentrequestRunTimePermission(newString[]{Manifest.permission.CAMERA}, newI_PermissionListener()
{
@OverridepublicvoidonSuccess()
{
YHViewInject.create().showTips("授权成功");
//直接执行相应操作了outsideAty.showActivity(outsideAty, HTML5WebViewCustomAD.class);
}
@OverridepublicvoidonGranted(List<String> grantedPermission)
{
}
@OverridepublicvoidonFailure(List<String> deniedPermission)
{
YHViewInject.create().showTips("您没有授权" + Constants.initPermissionNames().get(deniedPermission.get(0)) + "权限,请在设置中打开授权");
}
});1.YHAdapter<D> adatper2.YHHolder<D> holder3.YHRecyclerViewRecyclerView4.I_BaseAdapter<D, H> 适配器相关的接口,与RecyclerView配套使用5.I_YHHolder<D> Holder相关接口6.I_YHItemClickListener<T> 事件接口LinearLayoutManagerlayoutManager = newLinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.addItemDecoration(mRecyclerView.newYHItemDecoration());//分割线mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setEmptyView(empty_layout);//没有数据的空布局mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
mRecyclerView.setFootViewText(getString(R.string.listview_loading), "没有更多");
//mRecyclerView.setArrowImageView(R.mipmap.iconfont_downgrey);mAdapter = newMyAdapter();
mAdapter.setOnItemClickListener(this);
mRecyclerView.setLoadingListener(newYHRecyclerView.LoadingListener()
{
@OverridepublicvoidonRefresh()
{
//下拉
}
@OverridepublicvoidonLoadMore()
{
//上拉
}
});
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.refresh();
}
//刷新mAdapter.setDatas(list);
//刷新完毕mRecyclerView.refreshComplete();
//没有更多mRecyclerView.setNoMore(true);
mAdapter.notifyDataSetChanged();
//加载更多mAdapter.addDatas(list);
//加载完毕mRecyclerView.loadMoreComplete();1.YHRequestFactory.java//url 分为2部分 头和后缀//headers 请求头 Map<String,String>YHRequestFactory.getRequestManger().get("", "",headers, new HttpCallBack()
{
@Override
public void onSuccess(String t)
{
super.onSuccess(t);
LogUtils.e(TAG, t);
}
@Override
public void onFailure(int errorNo, String strMsg)
{
super.onFailure(errorNo, strMsg);
LogUtils.e(TAG, strMsg);
}
}, TAG);1.YHGlide-->GlideYHGlide.getInstanse(MyApplication.getInstance()).loadImgeForUrl(item.getPic(), (ImageView) holder.getView(R.id.menu_pic));Copyright (C) Justson(https://github.com/android-coco/YhLibraryForAndroid)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.