|
@@ -4,18 +4,13 @@ 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.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.Color;
|
|
|
import android.graphics.RectF;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
@@ -28,6 +23,7 @@ import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.Toast;
|
|
@@ -37,7 +33,7 @@ import com.compdfkit.core.document.CPDFDocument;
|
|
|
import com.compdfkit.core.page.CPDFPage;
|
|
|
import com.compdfkit.core.watermark.CPDFImageWatermark;
|
|
|
import com.compdfkit.core.watermark.CPDFWatermark;
|
|
|
-import com.compdfkit.pdfviewer.adapter.WatermarkListAdapter;
|
|
|
+import com.compdfkit.pdfviewer.customview.listview.WatermarkListView;
|
|
|
import com.compdfkit.pdfviewer.customview.watermarkview.ImageWatermarkView;
|
|
|
import com.compdfkit.pdfviewer.customview.watermarkview.TextWatermarkView;
|
|
|
import com.compdfkit.pdfviewer.customview.watermarkview.WatermarkView;
|
|
@@ -49,19 +45,23 @@ import com.google.android.material.tabs.TabLayout;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
+ private TabLayout tabLayout;
|
|
|
+ private View pageContainer;
|
|
|
+
|
|
|
private ImageView pageImage;
|
|
|
private ImageView fullScreenMask;
|
|
|
|
|
|
- private AppCompatImageButton expandListBtn;
|
|
|
- private RecyclerView watermarkList;
|
|
|
- private WatermarkListAdapter adapter;
|
|
|
+ private WatermarkListView watermarkListView;
|
|
|
|
|
|
private CPDFDocument document = new CPDFDocument(this);
|
|
|
private WatermarkView watermark;
|
|
|
private WatermarkConsoleFragment consoleFragment;
|
|
|
|
|
|
+ private MenuItem doneItem;
|
|
|
+
|
|
|
private int currentPageHeight = 0;
|
|
|
private int currentPageWidth = 0;
|
|
|
|
|
@@ -78,39 +78,88 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ int[] themes = new int[] {R.style.AppTheme, R.style.AppRedTheme, R.style.AppOrangeTheme, R.style.AppGreenTheme, R.style.AppCyanBlueTheme};
|
|
|
+ int randomTheme = new Random().nextInt(5);
|
|
|
+ setTheme(themes[randomTheme]);
|
|
|
+
|
|
|
super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ WindowManager.LayoutParams windowAttributes = getWindow().getAttributes();
|
|
|
+ windowAttributes.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
|
|
|
+ getWindow().setAttributes(windowAttributes);
|
|
|
+
|
|
|
setContentView(R.layout.activity_main);
|
|
|
addMenuProvider(this);
|
|
|
|
|
|
if (this.getResources().getConfiguration().uiMode == 0x11) {
|
|
|
WindowInsetsControllerCompat wic = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
|
|
|
- wic.setAppearanceLightStatusBars(true);
|
|
|
+// assert wic != null;
|
|
|
+ if (wic != null)
|
|
|
+ wic.setAppearanceLightStatusBars(true);
|
|
|
}
|
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
+ pageContainer = findViewById(R.id.page_container);
|
|
|
+
|
|
|
watermark = findViewById(R.id.watermark_text);
|
|
|
- consoleFragment = (WatermarkConsoleFragment) getSupportFragmentManager().findFragmentByTag("console_fragment");
|
|
|
|
|
|
+ consoleFragment = (WatermarkConsoleFragment) getSupportFragmentManager().findFragmentByTag("console_fragment");
|
|
|
assert consoleFragment != null;
|
|
|
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();
|
|
|
- }
|
|
|
+ watermarkListView = findViewById(R.id.watermark_list_view);
|
|
|
+
|
|
|
+ tabLayout = findViewById(R.id.tab_layout);
|
|
|
+ initTabLayout();
|
|
|
+
|
|
|
+ if (!(Build.VERSION.SDK_INT < Build.VERSION_CODES.R || Environment.isExternalStorageManager())) {
|
|
|
+ Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+// File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
+ String rootpath = Environment.getExternalStorageDirectory().getPath();
|
|
|
+
|
|
|
+ File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
+ Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
+
|
|
|
+ reloadDocument(PDFFile, PDFUri);
|
|
|
+
|
|
|
+ consoleFragment.setDocumentPageCount(document.getPageCount());
|
|
|
+
|
|
|
+ pageImage.post(() -> {
|
|
|
+ initPageImageContent();
|
|
|
+ initPageImageListener();
|
|
|
+ });
|
|
|
+
|
|
|
+ watermarkListView.post(() -> {
|
|
|
+ watermarkListView.scrollTo(watermarkListView.getWidth(), 0);
|
|
|
+ watermarkListView.initList(document, consoleFragment);
|
|
|
});
|
|
|
|
|
|
- watermarkList = findViewById(R.id.watermark_list);
|
|
|
+ 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_prime, menu);
|
|
|
+
|
|
|
+ doneItem = menu.findItem(R.id.done);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initTabLayout() {
|
|
|
|
|
|
- TabLayout tabLayout = findViewById(R.id.tab_layout);
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
@Override
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
@@ -123,150 +172,120 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
@Override
|
|
|
public void onTabReselected(TabLayout.Tab tab) {}
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
- if (!(Build.VERSION.SDK_INT < Build.VERSION_CODES.R || Environment.isExternalStorageManager())) {
|
|
|
- Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
-
|
|
|
- File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
- Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
-
|
|
|
- reloadDocument(PDFFile, PDFUri);
|
|
|
-
|
|
|
- consoleFragment.setDocumentPageCount(document.getPageCount());
|
|
|
+ public void initPageImageContent() {
|
|
|
CPDFPage currentPage = document.pageAtIndex(0);
|
|
|
|
|
|
RectF pageSize = document.getPageSize(0);
|
|
|
float pageW = pageSize.right - pageSize.left;
|
|
|
float pageH = pageSize.bottom - pageSize.top;
|
|
|
|
|
|
- pageImage.post(() -> {
|
|
|
- imageHeight = pageImage.getHeight();
|
|
|
- sizeConvertRate = pageImage.getHeight() / pageH;
|
|
|
- imageWidth = (int) (sizeConvertRate * pageW);
|
|
|
+ if (pageW / pageH > ((float) pageContainer.getWidth() / (float) pageContainer.getHeight())) {
|
|
|
+ sizeConvertRate = pageContainer.getWidth() / pageW;
|
|
|
+
|
|
|
+ imageHeight = (int) (sizeConvertRate * pageH);
|
|
|
+ imageWidth = pageContainer.getWidth();
|
|
|
|
|
|
+ pageImage.setMaxHeight(imageHeight);
|
|
|
pageImage.setMaxWidth(imageWidth);
|
|
|
+ } else {
|
|
|
+ sizeConvertRate = pageContainer.getHeight() / pageH;
|
|
|
|
|
|
- TextWatermarkView tempT = (TextWatermarkView) watermark;
|
|
|
- tempT.setSizeConvertRate(sizeConvertRate);
|
|
|
- ImageWatermarkView tempI = findViewById(R.id.watermark_image);
|
|
|
- tempI.setSizeConvertRate(sizeConvertRate);
|
|
|
-
|
|
|
- currentPageHeight = pageImage.getHeight();
|
|
|
- currentPageWidth = imageWidth;
|
|
|
- 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;
|
|
|
-
|
|
|
- double currentRotation = 0;
|
|
|
- double resultRotation = 0;
|
|
|
-
|
|
|
- int[] location = new int[2];
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onDrag(View view, DragEvent dragEvent) {
|
|
|
-
|
|
|
- if (watermark.getCurrentEvent() == WatermarkView.DRAG_EVENT) {
|
|
|
- float xOffset = 1.0f * watermark.getWidth() / 2;
|
|
|
- float yOffset = 1.0f * watermark.getHeight() / 2;
|
|
|
-
|
|
|
- int xOutline = pageImage.getLeft();
|
|
|
- int yOutline = pageImage.getTop();
|
|
|
- watermark.getLocationOnScreen(location);
|
|
|
-
|
|
|
- //TODO:需要优化控件越界行为
|
|
|
- switch (dragEvent.getAction()) {
|
|
|
- case DragEvent.ACTION_DRAG_LOCATION:
|
|
|
- watermark.setX(dragEvent.getX() + xOutline - xOffset);
|
|
|
- watermark.setY(dragEvent.getY() + yOutline - yOffset);
|
|
|
-
|
|
|
- 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: (" + 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);
|
|
|
- return false;
|
|
|
- default:
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- float xOffset = 1.0f * watermark.getWidth() / 2; /* 控件一半宽度 */
|
|
|
- float yOffset = 1.0f * watermark.getHeight() / 2; /* 控件一半高度 */
|
|
|
-
|
|
|
- float baseSlope = yOffset / xOffset * -1;
|
|
|
-
|
|
|
- watermark.getLocationOnScreen(location);
|
|
|
-
|
|
|
- float centerPointX = watermark.getX() + 1.0f * watermark.getWidth() / 2; /* 控件中心点x = 当前控件位置x + 控件一半宽度 */
|
|
|
- float centerPointY = watermark.getY() + 1.0f * watermark.getHeight() / 2; /* 控件中心点y = 当前控件位置y + 控件一半高度 */
|
|
|
-
|
|
|
- if (dragEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
|
|
|
- currentSlope = (dragEvent.getY() + pageImage.getTop() - centerPointY) / (dragEvent.getX() + pageImage.getLeft() - centerPointX) * -1;
|
|
|
- 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 += Math.PI;
|
|
|
- }
|
|
|
-
|
|
|
- resultRotation = currentRotation - Math.toDegrees(Math.atan(baseSlope));
|
|
|
-
|
|
|
- watermark.setRotation((float) resultRotation * -1);
|
|
|
- watermark.setRotationRadian((float) Math.toRadians(resultRotation));
|
|
|
-// Log.d("RollTest", "Current slope: " + currentSlope + ", Result rotation: " + resultRotation + ", Current rotation: " + currentRotation);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
+ imageHeight = pageContainer.getHeight();
|
|
|
+ imageWidth = (int) (sizeConvertRate * pageW);
|
|
|
|
|
|
- watermarkList.post(() -> {
|
|
|
- int watermarkCount = document.getWatermarkCount();
|
|
|
+ pageImage.setMaxWidth(imageWidth);
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < watermarkCount; i++) {
|
|
|
- CPDFWatermark tempWatermark = document.getWatermark(i);
|
|
|
- WatermarkHandle.addSettingIntoList(tempWatermark);
|
|
|
- }
|
|
|
+ TextWatermarkView tempT = (TextWatermarkView) watermark;
|
|
|
+ tempT.setSizeConvertRate(sizeConvertRate);
|
|
|
+ ImageWatermarkView tempI = findViewById(R.id.watermark_image);
|
|
|
+ tempI.setSizeConvertRate(sizeConvertRate);
|
|
|
|
|
|
- adapter = new WatermarkListAdapter(MainActivity.this, consoleFragment, WatermarkHandle.getSettingList());
|
|
|
- watermarkList.setAdapter(adapter);
|
|
|
+ currentPageHeight = imageHeight;
|
|
|
+ currentPageWidth = imageWidth;
|
|
|
+ Bitmap pageBitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_4444);
|
|
|
|
|
|
- LinearLayoutManager manager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
|
|
|
- watermarkList.setLayoutManager(manager);
|
|
|
+ currentPage.renderPage(pageBitmap, 0, 0, imageWidth, imageHeight, 0xFFFFFFFF, 255, 0, true, true);
|
|
|
+ refreshPageImage(pageBitmap);
|
|
|
+ fullScreenMask.setImageBitmap(pageBitmap);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initPageImageListener() {
|
|
|
+ pageImage.setOnDragListener((view, dragEvent) -> {
|
|
|
+ float xOffset = 1.0f * watermark.getWidth() / 2;
|
|
|
+ float yOffset = 1.0f * watermark.getHeight() / 2;
|
|
|
|
|
|
- watermarkList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
|
|
+ if (watermark.getCurrentEvent() == WatermarkView.DRAG_EVENT) {
|
|
|
+ return handleDragEvent(dragEvent, xOffset, yOffset);
|
|
|
+ } else {
|
|
|
+ return handleRollEvent(dragEvent, xOffset, yOffset);
|
|
|
+ }
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
- Log.d("Render. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
+ public void setTabLayoutEnable(boolean enable) {
|
|
|
+ ViewGroup viewGroup = (ViewGroup) tabLayout.getChildAt(0);;
|
|
|
+ if (viewGroup != null) {
|
|
|
+ for (int childIndex = 0; childIndex < viewGroup.getChildCount(); childIndex++) {
|
|
|
+ View tabView = viewGroup.getChildAt(childIndex);
|
|
|
+ if (tabView != null)
|
|
|
+ tabView.setEnabled(enable);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
|
|
- menuInflater.inflate(R.menu.menu_prime, menu);
|
|
|
+ public boolean handleDragEvent(@NonNull DragEvent dragEvent, float xOffset, float yOffset) {
|
|
|
+ int xOutline = pageImage.getLeft();
|
|
|
+ int yOutline = pageImage.getTop();
|
|
|
+
|
|
|
+ switch (dragEvent.getAction()) {
|
|
|
+ case DragEvent.ACTION_DRAG_LOCATION:
|
|
|
+ watermark.setX(dragEvent.getX() + xOutline - xOffset);
|
|
|
+ watermark.setY(dragEvent.getY() + yOutline - yOffset);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ case DragEvent.ACTION_DRAG_ENDED:
|
|
|
+ watermark.setVisibility(View.VISIBLE);
|
|
|
+ return false;
|
|
|
+ default:
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
|
|
|
- return false;
|
|
|
+ public boolean handleRollEvent(@NonNull DragEvent dragEvent, float xOffset, float yOffset) {
|
|
|
+ float currentSlope;
|
|
|
+
|
|
|
+ double currentRotation = 0;
|
|
|
+ double resultRotation = 0;
|
|
|
+
|
|
|
+ float baseSlope = yOffset / xOffset * -1;
|
|
|
+
|
|
|
+ float centerPointX = watermark.getX() + 1.0f * watermark.getWidth() / 2; /* 控件中心点x = 当前控件位置x + 控件一半宽度 */
|
|
|
+ float centerPointY = watermark.getY() + 1.0f * watermark.getHeight() / 2; /* 控件中心点y = 当前控件位置y + 控件一半高度 */
|
|
|
+
|
|
|
+ if (dragEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
|
|
|
+ currentSlope = (dragEvent.getY() + pageImage.getTop() - centerPointY) / (dragEvent.getX() + pageImage.getLeft() - centerPointX) * -1;
|
|
|
+ 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;
|
|
|
+
|
|
|
+ resultRotation = currentRotation - Math.toDegrees(Math.atan(baseSlope));
|
|
|
+
|
|
|
+ watermark.setRotation((float) resultRotation * -1);
|
|
|
+ watermark.setRotationRadian((float) Math.toRadians(resultRotation));
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public void changeWatermarkLocation(float x, float y) {
|
|
@@ -300,14 +319,30 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
pageImage.setImageBitmap(updatePageBitmap);
|
|
|
}
|
|
|
|
|
|
- public void reloadDocument(File PDFFile, Uri PDFUri) {
|
|
|
+ public void reloadDocument() throws CPDFDocumentException {
|
|
|
+ if (document.hasChanges()) {
|
|
|
+ boolean res;
|
|
|
+ res = document.save();
|
|
|
+ }
|
|
|
+ document.close();
|
|
|
+
|
|
|
+ File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
+ Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
+
|
|
|
+ reloadDocument(PDFFile, PDFUri);
|
|
|
+ CPDFPage currentPage = document.pageAtIndex(0);
|
|
|
+
|
|
|
+ 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 reloadDocument(@NonNull 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 {
|
|
|
+ } else if (error != CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
|
|
|
Toast.makeText(this, "File failed.", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
}
|
|
@@ -317,47 +352,23 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
CPDFWatermark currentWatermark = document.createWatermark(types[consoleFragment.getMode()]);
|
|
|
|
|
|
WatermarkHandle.updateWatermark(currentWatermark, setting, sizeConvertRate);
|
|
|
- adapter.addSettingIntoList(setting);
|
|
|
+ watermarkListView.addSettingIntoList(setting);
|
|
|
}
|
|
|
|
|
|
public void changeWatermark(CPDFWatermark watermark, WatermarkSetting setting) {
|
|
|
WatermarkHandle.updateWatermark(watermark, setting, sizeConvertRate);
|
|
|
- adapter.updateSettingList(cacheIndex, setting);
|
|
|
+// 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void resetWatermark(int index) {
|
|
|
- if (index == -1 || index == cacheIndex)
|
|
|
+ if (index == -1)
|
|
|
return;
|
|
|
|
|
|
CPDFWatermark tempWatermark = document.getWatermark(index);
|
|
@@ -384,25 +395,9 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
|
|
|
Log.d(TAG, "hideWatermark: current watermark count:" + document.getWatermarkCount());
|
|
|
|
|
|
- reloadDocument();
|
|
|
- }
|
|
|
+ doneItem.setEnabled(true);
|
|
|
|
|
|
- public void reloadDocument() throws CPDFDocumentException {
|
|
|
- if (document.hasChanges()) {
|
|
|
- boolean res;
|
|
|
- res = document.save();
|
|
|
- }
|
|
|
- document.close();
|
|
|
-
|
|
|
- File PDFFile = new File("/storage/emulated/0/TestPDFs/test.pdf");
|
|
|
- Uri PDFUri = Uri.fromFile(PDFFile);
|
|
|
-
|
|
|
- reloadDocument(PDFFile, PDFUri);
|
|
|
- CPDFPage currentPage = document.pageAtIndex(0);
|
|
|
-
|
|
|
- Bitmap pageBitmap = Bitmap.createBitmap(currentPageWidth, currentPageHeight, Bitmap.Config.ARGB_4444);
|
|
|
- currentPage.renderPage(pageBitmap, 0, 0, currentPageWidth, currentPageHeight, 0xFFFFFFFF, 255, 0, true, true);
|
|
|
- refreshPageImage(pageBitmap);
|
|
|
+ reloadDocument();
|
|
|
}
|
|
|
|
|
|
public void finishEditWatermark(MenuItem menuItem) throws CPDFDocumentException {
|
|
@@ -412,15 +407,40 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
if (!editMode) {
|
|
|
createNewWatermark(setting);
|
|
|
Toast.makeText(this, "Add new watermark", Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ reloadDocument();
|
|
|
} else {
|
|
|
changeWatermark(document.getWatermark(cacheIndex), setting);
|
|
|
Toast.makeText(this, "Change a watermark, index:" + cacheIndex, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
cacheIndex = -1;
|
|
|
+
|
|
|
+ expandWatermarkList();
|
|
|
}
|
|
|
Log.d("Finish. Watermark Count", "current watermark count:" + document.getWatermarkCount());
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void changeEditMode(MenuItem menuItem) {
|
|
@@ -430,22 +450,32 @@ public class MainActivity extends AppCompatActivity implements MenuProvider {
|
|
|
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);
|
|
|
+ if (editMode) {
|
|
|
+ watermarkListView.showView();
|
|
|
+
|
|
|
+ setTabLayoutEnable(false);
|
|
|
+ doneItem.setEnabled(false);
|
|
|
+ } else {
|
|
|
+ resetWatermark(cacheIndex);
|
|
|
+ watermarkListView.hintView();
|
|
|
+
|
|
|
+ setTabLayoutEnable(true);
|
|
|
+ doneItem.setEnabled(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void expandWatermarkList() throws CPDFDocumentException {
|
|
|
+ watermarkListView.showView();
|
|
|
+
|
|
|
resetWatermark(cacheIndex);
|
|
|
watermark.setVisibility(View.INVISIBLE);
|
|
|
- watermarkList.setVisibility(View.VISIBLE);
|
|
|
reloadDocument();
|
|
|
+
|
|
|
+ doneItem.setEnabled(false);
|
|
|
}
|
|
|
|
|
|
public void closeWatermarkList() {
|
|
|
- expandListBtn.setVisibility(View.VISIBLE);
|
|
|
- watermarkList.setVisibility(View.INVISIBLE);
|
|
|
+ watermarkListView.hintList();
|
|
|
+ watermark.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
-
|
|
|
}
|