Skip to content

Commit ecde208

Browse files
authored
Merge pull request #10 from PSPDFKit/izacus/pspdfkit_android_300
Update React Native bindings for PSPDFKit Android 3.0.0
2 parents 4ac0774 + 89e3f92 commit ecde208

File tree

8 files changed

+106
-106
lines changed

8 files changed

+106
-106
lines changed

README.md

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -111,64 +111,42 @@ PSPDFKit.present('document.pdf', {
111111
- Android SDK
112112
- Android Build Tools 23.0.1 (React Native)
113113
- Android Build Tools 25.0.2 (PSPDFKit module)
114-
- PSPDFKit >= 2.9.3
114+
- PSPDFKit >= 3.0.0
115115
- react-native >= 0.41.2
116116

117117
#### Getting Started
118118

119-
Let's create a simple app that integrates `pspdfkit-*.aar` and uses the react-native-pspdfkit module.
119+
Let's create a simple app that integrates PSPDFKit and uses the react-native-pspdfkit module.
120120

121121
1. Make sure `react-native-cli` is installed: `yarn global add react-native-cli`
122122
2. Create the app with `react-native init YourApp`.
123123
3. Step into your newly created app folder: `cd YourApp`.
124124
4. Install `react-native-pspdfkit` from GitHub: `yarn add github:PSPDFKit/react-native`.
125-
5. Link module `react-native-pspdfkit`: `react-native link react-native-pspdfkit`.
126-
6. Add dependencies to `YourApp/node_modules/react-native-pspdfkit/android/build.gradle`.
127-
128-
A complete list of the dependencies needed can be found in the [documentation](https://pspdfkit.com/guides/android/current/getting-started/integrating-pspdfkit/#toc_manual-library-file-integration) step 6, under `Manual library file integration`.
129-
For PSPDFKit 2.9.3 :
130-
131-
```
132-
dependencies {
133-
...
134-
//compile 'com.pspdfkit:pspdfkit:2.9.3@aar' <-- DO NOT ADD THE LIBRARY ITSELF
135-
compile 'com.android.support:support-v4:25.1.+'
136-
compile 'com.android.support:appcompat-v7:25.1.+'
137-
compile "com.android.support:recyclerview-v7:25.1.+"
138-
compile "com.android.support:cardview-v7:25.1.+"
139-
compile "com.android.support:design:25.1.+"
140-
compile 'io.reactivex:rxjava:1.2.6'
141-
compile 'io.reactivex:rxandroid:1.2.1'
142-
compile 'com.getkeepsafe.relinker:relinker:1.2.2'
143-
}
125+
5. Link module `react-native-pspdfkit`: `react-native link react-native-pspdfkit`.
126+
6. Add PSPDFKit repository to `YourApp/android/build.gradle` so PSPDFKit library can be downloaded:
127+
128+
```diff
129+
allprojects {
130+
repositories {
131+
mavenLocal()
132+
jcenter()
133+
+ maven {
134+
+ url 'https://customers.pspdfkit.com/maven/'
135+
136+
+ credentials {
137+
+ username 'pspdfkit'
138+
+ password 'YOUR_MAVEN_KEY_GOES_HERE'
139+
+ }
140+
+ }
141+
maven {
142+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
143+
url "$rootDir/../node_modules/react-native/android"
144+
}
145+
}
146+
}
144147
```
145148

146-
7. Add the following lines to `YourApp/android/settings.gradle` file:
147-
148-
```
149-
include ':pspdfkit-lib'
150-
```
151-
152-
8. Create new `pspdfkit-lib` folder in `YourApp/android`.
153-
9. Create new `build.gradle` file in `YourApp/android/pspdfkit-lib` and add the following lines:
154-
155-
```
156-
configurations.maybeCreate("default")
157-
def library = fileTree(".").filter { it.isFile() }.filter { it.name.endsWith('.aar') }.files.name.first()
158-
artifacts.add("default", file(library))
159-
```
160-
161-
10. Copy `pspdfkit-*.aar` library in `YourApp/android/pspdfkit-lib`.
162-
11. Add the following dependencies to `YourApp/android/app/build.gradle` file:
163-
164-
```
165-
dependencies {
166-
...
167-
compile project(':pspdfkit-lib')
168-
}
169-
```
170-
171-
And modify the following lines (note **three** places to edit):
149+
7. PSPDFKit targets modern platforms, so you'll have to update `compileSdkVersion` and `targetSdkVersion` to at least API 25 (note **three** places to edit):
172150

173151
```diff
174152
...
@@ -192,15 +170,28 @@ artifacts.add("default", file(library))
192170
...
193171
```
194172
195-
12. Set primary color. In `YourApp/android/app/src/main/res/values/styles.xml` replace
173+
8. Enter your PSPDFKit license key into `YourApp/android/app/src/main/AndroidManifest.xml` file:
174+
175+
```diff
176+
<application>
177+
...
178+
179+
+ <meta-data
180+
+ android:name="pspdfkit_license_key"
181+
+ android:value="YOUR_LICENSE_KEY_GOES_HERE"/>
182+
183+
</application>
184+
```
185+
186+
9. Set primary color. In `YourApp/android/app/src/main/res/values/styles.xml` replace
196187
```xml
197188
<!-- Customize your theme here. -->
198189
```
199190
with
200191
```xml
201192
<item name="colorPrimary">#3C97C9</item>
202193
```
203-
13. Replace the default component from `YourApp/index.android.js` with a simple touch area to present a PDF document from the local device filesystem:
194+
10. Replace the default component from `YourApp/index.android.js` with a simple touch area to present a PDF document from the local device filesystem:
204195

205196
```javascript
206197
import React, { Component } from 'react';
@@ -224,7 +215,6 @@ with
224215
pageScrollDirection : "vertical"
225216
};
226217

227-
PSPDFKit.setLicenseKey(LICENSE);
228218
// Change 'YourApp' to your app's name.
229219
class YourApp extends Component {
230220
_onPressButton() {
@@ -276,13 +266,13 @@ with
276266
// Change both 'YourApp's to your app's name.
277267
AppRegistry.registerComponent('YourApp', () => YourApp);
278268
```
279-
14. Before launching the app you need to copy a PDF document onto your development device or emulator.
269+
11. Before launching the app you need to copy a PDF document onto your development device or emulator.
280270

281271
```bash
282272
adb push /path/to/your/document.pdf /sdcard/document.pdf
283273
```
284274

285-
15. Your app is now ready to launch. From `YourApp` directory run `react-native run-android`.
275+
12. Your app is now ready to launch. From `YourApp` directory run `react-native run-android`.
286276

287277
```bash
288278
react-native run-android
@@ -291,28 +281,33 @@ with
291281
#### Running Catalog Project
292282

293283
1. Clone the repository. `git clone https://github.com/PSPDFKit/react-native.git`.
294-
2. Add dependencies to `android/build.gradle` (not `samples/Catalog/android/build.gradle`).
295-
296-
A complete list of the dependencies needed can be found in the [documentation](https://pspdfkit.com/guides/android/current/getting-started/integrating-pspdfkit/#toc_manual-library-file-integration) step 6, under `Manual library file integration`.
297-
For PSPDFKit 2.9.3 :
298-
299-
```
300-
dependencies {
301-
...
302-
//compile 'com.pspdfkit:pspdfkit:2.9.3@aar' <-- DO NOT ADD THE LIBRARY ITSELF
303-
compile 'com.android.support:support-v4:25.1.+'
304-
compile 'com.android.support:appcompat-v7:25.1.+'
305-
compile "com.android.support:recyclerview-v7:25.1.+"
306-
compile "com.android.support:cardview-v7:25.1.+"
307-
compile "com.android.support:design:25.1.+"
308-
compile 'io.reactivex:rxjava:1.2.6'
309-
compile 'io.reactivex:rxandroid:1.2.1'
310-
compile 'com.getkeepsafe.relinker:relinker:1.2.2'
311-
}
284+
2. Install dependencies: run `yarn install` from `samples/Catalog` directory. (Because of a [bug](https://github.com/yarnpkg/yarn/issues/2165) you may need to clean `yarn`'s cache with `yarn cache clean` before.)
285+
3. Add your customer portal password to `samples/Catalog/build.gradle`:
286+
287+
```groovy
288+
maven {
289+
url 'https://customers.pspdfkit.com/maven/'
290+
291+
credentials {
292+
username 'pspdfkit'
293+
password 'YOUR_MAVEN_PASSWORD_GOES_HERE'
294+
}
295+
}
296+
```
297+
298+
4. Update license key in `samples/Catalog/android/app/src/main/AndroidManifest.xml`:
299+
300+
```xml
301+
<application>
302+
...
303+
304+
<meta-data
305+
android:name="pspdfkit_license_key"
306+
android:value="YOUR_LICENSE_KEY_GOES_HERE"/>
307+
308+
</application>
312309
```
313310
314-
3. Copy `pspdfkit-*.aar` library in `samples/Catalog/android/pspdfkit-lib`.
315-
4. Install dependencies: run `yarn install` from `samples/Catalog` directory. (Because of a [bug](https://github.com/yarnpkg/yarn/issues/2165) you may need to clean `yarn`'s cache with `yarn cache clean` before.)
316311
5. Catalog app is now ready to launch. From `samples/Catalog` directory run `react-native run-android`.
317312
318313
#### Configuration

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
}
55

66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.2.3'
7+
classpath 'com.android.tools.build:gradle:2.3.0'
88
}
99
}
1010

@@ -26,6 +26,6 @@ android {
2626
}
2727

2828
dependencies {
29+
compile 'com.pspdfkit:pspdfkit:3.0.0'
2930
compile 'com.facebook.react:react-native:+'
30-
compile project(':pspdfkit-lib')
3131
}

android/src/main/java/com/pspdfkit/react/ConfigurationAdapter.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import com.facebook.react.bridge.ReadableMap;
2020
import com.facebook.react.bridge.ReadableMapKeySetIterator;
21-
import com.pspdfkit.configuration.activity.HUDViewMode;
22-
import com.pspdfkit.configuration.activity.PSPDFActivityConfiguration;
21+
import com.pspdfkit.configuration.activity.HudViewMode;
22+
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;
2323
import com.pspdfkit.configuration.annotations.AnnotationEditingConfiguration;
2424
import com.pspdfkit.configuration.page.PageFitMode;
2525
import com.pspdfkit.configuration.page.PageScrollDirection;
@@ -32,7 +32,7 @@ public class ConfigurationAdapter {
3232
private static final String PAGE_SCROLL_CONTINUOUS = "scrollContinuously";
3333
private static final String FIT_PAGE_TO_WIDTH = "fitPageToWidth";
3434
private static final String IMMERSIVE_MODE = "immersiveMode";
35-
private static final String SYSTEM_HUD_MODE = "hudViewMode";
35+
private static final String SYSTEM_HUD_MODE = "HudViewMode";
3636
private static final String HUD_VIEW_MODE_AUTOMATIC = "automatic";
3737
private static final String HUD_VIEW_MODE_AUTOMATIC_BORDER_PAGES = "automaticBorderPages";
3838
private static final String HUD_VIEW_MODE_ALWAYS_VISIBLE = "alwaysVisible";
@@ -53,19 +53,19 @@ public class ConfigurationAdapter {
5353
private static final String SHOW_SHARE_ACTION = "showShareAction";
5454
private static final String SHOW_PRINT_ACTION = "showPrintAction";
5555

56-
private final PSPDFActivityConfiguration.Builder configuration;
56+
private final PdfActivityConfiguration.Builder configuration;
5757
private final Activity activity;
5858

5959

60-
public ConfigurationAdapter(@NonNull Activity activity, @NonNull String licenseKey, ReadableMap configuration) {
60+
public ConfigurationAdapter(@NonNull Activity activity, ReadableMap configuration) {
6161

6262
this.activity = activity;
6363
ReadableMapKeySetIterator iterator = configuration.keySetIterator();
6464
boolean emptyConfiguration = iterator.hasNextKey() ? false : true;
6565
if (emptyConfiguration) {
66-
this.configuration = getDefaultConfiguration(activity, licenseKey);
66+
this.configuration = getDefaultConfiguration(activity);
6767
} else {
68-
this.configuration = new PSPDFActivityConfiguration.Builder(activity, licenseKey);
68+
this.configuration = new PdfActivityConfiguration.Builder(activity);
6969

7070
if (configuration.hasKey(PAGE_SCROLL_DIRECTION)) {
7171
configurePageScrollDirection(configuration.getString(PAGE_SCROLL_DIRECTION));
@@ -157,7 +157,7 @@ private void configureFitPageToWidth(boolean fitPageToWidth) {
157157
}
158158

159159
private void configureInlineSearch(boolean inlineSearch) {
160-
final int searchType = inlineSearch ? PSPDFActivityConfiguration.SEARCH_INLINE : PSPDFActivityConfiguration.SEARCH_MODULAR;
160+
final int searchType = inlineSearch ? PdfActivityConfiguration.SEARCH_INLINE : PdfActivityConfiguration.SEARCH_MODULAR;
161161
configuration.setSearchType(searchType);
162162
}
163163

@@ -166,15 +166,15 @@ private void configureStartPage(int startPage) {
166166
}
167167

168168
private void configureSystemHudMode(String systemHudMode) {
169-
HUDViewMode hudMode = HUDViewMode.HUD_VIEW_MODE_AUTOMATIC;
169+
HudViewMode hudMode = HudViewMode.HUD_VIEW_MODE_AUTOMATIC;
170170
if (systemHudMode.equals(HUD_VIEW_MODE_AUTOMATIC)) {
171-
hudMode = HUDViewMode.HUD_VIEW_MODE_AUTOMATIC;
171+
hudMode = HudViewMode.HUD_VIEW_MODE_AUTOMATIC;
172172
} else if (systemHudMode.equals(HUD_VIEW_MODE_AUTOMATIC_BORDER_PAGES)) {
173-
hudMode = HUDViewMode.HUD_VIEW_MODE_AUTOMATIC_BORDER_PAGES;
173+
hudMode = HudViewMode.HUD_VIEW_MODE_AUTOMATIC_BORDER_PAGES;
174174
} else if (systemHudMode.equals(HUD_VIEW_MODE_ALWAYS_VISIBLE)) {
175-
hudMode = HUDViewMode.HUD_VIEW_MODE_VISIBLE;
175+
hudMode = HudViewMode.HUD_VIEW_MODE_VISIBLE;
176176
} else if (systemHudMode.equals(HUD_VIEW_MODE_ALWAYS_HIDDEN)) {
177-
hudMode = HUDViewMode.HUD_VIEW_MODE_HIDDEN;
177+
hudMode = HudViewMode.HUD_VIEW_MODE_HIDDEN;
178178
}
179179
configuration.setHudViewMode(hudMode);
180180
}
@@ -269,20 +269,20 @@ private void configureEnableTextSelection(boolean enableTextSelection) {
269269
configuration.textSelectionEnabled(enableTextSelection);
270270
}
271271

272-
public PSPDFActivityConfiguration build() {
272+
public PdfActivityConfiguration build() {
273273
return configuration.build();
274274
}
275275

276-
public static PSPDFActivityConfiguration.Builder getDefaultConfiguration(Context context, String license) {
276+
public static PdfActivityConfiguration.Builder getDefaultConfiguration(Context context) {
277277

278278
final PageScrollDirection pageScrollDirection = PageScrollDirection.HORIZONTAL;
279279
final PageScrollMode pageScrollMode = PageScrollMode.PER_PAGE;
280280
final PageFitMode pageFitMode = PageFitMode.FIT_TO_WIDTH;
281-
final int searchType = PSPDFActivityConfiguration.SEARCH_INLINE;
282-
final HUDViewMode hudViewMode = HUDViewMode.HUD_VIEW_MODE_AUTOMATIC;
281+
final int searchType = PdfActivityConfiguration.SEARCH_INLINE;
282+
final HudViewMode hudViewMode = HudViewMode.HUD_VIEW_MODE_AUTOMATIC;
283283
int startPage = 0;
284284

285-
PSPDFActivityConfiguration.Builder configuration = new PSPDFActivityConfiguration.Builder(context, license)
285+
PdfActivityConfiguration.Builder configuration = new PdfActivityConfiguration.Builder(context)
286286
.scrollDirection(pageScrollDirection)
287287
.scrollMode(pageScrollMode)
288288
.fitMode(pageFitMode)

android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.facebook.react.bridge.ReactMethod;
2121
import com.facebook.react.bridge.ReadableMap;
2222
import com.pspdfkit.PSPDFKit;
23-
import com.pspdfkit.ui.PSPDFActivity;
23+
import com.pspdfkit.ui.PdfActivity;
2424

2525
import java.util.HashMap;
2626
import java.util.Map;
@@ -40,20 +40,16 @@ public String getName() {
4040
return "PSPDFKit";
4141
}
4242

43-
@ReactMethod
44-
public void setLicenseKey(@NonNull String licenseKey) {
45-
this.licenseKey = licenseKey;
46-
}
47-
4843
@ReactMethod
4944
public void present(@NonNull String document, @NonNull ReadableMap configuration) {
5045
if (getCurrentActivity() != null) {
51-
ConfigurationAdapter configurationAdapter = new ConfigurationAdapter(getCurrentActivity(), licenseKey, configuration);
46+
ConfigurationAdapter configurationAdapter = new ConfigurationAdapter(getCurrentActivity(), configuration);
5247
// This is an edge case where file scheme is missing.
5348
if (Uri.parse(document).getScheme() == null) {
5449
document = FILE_SCHEME + document;
5550
}
56-
PSPDFActivity.showDocument(getCurrentActivity(), Uri.parse(document), configurationAdapter.build());
51+
52+
PdfActivity.showDocument(getCurrentActivity(), Uri.parse(document), configurationAdapter.build());
5753
}
5854
}
5955

samples/Catalog/android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
</intent-filter>
2727
</activity>
2828
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
29+
30+
<meta-data
31+
android:name="pspdfkit_license_key"
32+
android:value="YOUR_LICENSE_KEY_GOES_HERE"/>
2933
</application>
3034

3135
</manifest>

samples/Catalog/android/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.3'
8+
classpath 'com.android.tools.build:gradle:2.3.0'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
@@ -16,6 +16,14 @@ allprojects {
1616
repositories {
1717
mavenLocal()
1818
jcenter()
19+
maven {
20+
url 'https://customers.pspdfkit.com/maven/'
21+
22+
credentials {
23+
username 'pspdfkit'
24+
password 'YOUR_MAVEN_KEY_GOES_HERE'
25+
}
26+
}
1927
maven {
2028
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
2129
url "$rootDir/../node_modules/react-native/android"

samples/Catalog/android/pspdfkit-lib/build.gradle

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)