Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sobot_module_Dev
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sobot_android
Sobot_module_Dev
Commits
1945a1bb
Commit
1945a1bb
authored
Apr 22, 2022
by
郑娜伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils 1.1.0
parent
f0b62a35
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
3 deletions
+136
-3
sobot-utils-publish-mavencentral.gradle
sobot_utils/sobot-utils-publish-mavencentral.gradle
+1
-1
SobotMD5Util.java
sobot_utils/src/main/java/com/sobot/utils/SobotMD5Util.java
+26
-0
SobotSharedPreferencesUtil.java
...main/java/com/sobot/utils/SobotSharedPreferencesUtil.java
+15
-2
SobotSoftKeyboardUtils.java
...src/main/java/com/sobot/utils/SobotSoftKeyboardUtils.java
+94
-0
No files found.
sobot_utils/sobot-utils-publish-mavencentral.gradle
View file @
1945a1bb
...
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'utils'
//项目名
PUBLISH_VERSION
=
'1.1'
//版本号
PUBLISH_VERSION
=
'1.1
.0
'
//版本号
}
...
...
sobot_utils/src/main/java/com/sobot/utils/SobotMD5Util.java
0 → 100644
View file @
1945a1bb
package
com
.
sobot
.
utils
;
import
java.security.MessageDigest
;
public
class
SobotMD5Util
{
public
static
String
encode
(
String
str
)
{
try
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
bytes
=
digest
.
digest
(
str
.
getBytes
());
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
b
:
bytes
)
{
int
c
=
b
&
0xff
;
//负数转换成正数
String
result
=
Integer
.
toHexString
(
c
);
//把十进制的数转换成十六进制的书
if
(
result
.
length
()
<
2
)
{
sb
.
append
(
0
);
//让十六进制全部都是两位数
}
sb
.
append
(
result
);
}
return
sb
.
toString
();
//返回加密后的密文
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
return
""
;
}
}
}
\ No newline at end of file
sobot_utils/src/main/java/com/sobot/utils/SobotSharedPreferencesUtil.java
View file @
1945a1bb
...
...
@@ -230,10 +230,23 @@ public class SobotSharedPreferencesUtil {
}
/**
* 清除SharedPreferences全部保存数据<br>
* 删除一条数据
*/
public
void
remove
(
String
key
)
{
SharedPreferences
.
Editor
edit
=
preferences
.
edit
();
if
(
edit
!=
null
)
{
edit
.
remove
(
key
);
}
}
/**
* 清除全部保存数据
*/
public
void
clearAll
()
{
preferences
.
edit
().
clear
().
apply
();
SharedPreferences
.
Editor
edit
=
preferences
.
edit
();
if
(
edit
!=
null
)
{
edit
.
clear
();
}
}
}
sobot_utils/src/main/java/com/sobot/utils/SobotSoftKeyboardUtils.java
0 → 100644
View file @
1945a1bb
package
com
.
sobot
.
utils
;
import
android.app.Activity
;
import
android.graphics.Rect
;
import
android.os.Build
;
import
android.text.InputType
;
import
android.view.View
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.EditText
;
import
java.lang.reflect.Method
;
/**
* 软件键盘管理
* 如果需要按钮控制键盘显示或隐藏状态,前提条件必须要有焦点,不然则无效
*/
public
class
SobotSoftKeyboardUtils
{
/**
* 键盘状态
*
* @param activity
* @return true显示 false隐藏
*/
public
static
boolean
getSoftKeyboardStatus
(
Activity
activity
)
{
//获取当前屏幕内容的高度
int
screenHeight
=
activity
.
getWindow
().
getDecorView
().
getHeight
();
//获取View可见区域的bottom
Rect
rect
=
new
Rect
();
activity
.
getWindow
().
getDecorView
().
getWindowVisibleDisplayFrame
(
rect
);
return
screenHeight
-
rect
.
bottom
!=
0
;
}
/**
* 根据键盘状态显示或隐藏键盘
*
* @param activity
*/
public
static
void
showOrHideSoftKeyboard
(
Activity
activity
)
{
if
(
getSoftKeyboardStatus
(
activity
))
{
hideKeyboard
(
activity
);
}
else
{
showSoftKeyboard
(
activity
);
}
}
/**
* 软键盘显示
*
* @param activity
*/
public
static
void
showSoftKeyboard
(
Activity
activity
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
);
View
view
=
activity
.
getCurrentFocus
();
if
(
view
==
null
)
{
view
=
new
View
(
activity
);
}
imm
.
showSoftInput
(
view
,
InputMethodManager
.
SHOW_FORCED
);
}
/**
* 软键盘隐藏
*/
public
static
void
hideKeyboard
(
Activity
activity
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
);
View
view
=
activity
.
getCurrentFocus
();
if
(
view
==
null
)
{
view
=
new
View
(
activity
);
}
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
}
/**
* edit获取焦点但不显示软键盘
*
* @param editText
*/
public
static
void
disableShowInput
(
EditText
editText
)
{
if
(
Build
.
VERSION
.
SDK_INT
<=
10
)
{
editText
.
setInputType
(
InputType
.
TYPE_NULL
);
}
else
{
Class
<
EditText
>
cls
=
EditText
.
class
;
Method
method
;
try
{
method
=
cls
.
getMethod
(
"setShowSoftInputOnFocus"
,
boolean
.
class
);
method
.
setAccessible
(
true
);
method
.
invoke
(
editText
,
false
);
}
catch
(
Exception
e
)
{
//TODO: handle exception
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment