|
@@ -1,16 +1,22 @@
|
|
|
package com.compdfkit.pdfviewer;
|
|
|
|
|
|
+import static android.content.ContentValues.TAG;
|
|
|
+
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
+import androidx.appcompat.widget.AppCompatImageButton;
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
-import androidx.core.content.ContextCompat;
|
|
|
import androidx.core.view.MenuProvider;
|
|
|
+import androidx.core.view.ViewCompat;
|
|
|
+import androidx.core.view.WindowInsetsControllerCompat;
|
|
|
+import androidx.recyclerview.widget.DividerItemDecoration;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
|
-import android.graphics.Canvas;
|
|
|
+import android.graphics.Color;
|
|
|
import android.graphics.RectF;
|
|
|
-import android.graphics.drawable.Drawable;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
@@ -22,31 +28,35 @@ import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
+import android.view.WindowManager;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.compdfkit.core.common.CPDFDocumentException;
|
|
|
import com.compdfkit.core.document.CPDFDocument;
|
|
|
import com.compdfkit.core.page.CPDFPage;
|
|
|
-import com.compdfkit.core.utils.ColorUtils;
|
|
|
import com.compdfkit.core.watermark.CPDFImageWatermark;
|
|
|
-import com.compdfkit.core.watermark.CPDFTextWatermark;
|
|
|
import com.compdfkit.core.watermark.CPDFWatermark;
|
|
|
-import com.compdfkit.pdfviewer.customview.ImageWatermarkView;
|
|
|
-import com.compdfkit.pdfviewer.customview.TextWatermarkView;
|
|
|
-import com.compdfkit.pdfviewer.customview.WatermarkView;
|
|
|
+import com.compdfkit.pdfviewer.adapter.WatermarkListAdapter;
|
|
|
+import com.compdfkit.pdfviewer.customview.watermarkview.ImageWatermarkView;
|
|
|
+import com.compdfkit.pdfviewer.customview.watermarkview.TextWatermarkView;
|
|
|
+import com.compdfkit.pdfviewer.customview.watermarkview.WatermarkView;
|
|
|
import com.compdfkit.pdfviewer.entity.WatermarkSetting;
|
|
|
import com.compdfkit.pdfviewer.fragments.WatermarkConsoleFragment;
|
|
|
-import com.compdfkit.pdfviewer.tools.CoordinateMapper;
|
|
|
-import com.compdfkit.ui.reader.CPDFReaderView;
|
|
|
+import com.compdfkit.pdfviewer.tools.ConvertMapper;
|
|
|
+import com.compdfkit.pdfviewer.tools.WatermarkHandle;
|
|
|
import com.google.android.material.tabs.TabLayout;
|
|
|
|
|
|
-import org.w3c.dom.Text;
|
|
|
-
|
|
|
import java.io.File;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
private ImageView pageImage;
|
|
|
+ private ImageView fullScreenMask;
|
|
|
+
|
|
|
+ private AppCompatImageButton expandListBtn;
|
|
|
+ private RecyclerView watermarkList;
|
|
|
+ private WatermarkListAdapter adapter;
|
|
|
|
|
|
private CPDFDocument document = new CPDFDocument(this);
|
|
|
private WatermarkView watermark;
|
|
@@ -55,9 +65,16 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
private int currentPageHeight = 0;
|
|
|
private int currentPageWidth = 0;
|
|
|
|
|
|
- private float sizeConvertRate = 0;
|
|
|
+ private int imageHeight;
|
|
|
+ private int imageWidth;
|
|
|
+
|
|
|
+ private int cacheIndex = -1;
|
|
|
+
|
|
|
+ private boolean editMode = false;
|
|
|
+
|
|
|
+ private WatermarkSetting watermarkSettingCache;
|
|
|
|
|
|
- private CPDFPage testPage;
|
|
|
+ private float sizeConvertRate = 0;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -65,6 +82,11 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
setContentView(R.layout.activity_main);
|
|
|
addMenuProvider(this);
|
|
|
|
|
|
+ if (this.getResources().getConfiguration().uiMode == 0x11) {
|
|
|
+ WindowInsetsControllerCompat wic = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
|
|
|
+ wic.setAppearanceLightStatusBars(true);
|
|
|
+ }
|
|
|
+
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
@@ -75,16 +97,24 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
consoleFragment.setAssociatedWatermark(watermark);
|
|
|
|
|
|
pageImage = findViewById(R.id.page_image);
|
|
|
+ fullScreenMask = findViewById(R.id.full_screen_mask);
|
|
|
+
|
|
|
+ expandListBtn = findViewById(R.id.expand_list_btn);
|
|
|
+ expandListBtn.setOnClickListener(view -> {
|
|
|
+ try {
|
|
|
+ expandWatermarkList();
|
|
|
+ } catch (CPDFDocumentException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ watermarkList = findViewById(R.id.watermark_list);
|
|
|
|
|
|
TabLayout tabLayout = findViewById(R.id.tab_layout);
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
@Override
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
changeWatermark(tab.getPosition());
|
|
|
-
|
|
|
- consoleFragment.setAssociatedWatermark(watermark);
|
|
|
- consoleFragment.changePicker(tab.getPosition());
|
|
|
- watermark = tab.getPosition() == 0 ? findViewById(R.id.watermark_text) : findViewById(R.id.watermark_image);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -103,27 +133,21 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
|
|
|
- CPDFDocument.PDFDocumentError error = document.open(PDFFile.getAbsolutePath());
|
|
|
-
|
|
|
- if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {
|
|
|
- error = document.open(PDFUri, "password");
|
|
|
- } else if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
|
|
|
- Toast.makeText(this, "File:" + document.getFileName() + " open success.", Toast.LENGTH_SHORT).show();
|
|
|
- } else {
|
|
|
- Toast.makeText(this, "File failed.", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
+ reloadDocument(PDFFile, PDFUri);
|
|
|
|
|
|
+ consoleFragment.setDocumentPageCount(document.getPageCount());
|
|
|
CPDFPage currentPage = document.pageAtIndex(0);
|
|
|
- testPage = currentPage;
|
|
|
|
|
|
RectF pageSize = document.getPageSize(0);
|
|
|
float pageW = pageSize.right - pageSize.left;
|
|
|
float pageH = pageSize.bottom - pageSize.top;
|
|
|
|
|
|
pageImage.post(() -> {
|
|
|
- int imageHeight = pageImage.getHeight();
|
|
|
+ imageHeight = pageImage.getHeight();
|
|
|
sizeConvertRate = pageImage.getHeight() / pageH;
|
|
|
- int imageWidth = (int) (sizeConvertRate * pageW);
|
|
|
+ imageWidth = (int) (sizeConvertRate * pageW);
|
|
|
+
|
|
|
+ pageImage.setMaxWidth(imageWidth);
|
|
|
|
|
|
TextWatermarkView tempT = (TextWatermarkView) watermark;
|
|
|
tempT.setSizeConvertRate(sizeConvertRate);
|
|
@@ -132,16 +156,15 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
|
|
|
currentPageHeight = pageImage.getHeight();
|
|
|
currentPageWidth = imageWidth;
|
|
|
- Bitmap pageBitmap = Bitmap.createBitmap(imageWidth, pageImage.getHeight(), Bitmap.Config.ARGB_4444);
|
|
|
+ Bitmap pageBitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_4444);
|
|
|
|
|
|
currentPage.renderPage(pageBitmap, 0, 0, imageWidth, pageImage.getHeight(), 0xFFFFFFFF, 255, 0, true, true);
|
|
|
refreshPageImage(pageBitmap);
|
|
|
+ fullScreenMask.setImageBitmap(pageBitmap);
|
|
|
|
|
|
pageImage.setOnDragListener(new View.OnDragListener() {
|
|
|
float currentSlope;
|
|
|
|
|
|
- final float convertRate = (float) (180 / 3.141592653);
|
|
|
-
|
|
|
double currentRotation = 0;
|
|
|
double resultRotation = 0;
|
|
|
|
|
@@ -164,15 +187,18 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
watermark.setX(dragEvent.getX() + xOutline - xOffset);
|
|
|
watermark.setY(dragEvent.getY() + yOutline - yOffset);
|
|
|
|
|
|
- watermark.setPDFXOffset(CoordinateMapper.convertViewXtoPDFXOffset(watermark.getX() - pageImage.getLeft(), xOffset, imageWidth / 2, sizeConvertRate));
|
|
|
- watermark.setPDFYOffset(CoordinateMapper.convertViewYtoPDFYOffset(watermark.getY() - pageImage.getTop(), yOffset, imageHeight / 2, sizeConvertRate));
|
|
|
+ watermark.setPDFXOffset(ConvertMapper.convertViewXToPDFXOffset(watermark.getX() - pageImage.getLeft(), xOffset, imageWidth / 2f, sizeConvertRate));
|
|
|
+ watermark.setPDFYOffset(ConvertMapper.convertViewYToPDFYOffset(watermark.getY() - pageImage.getTop(), yOffset, imageHeight / 2f, sizeConvertRate));
|
|
|
+
|
|
|
+ watermark.setViewXOffset(watermark.getPDFXOffset() * sizeConvertRate);
|
|
|
+ watermark.setViewYOffset(watermark.getPDFYOffset() * sizeConvertRate);
|
|
|
|
|
|
// Log.d("DragTest", "Drag Location: (" + dragEvent.getX() + "," + dragEvent.getY() + ")");
|
|
|
// Log.d("DragTest", "Watermark Location: (" + location[0] + "," + location[1] + ")");
|
|
|
// Log.d("DragTest", "Watermark get xy: (" + watermark.getX() + "," + watermark.getY() + ")");
|
|
|
// Log.d("DragTest", "pdf page w h: (" + pageW + "," + pageH + ")");
|
|
|
-// Log.d("DragTest", "Watermark get PDF xy: (" + CoordinateMapper.convertViewXtoPDFXOffset(watermark.getX() - pageImage.getLeft(), xOffset, imageWidth / 2, sizeConvertRate)
|
|
|
-// + "," + CoordinateMapper.convertViewYtoPDFYOffset(watermark.getY() - pageImage.getTop(), yOffset, imageHeight / 2, sizeConvertRate) + ")");
|
|
|
+// Log.d("DragTest", "Watermark get PDF xy: (" + ConvertMapper.convertViewXtoPDFXOffset(watermark.getX() - pageImage.getLeft(), xOffset, imageWidth / 2, sizeConvertRate)
|
|
|
+// + "," + ConvertMapper.convertViewYtoPDFYOffset(watermark.getY() - pageImage.getTop(), yOffset, imageHeight / 2, sizeConvertRate) + ")");
|
|
|
return true;
|
|
|
case DragEvent.ACTION_DRAG_ENDED:
|
|
|
watermark.setVisibility(View.VISIBLE);
|
|
@@ -192,19 +218,18 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
float centerPointY = watermark.getY() + 1.0f * watermark.getHeight() / 2; /* 控件中心点y = 当前控件位置y + 控件一半高度 */
|
|
|
|
|
|
if (dragEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
|
|
|
- //TODO:该部分的取坐标存在冗余代码
|
|
|
currentSlope = (dragEvent.getY() + pageImage.getTop() - centerPointY) / (dragEvent.getX() + pageImage.getLeft() - centerPointX) * -1;
|
|
|
- currentRotation = Math.atan(currentSlope) * convertRate;
|
|
|
+ currentRotation = Math.toDegrees(Math.atan(currentSlope));
|
|
|
|
|
|
if ((dragEvent.getY() + pageImage.getTop() < centerPointY && dragEvent.getX() + pageImage.getLeft() < centerPointX) || (dragEvent.getY() + pageImage.getTop() > centerPointY && dragEvent.getX() + pageImage.getLeft() < centerPointX)) {
|
|
|
currentRotation += 180;
|
|
|
- currentSlope += 3.1415926f;
|
|
|
+ currentSlope += Math.PI;
|
|
|
}
|
|
|
|
|
|
- resultRotation = currentRotation - Math.atan(baseSlope) * convertRate;
|
|
|
+ resultRotation = currentRotation - Math.toDegrees(Math.atan(baseSlope));
|
|
|
|
|
|
watermark.setRotation((float) resultRotation * -1);
|
|
|
- watermark.setRotationRadian((float) (resultRotation / convertRate));
|
|
|
+ watermark.setRotationRadian((float) Math.toRadians(resultRotation));
|
|
|
// Log.d("RollTest", "Current slope: " + currentSlope + ", Result rotation: " + resultRotation + ", Current rotation: " + currentRotation);
|
|
|
return true;
|
|
|
}
|
|
@@ -214,13 +239,29 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- Log.d("Render. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
+ watermarkList.post(() -> {
|
|
|
+ int watermarkCount = document.getWatermarkCount();
|
|
|
|
|
|
+ for (int i = 0; i < watermarkCount; i++) {
|
|
|
+ CPDFWatermark tempWatermark = document.getWatermark(i);
|
|
|
+ WatermarkHandle.addSettingIntoList(tempWatermark);
|
|
|
+ }
|
|
|
+
|
|
|
+ adapter = new WatermarkListAdapter(MainActivity.this, consoleFragment, WatermarkHandle.getSettingList());
|
|
|
+ watermarkList.setAdapter(adapter);
|
|
|
+
|
|
|
+ LinearLayoutManager manager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
|
|
|
+ watermarkList.setLayoutManager(manager);
|
|
|
+
|
|
|
+ watermarkList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
|
|
+ });
|
|
|
+
|
|
|
+ Log.d("Render. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
|
|
- menuInflater.inflate(R.menu.menu_done, menu);
|
|
|
+ menuInflater.inflate(R.menu.menu_prime, menu);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -228,6 +269,20 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public void changeWatermarkLocation(float x, float y) {
|
|
|
+ float xOffset = 1.0f * watermark.getWidth() / 2;
|
|
|
+ float yOffset = 1.0f * watermark.getHeight() / 2;
|
|
|
+
|
|
|
+ watermark.setX(ConvertMapper.convertPDFXOffsetToViewX(x, xOffset, imageWidth / 2f, sizeConvertRate) + pageImage.getLeft());
|
|
|
+ watermark.setY(ConvertMapper.convertPDFYOffsetToViewY(y, yOffset, imageHeight / 2f, sizeConvertRate) + pageImage.getTop());
|
|
|
+
|
|
|
+ watermark.setPDFXOffset(x);
|
|
|
+ watermark.setPDFYOffset(y);
|
|
|
+
|
|
|
+ watermark.setViewXOffset(x * sizeConvertRate);
|
|
|
+ watermark.setViewYOffset(y * sizeConvertRate);
|
|
|
+ }
|
|
|
+
|
|
|
public void changeWatermark(int type) {
|
|
|
watermark.setVisibility(View.INVISIBLE);
|
|
|
if (type == 1) {
|
|
@@ -236,53 +291,105 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
watermark = findViewById(R.id.watermark_text);
|
|
|
}
|
|
|
watermark.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ consoleFragment.setAssociatedWatermark(watermark);
|
|
|
+ consoleFragment.changePicker(type);
|
|
|
}
|
|
|
|
|
|
public void refreshPageImage(Bitmap updatePageBitmap) {
|
|
|
pageImage.setImageBitmap(updatePageBitmap);
|
|
|
}
|
|
|
|
|
|
- public void finishEditWatermark(MenuItem menuItem) throws CPDFDocumentException {
|
|
|
- WatermarkSetting setting = consoleFragment.getWatermarkSetting();
|
|
|
- watermark.completeSetting(setting);
|
|
|
+ public void reloadDocument(File PDFFile, Uri PDFUri) {
|
|
|
+ CPDFDocument.PDFDocumentError error = document.open(PDFFile.getAbsolutePath());
|
|
|
|
|
|
+ if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {
|
|
|
+ error = document.open(PDFUri, "password");
|
|
|
+ } else if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
|
|
|
+// Toast.makeText(this, "File:" + document.getFileName() + " open success.", Toast.LENGTH_SHORT).show();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(this, "File failed.", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createNewWatermark(WatermarkSetting setting) {
|
|
|
CPDFWatermark.Type[] types = {CPDFWatermark.Type.WATERMARK_TYPE_TEXT, CPDFWatermark.Type.WATERMARK_TYPE_IMG};
|
|
|
+ CPDFWatermark currentWatermark = document.createWatermark(types[consoleFragment.getMode()]);
|
|
|
|
|
|
- CPDFWatermark watermark;
|
|
|
- watermark = document.createWatermark(types[consoleFragment.getMode()]);
|
|
|
- try {
|
|
|
- if (watermark != null && watermark.isValid()) {
|
|
|
- if (setting.getImage() != null)
|
|
|
- watermark.setImage(setting.getImage(), (int) (setting.getiWidth() * sizeConvertRate), (int) (setting.getiHeight() * sizeConvertRate));
|
|
|
- watermark.setText(setting.getText()); //设置文本
|
|
|
- watermark.setFontName(setting.getFontName()); //设置字体
|
|
|
- watermark.setTextRGBColor(setting.getTextRGBColor());
|
|
|
- watermark.setOpacity(setting.getOpacity());
|
|
|
- watermark.setFontSize(setting.getFontSize());
|
|
|
- watermark.setFront(true);
|
|
|
- watermark.setVertalign(CPDFWatermark.Vertalign.WATERMARK_VERTALIGN_CENTER);
|
|
|
- watermark.setHorizalign(CPDFWatermark.Horizalign.WATERMARK_HORIZALIGN_CENTER);
|
|
|
- watermark.setVertOffset(setting.getVertOffset());
|
|
|
- watermark.setHorizOffset(setting.getHorizOffset());
|
|
|
- watermark.setRotation(setting.getRotation());
|
|
|
- watermark.setScale(setting.getScale());
|
|
|
- watermark.setPages(setting.getPages());
|
|
|
- watermark.setFullScreen(setting.getFullScreen());
|
|
|
- watermark.setHorizontalSpacing(setting.getHorizontalSpacing());
|
|
|
- watermark.setVerticalSpacing(setting.getVerticalSpacing());
|
|
|
- watermark.update();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- if (watermark != null && watermark.isValid()) {
|
|
|
- watermark.release();
|
|
|
- }
|
|
|
+ WatermarkHandle.updateWatermark(currentWatermark, setting, sizeConvertRate);
|
|
|
+ adapter.addSettingIntoList(setting);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void changeWatermark(CPDFWatermark watermark, WatermarkSetting setting) {
|
|
|
+ WatermarkHandle.updateWatermark(watermark, setting, sizeConvertRate);
|
|
|
+ adapter.updateSettingList(cacheIndex, setting);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteWatermark(int deleteIndex) throws CPDFDocumentException {
|
|
|
+ CPDFWatermark targetWatermark = document.getWatermark(deleteIndex);
|
|
|
+ targetWatermark.clear();
|
|
|
+
|
|
|
+ adapter.deleteSettingFromList(deleteIndex);
|
|
|
+ reloadDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showFullScreenMask(boolean isFullScreen) {
|
|
|
+ if (isFullScreen) {
|
|
|
+ int imageHeight = pageImage.getHeight();
|
|
|
+ int imageWidth = pageImage.getWidth();
|
|
|
+
|
|
|
+ WatermarkView temp = watermark;
|
|
|
+
|
|
|
+ Bitmap fullScreenBitmap = temp.getFullScreenBitmap(imageWidth, imageHeight,
|
|
|
+ (int) ConvertMapper.convertMMtoViewUnit(consoleFragment.gethSpace(), sizeConvertRate),
|
|
|
+ (int) ConvertMapper.convertMMtoViewUnit(consoleFragment.getvSpace(), sizeConvertRate),
|
|
|
+ (int) watermark.getViewXOffset(),
|
|
|
+ (int) watermark.getViewYOffset(),
|
|
|
+ watermark.getRotation());
|
|
|
+ fullScreenMask.setImageBitmap(fullScreenBitmap);
|
|
|
+ fullScreenMask.setAlpha(consoleFragment.getCurrentOpacity());
|
|
|
+ fullScreenMask.setVisibility(View.VISIBLE);
|
|
|
+ watermark.setVisibility(View.INVISIBLE);
|
|
|
+ } else {
|
|
|
+ fullScreenMask.setVisibility(View.INVISIBLE);
|
|
|
+ watermark.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- Log.d("Finish. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
+ public void resetWatermark(int index) {
|
|
|
+ if (index == -1 || index == cacheIndex)
|
|
|
+ return;
|
|
|
+
|
|
|
+ CPDFWatermark tempWatermark = document.getWatermark(index);
|
|
|
+ WatermarkHandle.updateWatermark(tempWatermark, watermarkSettingCache, sizeConvertRate);
|
|
|
+ }
|
|
|
|
|
|
+ public void hideWatermark(int index) throws CPDFDocumentException {
|
|
|
+ CPDFWatermark currentWatermark = document.getWatermark(index);
|
|
|
+ if (index == cacheIndex)
|
|
|
+ return;
|
|
|
+
|
|
|
+ resetWatermark(cacheIndex);
|
|
|
+ cacheIndex = index;
|
|
|
+ watermarkSettingCache = WatermarkHandle.getSettingFromList(index);
|
|
|
+
|
|
|
+ if (currentWatermark.getType() == CPDFWatermark.Type.WATERMARK_TYPE_IMG) {
|
|
|
+ CPDFImageWatermark imageWatermark = (CPDFImageWatermark) currentWatermark;
|
|
|
+ imageWatermark.setOpacity(0f);
|
|
|
+ imageWatermark.update();
|
|
|
+ } else {
|
|
|
+ currentWatermark.setOpacity(0f);
|
|
|
+ currentWatermark.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.d(TAG, "hideWatermark: current watermark count:" + document.getWatermarkCount());
|
|
|
+
|
|
|
+ reloadDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reloadDocument() throws CPDFDocumentException {
|
|
|
if (document.hasChanges()) {
|
|
|
boolean res;
|
|
|
- //Save to original document
|
|
|
res = document.save();
|
|
|
}
|
|
|
document.close();
|
|
@@ -290,22 +397,55 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
|
|
|
- CPDFDocument.PDFDocumentError error = document.open(PDFFile.getAbsolutePath());
|
|
|
-
|
|
|
- if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {
|
|
|
- error = document.open(PDFUri, "password");
|
|
|
- } else if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
|
|
|
- Toast.makeText(this, "File:" + document.getFileName() + " open success.", Toast.LENGTH_SHORT).show();
|
|
|
- } else {
|
|
|
- Toast.makeText(this, "File failed.", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
-
|
|
|
+ reloadDocument(PDFFile, PDFUri);
|
|
|
CPDFPage currentPage = document.pageAtIndex(0);
|
|
|
-// currentPage.equals(testPage)
|
|
|
- Log.d("Finish EditWatermark", "the equal's result:" + (currentPage.equals(testPage)) );
|
|
|
|
|
|
Bitmap pageBitmap = Bitmap.createBitmap(currentPageWidth, currentPageHeight, Bitmap.Config.ARGB_4444);
|
|
|
currentPage.renderPage(pageBitmap, 0, 0, currentPageWidth, currentPageHeight, 0xFFFFFFFF, 255, 0, true, true);
|
|
|
refreshPageImage(pageBitmap);
|
|
|
}
|
|
|
+
|
|
|
+ public void finishEditWatermark(MenuItem menuItem) throws CPDFDocumentException {
|
|
|
+ WatermarkSetting setting = consoleFragment.getWatermarkSetting();
|
|
|
+ watermark.completeSetting(setting);
|
|
|
+
|
|
|
+ if (!editMode) {
|
|
|
+ createNewWatermark(setting);
|
|
|
+ Toast.makeText(this, "Add new watermark", Toast.LENGTH_SHORT).show();
|
|
|
+ } else {
|
|
|
+ changeWatermark(document.getWatermark(cacheIndex), setting);
|
|
|
+ Toast.makeText(this, "Change a watermark, index:" + cacheIndex, Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ cacheIndex = -1;
|
|
|
+ }
|
|
|
+ Log.d("Finish. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
+
|
|
|
+ reloadDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void changeEditMode(MenuItem menuItem) {
|
|
|
+ editMode = !editMode;
|
|
|
+
|
|
|
+ Objects.requireNonNull(getSupportActionBar()).setTitle(editMode ? R.string.edit_watermark : R.string.add_watermark);
|
|
|
+ menuItem.setIcon(editMode ? R.drawable.ic_baseline_watermark_add_24 : R.drawable.ic_baseline_edit_note_24);
|
|
|
+
|
|
|
+ watermark.setVisibility(editMode ? View.INVISIBLE : View.VISIBLE);
|
|
|
+ watermarkList.setVisibility(editMode ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ if (!editMode) {
|
|
|
+ expandListBtn.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void expandWatermarkList() throws CPDFDocumentException {
|
|
|
+ resetWatermark(cacheIndex);
|
|
|
+ watermark.setVisibility(View.INVISIBLE);
|
|
|
+ watermarkList.setVisibility(View.VISIBLE);
|
|
|
+ reloadDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void closeWatermarkList() {
|
|
|
+ expandListBtn.setVisibility(View.VISIBLE);
|
|
|
+ watermarkList.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
}
|