Commit c7a1e38b authored by wanglei's avatar wanglei

...

parent 9fa8260b
......@@ -19,9 +19,6 @@
android:theme="@style/Theme.PDFViewerScannerWhite"
android:usesCleartextTraffic="true"
tools:targetApi="34">
<activity
android:name=".ui.document.ppt.PptActivity"
android:exported="false" />
<meta-data
android:name="com.google.android.gms.version"
......@@ -49,6 +46,12 @@
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.document.ppt.PptActivity"
android:exported="false"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.document.excel.ExcelActivity"
android:exported="false"
......@@ -58,7 +61,9 @@
<activity
android:name=".ui.document.word.WordActivity"
android:exported="false"
android:theme="@style/Theme.PDFViewerScannerWhite" />
android:screenOrientation="portrait"
android:theme="@style/Theme.PDFViewerScannerWhite"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.document.pdf.PdfMergeActivity"
android:exported="false"
......
......@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint
import android.net.Uri
import android.provider.MediaStore
import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
......@@ -20,6 +21,7 @@ import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import com.base.pdfviewerscannerwhite.utils.updateMediaStore
class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
......@@ -81,7 +83,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
if (!checkStorePermission()) {
showStoragePermission(launcher)
updateMediaStore()
}
}
private fun initTabLayout() {
......
......@@ -28,6 +28,10 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
}
}
dependencies {
......
......@@ -6,7 +6,7 @@ import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.cherry.lib.doc.bean.DocEngine
import com.cherry.lib.doc.util.Constant
import kotlinx.android.synthetic.main.activity_doc_viewer.mDocView
import com.cherry.lib.doc.widget.DocView
open class DocViewerActivity : AppCompatActivity() {
private val TAG = "DocViewerActivity"
......@@ -16,7 +16,7 @@ open class DocViewerActivity : AppCompatActivity() {
activity: AppCompatActivity, docSourceType: Int, path: String?,
fileType: Int? = null, engine: Int? = null
) {
var intent = Intent(activity, DocViewerActivity::class.java)
val intent = Intent(activity, DocViewerActivity::class.java)
intent.putExtra(Constant.INTENT_SOURCE_KEY, docSourceType)
intent.putExtra(Constant.INTENT_DATA_KEY, path)
intent.putExtra(Constant.INTENT_TYPE_KEY, fileType)
......@@ -34,6 +34,8 @@ open class DocViewerActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_doc_viewer)
initView()
initData(intent)
}
......@@ -47,7 +49,13 @@ open class DocViewerActivity : AppCompatActivity() {
fileType = intent?.getIntExtra(Constant.INTENT_TYPE_KEY, -1) ?: -1
engine = intent?.getIntExtra(Constant.INTENT_ENGINE_KEY, DocEngine.INTERNAL.value) ?: DocEngine.INTERNAL.value
mDocView.openDoc(this,docUrl,docSourceType,fileType,false, DocEngine.values().first { it.value == engine })
findViewById<DocView>(R.id.mDocView).openDoc(
this,
docUrl,
docSourceType,
fileType,
false,
DocEngine.values().first { it.value == engine })
Log.e(TAG, "initData-docUrl = $docUrl")
Log.e(TAG, "initData-docSourceType = $docSourceType")
Log.e(TAG, "initData-fileType = $fileType")
......
......@@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import com.blankj.utilcode.util.AppUtils;
import com.cherry.lib.doc.office.common.IOfficeToPicture;
import com.cherry.lib.doc.office.constant.EventConstant;
......@@ -13,7 +12,6 @@ import com.cherry.lib.doc.office.constant.wp.WPViewConstant;
import com.cherry.lib.doc.office.res.ResKit;
import com.cherry.lib.doc.office.system.IMainFrame;
import com.cherry.lib.doc.office.system.MainControl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
......@@ -217,7 +215,7 @@ public abstract class IOffice implements IMainFrame {
* 是否绘制页码
*/
public boolean isDrawPageNumber() {
return true;
return false;
}
/**
......
......@@ -17,13 +17,9 @@
package com.cherry.lib.doc.office.fc.hslf.model;
import java.io.ByteArrayOutputStream;
import com.cherry.lib.doc.office.fc.ddf.EscherClientDataRecord;
import com.cherry.lib.doc.office.fc.ddf.EscherContainerRecord;
import com.cherry.lib.doc.office.fc.ddf.EscherProperties;
import com.cherry.lib.doc.office.fc.hslf.exceptions.HSLFException;
import com.cherry.lib.doc.office.fc.hslf.record.*;
import com.cherry.lib.doc.office.fc.hslf.record.Record;
import com.cherry.lib.doc.office.fc.hslf.usermodel.SlideShow;
......@@ -32,8 +28,7 @@ import com.cherry.lib.doc.office.fc.hslf.usermodel.SlideShow;
*
* @author Yegor Kozlov
*/
public final class MovieShape extends Picture
{
public final class MovieShape extends Picture {
public static final int DEFAULT_MOVIE_THUMBNAIL = -1;
public static final int MOVIE_MPEG = 1;
......@@ -44,8 +39,7 @@ public final class MovieShape extends Picture
*
* @param pictureIdx the index of the picture
*/
public MovieShape(int movieIdx, int pictureIdx)
{
public MovieShape(int movieIdx, int pictureIdx) {
super(pictureIdx, null);
setMovieIndex(movieIdx);
setAutoPlay(true);
......@@ -57,8 +51,7 @@ public final class MovieShape extends Picture
* @param idx the index of the picture
* @param parent the parent shape
*/
public MovieShape(int movieIdx, int idx, Shape parent)
{
public MovieShape(int movieIdx, int idx, Shape parent) {
super(idx, parent);
setMovieIndex(movieIdx);
}
......@@ -70,8 +63,7 @@ public final class MovieShape extends Picture
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
protected MovieShape(EscherContainerRecord escherRecord, Shape parent)
{
protected MovieShape(EscherContainerRecord escherRecord, Shape parent) {
super(escherRecord, parent);
}
......@@ -80,8 +72,7 @@ public final class MovieShape extends Picture
*
* @return the created <code>EscherContainerRecord</code> which holds shape data
*/
protected EscherContainerRecord createSpContainer(int idx, boolean isChild)
{
protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
_escherContainer = super.createSpContainer(idx, isChild);
/*setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x1000100);
......@@ -112,7 +103,8 @@ public final class MovieShape extends Picture
{
throw new HSLFException(e);
}
cldata.setRemainingData(out.toByteArray())*/;
cldata.setRemainingData(out.toByteArray())*/
;
return _escherContainer;
}
......@@ -120,17 +112,15 @@ public final class MovieShape extends Picture
/**
* Assign a movie to this shape
*
* @see com.cherry.lib.doc.office.fc.hslf.usermodel.SlideShow#addMovie(String, int)
* @param idx the index of the movie
* @see com.cherry.lib.doc.office.fc.hslf.usermodel.SlideShow#addMovie(String, int)
*/
public void setMovieIndex(int idx)
{
OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
public void setMovieIndex(int idx) {
OEShapeAtom oe = (OEShapeAtom) getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
oe.setOptions(idx);
AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null)
{
AnimationInfo an = (AnimationInfo) getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null) {
AnimationInfoAtom ai = an.getAnimationInfoAtom();
ai.setDimColor(0x07000000);
ai.setFlag(AnimationInfoAtom.Automatic, true);
......@@ -140,21 +130,17 @@ public final class MovieShape extends Picture
}
}
public void setAutoPlay(boolean flag)
{
AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null)
{
public void setAutoPlay(boolean flag) {
AnimationInfo an = (AnimationInfo) getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null) {
an.getAnimationInfoAtom().setFlag(AnimationInfoAtom.Automatic, flag);
updateClientData();
}
}
public boolean isAutoPlay()
{
AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null)
{
public boolean isAutoPlay() {
AnimationInfo an = (AnimationInfo) getClientDataRecord(RecordTypes.AnimationInfo.typeID);
if (an != null) {
return an.getAnimationInfoAtom().getFlag(AnimationInfoAtom.Automatic);
}
return false;
......@@ -163,27 +149,23 @@ public final class MovieShape extends Picture
/**
* @return UNC or local path to a video file
*/
public String getPath()
{
OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
public String getPath() {
OEShapeAtom oe = (OEShapeAtom) getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
int idx = oe.getOptions();
SlideShow ppt = getSheet().getSlideShow();
ExObjList lst = (ExObjList)ppt.getDocumentRecord().findFirstOfType(
ExObjList lst = (ExObjList) ppt.getDocumentRecord().findFirstOfType(
RecordTypes.ExObjList.typeID);
if (lst == null)
return null;
Record[] r = lst.getChildRecords();
for (int i = 0; i < r.length; i++)
{
if (r[i] instanceof ExMCIMovie)
{
ExMCIMovie mci = (ExMCIMovie)r[i];
for (int i = 0; i < r.length; i++) {
if (r[i] instanceof ExMCIMovie) {
ExMCIMovie mci = (ExMCIMovie) r[i];
ExVideoContainer exVideo = mci.getExVideo();
int objectId = exVideo.getExMediaAtom().getObjectId();
if (objectId == idx)
{
if (objectId == idx) {
return exVideo.getPathAtom().getText();
}
}
......
......@@ -29,7 +29,6 @@ import com.cherry.lib.doc.office.system.SysKit;
import com.cherry.lib.doc.office.system.beans.pagelist.APageListItem;
import com.cherry.lib.doc.office.system.beans.pagelist.APageListView;
import com.cherry.lib.doc.office.system.beans.pagelist.IPageListViewListener;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
......@@ -275,8 +274,6 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener
}
/**
* @param x 为100%的值
* @param y 为100%的值
* /
public long viewToModel(int x, int y, boolean isBack)
{
......@@ -484,7 +481,6 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener
/**
* page list view moving position
* @param position horizontal or vertical
*/
public int getPageListViewMovingPosition()
{
......@@ -515,7 +511,6 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener
* @param e2 MotionEvent instance
* @param velocityX x axis velocity
* @param velocityY y axis velocity
* @param eventNethodType event method
* @see IMainFrame#ON_CLICK
* @see IMainFrame#ON_DOUBLE_TAP
* @see IMainFrame#ON_DOUBLE_TAP_EVENT
......@@ -653,7 +648,6 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener
/**
* 绘制页信息
* @param canvas
* @param zoom
*/
private void drawPageNubmer(Canvas canvas)
{
......@@ -692,8 +686,6 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener
* set change page flag, Only when effectively the PageSize greater than ViewSize.
* (for PPT, word print mode, PDF)
*
* @param b = true, change page
* = false, don't change page
*/
public boolean isChangePage()
{
......
......@@ -7,14 +7,12 @@ import android.view.View
import android.view.ViewGroup
import android.view.animation.AlphaAnimation
import android.view.animation.LinearInterpolator
import android.widget.Toast
import androidx.core.view.updateLayoutParams
import android.widget.ImageView
import android.widget.ProgressBar
import androidx.recyclerview.widget.RecyclerView
import com.cherry.lib.doc.R
import com.cherry.lib.doc.util.ViewUtils.hide
import com.cherry.lib.doc.util.ViewUtils.show
import kotlinx.android.synthetic.main.page_item_pdf.view.*
import kotlinx.android.synthetic.main.pdf_view_page_loading_layout.view.*
/*
* -----------------------------------------------------------------
......@@ -31,13 +29,14 @@ internal class PdfPageViewAdapter(
private val renderer: PdfRendererCore?,
private val pageSpacing: Rect,
private val enableLoadingForPages: Boolean
) :
RecyclerView.Adapter<PdfPageViewAdapter.PdfPageViewHolder>() {
) : RecyclerView.Adapter<PdfPageViewAdapter.PdfPageViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PdfPageViewHolder {
return PdfPageViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.page_item_pdf,parent,
false)
LayoutInflater.from(parent.context).inflate(
R.layout.page_item_pdf, parent,
false
)
)
}
......@@ -49,21 +48,22 @@ internal class PdfPageViewAdapter(
holder.bindView()
}
inner class PdfPageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),View.OnAttachStateChangeListener {
inner class PdfPageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnAttachStateChangeListener {
fun bindView() {
}
private fun handleLoadingForPage(position: Int) {
val progressBar = itemView.findViewById<ProgressBar>(R.id.pdf_view_page_loading_progress)
if (!enableLoadingForPages) {
itemView.pdf_view_page_loading_progress.hide()
progressBar.hide()
return
}
if (renderer?.pageExistInCache(position) == true) {
itemView.pdf_view_page_loading_progress.hide()
progressBar.hide()
} else {
itemView.pdf_view_page_loading_progress.show()
progressBar.show()
}
}
......@@ -84,20 +84,22 @@ internal class PdfPageViewAdapter(
// this.rightMargin = pageSpacing.right
// this.bottomMargin = pageSpacing.bottom
// }
itemView.pageView.setImageBitmap(bitmap)
itemView.pageView.animation = AlphaAnimation(0F, 1F).apply {
val pageView = itemView.findViewById<ImageView>(R.id.pageView)
pageView.setImageBitmap(bitmap)
pageView.animation = AlphaAnimation(0F, 1F).apply {
interpolator = LinearInterpolator()
duration = 200
}
itemView.pdf_view_page_loading_progress.hide()
itemView.findViewById<ProgressBar>(R.id.pdf_view_page_loading_progress).hide()
}
}
}
}
override fun onViewDetachedFromWindow(p0: View) {
itemView.pageView.setImageBitmap(null)
itemView.pageView.clearAnimation()
val pageView = itemView.findViewById<ImageView>(R.id.pageView)
pageView.setImageBitmap(null)
pageView.clearAnimation()
}
}
}
\ No newline at end of file
......@@ -14,12 +14,10 @@ import android.widget.Toast
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
import com.cherry.lib.doc.R
import com.cherry.lib.doc.databinding.ListItemPdfBinding
import com.cherry.lib.doc.interfaces.OnPdfItemClickListener
import com.cherry.lib.doc.util.ViewUtils.hide
import com.cherry.lib.doc.util.ViewUtils.show
import kotlinx.android.synthetic.main.doc_view.view.mIvPdf
import kotlinx.android.synthetic.main.list_item_pdf.view.*
import kotlinx.android.synthetic.main.pdf_view_page_loading_layout.view.*
/*
* -----------------------------------------------------------------
......@@ -41,8 +39,10 @@ internal class PdfViewAdapter(
RecyclerView.Adapter<PdfViewAdapter.PdfPageViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PdfPageViewHolder {
return PdfPageViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.list_item_pdf,parent,
false)
LayoutInflater.from(parent.context).inflate(
R.layout.list_item_pdf, parent,
false
)
)
}
......@@ -59,24 +59,24 @@ internal class PdfViewAdapter(
holder.bindView()
}
inner class PdfPageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),View.OnAttachStateChangeListener {
inner class PdfPageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnAttachStateChangeListener {
val binding = ListItemPdfBinding.bind(itemView)
fun bindView() {
itemView.container_view.setOnClickListener {
binding.containerView.setOnClickListener {
listener?.OnPdfItemClick(adapterPosition)
}
}
private fun handleLoadingForPage(position: Int) {
if (!enableLoadingForPages) {
itemView.pdf_view_page_loading_progress.hide()
binding.include.pdfViewPageLoadingProgress.hide()
return
}
if (renderer?.pageExistInCache(position) == true) {
itemView.pdf_view_page_loading_progress.hide()
binding.include.pdfViewPageLoadingProgress.hide()
} else {
itemView.pdf_view_page_loading_progress.show()
binding.include.pdfViewPageLoadingProgress.show()
}
}
......@@ -89,28 +89,28 @@ internal class PdfViewAdapter(
renderer?.renderPage(adapterPosition) { bitmap: Bitmap?, pageNo: Int ->
if (pageNo == adapterPosition) {
bitmap?.let {
itemView.container_view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
binding.containerView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
height =
(itemView.container_view.width.toFloat() / ((bitmap.width.toFloat() / bitmap.height.toFloat()))).toInt()
(binding.containerView.width.toFloat() / ((bitmap.width.toFloat() / bitmap.height.toFloat()))).toInt()
this.topMargin = pageSpacing.top
this.leftMargin = pageSpacing.left
this.rightMargin = pageSpacing.right
this.bottomMargin = pageSpacing.bottom
}
itemView.pageView.setImageBitmap(bitmap)
itemView.pageView.animation = AlphaAnimation(0F, 1F).apply {
binding.pageView.setImageBitmap(bitmap)
binding.pageView.animation = AlphaAnimation(0F, 1F).apply {
interpolator = LinearInterpolator()
duration = 200
}
itemView.pdf_view_page_loading_progress.hide()
binding.include.pdfViewPageLoadingProgress.hide()
}
}
}
}
override fun onViewDetachedFromWindow(p0: View) {
itemView.pageView.setImageBitmap(null)
itemView.pageView.clearAnimation()
binding.pageView.setImageBitmap(null)
binding.pageView.clearAnimation()
}
}
......
package com.cherry.lib.doc.widget
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Environment
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.webkit.*
import androidx.constraintlayout.widget.ConstraintLayout
import com.cherry.lib.doc.R
import com.cherry.lib.doc.interfaces.OnWebLoadListener
import kotlinx.android.synthetic.main.doc_web_view.view.*
/*
* -----------------------------------------------------------------
* Copyright (C) 2018-2028, by Victor, All rights reserved.
* -----------------------------------------------------------------
* File: ProgressWebView
* Author: Victor
* Date: 2022/3/1 18:28
* Description:
* -----------------------------------------------------------------
*/
class DocWebView : ConstraintLayout, DownloadListener {
val TAG = "DocWebView"
var isLastLoadSuccess = false//是否成功加载完成过web,成功过后的网络异常 不改变web
var isError = false
var openLinkBySysBrowser = false//是否使用系统浏览器打开http链接
var mOnWebLoadListener: OnWebLoadListener? = null
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
initView()
}
fun initView() {
LayoutInflater.from(context).inflate(R.layout.doc_web_view, this, true)
mDocView.webChromeClient = DocWebChromeClient()
mDocView.webViewClient = DocWebViewClient()
//设置可以支持缩放
mDocView.settings.setSupportZoom(true)
//设置出现缩放工具
mDocView.settings.builtInZoomControls = true
//设定缩放控件隐藏
mDocView.settings.displayZoomControls = true
//设置可在大视野范围内上下左右拖动,并且可以任意比例缩放
mDocView.settings.useWideViewPort = true
//设置默认加载的可视范围是大视野范围
mDocView.settings.loadWithOverviewMode = true
//自适应屏幕 SINGLE_COLUMN:把所有内容放大到webview等宽的一列中 NORMAL:正常显示不做任何渲染。NARROW_COLUMNS:可能的话让所有列的宽度不超过屏幕宽度
mDocView.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
mDocView.settings.javaScriptEnabled = true
mDocView.settings.domStorageEnabled = true
mDocView.settings.allowFileAccess = true
mDocView.settings.allowFileAccessFromFileURLs = true
mDocView.settings.allowUniversalAccessFromFileURLs = true
mDocView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
mDocView.setDownloadListener(this)
}
private fun setProgress(newProgress: Int) {
mOnWebLoadListener?.OnWebLoadProgress(newProgress)
}
/**
* 千万不要更改这个 "SSDJsBirdge" 注意!!!!!
*/
@SuppressLint("JavascriptInterface")
fun addJavascriptInterface(jsInterface: Any) {
mDocView.addJavascriptInterface(jsInterface, "SSDJsBirdge")
}
fun reload() {
isError = false
mDocView.reload()
}
fun loadUrl(url: String) {
isError = false
try {
mDocView.loadUrl(url)
} catch (e: Exception) {
e.printStackTrace()
}
}
fun loadData(htmlData: String) {
mDocView.loadData(htmlData, "text/html", "utf-8")
}
fun loadData(htmlData: String, secondLinkBySysBrowser: Boolean) {
openLinkBySysBrowser = secondLinkBySysBrowser
mDocView.loadData(htmlData, "text/html", "utf-8")
}
fun downloadFile(url: String?, contentDisposition: String?, mimeType: String?) {
val request = DownloadManager.Request(Uri.parse(url))
// 允许媒体扫描,根据下载的文件类型被加入相册、音乐等媒体库
request.allowScanningByMediaScanner()
// 设置通知的显示类型,下载进行时和完成后显示通知
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
// 设置通知栏的标题,如果不设置,默认使用文件名
request.setTitle("下载完成")
// 设置通知栏的描述
// request.setDescription("This is description");
// 允许在计费流量下下载
request.setAllowedOverMetered(true)
// 允许该记录在下载管理界面可见
request.setVisibleInDownloadsUi(true)
// 允许漫游时下载
request.setAllowedOverRoaming(true)
val fileName = URLUtil.guessFileName(url, contentDisposition, mimeType)
Log.e(TAG, "downloadFile()-fileName = $fileName")
request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().toString() + "/Download/", fileName)
val downloadManager = mDocView.context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
// 添加一个下载任务
val downloadId = downloadManager.enqueue(request)
}
override fun onDownloadStart(
url: String?,
userAgent: String?,
contentDisposition: String?,
mimeType: String?,
contentLength: Long
) {
Log.e(TAG, "onDownloadStart()......url = $url")
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
context.startActivity(intent)
// downloadFile(url,contentDisposition,mimeType)
}
fun canGoBack(): Boolean {
val canGoBack = mDocView.canGoBack()
if (canGoBack) {
mDocView.goBack()
}
return canGoBack
}
fun onPause() {
mDocView.pauseTimers()
}
fun onResume() {
mDocView.resumeTimers()
}
/**
* must be called on the main thread
*/
fun onDestroy() {
try {
mDocView.clearHistory();
mDocView.clearCache(true)
mDocView.loadUrl("about:blank") // clearView() should be changed to loadUrl("about:blank"), since clearView() is deprecated now
mDocView.freeMemory()
mDocView.pauseTimers()
mDocView.destroy() // Note that mWebView.destroy() and mWebView = null do the exact same thing
} catch (e: Exception) {
e.printStackTrace()
}
}
fun setWebViewBackgroundColor(isBlack: Boolean) {
if (isBlack) {
//防止加载html白屏(针对播放视频)
setBackgroundColor(Color.BLACK)
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
onDestroy()
}
private inner class DocWebChromeClient : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
super.onProgressChanged(view, newProgress)
setProgress(newProgress)
}
override fun onReceivedTitle(view: WebView, title: String) {
super.onReceivedTitle(view, title)
if (title.contains("html")) {
return
}
mOnWebLoadListener?.onTitle(title)
}
}
private inner class DocWebViewClient : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
//在访问失败的时候会首先回调onReceivedError,然后再回调onPageFinished。
if (!isError) {
isLastLoadSuccess = true
mOnWebLoadListener?.OnWebLoadProgress(100)
}
}
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
super.onReceivedError(view, request, error)
//在访问失败的时候会首先回调onReceivedError,然后再回调onPageFinished。
isError = true
if (!isLastLoadSuccess) {//之前成功加载完成过,不会回调
mOnWebLoadListener?.OnWebLoadProgress(100)
}
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ import java.util.*
* -----------------------------------------------------------------
*/
class PinchImageView: AppCompatImageView {
class PinchImageView : AppCompatImageView {
companion object {
////////////////////////////////配置参数////////////////////////////////
/**
......@@ -557,14 +557,15 @@ class PinchImageView: AppCompatImageView {
}
////////////////////////////////初始化////////////////////////////////
constructor(context: Context) :super(context) {
constructor(context: Context) : super(context) {
initView()
}
constructor(context: Context,attrs: AttributeSet?) :super(context,attrs) {
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initView()
}
constructor(context: Context, attrs: AttributeSet?, defStyle: Int): super(context, attrs, defStyle) {
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
initView()
}
......@@ -742,8 +743,9 @@ class PinchImageView: AppCompatImageView {
*
* 在onTouchEvent末尾被执行.
*/
private val mGestureDetector = GestureDetector(this@PinchImageView.getContext(), object : SimpleOnGestureListener() {
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
private val mGestureDetector = GestureDetector(this@PinchImageView.context,
object : SimpleOnGestureListener() {
override fun onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
//只有在单指模式结束之后才允许执行fling
if (mPinchMode == PINCH_MODE_FREE && !(mScaleAnimator != null && mScaleAnimator!!.isRunning)) {
fling(velocityX, velocityY)
......@@ -1220,7 +1222,11 @@ class PinchImageView: AppCompatImageView {
*
* 在给定时间内从一个矩阵的变化逐渐动画到另一个矩阵的变化
*/
private inner class ScaleAnimator @JvmOverloads constructor(start: Matrix, end: Matrix, duration: Long = SCALE_ANIMATOR_DURATION.toLong()) : ValueAnimator(), AnimatorUpdateListener {
private inner class ScaleAnimator @JvmOverloads constructor(
start: Matrix,
end: Matrix,
duration: Long = SCALE_ANIMATOR_DURATION.toLong()
) : ValueAnimator(), AnimatorUpdateListener {
/**
* 开始矩阵
*/
......@@ -1287,7 +1293,8 @@ class PinchImageView: AppCompatImageView {
/**
* 对象池的最大容量
*/
private val mSize: Int) {
private val mSize: Int
) {
/**
* 对象池队列
......
package com.cherry.lib.doc.widget;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.ContextWrapper;
......@@ -41,6 +42,7 @@ public class PoiViewer {
initCacheDir();
}
@SuppressLint("SetJavaScriptEnabled")
private void initView() {
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setMessage("正在加载文件...");
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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"
xmlns:tools="http://schemas.android.com/tools">
<com.cherry.lib.doc.pdf.PinchZoomRecyclerView
android:id="@+id/mRvPdf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:scrollbars="vertical"
tools:listitem="@layout/list_item_pdf" />
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/mLlBigPdfImage"
......@@ -23,15 +14,15 @@
<com.cherry.lib.doc.widget.PinchImageView
android:id="@+id/mIvPdf"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/mPbBigLoading"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible"/>
tools:visibility="visible" />
<ImageView
android:layout_width="wrap_content"
......@@ -40,33 +31,29 @@
android:layout_marginTop="50dp"
android:layout_marginEnd="30dp"
android:scaleType="fitCenter"
android:src="@mipmap/ic_big_close"/>
android:src="@mipmap/ic_big_close"
tools:ignore="ContentDescription" />
</FrameLayout>
<FrameLayout
android:id="@+id/mFlDocContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<com.cherry.lib.doc.widget.PinchImageView
android:id="@+id/mIvImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"/>
<com.cherry.lib.doc.widget.DocWebView
android:id="@+id/mDocWeb"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:scaleType="fitCenter" />
<ProgressBar
android:id="@+id/mPlLoadProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/pb_webview_layer"
android:visibility="visible"/>
android:visibility="visible" />
<TextView
android:id="@+id/mPdfPageNo"
......@@ -79,7 +66,6 @@
android:paddingEnd="12dp"
android:paddingBottom="4dp"
android:textColor="#A19D9D"
android:textSize="16sp"
android:visibility="gone" />
android:textSize="16sp" />
</FrameLayout>
\ No newline at end of file
......@@ -14,6 +14,8 @@
android:padding="0dp"
android:scaleType="fitCenter" />
<include layout="@layout/pdf_view_page_loading_layout" />
<include
android:id="@+id/include"
layout="@layout/pdf_view_page_loading_layout" />
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment