DevUtils Github
Dev 工具类链式调用 Helper 类 -> DevHelper.java
方法注释
get获取单例 DevHelperviewHelper获取 ViewHelperdevHelper获取 DevHelperpostRunnable在主线程 Handler 中执行任务removeRunnable在主线程 Handler 中清除任务startTimer运行定时器closeTimer关闭定时器recycleBitmap 通知回收saveBitmapToSDCardJPEG保存图片到 SDCard - JPEGsaveBitmapToSDCardPNG保存图片到 SDCard - PNGsaveBitmapToSDCardWEBP保存图片到 SDCard - WEBPsaveBitmapToSDCard保存图片到 SDCardaddTextChangedListener添加输入监听事件removeTextChangedListener移除输入监听事件setKeyListener设置 KeyListenerrecord日志记录cleanInternalCache清除内部缓存 - path /data/data/package/cachecleanInternalFiles清除内部文件 - path /data/data/package/filescleanInternalDbs清除内部数据库 - path /data/data/package/databasescleanInternalDbByName根据名称清除数据库 - path /data/data/package/databases/dbNamecleanInternalSp清除内部 SP - path /data/data/package/shared_prefscleanExternalCache清除外部缓存 - path /storage/emulated/0/android/data/package/cachecleanCustomDir清除自定义路径下的文件, 使用需小心请不要误删, 而且只支持目录下的文件删除cleanApplicationData清除本应用所有的数据copyText复制文本到剪贴板copyUri复制 URI 到剪贴板copyIntent复制意图到剪贴板notifyMediaStore通知刷新本地资源insertImageIntoMediaStore添加图片到系统相册 ( 包含原图、相册图, 会存在两张 ) - 想要一张, 直接调用 notifyMediaStore()insertVideoIntoMediaStore添加视频到系统相册insertIntoMediaStore保存到系统相册showDialog显示 DialogcloseDialog关闭 DialogcloseDialogs关闭多个 DialogclosePopupWindow关闭 PopupWindowclosePopupWindows关闭多个 PopupWindowautoCloseDialog自动关闭 dialogautoClosePopupWindow自动关闭 PopupWindowopenKeyboard打开软键盘closeKeyboard关闭软键盘closeKeyBoardSpecial关闭软键盘 - 特殊处理judgeView设置某个 View 内所有非 EditText 的子 View OnTouchListener 事件registerSoftInputChangedListener注册软键盘改变监听registerSoftInputChangedListener2注册软键盘改变监听applyLanguage修改系统语言 (APP 多语言, 单独改变 APP 语言 )setOnClicks设置点击事件setOnLongClicks设置长按事件addTouchArea增加控件的触摸范围, 最大范围只能是父布局所包含的的区域cancelAllNotification移除通知 - 移除所有通知 ( 只是针对当前 Context 下的 Notification)cancelNotification移除通知 - 移除标记为 id 的通知 ( 只是针对当前 Context 下的所有 Notification)notifyNotification进行通知saveAssetsFormFile获取 Assets 资源文件数据并保存到本地saveRawFormFile获取 Raw 资源文件数据并保存到本地setWindowSecure设置禁止截屏setFullScreen设置屏幕为全屏setLandscape设置屏幕为横屏setPortrait设置屏幕为竖屏toggleScreenOrientation切换屏幕方向forceGetViewSize在 onCreate 中获取视图的尺寸 - 需回调 onGetSizeListener 接口, 在 onGetSize 中获取 View 宽高vibrate震动cancel取消震动closeIO关闭 IOcloseIOQuietly安静关闭 IOgetNetTime获取网络时间 - 默认使用百度链接waitForEndAsyn设置等待一段时间后, 通知方法 ( 异步 )waitForEnd设置等待一段时间后, 通知方法 ( 同步 )setAnimationListener设置动画事件
package dev
.utils
.app
.helper
;
import android
.annotation
.SuppressLint
;
import android
.app
.Activity
;
import android
.app
.Dialog
;
import android
.app
.Notification
;
import android
.content
.Context
;
import android
.content
.Intent
;
import android
.graphics
.Bitmap
;
import android
.net
.Uri
;
import android
.os
.Handler
;
import android
.support
.annotation
.IntRange
;
import android
.support
.annotation
.RawRes
;
import android
.support
.v4
.app
.DialogFragment
;
import android
.text
.TextWatcher
;
import android
.text
.method
.KeyListener
;
import android
.view
.View
;
import android
.view
.animation
.Animation
;
import android
.widget
.EditText
;
import android
.widget
.PopupWindow
;
import java
.io
.Closeable
;
import java
.io
.File
;
import java
.util
.Locale
;
import dev
.utils
.app
.AnalysisRecordUtils
;
import dev
.utils
.app
.CleanUtils
;
import dev
.utils
.app
.ClickUtils
;
import dev
.utils
.app
.ClipboardUtils
;
import dev
.utils
.app
.ContentResolverUtils
;
import dev
.utils
.app
.DialogUtils
;
import dev
.utils
.app
.EditTextUtils
;
import dev
.utils
.app
.HandlerUtils
;
import dev
.utils
.app
.KeyBoardUtils
;
import dev
.utils
.app
.LanguageUtils
;
import dev
.utils
.app
.ListenerUtils
;
import dev
.utils
.app
.NotificationUtils
;
import dev
.utils
.app
.ResourceUtils
;
import dev
.utils
.app
.ScreenUtils
;
import dev
.utils
.app
.SizeUtils
;
import dev
.utils
.app
.VibrationUtils
;
import dev
.utils
.app
.anim
.AnimationUtils
;
import dev
.utils
.app
.assist
.manager
.TimerManager
;
import dev
.utils
.app
.image
.BitmapUtils
;
import dev
.utils
.app
.image
.ImageUtils
;
import dev
.utils
.common
.CloseUtils
;
import dev
.utils
.common
.HttpURLConnectionUtils
;
import dev
.utils
.common
.assist
.TimeKeeper
;
public final class DevHelper {
private TimeKeeper mTimeKeeper
= new TimeKeeper();
private static final DevHelper HELPER
= new DevHelper();
public static DevHelper
get() {
return HELPER
;
}
public ViewHelper
viewHelper() {
return ViewHelper
.get();
}
public DevHelper
devHelper() {
return this;
}
public DevHelper
postRunnable(final Runnable runnable
) {
HandlerUtils
.postRunnable(runnable
);
return this;
}
public DevHelper
postRunnable(final Runnable runnable
, final long delayMillis
) {
HandlerUtils
.postRunnable(runnable
, delayMillis
);
return this;
}
public DevHelper
postRunnable(final Runnable runnable
, final long delayMillis
, final int number
, final int interval
) {
HandlerUtils
.postRunnable(runnable
, delayMillis
, number
, interval
);
return this;
}
public DevHelper
postRunnable(final Runnable runnable
, final long delayMillis
, final int number
, final int interval
, final HandlerUtils
.OnEndListener onEndListener
) {
HandlerUtils
.postRunnable(runnable
, delayMillis
, number
, interval
, onEndListener
);
return this;
}
public DevHelper
removeRunnable(final Runnable runnable
) {
HandlerUtils
.removeRunnable(runnable
);
return this;
}
public DevHelper
startTimer(final TimerManager
.AbsTimer timer
) {
if (timer
!= null
) timer
.startTimer();
return this;
}
public DevHelper
closeTimer(final TimerManager
.AbsTimer timer
) {
if (timer
!= null
) timer
.closeTimer();
return this;
}
public DevHelper
recycle(final Bitmap bitmap
) {
BitmapUtils
.recycle(bitmap
);
return this;
}
public DevHelper
saveBitmapToSDCardJPEG(final Bitmap bitmap
, final String filePath
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.JPEG
, 100);
}
public DevHelper
saveBitmapToSDCardJPEG(final Bitmap bitmap
, final File file
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.JPEG
, 100);
}
public DevHelper
saveBitmapToSDCardJPEG(final Bitmap bitmap
, final String filePath
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.JPEG
, quality
);
}
public DevHelper
saveBitmapToSDCardJPEG(final Bitmap bitmap
, final File file
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.JPEG
, quality
);
}
public DevHelper
saveBitmapToSDCardPNG(final Bitmap bitmap
, final String filePath
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.PNG
, 100);
}
public DevHelper
saveBitmapToSDCardPNG(final Bitmap bitmap
, final File file
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.PNG
, 100);
}
public DevHelper
saveBitmapToSDCardPNG(final Bitmap bitmap
, final String filePath
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.PNG
, quality
);
}
public DevHelper
saveBitmapToSDCardPNG(final Bitmap bitmap
, final File file
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.PNG
, quality
);
}
public DevHelper
saveBitmapToSDCardWEBP(final Bitmap bitmap
, final String filePath
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.WEBP
, 100);
}
public DevHelper
saveBitmapToSDCardWEBP(final Bitmap bitmap
, final File file
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.WEBP
, 100);
}
public DevHelper
saveBitmapToSDCardWEBP(final Bitmap bitmap
, final String filePath
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, filePath
, Bitmap
.CompressFormat
.WEBP
, quality
);
}
public DevHelper
saveBitmapToSDCardWEBP(final Bitmap bitmap
, final File file
,
@IntRange(from
= 0, to
= 100) final int quality
) {
return saveBitmapToSDCard(bitmap
, file
, Bitmap
.CompressFormat
.WEBP
, quality
);
}
public DevHelper
saveBitmapToSDCard(final Bitmap bitmap
, final String filePath
, final Bitmap
.CompressFormat format
,
@IntRange(from
= 0, to
= 100) final int quality
) {
ImageUtils
.saveBitmapToSDCard(bitmap
, filePath
, format
, quality
);
return this;
}
public DevHelper
saveBitmapToSDCard(final Bitmap bitmap
, final File file
, final Bitmap
.CompressFormat format
,
@IntRange(from
= 0, to
= 100) final int quality
) {
ImageUtils
.saveBitmapToSDCard(bitmap
, file
, format
, quality
);
return this;
}
public DevHelper
addTextChangedListener(final EditText editText
, final TextWatcher watcher
) {
EditTextUtils
.addTextChangedListener(editText
, watcher
);
return this;
}
public DevHelper
removeTextChangedListener(final EditText editText
, final TextWatcher watcher
) {
EditTextUtils
.removeTextChangedListener(editText
, watcher
);
return this;
}
public DevHelper
setKeyListener(final EditText editText
, final KeyListener keyListener
) {
EditTextUtils
.setKeyListener(editText
, keyListener
);
return this;
}
public DevHelper
setKeyListener(final EditText editText
, final String accepted
) {
EditTextUtils
.setKeyListener(editText
, accepted
);
return this;
}
public DevHelper
setKeyListener(final EditText editText
, final char[] accepted
) {
EditTextUtils
.setKeyListener(editText
, accepted
);
return this;
}
public DevHelper
record(final AnalysisRecordUtils
.FileInfo fileInfo
, final String
... logs
) {
AnalysisRecordUtils
.record(fileInfo
, logs
);
return this;
}
public DevHelper
cleanInternalCache() {
CleanUtils
.cleanInternalCache();
return this;
}
public DevHelper
cleanInternalFiles() {
CleanUtils
.cleanInternalFiles();
return this;
}
public DevHelper
cleanInternalDbs() {
CleanUtils
.cleanInternalDbs();
return this;
}
public DevHelper
cleanInternalDbByName(final String dbName
) {
CleanUtils
.cleanInternalDbByName(dbName
);
return this;
}
public DevHelper
cleanInternalSp() {
CleanUtils
.cleanInternalSp();
return this;
}
public DevHelper
cleanExternalCache() {
CleanUtils
.cleanExternalCache();
return this;
}
public DevHelper
cleanCustomDir(final String filePath
) {
CleanUtils
.cleanCustomDir(filePath
);
return this;
}
public DevHelper
cleanCustomDir(final File file
) {
CleanUtils
.cleanCustomDir(file
);
return this;
}
public DevHelper
cleanApplicationData(final String
... filePaths
) {
CleanUtils
.cleanApplicationData(filePaths
);
return this;
}
public DevHelper
copyText(final CharSequence text
) {
ClipboardUtils
.copyText(text
);
return this;
}
public DevHelper
copyUri(final Uri uri
) {
ClipboardUtils
.copyUri(uri
);
return this;
}
public DevHelper
copyIntent(final Intent intent
) {
ClipboardUtils
.copyIntent(intent
);
return this;
}
public DevHelper
notifyMediaStore(final File file
) {
ContentResolverUtils
.notifyMediaStore(file
);
return this;
}
public DevHelper
insertImageIntoMediaStore(final File file
, final String fileName
, final boolean isNotify
) {
ContentResolverUtils
.insertImageIntoMediaStore(file
, fileName
, isNotify
);
return this;
}
public DevHelper
insertVideoIntoMediaStore(final File file
) {
ContentResolverUtils
.insertVideoIntoMediaStore(file
);
return this;
}
public DevHelper
insertIntoMediaStore(final File file
, final long createTime
, final boolean isVideo
, final String mimeType
) {
ContentResolverUtils
.insertIntoMediaStore(file
, createTime
, isVideo
, mimeType
);
return this;
}
public <T
extends Dialog> DevHelper
showDialog(final T dialog
) {
DialogUtils
.showDialog(dialog
);
return this;
}
public DevHelper
closeDialog(final Dialog dialog
) {
DialogUtils
.closeDialog(dialog
);
return this;
}
public DevHelper
closeDialogs(final Dialog
... dialogs
) {
DialogUtils
.closeDialogs(dialogs
);
return this;
}
public DevHelper
closeDialog(final DialogFragment dialog
) {
DialogUtils
.closeDialog(dialog
);
return this;
}
public DevHelper
closeDialogs(final DialogFragment
... dialogs
) {
DialogUtils
.closeDialogs(dialogs
);
return this;
}
public DevHelper
closePopupWindow(final PopupWindow popupWindow
) {
DialogUtils
.closePopupWindow(popupWindow
);
return this;
}
public DevHelper
closePopupWindows(final PopupWindow
... popupWindows
) {
DialogUtils
.closePopupWindows(popupWindows
);
return this;
}
public <T
extends Dialog> DevHelper
autoCloseDialog(final T dialog
, final long delayMillis
, final Handler handler
) {
DialogUtils
.autoCloseDialog(dialog
, delayMillis
, handler
);
return this;
}
public <T
extends DialogFragment> DevHelper
autoCloseDialog(final T dialog
, final long delayMillis
, final Handler handler
) {
DialogUtils
.autoCloseDialog(dialog
, delayMillis
, handler
);
return this;
}
public <T
extends PopupWindow> DevHelper
autoClosePopupWindow(final T popupWindow
, final long delayMillis
, final Handler handler
) {
DialogUtils
.autoClosePopupWindow(popupWindow
, delayMillis
, handler
);
return this;
}
public DevHelper
openKeyboard(final EditText editText
) {
KeyBoardUtils
.openKeyboard(editText
);
return this;
}
public DevHelper
openKeyboard(final EditText editText
, final Handler handler
) {
KeyBoardUtils
.openKeyboard(editText
, handler
);
return this;
}
public DevHelper
openKeyboard(final EditText editText
, final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.openKeyboard(editText
, handler
, delayMillis
);
return this;
}
public DevHelper
openKeyboard() {
KeyBoardUtils
.openKeyboard();
return this;
}
public DevHelper
openKeyboard(final Handler handler
) {
KeyBoardUtils
.openKeyboard(handler
);
return this;
}
public DevHelper
openKeyboard(final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.openKeyboard(handler
, delayMillis
);
return this;
}
public DevHelper
closeKeyboard(final EditText editText
) {
KeyBoardUtils
.closeKeyboard(editText
);
return this;
}
public DevHelper
closeKeyboard() {
KeyBoardUtils
.closeKeyboard();
return this;
}
public DevHelper
closeKeyboard(final Activity activity
) {
KeyBoardUtils
.closeKeyboard(activity
);
return this;
}
public DevHelper
closeKeyboard(final Dialog dialog
) {
KeyBoardUtils
.closeKeyboard(dialog
);
return this;
}
public DevHelper
closeKeyBoardSpecial(final EditText editText
, final Dialog dialog
) {
KeyBoardUtils
.closeKeyBoardSpecial(editText
, dialog
);
return this;
}
public DevHelper
closeKeyBoardSpecial(final EditText editText
, final Dialog dialog
, final Handler handler
) {
KeyBoardUtils
.closeKeyBoardSpecial(editText
, dialog
, handler
);
return this;
}
public DevHelper
closeKeyBoardSpecial(final EditText editText
, final Dialog dialog
, final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.closeKeyBoardSpecial(editText
, dialog
, handler
, delayMillis
);
return this;
}
public DevHelper
closeKeyboard(final EditText editText
, final Handler handler
) {
KeyBoardUtils
.closeKeyboard(editText
, handler
);
return this;
}
public DevHelper
closeKeyboard(final EditText editText
, final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.closeKeyboard(editText
, handler
, delayMillis
);
return this;
}
public DevHelper
closeKeyboard(final Handler handler
) {
KeyBoardUtils
.closeKeyboard(handler
);
return this;
}
public DevHelper
closeKeyboard(final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.closeKeyboard(handler
, delayMillis
);
return this;
}
public DevHelper
closeKeyboard(final Activity activity
, final Handler handler
) {
KeyBoardUtils
.closeKeyboard(activity
, handler
);
return this;
}
public DevHelper
closeKeyboard(final Activity activity
, final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.closeKeyboard(activity
, handler
, delayMillis
);
return this;
}
public DevHelper
closeKeyboard(final Dialog dialog
, final Handler handler
) {
KeyBoardUtils
.closeKeyboard(dialog
, handler
);
return this;
}
public DevHelper
closeKeyboard(final Dialog dialog
, final Handler handler
, final int delayMillis
) {
KeyBoardUtils
.closeKeyboard(dialog
, handler
, delayMillis
);
return this;
}
public DevHelper
judgeView(final View view
, final Activity activity
) {
KeyBoardUtils
.judgeView(view
, activity
);
return this;
}
public DevHelper
registerSoftInputChangedListener(final Activity activity
, final KeyBoardUtils
.OnSoftInputChangedListener listener
) {
KeyBoardUtils
.registerSoftInputChangedListener(activity
, listener
);
return this;
}
public DevHelper
registerSoftInputChangedListener2(final Activity activity
, final KeyBoardUtils
.OnSoftInputChangedListener listener
) {
KeyBoardUtils
.registerSoftInputChangedListener2(activity
, listener
);
return this;
}
public DevHelper
applyLanguage(final Context context
, final Locale locale
) {
LanguageUtils
.applyLanguage(context
, locale
);
return this;
}
public DevHelper
applyLanguage(final Context context
, final String language
) {
LanguageUtils
.applyLanguage(context
, language
);
return this;
}
public DevHelper
setOnClicks(final View
.OnClickListener onClickListener
, final View
... views
) {
ListenerUtils
.setOnClicks(onClickListener
, views
);
return this;
}
public DevHelper
setOnLongClicks(final View
.OnLongClickListener onLongClickListener
, final View
... views
) {
ListenerUtils
.setOnLongClicks(onLongClickListener
, views
);
return this;
}
public DevHelper
addTouchArea(final View view
, final int range
) {
ClickUtils
.addTouchArea(view
, range
);
return this;
}
public DevHelper
addTouchArea(final View view
, final int top
, final int bottom
, final int left
, final int right
) {
ClickUtils
.addTouchArea(view
, top
, bottom
, left
, right
);
return this;
}
public DevHelper
cancelAllNotification() {
NotificationUtils
.cancelAll();
return this;
}
public DevHelper
cancelNotification(final int... args
) {
NotificationUtils
.cancel(args
);
return this;
}
public DevHelper
cancelNotification(final String tag
, final int id
) {
NotificationUtils
.cancel(tag
, id
);
return this;
}
public DevHelper
notifyNotification(final int id
, final Notification notification
) {
NotificationUtils
.notify(id
, notification
);
return this;
}
public DevHelper
notifyNotification(final String tag
, final int id
, final Notification notification
) {
NotificationUtils
.notify(tag
, id
, notification
);
return this;
}
public DevHelper
saveAssetsFormFile(final String fileName
, final File file
) {
ResourceUtils
.saveAssetsFormFile(fileName
, file
);
return this;
}
public DevHelper
saveRawFormFile(@RawRes final int resId
, final File file
) {
ResourceUtils
.saveRawFormFile(resId
, file
);
return this;
}
public DevHelper
setWindowSecure(final Activity activity
) {
ScreenUtils
.setWindowSecure(activity
);
return this;
}
public DevHelper
setFullScreen(final Activity activity
) {
ScreenUtils
.setFullScreen(activity
);
return this;
}
public DevHelper
setLandscape(final Activity activity
) {
ScreenUtils
.setLandscape(activity
);
return this;
}
public DevHelper
setPortrait(final Activity activity
) {
ScreenUtils
.setPortrait(activity
);
return this;
}
public DevHelper
toggleScreenOrientation(final Activity activity
) {
ScreenUtils
.toggleScreenOrientation(activity
);
return this;
}
public DevHelper
forceGetViewSize(final View view
, final SizeUtils
.onGetSizeListener listener
) {
SizeUtils
.forceGetViewSize(view
, listener
);
return this;
}
@SuppressLint("MissingPermission")
public DevHelper
vibrate(final long milliseconds
) {
VibrationUtils
.vibrate(milliseconds
);
return this;
}
@SuppressLint("MissingPermission")
public DevHelper
vibrate(final long[] pattern
, final int repeat
) {
VibrationUtils
.vibrate(pattern
, repeat
);
return this;
}
@SuppressLint("MissingPermission")
public DevHelper
cancel() {
VibrationUtils
.cancel();
return this;
}
public DevHelper
closeIO(final Closeable
... closeables
) {
CloseUtils
.closeIO(closeables
);
return this;
}
public DevHelper
closeIOQuietly(final Closeable
... closeables
) {
CloseUtils
.closeIOQuietly(closeables
);
return this;
}
public DevHelper
getNetTime(final HttpURLConnectionUtils
.TimeCallBack timeCallBack
) {
HttpURLConnectionUtils
.getNetTime(timeCallBack
);
return this;
}
public DevHelper
getNetTime(final String urlStr
, final HttpURLConnectionUtils
.TimeCallBack timeCallBack
) {
HttpURLConnectionUtils
.getNetTime(urlStr
, timeCallBack
);
return this;
}
public DevHelper
waitForEndAsyn(final long keepTimeMillis
, final TimeKeeper
.OnEndCallback endCallback
) {
mTimeKeeper
.waitForEndAsyn(keepTimeMillis
, endCallback
);
return this;
}
public DevHelper
waitForEnd(final long keepTimeMillis
, final TimeKeeper
.OnEndCallback endCallback
) {
mTimeKeeper
.waitForEnd(keepTimeMillis
, endCallback
);
return this;
}
public DevHelper
setAnimationListener(final Animation animation
, final Animation
.AnimationListener listener
) {
AnimationUtils
.setAnimationListener(animation
, listener
);
return this;
}
}