Giter Club home page Giter Club logo

android-utils's Introduction

Banner

Android-Utils: 常用的 Android 工具库合集

License Version Code Grade Build Min Sdk Version Author QQ Group

1、关于项目

该项目旨在收集 Android 开发中频繁使用的工具类,比如日志、Crash 收集、资源和属性获取、权限申请、TOAST 等,通过对相关的工具类进行封装,提供相关类的标准化应用,来降低开发者开发的难度。你可以参考 README 来了解项目中包含的工具类库。

2、在项目中使用

2.1 添加工程依赖

该项目已经被提交到了 jCenter,所以你可以很方便地在你的项目中使用它。

首先,你需要引用 jCenter 到你的项目中:

repositories { jcenter() }

然后,在你的项目中添加该依赖:

implementation 'me.shouheng.utils:utils-core:latest-version'

如果需要使用 utils-ktx,可以在项目中添加如下依赖,

implementation "me.shouheng.utils:utils-ktx:$latest-version"

2.2 项目初始化

然后你的自定义的 Application 中对工具类库进行初始化。这个步骤主要用来在类库内获取一个全局的 Context,从而使方法的调用更加简洁,不会占用你宝贵的启动时间。

public class SampleApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // 对工具类库进行初始化
        UtilsApp.init(this);
    }
}

初始化完毕之后,我们可以对类库中包含对模块进行个性化定制。具体可以参考示例代码和源码。

2.2 该类库中目前提供的功能

按照关注的主题,我们将项目中的类按照主题分成了几个大类。目前项目中的类的结构如下:

编号 类名 群组 说明
1 ActivityUtils 应用 Activity 启动、关闭、动画、启动参数构建
2 AppUtils 应用 App 安装与卸载,获取应用信息等
3 IntentUtils 应用 各种比较通用的意图,比如分享文字、打开应用商店等
4 ResUtils 资源 图片、字符串和其他资源获取
5 EncodeUtils 编码 base64 和 url 编码等
6 EncryptUtils 加密 md5 sha256 加密方式
7 RegexUtils 数据处理 正则表达式
8 StringUtils 数据处理 字符串处理
9 TimeUtils 数据处理 时间处理,时间和日期格式化等
10 DeviceUtils 设备信息 设备信息,比如 imei 手机型号 生产商等
11 NetworkUtils 设备信息 网络信息,网络类型等
12 ShellUtils 设备信息 命令行执行
13 PermissionUtils 权限 Android 6.0 运行时权限权限请求
14 CrashHelper 稳定性 崩溃日志
15 L 稳定性 日志输出,日志格式化,日志输出到文档等
16 FileUtils 数据存储 文件相关,获取文件信息,文件移动,删除和遍历等
17 PathUtils 数据存储 文件路径,获取手机中各个文件夹的路径等
18 IOUtils 数据存储 磁盘读写
19 SPUtils 数据存储 Sharedpreference 读写相关
20 ImageUtils ui 图片处理,缩放,旋转,变形,加水印等
21 ToastUtils ui 土司封装
22 ViewUtils ui 获取控件信息以及软键盘操作等

2.3 使用 Utils-ktx

utils-ktx 是基于 Android-Utils 和 Kotlin 的特性定制的拓展库,可以参考 utlis-ktx 模块来查看其源代码。其主要设计被用来简化常见的调用方式,从而使代码更加简洁。比如,

fun Context.attrFloatOf(attrRes: Int): Float = ResUtils.getAttrFloatValue(this, attrRes)

fun Context.attrColorOf(attrRes: Int): Int = ResUtils.getAttrColor(this, attrRes)

// ...

@ColorInt fun colorOf(@ColorRes id: Int): Int = ResUtils.getColor(id)

fun stringOf(@StringRes id: Int): String = ResUtils.getString(id)

// ...

fun String.md5(salt: String): String = EncryptUtils.md5(this, salt)

fun String.sha1(): String = EncryptUtils.sha1(this)

fun String.sha224(): String = EncryptUtils.sha224(this)

// ...

3、关于

3.1 关于作者

你可以通过访问下面的链接来获取作者的信息:

  1. Twitter: https://twitter.com/shouheng_wang
  2. Github: https://github.com/Shouheng88
  3. 掘金:https://juejin.im/user/585555e11b69e6006c907a2a
  4. 简书: https://www.jianshu.com/u/e1ad842673e2

3.2 更新日志

更新日志

4、捐赠项目

我们致力于为广大开发者和个人开发者提供快速开发应用的解决方案。您可以通过下面的渠道来支持我们的项目,

License

Copyright (c) 2019-2020 DaddyDev.

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.

android-utils's People

Contributors

shouheng88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.