Giter Club home page Giter Club logo

yutils's Introduction

Android快速开发工具集合——YUtils

3.0.0 版本更新

  • 3.0.0新增了kotlin版本,除了调用方式遵循kotlin的语法之外,类名的区别在于添加了后缀Kt,比如YUtilsKt,其他以此类推;
  • 此外,java版本和kotlin版本都删除了ExitUtils
  • kotlin版本没有GsonUtil

How to use

  • Step 1 project:build.gradle
	allprojects {
		repositories {
			...
			maven { url 'https://www.jitpack.io' }
		}
	}
  • Step 2 app:build.gradle
	dependencies {
	        implementation 'com.github.yechaoa:YUtils:3.0.2'
	}

一、初始化

in your Application

  	//初始化
        YUtils.initialize(this);
        //设置打印开关
        LogUtil.setIsLog(true);
        //注册Activity生命周期
        registerActivityLifecycleCallbacks(ActivityUtil.getActivityLifecycleCallbacks());

二、功能

1.YUtils(各种小工具)

  • void initialize(Application app)
    Application 中初始化

  • Application getApplication()
    获取全局上下文

  • int getScreenWidth()
    获取屏幕宽度

  • int getScreenHeight()
    获取屏幕高度

  • void showLoading(Activity activity,String msg)
    Loading加载框

  • void hideLoading()
    hideLoading

  • void finishBySleep(final long millis)
    根据时间休眠然后关闭当前页面,比如:3秒自动返回

  • String getVersionName()
    获取版本名

  • int getVersionCode()
    获取版本号

  • boolean checkPhoneNumber(String mobiles)
    校验手机号

  • String MD5(String data)
    MD5加密

  • int dp2px(float dp)
    dp2px

  • float px2dp(int px)
    px2dp

  • void copyToClipboard(String text)
    复制文本到粘贴板

  • View Foreground(View view, int color, int start, int end)
    字体高亮(TextView、EditText、Button)like this ---》 YUtils.Foreground(mEditText, Color.RED,1,2);

  • void closeSoftKeyboard()
    关闭软键盘

2.ToastUtil(任意线程,不重复显示,可取消).

  • showToast(final String msg)
    底部显示(默认),任何线程且不会超长显示

  • void showCenterToast(final String msg)
    showCenterToast 居中显示

  • void cancelToast()
    取消Toast,onDestroy时调用,或onPause,当前页面finish之后在下一个页面不会再显示

3.LogUtil(日志打印,带方法行数链接,可超长打印)

  • void setIsLog(boolean isLog)
    是否打印

  • setIsLog(boolean isLog, String tag)
    带全局tag

  • void i(String msg)
    不带tag

  • void i(String TAG, String msg)
    带tag

  • void d(String msg)

  • void d(String TAG, String msg)

  • void e(String msg)

  • void e(String TAG, String msg)

4.ActivityUtil(Activity管理)

  • Activity getCurrentActivity()
    获得当前栈顶Activity

  • String getCurrentActivityName()
    获得当前Activity名字

  • void finishActivity(Activity activity)
    关闭当前Activity

  • void closeAllActivity()
    关闭所有Activity

5.SpUtil(SharedPreferences)

  • void setString(String key, String value)
    String

  • String getString(String key)

  • void setStringSet(String key, Set value)
    StringSet

  • Set getStringSet(String key)

  • void setInt(String key, String value)
    Int

  • String getInt(String key)

  • void setBoolean(String key, String value)
    Boolean

  • String getBoolean(String key)

  • void setFloat(String key, String value)
    Float

  • String getFloat(String key)

  • void setLong(String key, String value)
    Long

  • String getLong(String key)

  • void removeByKey(String key)
    根据key移除

  • void removeAll()
    移除所有

6.ShareUtil(调用系统分享)

  • void shareImage(String title, Uri uri)
    分享图片

  • void shareText(String title, String text)
    分享文字

7.TimeUtil

  • String getDate()
    获取当前年月日

  • String getTime()
    获取当前时分秒

  • String getDateAndTime()
    获取当前年月日时分秒

  • Long getTimeForLong()
    获取当前时间,返回Long类型

  • String formatDate(String mDate)
    转换为年月日

8.ParseUtil(直接解析 Json)

2.0.8版本之后简化了解析方式,且不兼容更新

like this

{
     "code": "0",
     "data": "修改成功",
     "flag": true,
     "info": null
 }
  • String parseCode(String response)
    解析Code

  • boolean parseFlag(String response)
    解析Flag

  • String parseData(String response)
    解析data

  • String parseInfo(String response)
    解析info

  • String parseByKey(String response, String key)
    根据key值解析,只支持json中的一级字段

9.GsonUtil

  • String GsonString(Object object)
    转成json

  • T GsonToBean(String gsonString, Class cls)
    转成bean

  • List GsonToList(String gsonString, Class cls)
    转成list

  • GsonToMaps(String gsonString)


混淆

#YUtils
-keep class com.yechaoa.yutils.**{*;}

关于



License

   Copyright 2017 yechaoa

   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.

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.