Android藏文电子书阅读

    技术2024-08-11  69

    FolioReader-Android及Aria的实现电子书阅读器

    其实使用起来很方便,好像知乎也用了。也没有深入去研究写,主要看到两个项目优点多,几行代码就搞定!

    FolioReader Features

    Custom Fonts Custom Text Size Themes / Day mode / Night mode Text Highlighting List / Edit / Delete Highlights Handle Internal and External Links Portrait / Landscape Reading Time Left / Pages left In-App Dictionary Media Overlays (Sync text rendering with audio playback) TTS - Text to Speech Support Book Search Add Notes to a Highlight Last Read Position Listener Horizontal reading Distraction Free Reading

    Aria has the following characteristics

    can be used in Activity, Service, Fragment, Dialog, popupWindow, Notification and other components support the task of automatic scheduling, the user does not need to care about the state of the task switch logic Through the Aria event, it is easy to get the download status of the current download task a code plus can get the current download speed a code can be dynamically set the maximum number of downloads code to achieve speed limit It is easy to modify the number of download threads by modifying the configuration file priority to download a task

    工具

    Android Studio 安卓开发工具,被墙了下面是国内地址 http://www.android-studio.org/ 但感觉还是jetbrains的IDE比较牛逼 http://www.jetbrains.comFolioReader项目地址 https://github.com/FolioReader/FolioReader-AndroidAri项目地址 https://github.com/AriaLyy/Aria/blob/master/ENGLISH_README.md

    使用

    在manifest中配置权限

    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" tools:ignore="ProtectedPermissions" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    另外加一行配置Android9.0的

    <application android:networkSecurityConfig="@xml/network_security_config">

    之后在相应的/res/xml/network_security_config.xml配置

    <?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">127.0.0.1</domain> <domain includeSubdomains="true">localhost</domain> </domain-config> </network-security-config>

    布局文件就两个按钮,下载电子书文件和打开电子书文件

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/start" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Download book" /> <Button android:id="@+id/openbook" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open book" /> </LinearLayout>

    在仓库中添加依赖包

    implementation "com.folioreader:folioreader:0.5.1" implementation 'com.arialyy.aria:aria-core:3.5.1' annotationProcessor 'com.arialyy.aria:aria-compiler:3.5.1'

    主Activity代码

    package com.bookreader.zangke.bookreader; import android.app.Activity; import android.os.Environment; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.arialyy.aria.core.Aria; import com.folioreader.FolioReader; public class MainActivity extends Activity { private Button start,openbook; private String DOWNLOAD_URL="http://bmob-cdn-2250.b0.upaiyun.com/2018/11/21/aefd267e400d1c8c8076ceed5d743ad2.epub"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Aria.download(this).register(); start = findViewById(R.id.start); final String filepath = Environment.getExternalStorageDirectory().getPath()+"/bookeader/1.epub"; start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Aria.download(this) .load(DOWNLOAD_URL) .setFilePath(filepath,true) .start(); Toast.makeText(MainActivity.this,"Downloading book",Toast.LENGTH_SHORT).show(); } }); final FolioReader folioReader = FolioReader.get(); openbook =findViewById(R.id.openbook); openbook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { folioReader.openBook("sdcard/bookeader/1.epub"); Toast.makeText(MainActivity.this,filepath,Toast.LENGTH_SHORT).show(); } }); } }

    测试

    最后附藏文电子书库网址

    http://www.boreader.com

    源码下载地址

    源码地址:https://github.com/zangketb/folioReader-Tibetan

    Processed: 0.012, SQL: 10