ソースを参照

完成UI以及交互逻辑

dengyujia 2 年 前
コミット
1aa5094fbc

+ 4 - 6
.gitignore

@@ -7,15 +7,13 @@
 /.idea/workspace.xml
 /.idea/navEditor.xml
 /.idea/assetWizardSettings.xml
-
-/app/libs
-
-/app/src/androidTest
-/app/src/test
-
 .DS_Store
 /build
 /captures
 .externalNativeBuild
 .cxx
 local.properties
+
+app/libs
+app/src/androidTest
+app/src/test

+ 223 - 68
app/src/main/java/com/compdfkit/pdfviewer/MainActivity.java

@@ -1,52 +1,187 @@
 package com.compdfkit.pdfviewer;
 
+import androidx.annotation.NonNull;
 import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.content.ContextCompat;
-import androidx.core.graphics.drawable.DrawableCompat;
+import androidx.appcompat.widget.Toolbar;
+import androidx.core.view.MenuProvider;
 
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
+import android.graphics.RectF;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.provider.Settings;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ImageView;
 import android.widget.Toast;
 
 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.WatermarkView;
+import com.compdfkit.pdfviewer.fragments.WatermarkConsoleFragment;
 import com.compdfkit.ui.reader.CPDFReaderView;
+import com.google.android.material.tabs.TabLayout;
 
 import java.io.File;
 
-public class MainActivity extends AppCompatActivity {
+public class MainActivity extends AppCompatActivity implements MenuProvider {
+    private ImageView pageImage;
+
+    private CPDFDocument document = new CPDFDocument(this);
+
+    private WatermarkView watermark;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
-//        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);
-//        }
+        Toolbar toolbar = findViewById(R.id.toolbar);
+        setSupportActionBar(toolbar);
+
+        watermark = findViewById(R.id.watermark_text);
+        WatermarkConsoleFragment consoleFragment = (WatermarkConsoleFragment) getSupportFragmentManager().findFragmentByTag("console_fragment");
+
+        assert consoleFragment != null;
+        consoleFragment.setAssociatedWatermark(watermark);
+
+        pageImage = findViewById(R.id.page_image);
+
+        TabLayout tabLayout = findViewById(R.id.tab_layout);
+        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
+            @Override
+
+            public void onTabSelected(TabLayout.Tab tab) {
+                changeWatermark(tab.getPosition());
+
+                consoleFragment.changePicker(tab.getPosition());
+            }
+
+            @Override
+            public void onTabUnselected(TabLayout.Tab tab) {}
+
+            @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/01.pdf");
         Uri PDFUri = Uri.fromFile(PDFFile);
 
-        CPDFDocument document = new CPDFDocument(this);
         CPDFDocument.PDFDocumentError error = document.open(PDFFile.getAbsolutePath());
 
-        CPDFReaderView readerView;
-        readerView = (CPDFReaderView) findViewById(R.id.pdf_view);
+        CPDFPage currentPage = document.pageAtIndex(0);
+
+        RectF pageSize = document.getPageSize(0);
+        float pageW = pageSize.right - pageSize.left;
+        float pageH = pageSize.bottom - pageSize.top;
+
+        pageImage.post(() -> {
+            int imageWidth = (int) (pageImage.getHeight() / pageH * pageW);
+            Bitmap pageBitmap = Bitmap.createBitmap(imageWidth, pageImage.getHeight(), Bitmap.Config.RGB_565);
+
+            currentPage.renderPage(pageBitmap, 0, 0, imageWidth, pageImage.getHeight(), 0xFFFFFFFF, 100, 0, true, true);
+            pageImage.setImageBitmap(pageBitmap);
+
+            pageImage.setOnDragListener(new View.OnDragListener() {
+                float currentSlope;
+
+                final float convertRate = (float) (180 / 3.141592653);
+
+                double currentRotation = 0;
+                double resultRotation = 0;
+
+                int[] location = new int[2];
+
+                @Override
+                public boolean onDrag(View view, DragEvent dragEvent) {
+
+                    if (watermark.getCurrentEvent() == 0) {
+                        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_STARTED:
+                                return true;
+                            case DragEvent.ACTION_DRAG_ENTERED:
+                                return true;
+                            case DragEvent.ACTION_DRAG_LOCATION:
+                                watermark.setX(dragEvent.getX() + xOutline - xOffset); // dragEvent.getX()
+                                watermark.setY(dragEvent.getY() + yOutline - yOffset); // dragEvent.getY()
+
+                                Log.d("DragTest", "Drag Location: (" + dragEvent.getX() + "," + dragEvent.getY() + ")");
+                                Log.d("DragTest", "Watermark Location: (" + location[0] + "," + location[1] + ")");
+                                return true;
+                            case DragEvent.ACTION_DRAG_ENDED:
+                                watermark.setVisibility(View.VISIBLE);
+                                return false;
+                        }
+                        return true;
+                    } else {
+                        float xOffset = 1.0f * watermark.getWidth() / 2;/* 1.0f * watermark.getWatermarkLayout().getWidth() / 2;  /* 控件一半宽度 */
+                        float yOffset = 1.0f * watermark.getHeight() / 2;;/*1.0f * watermark.getWatermarkLayout().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 + 控件一半高度 */
+
+                        switch (dragEvent.getAction()) {
+                            case DragEvent.ACTION_DRAG_STARTED:
+                                return true;
+                            case DragEvent.ACTION_DRAG_ENTERED:
+                                return true;
+                            case DragEvent.ACTION_DRAG_LOCATION:
+
+                                //TODO:该部分的取坐标存在冗余代码
+                                currentSlope = (dragEvent.getY() + pageImage.getTop() - centerPointY) / (dragEvent.getX() + pageImage.getLeft() - centerPointX) * -1;
+                                currentRotation = Math.atan(currentSlope) * convertRate;
+
+                                if (dragEvent.getY() + pageImage.getTop() < centerPointY && dragEvent.getX() + pageImage.getLeft() < centerPointX)
+                                    currentRotation += 180;
+
+                                if (dragEvent.getY() + pageImage.getTop() > centerPointY && dragEvent.getX() + pageImage.getLeft() < centerPointX)
+                                    currentRotation += 180;
+
+                                resultRotation = currentRotation - Math.atan(baseSlope) * convertRate;
+
+                                watermark.setRotation((float) resultRotation * -1);
+                                watermark.setRotationRadian((float) Math.atan(currentSlope));
+                                Log.d("RollTest", "Current slope: " + currentSlope + ", Result rotation: " + resultRotation + ", Current rotation: " + currentRotation);
+                                return true;
+                            case DragEvent.ACTION_DRAG_ENDED:
+                                watermark.setVisibility(View.VISIBLE);
+                                return true;
+                        }
+                    }
+                    return true;
+                }
+            });
+        });
+
 
         if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {
             error = document.open(PDFUri, "password");
@@ -56,78 +191,74 @@ public class MainActivity extends AppCompatActivity {
             Toast.makeText(this, "File failed.", Toast.LENGTH_SHORT).show();
         }
 
-        readerView.setPDFDocument(document);
-        readerView.setVerticalMode(true);
-        readerView.setDoublePageMode(false);
-
         int watermarkIndex = 0;
-        CPDFWatermark watermark = null;
+        CPDFWatermark watermarkz = null;
 
         try {
-            watermark = document.getWatermark(watermarkIndex);
-            if (watermark != null)
-                watermark.clear();
+            watermarkz = document.getWatermark(watermarkIndex);
+            if (watermarkz != null)
+                watermarkz.clear();
         } finally {
-            if (watermark != null && watermark.isValid()) {
-                watermark.release();
+            if (watermarkz != null && watermarkz.isValid()) {
+                watermarkz.release();
             }
         }
 
-        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.pdf);
-
-        CPDFImageWatermark imgWatermark = (CPDFImageWatermark)
-                document.createWatermark(CPDFWatermark.Type.WATERMARK_TYPE_IMG);
-
-        assert drawable != null;
-        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
-        Canvas canvas = new Canvas(bitmap);
-        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
-        drawable.draw(canvas);
-
-        try {
-            if (imgWatermark != null && imgWatermark.isValid()) {
-                imgWatermark.setText("RA"); //设置文本
-                imgWatermark.setFontName("Helvetica"); //设置字体
-                imgWatermark.setImage(bitmap, 100, 100);
-                imgWatermark.setTextRGBColor(ColorUtils.parseColor(new int[] { 102, 204, 255 }));
-                imgWatermark.setOpacity(0.5f);
-                imgWatermark.setRotation(0.785f);
-                imgWatermark.setFontSize(100);
-                imgWatermark.setFront(false);
-                imgWatermark.setVertalign(CPDFWatermark.Vertalign.WATERMARK_VERTALIGN_CENTER);
-                imgWatermark.setHorizalign(CPDFWatermark.Horizalign.WATERMARK_HORIZALIGN_CENTER);
-                imgWatermark.setVertOffset(0);
-                imgWatermark.setHorizOffset(0);
-                imgWatermark.setScale(0.2f);
-                imgWatermark.setPages("1,3-5");
-                imgWatermark.setFullScreen(true);
-                imgWatermark.setHorizontalSpacing(100);
-                imgWatermark.setVerticalSpacing(100);
-                imgWatermark.update();
-            }
-        } finally {
-            if (imgWatermark != null && imgWatermark.isValid()) {
-                imgWatermark.release();
-            }
-        }
+//        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.pdf);
+//
+//        CPDFImageWatermark imgWatermark = (CPDFImageWatermark)
+//                document.createWatermark(CPDFWatermark.Type.WATERMARK_TYPE_IMG);
+//
+//        assert drawable != null;
+//        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+//        Canvas canvas = new Canvas(bitmap);
+//        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+//        drawable.draw(canvas);
+//
+//        try {
+//            if (imgWatermark != null && imgWatermark.isValid()) {
+//                imgWatermark.setText("RA"); //设置文本
+//                imgWatermark.setFontName("Helvetica"); //设置字体
+//                imgWatermark.setImage(bitmap, 100, 100);
+//                imgWatermark.setTextRGBColor(ColorUtils.parseColor(new int[] { 102, 204, 255 }));
+//                imgWatermark.setOpacity(0.5f);
+//                imgWatermark.setRotation(0.785f);
+//                imgWatermark.setFontSize(100);
+//                imgWatermark.setFront(false);
+//                imgWatermark.setVertalign(CPDFWatermark.Vertalign.WATERMARK_VERTALIGN_CENTER);
+//                imgWatermark.setHorizalign(CPDFWatermark.Horizalign.WATERMARK_HORIZALIGN_CENTER);
+//                imgWatermark.setVertOffset(0);
+//                imgWatermark.setHorizOffset(0);
+//                imgWatermark.setScale(0.2f);
+//                imgWatermark.setPages("1,3-5");
+//                imgWatermark.setFullScreen(true);
+//                imgWatermark.setHorizontalSpacing(100);
+//                imgWatermark.setVerticalSpacing(100);
+//                imgWatermark.update();
+//            }
+//        } finally {
+//            if (imgWatermark != null && imgWatermark.isValid()) {
+//                imgWatermark.release();
+//            }
+//        }
 
 //        CPDFTextWatermark textWatermark = (CPDFTextWatermark)
 //                document.createWatermark(CPDFWatermark.Type.WATERMARK_TYPE_TEXT);
 //        try {
 //            if (textWatermark != null && textWatermark.isValid()) {
-//                textWatermark.setText("RA"); //设置文本
+//                textWatermark.setText("Watermark"); //设置文本
 //                textWatermark.setFontName("Helvetica"); //设置字体
-//                textWatermark.setTextRGBColor(ColorUtils.parseColor(new int[] { 102, 204, 255 }));
+//                textWatermark.setTextRGBColor(ColorUtils.parseColor(new int[] { 255, 0, 0 }));
 //                textWatermark.setOpacity(1f);
-//                textWatermark.setFontSize(100);
-//                textWatermark.setFront(false);
+//                textWatermark.setFontSize(62);
+//                textWatermark.setFront(true);
 //                textWatermark.setVertalign(CPDFWatermark.Vertalign.WATERMARK_VERTALIGN_CENTER);
 //                textWatermark.setHorizalign(CPDFWatermark.Horizalign.WATERMARK_HORIZALIGN_CENTER);
 //                textWatermark.setVertOffset(0);
 //                textWatermark.setHorizOffset(0);
 //                textWatermark.setScale(1.0f);
-//                textWatermark.setPages("1,3-5");
-//                textWatermark.setFullScreen(true);
+//                textWatermark.setPages("0-5");
+//                textWatermark.setFullScreen(false);
 //                textWatermark.setHorizontalSpacing(10);
 //                textWatermark.setVerticalSpacing(10);
 //                textWatermark.update();
@@ -138,4 +269,28 @@ public class MainActivity extends AppCompatActivity {
 //            }
 //        }
     }
+
+    @Override
+    public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
+        menuInflater.inflate(R.menu.menu_done, menu);
+    }
+
+    @Override
+    public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
+        return false;
+    }
+
+    public void changeWatermark(int type) {
+        watermark.setVisibility(View.INVISIBLE);
+        if (type == 1) {
+            watermark = findViewById(R.id.watermark_image);
+        } else {
+            watermark = findViewById(R.id.watermark_text);
+        }
+        watermark.setVisibility(View.VISIBLE);
+    }
+
+    public void refreshPageImage(Bitmap updatePageBitmap) {
+        pageImage.setImageBitmap(updatePageBitmap);
+    }
 }

+ 107 - 0
app/src/main/java/com/compdfkit/pdfviewer/customview/ImageWatermarkView.java

@@ -0,0 +1,107 @@
+package com.compdfkit.pdfviewer.customview;
+
+import android.content.ClipData;
+import android.content.ClipDescription;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.compdfkit.pdfviewer.R;
+import com.compdfkit.pdfviewer.entity.WatermarkSetting;
+
+public class ImageWatermarkView extends WatermarkView {
+    private View WatermarkLayout;
+
+    private ImageView watermarkImage;
+
+    public ImageWatermarkView(@NonNull Context context) {
+        this(context, null);
+    }
+
+    public ImageWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public ImageWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        this(context, attrs, defStyleAttr, 0);
+    }
+
+    public ImageWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        init(context, attrs);
+    }
+
+    private void init(Context context, AttributeSet attrs) {
+        currentContext = context;
+        inflater = (LayoutInflater) currentContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+        TypedArray attribute = currentContext.obtainStyledAttributes(attrs, R.styleable.WatermarkView);
+        currentView = inflater.inflate(R.layout.watermark_image_view, this, true);
+
+        watermarkImage = currentView.findViewById(R.id.image_watermark);
+        rollingHandle = currentView.findViewById(R.id.watermark_i_handle);
+
+        currentView.setOnTouchListener((view, motionEvent) -> {
+            ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
+            ClipData dragData = new ClipData(
+                    (CharSequence) view.getTag(),
+                    new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },
+                    item);
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                view.startDragAndDrop(dragData, new DragShadowBuilder(rollingHandle), null, 0);     //自定义DragShadowBuilder
+            }
+
+            currentEvent = 0;
+            return true;
+        });
+
+        setRollingHandle();
+    }
+
+    @Override
+    public void setRollingHandle() {
+        rollingHandle.setOnTouchListener(new OnTouchListener() {
+            @Override
+            public boolean onTouch(View view, MotionEvent motionEvent) {
+                ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
+                ClipData dragData = new ClipData(
+                        (CharSequence) view.getTag(),
+                        new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },
+                        item);
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                    view.startDragAndDrop(dragData, new DragShadowBuilder(rollingHandle), null, 0);     //自定义DragShadowBuilder
+                }
+
+                currentEvent = 1;
+                return true;
+            }
+        });
+    }
+
+    @Override
+    public void setWatermarkOpacity(float opacity) {
+        watermarkImage.setAlpha(opacity);
+    }
+
+    @Override
+    public void setWatermarkScale(float scale) {
+        watermarkImage.setScaleX(scale);
+        watermarkImage.setScaleY(scale);
+    }
+
+    @Override
+    public WatermarkSetting completeSetting(WatermarkSetting setting) {
+        setting.setImage(null);
+        setting.setRotation(rotationRadian);
+        return setting;
+    }
+}

+ 138 - 0
app/src/main/java/com/compdfkit/pdfviewer/customview/TextWatermarkView.java

@@ -0,0 +1,138 @@
+package com.compdfkit.pdfviewer.customview;
+
+import android.annotation.SuppressLint;
+import android.content.ClipData;
+import android.content.ClipDescription;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.TypedArray;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
+
+import com.compdfkit.pdfviewer.R;
+import com.compdfkit.pdfviewer.entity.WatermarkSetting;
+
+public class TextWatermarkView extends WatermarkView{
+    private TextView watermarkText;
+
+    private float textDefaultSize = 123;
+
+    public TextWatermarkView(@NonNull Context context) {
+        this(context, null);
+    }
+
+    public TextWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public TextWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        this(context, attrs, defStyleAttr, 0);
+    }
+
+    public TextWatermarkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        init(context, attrs);
+    }
+
+    private void init(Context context, AttributeSet attrs) {
+        currentContext = context;
+        inflater = (LayoutInflater) currentContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+        TypedArray attribute = currentContext.obtainStyledAttributes(attrs, R.styleable.WatermarkView);
+        currentView = inflater.inflate(R.layout.watermark_text_view, this, true);
+
+        watermarkText = currentView.findViewById(R.id.text_watermark);
+        rollingHandle = currentView.findViewById(R.id.watermark_t_handle);
+
+        currentView.setOnTouchListener((view, motionEvent) -> {
+            ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
+            ClipData dragData = new ClipData(
+                    (CharSequence) view.getTag(),
+                    new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },
+                    item);
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                view.startDragAndDrop(dragData, new DragShadowBuilder(rollingHandle), null, 0);     //自定义DragShadowBuilder
+            }
+
+            currentEvent = 0;
+            return true;
+        });
+
+        watermarkText.setOnClickListener(new OnClickListener() {
+            @SuppressLint("SetTextI18n")
+            @Override
+            public void onClick(View view) {
+                final EditText editText = new EditText(currentContext);
+                editText.setText(watermarkText.getText().toString());
+
+                AlertDialog.Builder inputDialog = new AlertDialog.Builder(currentContext);
+                inputDialog.setTitle("Text watermark").setView(editText);
+                inputDialog.setPositiveButton("Done", new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialogInterface, int i) {
+                        watermarkText.setText(editText.getText().toString());
+                    }
+                });
+
+                inputDialog.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialogInterface, int i) {}
+                });
+                inputDialog.show();
+            }
+        });
+
+        setRollingHandle();
+    }
+
+    @Override
+    public void setRollingHandle() {
+        rollingHandle.setOnTouchListener(new OnTouchListener() {
+            @Override
+            public boolean onTouch(View view, MotionEvent motionEvent) {
+                currentEvent = 1;
+                ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
+                ClipData dragData = new ClipData(
+                        (CharSequence) view.getTag(),
+                        new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },
+                        item);
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                    view.startDragAndDrop(dragData, new DragShadowBuilder(rollingHandle), null, 0);     //自定义DragShadowBuilder
+                }
+                return true;
+            }
+        });
+    }
+
+    @Override
+    public void setWatermarkOpacity(float opacity) {
+        watermarkText.setAlpha(opacity);
+    }
+
+    @Override
+    public void setWatermarkScale(float scale) {
+        watermarkText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textDefaultSize * scale);
+    }
+
+    @Override
+    public void setTextWatermarkColor(int color) {
+        watermarkText.setTextColor(color);
+    }
+
+    @Override
+    public WatermarkSetting completeSetting(WatermarkSetting setting) {
+        setting.setText(watermarkText.getText().toString());
+        setting.setRotation(rotationRadian);
+        return setting;
+    }
+}

+ 40 - 27
app/src/main/java/com/compdfkit/pdfviewer/customview/WatermarkView.java

@@ -1,27 +1,44 @@
 package com.compdfkit.pdfviewer.customview;
 
+import android.annotation.SuppressLint;
+import android.content.ClipData;
+import android.content.ClipDescription;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.res.TypedArray;
+import android.os.Build;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
+import android.widget.EditText;
 import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
 import androidx.constraintlayout.widget.ConstraintLayout;
 
 import com.compdfkit.pdfviewer.R;
+import com.compdfkit.pdfviewer.entity.WatermarkSetting;
 
 public class WatermarkView extends ConstraintLayout {
-    private Context currentContext;
-    private LayoutInflater inflater;
-    private View currentView;
+    protected Context currentContext;
+    protected LayoutInflater inflater;
+    protected View currentView;
+    protected ImageButton rollingHandle;
 
-    private ImageButton rollingHandle;
+    protected float rotationRadian = 0;
 
-    private boolean imageMode = false;
+    protected static int DRAG_EVENT = 0;
+    protected static int ROLL_EVENT = 1;
+
+    //TODO:Try to change the event select.
+    protected int currentEvent = 0;
 
     public WatermarkView(@NonNull Context context) {
         this(context, null);
@@ -37,33 +54,29 @@ public class WatermarkView extends ConstraintLayout {
 
     public WatermarkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        init(context, attrs);
     }
 
-    private void init(Context context, AttributeSet attrs) {
-        currentContext = context;
-        inflater = (LayoutInflater) currentContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+    public void setRollingHandle() {}
+
+    public void setRotationRadian(float rotationRadian) {
+        this.rotationRadian = rotationRadian;
+    }
+
+    public float getRotationRadian() {
+        return rotationRadian;
+    }
+
+    public void setWatermarkOpacity(float opacity) {}
+
+    public void setWatermarkScale(float scale) {}
 
-        TypedArray attribute = currentContext.obtainStyledAttributes(attrs, R.styleable.WatermarkView);
-        imageMode = attribute.getBoolean(R.styleable.WatermarkView_image_mode, false);
+    public void setTextWatermarkColor(int color) {}
 
-        setImageMode(imageMode);
+    public WatermarkSetting completeSetting(WatermarkSetting setting) {
+        return setting;
     }
 
-    public void setImageMode(@NonNull Boolean isImageMode) {
-        if (isImageMode) {
-            currentView = inflater.inflate(R.layout.watermark_image_view, this, true);
-        } else {
-            currentView = inflater.inflate(R.layout.watermark_text_view, this, true);
-        }
-        Log.d("WatermarkView", "Current watermark mode: " + imageMode);
-        rollingHandle = currentView.findViewById(R.id.watermark_handle);
-
-        rollingHandle.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View view) {
-
-            }
-        });
+    public int getCurrentEvent() {
+        return currentEvent;
     }
 }

+ 160 - 0
app/src/main/java/com/compdfkit/pdfviewer/entity/WatermarkSetting.java

@@ -0,0 +1,160 @@
+package com.compdfkit.pdfviewer.entity;
+
+import android.graphics.Bitmap;
+
+public class WatermarkSetting {
+    private Bitmap image;
+    private int iWidth;
+    private int iHeight;
+
+    private String fontName;
+    private float fontSize;
+    private boolean front;
+    private boolean fullScreen;
+    private float horizOffset;
+    private float horizontalSpacing;
+    private float opacity;
+    private String pages;
+    private float rotation;
+    private float scale;
+    private String text;
+    private int textRGBColor;
+    private float verticalSpacing;
+    private float vertOffset;
+
+    public Bitmap getImage() {
+        return image;
+    }
+
+    public void setImage(Bitmap image) {
+        this.image = image;
+    }
+
+    public int getiWidth() {
+        return iWidth;
+    }
+
+    public void setiWidth(int iWidth) {
+        this.iWidth = iWidth;
+    }
+
+    public int getiHeight() {
+        return iHeight;
+    }
+
+    public void setiHeight(int iHeight) {
+        this.iHeight = iHeight;
+    }
+
+    public String getFontName() {
+        return fontName;
+    }
+
+    public void setFontName(String fontName) {
+        this.fontName = fontName;
+    }
+
+    public float getFontSize() {
+        return fontSize;
+    }
+
+    public void setFontSize(float fontSize) {
+        this.fontSize = fontSize;
+    }
+
+    public boolean isFront() {
+        return front;
+    }
+
+    public void setFront(boolean front) {
+        this.front = front;
+    }
+
+    public boolean isFullScreen() {
+        return fullScreen;
+    }
+
+    public void setFullScreen(boolean fullScreen) {
+        this.fullScreen = fullScreen;
+    }
+
+    public float getHorizOffset() {
+        return horizOffset;
+    }
+
+    public void setHorizOffset(float horizOffset) {
+        this.horizOffset = horizOffset;
+    }
+
+    public float getHorizontalSpacing() {
+        return horizontalSpacing;
+    }
+
+    public void setHorizontalSpacing(float horizontalSpacing) {
+        this.horizontalSpacing = horizontalSpacing;
+    }
+
+    public float getOpacity() {
+        return opacity;
+    }
+
+    public void setOpacity(float opacity) {
+        this.opacity = opacity;
+    }
+
+    public String getPages() {
+        return pages;
+    }
+
+    public void setPages(String pages) {
+        this.pages = pages;
+    }
+
+    public float getRotation() {
+        return rotation;
+    }
+
+    public void setRotation(float rotation) {
+        this.rotation = rotation;
+    }
+
+    public float getScale() {
+        return scale;
+    }
+
+    public void setScale(float scale) {
+        this.scale = scale;
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+
+    public int getTextRGBColor() {
+        return textRGBColor;
+    }
+
+    public void setTextRGBColor(int textRGBColor) {
+        this.textRGBColor = textRGBColor;
+    }
+
+    public float getVerticalSpacing() {
+        return verticalSpacing;
+    }
+
+    public void setVerticalSpacing(float verticalSpacing) {
+        this.verticalSpacing = verticalSpacing;
+    }
+
+    public float getVertOffset() {
+        return vertOffset;
+    }
+
+    public void setVertOffset(float vertOffset) {
+        this.vertOffset = vertOffset;
+    }
+}

+ 129 - 18
app/src/main/java/com/compdfkit/pdfviewer/fragments/WatermarkConsoleFragment.java

@@ -1,21 +1,41 @@
 package com.compdfkit.pdfviewer.fragments;
 
+import android.annotation.SuppressLint;
 import android.os.Bundle;
 
 import androidx.fragment.app.Fragment;
 
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.CompoundButton;
+import android.widget.ImageView;
 import android.widget.SeekBar;
 import android.widget.Spinner;
 import android.view.ViewGroup;
 import android.widget.CheckBox;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.compdfkit.pdfviewer.R;
+import com.compdfkit.pdfviewer.customview.WatermarkView;
+import com.compdfkit.pdfviewer.entity.WatermarkSetting;
 import com.google.android.material.textfield.TextInputEditText;
 
+import java.util.Objects;
+
 public class WatermarkConsoleFragment extends Fragment {
+    private int mode;
+
+    private int tWatermarkOpacity = 50;
+    private int tWatermarkSize = 50;
+
+    private int iWatermarkOpacity = 50;
+    private int iWatermarkSize = 50;
+
+    private WatermarkSetting setting = new WatermarkSetting();
+
+    private WatermarkView associatedWatermark = null;
 
     private View colorPicker;
     private View imagePicker;
@@ -33,11 +53,8 @@ public class WatermarkConsoleFragment extends Fragment {
     private TextInputEditText hSpaceEdit;
     private TextInputEditText vSpaceEdit;
 
-    private static final String ARG_PARAM1 = "param1";
-    private static final String ARG_PARAM2 = "param2";
-
-    private String mParam1;
-    private String mParam2;
+    private int[] colorpickers = { R.id.color_1, R.id.color_2, R.id.color_3, R.id.color_4, R.id.color_5, R.id.color_6, R.id.color_7 };
+    private int[] colors = { 0xFFFF0000, 0xFFFF6600, 0xFFFFDD00, 0xFF00FF33, 0xFF00FFFF, 0xFF0022FF, 0xFF8800FF };
 
     public WatermarkConsoleFragment() {
         // Required empty public constructor
@@ -46,8 +63,6 @@ public class WatermarkConsoleFragment extends Fragment {
     public static WatermarkConsoleFragment newInstance(String param1, String param2) {
         WatermarkConsoleFragment fragment = new WatermarkConsoleFragment();
         Bundle args = new Bundle();
-        args.putString(ARG_PARAM1, param1);
-        args.putString(ARG_PARAM2, param2);
         fragment.setArguments(args);
         return fragment;
     }
@@ -55,40 +70,136 @@ public class WatermarkConsoleFragment extends Fragment {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        if (getArguments() != null) {
-            mParam1 = getArguments().getString(ARG_PARAM1);
-            mParam2 = getArguments().getString(ARG_PARAM2);
-        }
     }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
         View returnView = inflater.inflate(R.layout.fragment_watermark_console, container, false);
-        InitViews(returnView);
+        initViews(returnView);
         return returnView;
     }
 
-    private void InitViews(View returnView) {
+    private void initViews(View returnView) {
         colorPicker = returnView.findViewById(R.id.color_picker);
         imagePicker = returnView.findViewById(R.id.image_picker);
 
+        opacityText = returnView.findViewById(R.id.opacity_text);
         opacitySlider = returnView.findViewById(R.id.opacity_slider);
-        sizeSlider = returnView.findViewById(R.id.size_slider);
+        initOpacitySlider();
 
-        opacityText = returnView.findViewById(R.id.opacity_text);
         sizeText = returnView.findViewById(R.id.size_text);
+        sizeSlider = returnView.findViewById(R.id.size_slider);
+        initSizeSlider();
 
         rangeSpinner = returnView.findViewById(R.id.page_range_spinner);
+        initRangeSpinner();
 
         fullScreenCheck = returnView.findViewById(R.id.full_screen_checkbox);
+        initFullScreenCheck();
+
+        initColorPicker(returnView);
 
         hSpaceEdit = returnView.findViewById(R.id.horizontal_space);
         vSpaceEdit = returnView.findViewById(R.id.vertical_space);
     }
 
-    public void ChangePicker(int mode) {
-        colorPicker.setVisibility(mode == 0 ? View.VISIBLE : View.INVISIBLE);
-        imagePicker.setVisibility(mode == 0 ? View.INVISIBLE : View.VISIBLE);
+    private void initColorPicker(View returnView) {
+        for (int i = 0; i < 7; i++) {
+            ImageView tempColor = returnView.findViewById(colorpickers[i]);
+
+            int tempI = i;
+            tempColor.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    associatedWatermark.setTextWatermarkColor(colors[tempI]);
+                }
+            });
+        }
+    }
+
+    private void initOpacitySlider() {
+        opacitySlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            @SuppressLint("SetTextI18n")
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
+                if (mode == 0)
+                    tWatermarkOpacity = i;
+                else
+                    iWatermarkOpacity = i;
+
+                opacityText.setText(i + "%");
+                setting.setOpacity(1.0f * i / 100);
+                associatedWatermark.setWatermarkOpacity(1.0f * i / 100);
+            }
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {}
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {}
+        });
+    }
+
+    private void initSizeSlider() {
+        sizeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            //TODO: The text's size and opacity should be independent.
+            @SuppressLint("SetTextI18n")
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
+                if (mode == 0)
+                    tWatermarkSize = i;
+                else
+                    iWatermarkSize = i;
+
+                i = i + 50;
+                sizeText.setText(i + "%");
+                setting.setScale(1.0f * i / 100);
+                associatedWatermark.setWatermarkScale(1.0f * i / 100);
+            }
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {}
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {}
+        });
+    }
+
+    private void initRangeSpinner() {
+        String[] mItems = { "All Pages", "Odd Pages", "Even Pages", "Custom Range" };
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, mItems);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        rangeSpinner.setAdapter(adapter);
+
+    }
+
+    private void initFullScreenCheck() {
+        fullScreenCheck.setOnCheckedChangeListener((compoundButton, b) -> {
+            boolean isFullScreen = fullScreenCheck.isChecked();
+
+            opacitySlider.setEnabled(!isFullScreen);
+            sizeSlider.setEnabled(!isFullScreen);
+            rangeSpinner.setEnabled(!isFullScreen);
+
+            hSpaceEdit.setEnabled(isFullScreen);
+            vSpaceEdit.setEnabled(isFullScreen);
+        });
+    }
+
+    public void setAssociatedWatermark(WatermarkView watermark) {
+        this.associatedWatermark = watermark;
+    }
+
+    public void changePicker(int mode) {
+        this.mode = mode;
+        colorPicker.setVisibility(this.mode == 0 ? View.VISIBLE : View.INVISIBLE);
+        imagePicker.setVisibility(this.mode == 0 ? View.INVISIBLE : View.VISIBLE);
+
+        opacitySlider.setProgress(this.mode == 0 ? tWatermarkOpacity : iWatermarkOpacity);
+        sizeSlider.setProgress(this.mode == 0 ? tWatermarkSize : iWatermarkSize);
+    }
+
+    public WatermarkSetting getWatermarkSetting() {
+        setting.setFullScreen(fullScreenCheck.isChecked());
+        setting.setHorizontalSpacing(Float.parseFloat(Objects.requireNonNull(hSpaceEdit.getText()).toString()));
+        setting.setVerticalSpacing(Float.parseFloat(Objects.requireNonNull(vSpaceEdit.getText()).toString()));
+        return setting;
     }
 }

+ 5 - 0
app/src/main/res/drawable/ic_baseline_done_24.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#FFFFFF"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
+</vector>

+ 25 - 10
app/src/main/res/layout/activity_main.xml

@@ -51,29 +51,44 @@
 
     </com.google.android.material.tabs.TabLayout>
 
-    <com.compdfkit.ui.reader.CPDFReaderView
-        android:id="@+id/pdf_view"
-        android:layout_width="match_parent"
+    <ImageView
+        android:id="@+id/page_image"
+        android:layout_width="wrap_content"
         android:layout_height="0dp"
         app:layout_constraintTop_toBottomOf="@id/tab_layout"
         app:layout_constraintBottom_toTopOf="@id/console_view"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent" />
+        app:layout_constraintStart_toStartOf="parent"
+        android:contentDescription="@string/page_image" />
 
-    <com.compdfkit.pdfviewer.customview.WatermarkView
+    <com.compdfkit.pdfviewer.customview.TextWatermarkView
+        android:id="@+id/watermark_text"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        app:layout_constraintBottom_toTopOf="@id/console_view"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/tab_layout"
-        app:image_mode="true" />
+        app:layout_constraintTop_toTopOf="@id/page_image"
+        app:layout_constraintBottom_toBottomOf="@id/page_image"
+        app:layout_constraintEnd_toEndOf="@id/page_image"
+        app:layout_constraintStart_toStartOf="@id/page_image"
+        app:image_mode="false" />
+
+    <com.compdfkit.pdfviewer.customview.ImageWatermarkView
+        android:id="@+id/watermark_image"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:visibility="invisible"
+        app:layout_constraintTop_toTopOf="@id/page_image"
+        app:layout_constraintBottom_toBottomOf="@id/page_image"
+        app:layout_constraintEnd_toEndOf="@id/page_image"
+        app:layout_constraintStart_toStartOf="@id/page_image"
+        app:image_mode="false" />
 
     <androidx.fragment.app.FragmentContainerView
         android:name="com.compdfkit.pdfviewer.fragments.WatermarkConsoleFragment"
         android:id="@+id/console_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:elevation="4dp"
+        android:tag="console_fragment"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintEnd_toEndOf="parent" />

+ 7 - 3
app/src/main/res/layout/fragment_watermark_console.xml

@@ -3,6 +3,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:background="@color/white"
     android:padding="10dp"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     tools:context=".fragments.WatermarkConsoleFragment">
@@ -153,7 +154,7 @@
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:padding="3dp"
-                android:text="/storage/emulated/0/tutu.png"
+                android:text="@string/default_image"
                 app:layout_constraintTop_toTopOf="@id/image_select_text"
                 app:layout_constraintBottom_toBottomOf="@id/image_select_text"
                 app:layout_constraintStart_toEndOf="@id/image_select_text"
@@ -237,7 +238,7 @@
         android:id="@+id/size_text"
         android:layout_width="40dp"
         android:layout_height="wrap_content"
-        android:text="@string/default_opacity"
+        android:text="@string/default_scale"
         app:layout_constraintTop_toTopOf="@id/size_icon"
         app:layout_constraintBottom_toBottomOf="@id/size_icon"
         app:layout_constraintEnd_toEndOf="parent"
@@ -256,10 +257,11 @@
         app:layout_constraintBottom_toTopOf="@id/full_screen_checkbox"
         app:layout_constraintStart_toStartOf="parent" />
 
-    <Spinner
+    <androidx.appcompat.widget.AppCompatSpinner
         android:id="@+id/page_range_spinner"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:spinnerMode="dropdown"
         app:layout_constraintBottom_toBottomOf="@id/page_range_text"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintTop_toTopOf="@id/page_range_text"
@@ -293,6 +295,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:hint="@string/default_space"
+            android:enabled="false"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toStartOf="@id/horizontal_space_mm"
             app:layout_constraintStart_toStartOf="parent"
@@ -314,6 +317,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:hint="@string/default_space"
+            android:enabled="false"
             app:layout_constraintBottom_toBottomOf="@id/horizontal_space"
             app:layout_constraintEnd_toStartOf="@id/vertical_space_mm"
             app:layout_constraintStart_toEndOf="@id/horizontal_space_mm"

+ 25 - 13
app/src/main/res/layout/watermark_image_view.xml

@@ -4,30 +4,42 @@
     android:layout_height="match_parent"
     xmlns:app="http://schemas.android.com/apk/res-auto">
 
-    <ImageView
-        android:id="@+id/image_watermark"
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/watermark_container_i"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:padding="15dp"
         android:background="@drawable/watermark_shape"
-        android:src="@drawable/pdf"
-        android:visibility="visible"
-        app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
-        android:contentDescription="@string/watermark_image" />
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" >
+
+        <ImageView
+            android:id="@+id/image_watermark"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="15dp"
+            android:src="@drawable/pdf"
+            android:alpha="0.5"
+            android:visibility="visible"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            android:contentDescription="@string/watermark_image" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
 
     <ImageButton
-        android:id="@+id/watermark_handle"
+        android:id="@+id/watermark_i_handle"
         android:layout_width="20dp"
         android:layout_height="20dp"
         app:srcCompat="@drawable/ic_white_roll_15"
         android:background="@drawable/watermark_handle_shape"
-        app:layout_constraintTop_toBottomOf="@id/image_watermark"
-        app:layout_constraintBottom_toBottomOf="@+id/image_watermark"
-        app:layout_constraintStart_toEndOf="@+id/image_watermark"
-        app:layout_constraintEnd_toEndOf="@id/image_watermark"
+        app:layout_constraintTop_toBottomOf="@+id/watermark_container_i"
+        app:layout_constraintBottom_toBottomOf="@+id/watermark_container_i"
+        app:layout_constraintStart_toEndOf="@+id/watermark_container_i"
+        app:layout_constraintEnd_toEndOf="@+id/watermark_container_i"
         android:contentDescription="@string/watermark_handle" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 30 - 16
app/src/main/res/layout/watermark_text_view.xml

@@ -2,33 +2,47 @@
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools">
 
-    <TextView
-        android:id="@+id/text_watermark"
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/watermark_t_container"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:padding="15dp"
-        android:text="@string/watermark"
         android:background="@drawable/watermark_shape"
-        android:textColor="#88FF0000"
-        android:textSize="35sp"
-        android:visibility="visible"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent" >
+
+        <TextView
+            android:id="@+id/text_watermark"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="15dp"
+            android:text="@string/watermark"
+            android:textColor="#FF0000"
+            android:textSize="35sp"
+            android:visibility="visible"
+            android:alpha="0.5"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
 
     <ImageButton
-        android:id="@+id/watermark_handle"
+        android:id="@+id/watermark_t_handle"
         android:layout_width="20dp"
         android:layout_height="20dp"
-        app:srcCompat="@drawable/ic_white_roll_15"
         android:background="@drawable/watermark_handle_shape"
-        app:layout_constraintTop_toBottomOf="@id/text_watermark"
-        app:layout_constraintBottom_toBottomOf="@+id/text_watermark"
-        app:layout_constraintStart_toEndOf="@+id/text_watermark"
-        app:layout_constraintEnd_toEndOf="@id/text_watermark"
-        android:contentDescription="@string/watermark_handle" />
+        android:contentDescription="@string/watermark_handle"
+        app:layout_constraintBottom_toBottomOf="@+id/watermark_t_container"
+        app:layout_constraintEnd_toEndOf="@+id/watermark_t_container"
+        app:layout_constraintStart_toEndOf="@+id/watermark_t_container"
+        app:layout_constraintTop_toBottomOf="@+id/watermark_t_container"
+        app:srcCompat="@drawable/ic_white_roll_15"
+        tools:ignore="TouchTargetSizeCheck" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 105 - 0
app/src/main/res/layout/watermark_view.xml

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout 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:app="http://schemas.android.com/apk/res-auto">
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/watermark_t"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" >
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/watermark_t_container"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@drawable/watermark_shape"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" >
+            <TextView
+                android:id="@+id/text_watermark"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:padding="15dp"
+                android:text="@string/watermark"
+                android:textColor="#FF0000"
+                android:textSize="35sp"
+                android:visibility="visible"
+                android:alpha="0.5"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent" />
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
+        <ImageButton
+            android:id="@+id/watermark_t_handle"
+            android:layout_width="20dp"
+            android:layout_height="20dp"
+            android:background="@drawable/watermark_handle_shape"
+            android:contentDescription="@string/watermark_handle"
+            app:layout_constraintBottom_toBottomOf="@+id/watermark_t_container"
+            app:layout_constraintEnd_toEndOf="@+id/watermark_t_container"
+            app:layout_constraintStart_toEndOf="@+id/watermark_t_container"
+            app:layout_constraintTop_toBottomOf="@+id/watermark_t_container"
+            app:srcCompat="@drawable/ic_white_roll_15"
+            tools:ignore="TouchTargetSizeCheck" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/watermark_i"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        android:visibility="invisible">
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/watermark_i_container"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@drawable/watermark_shape"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" >
+            <ImageView
+                android:id="@+id/image_watermark"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:padding="15dp"
+                android:src="@drawable/pdf"
+                android:alpha="0.5"
+                android:visibility="visible"
+                app:layout_constraintTop_toTopOf="parent"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintEnd_toEndOf="parent"
+                android:contentDescription="@string/watermark_image" />
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
+        <ImageButton
+            android:id="@+id/watermark_i_handle"
+            android:layout_width="20dp"
+            android:layout_height="20dp"
+            app:srcCompat="@drawable/ic_white_roll_15"
+            android:background="@drawable/watermark_handle_shape"
+            app:layout_constraintTop_toBottomOf="@+id/watermark_i_container"
+            app:layout_constraintBottom_toBottomOf="@+id/watermark_i_container"
+            app:layout_constraintStart_toEndOf="@+id/watermark_i_container"
+            app:layout_constraintEnd_toEndOf="@+id/watermark_i_container"
+            android:contentDescription="@string/watermark_handle" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 10 - 0
app/src/main/res/menu/menu_done.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <item
+        android:id="@+id/done"
+        android:icon="@drawable/ic_baseline_done_24"
+        android:title="@string/done"
+        app:showAsAction="always"/>
+</menu>

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -7,10 +7,14 @@
     <string name="opacity_icon">Opacity icon</string>
     <string name="full_screen">Full screen</string>
     <string name="default_opacity">50%</string>
+    <string name="default_scale">100%</string>
     <string name="page_range">Page Range</string>
     <string name="mm">mm</string>
     <string name="default_space">100</string>
     <string name="watermark_image">watermark image</string>
     <string name="watermark">Watermark</string>
     <string name="watermark_handle">Watermark Handle</string>
+    <string name="default_image">Default image</string>
+    <string name="done">Done</string>
+    <string name="page_image">Page Image</string>
 </resources>