Skip to content

Commit

Permalink
Updated version to alpha3 (#5)
Browse files Browse the repository at this point in the history
* Updated version to alpha3

- includes support for touch and linear
  acceleromter
- adds a payment sample for touch tracking
- no breaking changes for the api

* updated the README

* README cleanup
  • Loading branch information
rahul27 authored Oct 4, 2021
1 parent 1c81eba commit 3c7e44c
Show file tree
Hide file tree
Showing 44 changed files with 1,220 additions and 8 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

This repository includes a sample app that demonstrates the use of the Moonsense SDK for Android.
This repository includes sample apps that demonstrate the use of the Moonsense SDK for Android.

## TLDR

Expand All @@ -19,8 +19,9 @@ gpr.key=<token goes here>

## Version History

The latest release of the SDK is `0.1.0-alpha2`. Details about the current and past releases can be found below:
The latest release of the SDK is `0.1.0-alpha3`. Details about the current and past releases can be found below:

- [0.1.0-alpha3](https://github.com/moonsense/moonsense-android-sdk/releases/tag/0.1.0-alpha3)
- [0.1.0-alpha2](https://github.com/moonsense/moonsense-android-sdk/releases/tag/0.1.0-alpha2)

## Integration
Expand Down Expand Up @@ -52,12 +53,12 @@ With the credentials in place your are ready to include the following line to ad


```gradle
implementation("io.moonsense:android-sdk:0.1.0-alpha2")
implementation("io.moonsense:android-sdk:0.1.0-alpha3")
```

## Usage

The SDK needs to be initialized before it can be used. Use the `initialize()` method in either an `Application.onCreate()` or `Activity.onCreate()` to prepare the SDK for recording. The `initialize()` call expects a `publicToken` that can be generated using the [Moonsense Console](https://console.moonsense.cloud/). In order to obtain a token you need to:
The SDK needs to be initialized before it can be used. Use the `initialize()` method in either an `Application.onCreate()`/`Activity.onCreate()` to prepare the SDK for recording. For SDK/library developers you can add `initialize()` to your initialization routine. The `initialize()` call expects a `publicToken` that can be generated using the [Moonsense Console](https://console.moonsense.cloud/). In order to obtain a token you need to:

- Have a valid Moonsense account.
- Set up a project for the SDK to use. The default can be used in case you do not want to create one.
Expand All @@ -68,7 +69,10 @@ Once initialized you can use the `startSession()` and `stopAllSessions()` to sta

Additionally a `MoonsenseCallback` can be registered to provide the caller with events from the SDK.

This repo includes a sample app that demonstrates the SDK usage.
This repo includes two sample apps:

- `sample-app` - This sample app demonstrates the use of the Moonsense Android SDK within an application context. The example in this case is quite simple and minimal and can serve as a good starting point for developers looking for a quick integration.
- `sample-payment-app` - This sample app demonstrates the library usage of the Moonsense Android SDK. Note that the `sample-payment-app` does not directly depend on the Moonsense Android SDK. Instead it includes a dependency to the `sample-payment-sdk` which then packages the Moonsense Android SDK. The app developer here does not have any visibility into the Moonsense Android SDK as they only interface with the `sample-payment-sdk`. The example is useful for SDK/library developers looking to integrate the Moonsense Android SDK.

## Terms Of Service

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object AppConfig {
const val minSdkVersion = 16
const val targetSdkVersion = 30
const val versionCode = 1
const val versionName = "0.1.0-alpha2"
const val versionName = "0.1.0-alpha3"
const val buildToolsVersion = "30.0.3"
const val androidTestInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
const val jvmTarget = "11"
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

object Versions {
const val gradleTools = "7.0.1"
const val kotlinVersion = "1.5.10"
const val kotlinVersion = "1.5.31"
const val junit = "4.13.2"
const val junitAndroidX = "1.1.3"
const val espressoCore = "3.4.0"
const val constraintLayout = "2.1.0"
const val fragmentKtx = "1.3.6"
const val androidXLegacySupport = "1.0.0"
const val material = "1.4.0"
}
1 change: 1 addition & 0 deletions sample-payment-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
48 changes: 48 additions & 0 deletions sample-payment-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 Moonsense, Inc. All rights reserved.
* Created by rahul on 9/16/21, 8:46 AM
*/

plugins {
id("com.android.application")
id("kotlin-android")
}

android {
compileSdk = AppConfig.compileSdkVersion
buildToolsVersion = AppConfig.buildToolsVersion

defaultConfig {
applicationId = "io.moonsense.sample.payment.app"
minSdk = AppConfig.minSdkVersion
targetSdk = AppConfig.targetSdkVersion
versionCode = AppConfig.versionCode
versionName = AppConfig.versionName

testInstrumentationRunner = AppConfig.androidTestInstrumentationRunner
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = AppConfig.jvmTarget
}
}

dependencies {
implementation(project(":sample-payment-sdk"))
implementation("com.google.android.material:material:${Versions.material}")
implementation("androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}")
}
21 changes: 21 additions & 0 deletions sample-payment-app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
22 changes: 22 additions & 0 deletions sample-payment-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.moonsense.sample.payment.app">

<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2021 Moonsense, Inc. All rights reserved.
* Created by rahul on 9/16/21, 9:01 AM
*/

package io.moonsense.sample.payment.app

import android.graphics.Typeface
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import com.google.android.material.snackbar.Snackbar
import io.moonsense.sample.payment.app.widget.CookieItemView
import io.moonsense.sample.payment.sdk.PaymentDialog
import io.moonsense.sample.payment.sdk.PaymentListener
import java.util.Locale
import kotlin.math.roundToLong
import android.view.Gravity
import androidx.core.content.ContextCompat

internal class MainActivity : FragmentActivity(), () -> Unit {

private lateinit var chocoChipView: CookieItemView
private lateinit var oatmealRaisinView: CookieItemView
private lateinit var subtotalPriceView: TextView
private lateinit var taxPriceView: TextView
private lateinit var totalPriceView: TextView
private lateinit var buyButton: View
private lateinit var parentLayout: ViewGroup
private var totalPrice: Float = 0.0f

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
parentLayout = findViewById(R.id.parent_layout)
buyButton = findViewById(R.id.buy_button)
chocoChipView = findViewById(R.id.choco_chip_row)
oatmealRaisinView = findViewById(R.id.oatmeal_raisin_row)
subtotalPriceView = findViewById(R.id.subtotal_price)
taxPriceView = findViewById(R.id.tax_price)
totalPriceView = findViewById(R.id.total_price)
chocoChipView.setTitle(R.string.choco_chip)
oatmealRaisinView.setTitle(R.string.oatmeal_raisin)
initializeView()
}

private fun initializeView() {
chocoChipView.setOnQuantityChangedListener(this)
oatmealRaisinView.setOnQuantityChangedListener(this)

chocoChipView.setPrice(CHOCO_CHIP_COOKIE_PRICE)
oatmealRaisinView.setPrice(OATMEAL_RAISIN_COOKIE_PRICE)
chocoChipView.setQuantity(1)
oatmealRaisinView.setQuantity(1)

buyButton.setOnClickListener {
val price = (totalPrice * ONE_HUNDRED).roundToLong() / ONE_HUNDRED
PaymentDialog.launch(
this,
price,
object : PaymentListener {
override fun onComplete() {
showToast("Payment Complete!", R.color.background_green, R.color.black)
}

override fun onDismissed() {
showToast("Payment Incomplete!", R.color.background_red, R.color.red)
}
}
)
}
}

private fun showToast(message: String, snackBarBgColorRes: Int, textColorRes: Int) {
val snackBar = Snackbar.make(this, parentLayout, message, Snackbar.LENGTH_SHORT)
val view = snackBar.view
view.setBackgroundColor(ContextCompat.getColor(this, snackBarBgColorRes))
val textView = view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
textView.setTextColor(ContextCompat.getColor(this, textColorRes))
textView.typeface = Typeface.DEFAULT_BOLD
textView.gravity = Gravity.CENTER_HORIZONTAL
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.textAlignment = View.TEXT_ALIGNMENT_CENTER
}
snackBar.show()
}

override fun invoke() {
val subTotal = chocoChipView.getTotalPrice() + oatmealRaisinView.getTotalPrice()
val tax = subTotal * DEFAULT_TAX_PERCENTAGE
totalPrice = subTotal + tax
subtotalPriceView.text = getFormattedPrice(subTotal)
taxPriceView.text = getFormattedPrice(tax)
totalPriceView.text = getFormattedPrice(totalPrice)
}

private fun getFormattedPrice(value: Float) =
String.format(Locale.getDefault(), "$ %.2f", value)

companion object {
private const val CHOCO_CHIP_COOKIE_PRICE = 4.99f
private const val OATMEAL_RAISIN_COOKIE_PRICE = 5.99f
private const val DEFAULT_TAX_PERCENTAGE = 0.0825f
private const val ONE_HUNDRED = 100f
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2021 Moonsense, Inc. All rights reserved.
* Created by rahul on 8/19/21, 10:49 AM
*/

package io.moonsense.sample.payment.app

import android.app.Application
import io.moonsense.sample.payment.sdk.Payment

internal class MainApplication : Application() {

override fun onCreate() {
super.onCreate()
Payment.init(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2021 Moonsense, Inc. All rights reserved.
* Created by rahul on 9/21/21, 12:08 PM
*/

package io.moonsense.sample.payment.app.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import io.moonsense.sample.payment.app.R
import java.util.Locale

/**
* Represents a row of cookie for sale including the
* name, price and quantity.
*/
internal class CookieItemView @JvmOverloads constructor(
context: Context,
xmlAttrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, xmlAttrs, defStyleAttr) {

private var price: Float = 0.0f
private var quantity: Int = 1
private val priceView: TextView
private val countView: TextView

private val addButton: View
private val removeButton: View

private var onRowQuantityChanged: (() -> Unit)? = null

init {
val layoutInflater = LayoutInflater.from(context)
layoutInflater.inflate(R.layout.cookie_item_view, this, true)
priceView = findViewById(R.id.item_row_price)
countView = findViewById(R.id.item_row_count)
addButton = findViewById(R.id.item_row_add_button)
addButton.setOnClickListener {
setQuantity(quantity + 1)
}
removeButton = findViewById(R.id.item_row_remove_button)
removeButton.setOnClickListener {
setQuantity(quantity - 1)
}
}

fun setTitle(stringRes: Int) {
findViewById<TextView>(R.id.item_row_title).text = resources.getString(stringRes)
}

fun setPrice(price: Float) {
this.price = price
}

fun setQuantity(quantity: Int) {
if (quantity < 0) {
return
}
this.quantity = quantity
countView.text = quantity.toString()
val priceFormatted = String.format(Locale.getDefault(), "$ %.2f", price * quantity)
priceView.text = priceFormatted
onRowQuantityChanged?.invoke()
}

fun setOnQuantityChangedListener(listener: () -> Unit) {
this.onRowQuantityChanged = listener
}

fun getTotalPrice() = price * quantity
}
14 changes: 14 additions & 0 deletions sample-payment-app/src/main/res/drawable/add_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
~ Copyright (c) 2021 Moonsense, Inc. All rights reserved.
~ Created by rahul on 9/20/21, 8:23 AM
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/black"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h-2v-4L7,13v-2h4L11,7h2v4h4v2z"/>
</vector>
Loading

0 comments on commit 3c7e44c

Please sign in to comment.