From 9a8a88944ae89eb8476b7628ffa99aab102eab86 Mon Sep 17 00:00:00 2001 From: zlj <390057892@qq.com> Date: Mon, 11 Nov 2019 13:35:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=83=A8=E5=88=86java?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 3 + .../novel/read/activity/NovelReadActivity.kt | 4 +- .../read/adapter/holder/CategoryHolder.java | 2 +- .../com/novel/read/fragment/MoreFragment.kt | 23 +--- .../com/novel/read/http/AccountManager.kt | 5 +- .../com/novel/read/model/db/CollBookBean.java | 8 +- .../read/model/protocol/BookDetailResp.java | 2 +- .../read/model/protocol/RankByUpdateResp.java | 6 +- .../model/protocol/RecommendBookResp.java | 6 +- .../model/protocol/RecommendListResp.java | 6 +- .../novel/read/model/protocol/SearchResp.java | 6 +- .../novel/read/service/DownloadService.java | 2 +- .../com/novel/read/utlis/BrightnessUtils.java | 108 ---------------- .../com/novel/read/utlis/BrightnessUtils.kt | 116 +++++++++++++++++ .../java/com/novel/read/utlis/Charset.java | 4 +- .../com/novel/read/utlis/CleanCacheUtils.java | 1 - .../java/com/novel/read/utlis/MyTimeTask.java | 35 ----- .../java/com/novel/read/utlis/MyTimeTask.kt | 29 +++++ .../com/novel/read/utlis/NetworkUtils.java | 61 --------- .../java/com/novel/read/utlis/NetworkUtils.kt | 58 +++++++++ .../novel/read/utlis/PermissionsChecker.java | 30 ----- .../java/com/novel/read/utlis/PhoneUtils.java | 112 ---------------- .../java/com/novel/read/utlis/PhoneUtils.kt | 122 ++++++++++++++++++ .../java/com/novel/read/utlis/RxUtils.java | 4 - .../com/novel/read/utlis/ScreenUtils.java | 122 ------------------ .../java/com/novel/read/utlis/ScreenUtils.kt | 113 ++++++++++++++++ .../com/novel/read/utlis/StringUtils.java | 64 --------- .../java/com/novel/read/utlis/StringUtils.kt | 67 ++++++++++ .../read/widget/page/LocalPageLoader.java | 2 +- .../novel/read/widget/page/PageLoader.java | 28 ++-- .../read/widget/page/ReadSettingManager.java | 2 +- .../main/res/layout/dialog_go_appraise.xml | 2 +- 32 files changed, 553 insertions(+), 600 deletions(-) delete mode 100644 app/src/main/java/com/novel/read/utlis/BrightnessUtils.java create mode 100644 app/src/main/java/com/novel/read/utlis/BrightnessUtils.kt delete mode 100644 app/src/main/java/com/novel/read/utlis/MyTimeTask.java create mode 100644 app/src/main/java/com/novel/read/utlis/MyTimeTask.kt delete mode 100644 app/src/main/java/com/novel/read/utlis/NetworkUtils.java create mode 100644 app/src/main/java/com/novel/read/utlis/NetworkUtils.kt delete mode 100644 app/src/main/java/com/novel/read/utlis/PermissionsChecker.java delete mode 100644 app/src/main/java/com/novel/read/utlis/PhoneUtils.java create mode 100644 app/src/main/java/com/novel/read/utlis/PhoneUtils.kt delete mode 100644 app/src/main/java/com/novel/read/utlis/ScreenUtils.java create mode 100644 app/src/main/java/com/novel/read/utlis/ScreenUtils.kt delete mode 100644 app/src/main/java/com/novel/read/utlis/StringUtils.java create mode 100644 app/src/main/java/com/novel/read/utlis/StringUtils.kt diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 43fd926..5c82789 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,8 @@ + + diff --git a/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt b/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt index 6a8f3f4..5fa0cb8 100644 --- a/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt +++ b/app/src/main/java/com/novel/read/activity/NovelReadActivity.kt @@ -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) { diff --git a/app/src/main/java/com/novel/read/adapter/holder/CategoryHolder.java b/app/src/main/java/com/novel/read/adapter/holder/CategoryHolder.java index 86cfecd..5dce728 100644 --- a/app/src/main/java/com/novel/read/adapter/holder/CategoryHolder.java +++ b/app/src/main/java/com/novel/read/adapter/holder/CategoryHolder.java @@ -34,7 +34,7 @@ public class CategoryHolder extends ViewHolderImpl { 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())); } diff --git a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt index 0dc23aa..d801135 100644 --- a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt +++ b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt @@ -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() { diff --git a/app/src/main/java/com/novel/read/http/AccountManager.kt b/app/src/main/java/com/novel/read/http/AccountManager.kt index 1f5d03f..e61d59e 100644 --- a/app/src/main/java/com/novel/read/http/AccountManager.kt +++ b/app/src/main/java/com/novel/read/http/AccountManager.kt @@ -183,8 +183,8 @@ class AccountManager private constructor() { fun login(mContext: Context) { val map = HashMap() - 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() {} diff --git a/app/src/main/java/com/novel/read/model/db/CollBookBean.java b/app/src/main/java/com/novel/read/model/db/CollBookBean.java index 25d336b..ac844e3 100644 --- a/app/src/main/java/com/novel/read/model/db/CollBookBean.java +++ b/app/src/main/java/com/novel/read/model/db/CollBookBean.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java b/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java index 2caba59..7b9a527 100644 --- a/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RankByUpdateResp.java b/app/src/main/java/com/novel/read/model/protocol/RankByUpdateResp.java index 109931a..84487be 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RankByUpdateResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RankByUpdateResp.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java b/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java index 7a7fdb3..fe00967 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RecommendBookResp.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java b/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java index 9d1629d..24688a5 100644 --- a/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/RecommendListResp.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/model/protocol/SearchResp.java b/app/src/main/java/com/novel/read/model/protocol/SearchResp.java index 810ba9e..2c468d7 100644 --- a/app/src/main/java/com/novel/read/model/protocol/SearchResp.java +++ b/app/src/main/java/com/novel/read/model/protocol/SearchResp.java @@ -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) { diff --git a/app/src/main/java/com/novel/read/service/DownloadService.java b/app/src/main/java/com/novel/read/service/DownloadService.java index 2bfe186..ef652a9 100644 --- a/app/src/main/java/com/novel/read/service/DownloadService.java +++ b/app/src/main/java/com/novel/read/service/DownloadService.java @@ -242,7 +242,7 @@ public class DownloadService extends BaseService { } //判断网络是否出问题 - if (!NetworkUtils.isAvailable()) { + if (!NetworkUtils.INSTANCE.isAvailable()) { //章节加载失败 result = LOAD_ERROR; break; diff --git a/app/src/main/java/com/novel/read/utlis/BrightnessUtils.java b/app/src/main/java/com/novel/read/utlis/BrightnessUtils.java deleted file mode 100644 index f51f9ae..0000000 --- a/app/src/main/java/com/novel/read/utlis/BrightnessUtils.java +++ /dev/null @@ -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(); - } - } -} diff --git a/app/src/main/java/com/novel/read/utlis/BrightnessUtils.kt b/app/src/main/java/com/novel/read/utlis/BrightnessUtils.kt new file mode 100644 index 0000000..10b43e1 --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/BrightnessUtils.kt @@ -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() + } + + } +} diff --git a/app/src/main/java/com/novel/read/utlis/Charset.java b/app/src/main/java/com/novel/read/utlis/Charset.java index 08698ed..186758d 100644 --- a/app/src/main/java/com/novel/read/utlis/Charset.java +++ b/app/src/main/java/com/novel/read/utlis/Charset.java @@ -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; } diff --git a/app/src/main/java/com/novel/read/utlis/CleanCacheUtils.java b/app/src/main/java/com/novel/read/utlis/CleanCacheUtils.java index d6505dd..db06995 100644 --- a/app/src/main/java/com/novel/read/utlis/CleanCacheUtils.java +++ b/app/src/main/java/com/novel/read/utlis/CleanCacheUtils.java @@ -160,7 +160,6 @@ public class CleanCacheUtils { LitePal.deleteAll(BookChapterBean.class); } } catch (Exception e) { - LogUtils.e(e.toString()); } } diff --git a/app/src/main/java/com/novel/read/utlis/MyTimeTask.java b/app/src/main/java/com/novel/read/utlis/MyTimeTask.java deleted file mode 100644 index 1a57a5c..0000000 --- a/app/src/main/java/com/novel/read/utlis/MyTimeTask.java +++ /dev/null @@ -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(); //将原任务从队列中移除 - } - } - } -} diff --git a/app/src/main/java/com/novel/read/utlis/MyTimeTask.kt b/app/src/main/java/com/novel/read/utlis/MyTimeTask.kt new file mode 100644 index 0000000..88012c6 --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/MyTimeTask.kt @@ -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() + } + } +} diff --git a/app/src/main/java/com/novel/read/utlis/NetworkUtils.java b/app/src/main/java/com/novel/read/utlis/NetworkUtils.java deleted file mode 100644 index 1b95e3b..0000000 --- a/app/src/main/java/com/novel/read/utlis/NetworkUtils.java +++ /dev/null @@ -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是否连接状态 - *

需添加权限 {@code }

- * - * @param context 上下文 - * @return {@code true}: 连接
{@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; - } - - - -} diff --git a/app/src/main/java/com/novel/read/utlis/NetworkUtils.kt b/app/src/main/java/com/novel/read/utlis/NetworkUtils.kt new file mode 100644 index 0000000..fe78bf9 --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/NetworkUtils.kt @@ -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是否连接状态 + * + * 需添加权限 `` + * + * @param context 上下文 + * @return `true`: 连接

`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) + } + + +} diff --git a/app/src/main/java/com/novel/read/utlis/PermissionsChecker.java b/app/src/main/java/com/novel/read/utlis/PermissionsChecker.java deleted file mode 100644 index 442eb53..0000000 --- a/app/src/main/java/com/novel/read/utlis/PermissionsChecker.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/novel/read/utlis/PhoneUtils.java b/app/src/main/java/com/novel/read/utlis/PhoneUtils.java deleted file mode 100644 index 9054d45..0000000 --- a/app/src/main/java/com/novel/read/utlis/PhoneUtils.java +++ /dev/null @@ -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(); - - } -} diff --git a/app/src/main/java/com/novel/read/utlis/PhoneUtils.kt b/app/src/main/java/com/novel/read/utlis/PhoneUtils.kt new file mode 100644 index 0000000..d4f635e --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/PhoneUtils.kt @@ -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() + } + } +} diff --git a/app/src/main/java/com/novel/read/utlis/RxUtils.java b/app/src/main/java/com/novel/read/utlis/RxUtils.java index 11e019b..99fe4e2 100644 --- a/app/src/main/java/com/novel/read/utlis/RxUtils.java +++ b/app/src/main/java/com/novel/read/utlis/RxUtils.java @@ -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 SingleSource toSimpleSingle(Single upstream){ diff --git a/app/src/main/java/com/novel/read/utlis/ScreenUtils.java b/app/src/main/java/com/novel/read/utlis/ScreenUtils.java deleted file mode 100644 index e67c0f7..0000000 --- a/app/src/main/java/com/novel/read/utlis/ScreenUtils.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/com/novel/read/utlis/ScreenUtils.kt b/app/src/main/java/com/novel/read/utlis/ScreenUtils.kt new file mode 100644 index 0000000..126dbcd --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/ScreenUtils.kt @@ -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 + } +} diff --git a/app/src/main/java/com/novel/read/utlis/StringUtils.java b/app/src/main/java/com/novel/read/utlis/StringUtils.java deleted file mode 100644 index 654e438..0000000 --- a/app/src/main/java/com/novel/read/utlis/StringUtils.java +++ /dev/null @@ -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; - } - -} diff --git a/app/src/main/java/com/novel/read/utlis/StringUtils.kt b/app/src/main/java/com/novel/read/utlis/StringUtils.kt new file mode 100644 index 0000000..f9dadf2 --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/StringUtils.kt @@ -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 + } + +} diff --git a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java index 34c3c2d..0ae5115 100644 --- a/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/LocalPageLoader.java @@ -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())); diff --git a/app/src/main/java/com/novel/read/widget/page/PageLoader.java b/app/src/main/java/com/novel/read/widget/page/PageLoader.java index 68dcc47..7d0f7d5 100644 --- a/app/src/main/java/com/novel/read/widget/page/PageLoader.java +++ b/app/src/main/java/com/novel/read/widget/page/PageLoader.java @@ -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; diff --git a/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java b/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java index 24dd240..6df8551 100644 --- a/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java +++ b/app/src/main/java/com/novel/read/widget/page/ReadSettingManager.java @@ -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() { diff --git a/app/src/main/res/layout/dialog_go_appraise.xml b/app/src/main/res/layout/dialog_go_appraise.xml index 9167898..1a30481 100644 --- a/app/src/main/res/layout/dialog_go_appraise.xml +++ b/app/src/main/res/layout/dialog_go_appraise.xml @@ -42,7 +42,7 @@