parent
e435a31697
commit
9a8a88944a
@ -1,108 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.ContentResolver; |
||||
import android.provider.Settings; |
||||
import android.util.Log; |
||||
import android.view.WindowManager; |
||||
|
||||
/** |
||||
* Created by newbiechen on 17-5-19. |
||||
* 调节亮度的工具类 |
||||
*/ |
||||
|
||||
public class BrightnessUtils { |
||||
private static final String TAG = "BrightnessUtils"; |
||||
|
||||
/** |
||||
* 判断是否开启了自动亮度调节 |
||||
*/ |
||||
public static boolean isAutoBrightness(Activity activity) { |
||||
boolean isAuto = false; |
||||
try { |
||||
isAuto = Settings.System.getInt(activity.getContentResolver(), |
||||
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; |
||||
} catch (Settings.SettingNotFoundException e){ |
||||
e.printStackTrace(); |
||||
} |
||||
return isAuto; |
||||
} |
||||
|
||||
/** |
||||
* 获取屏幕的亮度 |
||||
* 系统亮度模式中,自动模式与手动模式获取到的系统亮度的值不同 |
||||
*/ |
||||
public static int getScreenBrightness(Activity activity) { |
||||
if(isAutoBrightness(activity)){ |
||||
return getAutoScreenBrightness(activity); |
||||
}else{ |
||||
return getManualScreenBrightness(activity); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取手动模式下的屏幕亮度 |
||||
* @return value:0~255 |
||||
*/ |
||||
public static int getManualScreenBrightness(Activity activity) { |
||||
int nowBrightnessValue = 0; |
||||
ContentResolver resolver = activity.getContentResolver(); |
||||
try { |
||||
nowBrightnessValue = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return nowBrightnessValue; |
||||
} |
||||
|
||||
/** |
||||
* 获取自动模式下的屏幕亮度 |
||||
* @return value:0~255 |
||||
*/ |
||||
public static int getAutoScreenBrightness(Activity activity) { |
||||
float nowBrightnessValue = 0; |
||||
|
||||
//获取自动调节下的亮度范围在 0~1 之间
|
||||
ContentResolver resolver = activity.getContentResolver(); |
||||
try { |
||||
nowBrightnessValue = Settings.System.getFloat(resolver, Settings.System.SCREEN_BRIGHTNESS); |
||||
Log.d(TAG, "getAutoScreenBrightness: " + nowBrightnessValue); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
//转换范围为 (0~255)
|
||||
float fValue = nowBrightnessValue * 225.0f; |
||||
Log.d(TAG,"brightness: " + fValue); |
||||
return (int)fValue; |
||||
} |
||||
|
||||
/** |
||||
* 设置亮度:通过设置 Windows 的 screenBrightness 来修改当前 Windows 的亮度 |
||||
* lp.screenBrightness:参数范围为 0~1 |
||||
*/ |
||||
public static void setBrightness(Activity activity, int brightness) { |
||||
try{ |
||||
WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); |
||||
//将 0~255 范围内的数据,转换为 0~1
|
||||
lp.screenBrightness = Float.valueOf(brightness) * (1f / 255f); |
||||
Log.d(TAG, "lp.screenBrightness == " + lp.screenBrightness); |
||||
activity.getWindow().setAttributes(lp); |
||||
}catch(Exception ex){ |
||||
ex.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取当前系统的亮度 |
||||
* @param activity |
||||
*/ |
||||
public static void setDefaultBrightness(Activity activity) { |
||||
try { |
||||
WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); |
||||
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; |
||||
activity.getWindow().setAttributes(lp); |
||||
} catch (Exception ex) { |
||||
ex.printStackTrace(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,116 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import android.app.Activity |
||||
import android.content.ContentResolver |
||||
import android.provider.Settings |
||||
import android.util.Log |
||||
import android.view.WindowManager |
||||
|
||||
/** |
||||
* Created by zlj |
||||
* 调节亮度的工具类 |
||||
*/ |
||||
|
||||
object BrightnessUtils { |
||||
private val TAG = "BrightnessUtils" |
||||
|
||||
/** |
||||
* 判断是否开启了自动亮度调节 |
||||
*/ |
||||
fun isAutoBrightness(activity: Activity): Boolean { |
||||
var isAuto = false |
||||
try { |
||||
isAuto = Settings.System.getInt( |
||||
activity.contentResolver, |
||||
Settings.System.SCREEN_BRIGHTNESS_MODE |
||||
) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC |
||||
} catch (e: Settings.SettingNotFoundException) { |
||||
e.printStackTrace() |
||||
} |
||||
|
||||
return isAuto |
||||
} |
||||
|
||||
/** |
||||
* 获取屏幕的亮度 |
||||
* 系统亮度模式中,自动模式与手动模式获取到的系统亮度的值不同 |
||||
*/ |
||||
fun getScreenBrightness(activity: Activity): Int { |
||||
return if (isAutoBrightness(activity)) { |
||||
getAutoScreenBrightness(activity) |
||||
} else { |
||||
getManualScreenBrightness(activity) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取手动模式下的屏幕亮度 |
||||
* @return value:0~255 |
||||
*/ |
||||
fun getManualScreenBrightness(activity: Activity): Int { |
||||
var nowBrightnessValue = 0 |
||||
val resolver = activity.contentResolver |
||||
try { |
||||
nowBrightnessValue = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS) |
||||
} catch (e: Exception) { |
||||
e.printStackTrace() |
||||
} |
||||
|
||||
return nowBrightnessValue |
||||
} |
||||
|
||||
/** |
||||
* 获取自动模式下的屏幕亮度 |
||||
* @return value:0~255 |
||||
*/ |
||||
fun getAutoScreenBrightness(activity: Activity): Int { |
||||
var nowBrightnessValue = 0f |
||||
|
||||
//获取自动调节下的亮度范围在 0~1 之间 |
||||
val resolver = activity.contentResolver |
||||
try { |
||||
nowBrightnessValue = |
||||
Settings.System.getFloat(resolver, Settings.System.SCREEN_BRIGHTNESS) |
||||
Log.d(TAG, "getAutoScreenBrightness: $nowBrightnessValue") |
||||
} catch (e: Exception) { |
||||
e.printStackTrace() |
||||
} |
||||
|
||||
//转换范围为 (0~255) |
||||
val fValue = nowBrightnessValue * 225.0f |
||||
Log.d(TAG, "brightness: $fValue") |
||||
return fValue.toInt() |
||||
} |
||||
|
||||
/** |
||||
* 设置亮度:通过设置 Windows 的 screenBrightness 来修改当前 Windows 的亮度 |
||||
* lp.screenBrightness:参数范围为 0~1 |
||||
*/ |
||||
fun setBrightness(activity: Activity, brightness: Int) { |
||||
try { |
||||
val lp = activity.window.attributes |
||||
//将 0~255 范围内的数据,转换为 0~1 |
||||
lp.screenBrightness = java.lang.Float.valueOf(brightness.toFloat()) * (1f / 255f) |
||||
Log.d(TAG, "lp.screenBrightness == " + lp.screenBrightness) |
||||
activity.window.attributes = lp |
||||
} catch (ex: Exception) { |
||||
ex.printStackTrace() |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取当前系统的亮度 |
||||
* @param activity |
||||
*/ |
||||
fun setDefaultBrightness(activity: Activity) { |
||||
try { |
||||
val lp = activity.window.attributes |
||||
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE |
||||
activity.window.attributes = lp |
||||
} catch (ex: Exception) { |
||||
ex.printStackTrace() |
||||
} |
||||
|
||||
} |
||||
} |
@ -1,35 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import java.util.Timer; |
||||
import java.util.TimerTask; |
||||
|
||||
/** |
||||
* create by zlj on 2019/7/15 |
||||
* describe: |
||||
*/ |
||||
public class MyTimeTask { |
||||
private Timer timer; |
||||
private TimerTask task; |
||||
private long time; |
||||
|
||||
public MyTimeTask(long time, TimerTask task) { |
||||
this.task = task; |
||||
this.time = time; |
||||
if (timer == null){ |
||||
timer=new Timer(); |
||||
} |
||||
} |
||||
|
||||
public void start(){ |
||||
timer.schedule(task, 0, time);//每隔time时间段就执行一次
|
||||
} |
||||
|
||||
public void stop(){ |
||||
if (timer != null) { |
||||
timer.cancel(); |
||||
if (task != null) { |
||||
task.cancel(); //将原任务从队列中移除
|
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import java.util.* |
||||
|
||||
/** |
||||
* create by zlj on 2019/7/15 |
||||
* describe: |
||||
*/ |
||||
class MyTimeTask(private val time: Long, private val task: TimerTask?) { |
||||
|
||||
private var timer: Timer? = null |
||||
|
||||
init { |
||||
if (timer == null) { |
||||
timer = Timer() |
||||
} |
||||
} |
||||
|
||||
fun start() { |
||||
timer!!.schedule(task, 0, time)//每隔time时间段就执行一次 |
||||
} |
||||
|
||||
fun stop() { |
||||
if (timer != null) { |
||||
timer!!.cancel() |
||||
task?.cancel() |
||||
} |
||||
} |
||||
} |
@ -1,61 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.content.Context; |
||||
import android.net.ConnectivityManager; |
||||
import android.net.NetworkInfo; |
||||
|
||||
import com.novel.read.base.MyApp; |
||||
|
||||
/** |
||||
* Created by newbiechen on 17-5-11. |
||||
*/ |
||||
|
||||
public class NetworkUtils { |
||||
|
||||
|
||||
/** |
||||
* 获取活动网络信息 |
||||
* @return NetworkInfo |
||||
*/ |
||||
public static NetworkInfo getNetworkInfo(){ |
||||
ConnectivityManager cm = (ConnectivityManager) MyApp.Companion.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
||||
|
||||
return cm.getActiveNetworkInfo(); |
||||
} |
||||
|
||||
/** |
||||
* 网络是否可用 |
||||
* @return |
||||
*/ |
||||
public static boolean isAvailable(){ |
||||
NetworkInfo info = getNetworkInfo(); |
||||
return info != null && info.isAvailable(); |
||||
} |
||||
|
||||
/** |
||||
* 网络是否连接 |
||||
* @return |
||||
*/ |
||||
public static boolean isConnected(){ |
||||
NetworkInfo info = getNetworkInfo(); |
||||
return info != null && info.isConnected(); |
||||
} |
||||
|
||||
/** |
||||
* 判断wifi是否连接状态 |
||||
* <p>需添加权限 {@code <uses-permission android:name="android.permission |
||||
* .ACCESS_NETWORK_STATE"/>}</p> |
||||
* |
||||
* @param context 上下文 |
||||
* @return {@code true}: 连接<br>{@code false}: 未连接 |
||||
*/ |
||||
public static boolean isWifiConnected(Context context) { |
||||
ConnectivityManager cm = (ConnectivityManager) context |
||||
.getSystemService(Context.CONNECTIVITY_SERVICE); |
||||
return cm != null && cm.getActiveNetworkInfo() != null |
||||
&& cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,58 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import android.content.Context |
||||
import android.net.ConnectivityManager |
||||
import android.net.NetworkInfo |
||||
|
||||
import com.novel.read.base.MyApp |
||||
|
||||
object NetworkUtils { |
||||
|
||||
/** |
||||
* 获取活动网络信息 |
||||
* @return NetworkInfo |
||||
*/ |
||||
private val networkInfo: NetworkInfo? |
||||
get() { |
||||
val cm = MyApp.context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |
||||
return cm.activeNetworkInfo |
||||
} |
||||
|
||||
/** |
||||
* 网络是否可用 |
||||
* @return |
||||
*/ |
||||
val isAvailable: Boolean |
||||
get() { |
||||
val info = networkInfo |
||||
return info != null && info.isAvailable |
||||
} |
||||
|
||||
/** |
||||
* 网络是否连接 |
||||
* @return |
||||
*/ |
||||
val isConnected: Boolean |
||||
get() { |
||||
val info = networkInfo |
||||
return info != null && info.isConnected |
||||
} |
||||
|
||||
/** |
||||
* 判断wifi是否连接状态 |
||||
* |
||||
* 需添加权限 `<uses-permission android:name="android.permission |
||||
* .ACCESS_NETWORK_STATE"/>` |
||||
* |
||||
* @param context 上下文 |
||||
* @return `true`: 连接<br></br>`false`: 未连接 |
||||
*/ |
||||
fun isWifiConnected(context: Context): Boolean { |
||||
val cm = context |
||||
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |
||||
return (cm.activeNetworkInfo != null |
||||
&& cm.activeNetworkInfo.type == ConnectivityManager.TYPE_WIFI) |
||||
} |
||||
|
||||
|
||||
} |
@ -1,30 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.content.Context; |
||||
import android.content.pm.PackageManager; |
||||
|
||||
import androidx.core.content.ContextCompat; |
||||
|
||||
public class PermissionsChecker { |
||||
private final Context mContext; |
||||
|
||||
public PermissionsChecker(Context context) { |
||||
mContext = context.getApplicationContext(); |
||||
} |
||||
|
||||
// 判断权限集合
|
||||
public boolean lacksPermissions(String... permissions) { |
||||
for (String permission : permissions) { |
||||
if (lacksPermission(permission)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
// 判断是否缺少权限
|
||||
private boolean lacksPermission(String permission) { |
||||
return ContextCompat.checkSelfPermission(mContext, permission) == |
||||
PackageManager.PERMISSION_DENIED; |
||||
} |
||||
} |
@ -1,112 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.annotation.SuppressLint; |
||||
import android.content.Context; |
||||
import android.os.Build; |
||||
import android.telephony.TelephonyManager; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
public class PhoneUtils { |
||||
private TelephonyManager telephonemanager; |
||||
private String IMSI; |
||||
private Context ctx; |
||||
|
||||
/** |
||||
* 获取手机国际识别码IMEI |
||||
*/ |
||||
public PhoneUtils(Context context) { |
||||
ctx = context; |
||||
telephonemanager = (TelephonyManager) context |
||||
.getSystemService(Context.TELEPHONY_SERVICE); |
||||
} |
||||
|
||||
/** |
||||
* 获取手机号码 |
||||
*/ |
||||
@SuppressLint("MissingPermission") |
||||
public String getNativePhoneNumber() { |
||||
|
||||
String nativephonenumber = null; |
||||
nativephonenumber = telephonemanager.getLine1Number(); |
||||
|
||||
return nativephonenumber; |
||||
} |
||||
|
||||
/** |
||||
* 获取手机服务商信息 |
||||
*/ |
||||
@SuppressLint("MissingPermission") |
||||
public String getProvidersName() { |
||||
String providerName = null; |
||||
try { |
||||
IMSI = telephonemanager.getSubscriberId(); |
||||
//IMSI前面三位460是国家号码,其次的两位是运营商代号,00、02是中国移动,01是联通,03是电信。
|
||||
System.out.print("IMSI是:" + IMSI); |
||||
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) { |
||||
providerName = "中国移动"; |
||||
} else if (IMSI.startsWith("46001")) { |
||||
providerName = "中国联通"; |
||||
} else if (IMSI.startsWith("46003")) { |
||||
providerName = "中国电信"; |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return providerName; |
||||
|
||||
} |
||||
|
||||
|
||||
public static String getUniquePsuedoID() { |
||||
String serial = null; |
||||
String m_szDevIDShort = "35" + // 35是IMEI开头的号
|
||||
Build.BOARD.length() % 10 + Build.BRAND.length() % 10 |
||||
+ Build.CPU_ABI.length() % 10 |
||||
+ Build.DEVICE.length() % 10 |
||||
+ Build.DISPLAY.length() % 10 |
||||
+ Build.HOST.length() % 10 |
||||
+ Build.ID.length() % 10 |
||||
+ Build.MANUFACTURER.length() % 10 |
||||
+ Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 |
||||
+ Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + |
||||
Build.USER.length() % 10; |
||||
//13 位
|
||||
try { |
||||
serial = Build.class.getField("SERIAL").get(null).toString(); |
||||
//API>=9 使用serial号
|
||||
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); |
||||
} catch (Exception exception) {//serial需要一个初始化
|
||||
serial = "serial"; // 随便一个初始化
|
||||
} |
||||
//使用硬件信息拼凑出来的15位号码
|
||||
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); |
||||
} |
||||
|
||||
/** |
||||
* 获取手机信息 |
||||
*/ |
||||
@SuppressLint("MissingPermission") |
||||
public String getPhoneInfo() { |
||||
|
||||
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); |
||||
return tm.getDeviceId(); |
||||
// return ("\nDeviceID(IMEI)" + tm.getDeviceId()) +
|
||||
// "\nDeviceSoftwareVersion:" + tm.getDeviceSoftwareVersion() +
|
||||
// "\ngetLine1Number:" + tm.getLine1Number() +
|
||||
// "\nNetworkCountryIso:" + tm.getNetworkCountryIso() +
|
||||
// "\nNetworkOperator:" + tm.getNetworkOperator() +
|
||||
// "\nNetworkOperatorName:" + tm.getNetworkOperatorName() +
|
||||
// "\nNetworkType:" + tm.getNetworkType() +
|
||||
// "\nPhoneType:" + tm.getPhoneType() +
|
||||
// "\nSimCountryIso:" + tm.getSimCountryIso() +
|
||||
// "\nSimOperator:" + tm.getSimOperator() +
|
||||
// "\nSimOperatorName:" + tm.getSimOperatorName() +
|
||||
// "\nSimSerialNumber:" + tm.getSimSerialNumber() +
|
||||
// "\ngetSimState:" + tm.getSimState() +
|
||||
// "\nSubscriberId:" + tm.getSubscriberId() +
|
||||
// "\nVoiceMailNumber:" + tm.getVoiceMailNumber();
|
||||
|
||||
} |
||||
} |
@ -0,0 +1,122 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import android.annotation.SuppressLint |
||||
import android.content.Context |
||||
import android.os.Build |
||||
import android.telephony.TelephonyManager |
||||
import java.util.* |
||||
|
||||
/** |
||||
* 获取手机国际识别码IMEI |
||||
*/ |
||||
class PhoneUtils(private val ctx: Context) { |
||||
|
||||
private val telephonemanager: TelephonyManager = ctx.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager |
||||
private var IMSI: String? = null |
||||
|
||||
/** |
||||
* 获取手机号码 |
||||
*/ |
||||
val nativePhoneNumber: String? |
||||
@SuppressLint("MissingPermission") |
||||
get() { |
||||
|
||||
var nativephonenumber: String? = null |
||||
nativephonenumber = telephonemanager.line1Number |
||||
|
||||
return nativephonenumber |
||||
} |
||||
|
||||
/** |
||||
* 获取手机服务商信息 |
||||
*/ |
||||
//IMSI前面三位460是国家号码,其次的两位是运营商代号,00、02是中国移动,01是联通,03是电信。 |
||||
val providersName: String? |
||||
@SuppressLint("MissingPermission") |
||||
get() { |
||||
var providerName: String? = null |
||||
try { |
||||
IMSI = telephonemanager.subscriberId |
||||
print("IMSI是:" + IMSI!!) |
||||
if (IMSI!!.startsWith("46000") || IMSI!!.startsWith("46002")) { |
||||
providerName = "中国移动" |
||||
} else if (IMSI!!.startsWith("46001")) { |
||||
providerName = "中国联通" |
||||
} else if (IMSI!!.startsWith("46003")) { |
||||
providerName = "中国电信" |
||||
} |
||||
|
||||
} catch (e: Exception) { |
||||
e.printStackTrace() |
||||
} |
||||
|
||||
return providerName |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取手机信息 |
||||
*/ |
||||
// return ("\nDeviceID(IMEI)" + tm.getDeviceId()) + |
||||
// "\nDeviceSoftwareVersion:" + tm.getDeviceSoftwareVersion() + |
||||
// "\ngetLine1Number:" + tm.getLine1Number() + |
||||
// "\nNetworkCountryIso:" + tm.getNetworkCountryIso() + |
||||
// "\nNetworkOperator:" + tm.getNetworkOperator() + |
||||
// "\nNetworkOperatorName:" + tm.getNetworkOperatorName() + |
||||
// "\nNetworkType:" + tm.getNetworkType() + |
||||
// "\nPhoneType:" + tm.getPhoneType() + |
||||
// "\nSimCountryIso:" + tm.getSimCountryIso() + |
||||
// "\nSimOperator:" + tm.getSimOperator() + |
||||
// "\nSimOperatorName:" + tm.getSimOperatorName() + |
||||
// "\nSimSerialNumber:" + tm.getSimSerialNumber() + |
||||
// "\ngetSimState:" + tm.getSimState() + |
||||
// "\nSubscriberId:" + tm.getSubscriberId() + |
||||
// "\nVoiceMailNumber:" + tm.getVoiceMailNumber(); |
||||
val phoneInfo: String |
||||
@SuppressLint("MissingPermission") |
||||
get() { |
||||
|
||||
val tm = ctx.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager |
||||
return tm.deviceId |
||||
|
||||
} |
||||
|
||||
companion object { |
||||
|
||||
// 35是IMEI开头的号 |
||||
//13 位 |
||||
//API>=9 使用serial号 |
||||
//serial需要一个初始化 |
||||
// 随便一个初始化 |
||||
//使用硬件信息拼凑出来的15位号码 |
||||
val uniquePsuedoID: String |
||||
get() { |
||||
var serial: String? = null |
||||
val m_szDevIDShort = ("35" + |
||||
Build.BOARD.length % 10 + Build.BRAND.length % 10 |
||||
+ Build.CPU_ABI.length % 10 |
||||
+ Build.DEVICE.length % 10 |
||||
+ Build.DISPLAY.length % 10 |
||||
+ Build.HOST.length % 10 |
||||
+ Build.ID.length % 10 |
||||
+ Build.MANUFACTURER.length % 10 |
||||
+ Build.MODEL.length % 10 + Build.PRODUCT.length % 10 |
||||
+ Build.TAGS.length % 10 + Build.TYPE.length % 10 + |
||||
Build.USER.length % 10) |
||||
try { |
||||
serial = Build::class.java.getField("SERIAL").get(null).toString() |
||||
return UUID( |
||||
m_szDevIDShort.hashCode().toLong(), |
||||
serial.hashCode().toLong() |
||||
).toString() |
||||
} catch (exception: Exception) { |
||||
serial = "serial" |
||||
} |
||||
|
||||
return UUID( |
||||
m_szDevIDShort.hashCode().toLong(), |
||||
serial!!.hashCode().toLong() |
||||
).toString() |
||||
} |
||||
} |
||||
} |
@ -1,122 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.content.res.Resources; |
||||
import android.util.DisplayMetrics; |
||||
import android.util.TypedValue; |
||||
import android.view.View; |
||||
|
||||
import androidx.appcompat.app.AppCompatActivity; |
||||
|
||||
import com.novel.read.base.MyApp; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* Created by newbiechen on 17-5-1. |
||||
*/ |
||||
|
||||
public class ScreenUtils { |
||||
|
||||
public static int dpToPx(int dp){ |
||||
DisplayMetrics metrics = getDisplayMetrics(); |
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,metrics); |
||||
} |
||||
|
||||
public static int pxToDp(int px){ |
||||
DisplayMetrics metrics = getDisplayMetrics(); |
||||
return (int) (px / metrics.density); |
||||
} |
||||
|
||||
public static int spToPx(int sp){ |
||||
DisplayMetrics metrics = getDisplayMetrics(); |
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,sp,metrics); |
||||
} |
||||
|
||||
public static int pxToSp(int px){ |
||||
DisplayMetrics metrics = getDisplayMetrics(); |
||||
return (int) (px / metrics.scaledDensity); |
||||
} |
||||
|
||||
/** |
||||
* 获取手机显示App区域的大小(头部导航栏+ActionBar+根布局),不包括虚拟按钮 |
||||
* @return |
||||
*/ |
||||
public static int[] getAppSize(){ |
||||
int[] size = new int[2]; |
||||
DisplayMetrics metrics = getDisplayMetrics(); |
||||
size[0] = metrics.widthPixels; |
||||
size[1] = metrics.heightPixels; |
||||
return size; |
||||
} |
||||
|
||||
/** |
||||
* 获取整个手机屏幕的大小(包括虚拟按钮) |
||||
* 必须在onWindowFocus方法之后使用 |
||||
* @param activity |
||||
* @return |
||||
*/ |
||||
public static int[] getScreenSize(AppCompatActivity activity){ |
||||
int[] size = new int[2]; |
||||
View decorView = activity.getWindow().getDecorView(); |
||||
size[0] = decorView.getWidth(); |
||||
size[1] = decorView.getHeight(); |
||||
return size; |
||||
} |
||||
|
||||
/** |
||||
* 获取导航栏的高度 |
||||
* @return |
||||
*/ |
||||
public static int getStatusBarHeight(){ |
||||
Resources resources = MyApp.Companion.getContext().getResources(); |
||||
int resourceId = resources.getIdentifier("status_bar_height","dimen","android"); |
||||
return resources.getDimensionPixelSize(resourceId); |
||||
} |
||||
|
||||
/** |
||||
* 获取虚拟按键的高度 |
||||
* @return |
||||
*/ |
||||
public static int getNavigationBarHeight() { |
||||
int navigationBarHeight = 0; |
||||
Resources rs = MyApp.Companion.getContext().getResources(); |
||||
int id = rs.getIdentifier("navigation_bar_height", "dimen", "android"); |
||||
if (id > 0 && hasNavigationBar()) { |
||||
navigationBarHeight = rs.getDimensionPixelSize(id); |
||||
} |
||||
return navigationBarHeight; |
||||
} |
||||
|
||||
/** |
||||
* 是否存在虚拟按键 |
||||
* @return |
||||
*/ |
||||
private static boolean hasNavigationBar() { |
||||
boolean hasNavigationBar = false; |
||||
Resources rs = MyApp.Companion.getContext().getResources(); |
||||
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android"); |
||||
if (id > 0) { |
||||
hasNavigationBar = rs.getBoolean(id); |
||||
} |
||||
try { |
||||
Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); |
||||
Method m = systemPropertiesClass.getMethod("get", String.class); |
||||
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys"); |
||||
if ("1".equals(navBarOverride)) { |
||||
hasNavigationBar = false; |
||||
} else if ("0".equals(navBarOverride)) { |
||||
hasNavigationBar = true; |
||||
} |
||||
} catch (Exception e) { |
||||
} |
||||
return hasNavigationBar; |
||||
} |
||||
|
||||
public static DisplayMetrics getDisplayMetrics(){ |
||||
DisplayMetrics metrics = MyApp |
||||
.Companion.getContext() |
||||
.getResources() |
||||
.getDisplayMetrics(); |
||||
return metrics; |
||||
} |
||||
} |
@ -0,0 +1,113 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import android.util.DisplayMetrics |
||||
import android.util.TypedValue |
||||
import androidx.appcompat.app.AppCompatActivity |
||||
import com.novel.read.base.MyApp |
||||
|
||||
object ScreenUtils { |
||||
|
||||
/** |
||||
* 获取手机显示App区域的大小(头部导航栏+ActionBar+根布局),不包括虚拟按钮 |
||||
* @return |
||||
*/ |
||||
val appSize: IntArray |
||||
get() { |
||||
val size = IntArray(2) |
||||
val metrics = displayMetrics |
||||
size[0] = metrics.widthPixels |
||||
size[1] = metrics.heightPixels |
||||
return size |
||||
} |
||||
|
||||
/** |
||||
* 获取导航栏的高度 |
||||
* @return |
||||
*/ |
||||
val statusBarHeight: Int |
||||
get() { |
||||
val resources = MyApp.context.resources |
||||
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") |
||||
return resources.getDimensionPixelSize(resourceId) |
||||
} |
||||
|
||||
/** |
||||
* 获取虚拟按键的高度 |
||||
* @return |
||||
*/ |
||||
val navigationBarHeight: Int |
||||
get() { |
||||
var navigationBarHeight = 0 |
||||
val rs = MyApp.context.resources |
||||
val id = rs.getIdentifier("navigation_bar_height", "dimen", "android") |
||||
if (id > 0 && hasNavigationBar()) { |
||||
navigationBarHeight = rs.getDimensionPixelSize(id) |
||||
} |
||||
return navigationBarHeight |
||||
} |
||||
|
||||
private val displayMetrics: DisplayMetrics |
||||
get() = MyApp.context |
||||
.resources |
||||
.displayMetrics |
||||
|
||||
fun dpToPx(dp: Int): Int { |
||||
val metrics = displayMetrics |
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp.toFloat(), metrics).toInt() |
||||
} |
||||
|
||||
fun pxToDp(px: Int): Int { |
||||
val metrics = displayMetrics |
||||
return (px / metrics.density).toInt() |
||||
} |
||||
|
||||
fun spToPx(sp: Int): Int { |
||||
val metrics = displayMetrics |
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp.toFloat(), metrics).toInt() |
||||
} |
||||
|
||||
fun pxToSp(px: Int): Int { |
||||
val metrics = displayMetrics |
||||
return (px / metrics.scaledDensity).toInt() |
||||
} |
||||
|
||||
/** |
||||
* 获取整个手机屏幕的大小(包括虚拟按钮) |
||||
* 必须在onWindowFocus方法之后使用 |
||||
* @param activity |
||||
* @return |
||||
*/ |
||||
fun getScreenSize(activity: AppCompatActivity): IntArray { |
||||
val size = IntArray(2) |
||||
val decorView = activity.window.decorView |
||||
size[0] = decorView.width |
||||
size[1] = decorView.height |
||||
return size |
||||
} |
||||
|
||||
/** |
||||
* 是否存在虚拟按键 |
||||
* @return |
||||
*/ |
||||
private fun hasNavigationBar(): Boolean { |
||||
var hasNavigationBar = false |
||||
val rs = MyApp.context.resources |
||||
val id = rs.getIdentifier("config_showNavigationBar", "bool", "android") |
||||
if (id > 0) { |
||||
hasNavigationBar = rs.getBoolean(id) |
||||
} |
||||
try { |
||||
val systemPropertiesClass = Class.forName("android.os.SystemProperties") |
||||
val m = systemPropertiesClass.getMethod("get", String::class.java) |
||||
val navBarOverride = m.invoke(systemPropertiesClass, "qemu.hw.mainkeys") as String |
||||
if ("1" == navBarOverride) { |
||||
hasNavigationBar = false |
||||
} else if ("0" == navBarOverride) { |
||||
hasNavigationBar = true |
||||
} |
||||
} catch (e: Exception) { |
||||
} |
||||
|
||||
return hasNavigationBar |
||||
} |
||||
} |
@ -1,64 +0,0 @@ |
||||
package com.novel.read.utlis; |
||||
|
||||
import android.content.Context; |
||||
import android.text.TextUtils; |
||||
|
||||
import com.spreada.utils.chinese.ZHConverter; |
||||
|
||||
import static com.novel.read.widget.page.ReadSettingManager.SHARED_READ_CONVERT_TYPE; |
||||
|
||||
public class StringUtils { |
||||
|
||||
/** |
||||
* 将文本中的半角字符,转换成全角字符 |
||||
*/ |
||||
public static String halfToFull(String input) { |
||||
input = deleteImgs(input); |
||||
char[] c = input.toCharArray(); |
||||
for (int i = 0; i < c.length; i++) { |
||||
if (c[i] == 32) //半角空格
|
||||
{ |
||||
c[i] = (char) 12288; |
||||
continue; |
||||
} |
||||
//根据实际情况,过滤不需要转换的符号
|
||||
//if (c[i] == 46) //半角点号,不转换
|
||||
// continue;
|
||||
|
||||
if (c[i] > 32 && c[i] < 127) //其他符号都转换为全角
|
||||
c[i] = (char) (c[i] + 65248); |
||||
} |
||||
return new String(c); |
||||
} |
||||
|
||||
private static String deleteImgs(String content) { |
||||
if (content != null && !TextUtils.isEmpty(content)) { |
||||
// 去掉所有html元素,
|
||||
String str = content.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll( |
||||
"<[^>]*>", ""); |
||||
str = str.replaceAll("[(/>)<]", ""); |
||||
return str; |
||||
} else { |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
public static String delete160(String des) { |
||||
des = des.replaceAll(" ", ""); |
||||
des = des.replaceAll("&#160;", ""); |
||||
des = des.replaceAll("\\s*", ""); |
||||
des = des.trim(); |
||||
return des; |
||||
} |
||||
|
||||
//繁簡轉換
|
||||
public static String convertCC(String input) { |
||||
int convertType = SpUtil.getIntValue(SHARED_READ_CONVERT_TYPE, 1); |
||||
|
||||
if (input.length() == 0) |
||||
return ""; |
||||
|
||||
return (convertType != 0) ? ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(input) : input; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.novel.read.utlis |
||||
|
||||
import android.content.Context |
||||
import android.text.TextUtils |
||||
|
||||
import com.spreada.utils.chinese.ZHConverter |
||||
|
||||
import com.novel.read.widget.page.ReadSettingManager.SHARED_READ_CONVERT_TYPE |
||||
|
||||
object StringUtils { |
||||
|
||||
/** |
||||
* 将文本中的半角字符,转换成全角字符 |
||||
*/ |
||||
fun halfToFull(input: String): String { |
||||
val text = deleteImgs(input) |
||||
val c = text.toCharArray() |
||||
for (i in c.indices) { |
||||
if (c[i].toInt() == 32) |
||||
//半角空格 |
||||
{ |
||||
c[i] = 12288.toChar() |
||||
continue |
||||
} |
||||
//根据实际情况,过滤不需要转换的符号 |
||||
//if (c[i] == 46) //半角点号,不转换 |
||||
// continue; |
||||
|
||||
if (c[i].toInt() in 33..126) |
||||
//其他符号都转换为全角 |
||||
c[i] = (c[i].toInt() + 65248).toChar() |
||||
} |
||||
return String(c) |
||||
} |
||||
|
||||
private fun deleteImgs(content: String?): String { |
||||
return if (content != null && !TextUtils.isEmpty(content)) { |
||||
// 去掉所有html元素, |
||||
var str = |
||||
content.replace("&[a-zA-Z]{1,10};".toRegex(), "").replace("<[^>]*>".toRegex(), "") |
||||
str = str.replace("[(/>)<]".toRegex(), "") |
||||
str |
||||
} else { |
||||
"" |
||||
} |
||||
} |
||||
|
||||
fun delete160(des: String): String { |
||||
var text = des |
||||
text = text.replace(" ".toRegex(), "") |
||||
text = text.replace("&#160;".toRegex(), "") |
||||
text = text.replace("\\s*".toRegex(), "") |
||||
text = text.trim { it <= ' ' } |
||||
return text |
||||
} |
||||
|
||||
//繁簡轉換 |
||||
fun convertCC(input: String): String { |
||||
val convertType = SpUtil.getIntValue(SHARED_READ_CONVERT_TYPE, 1) |
||||
|
||||
if (input.isEmpty()) |
||||
return "" |
||||
|
||||
return if (convertType != 0) ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(input) else input |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue