热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

最新优秀的通用Android应用架构:从建项目开始

1.项目结构现在的MVP模式越来越流行。就默认采用了。如果项目比较小的话:

1.项目结构


现在的MVP模式越来越流行。就默认采用了。

如果项目比较小的话:


  • app——Application Activity Fragment Presenter等的顶级父类

  • config——API,常量表等

  • model——数据层

  • entities——数据模型

  • presenter——MVP的P

  • view——MVP的V

  • utils——工具类集合

  • widget——各个可复用View集合


如果项目比较大,上面的方式一定会造成presenter和view里近百个文件。看瞎眼系列。推荐下列方式:


  • app

  • config

  • model

    • entities

  • module——将界面层以功能模块分配包。

    • launch

    • main

    • account

    • news

    • music

    • ……

  • utils

  • widget


2.配置主题


对于不遵守Material Design的项目无视这一步。


1.先在color.xml中写好需要的颜色:


"Orange">#ff5722

"DeepPurple">#673AB7

"DeepPurple900">#311B92

"White">#fff

"Gray">#888888

"Gray100">#dddddd

"Gray600">#999999


注意color.xml是配色表。应该是描述颜色而不是对字体颜色,背景颜色等的定义。这样能防止相近的颜色重复定义。而导致界面颜色不统一。


2.在style.xml里定义主题:




在res目录下,创建一个values-v21目录,再创建一个style.xml:



然后在AndroidManifest.xml文件中修改application的theme属性为上面定义的AppTheme.即可实现沉浸式状态栏。


然后关于Theme与Toolbar的详细设置参考我另两篇博客:


http://www.cnblogs.com/Jude95/p/4369816.html

http://www.cnblogs.com/Jude95/p/4370176.html


3.依赖库与SDK


必选的库:

gradle-retrolambda——Android的lambda表达式插件

fresco——Android最屌图片加载库

material-dialogs ——Material Dialog向下兼容库

material-ripple——Ripple向下兼容库

fastjson——最快JSON解析

butterknife——View注解库和配套插件android-butterknife-zelezny

ActiveAndroid——数据库注解库。

RxAndroid——Rx函数响应式编程中文文档

retrofit,okhttp,sqlbrite,okio——Square家的精品多啊

compile 'com.android.support:design:23.0.1'——谷歌Material Design控件库


下面安利几个自己写的库,如果有什么建议欢迎交流:

Utils——Android各种小功能集合

RollViewPager——自动轮播使用方便的ViewPager

EasyRecyclerView——支持下拉上拉刷新等功能全面的RecyclerView

SwipeBackHelper——Activity滑动关闭支持库,能达到微信效果


尝试了很多,这几个是现在常用的。

融云——即时通讯

友盟——数据统计,推送,意见反馈,自动更新,第三方分享及登录,社区

七牛——云存储

Mob——短信验证

Bmob——做后台不求人


依赖这一大堆库和SDK以后。建议在合适的时机初始化他们,而不是全堆在Application的onCreate()里面。这样会导致启动时间过长。启动后也会较卡。虽然是不会影响功能正常使用。


4.配置Gradle


某些SDK运行时需要检查签名是否正确。所以在debug模式时也必须用正式KEY签名。而把签名放进版本控制不是明智的做法。所以推荐下面的做法:

在app的gradle加入下面代码


Properties props = new Properties()

props.load(new FileInputStream(file("signing.properties")))

android {

signingConfigs {

release{

keyAlias props['KEY_ALIAS']

keyPassword props['KEY_PASSWORD']

storeFile file(props['KEYSTORE_FILE'])

storePassword props['KEYSTORE_PASSWORD']

}

}

buildTypes {

release {

signingConfig signingConfigs.release

}

debug {

signingConfig signingConfigs.release

}

}

}


在app的gradle文件同级目录新建signing.properties文件,里面填入你的key的相应信息


KEYSTORE_FILE = C:\\Users\\Mr.Jude\\Documents\\Android\\HelloWorld.jks

KEYSTORE_PASSWORD = xxxxxx

KEY_ALIAS = xxxxxx

KEY_PASSWORD = xxxxxx


将signing.properties添加进忽略目录。

其他人pull下来代码后。自己新建signing.properties填入相应信息后即可编译成功。


5.制定开发规范


为了避免合作开发写的代码风格迥异。或做出了多套开发模式。下面是个例子。毕竟是为了高效开发而制定的。适合自己项目的才是最好。


所有Activity继承BaseActivity

所有Fragment继承BaseFragment

所有Presenter继承BasePresenter

这样利于生命周期管理。也可以方便的全局修改。


命名,例

AccountFragment

UserDetailActivity


layout命名,例

activity_collection

fragment_account

item_person

include_toolbar

view_progress


不过对于庞大项目的开发。近百个activity开头的layout列表还是会眼瞎。所以那种情况会在前面加上模块名。


id命名,例

btn_send

tv_name

list_persons

et_password


然后用butterknife的插件生成变量会自动将下划线变成驼峰命名


变量命名:以m开头。例mAdapter使用时按一个m全都出来了

方法命名:与其写好名字不如写好注释。= =。


TextView使用官方标准字体




margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Display4"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Display3"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Display2"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Display1"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Headline"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Title"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Subhead"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Body2"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Body1"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Caption"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/TextAppearance.AppCompat.Button"


Button使用Material Design标准样式



margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/Widget.AppCompat.Button"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/Widget.AppCompat.Button.Borderless"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/Widget.AppCompat.Button.Borderless.Colored"

margin:0px; padding:0px; border:0px; font-family:inherit; height:inherit; max-width:100%!important; word-wrap:break-word!important; font-size:inherit!important; line-height:inherit!important; color:rgb(8,40,251)!important">"@style/Widget.AppCompat.Button.Small"


定好网络请求写法。文件存储方式与位置。写好项目所使用的类库框架用法。


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Day2列表、字典、集合操作详解
    本文详细介绍了列表、字典、集合的操作方法,包括定义列表、访问列表元素、字符串操作、字典操作、集合操作、文件操作、字符编码与转码等内容。内容详实,适合初学者参考。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 在Android中解析Gson解析json数据是很方便快捷的,可以直接将json数据解析成java对象或者集合。使用Gson解析json成对象时,默认将json里对应字段的值解析到java对象里对应字段的属性里面。然而,当我们自己定义的java对象里的属性名与json里的字段名不一样时,我们可以使用@SerializedName注解来将对象里的属性跟json里字段对应值匹配起来。本文介绍了使用@SerializedName注解解析json数据的方法,并给出了具体的使用示例。 ... [详细]
  • 原理:dismiss再弹出,把dialog设为全局对象。if(dialog!null&&dialog.isShowing()&&!(Activity.)isFinishing()) ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
  • Explain如何助力SQL语句的优化及其分析方法
    本文介绍了Explain如何助力SQL语句的优化以及分析方法。Explain是一个数据库SQL语句的模拟器,通过对SQL语句的模拟返回一个性能分析表,从而帮助工程师了解程序运行缓慢的原因。文章还介绍了Explain运行方法以及如何分析Explain表格中各个字段的含义。MySQL 5.5开始支持Explain功能,但仅限于select语句,而MySQL 5.7逐渐支持对update、delete和insert语句的模拟和分析。 ... [详细]
  • express工程中的json调用方法
    本文介绍了在express工程中如何调用json数据,包括建立app.js文件、创建数据接口以及获取全部数据和typeid为1的数据的方法。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 本博客基于android7.1版本分析,仅用于沟通学习使用上一篇博客介绍了android导出vCard联系人流程紧接着我们在这篇博客来看看它是如何导入一个vCard ... [详细]
  • 代码逻辑:拷贝功能:1.从编辑控件中获取文本。2.打开并清空剪贴板。(OpenClipboard,EmptyClipboard)3.创建一个全局缓冲区。(GlobalAlloc)4 ... [详细]
author-avatar
章小胭
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有