转换部分java代码

old
zlj 5 years ago
parent e435a31697
commit 9a8a88944a
  1. 3
      .idea/codeStyles/Project.xml
  2. 4
      app/src/main/java/com/novel/read/activity/NovelReadActivity.kt
  3. 2
      app/src/main/java/com/novel/read/adapter/holder/CategoryHolder.java
  4. 23
      app/src/main/java/com/novel/read/fragment/MoreFragment.kt
  5. 5
      app/src/main/java/com/novel/read/http/AccountManager.kt
  6. 8
      app/src/main/java/com/novel/read/model/db/CollBookBean.java
  7. 2
      app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java
  8. 6
      app/src/main/java/com/novel/read/model/protocol/RankByUpdateResp.java
  9. 6
      app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java
  10. 6
      app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java
  11. 6
      app/src/main/java/com/novel/read/model/protocol/SearchResp.java
  12. 2
      app/src/main/java/com/novel/read/service/DownloadService.java
  13. 108
      app/src/main/java/com/novel/read/utlis/BrightnessUtils.java
  14. 116
      app/src/main/java/com/novel/read/utlis/BrightnessUtils.kt
  15. 4
      app/src/main/java/com/novel/read/utlis/Charset.java
  16. 1
      app/src/main/java/com/novel/read/utlis/CleanCacheUtils.java
  17. 35
      app/src/main/java/com/novel/read/utlis/MyTimeTask.java
  18. 29
      app/src/main/java/com/novel/read/utlis/MyTimeTask.kt
  19. 61
      app/src/main/java/com/novel/read/utlis/NetworkUtils.java
  20. 58
      app/src/main/java/com/novel/read/utlis/NetworkUtils.kt
  21. 30
      app/src/main/java/com/novel/read/utlis/PermissionsChecker.java
  22. 112
      app/src/main/java/com/novel/read/utlis/PhoneUtils.java
  23. 122
      app/src/main/java/com/novel/read/utlis/PhoneUtils.kt
  24. 4
      app/src/main/java/com/novel/read/utlis/RxUtils.java
  25. 122
      app/src/main/java/com/novel/read/utlis/ScreenUtils.java
  26. 113
      app/src/main/java/com/novel/read/utlis/ScreenUtils.kt
  27. 64
      app/src/main/java/com/novel/read/utlis/StringUtils.java
  28. 67
      app/src/main/java/com/novel/read/utlis/StringUtils.kt
  29. 2
      app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java
  30. 28
      app/src/main/java/com/novel/read/widget/page/PageLoader.java
  31. 2
      app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java
  32. 2
      app/src/main/res/layout/dialog_go_appraise.xml

@ -1,5 +1,8 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<AndroidXmlCodeStyleSettings>
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>

@ -134,8 +134,8 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
SystemBarUtils.transparentStatusBar(this)
//隐藏StatusBar
read_pv_page!!.post { this.hideSystemBar() }
read_abl_top_menu.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, 0)
ll_download.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, ScreenUtils.dpToPx(15))
read_abl_top_menu.setPadding(0, ScreenUtils.statusBarHeight, 0, 0)
ll_download.setPadding(0, ScreenUtils.statusBarHeight, 0, ScreenUtils.dpToPx(15))
val lp = window.attributes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

@ -34,7 +34,7 @@ public class CategoryHolder extends ViewHolderImpl<TxtChapter> {
mTvChapter.setSelected(false);
mTvChapter.setTextColor(ContextCompat.getColor(getContext(),R.color.colorTitle));
mTvChapter.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
mTvChapter.setText(StringUtils.convertCC(value.getTitle()));
mTvChapter.setText(StringUtils.INSTANCE.convertCC(value.getTitle()));
}

@ -55,7 +55,9 @@ class MoreFragment : NovelBaseFragment() {
tv_appraise.setOnClickListener {
val dialog = AppraiseDialog(activity!!)
dialog.appraiseDialog(View.OnClickListener {
goToMarket(activity!!, VersionUtil.getPackage(activity!!))
val uri = Uri.parse("https://github.com/390057892/reader")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
dialog.dismiss()
})
dialog.show()
@ -100,25 +102,6 @@ class MoreFragment : NovelBaseFragment() {
return fragment
}
fun goToMarket(context: Context, packageName: String?) {
val uri = Uri.parse("market://details?id=" + packageName!!)
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
val googlePlay = "com.android.vending"//这里对应的是谷歌商店,跳转别的商店改成对应的即可
goToMarket.setPackage(googlePlay)//这里对应的是谷歌商店,跳转别的商店改成对应的即可
try {
context.startActivity(goToMarket)
} catch (e: ActivityNotFoundException) {
if (goToMarket.resolveActivity(context.packageManager) != null) { //有浏览器
context.startActivity(goToMarket)
} else {
context.showToast("未检测到Google应用商店")
}
e.printStackTrace()
}
}
}
override fun onDestroy() {

@ -183,8 +183,8 @@ class AccountManager private constructor() {
fun login(mContext: Context) {
val map = HashMap<String, String>()
Log.e("getUniquePsuedoID", "login: " + PhoneUtils.getUniquePsuedoID())
map["code"] = PhoneUtils.getUniquePsuedoID()
Log.e("getUniquePsuedoID", "login: " + PhoneUtils.uniquePsuedoID)
map["code"] = PhoneUtils.uniquePsuedoID
val call = accountService.login(Urls.login, mapToBody(map))
call.enqueue(ServiceCallback(LoginEvent::class.java))
}
@ -233,7 +233,6 @@ class AccountManager private constructor() {
if (bookChapters[0].title == title) {
EventManager.instance.postEvent(ErrorChapterEvent())
}
LogUtils.e(t)
}
override fun onComplete() {}

@ -73,7 +73,7 @@ public class CollBookBean extends LitePalSupport implements Serializable {
}
public String getTitle() {
return title == null ? "" : StringUtils.convertCC(title);
return title == null ? "" : StringUtils.INSTANCE.convertCC(title);
}
public void setTitle(String title) {
@ -81,7 +81,7 @@ public class CollBookBean extends LitePalSupport implements Serializable {
}
public String getAuthor() {
return author == null ? "" :StringUtils.convertCC(author);
return author == null ? "" : StringUtils.INSTANCE.convertCC(author);
}
public void setAuthor(String author) {
@ -89,7 +89,7 @@ public class CollBookBean extends LitePalSupport implements Serializable {
}
public String getShortIntro() {
return shortIntro == null ? "" :StringUtils.convertCC(shortIntro);
return shortIntro == null ? "" : StringUtils.INSTANCE.convertCC(shortIntro);
}
public void setShortIntro(String shortIntro) {
@ -153,7 +153,7 @@ public class CollBookBean extends LitePalSupport implements Serializable {
}
public String getLastChapter() {
return lastChapter == null ? "" : StringUtils.convertCC(lastChapter);
return lastChapter == null ? "" : StringUtils.INSTANCE.convertCC(lastChapter);
}
public void setLastChapter(String lastChapter) {

@ -83,7 +83,7 @@ public class BookDetailResp {
}
public String getDescription() {
return description == null ? "" : StringUtils.delete160(description);
return description == null ? "" : StringUtils.INSTANCE.delete160(description);
}
public void setDescription(String description) {

@ -57,7 +57,7 @@ public class RankByUpdateResp implements Serializable {
}
public String getTitle() {
return title == null ? "" : StringUtils.convertCC(title);
return title == null ? "" : StringUtils.INSTANCE.convertCC(title);
}
public void setTitle(String title) {
@ -73,7 +73,7 @@ public class RankByUpdateResp implements Serializable {
}
public String getDescription() {
return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description));
return description == null ? "" : StringUtils.INSTANCE.convertCC(StringUtils.INSTANCE.delete160(description));
}
public void setDescription(String description) {
@ -97,7 +97,7 @@ public class RankByUpdateResp implements Serializable {
}
public String getAuthor() {
return author == null ? "" :StringUtils.convertCC(author);
return author == null ? "" : StringUtils.INSTANCE.convertCC(author);
}
public void setAuthor(String author) {

@ -54,7 +54,7 @@ public class RecommendBookResp implements Serializable {
}
public String getTitle() {
return title == null ? "" : StringUtils.convertCC(title);
return title == null ? "" : StringUtils.INSTANCE.convertCC(title);
}
public void setTitle(String title) {
@ -70,7 +70,7 @@ public class RecommendBookResp implements Serializable {
}
public String getDescription() {
return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description));
return description == null ? "" : StringUtils.INSTANCE.convertCC(StringUtils.INSTANCE.delete160(description));
}
public void setDescription(String description) {
@ -94,7 +94,7 @@ public class RecommendBookResp implements Serializable {
}
public String getAuthor() {
return author == null ? "" : StringUtils.convertCC(author) ;
return author == null ? "" : StringUtils.INSTANCE.convertCC(author) ;
}
public void setAuthor(String author) {

@ -117,7 +117,7 @@ public class RecommendListResp implements Serializable {
}
public String getBook_title() {
return book_title == null ? "" : StringUtils.convertCC(book_title);
return book_title == null ? "" : StringUtils.INSTANCE.convertCC(book_title);
}
public void setBook_title(String book_title) {
@ -133,7 +133,7 @@ public class RecommendListResp implements Serializable {
}
public String getAuthor() {
return author == null ? "" : StringUtils.convertCC(author);
return author == null ? "" : StringUtils.INSTANCE.convertCC(author);
}
public void setAuthor(String author) {
@ -141,7 +141,7 @@ public class RecommendListResp implements Serializable {
}
public String getDescription() {
return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description));
return description == null ? "" : StringUtils.INSTANCE.convertCC(StringUtils.INSTANCE.delete160(description));
}
public void setDescription(String description) {

@ -69,7 +69,7 @@ public class SearchResp implements Serializable {
}
public String getTitle() {
return title == null ? "" : StringUtils.convertCC(title);
return title == null ? "" : StringUtils.INSTANCE.convertCC(title);
}
public void setTitle(String title) {
@ -93,7 +93,7 @@ public class SearchResp implements Serializable {
}
public String getDescription() {
return description == null ? "" : StringUtils.convertCC(StringUtils.delete160(description));
return description == null ? "" : StringUtils.INSTANCE.convertCC(StringUtils.INSTANCE.delete160(description));
}
public void setDescription(String description) {
@ -117,7 +117,7 @@ public class SearchResp implements Serializable {
}
public String getAuthor() {
return author == null ? "" : StringUtils.convertCC(author);
return author == null ? "" : StringUtils.INSTANCE.convertCC(author);
}
public void setAuthor(String author) {

@ -242,7 +242,7 @@ public class DownloadService extends BaseService {
}
//判断网络是否出问题
if (!NetworkUtils.isAvailable()) {
if (!NetworkUtils.INSTANCE.isAvailable()) {
//章节加载失败
result = LOAD_ERROR;
break;

@ -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()
}
}
}

@ -8,14 +8,14 @@ public enum Charset {
UTF16LE("UTF-16LE"),
UTF16BE("UTF-16BE"),
GBK("GBK");
private String mName;
public static final byte BLANK = 0x0a;
private Charset(String name) {
mName = name;
}
public String getName() {
return mName;
}

@ -160,7 +160,6 @@ public class CleanCacheUtils {
LitePal.deleteAll(BookChapterBean.class);
}
} catch (Exception e) {
LogUtils.e(e.toString());
}
}

@ -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()
}
}
}

@ -9,10 +9,6 @@ import io.reactivex.SingleSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* Created by newbiechen on 17-4-29.
*/
public class RxUtils {
public static <T> SingleSource<T> toSimpleSingle(Single<T> upstream){

@ -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("&#160;", "");
des = des.replaceAll("&amp;#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("&#160;".toRegex(), "")
text = text.replace("&amp;#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
}
}

@ -429,7 +429,7 @@ public class LocalPageLoader extends PageLoader {
//从文件中获取数据
byte[] content = getChapterContent(chapter);
String test = new String(content);
test = StringUtils.convertCC(test);
test = StringUtils.INSTANCE.convertCC(test);
content = test.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(content);
return new BufferedReader(new InputStreamReader(bais, mCharset.getName()));

@ -176,8 +176,8 @@ public abstract class PageLoader {
mPageMode = mSettingManager.getPageMode();
mPageStyle = mSettingManager.getPageStyle();
// 初始化参数
mMarginWidth = ScreenUtils.dpToPx(DEFAULT_MARGIN_WIDTH);
mMarginHeight = ScreenUtils.dpToPx(DEFAULT_MARGIN_HEIGHT);
mMarginWidth = ScreenUtils.INSTANCE.dpToPx(DEFAULT_MARGIN_WIDTH);
mMarginHeight = ScreenUtils.INSTANCE.dpToPx(DEFAULT_MARGIN_HEIGHT);
// 配置文字有关的参数
setUpTextParams(mSettingManager.getTextSize());
}
@ -190,7 +190,7 @@ public abstract class PageLoader {
private void setUpTextParams(int textSize) {
// 文字大小
mTextSize = textSize;
mTitleSize = mTextSize + ScreenUtils.spToPx(EXTRA_TITLE_SIZE);
mTitleSize = mTextSize + ScreenUtils.INSTANCE.spToPx(EXTRA_TITLE_SIZE);
// 行间距(大小为字体的一半)
mTextInterval = mTextSize / 2;
mTitleInterval = mTitleSize / 2;
@ -204,7 +204,7 @@ public abstract class PageLoader {
mTipPaint = new Paint();
mTipPaint.setColor(mTextColor);
mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
mTipPaint.setTextSize(ScreenUtils.INSTANCE.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
mTipPaint.setAntiAlias(true);
mTipPaint.setSubpixelText(true);
@ -742,7 +742,7 @@ public abstract class PageLoader {
private void drawBackground(Bitmap bitmap, boolean isUpdate) {
Canvas canvas = new Canvas(bitmap);
int tipMarginHeight = ScreenUtils.dpToPx(3);
int tipMarginHeight = ScreenUtils.INSTANCE.dpToPx(3);
if (!isUpdate) {
//绘制背景
canvas.drawColor(mBgColor);
@ -776,7 +776,7 @@ public abstract class PageLoader {
} else {
//擦除区域
mBgPaint.setColor(mBgColor);
canvas.drawRect(mDisplayWidth >> 1, mDisplayHeight - mMarginHeight + ScreenUtils.dpToPx(2), mDisplayWidth, mDisplayHeight, mBgPaint);
canvas.drawRect(mDisplayWidth >> 1, mDisplayHeight - mMarginHeight + ScreenUtils.INSTANCE.dpToPx(2), mDisplayWidth, mDisplayHeight, mBgPaint);
}
//绘制电池
@ -786,8 +786,8 @@ public abstract class PageLoader {
int outFrameWidth = (int) mTipPaint.measureText("xxx");
int outFrameHeight = (int) mTipPaint.getTextSize();
int polarHeight = ScreenUtils.dpToPx(6);
int polarWidth = ScreenUtils.dpToPx(2);
int polarHeight = ScreenUtils.INSTANCE.dpToPx(6);
int polarWidth = ScreenUtils.INSTANCE.dpToPx(2);
int border = 1;
int innerMargin = 1;
@ -795,7 +795,7 @@ public abstract class PageLoader {
int polarLeft = visibleRight - polarWidth;
int polarTop = visibleBottom - (outFrameHeight + polarHeight) / 2;
Rect polar = new Rect(polarLeft, polarTop, visibleRight,
polarTop + polarHeight - ScreenUtils.dpToPx(2));
polarTop + polarHeight - ScreenUtils.INSTANCE.dpToPx(2));
mBatteryPaint.setStyle(Paint.Style.FILL);
canvas.drawRect(polar, mBatteryPaint);
@ -803,7 +803,7 @@ public abstract class PageLoader {
//外框的制作
int outFrameLeft = polarLeft - outFrameWidth;
int outFrameTop = visibleBottom - outFrameHeight;
int outFrameBottom = visibleBottom - ScreenUtils.dpToPx(2);
int outFrameBottom = visibleBottom - ScreenUtils.INSTANCE.dpToPx(2);
Rect outFrame = new Rect(outFrameLeft, outFrameTop, polarLeft, outFrameBottom);
mBatteryPaint.setStyle(Paint.Style.STROKE);
@ -822,7 +822,7 @@ public abstract class PageLoader {
//底部的字显示的位置Y
float y = mDisplayHeight - mTipPaint.getFontMetrics().bottom - tipMarginHeight;
String time = DateUtli.dateConvert(System.currentTimeMillis(), Constant.FORMAT_TIME);
float x = outFrameLeft - mTipPaint.measureText(time) - ScreenUtils.dpToPx(4);
float x = outFrameLeft - mTipPaint.measureText(time) - ScreenUtils.INSTANCE.dpToPx(4);
canvas.drawText(time, x, y, mTipPaint);
}
@ -1299,18 +1299,18 @@ public abstract class PageLoader {
int titleLinesCount = 0;
boolean showTitle = true; // 是否展示标题
String paragraph = chapter.getTitle();//默认展示标题
String title = StringUtils.convertCC(chapter.getTitle());
String title = StringUtils.INSTANCE.convertCC(chapter.getTitle());
String half;
try {
while (showTitle || (paragraph = br.readLine()) != null) {
half = paragraph;
paragraph = StringUtils.convertCC(paragraph);
paragraph = StringUtils.INSTANCE.convertCC(paragraph);
// 重置段落
if (!showTitle) {
paragraph = paragraph.replaceAll("\\s", "");
// 如果只有换行符,那么就不执行
if (paragraph.equals("")) continue;
paragraph = StringUtils.halfToFull(" " + paragraph + "\n");
paragraph = StringUtils.INSTANCE.halfToFull(" " + paragraph + "\n");
} else {
//设置 title 的顶部间距
rHeight -= mTitlePara;

@ -80,7 +80,7 @@ public class ReadSettingManager {
}
public int getTextSize() {
return SpUtil.getIntValue(SHARED_READ_TEXT_SIZE, ScreenUtils.spToPx(16));
return SpUtil.getIntValue(SHARED_READ_TEXT_SIZE, ScreenUtils.INSTANCE.spToPx(16));
}
public boolean isDefaultTextSize() {

@ -42,7 +42,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/content"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="19dp"
android:layout_marginTop="10dp"

Loading…
Cancel
Save