一、我的项目分包结构
app
src
main
java
freshclient(项目名称)
adapter:存放所有adapter
application:存放全局类
base:存放activity,fragment等基类
model:所有的实体类
utils: 存放一些工具类
ui:按功能模块分包,存放activity,fragment
home:首页
shoper:商家
order:订单
mine:我的
user:登录注册,用户相关的
utils:一些工具类
view:自定义view
res(对特殊分包进行说明)了解途径http://www.jianshu.com/p/8e893581b9c7#comment-10816700
block-res:对资源文件的优化封装,作用是为了模块化资源文件,使资源文件趋于清晰化,模块化,查找起来更加方便
classfiy:分类模块的资源文件都存放在该包下
layout:存放布局文件,目前只模块化layout布局文件,values等文件共用的更方便,当然有需要也可以模块化,根据项目而定
drawable:
values:
mipmap:
home:首页模块的资源文件存在该包下
mine:我的模块的资源文件存放在该包下
shopcart:购物车的资源文件存放在该包下
layout:布局文件,继续存放一些公用的layout
二、我的项目中用到的框架
//网络框架 okgo
implementation 'com.lzy.net:okgo:2.1.4'
//fastjson数据解析
implementation 'com.alibaba:fastjson:1.2.35'
//注解
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//适配
implementation 'com.zhy:autolayout:1.4.5'
//工具库
implementation 'com.jude:utils:1.2.2'
//glide拓展库 实现圆角 模糊等效果
implementation 'jp.wasabeef:glide-transformations:3.1.1'
//圆头像
implementation 'de.hdodenhof:circleimageview:2.1.0'
//RecyclerView万能Adapter
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
//6.0 权限获取
implementation 'com.mylhyl:acp:1.1.5'
//广告无限轮播框架
implementation 'com.youth.banner:banner:1.4.9'
//xrecyclerview 统一加载框架
implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
//recyclerView的baseadapter
implementation 'com.zhy:base-rvadapter:3.0.3'
//鸿洋流式布局
implementation 'com.zhy:flowlayout-lib:1.0.3'
//类似美团下拉菜单
implementation 'com.github.dongjunkun:DropDownMenu:1.0.4'
//xtablayout 自定义tab长度
implementation 'com.androidkun:XTabLayout:1.0.6'
//右下角字数Editext
implementation 'com.github.FJ917:FJEditTextCount:v1.0.3'
//横纵向滑动RecyclerView
implementation 'com.kelin.scrollablepanel:library:1.2.0'
我的GitHub
hongyang适配 https://github.com/hongyangAndroid/AndroidAutoLayout
RecyclerView万能Adapter(超级好用) https://github.com/CymChad/BaseRecyclerViewAdapterHelper
鸿洋 baseAdapter https://github.com/hongyangAndroid/baseAdapter
鸿洋流式布局 https://github.com/hongyangAndroid/https://github.com/hongyangAndroid/FlowLayout
XTabLayout(改变指示线的长度等) https://github.com/AndroidKun/XTabLayout
滚轮选择库 https://github.com/Bigkoo/Android-PickerView
图片裁剪库 https://github.com/Yalantis/uCrop
类似美团下拉选择菜单 https://github.com/dongjunkun/DropDownMenu
广告无限轮播框架 https://github.com/youth5201314/banner
6.0 权限获取 https://github.com/mylhyl/AndroidAcp
三、我的项目中Base类封装
1.BaseApplication
public class MyApplication extends Application{
private static MyApplication instance;
private static TelephonyManager sTelephonyManager;
private static ActivityManager sActivityManager;
public static Context sContext;
@Override
public void onCreate() {
super.onCreate();
initConfigs();
}
private void initConfigs() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
//退出程序
System.exit(0);
}
});
sContext = getApplicationContext();
sTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
sActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
initOkGo();
photoPermissions();
}
//android 7.0系统解决拍照的问题
private void photoPermissions() {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
}
//初始化okgo
private void initOkGo() {
OkGo.init(this);
OkGo.getInstance()
.setConnectTimeout(OkGo.DEFAULT_MILLISECONDS) //全局连接超时时间
.setReadTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局读取超时时间
.setWriteTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局写入超时时间
//可以全局统一设置超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0
.setRetryCount(3)
//可以全局统一设置缓存模式,默认是不使用缓存
.setCacheMode(CacheMode.NO_CACHE);
}
public static Context getAppContext() {
return sContext;
}
public static TelephonyManager getTelephonyManager() {
return sTelephonyManager;
}
public static ActivityManager getsActivityManager() {
return sActivityManager;
}
public synchronized static MyApplication getInstance() {
if (instance == null)
instance = new MyApplication();
return instance;
}
}
2.BaseActivity
public abstract class BaseActivity extends Activity {
public static final String TAG = "BaseActivity";
protected LayoutInflater mLayoutInflater;
protected Activity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
mLayoutInflater = LayoutInflater.from(this);
activity = this;
}
四、开发中需要考虑的小细节
1.app整体风格统一
项目中列表下拉刷新上滑加载更多 样式统一;
网络请求数据,加载中、加载成功以及加载失败 处理样式统一;
网路请求数据等待中样式统一;
项目中用到弹窗(浮层)样式统一;
app中所有图片加载的地方,预加载和加载失败 图片样式统一;
2.app代码管理统一
所有颜色值,文字,尺寸值都统一放在values下的各自xml文件中;
工具类等公用的东西不要重复;
3.开发中容易忽略的小细节
Activity非必须情况设置竖屏,可在基类中统一设置;