Skip to content

Commit ccf513d

Browse files
committed
v2.6.9
1 parent 1836b2a commit ccf513d

93 files changed

Lines changed: 5288 additions & 2074 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
62.6 KB
Binary file not shown.
79.6 KB
Binary file not shown.

ComPDFKit_Tools/build.gradle

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@ plugins {
22
id 'com.android.library'
33
}
44

5-
6-
75
android {
86
namespace 'com.compdfkit.tools'
97
compileSdk rootProject.ext.android.COMPILESDK
108
resourcePrefix 'tools_'
119

12-
publishing {
13-
singleVariant('release') {
14-
withSourcesJar()
15-
withJavadocJar()
16-
}
17-
}
18-
1910
defaultConfig {
2011
minSdk rootProject.ext.android.MINSDK
2112
targetSdk rootProject.ext.android.TARGETSDK
@@ -51,12 +42,8 @@ android {
5142
dependencies {
5243

5344
api fileTree(include: ['*.jar'], dir: 'libs')
54-
// use this
55-
// api project(path:':ComPDFKit_Repo:compdfkit')
56-
// api project(path:':ComPDFKit_Repo:compdfkit-ui')
57-
// or use
58-
api ('com.compdf:compdfkit:2.6.8')
59-
api ('com.compdf:compdfkit-ui:2.6.8')
45+
api project(path:':ComPDFKit_Repo:compdfkit')
46+
api project(path:':ComPDFKit_Repo:compdfkit-ui')
6047
api 'com.github.bumptech.glide:glide:4.15.1'
6148
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
6249
api "androidx.print:print:1.0.0"

ComPDFKit_Tools/src/main/assets/tools_default_configuration.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"toolbarConfig": {
1414
"mainToolbarVisible": true,
15+
"mainToolbarTitleVisible": true,
1516
"contentEditorToolbarVisible": true,
1617
"annotationToolbarVisible": true,
1718
"formToolbarVisible": true,
@@ -53,6 +54,7 @@
5354
"autoShowStampPicker": true,
5455
"autoShowPicPicker": true,
5556
"autoShowLinkDialog": true,
57+
"autoShowNoteEditDialog": true,
5658
"interceptNoteAction": false,
5759
"interceptLinkAction": false,
5860
"availableTypes": [
@@ -182,9 +184,8 @@
182184
"showCreateListBoxOptionsDialog": true,
183185
"showCreateComboBoxOptionsDialog": true,
184186
"showCreatePushButtonOptionsDialog": true,
185-
"interceptListBoxAction": false,
186-
"interceptComboBoxAction": false,
187-
"interceptPushButtonAction": false,
187+
"interceptAllFormWidgetActions": false,
188+
"interceptFormWidgetActions": [],
188189
"availableTypes": [
189190
"textField",
190191
"checkBox",
@@ -828,4 +829,4 @@
828829
]
829830
}
830831
}
831-
}
832+
}

ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationbar/CAnnotationToolbar.java

Lines changed: 157 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.compdfkit.tools.common.pdf.config.AnnotationsConfig;
3737
import com.compdfkit.tools.common.utils.CListUtil;
3838
import com.compdfkit.tools.common.utils.CLog;
39+
import com.compdfkit.tools.common.utils.annotation.CPDFAnnotationManager;
3940
import com.compdfkit.tools.common.utils.customevent.CPDFCustomEventCallbackHelper;
4041
import com.compdfkit.tools.common.utils.customevent.CPDFCustomEventField;
4142
import com.compdfkit.tools.common.utils.customevent.CPDFCustomEventType;
@@ -52,8 +53,12 @@
5253
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
5354
import com.compdfkit.ui.proxy.attach.IInkDrawCallback;
5455
import com.compdfkit.ui.proxy.attach.IInkDrawCallback.Mode;
56+
import com.compdfkit.ui.proxy.CPDFBaseAnnotImpl;
57+
import com.compdfkit.ui.reader.CPDFPageView;
5558
import com.compdfkit.ui.reader.CPDFReaderView;
5659
import com.compdfkit.ui.reader.CPDFReaderView.ViewMode;
60+
import com.compdfkit.ui.reader.CPDFSelectAnnotCallback;
61+
import com.compdfkit.ui.reader.OnViewModeChangedListener;
5762

5863
import java.util.ArrayList;
5964
import java.util.Arrays;
@@ -86,6 +91,20 @@ public class CAnnotationToolbar extends FrameLayout {
8691

8792
private LinearLayout llAnnotTools;
8893

94+
@Nullable
95+
private CPDFBaseAnnotImpl<CPDFAnnotation> selectedAnnotImpl;
96+
97+
@Nullable
98+
private CPDFPageView selectedAnnotPageView;
99+
100+
@Nullable
101+
private CPDFSelectAnnotCallback selectAnnotCallback;
102+
103+
@Nullable
104+
private OnViewModeChangedListener viewModeChangedListener;
105+
106+
private boolean listeningSelectAnnot = false;
107+
89108
public enum UndoManagerType {
90109
AnnotUndo,
91110

@@ -131,15 +150,15 @@ private void initListener() {
131150
public void initWithPDFView(CPDFViewCtrl pdfView) {
132151
this.pdfView = pdfView;
133152
toolListAdapter.setList(CAnnotationToolDatas.getAnnotationList(pdfView));
153+
setupSelectedAnnotationCallbacks();
134154
this.pdfView.addOnPDFFocusedTypeChangeListener(type -> {
135155
if (type == CPDFAnnotation.Type.UNKNOWN) {
156+
clearSelectedAnnotationStyleTarget();
136157
if (toolListAdapter.hasSelectAnnotType()) {
137158
if (toolListAdapter.getCurrentAnnotType() != CAnnotationType.INK_ERASER){
138159
toolListAdapter.selectByType(CAnnotationType.UNKNOWN);
139160
}
140-
if (ivSetting != null) {
141-
ivSetting.setEnabled(toolListAdapter.annotEnableSetting());
142-
}
161+
updateSettingButtonState();
143162
}
144163
if (toolListAdapter.getCurrentAnnotType() != CAnnotationType.INK_ERASER) {
145164
setUndoManagerType(UndoManagerType.AnnotUndo);
@@ -152,6 +171,108 @@ public void initWithPDFView(CPDFViewCtrl pdfView) {
152171
setUndoManagerType(UndoManagerType.AnnotUndo);
153172
}
154173
});
174+
syncSelectAnnotListenerWithViewMode(pdfView.getCPdfReaderView().getViewMode());
175+
}
176+
177+
private void setupSelectedAnnotationCallbacks() {
178+
if (selectAnnotCallback == null) {
179+
selectAnnotCallback = new CPDFSelectAnnotCallback() {
180+
@Override
181+
public void onAnnotationSelected(CPDFPageView pageView,
182+
CPDFBaseAnnotImpl<CPDFAnnotation> annotImpl) {
183+
if (canShowSelectedAnnotationStyleDialog(annotImpl)) {
184+
selectedAnnotPageView = pageView;
185+
selectedAnnotImpl = annotImpl;
186+
} else {
187+
clearSelectedAnnotationStyleTarget();
188+
}
189+
updateSettingButtonState();
190+
}
191+
192+
@Override
193+
public void onAnnotationDeselected(CPDFPageView pageView,
194+
CPDFBaseAnnotImpl<CPDFAnnotation> annotImpl) {
195+
if (selectedAnnotImpl == annotImpl
196+
|| (selectedAnnotImpl != null && annotImpl != null
197+
&& selectedAnnotImpl.getId() == annotImpl.getId())) {
198+
clearSelectedAnnotationStyleTarget();
199+
updateSettingButtonState();
200+
}
201+
}
202+
};
203+
}
204+
if (viewModeChangedListener == null) {
205+
viewModeChangedListener = this::syncSelectAnnotListenerWithViewMode;
206+
pdfView.addOnPDFViewModeChangeListener(viewModeChangedListener);
207+
}
208+
}
209+
210+
private void syncSelectAnnotListenerWithViewMode(ViewMode viewMode) {
211+
if (viewMode == ViewMode.ANNOT) {
212+
startListenSelectAnnot();
213+
} else {
214+
stopListenSelectAnnot();
215+
clearSelectedAnnotationStyleTarget();
216+
updateSettingButtonState();
217+
}
218+
}
219+
220+
private void startListenSelectAnnot() {
221+
if (!listeningSelectAnnot && pdfView != null && selectAnnotCallback != null) {
222+
pdfView.addOnPDFSelectAnnotChangeListener(selectAnnotCallback);
223+
listeningSelectAnnot = true;
224+
}
225+
}
226+
227+
private void stopListenSelectAnnot() {
228+
if (listeningSelectAnnot && pdfView != null && selectAnnotCallback != null) {
229+
pdfView.removeOnPDFSelectAnnotChangeListener(selectAnnotCallback);
230+
listeningSelectAnnot = false;
231+
}
232+
}
233+
234+
private void clearSelectedAnnotationStyleTarget() {
235+
selectedAnnotImpl = null;
236+
selectedAnnotPageView = null;
237+
}
238+
239+
private boolean hasSelectedAnnotationStyleTarget() {
240+
return isAnnotationMode()
241+
&& selectedAnnotImpl != null
242+
&& selectedAnnotPageView != null
243+
&& canShowSelectedAnnotationStyleDialog(selectedAnnotImpl);
244+
}
245+
246+
private boolean isAnnotationMode() {
247+
return pdfView != null && pdfView.getCPdfReaderView().getViewMode() == ViewMode.ANNOT;
248+
}
249+
250+
private boolean canShowSelectedAnnotationStyleDialog(@Nullable CPDFBaseAnnotImpl<CPDFAnnotation> annotImpl) {
251+
if (annotImpl == null) {
252+
return false;
253+
}
254+
switch (annotImpl.getAnnotType()) {
255+
case TEXT:
256+
case HIGHLIGHT:
257+
case UNDERLINE:
258+
case SQUIGGLY:
259+
case STRIKEOUT:
260+
case INK:
261+
case SQUARE:
262+
case CIRCLE:
263+
case LINE:
264+
case FREETEXT:
265+
return true;
266+
default:
267+
return false;
268+
}
269+
}
270+
271+
private void updateSettingButtonState() {
272+
if (ivSetting != null) {
273+
ivSetting.setEnabled(hasSelectedAnnotationStyleTarget()
274+
|| toolListAdapter.annotEnableSetting());
275+
}
155276
}
156277
private void setUndoManagerType(UndoManagerType undoManagerType) {
157278
this.undoManagerType = undoManagerType;
@@ -176,10 +297,26 @@ private void setUndoManagerType(UndoManagerType undoManagerType) {
176297
}
177298

178299
private void showAnnotStyleDialog() {
300+
if (hasSelectedAnnotationStyleTarget()) {
301+
showSelectedAnnotStyleDialog();
302+
return;
303+
}
179304
CStyleType styleType = toolListAdapter.getCurrentAnnotType().getStyleType();
180305
showAnnotStyleDialog(styleType);
181306
}
182307

308+
private void showSelectedAnnotStyleDialog() {
309+
saveInk();
310+
CViewUtils.hideKeyboard(this);
311+
FragmentActivity fragmentActivity = CViewUtils.getFragmentActivity(getContext());
312+
CPDFBaseAnnotImpl<CPDFAnnotation> annotImpl = selectedAnnotImpl;
313+
CPDFPageView pageView = selectedAnnotPageView;
314+
if (fragmentActivity != null && annotImpl != null && pageView != null) {
315+
CPDFAnnotationManager.showPropertiesDialog(
316+
fragmentActivity.getSupportFragmentManager(), annotImpl, pageView);
317+
}
318+
}
319+
183320
public void showAnnotStyleDialog(CStyleType styleType) {
184321
saveInk();
185322
CViewUtils.hideKeyboard(this);
@@ -230,9 +367,8 @@ public void switchAnnotationUnknown(){
230367
setUndoManagerType(UndoManagerType.AnnotUndo);
231368
}
232369
toolListAdapter.selectByType(CAnnotationType.UNKNOWN);
233-
if (ivSetting != null) {
234-
ivSetting.setEnabled(toolListAdapter.annotEnableSetting());
235-
}
370+
clearSelectedAnnotationStyleTarget();
371+
updateSettingButtonState();
236372
pdfView.resetAnnotationType();
237373
pdfView.getCPdfReaderView().getInkDrawHelper().onSave();
238374
pdfView.getCPdfReaderView().getInkDrawHelper().setMode(Mode.DRAW);
@@ -245,9 +381,8 @@ public void switchAnnotationType(CAnnotationType type) {
245381
return;
246382
}
247383
toolListAdapter.selectByType(type);
248-
if (ivSetting != null) {
249-
ivSetting.setEnabled(toolListAdapter.annotEnableSetting());
250-
}
384+
clearSelectedAnnotationStyleTarget();
385+
updateSettingButtonState();
251386
AnnotationsConfig annotationsConfig = pdfView.getCPDFConfiguration().annotationsConfig;
252387
pdfView.getCPdfReaderView().getInkDrawHelper().onSave();
253388
pdfView.getCPdfReaderView().removeAllAnnotFocus();
@@ -453,6 +588,7 @@ public void setTools(List<AnnotationsConfig.AnnotationTools> tools) {
453588
showAnnotStyleDialog();
454589
});
455590
ivSetting = toolView;
591+
updateSettingButtonState();
456592
break;
457593
case Undo:
458594
toolView.setImageResource(R.drawable.tools_ic_annotation_undo);
@@ -560,6 +696,8 @@ public void setAnnotationList(CAnnotationType... types) {
560696

561697
public void reset() {
562698
toolListAdapter.selectByType(CAnnotationType.UNKNOWN);
699+
clearSelectedAnnotationStyleTarget();
700+
updateSettingButtonState();
563701
rvAnnotationList.scrollToPosition(0);
564702
redoUndoManager();
565703
}
@@ -572,5 +710,15 @@ public void addAnnotationCreatePreparedListener(COnAnnotationCreatePreparedListe
572710
annotationCreatePreparedListeners.add(listener);
573711
}
574712

713+
public void release() {
714+
stopListenSelectAnnot();
715+
if (pdfView != null && viewModeChangedListener != null) {
716+
pdfView.removeOnPDFViewModeChangeListener(viewModeChangedListener);
717+
}
718+
viewModeChangedListener = null;
719+
clearSelectedAnnotationStyleTarget();
720+
updateSettingButtonState();
721+
}
722+
575723

576724
}

0 commit comments

Comments
 (0)