diff --git a/README.md b/README.md index 0515fc2..f2020f3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # android-native-sdk -A lightweight SDK that allows for easy integration of eko videos into an Android app +A lightweight SDK that allows for easy integration of eko projects into an Android app # Usage Add the Gradle dependency to your application's build.gradle file @@ -9,6 +9,11 @@ implementation 'com.eko:android-native-sdk:0.0.+' # API ## EkoPlayer This is the view in which the eko player will reside. It will also forward any events from the player to the rest of the app. +### Static +#### EkoPlayer.clearData(context: Context) +Clears all the all EkoPlayer's Webview data, including: cache, cookies and javasctript storage. +NOTE: Since Webview data in Android is shared at the app level, calling this method +will clear the data for all of the app's Webviews. ### Properties #### appName: String App name is for analytics purposes. Will default to the bundle id if not set. @@ -16,22 +21,22 @@ App name is for analytics purposes. Will default to the bundle id if not set. #### init() The EkoPlayerView can be initialized programmatically or included via the layout XML. #### load(projectId: String, options: EkoOptions) -Will load and display an eko video. The EkoPlayer will display the loading animation while it prepares the project for playback if `showCover=true` in the options. +Will load and display an eko project. The EkoPlayer will display the loading animation while it prepares the project for playback if `cover` is set in the options. | Param | Type | Description | | :-------------: |:--------------:| :------------| | projectId | `String` | The id of a project to display | | options | `EkoOptions` | Options for project delivery. See [EkoOptions](#ekooptions) for more details. | #### load(projectId: String) -Will load and display an eko video. The EkoPlayer will display the loading animation while it prepares the project for playback with default options. +Will load and display an eko project. The EkoPlayer will display the loading animation while it prepares the project for playback with default options. | Param | Type | Description | | :-------------: |:--------------:| :------------| | projectId | `String` | The id of a project to display | #### play() -Will attempt to begin playing an eko video. +Will attempt to begin playing an eko project. #### pause() -Will attempt to pause an eko video. +Will attempt to pause an eko project. #### invoke(method: String, args: List\?) Will call any player function defined on the developer site and return the response via callback function. @@ -41,11 +46,13 @@ Will call any player function defined on the developer site and return the respo | args | `List?` | Any arguments that should be passed into the method (must be serializable to json) | #### setEkoPlayerListener(ekoPlayerListener: IEkoPlayerListener?) Set a listener that listens to events configured in the options object when `load` was called. Also listens to any errors that might happen. +#### setEkoPlayerShareListener(ekoPlayerShareLister: IEkoPlayerShareListener?) +Set a listener to handle share intents. If set to `null`, the default Android share screen will be shown. #### setEkoPlayerUrlListener(ekoPlayerUrlListener: IEkoPlayerUrlListener?) Set a listener to handle link outs. If set to `null`, link outs will automatically open in the browser. ## IEkoPlayerListener -Listener interface for receiving events and errors from an eko video. +Listener interface for receiving events and errors from an eko project. ### Methods #### onEvent(event:String, args: JSONArray?) The eko player triggers a number of events. The app can listen to these events by providing the event name in the load call. This function will be called whenever an event passed in to `load()` is triggered. @@ -66,22 +73,31 @@ Called whenever an error occurs. This could happen in the loading process (if an Listener interface for link out events. ### Methods #### onUrlOpen(url: String) -There can be link outs from within an eko video. This function will be called whenever a link out is supposed to occur. The listener is responsible for opening the url. +There can be link outs from within an eko project. This function will be called whenever a link out is supposed to occur. The listener is responsible for opening the url. | Param | Type | Description | | :-------------: |:--------------:| :------------| | url | `String` | The url to open. | +## IEkoPlayerShareListener +Listener interface for share intents. +### Methods +#### onShare(url: String) +There can be share intents from within an eko project via share buttons or ekoshell. This function will be called whenever a share intent happened. + +| Param | Type | Description | +| :-------------: |:--------------:| :------------| +| url | `String` | The canonical url of the project. | + ## EkoOptions ### Properties #### params: Map = { “autoplay”: true } A list of embed params that will affect the delivery. #### events: List\ = [] A list of events that should be forwarded to the app -#### showCover: Boolean = true -Will the SDK show a cover while loading -#### customCover: View? -A custom view to display instead of the default one +#### cover: Class\? = EkoDefaultCover::class.java +A View to cover the loading of the eko project. Set to `null` to disable. +Will be initialized by the EkoPlayer. # Default Player Events #### eko.canplay diff --git a/samples/helloeko/build.gradle b/samples/helloeko/build.gradle index accceca..a354e53 100644 --- a/samples/helloeko/build.gradle +++ b/samples/helloeko/build.gradle @@ -10,7 +10,7 @@ android { applicationId "com.eko.sdktest" minSdkVersion 21 targetSdkVersion 28 - versionCode 8 + versionCode 10 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/samples/helloeko/src/main/java/com/eko/sdktest/CustomCover.kt b/samples/helloeko/src/main/java/com/eko/sdktest/CustomCover.kt new file mode 100644 index 0000000..33acec6 --- /dev/null +++ b/samples/helloeko/src/main/java/com/eko/sdktest/CustomCover.kt @@ -0,0 +1,11 @@ +package com.eko.sdktest + +import android.content.Context +import android.graphics.Color +import android.view.View + +class CustomCover(context: Context?) : View(context) { + init { + setBackgroundColor(Color.BLUE) + } +} \ No newline at end of file diff --git a/samples/helloeko/src/main/java/com/eko/sdktest/MainActivity.kt b/samples/helloeko/src/main/java/com/eko/sdktest/MainActivity.kt index 68b51ec..c29ea14 100644 --- a/samples/helloeko/src/main/java/com/eko/sdktest/MainActivity.kt +++ b/samples/helloeko/src/main/java/com/eko/sdktest/MainActivity.kt @@ -7,13 +7,15 @@ import android.os.Bundle import android.text.method.ScrollingMovementMethod import android.view.View import android.view.inputmethod.InputMethodManager +import android.widget.Button import android.widget.CheckBox import android.widget.TextView import android.widget.Toast import com.eko.sdk.* import org.json.JSONArray -class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListener { +class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListener, + IEkoPlayerShareListener { private lateinit var projectIdTextView: TextView private lateinit var customEventsTextView: TextView private lateinit var eventsTextView: TextView @@ -21,6 +23,7 @@ class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListe private lateinit var envTextView: TextView private lateinit var paramsTextView: TextView private lateinit var customCoverCheck: CheckBox + private lateinit var clearDataButton: Button private lateinit var ekoPlayer: EkoPlayer override fun onCreate(savedInstanceState: Bundle?) { @@ -34,6 +37,7 @@ class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListe envTextView = findViewById(R.id.envTextView) paramsTextView = findViewById(R.id.paramsTextView) customCoverCheck = findViewById(R.id.customCoverCheck) + clearDataButton = findViewById(R.id.clearDataButton) eventsTextView.movementMethod = ScrollingMovementMethod() ekoPlayer = findViewById(R.id.ekoplayer) @@ -67,12 +71,21 @@ class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListe Toast.makeText(this, "URL: $url", Toast.LENGTH_LONG).show() } + override fun onShare(url: String) { + Toast.makeText(this, "Shared: $url", Toast.LENGTH_LONG).show() + } + fun loadProject(view: View) { + clearDataButton.isEnabled = false val projectId = projectIdTextView.text val customEvents = customEventsTextView.text if (projectId.isNotBlank()) { val configuration = EkoPlayerOptions() - configuration.events = customEvents.split(", ") + "eko.canplay" + if (customEvents.isNotBlank()) { + configuration.events = customEvents.split(", ") + "eko.canplay" + } else { + configuration.events = listOf("eko.canplay") + } val params = HashMap() val paramsStringPairs = paramsTextView.text.split(",") paramsStringPairs.forEach { paramsPairString -> @@ -86,9 +99,9 @@ class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListe } configuration.environment = envTextView.text.toString() if (customCoverCheck.isChecked) { - val customCover = View(this) - customCover.setBackgroundColor(Color.BLUE) - configuration.customCover = customCover +// val customCover = View(this) +// customCover.setBackgroundColor(Color.BLUE) + configuration.cover = CustomCover::class.java } ekoPlayer.load(projectId.toString(), configuration) loadingTextView.visibility = View.VISIBLE @@ -127,4 +140,17 @@ class MainActivity : AppCompatActivity(), IEkoPlayerListener, IEkoPlayerUrlListe ekoPlayer.setEkoPlayerUrlListener(null) } } + + fun handleShareChecked(view: View) { + val isChecked = (view as CheckBox).isChecked + if (isChecked) { + ekoPlayer.setEkoPlayerShareListener(this) + } else { + ekoPlayer.setEkoPlayerShareListener(null) + } + } + + fun onClearDataButtonPressed(view: View) { + EkoPlayer.clearData(this) + } } diff --git a/samples/helloeko/src/main/res/layout/activity_main.xml b/samples/helloeko/src/main/res/layout/activity_main.xml index c8540f7..a5cff22 100644 --- a/samples/helloeko/src/main/res/layout/activity_main.xml +++ b/samples/helloeko/src/main/res/layout/activity_main.xml @@ -34,7 +34,7 @@ android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" + android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:onClick="pause" android:text="Pause" @@ -62,6 +62,7 @@ android:gravity="bottom" android:nestedScrollingEnabled="true" android:scrollbars="vertical" + android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -107,12 +108,11 @@ android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginTop="16dp" + android:fontFamily="sans-serif-medium" android:onClick="clearLog" android:text="Clear Log" - app:layout_constraintStart_toEndOf="@+id/button3" - app:layout_constraintTop_toBottomOf="@+id/customEventsTextView" /> + app:layout_constraintEnd_toEndOf="@+id/eventsTextView" + app:layout_constraintTop_toTopOf="@+id/eventsTextView" /> + +