|
@@ -36,10 +36,17 @@ import com.compdfkit.tools.annotation.pdfproperties.pdfnote.CPDFtextAnnotImpl;
|
|
|
import com.compdfkit.tools.common.utils.dialog.CGotoPageDialog;
|
|
|
import com.compdfkit.tools.common.utils.viewutils.CDimensUtils;
|
|
|
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
+import com.compdfkit.ui.proxy.CPDFBaseAnnotImpl;
|
|
|
+import com.compdfkit.ui.reader.CPDFAddAnnotCallback;
|
|
|
+import com.compdfkit.ui.reader.CPDFPageView;
|
|
|
import com.compdfkit.ui.reader.CPDFReaderView;
|
|
|
import com.compdfkit.ui.reader.IReaderViewCallback;
|
|
|
+import com.compdfkit.ui.reader.OnFocusedTypeChangedListener;
|
|
|
import com.compdfkit.ui.widget.CPDFSlideBar;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* compdfkit sdk CPDFReaderView ctrl view <br/>
|
|
@@ -93,13 +100,15 @@ import com.compdfkit.ui.widget.CPDFSlideBar;
|
|
|
* <p/>
|
|
|
* app:tools_enable_page_indicator="true|false"
|
|
|
*/
|
|
|
-public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback {
|
|
|
+public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback ,OnFocusedTypeChangedListener{
|
|
|
|
|
|
private CPDFReaderView cPdfReaderView;
|
|
|
|
|
|
- public int currentPageIndex = 0;
|
|
|
+ public CPDFPageIndicatorView indicatorView;
|
|
|
|
|
|
- private CPDFSlideBar slideBar;
|
|
|
+ public CPDFSlideBar slideBar;
|
|
|
+
|
|
|
+ public int currentPageIndex = 0;
|
|
|
|
|
|
private boolean enableSliderBar = true;
|
|
|
|
|
@@ -112,12 +121,27 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
@DrawableRes
|
|
|
private int sliderBarIconResId = R.drawable.tools_ic_pdf_slider_bar;
|
|
|
|
|
|
- private CPDFPageIndicatorView indicatorView;
|
|
|
-
|
|
|
private boolean enablePageIndicator = true;
|
|
|
|
|
|
+ private int pageIndicatorMarginBottom = 16;
|
|
|
+
|
|
|
private OnTapMainDocAreaCallback onTapMainDocAreaCallback;
|
|
|
|
|
|
+ private boolean isScrolling = false;
|
|
|
+
|
|
|
+ private Handler handler = new Handler(Looper.getMainLooper());
|
|
|
+
|
|
|
+ private ObjectAnimator pageIndicatorAnimator = null;
|
|
|
+
|
|
|
+ private List<OnFocusedTypeChangedListener> pdfViewFocusedListenerList = new ArrayList<>();
|
|
|
+
|
|
|
+ private Runnable hideIndicatorRunnable = () -> {
|
|
|
+ if (pageIndicatorAnimator != null) {
|
|
|
+ isScrolling = false;
|
|
|
+ pageIndicatorAnimator.reverse();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
public CPDFViewCtrl(@NonNull Context context) {
|
|
|
this(context, null);
|
|
|
}
|
|
@@ -132,7 +156,6 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
initCPDFReaderView();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void initAttr(Context context, AttributeSet attributeSet) {
|
|
|
try {
|
|
|
TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.CPDFReaderView);
|
|
@@ -148,12 +171,18 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
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);
|
|
|
enablePageIndicator = typedArray.getBoolean(R.styleable.CPDFReaderView_tools_enable_page_indicator, true);
|
|
|
+ pageIndicatorMarginBottom = typedArray.getDimensionPixelOffset(R.styleable.CPDFReaderView_tools_page_indicator_margin_bottom, 16);
|
|
|
+ if (enableSliderBar) {
|
|
|
+ slideBar = new CPDFSliderBarView(getContext());
|
|
|
+ }
|
|
|
+ if (enablePageIndicator){
|
|
|
+ indicatorView = new CPDFPageIndicatorView(getContext());
|
|
|
+ }
|
|
|
typedArray.recycle();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -162,11 +191,10 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
cPdfReaderView.setDoublePageMode(false);
|
|
|
cPdfReaderView.setReaderViewCallback(this);
|
|
|
cPdfReaderView.setContextMenuShowListener(new CContextMenuHelper(cPdfReaderView));
|
|
|
+ cPdfReaderView.setOnFocusedTypeChangedListener(this);
|
|
|
setAllowAddAndEditAnnot(false);
|
|
|
- //note注释创建、点击操作类
|
|
|
- cPdfReaderView.getAnnotImplRegistry().registAttachHelper(CPDFTextAnnotation.class, CPDFtextAnnotAttachHelper.class);
|
|
|
- cPdfReaderView.getAnnotImplRegistry().registImpl(CPDFTextAnnotation.class, CPDFtextAnnotImpl.class);
|
|
|
- setAllowAddAndEditAnnot(true);
|
|
|
+// cPdfReaderView.getAnnotImplRegistry().registAttachHelper(CPDFTextAnnotation.class, CPDFtextAnnotAttachHelper.class);
|
|
|
+// cPdfReaderView.getAnnotImplRegistry().registImpl(CPDFTextAnnotation.class, CPDFtextAnnotImpl.class);
|
|
|
addView(cPdfReaderView);
|
|
|
}
|
|
|
|
|
@@ -213,10 +241,6 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public com.compdfkit.ui.reader.CPDFReaderView getCPdfReaderView() {
|
|
|
- return cPdfReaderView;
|
|
|
- }
|
|
|
-
|
|
|
public void changeAnnotationType(CPDFAnnotation.Type type) {
|
|
|
cPdfReaderView.setTouchMode(CPDFReaderView.TouchMode.ADD_ANNOT);
|
|
|
cPdfReaderView.setCurrentFocusedType(type);
|
|
@@ -227,6 +251,18 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
cPdfReaderView.setCurrentFocusedType(CPDFAnnotation.Type.UNKNOWN);
|
|
|
}
|
|
|
|
|
|
+ public com.compdfkit.ui.reader.CPDFReaderView getCPdfReaderView() {
|
|
|
+ return cPdfReaderView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTypeChanged(CPDFAnnotation.Type type) {
|
|
|
+ if (pdfViewFocusedListenerList != null) {
|
|
|
+ for (OnFocusedTypeChangedListener onFocusedTypeChangedListener : pdfViewFocusedListenerList) {
|
|
|
+ onFocusedTypeChangedListener.onTypeChanged(type);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void onTapMainDocArea() {
|
|
@@ -269,17 +305,16 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
if (!enableSliderBar) {
|
|
|
return;
|
|
|
}
|
|
|
- CPDFSliderBarView cpdfSliderBarView = new CPDFSliderBarView(getContext());
|
|
|
+ CPDFSliderBarView cpdfSliderBarView = (CPDFSliderBarView) slideBar;
|
|
|
cpdfSliderBarView.initWithPDFView(this);
|
|
|
cpdfSliderBarView.initSliderBar(slideBarPosition, sliderBarThumbnailWidth, sliderBarThumbnailHeight);
|
|
|
cpdfSliderBarView.setSlideBarBitmap(sliderBarIconResId);
|
|
|
setSliderBar(cpdfSliderBarView);
|
|
|
}
|
|
|
|
|
|
- public void setSliderBar(CPDFSlideBar cpdfSlideBar) {
|
|
|
+ private void setSliderBar(CPDFSlideBar cpdfSlideBar) {
|
|
|
enableSliderBar = true;
|
|
|
slideBar = cpdfSlideBar;
|
|
|
-
|
|
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
|
|
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
|
|
linearLayout.setLayoutParams(layoutParams);
|
|
@@ -292,8 +327,6 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
addView(linearLayout);
|
|
|
}
|
|
|
|
|
|
- ObjectAnimator pageIndicatorAnimator = null;
|
|
|
-
|
|
|
/**
|
|
|
* Add a page indicator in the lower left corner of the page.
|
|
|
* After clicking, a page number jump input box will pop up, and you can jump to the corresponding PDF page
|
|
@@ -301,16 +334,15 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
*
|
|
|
* @see CPDFPageIndicatorView
|
|
|
*/
|
|
|
- public void addPageIndicator() {
|
|
|
+ private void addPageIndicator() {
|
|
|
if (!enablePageIndicator) {
|
|
|
return;
|
|
|
}
|
|
|
- indicatorView = new CPDFPageIndicatorView(getContext());
|
|
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
|
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
|
|
int margin = CDimensUtils.dp2px(getContext(), 16);
|
|
|
- layoutParams.setMargins(margin, 0, 0, margin);
|
|
|
+ layoutParams.setMargins(margin, 0, 0, pageIndicatorMarginBottom+margin);
|
|
|
indicatorView.setLayoutParams(layoutParams);
|
|
|
indicatorView.setAlpha(0F);
|
|
|
addView(indicatorView);
|
|
@@ -319,8 +351,7 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
indicatorView.setTotalPage(totalPageCount);
|
|
|
indicatorView.setPageIndicatorClickListener(pageIndex -> {
|
|
|
CGotoPageDialog dialog = new CGotoPageDialog(getContext());
|
|
|
- dialog.setHintInputText(getContext().getString(R.string.tools_search_header_page) +
|
|
|
- String.format(" (%d/%d)", 1, totalPageCount));
|
|
|
+ dialog.setHintInputText(getContext().getString(R.string.tools_search_header_page) + String.format(" (%d/%d)", 1, totalPageCount));
|
|
|
dialog.setOnSetPDFDisplayPageIndexListener(page -> {
|
|
|
if (page <= totalPageCount && page > 0) {
|
|
|
cPdfReaderView.setDisplayPageIndex(page - 1, true);
|
|
@@ -328,26 +359,13 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
});
|
|
|
dialog.show();
|
|
|
});
|
|
|
-
|
|
|
pageIndicatorAnimator = ObjectAnimator.ofFloat(indicatorView, "alpha", 0F, 1F);
|
|
|
pageIndicatorAnimator.setDuration(100);
|
|
|
pageIndicatorAnimator.setInterpolator(new FastOutLinearInInterpolator());
|
|
|
showPageIndicator();
|
|
|
- Log.e("CPDFView", "init addPageIndicator");
|
|
|
hidePageIndicator();
|
|
|
}
|
|
|
|
|
|
- private boolean isScrolling = false;
|
|
|
-
|
|
|
- private Handler handler = new Handler(Looper.getMainLooper());
|
|
|
-
|
|
|
- private Runnable hideIndicatorRunnable = () -> {
|
|
|
- if (pageIndicatorAnimator != null) {
|
|
|
- isScrolling = false;
|
|
|
- pageIndicatorAnimator.reverse();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
private void hidePageIndicator() {
|
|
|
handler.postDelayed(hideIndicatorRunnable, 3000);
|
|
|
}
|
|
@@ -358,10 +376,15 @@ public class CPDFViewCtrl extends RelativeLayout implements IReaderViewCallback
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void addOnPDFFocusedTypeChangeListener(OnFocusedTypeChangedListener listener){
|
|
|
+ pdfViewFocusedListenerList.add(listener);
|
|
|
+ }
|
|
|
+
|
|
|
public void setOnTapMainDocAreaCallback(OnTapMainDocAreaCallback onTapMainDocAreaCallback) {
|
|
|
this.onTapMainDocAreaCallback = onTapMainDocAreaCallback;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public interface OnTapMainDocAreaCallback {
|
|
|
void onTapMainDocArea();
|
|
|
}
|