-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
44 changed files
with
1,220 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
109 changes: 109 additions & 0 deletions
109
sample-payment-app/src/main/java/io/moonsense/sample/payment/app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sample-payment-app/src/main/java/io/moonsense/sample/payment/app/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
sample-payment-app/src/main/java/io/moonsense/sample/payment/app/widget/CookieItemView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.