Migration guide for Android SDK 4 features
Nutrient Android SDK 4 is a major new release and includes many new features and a few breaking changes.
Removed optionals
We’ve removed our com.pspdfkit.utilities.Optional class that was used when returning objects that may or may not have a value. It has been replaced with the RxJava 2 Maybe(opens in a new tab) class, which is a reactive type that either returns a value in onSuccess(), simply completes in onComplete(), or throws an error in onError(). This is much more convenient to use.
For example, this:
@NonNullpublic Optional<Annotation> getAnnotation(int pageIndex, int objectNumber)
@NonNullpublic Observable<Optional<Annotation>> getAnnotationAsync(int pageIndex, int objectNumber)becomes this:
@Nullablepublic Annotation getAnnotation(int pageIndex, int objectNumber)
@NonNullpublic Maybe<Annotation> getAnnotationAsync(int pageIndex, int objectNumber)Here is the full list of modified methods:
AnnotationProvider#getAnnotationAsync(int, int)fromObservable<Optional<Annotation>>toMaybe<Annotation>.AnnotationProvider#getAnnotation(int, int)fromOptional<Annotation>to@Nullable Annotation.FormProvider#getFormElementForAnnotationAsync()fromObservable<Optional<FormElement>>toMaybe<FormElement>.FormProvider#getFormElementForAnnotation()fromOptional<FormElement>to@Nullable FormElement.FormProvider#getFormFieldWithFullyQualifiedNameAsync()fromObservable<Optional<FormElement>>toMaybe<FormElement>.FormProvider#getFormFieldWithFullyQualifiedName()fromOptional<FormElement>to@Nullable FormElement.FormProvider#getFormElementWithNameAsync()fromObservable<Optional<FormElement>>toMaybe<FormElement>.FormProvider#getFormElementWithName()fromOptional<FormElement>to@Nullable FormElement.WidgetAnnotation#getFormElementAsync()fromObservable<Optional<FormElement>>toMaybe<FormElement>.WidgetAnnotation#getFormElement()fromOptional<FormElement>to@Nullable FormElement.
New Android SDK version
We’ve updated our SDK to fully support Android 8.0 Oreo. In order to ensure that everything works as expected, it is required that you update the compileSdkVersion in the build.gradle of your application to 26. We also increased the minimum required version to Android 4.4 KitKat (API Level 19), so you also need to update your minSdkVersion to 19. If you are using Kotlin in your application, this change will require that you update all your findViewById calls.
For example, this:
val textView = findViewById(R.id.textview) as TextViewbecomes this:
val textView: TextView = findViewById(R.id.textview)If you are still using Java, Android Studio will remind you to remove the cast.
For example, this:
TextView textView = (TextView) findViewById(R.id.textview);becomes this:
TextView textView = findViewById(R.id.textview);Updated dependencies
We’ve updated RxJava to 2.1.3. If you’re using the recommended Maven repository approach to add Nutrient to your project, you don’t have to do anything; the dependency will be updated automatically.
If you’re not using our Maven repository, make sure to update dependencies to the new version:
implementation 'io.reactivex.rxjava2:rxjava:2.1.3'ProGuard rules
There is no longer a need to specify additional ProGuard rules since Nutrient uses consumersProguardFiles to keep ProGuard from obfuscating the required symbols. For more information, check our ProGuard section in the guides.
Unified naming for listeners
We’ve cleaned up all inconsistent names of callbacks and their management methods in order to unify our APIs and be consistent with Android framework styles.
Here is the full list of changes:
- Renamed
DownloadDocumentTask.DownloadedFileCallbacktoDownloadDocumentTask.OnFileDownloadedListener. - Renamed
ExtractAssetTask.OnDocumentExtractedCallbacktoExtractAssetTask.OnDocumentExtractedListener. - Renamed
InstantPdfDocument#registerInstantDocumentListenertoInstantPdfDocument#addInstantDocumentListener. - Renamed
InstantPdfDocument#unregisterInstantDocumentListenertoInstantPdfDocument#removeInstantDocumentListener. - Renamed
InstantPdfFragment#registerInstantDocumentListenertoInstantPdfFragment#addInstantDocumentListener. - Renamed
InstantPdfFragment#unregisterInstantDocumentListenertoInstantPdfFragment#removeInstantDocumentListener. - Renamed
OnAnnotationProviderUpdatedListener#onAnnotationDeletedtoOnAnnotationProviderUpdatedListener#onAnnotationRemoved. - Renamed
AnnotationProvider.OnAnnotationProviderUpdatedListenertoAnnotationProvider.OnAnnotationUpdatedListener. - Renamed
AnnotationProvider#registerOnAnnotationProviderUpdatedListenertoAnnotationProvider#addOnAnnotationUpdatedListener. - Renamed
AnnotationProvider#unregisterOnAnnotationProviderUpdatedListenertoAnnotationProvider#removeOnAnnotationUpdatedListener. - Renamed
ActionResolver#registerDocumentActionListenertoActionResolver#addDocumentActionListener. - Renamed
ActionResolver#unregisterDocumentActionListenertoActionResolver#removeDocumentActionListener. - Renamed
NewPageFactory.OnNewPageReadyCallbacktoNewPageFactory.OnNewPageReadyListener. - Renamed
PdfLibrary#registerLibraryIndexingListenertoPdfLibrary#addLibraryIndexingListener. - Renamed
PdfLibrary#unregisterLibraryIndexingListenertoPdfLibrary#removeLibraryIndexingListener. - Renamed
FormProvider#registerOnFormFieldUpdatedListenertoFormProvider#addOnFormFieldUpdatedListener. - Renamed
FormProvider#unregisterOnFormFieldUpdatedListenertoFormProvider#removeOnFormFieldUpdatedListener. - Renamed
FormProvider#registerOnFormTabOrderUpdatedListenertoFormProvider#addOnFormTabOrderUpdatedListener. - Renamed
FormProvider#unregisterOnFormTabOrderUpdatedListenertoFormProvider#removeOnFormTabOrderUpdatedListener. - Renamed
FormProvider#registerOnTextFormFieldUpdatedListenertoFormProvider#addOnTextFormFieldUpdatedListener. - Renamed
FormProvider#unregisterOnTextFormFieldUpdatedListenertoFormProvider#removeOnTextFormFieldUpdatedListener. - Renamed
FormProvider#registerOnButtonFormFieldUpdatedListenertoFormProvider#addOnButtonFormFieldUpdatedListener. - Renamed
FormProvider#unregisterOnButtonFormFieldUpdatedListenertoFormProvider#removeOnButtonFormFieldUpdatedListener. - Renamed
FormProvider#registerOnChoiceFormFieldUpdatedListenertoFormProvider#addOnChoiceFormFieldUpdatedListener. - Renamed
FormProvider#unregisterOnChoiceFormFieldUpdatedListenertoFormProvider#removeOnChoiceFormFieldUpdatedListener. - Renamed
DefaultDocumentEditorListener.UriValidationCallbacktoDefaultDocumentEditorListener.UriValidationListener. - Renamed
PdfDocumentEditorListenerCallbacktoOnFileWriteCompleteListener. - Renamed
PSPDFKitViews#setDocumentEditorListenertoPSPDFKitViews#setPdfDocumentEditorListener. - Renamed
PdfFragment#registerDocumentListenertoPdfFragment#addDocumentListener. - Renamed
PdfFragment#unregisterDocumentListenertoPdfFragment#removeDocumentListener. - Renamed
PdfFragment#registerDocumentScrollListenertoPdfFragment#addDocumentScrollListener. - Renamed
PdfFragment#unregisterDocumentScrollListenertoPdfFragment#removeDocumentScrollListener. - Renamed
PdfOutlineView.OnAnnotationTappedListenertoPdfOutlineView.OnAnnotationTapListenerand itsonAnnotationTappedmethod toonAnnotationTap. - Renamed
PdfOutlineView.OnOutlineElementTappedListenertoPdfOutlineView.OnOutlineElementTapListenerand itsonOutlineElementTappedmethod toonOutlineElementTap. - Renamed
PdfOutlineView#setOnAnnotationTappedListenertoPdfOutlineView#setOnAnnotationTapListener. - Renamed
PdfOutlineView#setOnOutlineElementTappedListenertoPdfOutlineView#setOnOutlineElementTapListener. - Renamed
PdfThumbnailGrid#setDocumentEditorListenertoPdfThumbnailGrid#setPdfDocumentEditorListener. - Renamed
PdfThumbnailGrid#registerDocumentEditingModeChangeListenertoPdfThumbnailGrid#addOnDocumentEditingModeChangeListener. - Renamed
PdfThumbnailGrid#unregisterDocumentEditingModeChangeListenertoPdfThumbnailGrid#removeOnDocumentEditingModeChangeListener. - Renamed
PdfThumbnailGrid#registerDocumentEditingPageSelectionChangeListenertoPdfThumbnailGrid#addOnDocumentEditingPageSelectionChangeListener. - Renamed
PdfThumbnailGrid#unregisterDocumentEditingPageSelectionChangeListenertoPdfThumbnailGrid#removeOnDocumentEditingPageSelectionChangeListener. - Renamed
ActionMenu#registerActionMenuListenertoActionMenu#addActionMenuListener. - Renamed
ActionMenu#unregisterActionMenuListenertoActionMenu#removeActionMenuListener. - Renamed
FormEditingBar#registerFormEditingBarLifecycleListenertoFormEditingBar#addOnFormEditingBarLifecycleListener. - Renamed
FormEditingBar#unregisterFormEditingBarLifecycleListenertoFormEditingBar#removeOnFormEditingBarLifecycleListener. - Renamed
PropertyInspectorCoordinatorLayoutController#registerPropertyInspectorLifecycleListenertoPropertyInspectorCoordinatorLayoutController#addPropertyInspectorLifecycleListener. - Renamed
PropertyInspectorCoordinatorLayoutController#unregisterPropertyInspectorLifecycleListenertoPropertyInspectorCoordinatorLayoutController#removePropertyInspectorLifecycleListener. - Renamed
BookmarkViewAdapter#registerBookmarkChangeListenertoBookmarkViewAdapter#addBookmarkListener. - Renamed
BookmarkViewAdapter#unregisterBookmarkChangeListertoBookmarkViewAdapter#removeBookmarkListener. - Renamed
OnModeChangedListener#OnPageTransitionChangedtoOnModeChangedListener#OnScrollModeChange. - Renamed
OnModeChangedListener#OnScrollDirectionChangedtoOnModeChangedListener#OnScrollDirectionChange. - Renamed
OnModeChangedListener#OnPageLayoutChangedtoOnModeChangedListener#OnPageLayoutChange. - Renamed
OnModeChangedListener#OnThemeChangedtoOnModeChangedListener#OnThemeChange. - Renamed
OnModeChangedListener#OnScreenTimeoutChangedtoOnModeChangedListener#OnScreenTimeoutChange. - Renamed
AnnotationManager#registerAnnotationSelectedListenertoAnnotationManager#addOnAnnotationSelectedListener. - Renamed
AnnotationManager#unregisterAnnotationSelectedListenertoAnnotationManager#removeOnAnnotationSelectedListener. - Renamed
AnnotationManager#registerAnnotationDeselectedListenertoAnnotationManager#addOnAnnotationDeselectedListener. - Renamed
AnnotationManager#unregisterAnnotationDeselectedListenertoAnnotationManager#removeOnAnnotationDeselectedListener. - Renamed
AnnotationManager#registerAnnotationUpdatedListenertoAnnotationManager#addOnAnnotationUpdatedListener. - Renamed
AnnotationManager#unregisterAnnotationUpdatedListenertoAnnotationManager#removeOnAnnotationUpdatedListener. - Renamed
AnnotationManager#registerAnnotationCreationModeChangeListenertoAnnotationManager#addOnAnnotationCreationModeChangeListener. - Renamed
AnnotationManager#unregisterAnnotationCreationModeChangeListenertoAnnotationManager#removeOnAnnotationCreationModeChangeListener. - Renamed
AnnotationManager#registerAnnotationCreationModeSettingsChangeListenertoAnnotationManager#addOnAnnotationCreationModeSettingsChangeListener. - Renamed
AnnotationManager#unregisterAnnotationCreationModeSettingsChangeListenertoAnnotationManager#removeOnAnnotationCreationModeSettingsChangeListener. - Renamed
AnnotationManager#registerAnnotationEditingModeChangeListenertoAnnotationManager#addOnAnnotationEditingModeChangeListener. - Renamed
AnnotationManager#unregisterAnnotationEditingModeChangeListenertoAnnotationManager#removeOnAnnotationEditingModeChangeListener. - Renamed
DocumentEditingManager#registerDocumentEditingModeChangeListenertoDocumentEditingManager#addOnDocumentEditingModeChangeListener. - Renamed
DocumentEditingManager#unregisterDocumentEditingModeChangeListenertoDocumentEditingManager#removeOnDocumentEditingModeChangeListener. - Renamed
DocumentEditingManager#registerDocumentEditingPageSelectionChangeListenertoDocumentEditingManager#addOnDocumentEditingPageSelectionChangeListener. - Renamed
DocumentEditingManager#unregisterDocumentEditingPageSelectionChangeListenertoDocumentEditingManager#removeOnDocumentEditingPageSelectionChangeListener. - Renamed
FormManager#registerFormElementSelectedListenertoFormManager#addOnFormElementSelectedListener. - Renamed
FormManager#unregisterFormElementSelectedListenertoFormManager#removeOnFormElementSelectedListener. - Renamed
FormManager#registerFormElementDeselectedListenertoFormManager#addOnFormElementDeselectedListener. - Renamed
FormManager#unregisterFormElementDeselectedListenertoFormManager#removeOnFormElementDeselectedListener. - Renamed
FormManager#registerFormElementUpdatedListenertoFormManager#addOnFormElementUpdatedListener. - Renamed
FormManager#unregisterFormElementUpdatedListenertoFormManager#removeOnFormElementUpdatedListener. - Renamed
FormManager#registerFormElementEditingModeChangeListenertoFormManager#addOnFormElementEditingModeChangeListener. - Renamed
FormManager#unregisterFormElementEditingModeChangeListenertoFormManager#removeOnFormElementEditingModeChangeListener. - Renamed
FormManager#registerFormElementClickedListenertoFormManager#addOnFormElementClickedListener. - Renamed
FormManager#unregisterFormElementClickedListenertoFormManager#removeOnFormElementClickedListener. - Renamed
TextSelectionManager#registerTextSelectionModeChangeListenertoTextSelectionManager#addOnTextSelectionModeChangeListener. - Renamed
TextSelectionManager#unregisterTextSelectionModeChangeListenertoTextSelectionManager#removeOnTextSelectionModeChangeListener. - Renamed
TextSelectionManager#registerTextSelectionChangeListenertoTextSelectionManager#addOnTextSelectionChangeListener. - Renamed
TextSelectionManager#unregisterTextSelectionChangeListenertoTextSelectionManager#removeOnTextSelectionChangeListener. - Changed
ContextualToolbar#setToolbarCoordinatorControllerto accept@Nullable ToolbarCoordinatorLayoutControllerso that you can clear it by passingnull. - Removed
ContextualToolbar#removeToolbarCoordinatorController; useContextualToolbar#setToolbarCoordinatorController(null)instead. - Changed
ContextualToolbar#setOnMenuItemClickListenerto accept@Nullable OnMenuItemClickListenerso that you can clear it by passingnull. - Removed
ContextualToolbar#removeOnMenuItemClickListener; useContextualToolbar#setOnMenuItemClickListener(null)instead. - Changed
ContextualToolbar#setOnMenuItemLongClickListenerto accept@Nullable OnMenuItemLongClickListenerso that you can clear it by passingnull. - Removed
ContextualToolbar#removeOnMenuItemClickListener; useContextualToolbar#setOnMenuItemLongClickListener(null)instead. - Deprecated
AnnotationManager.OnAnnotationUpdatedListener, useAnnotationProvider.OnAnnotationUpdatedListenerinstead.
Dropped deprecated fields and methods
Here is the full list of what we’ve dropped:
- Removed
PdfActivityConfiguration.Builder#diskCacheSize(),PdfConfiguration.Builder#diskCacheSize()— disk cache is not supported. - Removed
PdfDocument#getUri()andPdfDocument#getUriList(). - Removed
PdfYouTubeActivity#ARG_YOUTUBE_URL; use#ARG_MEDIA_URIfor passingMediaUriobjects through intent. - Removed
PdfMediaDialog#ARG_URI; use#ARG_MEDIA_URIfor passingMediaUriobjects through intent. - Removed
PrintOptions(PdfProcessorTask.AnnotationProcessingMode, ..)constructors; usePrintOptions(boolean, ..)instead. - Removed
PdfFragment#enterAnnotationCreationMode(AnnotationType); useenterAnnotationCreationMode(AnnotationTool)instead. - Removed
PdfFragment#clearTextSelection(); useexitCurrentlyActiveMode()instead. - Removed
PdfFragment#setTextSelection(); useenterTextSelectionMode()instead. - Removed
DocumentSharingManager#generateDocumentName(); usegetTitle()instead.
Renamed HUD terminology to user interface
We’ve replaced the term HUD in our codebase with “user interface” and applied proper camel casing on symbol names:
- Renamed
HudViewModeenum toUserInterfaceViewMode, and all its values begin withUSER_INTERFACEnow. - Renamed
getHudViewMode()togetUserInterfaceViewMode()onPdfActivityConfiguration,PdfActivity, andPdfActivityApi. Its new return type is nowUserInterfaceViewMode. - Renamed
setHudViewMode(HudViewMode)tosetUserInterfaceViewMode(UserInterfaceViewMode)onPdfActivityConfiguration,PdfActivity, andPdfActivityApi. - Renamed
HudViewModetoUserInterfaceViewModeonPdfActivityConfiguration.Builder.
Supplementary changes
This last section is for changes that don’t apply to a specific section:
- Replaced
AnnotationTypewithAnnotationToolinAnnotationPreferencesManagermethods. - Changed the thickness property type of
AnnotationCreationControllerfrominttofloat.
You can see the full list of changes in the Android changelog.