Skip to content

Commit d647832

Browse files
android sdk comments
1 parent 59d67b7 commit d647832

1 file changed

Lines changed: 148 additions & 170 deletions

File tree

modules/ROOT/pages/mobile-embed-android.adoc

Lines changed: 148 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:page-pageid: embed-ts-android
77
:page-description: Use the Android Embed SDK to embed ThoughtSpot in your Android mobile app
88

9-
Your application developers can embed a ThoughtSpot Liveboard in your Android app using the ThoughtSpot Android Embed SDK.
9+
Your application developers can embed a ThoughtSpot Liveboard in your native Android app using the ThoughtSpot Android Embed SDK.
1010

1111
== Before you begin
1212

@@ -17,6 +17,55 @@ Ensure that your host app embedding ThoughtSpot is added to the xref:security-se
1717
* Access to the Liveboard object that you want to embed.
1818
* Android Studio is installed. +
1919

20+
== Install the SDK
21+
To download the Android Embed SDK from Maven Central to your project and install the libraries, add the following code to your app-level `build.gradle.kts`:
22+
23+
[source,kotlin]
24+
----
25+
implementation("io.github.thoughtspot:android-embed-sdk:0.0.1-beta")
26+
----
27+
28+
* `implementation` +
29+
Instructs Gradle to add the dependency for compile and runtime usage in your Android project.
30+
* `com.github.thoughtspot` +
31+
GitHub reference ID
32+
* `android-embed-sdk` +
33+
The GitHub repository containing the Android Embed SDK package.
34+
* `Tag` +
35+
Indicates the version of the SDK to use. Replace this with a specific release tag from the GitHub repository. For example,0.0.1-beta.
36+
37+
The SDK may require network access to communicate with your ThoughtSpot instance. Ensure your app’s `AndroidManifest.xml` includes the following:
38+
39+
== XML Layout
40+
41+
In the `activity_main.xml` of your project, add the following to define a custom Android view component:
42+
43+
[source,xml]
44+
----
45+
<!-- res/layout/activity_main.xml -->
46+
<com.thoughtspot.android.embedsdk.LiveboardEmbed
47+
android:id="@+id/liveboard_embed_view"
48+
android:layout_width="match_parent"
49+
android:layout_height="wrap_content"
50+
app:layout_constraintTop_toTopOf="parent"
51+
app:layout_constraintBottom_toTopOf="@id/another_view"
52+
app:layout_constraintStart_toStartOf="parent"
53+
app:layout_constraintEnd_toEndOf="parent" />
54+
----
55+
56+
* `<com.thoughtspot.android.embedsdk.LiveboardEmbed ... />` +
57+
Declares a custom view to render the Liveboard in the app.
58+
* `android:id="@+id/liveboard_embed_view"` +
59+
Assigns a unique ID to this view so you can reference it in your Kotlin/Java code.
60+
* `android:layout_width="match_parent"` and `android:layout_height="wrap_content"` +
61+
Sets the width and height of the layout for embedded view.
62+
* The `app:layout_constraint...` attributes +
63+
Positions the view relative to the other UI elements.
64+
65+
You'll need to add a reference to this view in your code and then load a specific Liveboard into it.
66+
67+
////
68+
2069
== Import the SDK to your Android application project
2170
2271
You can add the Android Embed SDK to your project using one of the following methods:
@@ -74,74 +123,46 @@ GitHub reference ID
74123
The GitHub repository containing the Android Embed SDK package.
75124
* `<version>` +
76125
Replace it with the SDK version. For example, 1.0.0.
126+
////
77127

78-
== Import the SDK and configure authentication
79-
80-
. Import the components from the SDK and configure authentication. You can initialize the SDK in your application class or MainActivity.
128+
== Initialize the SDK
81129

130+
. In your application class or MainActivity, add the embedView.
82131
+
83132
[source,kotlin]
84133
----
85-
package com.your-id.prj-name
86-
87-
import android.app.Activity
88-
import android.content.res.Configuration
89-
import android.os.Bundle
90-
import androidx.appcompat.app.AppCompatActivity
91-
import com.thoughtspot.android_embed_sdk.LiveboardEmbed
92-
import com.thoughtspot.android_embed_sdk.AuthType
93-
import com.thoughtspot.android_embed_sdk.EmbedEvent
94-
import com.thoughtspot.android_embed_sdk.HostEvent
95-
import customCssInterface
96-
import kotlinx.coroutines.*
97-
import CustomStyles
98-
import CustomisationsInterface
99-
import EmbedConfig
100-
import LiveboardViewConfig
101-
102-
class MainActivity : AppCompatActivity() {
103-
// You can instead fetch token from your backend.
104-
private suspend fun fetchAuthTokenAsync(): String {
105-
return "<YOUR_TRUSTED_AUTH_TOKEN>"
106-
}
107-
private val getAuthToken: () -> String = {
108-
runBlocking {
109-
fetchAuthTokenAsync()
110-
}
111-
}
134+
val embedView = findViewById<LiveboardEmbed>(R.id.liveboard_embed_view)
112135
----
113136

114-
. Add ThoughtSpot host URL and authentication method.
137+
. Specify ThoughtSpot application URL, authentication attributes and token fetching method.
115138
+
116139
[source,kotlin]
117140
----
118-
val embedConfig = EmbedConfig(
119-
thoughtSpotHost = "ts-host", // Replace it with your ThoughtSpot application URL
120-
authType = AuthType.TrustedAuthTokenCookieless, //
121-
)
122-
----
123-
124-
== Add the embed view to your application layout
141+
val embedConfig = EmbedConfig(
142+
thoughtSpotHost = "https://your.thoughtspot.instance", // Replace it with your ThoughtSpot application URL
143+
authType = AuthType.TrustedAuthTokenCookieless
144+
)
145+
146+
val getAuthToken: () -> String = {
147+
runBlocking {
148+
// Replace with real token retrieval logic
149+
"your-auth-token"
150+
}
151+
}
125152
126-
. Define the Liveboard embed view in the `activity_main.xml` file:
127-
+
128-
[source,xml]
129-
----
130-
<!-- res/layout/activity_main.xml -->
131-
<com.thoughtspot.androidembed.ThoughtSpotEmbedView
132-
android:id="@+id/embedView"
133-
android:layout_width="match_parent"
134-
android:layout_height="match_parent" />
135153
----
136-
137-
. Add the embed view to your app layout.
154+
. Initialize the SDK.
138155
+
139-
[source,kotlin]
156+
[source,Kotlin]
140157
----
141-
val embedView = findViewById<LiveboardEmbed>(R.id.liveboard_embed_view)
158+
embedView.initialize(
159+
viewConfig = viewConfig,
160+
embedConfig = embedConfig,
161+
getAuthToken = getAuthToken
162+
)
142163
----
143164

144-
== Add the Liveboard
165+
== Add the Liveboard and configure the embed view
145166

146167
Add the Liveboard GUID.
147168

@@ -211,25 +232,13 @@ Define CSS variables to apply custom styles.
211232
liveboardId = "your-livebaord-id",
212233
enable2ColumnLayout = true,
213234
customizations = CustomisationsInterface(
214-
style = CustomStyles(
215-
customCSS = customCssInterface(
216-
variables = mapOf(
235+
style = CustomStyles(
236+
customCSS = customCssInterface(
237+
variables = mapOf(
217238
"--ts-var-primary-color" to "#0055ff",
218239
"--ts-var-max-width" to "1200px",
219240
"--ts-var-enable-2-column-layout" to "true",
220241
"--ts-var-root-background" to "#fef4dd",
221-
"--ts-var-root-color" to "#4a4a4a",
222-
"--ts-var-viz-title-color" to "#8e6b23",
223-
"--ts-var-viz-title-font-family" to "'Georgia','Times New Roman',serif",
224-
"--ts-var-viz-title-text-transform" to "capitalize",
225-
"--ts-var-viz-description-color" to "#6b705c",
226-
"--ts-var-viz-description-font-family" to "'Verdana','Helvetica', sans-serif",
227-
"--ts-var-viz-border-radius" to "6px",
228-
"--ts-var-viz-box-shadow" to "0 3px 6px rgba(0, 0, 0, 0.15)",
229-
"--ts-var-viz-background" to "#fffbf0",
230-
"--ts-var-viz-legend-hover-background" to "#ffe4b5",
231-
"--ts-var-liveboard-dual-column-breakpoint" to "1100px",
232-
"--ts-var-liveboard-single-column-breakpoint" to "320px"
233242
)
234243
)
235244
)
@@ -244,129 +253,98 @@ To listen to the events emitted by the embedded ThoughtSpot component, register
244253
[source,Kotlin]
245254
----
246255
// Register an event listener for authentication failures and custom actions
247-
embedView.getController()?.on(EmbedEvent.Load) { payload ->
248-
println("Liveboard loaded with payload: $payload")
256+
embedView.getController()?.on(EmbedEvent.AuthInit) { payload ->
257+
println("Auth initialized: $payload")
258+
}
249259
----
250260

251261
To trigger actions on the embedded ThoughtSpot interface, use xref:embed-events.adoc#host-events[Host events].
252262

253263
[source,Kotlin]
254264
----
255-
// Trigger an action via a host event
256-
embedView.getController()?.trigger(HostEvent.ReLoad) { payload ->
257-
println("Liveboard reloaded with payload: $payload")
265+
// Trigger reload action
266+
embedView.getController()?.trigger(HostEvent.Reload)
258267
----
259268

260269
== Build your app and render the embedded object
261270

262-
Initialize the SDK, build your app, and render your embed.
263-
264-
[source,Kotlin]
265-
----
266-
embedView.initialize(
267-
viewConfig = viewConfig,
268-
embedConfig = embedConfig,
269-
getAuthToken = getAuthToken
270-
)
271-
----
271+
Build your app, and render your embed.
272272

273273
== Code sample
274274

275275
[source,Kotlin]
276276
----
277-
package com.your-id.prj-name
278-
279-
import android.app.Activity
280-
import android.content.res.Configuration
281-
import android.os.Bundle
282-
import androidx.appcompat.app.AppCompatActivity
283-
import com.thoughtspot.android_embed_sdk.LiveboardEmbed
284-
import com.thoughtspot.android_embed_sdk.AuthType
285-
import com.thoughtspot.android_embed_sdk.EmbedEvent
286-
import com.thoughtspot.android_embed_sdk.HostEvent
287-
import customCssInterface
288-
import kotlinx.coroutines.*
289-
import CustomStyles
290-
import CustomisationsInterface
291-
import EmbedConfig
292-
import LiveboardViewConfig
293-
294-
class MainActivity : AppCompatActivity() {
295-
// You can instead fetch token from your backend.
296-
private suspend fun fetchAuthTokenAsync(): String {
297-
return "<YOUR_TRUSTED_AUTH_TOKEN>"
298-
}
299-
300-
private val getAuthToken: () -> String = {
301-
runBlocking {
302-
fetchAuthTokenAsync()
303-
}
304-
}
305-
306-
override fun onCreate(savedInstanceState: Bundle?) {
307-
super.onCreate(savedInstanceState)
308-
setContentView(R.layout.activity_main)
309-
310-
val embedView = findViewById<LiveboardEmbed>(R.id.liveboard_embed_view)
311-
312-
val viewConfig = LiveboardViewConfig(
313-
liveboardId = "your-livebaord-id",
314-
enable2ColumnLayout = true,
315-
visibleActions = listOf(
316-
Action.AddFilter, //Add filter menu action
317-
Action.Share, // Share action
318-
Action.DrillDown, // Drill down action
319-
Action.AxisMenuFilter, // Filter action on chart axis
320-
Action.AxisMenuTimeBucket, // Time bucket option in the chart axis
321-
),
322-
// These actions will be grayed out and not clickable
323-
disabledActions = listOf(Action.Download),
324-
// Optionally, add a tooltip text for disabled actions
325-
disabledActionReason = "Contact your administrator to enable this action",
326-
customizations = CustomisationsInterface(
327-
// Define CSS for custom styling
328-
style = CustomStyles(
329-
customCSS = customCssInterface(
330-
variables = mapOf(
331-
"--ts-var-primary-color" to "#0055ff",
332-
"--ts-var-max-width" to "1200px",
333-
"--ts-var-enable-2-column-layout" to "true",
334-
"--ts-var-root-background" to "#fef4dd",
335-
"--ts-var-root-color" to "#4a4a4a",
336-
"--ts-var-viz-title-color" to "#8e6b23",
337-
"--ts-var-viz-title-font-family" to "'Georgia', 'Times New Roman', serif",
338-
"--ts-var-viz-title-text-transform" to "capitalize",
339-
"--ts-var-viz-description-color" to "#6b705c",
340-
"--ts-var-viz-description-font-family" to "'Verdana', 'Helvetica', sans-serif",
341-
"--ts-var-viz-border-radius" to "6px",
342-
"--ts-var-viz-box-shadow" to "0 3px 6px rgba(0, 0, 0, 0.15)",
343-
"--ts-var-viz-background" to "#fffbf0",
344-
"--ts-var-viz-legend-hover-background" to "#ffe4b5",
345-
"--ts-var-liveboard-dual-column-breakpoint" to "1100px",
346-
"--ts-var-liveboard-single-column-breakpoint" to "320px"
347-
)
348-
)
277+
import kotlinx.coroutines.runBlocking
278+
// Import other necessary ThoughtSpot SDK classes
279+
280+
val embedView = findViewById<LiveboardEmbed>(R.id.liveboard_embed_view)
281+
282+
val viewConfig = LiveboardViewConfig(
283+
liveboardId = "your-liveboard-id", // Replace with your Liveboard ID
284+
enable2ColumnLayout = true,
285+
visibleActions = listOf(
286+
Action.AddFilter, // Add filter menu action
287+
Action.Share, // Share action
288+
Action.DrillDown, // Drill down action
289+
Action.AxisMenuFilter, // Filter action on chart axis
290+
Action.AxisMenuTimeBucket // Time bucket option in the chart axis
291+
),
292+
// These actions will be grayed out and not clickable
293+
disabledActions = listOf(Action.Download),
294+
// Optionally, add a tooltip text for disabled actions
295+
disabledActionReason = "Contact your administrator to enable this action",
296+
customizations = CustomisationsInterface(
297+
style = CustomStyles(
298+
customCSS = customCssInterface(
299+
variables = mapOf(
300+
"--ts-var-primary-color" to "#0055ff",
301+
"--ts-var-liveboard-dual-column-breakpoint" to "1100px",
302+
"--ts-var-max-width" to "1200px",
303+
"--ts-var-enable-2-column-layout" to "true",
304+
"--ts-var-root-background" to "#fef4dd",
305+
"--ts-var-root-color" to "#4a4a4a",
306+
"--ts-var-viz-title-color" to "#8e6b23",
307+
"--ts-var-viz-title-font-family" to "'Georgia', 'Times New Roman', serif",
308+
"--ts-var-viz-title-text-transform" to "capitalize",
309+
"--ts-var-viz-description-color" to "#6b705c",
310+
"--ts-var-viz-description-font-family" to "'Verdana', 'Helvetica', sans-serif",
311+
"--ts-var-viz-border-radius" to "6px",
312+
"--ts-var-viz-box-shadow" to "0 3px 6px rgba(0, 0, 0, 0.15)",
313+
"--ts-var-viz-background" to "#fffbf0",
314+
"--ts-var-viz-legend-hover-background" to "#ffe4b5",
315+
"--ts-var-liveboard-single-column-breakpoint" to "320px"
316+
// Add more variables as needed
349317
)
350318
)
351319
)
320+
)
321+
)
322+
323+
val embedConfig = EmbedConfig(
324+
thoughtSpotHost = "https://your.thoughtspot.instance",
325+
authType = AuthType.TrustedAuthTokenCookieless
326+
)
327+
328+
val getAuthToken: () -> String = {
329+
runBlocking {
330+
// Replace with real token retrieval logic
331+
"your-auth-token"
332+
}
333+
}
352334
353-
val embedConfig = EmbedConfig(
354-
thoughtSpotHost = "ts-host",
355-
authType = AuthType.TrustedAuthTokenCookieless
356-
)
357-
358-
embedView.initialize(
359-
viewConfig = viewConfig,
360-
embedConfig = embedConfig,
361-
getAuthToken = getAuthToken
362-
)
335+
embedView.initialize(
336+
viewConfig = viewConfig,
337+
embedConfig = embedConfig,
338+
getAuthToken = getAuthToken
339+
)
363340
364-
// Example: Listen to Reload event
365-
embedView.getController()?.on(HostEvent.Reload) { payload ->
366-
println("Liveboard reloaded with payload: $payload")
367-
}
368-
}
341+
// Example: Listen to AuthInit event
342+
embedView.getController()?.on(EmbedEvent.AuthInit) { payload ->
343+
println("Auth initialized: \$2ayload")
369344
}
345+
346+
// Trigger reload action
347+
embedView.getController()?.trigger(HostEvent.Reload)
370348
----
371349

372350
== Test your embed

0 commit comments

Comments
 (0)