Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dipendra Sharma <dipendrasharma@gofynd.com>
Anitha Sangu <anithasangu@gofynd.com>
Gautham Prabhu <gauthamprabhu@gofynd.com>
Vijay Makwana <vijaymakwana@gofynd.com>
283 changes: 176 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,72 @@
# GlamAR SDK Documentation
# GlamAR Android SDK

[![Maven Central](https://img.shields.io/maven-central/v/io.pixelbin.glamar/glamar.svg)](https://central.sonatype.com/artifact/io.pixelbin.glamar/glamar)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

## Overview

The GlamAR SDK provides tools to integrate augmented reality (AR) features into your Android application. The SDK is distributed as a local `.aar` file. This document covers the installation, initialization, and usage of the SDK, including details about `GlamArView` API, and `GlamAr` instance API.
GlamAR is a powerful Augmented Reality SDK for Android that enables virtual try-on experiences for makeup, jewelry, and other beauty products. The SDK provides an easy-to-integrate solution with real-time AR capabilities, face detection, and product visualization features.

## Features

- Real-time virtual makeup try-on
- Multiple product category support
- Camera and image-based preview modes
- Real-time face tracking and analysis
- Easy integration with Android applications
- Snapshot functionality
- High-performance WebView-based rendering
- Original/Modified view comparison
- Configurable parameters

## Installation

1. **Add the `.aar` file to your project:**
- Place the `.aar` file in the `libs` directory of your project.
- Open your project's `build.gradle` file and add the following:
- Also add `okhttp` and `gson` dependencies
### Maven Central

```groovy
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
// Other dependencies
}
```
The GlamAR SDK is available on Maven Central. Add the following dependency to your app's `build.gradle`:

2. **Sync your project with Gradle files.**
```groovy
dependencies {
implementation 'io.pixelbin.glamar:glamar:1.0.2'
}
```

## Initialization
### Manual Installation

Alternatively, you can manually include the `.aar` file:

1. Place the `.aar` file in your project's `libs` directory
2. Add the following to your app's `build.gradle`:

```groovy
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
}
```

Sync your project with Gradle files.

## Required Permissions

Add these permissions to your `AndroidManifest.xml`:

### Initialize SDK in Application Class
```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" /> <!-- Required for camera preview mode -->
```

## Initialization

Initialize the SDK in your `Application` class to ensure it's set up when your app starts. By default it will be pointing to development make development parameter false for prod.
Initialize the SDK in your Application class to ensure it is set up when your app starts.

```kotlin
class MyApplication : Application() {

override fun onCreate() {
super.onCreate()
GlamAr.initialize(accessKey = "YOUR_ACCESS_KEY", development = false)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY")
}
}
```
Expand All @@ -43,148 +76,184 @@ Don't forget to register your `Application` class in the `AndroidManifest.xml`:
```xml
<application
android:name=".MyApplication"
... >
<!-- Other configurations -->
</application>
```

## GlamArView
This "init" will prompt our SDK to create a webview and open our SDK in it.

## AR View

### Setup

To use `GlamArView`, add it to your layout:
To use the webview we have created you will need to add it your layout. Paste the following code inside your layout xml file where you want to show the webview.

```xml
<com.example.glamar.GlamArView
<FrameLayout
android:id="@+id/glamARView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
```

### Starting Preview

Start the preview in various modes using `startPreview`:
Inside the activity class add the following code:

```kotlin
glamARView.startPreview(previewMode = PreviewMode.None)
glamARView.startPreview(previewMode = PreviewMode.Camera)
glamARView.startPreview(previewMode = PreviewMode.Image(imageUrl = "IMAGE_URL"))
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// This passes the activity context to the webview
GlamArWebViewManager.setUpActivityContext(this)

// This adds the webview created by SDK in the layout
GlamArWebViewManager.getPreparedWebView()?.let { webView ->
val glamARView = findViewById<FrameLayout>(R.id.glamARView)
glamARView.apply {
addView(webView)
}
}
}
}
```

### Applying SKUs
You should be able to see GlamAR SDK page being loaded.

Apply a SKU to the `GlamArView`:
### Initialization options

```kotlin
glamARView.applySku(skuId = "SKU_ID", category = "CATEGORY")
Opens the SDK Home screen with relevant category module setup.

```kotline
import io.pixelbin.glamar.model.GlamAROverrides

val overrides = GlamAROverrides(
category = "sunglasses",
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)
```

### Clearing View
Open the SDK with Live mode (web camera) straightaway. This bypasses the SDK home screen.

```kotline
import io.pixelbin.glamar.model.GlamAROverrides
import io.pixelbin.glamar.model.Configuration
import io.pixelbin.glamar.model.GlobalConfig

val overrides = GlamAROverrides(
category = "sunglasses",
configuration = Configuration(
global = GlobalConfig(
openLiveOnInit = true,
),
)
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)
```

Clear the `GlamArView`:
Open SDK with disabled previous button and cross button.

```kotline
import io.pixelbin.glamar.model.GlamAROverrides
import io.pixelbin.glamar.model.Configuration
import io.pixelbin.glamar.model.GlobalConfig

val overrides = GlamAROverrides(
category = "sunglasses",
configuration = Configuration(
global = GlobalConfig(
disableClose = true,
disableBack = false
),
)
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)
```

### Applying SKUs

Apply a SKU:

```kotlin
glamARView.clear()
GlamAr.applySku(skuId = "SKU_ID")
```

### Taking Snapshot

Take a snapshot of the current view:

```kotlin
glamARView.snapshot()
GlamAr.snapshot()
```

## GlamAr Instance API

### Fetch SKU List
## Permissions

Fetch a list of SKUs:
Ensure that you handle permissions appropriately, especially for camera access when using `openLiveOnInit`.

```kotlin
GlamAr.getInstance().api.fetchSkuList(pageNo = 1, pageSize = 100) { result ->
result.onSuccess { skuListResponse ->
// Handle success
}.onFailure { exception ->
// Handle failure
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
GlamArPermissionHandler.onRequestPermissionsResult(requestCode, grantResults)
}
```

### Fetch Specific SKU
## Event Handling

Fetch details of a specific SKU:
Event listeners are essential soon after initialization is called to start listening to GlamAR SDK callback events.

### addEventListener

```kotlin
GlamAr.getInstance().api.fetchSku(id = "SKU_ID") { result ->
result.onSuccess { item ->
// Handle success
}.onFailure { exception ->
// Handle failure
}
// Can be any event type sent from SDK
GlamAR.addEventListener("sku-applied"){
GlamArLogger.d("TAG", "sku-applied callback")
}
```

## Example Usage

Here's a complete example demonstrating the usage of `GlamAr` and `GlamArView`:
### removeEventListener
Can also unregister from listening to events previously registered to but calling

```kotlin
class MainActivity : AppCompatActivity() {

private lateinit var glamARView: GlamArView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

glamARView = findViewById(R.id.glamARView)
val applyBtn = findViewById<Button>(R.id.apply_sku)
val initBtn = findViewById<Button>(R.id.init)
val download = findViewById<Button>(R.id.download)

glamARView.startPreview(
previewMode = PreviewMode.Image(imageUrl = "IMAGE_URL")
)

applyBtn.setOnClickListener {
glamARView.applySku(skuId = "SKU_ID", category = "style")
}

initBtn.setOnClickListener {
glamARView.clear()
}

download.setOnClickListener {
glamARView.snapshot()
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
glamARView.onRequestPermissionsResult(requestCode, grantResults)
}
}
GlamAR.removeEventListener("sku-applied")
```

## Permissions

Ensure you handle permissions appropriately, especially for camera access if using `PreviewMode.Camera`.
## Best Practices

1. Always handle permissions appropriately:
```kotlin
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
glamARView.onRequestPermissionsResult(requestCode, grantResults)
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
GlamArPermissionHandler.onRequestPermissionsResult(requestCode, grantResults)
}
```
2. Initialize the SDK early in your application lifecycle
3. Handle callbacks for better user experience
4. Use appropriate preview modes based on your use case
5. Implement proper error handling

## Version History

- 1.0.2 (Latest)
- New updated GlamAR structure
- 1.0.1
- Maven Central release
- Enhanced face tracking
- Improved performance
- Bug fixes and stability improvements

## Support

For support and bug reports, please create an issue in our GitHub repository or contact our support team at support@pixelbin.io.

## Conclusion
## License

This document provides a comprehensive overview of the GlamAR SDK, detailing how to install, initialize, and use its various components. Use this as a reference to integrate AR features into your Android application effectively.
GlamAR SDK is available under the MIT license. See the LICENSE file for more info.
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
buildConfig = true
}

buildTypes {
release {
isMinifyEnabled = false
Expand All @@ -36,7 +40,6 @@ android {
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
Expand All @@ -46,8 +49,5 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

// implementation(libs.glamar.android)


}
Loading