### Add Piano SDK Dependencies via Gradle Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/README.md Add the Piano SDK dependencies to your project's build.gradle or build.gradle.kts file. This example shows how to include the composer, composer-show-template, and id modules. ```gradle dependencies { // ... implementation "io.piano.android:composer:x.y.z" implementation "io.piano.android:composer-show-template:x.y.z" implementation "io.piano.android:id:x.y.z" // ... } ``` -------------------------------- ### Handle Recommendation Clicks and Display Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-c1x/README.md Implement the activity logic to handle recommendation clicks and track display events. This includes interacting with CxenseSdk and Composer. ```kotlin class RecommendationsDisplayActivity : AppCompatActivity() { val adapter = RecommendationsAdapter { item, trackingId -> // tracking for C1X CxenseSdk.getInstance().trackClick(item, object : LoadCallback { override fun onError(throwable: Throwable) { Timber.e(throwable, "Can't track click on recommendation") } override fun onSuccess(data: Unit) { Timber.d("Tracked click on recommendation") } }) Composer.getInstance().trackRecommendationsClick(trackingId, item.url) // process recommendation click. for example, start playing video, display news, etc... } val recommendationsListener = ShowRecommendationsListener { event: Event -> CxenseSdk.getInstance().loadWidgetRecommendations( widgetId = event.eventData.widgetId, experienceId = event.eventExecutionContext.experienceId, callback = object : LoadCallback> { override fun onError(throwable: Throwable) { // process error at loading recommendations here Timber.e(throwable, "Can't load widget recommendations") } override fun onSuccess(data: List) { // recommendations are loaded, we can show them, for example via RecyclerView val trackingId = event.eventExecutionContext.trackingId adapter.submitRecommendations(trackingId, data) Composer.getInstance().trackRecommendationsDisplay(trackingId) } } ) } // other code here } ``` -------------------------------- ### Initialize Composer SDK Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer/README.md Initialize the Composer SDK using either a predefined endpoint or a custom endpoint configuration. ```kotlin // Use one of these Composer.init(context, BuildConfig.PIANO_AID, Endpoint.PRODUCTION) // use here one of endpoints listed above Composer.init(context, BuildConfig.PIANO_AID, Endpoint(composerHost, apiHost)) ``` -------------------------------- ### Sign in Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Initiates the sign-in process. The result of the authorization is handled by a registered activity result launcher. ```APIDOC ## Sign in ### Description Initiates the sign-in process. The result of the authorization is handled by a registered activity result launcher. ### Method `PianoId.signIn()` ### Parameters None ### Request Example ```kotlin authResult.launch( PianoId.signIn() // ... configure "Sign In" ... ) ``` ### Response Handles authorization results via `registerForActivityResult` with `PianoIdAuthResultContract`. - `PianoIdAuthSuccessResult`: Contains the authorization token and user registration status. - `PianoIdAuthFailureResult`: Contains an exception if the authorization failed. - `null`: If the user cancels the authorization process. ``` -------------------------------- ### Launch Sign In Flow Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Launch the Piano ID sign-in flow using the registered activity result launcher. ```kotlin authResult.launch( PianoId.signIn() // ... configure "Sign In" ... ) ``` -------------------------------- ### Initialize PianoC1X Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-c1x/README.md Replace the existing Composer initialization with PianoC1X.init, providing the necessary context, site ID, aid, and endpoint. ```kotlin PianoC1X.init(context, siteId, aid, endpoint) ``` -------------------------------- ### Initialize Piano ID with Google OAuth Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Initialize the Piano ID SDK and configure it to use Google as an OAuth provider. ```kotlin class MyApplication : Application() { override fun onCreate() { super.onCreate() PianoId.init(...).with(GoogleOAuthProvider()) } } ``` -------------------------------- ### Show Recommendations with Built-in Controller Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-c1x/README.md Use the ShowRecommendationsController to display recommendations directly. This is suitable for standard recommendation display scenarios. ```kotlin ShowRecommendationsController(event).show(activity) ``` -------------------------------- ### Initialize Piano ID with Facebook OAuth Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Initialize the Piano ID SDK and configure it to use Facebook as an OAuth provider. ```kotlin class MyApplication : Application() { override fun onCreate() { super.onCreate() PianoId.init(...).with(FacebookOAuthProvider()) } } ``` -------------------------------- ### Request User Experience Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer/README.md Request a user experience with custom parameters and define listeners for various events like user segments, meters, show templates, and non-site interactions. Handles potential exceptions during the request. ```kotlin val request = ExperienceRequest.Builder() .tag("custom_tag") .debug(true) .customParams(customParameters) .build() val listeners = listOf( UserSegmentListener { (eventModuleParams, eventExecutionContext, eventData) -> // process event here. }, MeterListener { (_, _, eventData) -> // process event here. }, ShowTemplateListener { event: Event -> // process event here }, NonSiteListener { (eventModuleParams, eventExecutionContext) -> // process event here } ) Composer.getInstance().getExperience(request, listeners) { exception: ComposerException -> // process exception here. } ``` -------------------------------- ### Show Custom Form Listener Implementation (Kotlin) Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/show-custom-form/README.md Implement the ShowFormController to handle custom form events. This includes providing an event, access token, and a callback for invalid access tokens that should trigger a user sign-in. ```kotlin ShowFormController(event, currentAccessToken) { // access token is invalid and we should show login to user here signIn() }.also { it.show(activity) } ``` -------------------------------- ### Create Recommendations Adapter Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-c1x/README.md Implement a RecyclerView adapter to display recommendations. This adapter handles item submission and view holder creation for custom recommendation UIs. ```kotlin class RecommendationsAdapter(private val clickListener: (WidgetItem, String) -> Unit): ListAdapter(DIFF_CALLBACK) { private var trackingId = "" override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = RecommendationViewHolder( LayoutInflater.from(parent.context).inflate(R.layout.recommendation_item, parent)) { clickListener(it, trackingId) } override fun onBindViewHolder(holder: RecommendationViewHolder, position: Int) { holder.updateView(getItem(position)) } fun submitRecommendations(trackingId: String, data: List?) { this.trackingId = trackingId submitList(data) } companion object { private val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: WidgetItem, newItem: WidgetItem): Boolean { // implement it for your case TODO("Not yet implemented") } override fun areContentsTheSame(oldItem: WidgetItem, newItem: WidgetItem): Boolean { // implement it for your case TODO("Not yet implemented") } } } } class RecommendationViewHolder(containerView: View, clickListener: (WidgetItem) -> Unit): RecyclerView.ViewHolder(containerView) { lateinit var item: WidgetItem init { containerView.setOnClickListener { clickListener(item) } } fun updateView(widgetItem: WidgetItem) { item = widgetItem // update items } } ``` -------------------------------- ### Show Template Event Processing Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-show-template/README.md Initiate the display of a show template event using the ShowTemplateController. Choose the appropriate method based on whether an inline WebView provider is used. ```kotlin // Use one of these ShowTemplateController(showTemplateEvent, customJavascriptInterface).show(activity) ShowTemplateController(showTemplateEvent, customJavascriptInterface).show(activity, inlineWebViewProvider) ``` -------------------------------- ### Initialize Piano ID SDK Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Initialize the Piano ID SDK in your Application class, specifying the endpoint and your application ID. ```kotlin class MyApplication : Application() { override fun onCreate() { super.onCreate() PianoId.init(PianoId.ENDPOINT_PRODUCTION, BuildConfig.PIANO_AID) } } ``` -------------------------------- ### Passwordless sign-in URI handling Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Handles deep links for passwordless authentication, parsing the token from the URI. ```APIDOC ## Passwordless sign-in URI handling ### Description Handles deep links for passwordless authentication, parsing the token from the URI. ### Method `uri.isPianoIdUri()` and `uri.parsePianoIdToken()` ### Parameters - **uri** (Uri) - Required - The incoming deep link URI. ### Request Example ```kotlin val uri = intent.data if (uri.isPianoIdUri()) { // It's Piano paswordless auth link uri.parsePianoIdToken { r -> r.onFailure { // Auth unsuccessful, process it }.onSuccess { // Auth successful, save access token here } } } else { // App deep link, process as usual } ``` ### Response Provides a result object that indicates success or failure of the passwordless authentication. - `onSuccess`: Callback for successful authentication, providing the token. - `onFailure`: Callback for failed authentication, providing an exception. ``` -------------------------------- ### Add Composer Show Template Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-show-template/README.md Add the Composer Show Template AAR dependency to your project's build.gradle or build.gradle.kts file. ```kotlin dependencies { implementation("io.piano.android:composer-show-template:$VERSION") } ``` -------------------------------- ### Set User Access Token Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer/README.md Set the user's access token for the Composer SDK instance. ```kotlin Composer.getInstance().userToken(accessToken) ``` -------------------------------- ### Add Show Custom Form Dependency (Kotlin DSL) Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/show-custom-form/README.md Add the Show Custom Form AAR dependency to your project's build.gradle or build.gradle.kts file using Maven Central. ```kotlin dependencies { implementation("io.piano.android:show-custom-form:$VERSION") } ``` -------------------------------- ### Handle Passwordless Authentication URI Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md In your login activity's onCreate method, check if the incoming intent data is a Piano ID passwordless authentication URI and process it. ```kotlin val uri = intent.data if (uri.isPianoIdUri()) { // It's Piano paswordless auth link uri.parsePianoIdToken { r -> r.onFailure { // Auth unsuccessful, process it }.onSuccess { // Auth successful, save access token here } } } else { // App deep link, process as usual } ``` -------------------------------- ### Add Composer SDK Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer/README.md Add the Composer SDK dependency to your project's build.gradle or build.gradle.kts file to include it in your application. ```kotlin dependencies { implementation("io.piano.android:composer:$VERSION") } ``` -------------------------------- ### Add Composer C1X Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer-c1x/README.md Add the Composer C1X artifact to your project's build.gradle or build.gradle.kts file. Ensure you replace `$VERSION` with the actual version number. ```kotlin dependencies { implementation("io.piano.android:composer-c1x:$VERSION") } ``` -------------------------------- ### Add Google OAuth Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Add the Google OAuth provider dependency to your project for social sign-in. ```kotlin dependencies { implementation("io.piano.android:id-oauth-google:$VERSION") } ``` -------------------------------- ### Handle Authentication Result Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Register a callback to process the result of the Piano ID authentication process, handling success, failure, or cancellation. ```kotlin private val authResult = registerForActivityResult(PianoIdAuthResultContract()) { r -> when (r) { null -> { /* user cancelled Authorization process */ } is PianoIdAuthSuccessResult -> { val token = r.token val isNewUserRegistered = r.isNewUser if (token.emailConfirmationRequired) { // process enabled Double opt-in } // process successful authorization } is PianoIdAuthFailureResult -> { val e = r.exception // Authorization failed, check e.cause for details } } } ``` -------------------------------- ### Piano SDK License Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/README.md This is the Apache License, Version 2.0, under which the Piano SDK for Android is distributed. It outlines the terms for using, modifying, and distributing the software. ```plaintext Copyright 2016 Piano, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Composer SDK Endpoints Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/composer/README.md Defines the available endpoints for the Composer SDK, including production, sandbox, and regional variants. ```kotlin Endpoint.PRODUCTION // Production endpoint Endpoint.PRODUCTION_EUROPE // Production endpoint for Europe region Endpoint.PRODUCTION_AUSTRALIA // Production endpoint for Australia region Endpoint.PRODUCTION_ASIA_PACIFIC // Production endpoint for Asia/Pacific region Endpoint.SANDBOX // Sandbox endpoint ``` -------------------------------- ### Add Piano ID SDK Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Add the Piano ID Android SDK to your project's build.gradle file using Maven Central. ```kotlin dependencies { implementation("io.piano.android:id:$VERSION") } ``` -------------------------------- ### Add Facebook OAuth Dependency Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Add the Facebook OAuth provider dependency to your project for social sign-in. ```kotlin dependencies { implementation("io.piano.android:id-oauth-facebook:$VERSION") } ``` -------------------------------- ### Sign Out User Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Sign out the current user using their access token. An optional callback can be provided. ```kotlin PianoId.signout(accessToken) // or PianoId.signout(accessToken) { // callback code here } ``` -------------------------------- ### Refresh Access Token Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Refresh the user's access token using their refresh token. A callback is required to handle the result. ```kotlin PianoId.refreshToken(refreshToken) { // callback code here } ``` -------------------------------- ### Configure Android Manifest for Passwordless Login Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Add an intent filter to your login activity in AndroidManifest.xml to handle passwordless authentication URIs. ```xml ``` -------------------------------- ### Piano ID Endpoints Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md List of available endpoints for Piano ID authentication. ```plaintext PianoId.ENDPOINT_PRODUCTION - Production endpoint PianoId.ENDPOINT_PRODUCTION_EUROPE - Europe production endpoint PianoId.ENDPOINT_PRODUCTION_AUSTRALIA - Australia production endpoint PianoId.ENDPOINT_PRODUCTION_ASIA_PACIFIC - Asia/Pacific production endpoint PianoId.ENDPOINT_SANDBOX - Sandbox endpoint ``` -------------------------------- ### Refresh token Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Refreshes the user's access token using a provided refresh token. ```APIDOC ## Refresh token ### Description Refreshes the user's access token using a provided refresh token. ### Method `PianoId.refreshToken(refreshToken)` ### Parameters - **refreshToken** (string) - Required - The refresh token to use for obtaining a new access token. ### Request Example ```kotlin PianoId.refreshToken(refreshToken) { // callback code here } ``` ### Response Callback is executed upon completion of the token refresh process. ``` -------------------------------- ### Sign out Source: https://github.com/tinypass/piano-sdk-for-android/blob/main/id/README.md Signs the user out by invalidating the provided access token. ```APIDOC ## Sign out ### Description Signs the user out by invalidating the provided access token. ### Method `PianoId.signout(accessToken)` ### Parameters - **accessToken** (string) - Required - The access token to invalidate. ### Request Example ```kotlin PianoId.signout(accessToken) // or with a callback PianoId.signout(accessToken) { // callback code here } ``` ### Response Callback is optional and can be used for post-sign-out operations. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.