d
This commit is contained in:
671
app/src/main/java/com/fenghoo/seven/utils/AbStrUtil.java
Normal file
671
app/src/main/java/com/fenghoo/seven/utils/AbStrUtil.java
Normal file
@@ -0,0 +1,671 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
|
||||
/**
|
||||
* 描述:字符串处理类.
|
||||
*/
|
||||
public final class AbStrUtil {
|
||||
|
||||
/**
|
||||
* 描述:将null转化为“”.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 字符串的String类型
|
||||
*/
|
||||
public static String parseEmpty(String str) {
|
||||
if (str == null || "null".equals(str.trim())) {
|
||||
str = "";
|
||||
}
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:判断一个字符串是否为null或空值.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.trim().length() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串中文字符的长度(每个中文算2个字符).
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 中文字符的长度
|
||||
*/
|
||||
public static int chineseLength(String str) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
|
||||
if (!isEmpty(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
/* 获取一个字符 */
|
||||
String temp = str.substring(i, i + 1);
|
||||
/* 判断是否为中文字符 */
|
||||
if (temp.matches(chinese)) {
|
||||
valueLength += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:获取字符串的长度.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 字符串的长度(中文字符计2个)
|
||||
*/
|
||||
public static int strLength(String str) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
// 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// 获取一个字符
|
||||
String temp = str.substring(i, i + 1);
|
||||
// 判断是否为中文字符
|
||||
if (temp.matches(chinese)) {
|
||||
// 中文字符长度为2
|
||||
valueLength += 2;
|
||||
} else {
|
||||
// 其他字符长度为1
|
||||
valueLength += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:获取指定长度的字符所在位置.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @param maxL 要取到的长度(字符长度,中文字符计2个)
|
||||
* @return 字符的所在位置
|
||||
*/
|
||||
public static int subStringLength(String str, int maxL) {
|
||||
int currentIndex = 0;
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
// 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// 获取一个字符
|
||||
String temp = str.substring(i, i + 1);
|
||||
// 判断是否为中文字符
|
||||
if (temp.matches(chinese)) {
|
||||
// 中文字符长度为2
|
||||
valueLength += 2;
|
||||
} else {
|
||||
// 其他字符长度为1
|
||||
valueLength += 1;
|
||||
}
|
||||
if (valueLength >= maxL) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:手机号格式验证.
|
||||
*
|
||||
* @param str 指定的手机号码字符串
|
||||
* @return 是否为手机号码格式:是为true,否则false
|
||||
*/
|
||||
public static Boolean isMobileNo(String str) {
|
||||
Boolean isMobileNo = false;
|
||||
try {
|
||||
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0-9]))\\d{8}$");
|
||||
Matcher m = p.matcher(str);
|
||||
isMobileNo = m.matches();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return isMobileNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:是否只是字母和数字.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 是否只是字母和数字:是为true,否则false
|
||||
*/
|
||||
public static Boolean isNumberLetter(String str) {
|
||||
Boolean isNoLetter = false;
|
||||
String expr = "^[A-Za-z0-9]+$";
|
||||
if (str.matches(expr)) {
|
||||
isNoLetter = true;
|
||||
}
|
||||
return isNoLetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查价格和面积是不是符合格式
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return
|
||||
* @author 常斌
|
||||
* 2015-7-7 上午11:49:00 create
|
||||
*/
|
||||
public static Boolean isPriceOrArea(String str) {
|
||||
Boolean isPrice = false;
|
||||
String expr = "\\d{1,10}(\\.\\d{1,2})?$";
|
||||
if (str.matches(expr)) {
|
||||
isPrice = true;
|
||||
}
|
||||
return isPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是身份证号码
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return
|
||||
* @author 常斌
|
||||
* 2015-7-7 上午10:51:44 create 是否是身份证号码:是为true,不是为false
|
||||
*/
|
||||
public static Boolean isIDCardNo(String str) {
|
||||
Boolean isIDCardNo = false;
|
||||
String expr1 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";//15位的
|
||||
String expr2 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$";//18位的
|
||||
if (str.matches(expr1)) {
|
||||
isIDCardNo = true;
|
||||
} else isIDCardNo = str.matches(expr2);
|
||||
return isIDCardNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:是否只是数字.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 是否只是数字:是为true,否则false
|
||||
*/
|
||||
public static Boolean isNumber(String str) {
|
||||
Boolean isNumber = false;
|
||||
String expr = "^[0-9]+$";
|
||||
if (str.matches(expr)) {
|
||||
isNumber = true;
|
||||
}
|
||||
return isNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:是否是邮箱.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 是否是邮箱:是为true,否则false
|
||||
*/
|
||||
public static Boolean isEmail(String str) {
|
||||
Boolean isEmail = false;
|
||||
String expr = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
|
||||
if (str.matches(expr)) {
|
||||
isEmail = true;
|
||||
}
|
||||
return isEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:是否是中文.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 是否是中文:是为true,否则false
|
||||
*/
|
||||
public static Boolean isChinese(String str) {
|
||||
Boolean isChinese = true;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
// 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// 获取一个字符
|
||||
String temp = str.substring(i, i + 1);
|
||||
// 判断是否为中文字符
|
||||
if (temp.matches(chinese)) {
|
||||
} else {
|
||||
isChinese = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isChinese;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:是否包含中文.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 是否包含中文:是为true,否则false
|
||||
*/
|
||||
public static Boolean isContainChinese(String str) {
|
||||
Boolean isChinese = false;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
// 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// 获取一个字符
|
||||
String temp = str.substring(i, i + 1);
|
||||
// 判断是否为中文字符
|
||||
if (temp.matches(chinese)) {
|
||||
isChinese = true;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return isChinese;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:从输入流中获得String.
|
||||
*
|
||||
* @param is 输入流
|
||||
* @return 获得的String
|
||||
*/
|
||||
public static String convertStreamToString(InputStream is) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
|
||||
// 最后一个\n删除
|
||||
if (sb.indexOf("\n") != -1 && sb.lastIndexOf("\n") == sb.length() - 1) {
|
||||
sb.delete(sb.lastIndexOf("\n"), sb.lastIndexOf("\n") + 1);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:标准化日期时间类型的数据,不足两位的补0.
|
||||
*
|
||||
* @param dateTime 预格式的时间字符串,如:2012-3-2 12:2:20
|
||||
* @return String 格式化好的时间字符串,如:2012-03-20 12:02:20
|
||||
*/
|
||||
public static String dateTimeFormat(String dateTime) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
if (isEmpty(dateTime)) {
|
||||
return null;
|
||||
}
|
||||
String[] dateAndTime = dateTime.split(" ");
|
||||
if (dateAndTime.length > 0) {
|
||||
for (String str : dateAndTime) {
|
||||
if (str.indexOf("-") != -1) {
|
||||
String[] date = str.split("-");
|
||||
for (int i = 0; i < date.length; i++) {
|
||||
String str1 = date[i];
|
||||
sb.append(strFormat2(str1));
|
||||
if (i < date.length - 1) {
|
||||
sb.append("-");
|
||||
}
|
||||
}
|
||||
} else if (str.indexOf(":") != -1) {
|
||||
String[] date = str.split(":");
|
||||
for (int i = 0; i < date.length; i++) {
|
||||
String str1 = date[i];
|
||||
sb.append(strFormat2(str1));
|
||||
if (i < date.length - 1) {
|
||||
sb.append(":");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:不足2个字符的在前面补“0”.
|
||||
*
|
||||
* @param str 指定的字符串
|
||||
* @return 至少2个字符的字符串
|
||||
*/
|
||||
public static String strFormat2(String str) {
|
||||
try {
|
||||
if (str.length() <= 1) {
|
||||
str = "0" + str;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:截取字符串到指定字节长度.
|
||||
*
|
||||
* @param str the str
|
||||
* @param length 指定字节长度
|
||||
* @return 截取后的字符串
|
||||
*/
|
||||
public static String cutString(String str, int length) {
|
||||
return cutString(str, length, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:截取字符串到指定字节长度.
|
||||
*
|
||||
* @param str 文本
|
||||
* @param length 字节长度
|
||||
* @param dot 省略符号
|
||||
* @return 截取后的字符串
|
||||
*/
|
||||
public static String cutString(String str, int length, String dot) {
|
||||
int strBLen = strlen(str, "GBK");
|
||||
if (strBLen <= length) {
|
||||
return str;
|
||||
}
|
||||
int temp = 0;
|
||||
StringBuffer sb = new StringBuffer(length);
|
||||
char[] ch = str.toCharArray();
|
||||
for (char c : ch) {
|
||||
sb.append(c);
|
||||
if (c > 256) {
|
||||
temp += 2;
|
||||
} else {
|
||||
temp += 1;
|
||||
}
|
||||
if (temp >= length) {
|
||||
if (dot != null) {
|
||||
sb.append(dot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:截取字符串从第一个指定字符.
|
||||
*
|
||||
* @param str1 原文本
|
||||
* @param str2 指定字符
|
||||
* @param offset 偏移的索引
|
||||
* @return 截取后的字符串
|
||||
*/
|
||||
public static String cutStringFromChar(String str1, String str2, int offset) {
|
||||
if (isEmpty(str1)) {
|
||||
return "";
|
||||
}
|
||||
int start = str1.indexOf(str2);
|
||||
if (start != -1) {
|
||||
if (str1.length() > start + offset) {
|
||||
return str1.substring(start + offset);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:获取字节长度.
|
||||
*
|
||||
* @param str 文本
|
||||
* @param charset 字符集(GBK)
|
||||
* @return the int
|
||||
*/
|
||||
public static int strlen(String str, String charset) {
|
||||
if (str == null || str.length() == 0) {
|
||||
return 0;
|
||||
}
|
||||
int length = 0;
|
||||
try {
|
||||
length = str.getBytes(charset).length;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取大小的描述.
|
||||
*
|
||||
* @param size 字节个数
|
||||
* @return 大小的描述
|
||||
*/
|
||||
public static String getSizeDesc(long size) {
|
||||
String suffix = "B";
|
||||
if (size >= 1024) {
|
||||
suffix = "K";
|
||||
size = size >> 10;
|
||||
if (size >= 1024) {
|
||||
suffix = "M";
|
||||
// size /= 1024;
|
||||
size = size >> 10;
|
||||
if (size >= 1024) {
|
||||
suffix = "G";
|
||||
size = size >> 10;
|
||||
// size /= 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
return size + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:ip地址转换为10进制数.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the long
|
||||
*/
|
||||
public static long ip2int(String ip) {
|
||||
ip = ip.replace(".", ",");
|
||||
String[] items = ip.split(",");
|
||||
return Long.valueOf(items[0]) << 24 | Long.valueOf(items[1]) << 16 | Long.valueOf(items[2]) << 8 | Long.valueOf(items[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println(dateTimeFormat("2012-3-2 12:2:20"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串数组转换为list
|
||||
*
|
||||
* @param arr 字符串数组
|
||||
* @return 2015-5-4 上午11:15:57 create
|
||||
*/
|
||||
public static List<String> arrayToList(String[] arr) {
|
||||
return Arrays.asList(arr);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Unicode编码字符串 装汉字
|
||||
// *
|
||||
// * @param utfString
|
||||
// * @return
|
||||
// * @author wop
|
||||
// * 2015-5-11 下午6:15:28 create
|
||||
// */
|
||||
// public static String convert(String utfString) {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// int i = -1;
|
||||
// int pos = 0;
|
||||
//
|
||||
// while ((i = utfString.indexOf("\\u", pos)) != -1) {
|
||||
// sb.append(utfString.substring(pos, i));
|
||||
// if (i + 5 < utfString.length()) {
|
||||
// pos = i + 6;
|
||||
// sb.append((char) Integer.parseInt(utfString.substring(i + 2, i + 6), 16));
|
||||
// }
|
||||
// }
|
||||
// return sb.toString();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 将Unicode编码解析成汉字
|
||||
*
|
||||
* @param pStr 包含(汉字的Unicode)编码的字符串
|
||||
* @return
|
||||
*/
|
||||
public static String decodeUnicode(String pStr) {
|
||||
char aChar;
|
||||
int len = pStr.length();
|
||||
StringBuffer outBuffer = new StringBuffer(len);
|
||||
for (int x = 0; x < len; ) {
|
||||
aChar = pStr.charAt(x++);
|
||||
if (aChar == '\\') {
|
||||
aChar = pStr.charAt(x++);
|
||||
if (aChar == 'u') {
|
||||
int value = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
aChar = pStr.charAt(x++);
|
||||
switch (aChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
value = (value << 4) + aChar - '0';
|
||||
break;
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
value = (value << 4) + 10 + aChar - 'a';
|
||||
break;
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'E':
|
||||
case 'F':
|
||||
value = (value << 4) + 10 + aChar - 'A';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Malformed encoding.");
|
||||
}
|
||||
}
|
||||
outBuffer.append((char) value);
|
||||
} else {
|
||||
if (aChar == 't') {
|
||||
aChar = '\t';
|
||||
} else if (aChar == 'r') {
|
||||
aChar = '\r';
|
||||
} else if (aChar == 'n') {
|
||||
aChar = '\n';
|
||||
} else if (aChar == 'f') {
|
||||
aChar = '\f';
|
||||
}
|
||||
outBuffer.append(aChar);
|
||||
}
|
||||
} else {
|
||||
outBuffer.append(aChar);
|
||||
}
|
||||
}
|
||||
return outBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串按指定的分隔符转换成String[]
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param tmp 指定的分隔符
|
||||
* @return
|
||||
* @author wop
|
||||
* 2015-5-21 上午9:59:47 create
|
||||
*/
|
||||
public static String[] getStrings(String str, String tmp) {
|
||||
String[] result = str.split(tmp);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除集合里面重复的数据
|
||||
*
|
||||
* @param li 原集合
|
||||
* @return 处理以后的集合
|
||||
*/
|
||||
public static ArrayList<String> getNewList(ArrayList<String> li) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (int i = 0; i < li.size(); i++) {
|
||||
String str = li.get(i); //获取传入集合对象的每一个元素
|
||||
if (!list.contains(str)) { //查看新集合中是否有指定的元素,如果没有则加入
|
||||
list.add(str);
|
||||
}
|
||||
}
|
||||
return list; //返回集合
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤网页标签
|
||||
*/
|
||||
public static String getHtml2Text(String inputString) {
|
||||
String htmlStr = inputString; //含html标签的字符串
|
||||
String textStr = "";
|
||||
Pattern p_script;
|
||||
Matcher m_script;
|
||||
Pattern p_style;
|
||||
Matcher m_style;
|
||||
Pattern p_html;
|
||||
Matcher m_html;
|
||||
try {
|
||||
String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
|
||||
String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style> }
|
||||
String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
|
||||
|
||||
p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
|
||||
m_script = p_script.matcher(htmlStr);
|
||||
htmlStr = m_script.replaceAll(""); //过滤script标签
|
||||
|
||||
p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
|
||||
m_style = p_style.matcher(htmlStr);
|
||||
htmlStr = m_style.replaceAll(""); //过滤style标签
|
||||
|
||||
p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
|
||||
m_html = p_html.matcher(htmlStr);
|
||||
htmlStr = m_html.replaceAll(""); //过滤html标签
|
||||
|
||||
textStr = htmlStr;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Html2Text: " + e.getMessage());
|
||||
}
|
||||
|
||||
return textStr;//返回文本字符串
|
||||
}
|
||||
|
||||
}
|
||||
177
app/src/main/java/com/fenghoo/seven/utils/BaseAdapter.java
Normal file
177
app/src/main/java/com/fenghoo/seven/utils/BaseAdapter.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseAdapter<T> extends android.widget.BaseAdapter {
|
||||
protected LayoutInflater mInflater;
|
||||
protected Context mContext;
|
||||
protected SparseArray<View> viewHolder;
|
||||
protected IAdpListener mListener;
|
||||
protected final List<T> mList = new ArrayList<T>();
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param dataList
|
||||
*/
|
||||
public BaseAdapter(Context context) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.mContext = context;
|
||||
this.mInflater = LayoutInflater.from(mContext);
|
||||
}
|
||||
|
||||
public void setAdpListener(IAdpListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
return mList;
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
mList.clear();
|
||||
mList.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void appendToList(List<T> list) {
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
mList.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void appendToTopList(List<T> list) {
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
mList.addAll(0, list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mList.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mList == null ? 0 : mList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getItem(int position) {
|
||||
return mList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getConvertView(position, convertView, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* getConvertView
|
||||
*
|
||||
* @param position
|
||||
* @param convertView
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
protected abstract View getConvertView(int position, View convertView,
|
||||
ViewGroup parent);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "hiding" })
|
||||
protected <T extends View> T Get(View view, int id) {
|
||||
viewHolder = (SparseArray<View>) view.getTag();
|
||||
if (viewHolder == null) {
|
||||
viewHolder = new SparseArray<View>();
|
||||
view.setTag(viewHolder);
|
||||
}
|
||||
View childView = viewHolder.get(id);
|
||||
if (childView == null) {
|
||||
childView = view.findViewById(id);
|
||||
viewHolder.put(id, childView);
|
||||
}
|
||||
return (T) childView;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @param id
|
||||
* @param text
|
||||
*/
|
||||
protected void setText(View v, String text) {
|
||||
if(v==null)
|
||||
return ;
|
||||
if (TextUtils.isEmpty(text))
|
||||
text = "";
|
||||
if (v instanceof TextView) {// TextView
|
||||
((TextView) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
((Button) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
((CheckBox) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
((RadioButton) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
((EditText) v).setText(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: IAdpListener
|
||||
* @Description: TODO(描述: )
|
||||
* @author Lijc
|
||||
* @Company: BlueMobi
|
||||
* @date 2015<31>?5<>?5<>? 上午10:00:15
|
||||
* @version V1.0
|
||||
*/
|
||||
public interface IAdpListener {
|
||||
/**
|
||||
* Item点击事件
|
||||
*
|
||||
* @param data
|
||||
* 数据
|
||||
* @param flag
|
||||
* 事件标志
|
||||
* @param position
|
||||
* 位置
|
||||
*/
|
||||
public void onItemEvent(Object data, int flag, int position);
|
||||
}
|
||||
}
|
||||
42
app/src/main/java/com/fenghoo/seven/utils/DensityUtil.java
Normal file
42
app/src/main/java/com/fenghoo/seven/utils/DensityUtil.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
|
||||
public class DensityUtil {
|
||||
private DensityUtil() {
|
||||
throw new UnsupportedOperationException("cannot be instantiated");
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*/
|
||||
public static int dp2px(Context context, float dpVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
dpVal, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
* sp转px
|
||||
*/
|
||||
public static int sp2px(Context context, float spVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
|
||||
spVal, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
* px转dp
|
||||
*/
|
||||
public static float px2dp(Context context, float pxVal) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (pxVal / scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* px转sp
|
||||
*/
|
||||
public static float px2sp(Context context, float pxVal) {
|
||||
return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);
|
||||
}
|
||||
|
||||
}
|
||||
666
app/src/main/java/com/fenghoo/seven/utils/GlideTools.java
Normal file
666
app/src/main/java/com/fenghoo/seven/utils/GlideTools.java
Normal file
@@ -0,0 +1,666 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* @ ClassName: XGlide .class
|
||||
* @ function:图片加载类
|
||||
* @ author linzl 2017/1/23 10:24
|
||||
* @ version 1.0
|
||||
*/
|
||||
|
||||
public class GlideTools {
|
||||
|
||||
private static GlideTools singleton;
|
||||
private static Context mCtx;
|
||||
private static RequestManager glideRequest;
|
||||
private boolean isDiskCache = true;
|
||||
|
||||
public static GlideTools init(Context ctx) {
|
||||
mCtx=ctx;
|
||||
glideRequest = Glide.with(ctx);
|
||||
// TODO 双重校验锁
|
||||
if (null == singleton)
|
||||
synchronized (GlideTools.class) {
|
||||
if (null == singleton) {
|
||||
singleton = new GlideTools();
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDiskCache(boolean isCache) {
|
||||
this.isDiskCache = isCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* url
|
||||
*
|
||||
* @param iv
|
||||
* @param url
|
||||
*/
|
||||
// public void display(ImageView iv, String url) {
|
||||
// display(iv, url, -1);
|
||||
// }
|
||||
public void display(ImageView iv, String url) {
|
||||
glideRequest.load(url).into(iv);
|
||||
}
|
||||
/**
|
||||
* url
|
||||
*
|
||||
* @param iv
|
||||
* @param url
|
||||
* @param defaultResId
|
||||
*/
|
||||
// public void display(ImageView iv, String url, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<String> builder = glideRequest.load(url);
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
*/
|
||||
public void display(ImageView iv, Uri uri) {
|
||||
display(iv, uri, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void display(ImageView iv, Uri uri, int defaultResId) {
|
||||
if (iv == null)
|
||||
return;
|
||||
// DrawableRequestBuilder<Uri> builder = glideRequest.load(uri);
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId);
|
||||
glideRequest.load(uri).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
*/
|
||||
public void display(ImageView iv, int drawableId) {
|
||||
display(iv, drawableId, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void display(ImageView iv, int drawableId, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<Integer> builder = glideRequest.load(drawableId);
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId);
|
||||
glideRequest.load(drawableId).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
*/
|
||||
public void display(ImageView iv, File imgFile) {
|
||||
display(iv, imgFile, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void display(ImageView iv, File imgFile, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<File> builder = glideRequest.load(imgFile);
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId);
|
||||
glideRequest.load(imgFile).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* byte[]
|
||||
*
|
||||
* @ param iv
|
||||
* @ param modle
|
||||
*/
|
||||
public void display(ImageView iv, byte[] modle) {
|
||||
display(iv, modle, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* byte[]
|
||||
*
|
||||
* @ param iv
|
||||
* @ param modle
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void display(ImageView iv, byte[] modle, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<byte[]> builder = glideRequest.load(modle);
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId);
|
||||
glideRequest.load(modle).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ///圆角图片--------------------------------------------------------------------
|
||||
/**
|
||||
* 圆角-Url
|
||||
*
|
||||
* @ param iv
|
||||
* @ param url
|
||||
* @ param roundDip
|
||||
*/
|
||||
public void displayRound(ImageView iv, String url, int roundDip) {
|
||||
displayRound(iv, url, roundDip, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-Url
|
||||
*
|
||||
* @ param iv
|
||||
* @ param url
|
||||
* @ param roundDip
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayRound(ImageView iv, String url, int roundDip, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<String> builder = glideRequest.load(url).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
glideRequest.load(url).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
* @ param roundDip
|
||||
*/
|
||||
public void displayRound(ImageView iv, int drawableId, int roundDip) {
|
||||
displayRound(iv, drawableId, roundDip, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
* @ param roundDip
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayRound(ImageView iv, int drawableId, int roundDip, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<Integer> builder = glideRequest.load(drawableId).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
glideRequest.load(drawableId).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
* @ param roundDip
|
||||
*/
|
||||
public void displayRound(ImageView iv, Uri uri, int roundDip) {
|
||||
displayRound(iv, uri, roundDip, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
* @ param roundDip
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayRound(ImageView iv, Uri uri, int roundDip, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<Uri> builder = glideRequest.load(uri).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
glideRequest.load(uri).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
* @ param roundDip
|
||||
*/
|
||||
public void displayRound(ImageView iv, File imgFile, int roundDip) {
|
||||
displayRound(iv, imgFile, roundDip, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角-File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
* @ param roundDip
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayRound(ImageView iv, File imgFile, int roundDip, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<File> builder = glideRequest.load(imgFile).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx, roundDip));
|
||||
glideRequest.load(imgFile).apply(options).into(iv);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 圆图片
|
||||
/**
|
||||
* 圆图片-drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
*/
|
||||
public void displayCircle(ImageView iv, int drawableId) {
|
||||
displayCircle(iv, drawableId, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-drawableId
|
||||
*
|
||||
* @ param iv
|
||||
* @ param drawableId
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayCircle(ImageView iv, int drawableId, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<Integer> builder = glideRequest.load(drawableId).transform(new GlideCircleTransform(mCtx));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx));
|
||||
glideRequest.load(drawableId).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
public void displaypic(ImageView iv, String url, int defaultResId) {
|
||||
RequestOptions options = new RequestOptions()
|
||||
.centerCrop()
|
||||
.placeholder(defaultResId)
|
||||
.error(defaultResId)
|
||||
.priority(Priority.HIGH);
|
||||
Glide.with(mCtx).load(url).apply(options).into(iv);
|
||||
}
|
||||
/**
|
||||
* 圆图片-url
|
||||
*
|
||||
* @ param iv
|
||||
* @ param url
|
||||
*/
|
||||
public void displayCircle(ImageView iv, String url) {
|
||||
displayCircle(iv, url, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-url
|
||||
*
|
||||
* @ param iv
|
||||
* @ param url
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayCircle(ImageView iv, String url, int defaultResId) {
|
||||
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx));
|
||||
glideRequest.load(url).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
*/
|
||||
public void displayCircle(ImageView iv, Uri uri) {
|
||||
displayCircle(iv, uri, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-Uri
|
||||
*
|
||||
* @ param iv
|
||||
* @ param uri
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayCircle(ImageView iv, Uri uri, int defaultResId) {
|
||||
// if (iv == null)
|
||||
// return;
|
||||
// DrawableRequestBuilder<Uri> builder = glideRequest.load(uri).transform(new GlideCircleTransform(mCtx));
|
||||
// if (defaultResId != -1)
|
||||
// builder.placeholder(defaultResId);
|
||||
// if (isDiskCache)
|
||||
// builder.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
// builder.into(iv);
|
||||
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx));
|
||||
glideRequest.load(uri).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
*/
|
||||
public void displayCircle(ImageView iv, File imgFile) {
|
||||
displayCircle(iv, imgFile, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片-File
|
||||
*
|
||||
* @ param iv
|
||||
* @ param imgFile
|
||||
* @ param defaultResId
|
||||
*/
|
||||
public void displayCircle(ImageView iv, File imgFile, int defaultResId) {
|
||||
|
||||
if (iv == null)
|
||||
return;
|
||||
if (defaultResId != -1){
|
||||
RequestOptions options = new RequestOptions().placeholder(defaultResId).transform(new GlideRoundTransform(mCtx));
|
||||
glideRequest.load(imgFile).apply(options).into(iv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 下载图片获取地址 */
|
||||
public String downloadPath(String url) {
|
||||
try {
|
||||
File file = glideRequest.load(url).downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
|
||||
return file.getPath();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return "";
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载图片 */
|
||||
public File downloadFile(String url) {
|
||||
try {
|
||||
File file = glideRequest.load(url).downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
|
||||
return file;
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除图片缓存
|
||||
*/
|
||||
public void Clear() {
|
||||
Glide.get(mCtx).clearDiskCache();
|
||||
Glide.get(mCtx).clearMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆图片
|
||||
*/
|
||||
public class GlideCircleTransform extends BitmapTransformation {
|
||||
public GlideCircleTransform(Context context) {
|
||||
// super(context);
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
|
||||
return circleCrop(pool, toTransform);
|
||||
}
|
||||
|
||||
private Bitmap circleCrop(BitmapPool pool, Bitmap source) {
|
||||
if (source == null)
|
||||
return null;
|
||||
|
||||
int size = Math.min(source.getWidth(), source.getHeight());
|
||||
int x = (source.getWidth() - size) / 2;
|
||||
int y = (source.getHeight() - size) / 2;
|
||||
|
||||
// TODO this could be acquired from the pool too
|
||||
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
|
||||
|
||||
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
|
||||
if (result == null) {
|
||||
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(result);
|
||||
Paint paint = new Paint();
|
||||
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
|
||||
paint.setAntiAlias(true);
|
||||
float r = size / 2f;
|
||||
canvas.drawCircle(r, r, r, paint);
|
||||
return result;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getId() {
|
||||
// return getClass().getName();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆角头像
|
||||
*/
|
||||
public class GlideRoundTransform extends BitmapTransformation {
|
||||
|
||||
private float radius = 0f;
|
||||
|
||||
public GlideRoundTransform(Context context) {
|
||||
this(context, 4);
|
||||
}
|
||||
|
||||
public GlideRoundTransform(Context context, int dp) {
|
||||
// super(context);
|
||||
super();
|
||||
this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
|
||||
return roundCrop(pool, toTransform);
|
||||
}
|
||||
|
||||
private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
|
||||
if (source == null)
|
||||
return null;
|
||||
|
||||
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
if (result == null) {
|
||||
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(result);
|
||||
Paint paint = new Paint();
|
||||
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
|
||||
paint.setAntiAlias(true);
|
||||
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
|
||||
canvas.drawRoundRect(rectF, radius, radius, paint);
|
||||
return result;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getId() {
|
||||
// return getClass().getName() + Math.round(radius);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
172
app/src/main/java/com/fenghoo/seven/utils/LocatData.java
Normal file
172
app/src/main/java/com/fenghoo/seven/utils/LocatData.java
Normal file
@@ -0,0 +1,172 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import com.fenghoo.seven.BaseApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LocatData {
|
||||
/** Shared */
|
||||
public static final String APP_SHARED_NAME = "svojcll.shared";
|
||||
/** */
|
||||
public static final String APP_SOSO_HISTORY_POST = "data.soso.history.post";
|
||||
/** */
|
||||
public static final String APP_SOSO_HISTORY_GOOD = "data.soso.history.good";
|
||||
/** */
|
||||
public static final String APP_LOGIN = "data.login.infor";
|
||||
/** */
|
||||
public static final String APP_USER = "data.user.infor";
|
||||
// 单例模式
|
||||
private static LocatData instance;
|
||||
|
||||
|
||||
/** */
|
||||
public static final String AD_IMG_URL = "data.ad.img.urls";
|
||||
/** */
|
||||
public static final String AD_IMG_PATH = "data.ad.img.path";
|
||||
|
||||
public void putAdPath(String path) {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(AD_IMG_PATH, path);
|
||||
}
|
||||
|
||||
public String getAdPath() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
return sharedTools.getObject(AD_IMG_PATH, String.class);
|
||||
}
|
||||
|
||||
public void putAdUrl(String path) {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(AD_IMG_URL, path);
|
||||
}
|
||||
|
||||
public String getAdUrl() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
return sharedTools.getObject(AD_IMG_URL, String.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private LocatData() {
|
||||
}
|
||||
|
||||
public static LocatData Init() {
|
||||
// mContext = ctx;
|
||||
// TODO 双重校验锁
|
||||
if (null == instance) {
|
||||
synchronized (LocatData.class) {
|
||||
if (null == instance) {
|
||||
instance = new LocatData();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** 清空本地历史搜索 */
|
||||
public void clearPost() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(APP_SOSO_HISTORY_POST, "");
|
||||
}
|
||||
|
||||
/** 添加搜索KEY合集 */
|
||||
public void addPost(String sosoKey) {
|
||||
List<String> tempList = getPosts();
|
||||
|
||||
if (tempList.contains(sosoKey)) {
|
||||
tempList.remove(sosoKey);
|
||||
}
|
||||
tempList.add(0, sosoKey);
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
for (int i = 0; i < tempList.size(); i++) {
|
||||
sb.append(tempList.get(i));
|
||||
if (i < tempList.size() - 1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(APP_SOSO_HISTORY_POST, sb.toString());
|
||||
|
||||
}
|
||||
|
||||
/** 获取搜索KEY合集 */
|
||||
private String getPostStr() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
String temp = sharedTools
|
||||
.getObject(APP_SOSO_HISTORY_POST, String.class);
|
||||
return (null == temp || "".equals(temp) ? "" : temp);
|
||||
}
|
||||
|
||||
/** 获取搜索KEY合集 */
|
||||
public List<String> getPosts() {
|
||||
String temp = getPostStr();
|
||||
if ("".equals(temp)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
List<String> tempList = new ArrayList<String>();
|
||||
String[] str = temp.split(",");
|
||||
for (int i = 0; i < str.length; i++) {
|
||||
tempList.add(str[i]);
|
||||
}
|
||||
return tempList;
|
||||
|
||||
}
|
||||
|
||||
/** 清空本地历史搜索 */
|
||||
public void clearGood() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(APP_SOSO_HISTORY_GOOD, "");
|
||||
}
|
||||
|
||||
/** 添加搜索KEY合集 */
|
||||
public void addGood(String sosoKey) {
|
||||
List<String> tempList = getGoods();
|
||||
|
||||
if (tempList.contains(sosoKey)) {
|
||||
tempList.remove(sosoKey);
|
||||
}
|
||||
tempList.add(0, sosoKey);
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
for (int i = 0; i < tempList.size(); i++) {
|
||||
sb.append(tempList.get(i));
|
||||
if (i < tempList.size() - 1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
sharedTools.setObject(APP_SOSO_HISTORY_GOOD, sb.toString());
|
||||
}
|
||||
|
||||
/** 获取搜索KEY合集 */
|
||||
private String getGoodStr() {
|
||||
SharedTools sharedTools = new SharedTools(
|
||||
BaseApplication.getInstance(), APP_SHARED_NAME);
|
||||
String temp = sharedTools
|
||||
.getObject(APP_SOSO_HISTORY_GOOD, String.class);
|
||||
return (null == temp || "".equals(temp) ? "" : temp);
|
||||
}
|
||||
|
||||
/** 获取搜索KEY合集 */
|
||||
public List<String> getGoods() {
|
||||
String temp = getGoodStr();
|
||||
if ("".equals(temp)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
List<String> tempList = new ArrayList<String>();
|
||||
String[] str = temp.split(",");
|
||||
for (int i = 0; i < str.length; i++) {
|
||||
tempList.add(str[i]);
|
||||
}
|
||||
return tempList;
|
||||
}
|
||||
|
||||
}
|
||||
224
app/src/main/java/com/fenghoo/seven/utils/NetUtils.java
Normal file
224
app/src/main/java/com/fenghoo/seven/utils/NetUtils.java
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (C) 2016 android@19code.com
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Blog : http://blog.csdn.net/u011240877
|
||||
* 网络工具
|
||||
*
|
||||
*/
|
||||
public class NetUtils {
|
||||
|
||||
public static final String NETWORK_TYPE_WIFI = "wifi";
|
||||
public static final String NETWORK_TYPE_3G = "3g";
|
||||
public static final String NETWORK_TYPE_2G = "2g";
|
||||
public static final String NETWORK_TYPE_WAP = "wap";
|
||||
public static final String NETWORK_TYPE_UNKNOWN = "unknown";
|
||||
public static final String NETWORK_TYPE_DISCONNECT = "disconnect";
|
||||
|
||||
public static int getNetworkType(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
|
||||
return networkInfo == null ? -1 : networkInfo.getType();
|
||||
}
|
||||
|
||||
public static String getNetworkTypeName(Context context) {
|
||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo;
|
||||
String type = NETWORK_TYPE_DISCONNECT;
|
||||
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
|
||||
return type;
|
||||
}
|
||||
|
||||
if (networkInfo.isConnected()) {
|
||||
String typeName = networkInfo.getTypeName();
|
||||
if ("WIFI".equalsIgnoreCase(typeName)) {
|
||||
type = NETWORK_TYPE_WIFI;
|
||||
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
|
||||
//String proxyHost = android.net.Proxy.getDefaultHost();//deprecated
|
||||
String proxyHost = System.getProperty("http.proxyHost");
|
||||
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
|
||||
} else {
|
||||
type = NETWORK_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static boolean isConnected(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
||||
if (info != null && info.isConnected()) {
|
||||
if (info.getState() == NetworkInfo.State.CONNECTED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivity != null) {
|
||||
NetworkInfo info = connectivity.getActiveNetworkInfo();
|
||||
return info.isAvailable();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isWiFi(Context cxt) {
|
||||
ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
// wifi的状态:ConnectivityManager.TYPE_WIFI
|
||||
// 3G的状态:ConnectivityManager.TYPE_MOBILE
|
||||
return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
|
||||
}
|
||||
|
||||
//unchecked
|
||||
public static void openNetSetting(Activity act) {
|
||||
Intent intent = new Intent();
|
||||
ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
|
||||
intent.setComponent(cm);
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
act.startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether is fast mobile network
|
||||
*/
|
||||
|
||||
private static boolean isFastMobileNetwork(Context context) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (telephonyManager == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (telephonyManager.getNetworkType()) {
|
||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
return false;
|
||||
case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||
return false;
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||
return false;
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||
return false;
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_IDEN:
|
||||
return false;
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
return true;
|
||||
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setWifiEnabled(Context context, boolean enabled) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
wifiManager.setWifiEnabled(enabled);
|
||||
}
|
||||
|
||||
public static void setDataEnabled(Context context, boolean enabled) {
|
||||
ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
Class<?> conMgrClass = null;
|
||||
Field iConMgrField = null;
|
||||
Object iConMgr = null;
|
||||
Class<?> iConMgrClass = null;
|
||||
Method setMobileDataEnabledMethod = null;
|
||||
try {
|
||||
conMgrClass = Class.forName(conMgr.getClass().getName());
|
||||
iConMgrField = conMgrClass.getDeclaredField("mService");
|
||||
iConMgrField.setAccessible(true);
|
||||
iConMgr = iConMgrField.get(conMgr);
|
||||
iConMgrClass = Class.forName(iConMgr.getClass().getName());
|
||||
setMobileDataEnabledMethod = iConMgrClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
|
||||
setMobileDataEnabledMethod.setAccessible(true);
|
||||
setMobileDataEnabledMethod.invoke(iConMgr, enabled);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ScanResult> getWifiScanResults(Context context) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
return wifiManager.startScan() ? wifiManager.getScanResults() : null;
|
||||
}
|
||||
|
||||
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
ScanResult scanResult = null;
|
||||
boolean f = wifiManager.startScan();
|
||||
if (!f) {
|
||||
getScanResultsByBSSID(context, bssid);
|
||||
}
|
||||
List<ScanResult> list = wifiManager.getScanResults();
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
scanResult = list.get(i);
|
||||
if (scanResult.BSSID.equals(bssid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scanResult;
|
||||
}
|
||||
|
||||
public static WifiInfo getWifiConnectionInfo(Context context) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
return wifiManager.getConnectionInfo();
|
||||
}
|
||||
}
|
||||
76
app/src/main/java/com/fenghoo/seven/utils/SPUtils.java
Normal file
76
app/src/main/java/com/fenghoo/seven/utils/SPUtils.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2016 android@19code.com
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
/**
|
||||
* Create by h4de5ing 2016/5/7 007
|
||||
* SharedPreferences工具
|
||||
*
|
||||
*/
|
||||
public class SPUtils {
|
||||
|
||||
public static void setSP(Context context, String key, Object object) {
|
||||
String type = object.getClass().getSimpleName();
|
||||
String packageName = context.getPackageName();
|
||||
SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
|
||||
Editor edit = sp.edit();
|
||||
if ("String".equals(type)) {
|
||||
edit.putString(key, (String) object);
|
||||
} else if ("Integer".equals(type)) {
|
||||
edit.putInt(key, (Integer) object);
|
||||
} else if ("Boolean".equals(type)) {
|
||||
edit.putBoolean(key, (Boolean) object);
|
||||
} else if ("Float".equals(type)) {
|
||||
edit.putFloat(key, (Float) object);
|
||||
} else if ("Long".equals(type)) {
|
||||
edit.putLong(key, (Long) object);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
public static Object getSp(Context context, String key, Object defaultObject) {
|
||||
String type = defaultObject.getClass().getSimpleName();
|
||||
String packageName = context.getPackageName();
|
||||
SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
|
||||
if ("String".equals(type)) {
|
||||
return sp.getString(key, (String) defaultObject);
|
||||
} else if ("Integer".equals(type)) {
|
||||
return sp.getInt(key, (Integer) defaultObject);
|
||||
} else if ("Boolean".equals(type)) {
|
||||
return sp.getBoolean(key, (Boolean) defaultObject);
|
||||
} else if ("Float".equals(type)) {
|
||||
return sp.getFloat(key, (Float) defaultObject);
|
||||
} else if ("Long".equals(type)) {
|
||||
return sp.getLong(key, (Long) defaultObject);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void cleanAllSP(Context context) {
|
||||
String packageName = context.getPackageName();
|
||||
SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
|
||||
Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
189
app/src/main/java/com/fenghoo/seven/utils/SharedTools.java
Normal file
189
app/src/main/java/com/fenghoo/seven/utils/SharedTools.java
Normal file
@@ -0,0 +1,189 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: LShared
|
||||
* @Description: TODO(描述: SharedPreferences 工具类)
|
||||
* @author Lee
|
||||
* @date 2016年4月11日 上午10:00:27
|
||||
* @version V1.0
|
||||
*/
|
||||
public class SharedTools {
|
||||
|
||||
Context context;
|
||||
String name;
|
||||
public static final String SP_NAME = "tsxn";
|
||||
SharedPreferences sp;
|
||||
Editor editor;
|
||||
|
||||
public SharedTools(Context context) {
|
||||
this.context = context;
|
||||
sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
editor = sp.edit();
|
||||
}
|
||||
|
||||
public SharedTools(Context context, String name) {
|
||||
this.context = context;
|
||||
this.name = name;
|
||||
sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
|
||||
editor = sp.edit();
|
||||
}
|
||||
|
||||
public void setBoolean(String key, boolean bool) {
|
||||
editor.putBoolean(key, bool);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return sp.getBoolean(key, false);
|
||||
}
|
||||
|
||||
public void setString(String key, String val) {
|
||||
editor.putString(key, val);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return sp.getString(key, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key和预期的value类型获取value的值
|
||||
*
|
||||
* @param key
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public <T> T getValue(String key, Class<T> clazz) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("请先调用带有context,name参数的构造!");
|
||||
}
|
||||
|
||||
SharedPreferences sp = this.context.getSharedPreferences(this.name,
|
||||
Context.MODE_PRIVATE);
|
||||
return getValue(key, clazz, sp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对复杂类型存储<对象>
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
public void setObject(String key, Object object) {
|
||||
SharedPreferences sp = this.context.getSharedPreferences(this.name,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = null;
|
||||
try {
|
||||
|
||||
out = new ObjectOutputStream(baos);
|
||||
out.writeObject(object);
|
||||
String objectVal = new String(Base64.encode(baos.toByteArray(),
|
||||
Base64.DEFAULT));
|
||||
Editor editor = sp.edit();
|
||||
editor.putString(key, objectVal);
|
||||
editor.commit();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (baos != null) {
|
||||
baos.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getObject(String key, Class<T> clazz) {
|
||||
SharedPreferences sp = this.context.getSharedPreferences(this.name,
|
||||
Context.MODE_PRIVATE);
|
||||
if (sp.contains(key)) {
|
||||
String objectVal = sp.getString(key, null);
|
||||
byte[] buffer = Base64.decode(objectVal, Base64.DEFAULT);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
ois = new ObjectInputStream(bais);
|
||||
T t = (T) ois.readObject();
|
||||
return t;
|
||||
} catch (StreamCorruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (bais != null) {
|
||||
bais.close();
|
||||
}
|
||||
if (ois != null) {
|
||||
ois.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于外部不可见的过渡方法
|
||||
*
|
||||
* @param key
|
||||
* @param clazz
|
||||
* @param sp
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getValue(String key, Class<T> clazz, SharedPreferences sp) {
|
||||
T t;
|
||||
try {
|
||||
|
||||
t = clazz.newInstance();
|
||||
|
||||
if (t instanceof Integer) {
|
||||
return (T) Integer.valueOf(sp.getInt(key, 0));
|
||||
} else if (t instanceof String) {
|
||||
return (T) sp.getString(key, "");
|
||||
} else if (t instanceof Boolean) {
|
||||
return (T) Boolean.valueOf(sp.getBoolean(key, false));
|
||||
} else if (t instanceof Long) {
|
||||
return (T) Long.valueOf(sp.getLong(key, 0L));
|
||||
} else if (t instanceof Float) {
|
||||
return (T) Float.valueOf(sp.getFloat(key, 0L));
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("system", "类型输入错误或者复杂类型无法解析[" + e.getMessage() + "]");
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("system", "类型输入错误或者复杂类型无法解析[" + e.getMessage() + "]");
|
||||
}
|
||||
Log.e("system", "无法找到" + key + "对应的值");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
//leftRight为横向间的距离 topBottom为纵向间距离
|
||||
private int leftRight;
|
||||
private int topBottom;
|
||||
|
||||
public SpaceItemDecoration(int leftRight, int topBottom) {
|
||||
this.leftRight = leftRight;
|
||||
this.topBottom = topBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
||||
//竖直方向的
|
||||
if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
|
||||
//最后一项需要 bottom
|
||||
if (parent.getChildAdapterPosition(view) == layoutManager.getItemCount() - 1) {
|
||||
outRect.bottom = topBottom;
|
||||
}
|
||||
outRect.top = topBottom;
|
||||
outRect.left = leftRight;
|
||||
outRect.right = leftRight;
|
||||
} else {
|
||||
//最后一项需要right
|
||||
if (parent.getChildAdapterPosition(view) == layoutManager.getItemCount() - 1) {
|
||||
outRect.right = leftRight;
|
||||
}
|
||||
outRect.top = topBottom;
|
||||
outRect.left = leftRight;
|
||||
outRect.bottom = topBottom;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
205
app/src/main/java/com/fenghoo/seven/utils/StatusBarUtil.java
Normal file
205
app/src/main/java/com/fenghoo/seven/utils/StatusBarUtil.java
Normal file
@@ -0,0 +1,205 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by XiaoQiang on 2017/6/21.
|
||||
*/
|
||||
public class StatusBarUtil {
|
||||
|
||||
/**
|
||||
* 修改状态栏为全透明
|
||||
* @param activity
|
||||
*/
|
||||
@TargetApi(19)
|
||||
public static void transparencyBar(Activity activity){
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = activity.getWindow();
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(Color.WHITE);
|
||||
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Window window =activity.getWindow();
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态栏颜色,支持4.4以上版本
|
||||
* @param activity
|
||||
* @param colorId
|
||||
*/
|
||||
public static void setStatusBarColor(Activity activity,int colorId) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = activity.getWindow();
|
||||
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(activity.getResources().getColor(colorId));
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
//使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明
|
||||
transparencyBar(activity);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(activity);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(colorId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*状态栏亮色模式,设置状态栏黑色文字、图标,
|
||||
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
|
||||
* @param activity
|
||||
* @return 1:MIUUI 2:Flyme 3:android6.0
|
||||
*/
|
||||
public static int StatusBarLightMode(Activity activity){
|
||||
int result=0;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if(MIUISetStatusBarLightMode(activity, true)){
|
||||
result=1;
|
||||
}else if(FlymeSetStatusBarLightMode(activity.getWindow(), true)){
|
||||
result=2;
|
||||
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
result=3;
|
||||
}else{
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = activity.getWindow();
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(Color.BLACK);
|
||||
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Window window =activity.getWindow();
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已知系统类型时,设置状态栏黑色文字、图标。
|
||||
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
|
||||
* @param activity
|
||||
* @param type 1:MIUUI 2:Flyme 3:android6.0
|
||||
*/
|
||||
public static void StatusBarLightMode(Activity activity,int type){
|
||||
if(type==1){
|
||||
MIUISetStatusBarLightMode(activity, true);
|
||||
}else if(type==2){
|
||||
FlymeSetStatusBarLightMode(activity.getWindow(), true);
|
||||
}else if(type==3){
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态栏暗色模式,清除MIUI、flyme或6.0以上版本状态栏黑色文字、图标
|
||||
*/
|
||||
public static void StatusBarDarkMode(Activity activity,int type){
|
||||
if(type==1){
|
||||
MIUISetStatusBarLightMode(activity, false);
|
||||
}else if(type==2){
|
||||
FlymeSetStatusBarLightMode(activity.getWindow(), false);
|
||||
}else if(type==3){
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置状态栏图标为深色和魅族特定的文字风格
|
||||
* 可以用来判断是否为Flyme用户
|
||||
* @param window 需要设置的窗口
|
||||
* @param dark 是否把状态栏文字及图标颜色设置为深色
|
||||
* @return boolean 成功执行返回true
|
||||
*
|
||||
*/
|
||||
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
|
||||
boolean result = false;
|
||||
if (window != null) {
|
||||
try {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
Field darkFlag = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
|
||||
Field meizuFlags = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("meizuFlags");
|
||||
darkFlag.setAccessible(true);
|
||||
meizuFlags.setAccessible(true);
|
||||
int bit = darkFlag.getInt(null);
|
||||
int value = meizuFlags.getInt(lp);
|
||||
if (dark) {
|
||||
value |= bit;
|
||||
} else {
|
||||
value &= ~bit;
|
||||
}
|
||||
meizuFlags.setInt(lp, value);
|
||||
window.setAttributes(lp);
|
||||
result = true;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要MIUIV6以上
|
||||
* @param activity
|
||||
* @param dark 是否把状态栏文字及图标颜色设置为深色
|
||||
* @return boolean 成功执行返回true
|
||||
*
|
||||
*/
|
||||
public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) {
|
||||
boolean result = false;
|
||||
Window window=activity.getWindow();
|
||||
if (window != null) {
|
||||
Class clazz = window.getClass();
|
||||
try {
|
||||
int darkModeFlag = 0;
|
||||
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
|
||||
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
|
||||
darkModeFlag = field.getInt(layoutParams);
|
||||
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
|
||||
if(dark){
|
||||
extraFlagField.invoke(window,darkModeFlag,darkModeFlag);//状态栏透明且黑色字体
|
||||
}else{
|
||||
extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
|
||||
}
|
||||
result=true;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
//开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
|
||||
if(dark){
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}else {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
264
app/src/main/java/com/fenghoo/seven/utils/StringUtils.java
Normal file
264
app/src/main/java/com/fenghoo/seven/utils/StringUtils.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (C) 2016 android@19code.com
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* 字符串工具
|
||||
* Created by Gh0st on 2016/6/2 002.
|
||||
*/
|
||||
public class StringUtils {
|
||||
/**
|
||||
* The pyvalue.
|
||||
*/
|
||||
private static int[] pyvalue = new int[]{-20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036, -20032,
|
||||
-20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, -19741, -19739, -19728,
|
||||
-19725, -19715, -19540, -19531, -19525, -19515, -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, -19263, -19261,
|
||||
-19249, -19243, -19242, -19238, -19235, -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977, -18961,
|
||||
-18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490,
|
||||
-18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988,
|
||||
-17970, -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703, -17701, -17697, -17692,
|
||||
-17683, -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, -17185, -16983, -16970, -16942, -16915, -16733,
|
||||
-16708, -16706, -16689, -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, -16419,
|
||||
-16412, -16407, -16403, -16401, -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, -16155, -15959,
|
||||
-15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, -15652, -15640, -15631,
|
||||
-15625, -15454, -15448, -15436, -15435, -15419, -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, -15183, -15180,
|
||||
-15165, -15158, -15153, -15150, -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, -14941,
|
||||
-14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857,
|
||||
-14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594, -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353,
|
||||
-14345, -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094,
|
||||
-14092, -14090, -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, -13894, -13878, -13870, -13859, -13847, -13831,
|
||||
-13658, -13611, -13601, -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, -13359, -13356, -13343, -13340, -13329,
|
||||
-13326, -13318, -13147, -13138, -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, -12875, -12871, -12860,
|
||||
-12858, -12852, -12849, -12838, -12831, -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, -12346, -12320, -12300,
|
||||
-12120, -12099, -12089, -12074, -12067, -12058, -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, -11536, -11358,
|
||||
-11340, -11339, -11324, -11303, -11097, -11077, -11067, -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014,
|
||||
-10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309,
|
||||
-10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254};
|
||||
|
||||
/**
|
||||
* The pystr.
|
||||
*/
|
||||
public static String[] pystr = new String[]{"a", "ai", "an", "ang", "ao", "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", "bian",
|
||||
"biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", "can", "cang", "cao", "ce", "ceng", "cha", "chai", "chan", "chang", "chao", "che",
|
||||
"chen", "cheng", "chi", "chong", "chou", "chu", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan",
|
||||
"cui", "cun", "cuo", "da", "dai", "dan", "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong", "dou", "du",
|
||||
"duan", "dui", "dun", "duo", "e", "en", "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu", "ga", "gai", "gan", "gang",
|
||||
"gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", "guo", "ha", "hai", "han", "hang",
|
||||
"hao", "he", "hei", "hen", "heng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo", "ji", "jia", "jian",
|
||||
"jiang", "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", "kan", "kang", "kao", "ke", "ken",
|
||||
"keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai", "lan", "lang", "lao", "le", "lei", "leng",
|
||||
"li", "lia", "lian", "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", "lv", "luan", "lue", "lun", "luo", "ma", "mai",
|
||||
"man", "mang", "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu", "na", "nai",
|
||||
"nan", "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", "niao", "nie", "nin", "ning", "niu", "nong", "nu", "nv", "nuan",
|
||||
"nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pu",
|
||||
"qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", "re",
|
||||
"ren", "reng", "ri", "rong", "rou", "ru", "ruan", "rui", "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", "seng", "sha",
|
||||
"shai", "shan", "shang", "shao", "she", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", "shui", "shun",
|
||||
"shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo", "ta", "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao",
|
||||
"tie", "ting", "tong", "tou", "tu", "tuan", "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu", "xi",
|
||||
"xia", "xian", "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", "yan", "yang", "yao", "ye", "yi",
|
||||
"yin", "ying", "yo", "yong", "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan", "zang", "zao", "ze", "zei", "zen", "zeng", "zha",
|
||||
"zhai", "zhan", "zhang", "zhao", "zhe", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui",
|
||||
"zhun", "zhuo", "zi", "zong", "zou", "zu", "zuan", "zui", "zun", "zuo"};
|
||||
|
||||
|
||||
public static int getChsAscii(String chs) {
|
||||
int asc = 0;
|
||||
try {
|
||||
byte[] bytes = chs.getBytes("gb2312");
|
||||
/*if (bytes == null || bytes.length > 2 || bytes.length <= 0) {
|
||||
throw new RuntimeException("illegal resource string");
|
||||
}*/
|
||||
if (bytes.length == 1) {
|
||||
asc = bytes[0];
|
||||
}
|
||||
if (bytes.length == 2) {
|
||||
int hightByte = 256 + bytes[0];
|
||||
int lowByte = 256 + bytes[1];
|
||||
asc = (256 * hightByte + lowByte) - 256 * 256;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR:ChineseSpelling.class-getChsAscii(String chs)" + e);
|
||||
}
|
||||
return asc;
|
||||
}
|
||||
|
||||
public static String convert(String str) {
|
||||
String result = null;
|
||||
int ascii = getChsAscii(str);
|
||||
if (ascii > 0 && ascii < 160) {
|
||||
result = String.valueOf((char) ascii);
|
||||
} else {
|
||||
for (int i = (pyvalue.length - 1); i >= 0; i--) {
|
||||
if (pyvalue[i] <= ascii) {
|
||||
result = pystr[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getSelling(String chs) {
|
||||
String key, value;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int i = 0; i < chs.length(); i++) {
|
||||
key = chs.substring(i, i + 1);
|
||||
if (key.getBytes().length >= 2) {
|
||||
value = convert(key);
|
||||
if (value == null) {
|
||||
value = "unknown";
|
||||
}
|
||||
} else {
|
||||
value = key;
|
||||
}
|
||||
buffer.append(value);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String parseEmpty(String str) {
|
||||
if (str == null || "null".equals(str.trim())) {
|
||||
str = "";
|
||||
}
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.trim().length() == 0;
|
||||
}
|
||||
|
||||
public static int chineseLength(String str) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
String temp = str.substring(i, i + 1);
|
||||
if (temp.matches(chinese)) {
|
||||
valueLength += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
|
||||
public static int strLength(String str) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
String temp = str.substring(i, i + 1);
|
||||
if (temp.matches(chinese)) {
|
||||
valueLength += 2;
|
||||
} else {
|
||||
valueLength += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
|
||||
public static int subStringLength(String str, int maxL) {
|
||||
int currentIndex = 0;
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
String temp = str.substring(i, i + 1);
|
||||
if (temp.matches(chinese)) {
|
||||
valueLength += 2;
|
||||
} else {
|
||||
valueLength += 1;
|
||||
}
|
||||
if (valueLength >= maxL) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
public static Boolean isChinese(String str) {
|
||||
Boolean isChinese = true;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
String temp = str.substring(i, i + 1);
|
||||
isChinese = temp.matches(chinese);
|
||||
}
|
||||
}
|
||||
return isChinese;
|
||||
}
|
||||
|
||||
public static Boolean isContainChinese(String str) {
|
||||
Boolean isChinese = false;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
if (!isEmpty(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
String temp = str.substring(i, i + 1);
|
||||
isChinese = temp.matches(chinese);
|
||||
}
|
||||
}
|
||||
return isChinese;
|
||||
}
|
||||
|
||||
public static String strFormat2(String str) {
|
||||
try {
|
||||
if (str.length() <= 1) {
|
||||
str = "0" + str;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static int convert2Int(Object value, int defaultValue) {
|
||||
if (value == null || "".equals(value.toString().trim())) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Double.valueOf(value.toString()).intValue();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static String decimalFormat(float s, String format) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat(format);
|
||||
return decimalFormat.format(s);
|
||||
}
|
||||
|
||||
|
||||
public static void copy(TextView mTvWechat, Activity activity) {
|
||||
String dataa = mTvWechat.getText().toString().substring(0);
|
||||
if (!TextUtils.isEmpty(dataa)) {
|
||||
ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// 将文本内容放到系统剪贴板里。
|
||||
cm.setText(dataa);
|
||||
ToastUtils.showToast(activity, "复制成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
app/src/main/java/com/fenghoo/seven/utils/ToastUtils.java
Normal file
58
app/src/main/java/com/fenghoo/seven/utils/ToastUtils.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by gh0st on 2017/1/17.
|
||||
* 吐司工具类
|
||||
*/
|
||||
|
||||
public class ToastUtils {
|
||||
private static Toast mToast;
|
||||
private static String message;
|
||||
private static TextView mTextView;
|
||||
|
||||
|
||||
public static void showToast1(Context context, String string) {
|
||||
Toast.makeText(context , string , Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
public static void showToast(Context context, int string) {
|
||||
Toast.makeText(context , string , Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static void showToast(Context context, String message) {
|
||||
//加载Toast布局
|
||||
View toastRoot = LayoutInflater.from(context).inflate(R.layout.toast, null);
|
||||
//初始化布局控件
|
||||
mTextView = (TextView) toastRoot.findViewById(R.id.message);
|
||||
// mImageView = (ImageView) toastRoot.findViewById(R.id.imageView);
|
||||
//为控件设置属性
|
||||
mTextView.setText(message);
|
||||
// mImageView.setImageResource(R.mipmap.ic_launcher);
|
||||
//Toast的初始化
|
||||
Toast toastStart = new Toast(context);
|
||||
//获取屏幕高度
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
int height = wm.getDefaultDisplay().getHeight();
|
||||
//Toast的Y坐标是屏幕高度的1/3,不会出现不适配的问题
|
||||
toastStart.setGravity(Gravity.BOTTOM, 0, height / 3);
|
||||
toastStart.setDuration(Toast.LENGTH_LONG);
|
||||
toastStart.setView(toastRoot);
|
||||
toastStart.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1338
app/src/main/java/com/fenghoo/seven/utils/ToolsText.java
Normal file
1338
app/src/main/java/com/fenghoo/seven/utils/ToolsText.java
Normal file
File diff suppressed because it is too large
Load Diff
464
app/src/main/java/com/fenghoo/seven/utils/ToolsUtils.java
Normal file
464
app/src/main/java/com/fenghoo/seven/utils/ToolsUtils.java
Normal file
@@ -0,0 +1,464 @@
|
||||
/*
|
||||
*******************************************
|
||||
* File: WidgetTools.java
|
||||
* Author: Lijc
|
||||
* Date: 2015-3-20
|
||||
* Company: BlueMobi
|
||||
********************************************/
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Paint;
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: WidgetTools
|
||||
* @Description: TODO(描述: Widget工具类)
|
||||
* @author Lijc
|
||||
* @Company: BlueMobi
|
||||
* @date 2015年4月3日 下午6:04:29
|
||||
* @version V1.0
|
||||
* <p>
|
||||
* >>>使用说明:
|
||||
* <p>
|
||||
* 1.setText()可用于TextView,Button,CheckBox,RadioButton,EditText;
|
||||
* <p>
|
||||
* 2.setUnderline() 在文字下面设置下划线
|
||||
* <p>
|
||||
* 3.setDeleteline() 在文字上设置删除线
|
||||
* <p>
|
||||
* 4.getText() 获取文字
|
||||
* <p>
|
||||
* 5.get() ViewHolder 简洁模式
|
||||
* <p>
|
||||
* 6.spanText() 文字前面插入图片
|
||||
* <p>
|
||||
* 7.DisplayImage()获取设置图片
|
||||
* <p>
|
||||
* 8.formatMoney() 格式化显示金额
|
||||
* <p>
|
||||
* 9.getAppCode() 获取版本code
|
||||
*/
|
||||
public class ToolsUtils {
|
||||
|
||||
private static long lastClickTime;
|
||||
|
||||
/**
|
||||
* 连续点击
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFastDoubleClick() {
|
||||
long time = System.currentTimeMillis();
|
||||
long timeD = time - lastClickTime;
|
||||
if (0 < timeD && timeD < 1000) {
|
||||
return true;
|
||||
}
|
||||
lastClickTime = time;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: getText @Description: TODO @param tv @param text @return
|
||||
* void @throws
|
||||
*/
|
||||
public static String getText(View v) {
|
||||
if (v instanceof TextView) {// TextView
|
||||
return ((TextView) v).getText().toString();
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
return ((Button) v).getText().toString();
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
return ((CheckBox) v).getText().toString();
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
return ((RadioButton) v).getText().toString();
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
return ((EditText) v).getText().toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO 设置TextView的text 为空时默认显示 -- @param
|
||||
* tv @param text @return void @throws
|
||||
*/
|
||||
public static void setText(View v, String text) {
|
||||
setText(v, text, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO 设置TextView的text @param tv @param
|
||||
* text @param defaultText 默认显示 @return void @throws
|
||||
*/
|
||||
public static void setText(View v, String text, String defaultText) {
|
||||
if (TextUtils.isEmpty(text))
|
||||
text = defaultText;
|
||||
if (v instanceof TextView) {// TextView
|
||||
((TextView) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
((Button) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
((CheckBox) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
((RadioButton) v).setText(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
((EditText) v).setText(text);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO String资源文件的format方法 @param @param
|
||||
* tv @param @param context @param @param text @param @param
|
||||
* resId @return void @throws
|
||||
*/
|
||||
public static void setText(View v, Context context, String text, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
setText(v, String.format(format, text));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO String资源文件的format方法 @param tv @param
|
||||
* context @param i @param resId @return void @throws
|
||||
*/
|
||||
public static void setText(View v, Context context, int i, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
setText(v, String.format(format, i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO String资源文件的format方法 @param @param
|
||||
* tv @param @param context @param @param text1 @param @param
|
||||
* text2 @param @param resId @return void @throws
|
||||
*/
|
||||
public static void setText(View v, Context context, String text1, String text2, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
setText(v, String.format(format, text1, text2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText @Description: TODO String资源文件的format方法 @param @param
|
||||
* tv @param @param context @param @param i1 @param @param
|
||||
* i2 @param @param resId @return void @throws
|
||||
*/
|
||||
public static void setText(View v, Context context, int i1, int i2, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
setText(v, String.format(format, i1, i2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setTextViewStyle @Description: TODO 优惠价格 @param tv @param
|
||||
* text @return void @throws
|
||||
*/
|
||||
public static void setTextViewStyle(TextView tv) {
|
||||
tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setUnderline @Description: TODO 下划线 @param tv @param text @return
|
||||
* void @throws
|
||||
*/
|
||||
public static void setUnderline(View v) {
|
||||
if (v instanceof TextView) {// TextView
|
||||
((TextView) v).getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
((TextView) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
((Button) v).getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
((Button) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
((CheckBox) v).getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
((CheckBox) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
((RadioButton) v).getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
((RadioButton) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
((EditText) v).getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
((EditText) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setDelline @Description: TODO 删除线 @param tv @param text @return
|
||||
* void @throws
|
||||
*/
|
||||
public static void setDeleteline(View v) {
|
||||
if (v instanceof TextView) {// TextView
|
||||
((TextView) v).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
((TextView) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
((Button) v).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
((Button) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
((CheckBox) v).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
((CheckBox) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
((RadioButton) v).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
((RadioButton) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
((EditText) v).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
((EditText) v).getPaint().setAntiAlias(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO ViewHodler简写模式
|
||||
* @param view
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public <T extends View> T get(View view, int id) {
|
||||
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
|
||||
if (viewHolder == null) {
|
||||
viewHolder = new SparseArray<>();
|
||||
view.setTag(viewHolder);
|
||||
}
|
||||
View childView = viewHolder.get(id);
|
||||
if (childView == null) {
|
||||
childView = view.findViewById(id);
|
||||
viewHolder.put(id, childView);
|
||||
}
|
||||
return (T) childView;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param v
|
||||
* @param drawableId
|
||||
* @param text
|
||||
*/
|
||||
public static void spanText(Context context, View v, int drawableId, String text) {
|
||||
Bitmap b = BitmapFactory.decodeResource(context.getResources(), drawableId);
|
||||
ImageSpan imgSpan = new ImageSpan(context, b);
|
||||
SpannableString spanString = new SpannableString("ic");
|
||||
spanString.setSpan(imgSpan, 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (v instanceof TextView) {// TextView
|
||||
((TextView) v).setText(spanString);
|
||||
((TextView) v).append(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof Button) {// Button
|
||||
((Button) v).setText(spanString);
|
||||
((Button) v).append(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof CheckBox) {// CheckBox
|
||||
((CheckBox) v).setText(spanString);
|
||||
((CheckBox) v).append(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof RadioButton) {// RadioButton
|
||||
((RadioButton) v).setText(spanString);
|
||||
((RadioButton) v).append(text);
|
||||
return;
|
||||
}
|
||||
if (v instanceof EditText) {// EditText
|
||||
((EditText) v).setText(spanString);
|
||||
((EditText) v).append(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用版本code
|
||||
*
|
||||
* @param ctx
|
||||
* @return
|
||||
*/
|
||||
public static int getAppCode(Context ctx) {
|
||||
try {
|
||||
PackageManager packageManager = ctx.getPackageManager();
|
||||
PackageInfo packInfo = packageManager.getPackageInfo(ctx.getPackageName(), 0);
|
||||
return packInfo.versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 2 * 获取版本号
|
||||
* 3 * @return 当前应用的版本号
|
||||
* 4
|
||||
*/
|
||||
public static String getVersion(Context ctx) {
|
||||
try {
|
||||
PackageManager manager = ctx.getPackageManager();
|
||||
PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0);
|
||||
return "V"+info.versionName;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* px转dp
|
||||
*
|
||||
* @param poContext
|
||||
* @param pxValue
|
||||
* @return
|
||||
*/
|
||||
public static int px2dip(Context poContext, float pxValue) {
|
||||
final float scale = poContext.getResources().getDisplayMetrics().density;
|
||||
return (int) (pxValue / scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*
|
||||
* @param poContext
|
||||
* @param dpValue
|
||||
* @return
|
||||
*/
|
||||
public static int dip2px(Context poContext, float dpValue) {
|
||||
final float scale = poContext.getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将px值转换为sp值,保证文字大小不变
|
||||
*
|
||||
* @param pxValue
|
||||
* @param
|
||||
* (DisplayMetrics类中属性scaledDensity)
|
||||
* @return
|
||||
*/
|
||||
public static int px2sp(Context context, float pxValue) {
|
||||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
|
||||
return (int) (pxValue / fontScale + 0.5f);
|
||||
}
|
||||
|
||||
public static int getScreenWidth(Activity poActivity) {
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
poActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
|
||||
// int width = metric.widthPixels; // 屏幕宽度(像素)
|
||||
// int height = metric.heightPixels; // 屏幕高度(像素)
|
||||
// float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
// int densityDpi = metric.densityDpi;
|
||||
return metric.widthPixels;
|
||||
}
|
||||
|
||||
public static int getScreenHeight(Activity poActivity) {
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
poActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
|
||||
// int width = metric.widthPixels; // 屏幕宽度(像素)
|
||||
// int height = metric.heightPixels; // 屏幕高度(像素)
|
||||
// float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
// int densityDpi = metric.densityDpi;
|
||||
return metric.heightPixels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置 编辑文本的长度
|
||||
* @param mContext
|
||||
* @param editText
|
||||
* @param lens
|
||||
*/
|
||||
public static void setEditTextLenth(final Activity mContext,final EditText editText,final int lens) {
|
||||
/**
|
||||
* 设置商品描述的字数最多为140个字符
|
||||
*/
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// TODO Auto-generated method stub
|
||||
Editable editable = editText.getText();
|
||||
int len = editable.length();
|
||||
editText.setText("(" + editable.length() + "/" + 140 + ")");
|
||||
if (len > lens) {
|
||||
Toast.makeText(mContext, "最多140个字符", Toast.LENGTH_SHORT).show();
|
||||
int selEndIndex = Selection.getSelectionEnd(editable);
|
||||
String str = editable.toString();
|
||||
String newStr = str.substring(0, 140);// 截取新字符串
|
||||
editText.setText(newStr);
|
||||
editable = editText.getText();
|
||||
int newLen = editable.length();// 新字符串的长度
|
||||
// 旧光标位置超过字符串长度
|
||||
if (selEndIndex > newLen) {
|
||||
selEndIndex = editable.length();
|
||||
}
|
||||
Selection.setSelection(editable, selEndIndex);// 设置新光标所在的位置
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// TODO Auto-generated method stub
|
||||
String strTmp = s.toString();
|
||||
// String tmp = EmojiFilter.filterEmoji(strTmp);
|
||||
// if (!strTmp.trim().equals("") && !strTmp.equals(tmp)) {
|
||||
// editText.setText(tmp);
|
||||
// editText.invalidate();
|
||||
// Toast.makeText(mContext, "暂不支持表情输入", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
if (s instanceof Spannable) {// 改变光标的位置到最后
|
||||
Spannable spanText = (Spannable) s;
|
||||
Selection.setSelection(spanText, s.length());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
32
app/src/main/java/com/fenghoo/seven/utils/UiUtils.java
Normal file
32
app/src/main/java/com/fenghoo/seven/utils/UiUtils.java
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class UiUtils {
|
||||
|
||||
static public int getScreenWidthPixels(Context context) {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
|
||||
.getMetrics(dm);
|
||||
return dm.widthPixels;
|
||||
}
|
||||
|
||||
static public int dipToPx(Context context, int dip) {
|
||||
return (int) (dip * getScreenDensity(context) + 0.5f);
|
||||
}
|
||||
|
||||
static public float getScreenDensity(Context context) {
|
||||
try {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
|
||||
.getMetrics(dm);
|
||||
return dm.density;
|
||||
} catch (Exception e) {
|
||||
return DisplayMetrics.DENSITY_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class VerificationUtils {
|
||||
|
||||
/**
|
||||
* 验证手机格式
|
||||
*/
|
||||
public static boolean isMobile(String number) {
|
||||
/*
|
||||
移动:134、135、136、137、138、139、150、151、152、157(TD)、158、159、178(新)、182、184、187、188
|
||||
联通:130、131、132、152、155、156、185、186
|
||||
电信:133、153、170、173、177、180、181、189、(1349卫通)
|
||||
总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9
|
||||
*/
|
||||
String num = "[1][34578]\\d{9}";//"[1]"代表第1位为数字1,"[34578]"代表第二位可以为3、4、5、7、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
|
||||
if (TextUtils.isEmpty(number)) {
|
||||
return false;
|
||||
} else {
|
||||
//matches():字符串是否在给定的正则表达式匹配
|
||||
return number.matches(num);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
public interface WebViewJavaScriptFunction {
|
||||
|
||||
void onJsFunctionCalled(String tag);
|
||||
}
|
||||
136
app/src/main/java/com/fenghoo/seven/utils/WidgetTools.java
Normal file
136
app/src/main/java/com/fenghoo/seven/utils/WidgetTools.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
*******************************************
|
||||
* File: WidgetTools.java
|
||||
* Author: Lijc
|
||||
* Date: 2015-3-20
|
||||
* Company: BlueMobi
|
||||
********************************************/
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class WidgetTools {
|
||||
/**
|
||||
* @Title: setText
|
||||
* @Description: TODO 设置TextView的text 为空时默认显示 --
|
||||
* @param tv
|
||||
* @param text
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void setText(TextView tv, String text) {
|
||||
if ("null".equals(text) || "".equals(text)||null == text) {
|
||||
setText(tv, "— —", "— —");
|
||||
} else {
|
||||
setText(tv, text, "— —");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void setEditText(EditText tv, String text1,String test2) {
|
||||
if (("null".equals(text1) || "".equals(text1)||null == text1)&&"null".equals(test2) || "".equals(test2)||null == test2) {
|
||||
setText(tv, text1+test2, "");
|
||||
} else {
|
||||
setText(tv, text1+test2, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//viewpage滑动折叠卡片效果
|
||||
public static void setTexttwo(TextView tv, String text,String texttwo) {
|
||||
if ("null".equals(text) || "".equals(text)||null == text) {
|
||||
setText(tv, texttwo+"— —", texttwo+"— —");
|
||||
} else {
|
||||
setText(tv, texttwo+text, texttwo+"— —");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void setTextfive(TextView tv,String mctext, String text) {
|
||||
if ("null".equals(text) || "".equals(text)||null == text) {
|
||||
setText(tv, mctext+"— —", mctext+"— —");
|
||||
} else {
|
||||
setText(tv,mctext+text, mctext+"— —");
|
||||
}
|
||||
|
||||
}
|
||||
public static void setTextsix(TextView tv,String mctext, String text) {
|
||||
if ("null".equals(text) || "".equals(text)||null == text) {
|
||||
setText(tv, mctext+"00:00", mctext+"00:00");
|
||||
} else {
|
||||
setText(tv,mctext+text, mctext+"00:00");
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @Title: setText
|
||||
* @Description: TODO 设置TextView的text
|
||||
* @param tv
|
||||
* @param text
|
||||
* @param defaultText
|
||||
* 默认显示
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void setText(TextView tv, String text, String defaultText) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
tv.setText(defaultText);
|
||||
} else {
|
||||
tv.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText
|
||||
* @Description: TODO String资源文件的format方法
|
||||
* @param @param tv
|
||||
* @param @param context
|
||||
* @param @param text
|
||||
* @param @param resId
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void setText(TextView tv, Context context, String text,
|
||||
int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
tv.setText(String.format(format, text));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText
|
||||
* @Description: TODO String资源文件的format方法
|
||||
* @param tv
|
||||
* @param context
|
||||
* @param i
|
||||
* @param resId
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void setText(TextView tv, Context context, int i, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
tv.setText(String.format(format, i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: setText
|
||||
* @Description: TODO String资源文件的format方法
|
||||
* @param @param tv
|
||||
* @param @param context
|
||||
* @param @param text1
|
||||
* @param @param text2
|
||||
* @param @param resId
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void setText(TextView tv, Context context, String text1,
|
||||
String text2, int resId) {
|
||||
String format = context.getResources().getString(resId);
|
||||
tv.setText(String.format(format, text1, text2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
91
app/src/main/java/com/fenghoo/seven/utils/X5WebView.java
Normal file
91
app/src/main/java/com/fenghoo/seven/utils/X5WebView.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package com.fenghoo.seven.utils;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.tencent.smtt.sdk.WebSettings;
|
||||
import com.tencent.smtt.sdk.WebView;
|
||||
import com.tencent.smtt.sdk.WebViewClient;
|
||||
|
||||
|
||||
public class X5WebView extends WebView {
|
||||
TextView title;
|
||||
private WebViewClient client = new WebViewClient() {
|
||||
/**
|
||||
* 防止加载网页时调起系统浏览器
|
||||
*/
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public X5WebView(Context arg0, AttributeSet arg1) {
|
||||
super(arg0, arg1);
|
||||
this.setWebViewClient(client);
|
||||
// this.setWebChromeClient(chromeClient);
|
||||
// WebStorage webStorage = WebStorage.getInstance();
|
||||
initWebViewSettings();
|
||||
this.getView().setClickable(true);
|
||||
}
|
||||
|
||||
private void initWebViewSettings() {
|
||||
WebSettings webSetting = this.getSettings();
|
||||
webSetting.setJavaScriptEnabled(true);
|
||||
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
|
||||
webSetting.setAllowFileAccess(true);
|
||||
webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
|
||||
webSetting.setSupportZoom(true);
|
||||
webSetting.setBuiltInZoomControls(true);
|
||||
webSetting.setUseWideViewPort(true);
|
||||
webSetting.setSupportMultipleWindows(true);
|
||||
// webSetting.setLoadWithOverviewMode(true);
|
||||
webSetting.setAppCacheEnabled(true);
|
||||
// webSetting.setDatabaseEnabled(true);
|
||||
webSetting.setDomStorageEnabled(true);
|
||||
webSetting.setGeolocationEnabled(true);
|
||||
webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
|
||||
// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
|
||||
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
|
||||
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
|
||||
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
|
||||
// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
|
||||
// settings 的设计
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
||||
// boolean ret = super.drawChild(canvas, child, drawingTime);
|
||||
// canvas.save();
|
||||
// Paint paint = new Paint();
|
||||
// paint.setColor(0x7fff0000);
|
||||
// paint.setTextSize(24.f);
|
||||
// paint.setAntiAlias(true);
|
||||
// if (getX5WebViewExtension() != null) {
|
||||
// canvas.drawText(this.getContext().getPackageName() + "-pid:"
|
||||
// + android.os.Process.myPid(), 10, 50, paint);
|
||||
// canvas.drawText(
|
||||
// "X5 Core:" + QbSdk.getTbsVersion(this.getContext()), 10,
|
||||
// 100, paint);
|
||||
// } else {
|
||||
// canvas.drawText(this.getContext().getPackageName() + "-pid:"
|
||||
// + android.os.Process.myPid(), 10, 50, paint);
|
||||
// canvas.drawText("Sys Core", 10, 100, paint);
|
||||
// }
|
||||
// canvas.drawText(Build.MANUFACTURER, 10, 150, paint);
|
||||
// canvas.drawText(Build.MODEL, 10, 200, paint);
|
||||
// canvas.restore();
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
public X5WebView(Context arg0) {
|
||||
super(arg0);
|
||||
setBackgroundColor(85621);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.fenghoo.seven.utils.checkVersionsUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.fenghoo.seven.main.entity.LoginBean;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* ProfileSpUtils
|
||||
* (๑• . •๑)
|
||||
* 类描述:轻量级资料存储工具
|
||||
* Created by LeiXiaoXing on 2017/4/11 11:01
|
||||
*/
|
||||
public class ProfileSpUtils {
|
||||
private static final String SP_NAME = "user_profile";
|
||||
private static final String SP_NAME_SHOW_ADD_FRIEND_RED="show_red_dot";
|
||||
private static final String SP_PUSH_NAME="user_push";
|
||||
/**
|
||||
* 用户设置信息存储
|
||||
*/
|
||||
private static final String SETTING_SP_NAME = "user_setting";
|
||||
private static final String KEY_USER = "User";
|
||||
private static final String KEY_HEAD = "head_img";
|
||||
private static final String KEY_LOGIN = "login";
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private static final String KEY_MOBILE = "MOBILE";
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private static final String KEY_PASSWORD = "PASSWORD";
|
||||
private static ProfileSpUtils ourInstance = null;
|
||||
/**
|
||||
* 小米和华为推送相关id
|
||||
*/
|
||||
private static final String KEY_MI_PUSH="regId";
|
||||
private static final String KEY_HW_PUSH="tmId";
|
||||
|
||||
private static SharedPreferences sharedPreferences;
|
||||
private static SharedPreferences settingSharedPreferences;
|
||||
private static SharedPreferences showAddFriendRedSharedPreferences;
|
||||
private static SharedPreferences pushSharedPreferences;//小米和华为;
|
||||
|
||||
private boolean isFirst = true;//是否是第一次登陆
|
||||
|
||||
public ProfileSpUtils() {
|
||||
}
|
||||
|
||||
public static ProfileSpUtils getInstance() {
|
||||
if (ourInstance == null) {
|
||||
synchronized (ProfileSpUtils.class) {
|
||||
if (ourInstance == null) {
|
||||
ourInstance = new ProfileSpUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param context 上下文对象,建议使用Application的Context
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
settingSharedPreferences = context.getSharedPreferences(SETTING_SP_NAME, Context.MODE_PRIVATE);
|
||||
showAddFriendRedSharedPreferences=context.getSharedPreferences(SP_NAME_SHOW_ADD_FRIEND_RED,
|
||||
Context.MODE_PRIVATE);
|
||||
pushSharedPreferences=context.getSharedPreferences(SP_PUSH_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户登录状态
|
||||
*
|
||||
* @param isLogin 用户登录状态
|
||||
*/
|
||||
public void saveLoginSatus(boolean isLogin) {
|
||||
SharedPreferences.Editor edit = sharedPreferences.edit();
|
||||
if (!isLogin) {
|
||||
//退出的登录,清除用户数据
|
||||
edit.clear();
|
||||
}
|
||||
|
||||
edit.putBoolean(KEY_LOGIN, isLogin)
|
||||
.apply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 记住密码
|
||||
*/
|
||||
public void savePassword(String mobile, String password) {
|
||||
settingSharedPreferences.edit()
|
||||
.putString(KEY_MOBILE, mobile)
|
||||
.putString(KEY_PASSWORD, password)
|
||||
.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取保存的用户账号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getKeyMobile() {
|
||||
return settingSharedPreferences.getString(KEY_MOBILE, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取保存的密码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getKeyPassword() {
|
||||
return settingSharedPreferences.getString(KEY_PASSWORD, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户登录状态
|
||||
*
|
||||
* @return 用户登录状态
|
||||
*/
|
||||
public boolean isLogin() {
|
||||
return sharedPreferences.getBoolean(KEY_LOGIN, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存用户资料
|
||||
*
|
||||
* @param loginbean 用户资料实体类
|
||||
*/
|
||||
// public void saveProfile(LoginBean loginbean) {
|
||||
// //头像数据转存
|
||||
// LoginBean loginBean = new LoginBean();
|
||||
// loginBean.getResult().getData().setHead_img(loginbean.getResult().getData().getHead_img());
|
||||
|
||||
|
||||
|
||||
// loginBean.setHome_Page_Size(treeUserEntity.getHome_Page_Size());
|
||||
// loginBean.setOrigin(treeUserEntity.getOrigin_img());
|
||||
// loginBean.setInfo_page_size(treeUserEntity.getInfo_page_size());
|
||||
// loginBean.setUser_list_size(treeUserEntity.getUser_list_size());
|
||||
//
|
||||
// sharedPreferences.edit()
|
||||
// .putString(KEY_USER, new Gson().toJson(treeUserEntity))
|
||||
// .putString(KEY_HEAD, new Gson().toJson(userHeadEntity))
|
||||
// .apply();
|
||||
|
||||
/**
|
||||
* 获取SP存储的用户资料
|
||||
*
|
||||
* @return SP存储的用户资料
|
||||
*/
|
||||
public LoginBean getUserProfie() {
|
||||
String userStr = sharedPreferences.getString(KEY_USER, "");
|
||||
if (TextUtils.isEmpty(userStr)) {
|
||||
return new LoginBean();
|
||||
}
|
||||
return new Gson().fromJson(userStr, LoginBean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户资料
|
||||
*
|
||||
* @param treeUserEntity 用户资料实体类
|
||||
*/
|
||||
public void saveProfile(LoginBean treeUserEntity) {
|
||||
sharedPreferences.edit()
|
||||
.putString(KEY_USER, new Gson().toJson(treeUserEntity))
|
||||
.apply();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user