Browse Source

ComPDFKit Tools(Android) - 1.优化自定义View显示效果 2.新增部分自定义View使用注释

liuxiaolong 1 year ago
parent
commit
519ce7af69

+ 74 - 65
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfview/CPDFReaderView.java

@@ -11,25 +11,62 @@ package com.compdfkit.tools.pdfview;
 
 import android.content.Context;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
 import android.util.AttributeSet;
-import android.widget.FrameLayout;
 import android.widget.RelativeLayout;
 
+import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-import androidx.constraintlayout.widget.ConstraintLayout;
 
-import com.bumptech.glide.request.target.SimpleTarget;
-import com.bumptech.glide.request.transition.Transition;
 import com.compdfkit.core.document.CPDFDocument;
 import com.compdfkit.tools.R;
-import com.compdfkit.tools.utils.glide.CPDFImageLoad;
-import com.compdfkit.tools.utils.glide.pdf.CGlidePDFUrl;
+import com.compdfkit.tools.pdfview.view.CPDFSliderBarView;
 import com.compdfkit.ui.reader.IReaderViewCallback;
 import com.compdfkit.ui.widget.CPDFSlideBar;
 
 
+/**
+ * compdfkit sdk CPDFReaderView ctrl view
+ * ︳--------------------------------︳
+ * ︳                      |---------︳
+ * ︳                      |sliderbar︳
+ * ︳                      |---------︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳         pdfReaderView          ︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳                                ︳
+ * ︳--------------------------------︳
+ *
+ * step 1:
+ * Use CPDFReaderView in xml layout
+ * <com.compdfkit.tools.pdfview.CPDFReaderView
+ *         android:id="@+id/pdf_reader_view"
+ *         android:layout_width="match_parent"
+ *         android:layout_height="0dp"
+ *         app:tools_enable_slider_bar="true"
+ *         app:tools_slider_bar_position="right"
+ *         app:tools_slider_bar_icon="@drawable/tools_ic_pdf_slider_bar"
+ *         />
+ *
+ * step 2:
+ * open pdf file
+ * use {@link CPDFReaderView#openPdfFile(String pdfFilePath)}
+ *
+ * Congratulations you have completed the pdf file display!!!
+ *
+ * custom attributes:
+ * app:tools_enable_slider_bar="true|false" : show or hide slider bar
+ * app:tools_slider_bar_position="left|right" : slider bar show position
+ * app:tools_slider_bar_icon="@drawable/xxx" : slider bar icon res id
+ * app:tools_slider_bar_thumbnail_width="120dp" : The width of the PDF thumbnail view displayed while sliding the SliderBar.
+ * app:tools_slider_bar_thumbnail_hei="200dp" : The height of the PDF thumbnail view displayed while sliding the SliderBar.
+ *
+ */
 public class CPDFReaderView extends RelativeLayout implements IReaderViewCallback {
 
     private com.compdfkit.ui.reader.CPDFReaderView cPdfReaderView;
@@ -43,6 +80,9 @@ public class CPDFReaderView extends RelativeLayout implements IReaderViewCallbac
     private int sliderBarThumbnailWidth = 314;
     private int sliderBarThumbnailHeight = 444;
 
+    @DrawableRes
+    private int sliderBarIconResId = R.drawable.tools_ic_pdf_slider_bar;
+
     public CPDFReaderView(@NonNull Context context) {
         this(context, null);
     }
@@ -59,19 +99,25 @@ public class CPDFReaderView extends RelativeLayout implements IReaderViewCallbac
 
 
     private void initAttr(Context context, AttributeSet attributeSet){
-        TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.Tools_CPDFReaderView);
-        if (typedArray != null) {
-            enableSliderBar = typedArray.getBoolean(R.styleable.Tools_CPDFReaderView_tools_enable_slider_bar, true);
-            int sliderBarPositionEnum = typedArray.getInt(R.styleable.Tools_CPDFReaderView_tools_slider_bar_position, 1);
-            if (sliderBarPositionEnum == 0){
-                slideBarPosition = CPDFSlideBar.SlideBarPosition.LEFT;
-            }else {
-                slideBarPosition = CPDFSlideBar.SlideBarPosition.RIGHT;
+        try {
+            TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.CPDFReaderView);
+            if (typedArray != null) {
+                enableSliderBar = typedArray.getBoolean(R.styleable.CPDFReaderView_tools_enable_slider_bar, true);
+                int sliderBarPositionEnum = typedArray.getInt(R.styleable.CPDFReaderView_tools_slider_bar_position, 1);
+                if (sliderBarPositionEnum == 0){
+                    slideBarPosition = CPDFSlideBar.SlideBarPosition.LEFT;
+                }else {
+                    slideBarPosition = CPDFSlideBar.SlideBarPosition.RIGHT;
+                }
+                sliderBarThumbnailWidth = typedArray.getDimensionPixelOffset(R.styleable.CPDFReaderView_tools_slider_bar_thumbnail_width, 314);
+                sliderBarThumbnailHeight = typedArray.getDimensionPixelOffset(R.styleable.CPDFReaderView_tools_slider_bar_thumbnail_height, 444);
+                sliderBarIconResId = typedArray.getResourceId(R.styleable.CPDFReaderView_tools_slider_bar_icon, R.drawable.tools_ic_pdf_slider_bar);
+                typedArray.recycle();
             }
-            sliderBarThumbnailWidth = typedArray.getDimensionPixelOffset(R.styleable.Tools_CPDFReaderView_tools_slider_bar_thumbnail_width, 314);
-            sliderBarThumbnailHeight = typedArray.getDimensionPixelOffset(R.styleable.Tools_CPDFReaderView_tools_slider_bar_thumbnail_height, 444);
+        }catch (Exception e){
 
         }
+
     }
 
 
@@ -144,61 +190,24 @@ public class CPDFReaderView extends RelativeLayout implements IReaderViewCallbac
     }
 
 
+
     private void initCPDFSliderBar() {
         if (!enableSliderBar){
             return;
         }
-        slideBar = new CPDFSlideBar(getContext());
+        CPDFSliderBarView cpdfSliderBarView = new CPDFSliderBarView(getContext());
+        cpdfSliderBarView.bindCPdfReaderView(this);
+        cpdfSliderBarView.initSliderBar(slideBarPosition, sliderBarThumbnailWidth, sliderBarThumbnailHeight);
+        cpdfSliderBarView.setSlideBarBitmap(sliderBarIconResId);
+        setSliderBar(cpdfSliderBarView);
+    }
+
+    public void setSliderBar(CPDFSlideBar cpdfSlideBar){
+        enableSliderBar = true;
         LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
+        slideBar = cpdfSlideBar;
         slideBar.setLayoutParams(layoutParams);
         addView(slideBar);
-        int count = cPdfReaderView.getPDFDocument().getPageCount();
-        slideBar.setSlideBarBitmap(R.drawable.tools_ic_pdf_slider_bar_thumbnail);
-        slideBar.setDefaultThumbnailSize(sliderBarThumbnailWidth, sliderBarThumbnailHeight);
-        slideBar.setPageCount(count);
-        slideBar.setSlideBarPosition(slideBarPosition);
-        slideBar.setOnScrollToPageListener(new CPDFSlideBar.OnScrollToPageListener() {
-            int currentScrollPageIndex = -1;
-
-            @Override
-            public void onScrollBegin(int pageIndex) {
-                cPdfReaderView.removeAllAnnotFocus();
-                refreshBitmap(pageIndex);
-            }
-
-            @Override
-            public void onScroll(int i) {
-
-            }
-
-            @Override
-            public void onScrollEnd(int pageIndex) {
-                currentScrollPageIndex = -1;
-                cPdfReaderView.setDisplayPageIndex(pageIndex);
-
-            }
-
-            @Override
-            public void onScrollToPage(int pageIndex) {
-                refreshBitmap(pageIndex);
-            }
-
-            private void refreshBitmap(int pageIndex) {
-                if (currentScrollPageIndex != pageIndex){
-                    currentScrollPageIndex = pageIndex;
-                    CPDFImageLoad.loadPdfPageImage(getContext(),
-                            new CGlidePDFUrl(cPdfReaderView.getPDFDocument(), currentScrollPageIndex, sliderBarThumbnailWidth, sliderBarThumbnailHeight),
-                            cPdfReaderView.getPDFDocument().getAbsolutePath(),
-                            false, false, new SimpleTarget<Bitmap>(sliderBarThumbnailWidth, sliderBarThumbnailHeight) {
-                                @Override
-                                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
-                                    slideBar.setThumbnailBitmap(resource);
-                                }
-                            }
-                    );
-                }
-            }
-        });
 
     }
 }

+ 107 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfview/view/CPDFSliderBarView.java

@@ -0,0 +1,107 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfview.view;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.util.AttributeSet;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.bumptech.glide.request.target.SimpleTarget;
+import com.bumptech.glide.request.transition.Transition;
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.pdfview.CPDFReaderView;
+import com.compdfkit.tools.utils.glide.CPDFImageLoad;
+import com.compdfkit.tools.utils.glide.pdf.CGlidePDFUrl;
+import com.compdfkit.ui.widget.CPDFSlideBar;
+
+
+public class CPDFSliderBarView extends CPDFSlideBar implements CPDFSlideBar.OnScrollToPageListener {
+
+    int currentScrollPageIndex = -1;
+
+    private int sliderBarThumbnailWidth = 314;
+    private int sliderBarThumbnailHeight = 444;
+
+    private CPDFReaderView cpdfReaderView;
+
+    public CPDFSliderBarView(Context context) {
+        this(context, null);
+    }
+
+    public CPDFSliderBarView(Context context, @Nullable AttributeSet attributeSet) {
+        this(context, attributeSet, 0);
+    }
+
+    public CPDFSliderBarView(Context context, @Nullable AttributeSet attributeSet, int i) {
+        super(context, attributeSet, i);
+        setOnScrollToPageListener(this);
+    }
+
+
+    public void bindCPdfReaderView(CPDFReaderView cpdfReaderView) {
+        this.cpdfReaderView = cpdfReaderView;
+        if (cpdfReaderView.getCPdfReaderView().getPDFDocument() != null) {
+            setPageCount(cpdfReaderView.getCPdfReaderView().getPDFDocument().getPageCount());
+        }
+    }
+
+    public void initSliderBar(CPDFSlideBar.SlideBarPosition position, int thumbnailWidth, int thumbnailHeight){
+        sliderBarThumbnailWidth = thumbnailWidth;
+        sliderBarThumbnailHeight = thumbnailHeight;
+        setDefaultThumbnailSize(sliderBarThumbnailWidth, sliderBarThumbnailHeight);
+        setSlideBarBitmap(R.drawable.tools_ic_pdf_slider_bar);
+        setSlideBarPosition(position);
+    }
+
+
+
+    @Override
+    public void onScrollBegin(int pageIndex) {
+        if (cpdfReaderView != null) {
+            cpdfReaderView.getCPdfReaderView().removeAllAnnotFocus();
+        }
+    }
+
+    @Override
+    public void onScroll(int pageIndex) {
+
+    }
+
+    @Override
+    public void onScrollEnd(int pageIndex) {
+        currentScrollPageIndex = -1;
+        cpdfReaderView.getCPdfReaderView().setDisplayPageIndex(pageIndex);
+    }
+
+    @Override
+    public void onScrollToPage(int pageIndex) {
+        refreshDocumentPageThumbnail(pageIndex);
+    }
+
+
+    private void refreshDocumentPageThumbnail(int pageIndex) {
+        if (currentScrollPageIndex != pageIndex){
+            currentScrollPageIndex = pageIndex;
+            CPDFImageLoad.loadPdfPageImage(getContext(),
+                    new CGlidePDFUrl(cpdfReaderView.getCPdfReaderView().getPDFDocument(), currentScrollPageIndex, sliderBarThumbnailWidth, sliderBarThumbnailHeight),
+                    cpdfReaderView.getCPdfReaderView().getPDFDocument().getAbsolutePath(),
+                    false, false, new SimpleTarget<Bitmap>(sliderBarThumbnailWidth, sliderBarThumbnailHeight) {
+                        @Override
+                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+                            setThumbnailBitmap(resource);
+                        }
+                    }
+            );
+        }
+    }
+}

+ 53 - 48
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfview/CPDFToolBar.java

@@ -7,37 +7,69 @@
  * This notice may not be removed from this file.
  */
 
-package com.compdfkit.tools.pdfview;
+package com.compdfkit.tools.pdfview.view;
 
 
 import android.content.Context;
-import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.util.TypedValue;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.FrameLayout;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-import androidx.appcompat.content.res.AppCompatResources;
 import androidx.appcompat.widget.AppCompatImageView;
 import androidx.appcompat.widget.AppCompatTextView;
-import androidx.core.view.ViewCompat;
 
 import com.compdfkit.tools.R;
-import com.google.android.material.shape.MaterialShapeDrawable;
+import com.compdfkit.tools.utils.viewutils.ViewUtils;
 
+
+/**
+ * pdf ui tool bar
+ * ︳------------------------------------------------︳
+ * ︳                 title     icon1  icon2 icon3   ︳
+ * ︳------------------------------------------------︳
+ * icon1: searchIcon
+ * icon2: boTaIcon
+ * icon3: moreIcon
+ *
+ * use samples:
+ * <com.compdfkit.tools.pdfview.view.CPDFToolBar
+ *     android:id="@+id/pdf_tool_bar"
+ *     android:layout_width="match_parent"
+ *     android:layout_height="?android:attr/actionBarSize"
+ *     app:tools_toolbar_title="@string/viewer_toolbar_title"
+ *     app:tools_toolbar_bota_icon="@drawable/xxx"
+ *     app:tools_toolbar_more_icon="@drawable/xxx"
+ *     app:tools_toolbar_search_icon="@drawable/xxx"/>
+ *
+ * custom attrs:
+ * app:tools_toolbar_title="@string/xxx"
+ * app:tools_toolbar_search_icon="@drawable/xxx"
+ * app:tools_toolbar_bota_icon="@drawable/xxx"
+ * app:tools_toolbar_more_icon="@drawable/xxx"
+ *
+ * btn click listener
+ * searchBtnClick:
+ * @see CPDFToolBar#setSearchBtnClickListener(OnClickListener)
+ *
+ * botaBtnClick:
+ * @see CPDFToolBar#setBoTaBtnClickListener(OnClickListener)
+ *
+ * moreBtnClick:
+ * @see CPDFToolBar#setMoreBtnClickListener(OnClickListener)
+ *
+ *
+ */
 public class CPDFToolBar extends FrameLayout {
 
     private AppCompatTextView tvToolBarTitle;
     private AppCompatImageView ivToolBarSearchBtn;
-    private AppCompatImageView ivToolBarOutlineBtn;
+    private AppCompatImageView ivToolBarBoTaBtn;
     private AppCompatImageView ivToolBarMoreBtn;
 
     public CPDFToolBar(@NonNull Context context) {
@@ -50,8 +82,6 @@ public class CPDFToolBar extends FrameLayout {
 
     public CPDFToolBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-
-
         initToolBar(context, attrs);
 
     }
@@ -61,70 +91,45 @@ public class CPDFToolBar extends FrameLayout {
         tvToolBarTitle = findViewById(R.id.tv_tool_bar_title);
         ivToolBarMoreBtn = findViewById(R.id.iv_tool_bar_more);
         ivToolBarSearchBtn = findViewById(R.id.iv_tool_bar_search);
-        ivToolBarOutlineBtn = findViewById(R.id.iv_tool_bar_outline);
+        ivToolBarBoTaBtn = findViewById(R.id.iv_tool_bar_bota);
         initAttributes(context, attrs);
     }
 
     private void initAttributes(Context context, @Nullable AttributeSet attrs) {
-        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tools_CPDFToolBar);
+        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CPDFToolBar);
         if (typedArray != null) {
-            String toolBarTitle = typedArray.getString(R.styleable.Tools_CPDFToolBar_tools_toolbar_title);
-            typedArray.getResourceId(R.styleable.Tools_CPDFToolBar_tools_toolbar_search_icon, -1);
+            String toolBarTitle = typedArray.getString(R.styleable.CPDFToolBar_tools_toolbar_title);
+            typedArray.getResourceId(R.styleable.CPDFToolBar_tools_toolbar_search_icon, -1);
             if (!TextUtils.isEmpty(toolBarTitle)) {
                 tvToolBarTitle.setText(toolBarTitle);
             }
-            Drawable searchIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_search_icon, R.drawable.tools_ic_search);
+            Drawable searchIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_search_icon, R.drawable.tools_ic_search);
             if (searchIconDrawable != null) {
                 ivToolBarSearchBtn.setImageDrawable(searchIconDrawable);
             }
-            Drawable outlineIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_outline_icon, R.drawable.tools_ic_outline);
-            if (outlineIconDrawable != null) {
-                ivToolBarOutlineBtn.setImageDrawable(outlineIconDrawable);
+            Drawable boTaIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_bota_icon, R.drawable.tools_ic_outline);
+            if (boTaIconDrawable != null) {
+                ivToolBarBoTaBtn.setImageDrawable(boTaIconDrawable);
             }
-            Drawable moreIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_more_icon, R.drawable.tools_ic_more);
+            Drawable moreIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_more_icon, R.drawable.tools_ic_more);
             if (moreIconDrawable != null) {
                 ivToolBarMoreBtn.setImageDrawable(moreIconDrawable);
             }
 
-            int color;
-            if (getBackground() != null && getBackground() instanceof ColorDrawable) {
-                ColorDrawable colorDrawable = (ColorDrawable) getBackground();
-                color = colorDrawable.getColor();
-            } else {
-                TypedValue typedValue = new TypedValue();
-                getContext().getTheme().resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true);
-                color = typedValue.data;
-            }
-            MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
-            materialShapeDrawable.setFillColor(ColorStateList.valueOf(color));
-            materialShapeDrawable.initializeElevationOverlay(context);
-            materialShapeDrawable.setElevation(ViewCompat.getElevation(this));
-            ViewCompat.setBackground(this, materialShapeDrawable);
+            ViewUtils.applyViewBackground(this);
 
             typedArray.recycle();
         }
     }
 
-    private Drawable loadImageFromAttributes(TypedArray typedArray, int index, int defValue) {
-        Drawable drawable = null;
-        try {
-            int resId = typedArray.getResourceId(index, defValue);
-            if (resId != -1) {
-                drawable = AppCompatResources.getDrawable(getContext(), resId);
-            }
-            return drawable;
-        } catch (Exception e) {
-            return null;
-        }
-    }
 
 
     public void setSearchBtnClickListener(View.OnClickListener clickListener) {
         ivToolBarSearchBtn.setOnClickListener(clickListener);
     }
 
-    public void setOutlineBtnClickListener(View.OnClickListener clickListener) {
-        ivToolBarOutlineBtn.setOnClickListener(clickListener);
+    public void setBoTaBtnClickListener(View.OnClickListener clickListener) {
+        ivToolBarBoTaBtn.setOnClickListener(clickListener);
     }
 
     public void setMoreBtnClickListener(View.OnClickListener clickListener) {

+ 42 - 37
compdfkit-tools/src/main/java/com/compdfkit/tools/utils/view/CToolBar.java

@@ -11,29 +11,49 @@ package com.compdfkit.tools.utils.view;
 
 
 import android.content.Context;
-import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.util.TypedValue;
 import android.view.LayoutInflater;
 import android.widget.FrameLayout;
 
+import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.StringRes;
-import androidx.appcompat.content.res.AppCompatResources;
 import androidx.appcompat.widget.AppCompatImageView;
 import androidx.appcompat.widget.AppCompatTextView;
-import androidx.core.content.ContextCompat;
-import androidx.core.view.ViewCompat;
 
 import com.compdfkit.tools.R;
-import com.google.android.material.shape.MaterialShapeDrawable;
+import com.compdfkit.tools.utils.viewutils.ViewUtils;
 
+/**
+ * compdfkit-tools ui common toolbar
+ * ︳------------------------------︳
+ * ︳ <          title             ︳
+ * ︳------------------------------︳
+ *
+ * use samples
+ * <com.compdfkit.tools.utils.view.CToolBar
+ *         android:id="@+id/tool_bar"
+ *         android:layout_width="match_parent"
+ *         android:layout_height="?android:attr/actionBarSize"
+ *         app:tools_toolbar_title="@string/tools_outline"
+ *         app:tools_toolbar_back_icon="@drawable/tools_ic_back"
+ *         android:elevation="4dp"/>
+ *
+ * custom attributes:
+ * tools_toolbar_title
+ * tools_toolbar_back_icon
+ *
+ * method:
+ * @see CToolBar#setTitle(String)
+ * @see CToolBar#setTitle(int)
+ * @see CToolBar#setBackImageIconResource(int)
+ * @see CToolBar#setBackBtnClickListener(OnClickListener)
+ *
+ */
 public class CToolBar extends FrameLayout {
 
     private AppCompatTextView tvToolBarTitle;
@@ -62,54 +82,30 @@ public class CToolBar extends FrameLayout {
     }
 
     private void initAttributes(Context context, @Nullable AttributeSet attrs) {
-        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tools_CToolBar);
+        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CToolBar);
         if (typedArray != null) {
-            String toolBarTitle = typedArray.getString(R.styleable.Tools_CToolBar_tools_toolbar_title);
+            String toolBarTitle = typedArray.getString(R.styleable.CToolBar_tools_toolbar_title);
             if (!TextUtils.isEmpty(toolBarTitle)) {
                 tvToolBarTitle.setText(toolBarTitle);
             }
-            Drawable backIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CToolBar_tools_toolbar_back_icon, R.drawable.tools_ic_back);
+            Drawable backIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CToolBar_tools_toolbar_back_icon, R.drawable.tools_ic_back);
             if (backIconDrawable != null) {
                 ivToolBarBackBtn.setImageDrawable(backIconDrawable);
             }
 
-            int color;
-            if (getBackground() != null && getBackground() instanceof ColorDrawable) {
-                ColorDrawable colorDrawable = (ColorDrawable) getBackground();
-                color = colorDrawable.getColor();
-            } else {
-                TypedValue typedValue = new TypedValue();
-                getContext().getTheme().resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true);
-                color = typedValue.data;
-            }
-            MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
-            materialShapeDrawable.setFillColor(ColorStateList.valueOf(color));
-            materialShapeDrawable.initializeElevationOverlay(context);
-            materialShapeDrawable.setElevation(ViewCompat.getElevation(this));
-            ViewCompat.setBackground(this, materialShapeDrawable);
+            ViewUtils.applyViewBackground(this);
 
             typedArray.recycle();
         }
     }
 
-    private Drawable loadImageFromAttributes(TypedArray typedArray, int index, int defValue) {
-        Drawable drawable = null;
-        try {
-            int resId = typedArray.getResourceId(index, defValue);
-            if (resId != -1) {
-                drawable = AppCompatResources.getDrawable(getContext(), resId);
-            }
-            return drawable;
-        } catch (Exception e) {
-            return null;
-        }
-    }
 
 
     public void setBackBtnClickListener(OnClickListener clickListener) {
         ivToolBarBackBtn.setOnClickListener(clickListener);
     }
 
+
     public void setTitle(@StringRes int titleResId) {
         tvToolBarTitle.setText(titleResId);
     }
@@ -118,4 +114,13 @@ public class CToolBar extends FrameLayout {
         tvToolBarTitle.setText(title);
     }
 
+    /**
+     * set left back icon resource
+     * @param iconResId resId
+     */
+    public void setBackImageIconResource(@DrawableRes int iconResId){
+        ivToolBarBackBtn.setImageResource(iconResId);
+    }
+
+
 }

+ 61 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/utils/viewutils/ViewUtils.java

@@ -0,0 +1,61 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.utils.viewutils;
+
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.TypedArray;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.util.TypedValue;
+import android.view.View;
+
+import androidx.appcompat.content.res.AppCompatResources;
+import androidx.core.view.ViewCompat;
+
+import com.google.android.material.shape.MaterialShapeDrawable;
+
+public class ViewUtils {
+
+    public static Drawable loadDrawableFromAttributes(Context context, TypedArray typedArray, int index, int defValue) {
+        Drawable drawable = null;
+        try {
+            int resId = typedArray.getResourceId(index, defValue);
+            if (resId != -1) {
+                drawable = AppCompatResources.getDrawable(context, resId);
+            }
+            return drawable;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+
+    public static void applyViewBackground(View view){
+        int color;
+        if (view.getBackground() != null && view.getBackground() instanceof ColorDrawable) {
+            ColorDrawable colorDrawable = (ColorDrawable) view.getBackground();
+            color = colorDrawable.getColor();
+        } else {
+            TypedValue typedValue = new TypedValue();
+            view.getContext().getTheme().resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true);
+            color = typedValue.data;
+        }
+        MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
+        materialShapeDrawable.setFillColor(ColorStateList.valueOf(color));
+        materialShapeDrawable.initializeElevationOverlay(view.getContext());
+        materialShapeDrawable.setElevation(ViewCompat.getElevation(view));
+        ViewCompat.setBackground(view, materialShapeDrawable);
+    }
+
+
+
+}

compdfkit-tools/src/main/res/drawable/tools_ic_pdf_slider_bar_thumbnail.xml → compdfkit-tools/src/main/res/drawable/tools_ic_pdf_slider_bar.xml


+ 1 - 0
compdfkit-tools/src/main/res/layout/tools_cpdf_bota_dialog_fragment.xml

@@ -9,6 +9,7 @@
         android:layout_width="match_parent"
         android:layout_height="?android:attr/actionBarSize"
         app:tools_toolbar_title="@string/tools_outline"
+        app:tools_toolbar_back_icon="@drawable/tools_ic_back"
         android:elevation="4dp"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"

+ 2 - 2
compdfkit-tools/src/main/res/layout/tools_cpdf_tool_bar.xml

@@ -28,12 +28,12 @@
         app:tint="?android:attr/colorAccent"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintDimensionRatio="1:1"
-        app:layout_constraintEnd_toStartOf="@id/iv_tool_bar_outline"
+        app:layout_constraintEnd_toStartOf="@id/iv_tool_bar_bota"
         app:layout_constraintTop_toTopOf="parent"
         app:srcCompat="@drawable/tools_ic_search" />
 
     <androidx.appcompat.widget.AppCompatImageView
-        android:id="@+id/iv_tool_bar_outline"
+        android:id="@+id/iv_tool_bar_bota"
         android:layout_width="0dp"
         android:layout_height="match_parent"
         android:layout_margin="10dp"

+ 15 - 87
compdfkit-tools/src/main/res/layout/tools_pdf_document_info_dialog_fragment.xml

@@ -53,12 +53,7 @@
 
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -76,12 +71,7 @@
             </LinearLayout>
 
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -99,12 +89,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -122,12 +107,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -169,10 +149,7 @@
             </LinearLayout>
 
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <androidx.appcompat.widget.AppCompatTextView
                 style="@style/tools_document_info_header"
@@ -199,12 +176,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -222,12 +194,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -246,12 +213,7 @@
             </LinearLayout>
 
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -269,12 +231,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -292,11 +249,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:background="@color/tools_item_dividing_line_color" />
-
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <androidx.appcompat.widget.AppCompatTextView
                 style="@style/tools_document_info_header"
@@ -325,12 +278,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -348,12 +296,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -371,12 +314,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -395,12 +333,7 @@
             </LinearLayout>
 
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"
@@ -418,12 +351,7 @@
                     style="@style/tools_document_info_subTitle" />
             </LinearLayout>
 
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/qb_px_1"
-                android:layout_marginLeft="@dimen/qb_px_20"
-                android:layout_marginRight="@dimen/qb_px_20"
-                android:background="@color/tools_item_dividing_line_color" />
+            <View style="@style/tools_document_info_dividing_line_style" />
 
             <LinearLayout
                 style="@style/tools_document_info_item_style"

+ 4 - 0
compdfkit-tools/src/main/res/values-night/colors.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="tools_item_dividing_line_color">#33000000</color>
+</resources>

+ 8 - 0
compdfkit-tools/src/main/res/values/styles.xml

@@ -40,4 +40,12 @@
         <item name="android:background">?android:attr/colorBackground</item>
     </style>
 
+    <style name="tools_document_info_dividing_line_style">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">1dp</item>
+        <item name="android:layout_marginStart">20dp</item>
+        <item name="android:layout_marginEnd">20dp</item>
+        <item name="android:background">@color/tools_item_dividing_line_color</item>
+    </style>
+
 </resources>

+ 6 - 5
compdfkit-tools/src/main/res/values/tools_attrs.xml

@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
-<resources>
+<resources xmlns:tools="http://schemas.android.com/tools">
 
     <attr name="tools_toolbar_title" format="string"/>
 
-    <declare-styleable name="Tools_CPDFToolBar">
+    <declare-styleable name="CPDFToolBar" tools:ignore="ResourceName">
         <attr name="tools_toolbar_title"/>
         <attr name="tools_toolbar_search_icon" format="reference"/>
-        <attr name="tools_toolbar_outline_icon" format="reference"/>
+        <attr name="tools_toolbar_bota_icon" format="reference"/>
         <attr name="tools_toolbar_more_icon" format="reference"/>
     </declare-styleable>
 
-    <declare-styleable name="Tools_CToolBar">
+    <declare-styleable name="CToolBar" tools:ignore="ResourceName">
         <attr name="tools_toolbar_title"/>
         <attr name="tools_toolbar_back_icon" format="reference"/>
     </declare-styleable>
 
-    <declare-styleable name="Tools_CPDFReaderView">
+    <declare-styleable name="CPDFReaderView" tools:ignore="ResourceName">
         <attr name="tools_enable_slider_bar" format="boolean"/>
         <attr name="tools_slider_bar_position" format="enum">
             <enum name="left" value="0"/>
@@ -23,5 +23,6 @@
         </attr>
         <attr name="tools_slider_bar_thumbnail_width" format="dimension"/>
         <attr name="tools_slider_bar_thumbnail_height" format="dimension"/>
+        <attr name="tools_slider_bar_icon" format="reference"/>
     </declare-styleable>
 </resources>

+ 5 - 3
viewer-ctrl-demo/src/main/java/com/compdfkit/demo/viewer/MainActivity.java

@@ -3,7 +3,6 @@ package com.compdfkit.demo.viewer;
 import androidx.appcompat.app.AppCompatActivity;
 
 import android.os.Bundle;
-import android.util.Log;
 import android.view.View;
 import android.widget.Toast;
 
@@ -45,7 +44,10 @@ public class MainActivity extends AppCompatActivity {
         initToolbarListener();
         intSearchBarListener();
         CExtractAssetFileTask.extract(this, QUICK_START_GUIDE, QUICK_START_GUIDE, (pdfFile) ->
-                runOnUiThread(() -> binding.pdfReaderView.openPdfFile(pdfFile.getAbsolutePath())));
+                runOnUiThread(() -> {
+                    binding.pdfReaderView.openPdfFile(pdfFile.getAbsolutePath());
+                }));
+
     }
 
 
@@ -55,7 +57,7 @@ public class MainActivity extends AppCompatActivity {
             binding.pdfToolBar.setVisibility(View.GONE);
             binding.pdfSearchToolBar.setVisibility(View.VISIBLE);
         });
-        binding.pdfToolBar.setOutlineBtnClickListener(v -> {
+        binding.pdfToolBar.setBoTaBtnClickListener(v -> {
             CPDFBotaDialogFragment botaDialogFragment = CPDFBotaDialogFragment.newInstance();
             botaDialogFragment.setCPdfReaderView(binding.pdfReaderView);
             botaDialogFragment.show(getSupportFragmentManager(), "boTaDialogFragment");

+ 2 - 1
viewer-ctrl-demo/src/main/res/layout/viewer_activity_main.xml

@@ -7,7 +7,7 @@
     android:elevation="4dp"
     tools:context=".MainActivity">
 
-    <com.compdfkit.tools.pdfview.CPDFToolBar
+    <com.compdfkit.tools.pdfview.view.CPDFToolBar
         android:id="@+id/pdf_tool_bar"
         android:layout_width="match_parent"
         android:layout_height="?android:attr/actionBarSize"
@@ -35,6 +35,7 @@
         android:layout_height="0dp"
         app:tools_enable_slider_bar="true"
         app:tools_slider_bar_position="right"
+        app:tools_slider_bar_icon="@drawable/tools_ic_pdf_slider_bar"
         app:layout_constraintTop_toBottomOf="@id/pdf_tool_bar"
         app:layout_constraintBottom_toBottomOf="parent"/>