Commit 9105d9c3 authored by wanglei's avatar wanglei

...

parent 1eb1f4cd
......@@ -3,10 +3,10 @@ package com.base.pdfviewerscannerwhite.bean
import android.net.Uri
data class DocumentBean(
val path: String = "",
var path: String = "",
var uri: Uri = Uri.EMPTY,
val type: String = "",
var isBookmarked: Boolean = false
var type: String = "",
var isBookmarked: Boolean = false,
) {
var uiType: Int = 0//0首页模式 1合并选择模式 2拆分模式 3解锁加锁模式
var isSelect: Boolean = false
......
......@@ -74,8 +74,10 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
val file = File(item.path)
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize()
runCatching {
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize()
}
when (item.uiType) {
0 -> {
......
......@@ -8,19 +8,14 @@ import android.view.View
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityExcelBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentMore
import com.base.pdfviewerscannerwhite.utils.KeyBoardUtils.hideKeyboard
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import com.cherry.lib.doc.bean.DocEngine
import com.cherry.lib.doc.office.ss.control.SSControl
import com.cherry.lib.doc.util.Constant
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
class ExcelActivity : BaseActivity<ActivityExcelBinding>() {
......@@ -32,6 +27,7 @@ class ExcelActivity : BaseActivity<ActivityExcelBinding>() {
}
companion object {
var excelDocumentBean:DocumentBean = DocumentBean()
fun launchDocViewer(
activity: Activity,
docSourceType: Int,
......@@ -70,7 +66,7 @@ class ExcelActivity : BaseActivity<ActivityExcelBinding>() {
switchOrientation()
}
binding.ivMore.setOnClickListener {
showDocumentMore(DocumentBean.TYPE_EXCEL)
showDocumentMore(excelDocumentBean)
}
binding.mDocView.singleTapAction = {
......
......@@ -50,6 +50,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
private var saveMode = ""
private var path: String = ""
private var uri: String? = null
private var assets: String? = null
private var density = 0f
override val binding: ActivityPdfBinding by lazy {
......@@ -64,6 +65,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
path = intent.extras?.getString("path") ?: ""
uri = intent.extras?.getString("uri")
assets = intent.extras?.getString("assets") ?: ""
LogEx.logDebug(TAG, "path=$path")
LogEx.logDebug(TAG, "uri=$uri")
......
......@@ -9,13 +9,14 @@ import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import androidx.activity.addCallback
import androidx.core.view.isVisible
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PPT
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityPptBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentMore
import com.base.pdfviewerscannerwhite.utils.KeyBoardUtils.hideKeyboard
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.cherry.lib.doc.bean.DocEngine
import com.cherry.lib.doc.office.pg.control.PGControl
import com.cherry.lib.doc.office.system.beans.pagelist.APageListAdapter
import com.cherry.lib.doc.util.Constant
class PptActivity : BaseActivity<ActivityPptBinding>() {
......@@ -27,6 +28,8 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
}
companion object {
var pptDocumentBean: DocumentBean = DocumentBean()
fun launchDocViewer(
activity: Activity,
docSourceType: Int,
......@@ -44,6 +47,8 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
}
private var totalPageNumber = 0
@SuppressLint("SetTextI18n")
override fun initView() {
initSpData(intent)
......@@ -51,6 +56,7 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
if (!binding.tvPageCount.isVisible) {
binding.tvPageCount.isVisible = true
}
totalPageNumber = total
binding.tvPageCount.text = "$current/$total"
}
binding.mDocView.singleTapAction = {
......@@ -77,7 +83,10 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
switchOrientation()
}
binding.ivMore.setOnClickListener {
showDocumentMore(TYPE_PPT)
showDocumentMore(pptDocumentBean, totalPageNumber - 1) { pageIndex ->
((binding.mDocView.iOffice?.control?.appControl as PGControl)
.pgView.pgPrintMode.listView.showPDFPageForIndex(pageIndex))
}
}
}
......@@ -92,15 +101,15 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
private var docSourceType = 0
private var fileType = -1
private var engine: Int = DocEngine.INTERNAL.value
private var docUrl: String? = null// 文件地址
private var pathOrUri: String? = null// 文件地址
private fun initSpData(intent: Intent?) {
docUrl = intent?.getStringExtra(Constant.INTENT_DATA_KEY)
pathOrUri = intent?.getStringExtra(Constant.INTENT_DATA_KEY)
docSourceType = intent?.getIntExtra(Constant.INTENT_SOURCE_KEY, 0) ?: 0
fileType = intent?.getIntExtra(Constant.INTENT_TYPE_KEY, -1) ?: -1
engine = intent?.getIntExtra(Constant.INTENT_ENGINE_KEY, DocEngine.INTERNAL.value) ?: DocEngine.INTERNAL.value
binding.mDocView.openDoc(this, docUrl, docSourceType, fileType, false, DocEngine.values().first { it.value == engine })
LogEx.logDebug(TAG, "initData-docUrl = $docUrl")
binding.mDocView.openDoc(this, pathOrUri, docSourceType, fileType, false, DocEngine.values().first { it.value == engine })
LogEx.logDebug(TAG, "initData-docUrl = $pathOrUri")
LogEx.logDebug(TAG, "initData-docSourceType = $docSourceType")
LogEx.logDebug(TAG, "initData-fileType = $fileType")
LogEx.logDebug(TAG, "initData-engine = $engine")
......@@ -130,7 +139,6 @@ class PptActivity : BaseActivity<ActivityPptBinding>() {
if (isShowTopLayout) {
isShowTopLayout = false
hideKeyboard(binding.editSearch)
val topAnim: Animation = TranslateAnimation(0f, 0f, 0f, -binding.vAnimatorTop.height.toFloat())
topAnim.setDuration(200)
topAnim.setAnimationListener(object : Animation.AnimationListener {
......
......@@ -40,7 +40,7 @@ class WordActivity : BaseActivity<ActivityWordBinding>() {
switchOrientation()
}
binding.ivMore.setOnClickListener {
showDocumentMore(DocumentBean.TYPE_WORD)
showDocumentMore(wordDocumentBean)
}
mPoiViewer.singleTapAction = {
......@@ -112,5 +112,8 @@ class WordActivity : BaseActivity<ActivityWordBinding>() {
}
}
companion object {
var wordDocumentBean: DocumentBean = DocumentBean()
}
}
\ No newline at end of file
......@@ -78,14 +78,18 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
}
}
if (type == TYPE_WORD) {
startActivity(Intent(requireContext(), WordActivity::class.java).apply {
putExtra("path", item.path)
})
// startActivity(Intent(requireContext(), WordActivity::class.java).apply {
// putExtra("path", item.path)
// })
WordActivity.wordDocumentBean
PptActivity.launchDocViewer(requireActivity(), 3, item.path, -1, 100)
}
if (type == TYPE_EXCEL) {
ExcelActivity.excelDocumentBean
ExcelActivity.launchDocViewer(requireActivity(), 3, item.path, -1, 100)
}
if (type == TYPE_PPT) {
PptActivity.pptDocumentBean = item
PptActivity.launchDocViewer(requireActivity(), 3, item.path, -1, 100)
}
}
......
......@@ -5,6 +5,11 @@ import androidx.lifecycle.LifecycleCoroutineScope
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoDocx
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoPdf
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoPptx
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoXlsx
import com.base.pdfviewerscannerwhite.utils.AssetUtils.saveAssetsFile
import com.base.pdfviewerscannerwhite.utils.SpStringUtils
import com.base.pdfviewerscannerwhite.utils.getMediaFile
import kotlinx.coroutines.Dispatchers
......@@ -19,27 +24,39 @@ class DocumentPresenter(
) {
private fun getDocumentBeanList(): List<DocumentBean> {
context.saveAssetsFile()
var selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
val demoDocumentBean = DocumentBean()
if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
demoDocumentBean.path = context.getDemoPdf()
}
if (type == DocumentBean.TYPE_WORD) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_DOC, ConstObject.MIME_TYPE_DOCX)
demoDocumentBean.path = context.getDemoDocx()
}
if (type == DocumentBean.TYPE_EXCEL) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_XLS, ConstObject.MIME_TYPE_XLSX)
demoDocumentBean.path = context.getDemoXlsx()
}
if (type == DocumentBean.TYPE_PPT) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PPT, ConstObject.MIME_TYPE_PPTX)
demoDocumentBean.path = context.getDemoPptx()
}
demoDocumentBean.type = type
val bookmarkList = SpStringUtils.getSpStringList(SpStringUtils.BOOKMARK_KEY)
val list = context.getMediaFile(selectionArgs = selectionArgs)
val documentList = list.map {
DocumentBean(it.path, uri = it.uri, type, bookmarkList.contains(it.path))
DocumentBean(it.path, uri = it.uri, type = type, isBookmarked = bookmarkList.contains(it.path))
}
return documentList
val new = documentList.toMutableList()
new.add(0, demoDocumentBean)
return new
}
fun initData() = lifecycleScope.launch(Dispatchers.IO) {
......
......@@ -5,7 +5,6 @@ import android.net.Uri
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
......
......@@ -31,6 +31,7 @@ import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfMoreDialog
import com.base.pdfviewerscannerwhite.utils.ActivityLauncher
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePdfIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePdfPrintIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePptIntent
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
......@@ -231,7 +232,11 @@ object DialogView {
}
fun Activity.showDocumentMore(type: String) {
fun Activity.showDocumentMore(
documentBean: DocumentBean,
pageNumber: Int = 0,
jumpAction: ((pageIndex:Int) -> Unit)? = null
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogDocumentMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
......@@ -244,9 +249,43 @@ object DialogView {
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
if (type == TYPE_EXCEL) {
if (documentBean.type == TYPE_EXCEL) {
binding.llJump.visibility = View.GONE
}
if (documentBean.isBookmarked) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
}
binding.ivBookmark.setOnClickListener {
binding.ivBookmark.isSelected = !binding.ivBookmark.isSelected
if (binding.ivBookmark.isSelected) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
SpStringUtils.addSpString(SpStringUtils.BOOKMARK_KEY, documentBean.path)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
SpStringUtils.deleteSpString(SpStringUtils.BOOKMARK_KEY, documentBean.path)
}
}
binding.llDetail.setOnClickListener {
showDocumentDetail(documentBean.path)
}
binding.llShare.setOnClickListener {
val uri = FileProvider.getUriForFile(
this, this.packageName + ".provider", File(documentBean.path)
)
startActivity(Intent.createChooser(sharePptIntent(uri), "Share PDF"))
}
binding.llJump.setOnClickListener {
showJumpPageNumberDialog(pageNumber) { pageIndex ->
dialog.dismiss()
jumpAction?.invoke(pageIndex)
}
}
}
......
package com.base.pdfviewerscannerwhite.utils
import android.content.Context
import android.content.res.AssetManager
import java.io.BufferedReader
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
object AssetUtils {
fun Context.readByteArrayFromAsset(fileName: String): ByteArray {
val assetManager: AssetManager = this.assets
var ins: InputStream? = null
val byteStream = ByteArrayOutputStream()
try {
ins = assetManager.open(fileName)
var nextValue: Int
while (ins.read().also { nextValue = it } != -1) {
byteStream.write(nextValue)
}
} catch (e: IOException) {
e.printStackTrace()
} finally {
try {
ins?.close()
byteStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
return byteStream.toByteArray()
}
fun Context.getDemoPdf(): String {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
val file = File(demoFile, "DEMO.pdf")
return file.absolutePath
}
fun Context.getDemoDocx(): String {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
val file = File(demoFile, "DEMO.docx")
return file.absolutePath
}
fun Context.getDemoXlsx(): String {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
val file = File(demoFile, "DEMO.xlsx")
return file.absolutePath
}
fun Context.getDemoPptx(): String {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
val file = File(demoFile, "DEMO.pptx")
return file.absolutePath
}
fun Context.saveAssetsFile() {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
arrayOf("DEMO.pdf,DEMO.docx", "DEMO.xlsx", "DEMO.pptx").forEach {
val file = File(demoFile, it)
if (file.exists() && file.length() != 0L) {
return
}
file.createNewFile()
try {
FileOutputStream(file).use { fos -> fos.write(readByteArrayFromAsset(it)) }
} catch (e: IOException) {
e.printStackTrace()
}
}
}
fun Context.readJsonFromAsset(fileName: String): String {
var json = ""
try {
val assetManager = this.assets
val inputStream = assetManager.open(fileName)
val reader = BufferedReader(InputStreamReader(inputStream))
var line: String?
val jsonString = StringBuilder()
while (reader.readLine().also { line = it } != null) {
jsonString.append(line)
}
reader.close()
inputStream.close()
json = jsonString.toString()
} catch (e: IOException) {
e.printStackTrace()
}
return json
}
}
\ No newline at end of file
......@@ -15,6 +15,16 @@ object IntentShareUtils {
return shareIntent
}
fun sharePptIntent(uri: Uri): Intent {
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, uri)
type = "application/vnd.ms-powerpoint"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 授权临时权限
}
return shareIntent
}
fun sharePdfPrintIntent(uri: Uri): Intent {
// 创建打印的 Intent
val intent = Intent(Intent.ACTION_SEND)
......
......@@ -61,22 +61,10 @@
android:layout_marginEnd="16dp"
android:src="@mipmap/hengping"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_search"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="@mipmap/h_sousuo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_more"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_more"
android:layout_width="wrap_content"
......@@ -88,24 +76,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<EditText
android:id="@+id/edit_search"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="20dp"
android:background="@drawable/bg_f8f9fe_10"
android:hint="input..."
android:paddingHorizontal="18dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="#B8B9BD"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_search"
app:layout_constraintStart_toEndOf="@id/fl_fanhui"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="Autofill,HardcodedText,TextFields" />
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -6,5 +6,7 @@
<external-path
name="extern_files"
path="." />
<files-path
name="files"
path="." />
</paths>
......@@ -317,7 +317,6 @@ public abstract class IOffice implements IMainFrame {
@Override
public boolean isChangePage() {
// TODO Auto-generated method stub
return true;
}
......
......@@ -544,7 +544,7 @@ public class PGControl extends AbstractControl {
//
private boolean isDispose;
//
private Presentation pgView;
public Presentation pgView;
//
private IControl mainControl;
//
......
......@@ -42,8 +42,6 @@ public class PGPageListItem extends APageListItem
private static final int BACKGROUND_COLOR = 0xFFFFFFFF;
/**
*
* @param content
* @param parentSize
*/
public PGPageListItem(APageListView listView, IControl control, PGEditor editor, int pageWidth, int pageHeight)
{
......
......@@ -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;
......@@ -627,7 +626,7 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener {
//
private IControl control;
//
private APageListView listView;
public APageListView listView;
// 绘制器
private Paint paint;
//
......
......@@ -1057,6 +1057,6 @@ public class Presentation extends FrameLayout implements IFind, IExportListener
/**
*
*/
private PGPrintMode pgPrintMode;
public PGPrintMode pgPrintMode;
private CalloutView callouts;
}
......@@ -32,7 +32,6 @@ public class APageListAdapter extends BaseAdapter
/**
* construct
*
* @param pdfListView
*/
public APageListAdapter(APageListView view)
{
......
......@@ -1025,7 +1025,7 @@ public class APageListView extends AdapterView<Adapter> {
//
private IPageListViewListener pageListViewListener;
//
private Adapter pageAdapter;
public Adapter pageAdapter;
//
private APageListEventManage eventManage;
//
......
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