- Step 1 project:build.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
- Step 2 app:build.gradle(以下3种引用方式,三选一即可)
dependencies {
//kotlin 版本
implementation 'com.github.yechaoa.YUtils:yutilskt:3.4.0'
//java 版本
implementation 'com.github.yechaoa.YUtils:yutils:3.4.0'
//kotlin && java 版本
implementation 'com.github.yechaoa:YUtils:3.4.0'
}
//初始化
YUtils.init(this);
//打印开关(可选,默认false不打印)
LogUtil.setIsLog(true);
-
void init(Application app)
Application 中初始化 -
Application getApp()
获取Application -
Context getAppContext()
获取全局上下文 -
void showLoading(Activity activity,String msg)
Loading加载框,kotlin版本参数更多 -
void hideLoading()
hideLoading -
boolean getLoadingDialog()
获取dialog -
boolean loadingIsShowing()
loading是否显示 -
void finishBySleep(final long millis)
根据时间休眠然后关闭当前页面,比如:3秒自动返回 -
String getVersionName()
获取版本名 -
int getVersionCode()
获取版本号 -
boolean checkPhoneNumber(String number)
校验手机号 -
String MD5(String data)
MD5加密 -
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 showSoftKeyboard(View view)
弹出软键盘 -
void closeSoftKeyboard()
关闭软键盘 -
Boolean hasSim()
是否有sim卡 即设备是否可以拨打电话等
-
show(final String msg)
底部显示(默认),任何线程且不会超长显示 -
void showCenter(final String msg)
showCenter 居中显示 -
void cancel()
取消Toast,onDestroy时调用,或onPause,当前页面finish之后在下一个页面不会再显示
kotlin分支中添加了一个Toast扩展,比之前使用更加简单方便,调用示例:
"111".show() -> 111
111.show() -> 111
111.show("222") -> 222
-
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)
-
Activity getCurrentActivity()
获得当前栈顶Activity -
String getCurrentActivityName()
获得当前Activity名字 -
void start(Class<?> targetActivity)
启动指定Activity 无参 -
void start(Class<?> targetActivity, Bundle bundle)
启动指定Activity,带Bundle参数(kotlin调用参数可选) -
void finish(Activity activity)
关闭指定Activity -
void closeAllActivity()
关闭所有Activity
-
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()
移除所有
-
void shareImage(String title, Uri uri)
分享图片 -
void shareText(String title, String text)
分享文字
-
String getDate()
获取当前年月日 -
String getTime()
获取当前时分秒 -
String getDateAndTime()
获取当前年月日时分秒 -
Long getTimeForLong()
获取当前时间,返回Long类型 -
String formatDate(String mDate)
转换为年月日
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中的一级字段
-
String GsonString(Object object)
转成json -
T GsonToBean(String gsonString, Class cls)
转成bean -
List GsonToList(String gsonString, Class cls)
转成list -
GsonToMaps(String gsonString)
-
int dp2px(float dp)
dp2px -
float px2dp(int px)
px2dp -
int getScreenWidth()
获取屏幕宽度 -
int getScreenHeight()
获取屏幕高度 -
int getStatusBarHeight()
获取状态栏高度 -
int getActionBarHeight()
获取ActionBar高度 -
int getNavBarHeight()
获取导航栏高度
- Upgrade gradle version to 7.5
- Upgrade targetSdkVersion 30 to 31
- Upgrade gradle to 6.7.1
- optimized code
- 优化调整
- 添加Toast扩展
- targetSdkVersion 30
- ToastUtil适配Android 11
#YUtils
-keep class com.yechaoa.yutils.**{*;}
- 我的博客:
- 我的邮箱:[email protected]
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.