Skip to content

Commit 5dd3e9e

Browse files
Update to PSPDFKit 5.1.1 (#40)
* Update to 5.1.1 * Apply suggestions from code review Co-Authored-By: davidschreiber <[email protected]>
1 parent 6451512 commit 5dd3e9e

File tree

9 files changed

+187
-110
lines changed

9 files changed

+187
-110
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ var options {
7171
disableDocumentEditor: true, // hide document editor (default: false)
7272
disableOutline: true, // hide the outline menu (default: false)
7373
disablePrinting: true, // hide option to print (default: false)
74-
disableShare: true, // hide share button (default: false)
7574
disableUndoRedo: true, // disable undo/redo system (default: false)
7675
hidePageLabels: true, // hide page labels (if available in PDF) in page overlay and thumbnail grid (default: false)
7776
hidePageNumberOverlay: false, // hide the overlay showing the current page (default: false)
@@ -81,6 +80,23 @@ var options {
8180
pageFitMode: PSPDFKit.PageFitMode.FIT_TO_WIDTH, // also valid: PSPDFKit.PageFitMode.FIT_TO_SCREEN
8281
scrollDirection: PSPDFKit.PageScrollDirection.VERTICAL, // also valid: PSPDFKit.PageScrollDirection.HORIZONTAL
8382
scrollMode: PSPDFKit.ScrollMode.CONTINUOUS, // also valid: PSPDFKit.ScrollMode.PER_PAGE
83+
// Configures which share actions should be visible in the user interface. (default: all enabled)
84+
shareFeatures: [
85+
/** Document sharing inside the activity. */
86+
PSPDFKit.ShareFeatures.DOCUMENT_SHARING,
87+
/** Sharing of embedded files (on file annotations). */
88+
PSPDFKit.ShareFeatures.EMBEDDED_FILE_SHARING,
89+
/** Sharing of text from selected free text annotations. */
90+
PSPDFKit.ShareFeatures.FREE_TEXT_ANNOTATION_SHARING,
91+
/** Sharing of selected image annotations. */
92+
PSPDFKit.ShareFeatures.IMAGE_SHARING,
93+
/** Sharing of text from selected note annotations. */
94+
PSPDFKit.ShareFeatures.NOTE_ANNOTATION_SHARING,
95+
/** Sharing of text from annotation contents or comments. */
96+
PSPDFKit.ShareFeatures.NOTE_EDITOR_CONTENT_SHARING,
97+
/** Sharing of selected text. */
98+
PSPDFKit.ShareFeatures.TEXT_SELECTION_SHARING
99+
],
84100
invertColors: false, // invert rendered colors (default: false)
85101
toGrayscale: true, // render document in grayscale only (default: false)
86102
title: "My PSPDFKit app", // title displayed in the viewer action bar
@@ -111,7 +127,7 @@ Create a new Apache Cordova project from your command line using the [Apache Cor
111127

112128
> Important: Your app's package name (in the above example `com.example.pdfapp`) has to match your PSPDFKit license name or PSPDFKit will throw an exception. If you don't have a license yet, you can request an evaluation license of PSPDFKit at https://pspdfkit.com/try.
113129
114-
Add Android platform support to your project. Right now, PSPDFKit 5.0.1 for Cordova is only compatible with the nightly build of `cordova-android` (until https://github.com/apache/cordova-android/pull/507 is available on the stable npm channel):
130+
Add Android platform support to your project. Right now, PSPDFKit 5.1.1 for Cordova is only compatible with the nightly build of `cordova-android` (until https://github.com/apache/cordova-android/pull/507 is available on the stable npm channel):
115131

116132
cordova platform add [email protected]
117133

@@ -171,7 +187,7 @@ It will then ask you if you want to integrate your new app with Cordova, answer
171187
cd todo
172188
```
173189

174-
Add Android platform support. Right now, PSPDFKit 5.0.1 for Cordova is only compatible with the nightly build of `cordova-android` (until https://github.com/apache/cordova-android/pull/507 is available on the stable npm channel):
190+
Add Android platform support. Right now, PSPDFKit 5.1.1 for Cordova is only compatible with the nightly build of `cordova-android` (until https://github.com/apache/cordova-android/pull/507 is available on the stable npm channel):
175191

176192
```shell
177193
ionic cordova platform add [email protected]

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pspdfkit-cordova-android",
3-
"version": "5.0.1",
3+
"version": "5.1.1",
44
"description": "Integration of the PSPDFKit for Android library.",
55
"cordova": {
66
"id": "pspdfkit-cordova-android",
@@ -21,7 +21,7 @@
2121
],
2222
"engines": {
2323
"cordovaDependencies": {
24-
"5.0.1": { "cordova-android": "8.0.0-nightly.2018.11.23.ef243418" }
24+
"5.1.1": { "cordova-android": "8.0.0-nightly.2018.11.23.ef243418" }
2525
}
2626
},
2727
"author": "PSPDFKit",

plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
~ UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
88
~ This notice may not be removed from this file.
99
-->
10-
<plugin id="pspdfkit-cordova-android" version="5.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0"
10+
<plugin id="pspdfkit-cordova-android" version="5.1.1" xmlns="http://apache.org/cordova/ns/plugins/1.0"
1111
xmlns:android="http://schemas.android.com/apk/res/android">
1212
<name>PSPDFKit-Android</name>
1313
<description>Integration of the PSPDFKit for Android library.</description>
@@ -68,4 +68,6 @@ In case there are issues, feel free to reach out to our support team at https://
6868
android:windowSoftInputMode="adjustNothing"/>
6969
</config-file>
7070
</platform>
71+
72+
<dependency id="cordova-plugin-enable-multidex"/>
7173
</plugin>

src/android/config.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ if (pspdfkitIsDemo == null) {
5151
ext.pspdfkitMavenModuleName = pspdfkitIsDemo ? 'pspdfkit-demo' : 'pspdfkit'
5252
ext.pspdfkitVersion = localProperties.getProperty('pspdfkit.version')
5353
if (pspdfkitVersion == null || pspdfkitVersion == '') {
54-
ext.pspdfkitVersion = '5.0.1'
54+
ext.pspdfkitVersion = '5.1.1'
5555
}

src/android/java/com/pspdfkit/cordova/PSPDFKitCordovaPlugin.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import android.content.pm.PackageManager;
1616
import android.graphics.Color;
1717
import android.net.Uri;
18-
import android.support.annotation.NonNull;
19-
import android.support.annotation.Nullable;
2018
import android.text.TextUtils;
2119
import android.view.ContextThemeWrapper;
2220

@@ -27,6 +25,7 @@
2725
import com.pspdfkit.configuration.page.PageFitMode;
2826
import com.pspdfkit.configuration.page.PageScrollDirection;
2927
import com.pspdfkit.configuration.page.PageScrollMode;
28+
import com.pspdfkit.configuration.sharing.ShareFeatures;
3029
import com.pspdfkit.preferences.PSPDFKitPreferences;
3130
import com.pspdfkit.ui.PdfActivity;
3231

@@ -38,9 +37,12 @@
3837
import org.json.JSONException;
3938
import org.json.JSONObject;
4039

41-
import java.io.File;
40+
import java.util.EnumSet;
4241
import java.util.Iterator;
4342

43+
import androidx.annotation.NonNull;
44+
import androidx.annotation.Nullable;
45+
4446
public class PSPDFKitCordovaPlugin extends CordovaPlugin {
4547

4648
private static final String METADATA_LICENSE_KEY = "pspdfkit_license_key";
@@ -132,8 +134,8 @@ public class PSPDFKitCordovaPlugin extends CordovaPlugin {
132134
builder.disablePrinting();
133135
} else if ("disableSearch".equals(option) && ((Boolean) value)) {
134136
builder.disableSearch();
135-
} else if ("disableShare".equals(option) && ((Boolean) value)) {
136-
builder.disableShare();
137+
} else if ("shareFeatures".equals(option)) {
138+
builder.setEnabledShareFeatures(parseShareFeatures((JSONArray) value));
137139
} else if ("disableUndoRedo".equals(option)) {
138140
builder.undoEnabled(!(Boolean) value);
139141
} else if ("hidePageLabels".equals(option) && ((Boolean) value)) {
@@ -203,6 +205,18 @@ public class PSPDFKitCordovaPlugin extends CordovaPlugin {
203205
return builder.build();
204206
}
205207

208+
/** Converts the given string array to an {@link EnumSet} of {@link ShareFeatures}. */
209+
private EnumSet<ShareFeatures> parseShareFeatures(@Nullable JSONArray shareFeatures) throws JSONException {
210+
EnumSet<ShareFeatures> features = ShareFeatures.none();
211+
if (shareFeatures != null) {
212+
for (int i = 0; i < shareFeatures.length(); i++) {
213+
final ShareFeatures feature = ShareFeatures.valueOf(shareFeatures.getString(i));
214+
features.add(feature);
215+
}
216+
}
217+
return features;
218+
}
219+
206220
/**
207221
* Ensures that Javascript "null" strings are correctly converted to javas <code>null</code>.
208222
*/
@@ -232,15 +246,12 @@ private void showDocument(@NonNull Uri documentUri, @Nullable final String passw
232246
* @param callbackContext Cordova callback.
233247
*/
234248
private void showDocumentFromAssets(@NonNull final String assetPath, @Nullable final String password, @NonNull final PdfActivityConfiguration configuration, @NonNull final CallbackContext callbackContext) {
235-
ExtractAssetTask.extract(assetPath, cordova.getActivity(), new ExtractAssetTask.OnDocumentExtractedCallback() {
236-
@Override
237-
public void onDocumentExtracted(File documentFile) {
238-
if (documentFile != null) {
239-
showDocumentForUri(Uri.fromFile(documentFile), password, configuration);
240-
callbackContext.success();
241-
} else {
242-
callbackContext.error("Could not load '" + assetPath + "' from the assets.");
243-
}
249+
ExtractAssetTask.extract(assetPath, cordova.getActivity(), documentFile -> {
250+
if (documentFile != null) {
251+
showDocumentForUri(Uri.fromFile(documentFile), password, configuration);
252+
callbackContext.success();
253+
} else {
254+
callbackContext.error("Could not load '" + assetPath + "' from the assets.");
244255
}
245256
});
246257
}

tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pspdfkit-cordova-android-tests",
3-
"version": "5.0.1",
3+
"version": "5.1.1",
44
"description": "Test suite of the PSPDFKit for Android library Cordova plugin.",
55
"cordova": {
66
"id": "pspdfkit-cordova-android-tests",

tests/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
1111
id="pspdfkit-cordova-android-tests"
12-
version="5.0.1">
12+
version="5.1.1">
1313
<name>PSPDFKit-Android Tests</name>
1414
<license>MIT</license>
1515

0 commit comments

Comments
 (0)