Commit 1945a1bb by 郑娜伟

utils 1.1.0

parent f0b62a35
......@@ -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' //版本号
}
......
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
......@@ -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();
}
}
}
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
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment