203 lines
6.6 KiB
Java
203 lines
6.6 KiB
Java
package com.ubt.jimu.utils;
|
|
|
|
import android.content.Context;
|
|
import android.text.SpannableString;
|
|
import android.text.method.LinkMovementMethod;
|
|
import android.text.style.ClickableSpan;
|
|
import android.text.style.ForegroundColorSpan;
|
|
import android.text.style.StyleSpan;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import android.widget.TextView;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubtech.utils.StringUtils;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.text.DecimalFormat;
|
|
import java.util.regex.Pattern;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class TextUtils {
|
|
public static void a(TextView textView, String str, String str2, ClickableSpan clickableSpan) {
|
|
int indexOf = str.indexOf(str2);
|
|
if (indexOf < 0) {
|
|
indexOf = 0;
|
|
}
|
|
int length = str2.length() + indexOf;
|
|
SpannableString spannableString = new SpannableString(str);
|
|
spannableString.setSpan(clickableSpan, indexOf, length, 33);
|
|
textView.setText(spannableString);
|
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
}
|
|
|
|
private static boolean a(char c) {
|
|
return (c == 0 || c == '\t' || c == '\n' || c == '\r' || (c >= ' ' && c <= 55295) || ((c >= 57344 && c <= 65533) || (c >= 0 && c <= 65535))) ? false : true;
|
|
}
|
|
|
|
public static boolean b(String str) {
|
|
return Pattern.compile("^[A-Za-z]+$").matcher(str).matches();
|
|
}
|
|
|
|
public static boolean c(String str) {
|
|
return Pattern.compile("^[0-9]+$").matcher(str).matches();
|
|
}
|
|
|
|
public static boolean d(String str) {
|
|
return Pattern.compile("^[A-Za-z0-9]+$").matcher(str).matches();
|
|
}
|
|
|
|
public static String e(String str) {
|
|
if (str == null || str.length() == 0) {
|
|
return str;
|
|
}
|
|
if (str.toLowerCase().startsWith("https")) {
|
|
try {
|
|
return URLEncoder.encode(str, "UTF-8");
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
return str;
|
|
}
|
|
}
|
|
String replace = str.replace("http", "https");
|
|
try {
|
|
return URLEncoder.encode(replace, "UTF-8");
|
|
} catch (UnsupportedEncodingException e2) {
|
|
e2.printStackTrace();
|
|
return replace;
|
|
}
|
|
}
|
|
|
|
public static int f(String str) {
|
|
if (StringUtils.e(str) || str.equals("local")) {
|
|
return 0;
|
|
}
|
|
return Integer.parseInt(str);
|
|
}
|
|
|
|
public static SpannableString a(String str, String str2, int i, int i2) {
|
|
SpannableString spannableString = new SpannableString(str);
|
|
spannableString.setSpan(new ForegroundColorSpan(i2), i, str2.length() + i, 33);
|
|
return spannableString;
|
|
}
|
|
|
|
public static SpannableString a(String str, int i, int i2, int i3) {
|
|
SpannableString spannableString = new SpannableString(str);
|
|
spannableString.setSpan(new ForegroundColorSpan(i3), i, i2, 33);
|
|
return spannableString;
|
|
}
|
|
|
|
public static SpannableString a(int i, int i2, String str) {
|
|
if (str == null) {
|
|
str = "";
|
|
}
|
|
SpannableString spannableString = new SpannableString(str);
|
|
spannableString.setSpan(new StyleSpan(1), i, i2, 33);
|
|
return spannableString;
|
|
}
|
|
|
|
public static String a(Context context, long j) {
|
|
long currentTimeMillis = (System.currentTimeMillis() - j) / 1000;
|
|
if (currentTimeMillis < 60) {
|
|
return context.getString(R.string.time_second);
|
|
}
|
|
if (currentTimeMillis < 3600) {
|
|
return String.format(context.getString(R.string.time_minute), (currentTimeMillis / 60) + "");
|
|
}
|
|
if (currentTimeMillis < 86400) {
|
|
return String.format(context.getString(R.string.time_hour), (currentTimeMillis / 3600) + "");
|
|
}
|
|
if (currentTimeMillis < 2592000) {
|
|
return String.format(context.getString(R.string.time_day), (currentTimeMillis / 86400) + "");
|
|
}
|
|
if (currentTimeMillis < 31104000) {
|
|
return String.format(context.getString(R.string.time_month), (currentTimeMillis / 2592000) + "");
|
|
}
|
|
return String.format(context.getString(R.string.time_year), (currentTimeMillis / 31104000) + "");
|
|
}
|
|
|
|
public static String a(int i) {
|
|
return i > 1000 ? String.format("%s k", new DecimalFormat("#.0").format(i / 1000)) : String.valueOf(i);
|
|
}
|
|
|
|
public static boolean a(String str) {
|
|
try {
|
|
return Pattern.compile("^[a-zA-Z0-9_\\-\\.]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$").matcher(str).matches();
|
|
} catch (Exception unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static boolean a(String str, int i, EditText editText) {
|
|
char[] charArray = str.toCharArray();
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
for (char c : charArray) {
|
|
i2 = StringUtils.a(c) ? i2 + 2 : i2 + 1;
|
|
i3++;
|
|
if (i2 > i) {
|
|
break;
|
|
}
|
|
}
|
|
if (i2 > i) {
|
|
int i4 = i3 - 1;
|
|
editText.setText(charArray, 0, i4);
|
|
editText.setSelection(i4);
|
|
return true;
|
|
}
|
|
LogUtils.d("leng=" + i2);
|
|
return false;
|
|
}
|
|
|
|
public static boolean a() {
|
|
return !Cache.getInstance().getUserId().equals("local");
|
|
}
|
|
|
|
public static void a(View view, boolean z) {
|
|
if (z) {
|
|
view.setAlpha(1.0f);
|
|
} else {
|
|
view.setAlpha(0.3f);
|
|
}
|
|
view.setEnabled(z);
|
|
}
|
|
|
|
public static String a(EditText editText, String str) {
|
|
if (str == null || str.length() < 1) {
|
|
return "";
|
|
}
|
|
char[] charArray = str.toCharArray();
|
|
StringBuilder sb = new StringBuilder();
|
|
boolean z = false;
|
|
for (int i = 0; i < str.length(); i++) {
|
|
try {
|
|
if (a(str.charAt(i))) {
|
|
charArray[i] = 0;
|
|
z = true;
|
|
} else {
|
|
sb.append(charArray[i]);
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
if (z) {
|
|
editText.setText(sb.toString());
|
|
editText.setSelection(sb.length());
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public static boolean a(String str, String str2) {
|
|
if (android.text.TextUtils.isEmpty(str)) {
|
|
return false;
|
|
}
|
|
try {
|
|
return Pattern.compile(str2).matcher(str).find();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
}
|