diff --git a/android/build.gradle b/android/build.gradle index 532c5b59..c7a97792 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -23,6 +23,8 @@ rootProject.allprojects { } apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 31 diff --git a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginMethodCallHandler.java b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginMethodCallHandler.java index e27ada93..af0a8394 100644 --- a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginMethodCallHandler.java +++ b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginMethodCallHandler.java @@ -5,6 +5,7 @@ import com.pdftron.common.PDFNetException; import com.pdftron.pdf.PDFNet; import com.pdftron.pdftronflutter.FlutterDocumentActivity; +import com.pdftron.pdftronflutter.kotlin.MyToast; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.EventChannel; @@ -20,6 +21,7 @@ import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_OPEN_DOCUMENT; import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SET_LEADING_NAV_BUTTON_ICON; import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SET_REQUESTED_ORIENTATION; +import static com.pdftron.pdftronflutter.helpers.PluginUtils.FUNCTION_SHOW_MY_TOAST; import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_CONFIG; import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_DOCUMENT; import static com.pdftron.pdftronflutter.helpers.PluginUtils.KEY_LEADING_NAV_BUTTON_ICON; @@ -316,6 +318,10 @@ public void onMethodCall(MethodCall call, Result result) { FlutterDocumentActivity.setOrientation(requestedOrientation); break; } + case FUNCTION_SHOW_MY_TOAST: { + MyToast.show(mContext); + break; + } default: PluginUtils.onMethodCall(call, result, FlutterDocumentActivity.getCurrentActivity()); break; diff --git a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java index 66ca0864..a824876f 100644 --- a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java +++ b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java @@ -354,6 +354,9 @@ public class PluginUtils { public static final String FUNCTION_SET_VERTICAL_SCROLL_POSITION = "setVerticalScrollPosition"; public static final String FUNCTION_GET_VISIBLE_PAGES = "getVisiblePages"; + // Kotlin Toast Method + public static final String FUNCTION_SHOW_MY_TOAST = "showMyToast"; + // Hygen Generated Method Constants public static final String FUNCTION_GET_ANNOTATIONS_ON_PAGE = "getAnnotationsOnPage"; diff --git a/android/src/main/java/com/pdftron/pdftronflutter/kotlin/MyToast.kt b/android/src/main/java/com/pdftron/pdftronflutter/kotlin/MyToast.kt new file mode 100644 index 00000000..6588acb0 --- /dev/null +++ b/android/src/main/java/com/pdftron/pdftronflutter/kotlin/MyToast.kt @@ -0,0 +1,13 @@ +package com.pdftron.pdftronflutter.kotlin + +import android.content.Context +import android.widget.Toast + +class MyToast { + companion object { + @JvmStatic + fun show(context: Context) { + Toast.makeText(context, "Kotlin API Called!!!", Toast.LENGTH_SHORT).show() + } + } +} \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index af24d697..e48c19bc 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -22,6 +22,8 @@ if (flutterVersionName == null) { } apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { diff --git a/example/android/build.gradle b/example/android/build.gradle index e29a4431..8979bdf4 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,4 +1,5 @@ buildscript { + ext.kotlin_version = "1.6.20" repositories { google() mavenCentral() @@ -6,6 +7,8 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.1.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } diff --git a/example/lib/main.dart b/example/lib/main.dart index 45658caf..3a40842e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -208,7 +208,7 @@ class _ViewerState extends State { // }); // Show a dialog when leading navigation button is pressed. - _showMyDialog(); + PdftronFlutter.showMyToast(); }); await controller.openDocument(_document, config: config); diff --git a/lib/pdftron_flutter.dart b/lib/pdftron_flutter.dart index cfc13d2a..9351eb8d 100644 --- a/lib/pdftron_flutter.dart +++ b/lib/pdftron_flutter.dart @@ -4,6 +4,7 @@ library pdftron; import 'dart:async'; import 'dart:convert'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'src/options.dart'; @@ -24,7 +25,8 @@ class PdftronFlutter { /// The current version of the OS that the app is running on. static Future get platformVersion async { - final String version = await _channel.invokeMethod(Functions.getPlatformVersion); + final String version = + await _channel.invokeMethod(Functions.getPlatformVersion); return version; } @@ -43,6 +45,11 @@ class PdftronFlutter { {Parameters.licenseKey: licenseKey}); } + /// Invokes Kotlin Toast API + static Future showMyToast() { + return _channel.invokeMethod(Functions.showMyToast); + } + /// Opens a document in the viewer with configurations. /// /// Uses the path specified by [document]. Takes a [password] for @@ -603,7 +610,7 @@ class PdftronFlutter { static Future exitSearchMode() { return _channel.invokeMethod(Functions.exitSearchMode); } - + /// Zooms the viewer to the given scale using the given coordinate as the center. /// /// The zoom center ([x],[y]) is represented in the screen space, whose origin @@ -612,7 +619,7 @@ class PdftronFlutter { return _channel.invokeMethod(Functions.zoomWithCenter, {"zoom": zoom, "x": x, "y": y}); } - + /// Zooms the viewer to fit the given rectangular area in the specified page. /// /// ```dart @@ -710,9 +717,9 @@ class PdftronFlutter { Parameters.red: red, Parameters.green: green, Parameters.blue: blue - }); + }); } - + /// Gets the horizontal and vertical scroll position in the current document viewer. /// /// The scroll position is returned as a `Map` with the keys @@ -742,7 +749,7 @@ class PdftronFlutter { Parameters.verticalScrollPosition: verticalScrollPosition }); } - + /// Gets the page numbers of currently visible pages in the viewer. static Future?> getVisiblePages() { return _channel.invokeMethod(Functions.getVisiblePages); @@ -751,9 +758,8 @@ class PdftronFlutter { // Hygen Generated Methods /// Gets the list of annotations on the given page. static Future?> getAnnotationsOnPage(int pageNumber) { - return _channel.invokeMethod(Functions.getAnnotationsOnPage, { - Parameters.pageNumber: pageNumber - }).then((jsonArray) { + return _channel.invokeMethod(Functions.getAnnotationsOnPage, + {Parameters.pageNumber: pageNumber}).then((jsonArray) { List annotations = jsonDecode(jsonArray); List annotList = new List.empty(growable: true); for (dynamic annotation in annotations) { diff --git a/lib/src/constants.dart b/lib/src/constants.dart index ac496644..6b5667e9 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -1,4 +1,3 @@ - /// Names of functions. class Functions { static const getPlatformVersion = "getPlatformVersion"; @@ -9,6 +8,7 @@ class Functions { static const getSavedSignatureFolder = "getSavedSignatureFolder"; /// Android only + static const showMyToast = "showMyToast"; static const getSavedSignatureJpgFolder = "getSavedSignatureJpgFolder"; static const importAnnotations = "importAnnotations"; static const exportAnnotations = "exportAnnotations"; @@ -75,7 +75,7 @@ class Functions { static const getScrollPos = "getScrollPos"; static const setHorizontalScrollPosition = "setHorizontalScrollPosition"; static const setVerticalScrollPosition = "setVerticalScrollPosition"; - static const smartZoom = "smartZoom"; + static const smartZoom = "smartZoom"; static const getVisiblePages = "getVisiblePages"; // Hygen Generated Methods @@ -458,4 +458,4 @@ class AnnotationManagerUndoMode { class ToolbarAlignment { static const Start = "GravityStart"; static const End = "GravityEnd"; -} \ No newline at end of file +} diff --git a/pubspec.yaml b/pubspec.yaml index fccaf66f..e0d3c309 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pdftron_flutter description: A convenience wrapper to build Flutter apps that use the PDFTron mobile SDK for smooth, flexible, and stand-alone document viewing. -version: 1.0.1-1 +version: 1.0.1-3 homepage: https://www.pdftron.com repository: https://github.com/PDFTron/pdftron-flutter issue_tracker: https://github.com/PDFTron/pdftron-flutter/issues