/
DocumentViewViewManager.java
198 lines (163 loc) · 7.14 KB
/
DocumentViewViewManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.pdftron.reactnative.viewmanagers;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.pdftron.common.PDFNetException;
import com.pdftron.reactnative.views.DocumentView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class DocumentViewViewManager extends ViewGroupManager<DocumentView> {
private static final String REACT_CLASS = "RCTDocumentView";
private SparseArray<DocumentView> mDocumentViews = new SparseArray<>();
@Override
public String getName() {
return REACT_CLASS;
}
private View.OnAttachStateChangeListener mOnAttachStateChangeListener = new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
DocumentView documentView = (DocumentView) v;
Log.d(getName(), "add to map: " + v.getId());
mDocumentViews.put(v.getId(), documentView);
}
@Override
public void onViewDetachedFromWindow(View v) {
DocumentView documentView = (DocumentView) v;
Log.d(getName(), "remove from map: " + v.getId());
mDocumentViews.remove(v.getId());
documentView.removeOnAttachStateChangeListener(mOnAttachStateChangeListener);
}
};
@Override
protected DocumentView createViewInstance(ThemedReactContext reactContext) {
DocumentView documentView = new DocumentView(reactContext);
documentView.setup(reactContext);
documentView.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
return documentView;
}
@ReactProp(name = "document")
public void setDocument(DocumentView documentView, @NonNull String filepath) {
documentView.setDocument(filepath);
}
@ReactProp(name = "password")
public void setPassword(DocumentView documentView, @Nullable String password) {
documentView.setPassword(password);
}
@ReactProp(name = "leadingNavButtonIcon")
public void setNavButtonIcon(DocumentView documentView, @NonNull String resName) {
documentView.setNavResName(resName);
}
@ReactProp(name = "showLeadingNavButton")
public void setShowNavButton(DocumentView documentView, boolean show) {
documentView.setShowNavIcon(show);
}
@ReactProp(name = "disabledElements")
public void setDisabledElements(DocumentView documentView, @NonNull ReadableArray array) {
documentView.setDisabledElements(array);
}
@ReactProp(name = "disabledTools")
public void setDisabledTools(DocumentView documentView, @NonNull ReadableArray array) {
documentView.setDisabledTools(array);
}
@ReactProp(name = "customHeaders")
public void setCustomHeaders(DocumentView documentView, @Nullable ReadableMap map) {
documentView.setCustomHeaders(map);
}
@ReactProp(name = "initialPageNumber")
public void setInitialPageNumber(DocumentView documentView, int pageNum) {
documentView.setInitialPageNumber(pageNum);
}
@ReactProp(name = "pageNumber")
public void setPageNumber(DocumentView documentView, int pageNum) {
documentView.setPageNumber(pageNum);
}
@ReactProp(name = "topToolbarEnabled")
public void setTopToolbarEnabled(DocumentView documentView, boolean topToolbarEnabled) {
documentView.setTopToolbarEnabled(topToolbarEnabled);
}
@ReactProp(name = "bottomToolbarEnabled")
public void setBottomToolbarEnabled(DocumentView documentView, boolean bottomToolbarEnabled) {
documentView.setBottomToolbarEnabled(bottomToolbarEnabled);
}
@ReactProp(name = "pageIndicatorEnabled")
public void setPageIndicatorEnabled(DocumentView documentView, boolean pageIndicatorEnabled) {
documentView.setPageIndicatorEnabled(pageIndicatorEnabled);
}
@ReactProp(name = "readOnly")
public void setReadOnly(DocumentView documentView, boolean readOnly) {
documentView.setReadOnly(readOnly);
}
@ReactProp(name = "fitMode")
public void setFitMode(DocumentView documentView, String fitMode) {
documentView.setFitMode(fitMode);
}
@ReactProp(name = "layoutMode")
public void setLayoutMode(DocumentView documentView, String layoutMode) {
documentView.setLayoutMode(layoutMode);
}
@ReactProp(name = "continuousAnnotationEditing")
public void setContinuousAnnotationEditing(DocumentView documentView, boolean contEditing) {
documentView.setContinuousAnnotationEditing(contEditing);
}
@ReactProp(name = "annotationAuthor")
public void setAnnotationAuthor(DocumentView documentView, String author) {
documentView.setAnnotationAuthor(author);
}
public void importAnnotations(int tag, String xfdf) throws PDFNetException {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
documentView.importAnnotations(xfdf);
} else {
throw new PDFNetException("", 0L, getName(), "importAnnotations", "Unable to find DocumentView.");
}
}
public String exportAnnotations(int tag, ReadableMap options) throws Exception {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
return documentView.exportAnnotations(options);
} else {
throw new PDFNetException("", 0L, getName(), "exportAnnotations", "Unable to find DocumentView.");
}
}
public void saveDocument(int tag) throws PDFNetException {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
documentView.saveDocument();
} else {
throw new PDFNetException("", 0L, getName(), "saveDocument", "Unable to find DocumentView.");
}
}
public void flattenAnnotations(int tag, boolean formsOnly) throws PDFNetException {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
documentView.flattenAnnotations(formsOnly);
} else {
throw new PDFNetException("", 0L, getName(), "flattenAnnotations", "Unable to find DocumentView.");
}
}
public void setToolMode(int tag, String item) throws PDFNetException {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
documentView.setToolMode(item);
} else {
throw new PDFNetException("", 0L, getName(), "setToolMode", "Unable to find DocumentView.");
}
}
public int getPageCount(int tag) throws PDFNetException {
DocumentView documentView = mDocumentViews.get(tag);
if (documentView != null) {
return documentView.getPageCount();
} else {
throw new PDFNetException("", 0L, getName(), "getPageCount", "Unable to find DocumentView.");
}
}
@Override
public boolean needsCustomLayoutForChildren() {
return true;
}
}