Skip to content

Commit

Permalink
Merge pull request #1 from EkoLabs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ptelad authored Jun 30, 2020
2 parents 85d1687 + 9c49e15 commit e792ee7
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 57 deletions.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -9,29 +9,34 @@ 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.
### Methods
#### 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\<Any>?)
Will call any player function defined on the developer site and return the response via callback function.

Expand All @@ -41,11 +46,13 @@ Will call any player function defined on the developer site and return the respo
| args | `List<Any>?` | 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.
Expand All @@ -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<String, String> = { “autoplay”: true }
A list of embed params that will affect the delivery.
#### events: List\<String> = []
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\<out View>? = 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
Expand Down
2 changes: 1 addition & 1 deletion samples/helloeko/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
11 changes: 11 additions & 0 deletions samples/helloeko/src/main/java/com/eko/sdktest/CustomCover.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
36 changes: 31 additions & 5 deletions samples/helloeko/src/main/java/com/eko/sdktest/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ 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
private lateinit var loadingTextView: TextView
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?) {
Expand All @@ -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)
Expand Down Expand Up @@ -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<String, String>()
val paramsStringPairs = paramsTextView.text.split(",")
paramsStringPairs.forEach { paramsPairString ->
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
31 changes: 26 additions & 5 deletions samples/helloeko/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" />

<TextView
android:id="@+id/loadingText"
Expand Down Expand Up @@ -146,6 +146,17 @@
app:layout_constraintStart_toStartOf="@+id/customCoverCheck"
app:layout_constraintTop_toBottomOf="@+id/customCoverCheck" />

<CheckBox
android:id="@+id/customCoverCheck3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkable="true"
android:checked="false"
android:onClick="handleShareChecked"
android:text="Handle Share"
app:layout_constraintStart_toStartOf="@+id/customCoverCheck"
app:layout_constraintTop_toBottomOf="@+id/customCoverCheck2" />

<Button
android:id="@+id/button5"
android:layout_width="40dp"
Expand All @@ -165,4 +176,14 @@
app:layout_constraintEnd_toStartOf="@+id/button5"
app:layout_constraintTop_toTopOf="@+id/ekoplayer" />

<Button
android:id="@+id/clearDataButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:onClick="onClearDataButtonPressed"
android:text="Clear Data"
app:layout_constraintStart_toEndOf="@+id/button3"
app:layout_constraintTop_toTopOf="@+id/button3" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "0.0.2"
versionName "0.0.3"
}
buildTypes {
release {
Expand Down
26 changes: 26 additions & 0 deletions sdk/src/main/java/com/eko/sdk/EkoDefaultCover.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.eko.sdk

import android.content.Context
import android.graphics.Color
import android.graphics.PorterDuff
import android.util.TypedValue
import android.view.Gravity
import android.widget.FrameLayout
import android.widget.ProgressBar

/**
* The default cover to be shown if not replaced in the EkoOptions.
* This is a simple black view with a white spinner in the middle.
*/
class EkoDefaultCover(context: Context) : FrameLayout(context) {
init {
setBackgroundColor(Color.BLACK)
val spinnerSize =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40f, resources.displayMetrics)
.toInt()
val spinner = ProgressBar(context)
spinner.layoutParams = LayoutParams(spinnerSize, spinnerSize, Gravity.CENTER)
spinner.indeterminateDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN)
addView(spinner)
}
}
Loading

0 comments on commit e792ee7

Please sign in to comment.