Skip to content

Commit

Permalink
Merge pull request #125 from prudrabhat/compatibility_changes
Browse files Browse the repository at this point in the history
UI Compatibility changes for Android 15
  • Loading branch information
prudrabhat authored Aug 12, 2024
2 parents 59df373 + 9f997b0 commit 3c93949
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.navigation.compose.rememberNavController
import com.adobe.marketing.mobile.assurance.internal.AssuranceComponentRegistry
Expand All @@ -26,7 +31,7 @@ import com.adobe.marketing.mobile.assurance.internal.ui.theme.AssuranceTheme.bac
/**
* Activity that hosts all of the Assurance UI.
*/
internal class AssuranceActivity : ComponentActivity() {
class AssuranceActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -36,29 +41,46 @@ internal class AssuranceActivity : ComponentActivity() {
setContent {
MaterialTheme(
content = {
// Locks the Assurance screen to always be in portrait mode.
val orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
DisposableEffect(orientation) {
val originalOrientation = requestedOrientation
requestedOrientation = orientation
onDispose {
// restore original orientation when view disappears
requestedOrientation = originalOrientation
}
}
Surface(
modifier = Modifier
.fillMaxSize(),
color = backgroundColor
) {
Box(
modifier = Modifier
.safeDrawingPadding()
.fillMaxSize()
) {

// Locks the Assurance screen to always be in portrait mode.
val orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
DisposableEffect(orientation) {
val originalOrientation = requestedOrientation
requestedOrientation = orientation
onDispose {
// restore original orientation when view disappears
requestedOrientation = originalOrientation
}
}

// Set the status bar and navigation bar colors to be the same as the
// background color of Assurance screens. This isto simulate an edge to edge
// experience while the Assurance UI is active.
SideEffect {
with(this@AssuranceActivity) {
window.statusBarColor = backgroundColor.toArgb()
window.navigationBarColor = backgroundColor.toArgb()
// Set the status bar and navigation bar colors to be the same as the
// background color of Assurance screens. This is to simulate an edge to edge
// experience while the Assurance UI is active.
// TODO:
// When Assurance SDK's target SDK is updated to 35 (where the
// window.statusBarColor, window.navigationBarColor APIs are deprecated),
// update activity-compose dependency and use enableEdgeToEdge API.
SideEffect {
with(this@AssuranceActivity) {
window.statusBarColor = backgroundColor.toArgb()
window.navigationBarColor = backgroundColor.toArgb()
}
}

// The AssuranceNavHost composable which is the entry point for the Assurance UI.
AssuranceNavHost(rememberNavController(), connectionPhase)
}
}

// The AssuranceNavHost composable which is the entry point for the Assurance UI.
AssuranceNavHost(rememberNavController(), connectionPhase)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Alignment
Expand All @@ -44,9 +48,12 @@ internal fun DialPadView(
pinScreenState: State<PinScreenState>,
onAction: (action: PinScreenAction) -> Unit
) {

val scrollState = rememberScrollState()
Box(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.background(backgroundColor)
.padding(horizontal = AssuranceTheme.dimensions.padding.xxLarge)
.testTag(AssuranceUiTestTags.PinScreen.DIAL_PAD_VIEW)
Expand All @@ -62,6 +69,7 @@ internal fun DialPadView(
NumberRow(listOf("4", "5", "6"), onClick = { action -> onAction(action) })
NumberRow(listOf("7", "8", "9"), onClick = { action -> onAction(action) })
SymbolRow(onClick = { action -> onAction(action) })
Spacer(modifier = Modifier.height(AssuranceTheme.dimensions.spacing.xLarge))
}

ActionButtonRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal fun PinAuthErrorMessageContent(text: String) {
fontFamily = FontFamily.SansSerif,
fontSize = 18.sp,
fontWeight = FontWeight.Normal,
textAlign = TextAlign.Justify
textAlign = TextAlign.Start
),
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ import com.adobe.marketing.mobile.assurance.internal.ui.theme.AssuranceTheme.bac
@Composable
internal fun PinConnectingView() {
Box(
modifier = Modifier.run {
fillMaxSize()
.background(backgroundColor)
.padding(horizontal = AssuranceTheme.dimensions.padding.xLarge)
}
modifier = Modifier
.fillMaxSize()
.background(backgroundColor)
.padding(horizontal = AssuranceTheme.dimensions.padding.xLarge)
) {
Column(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal fun QuickConnectErrorPanel(error: AssuranceConstants.AssuranceConnectio
text = error.description,
color = Color.White,
fontFamily = FontFamily.SansSerif,
textAlign = TextAlign.Center,
textAlign = TextAlign.Start,
style = TextStyle(
color = Color.White,
fontSize = AssuranceTheme.typography.font.size.large.sp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ internal object Dimensions {
internal class Spacing(
val small: Dp,
val medium: Dp,
val large: Dp
val large: Dp,
val xLarge: Dp
)

internal class Size(
Expand Down Expand Up @@ -68,6 +69,7 @@ internal object Dimensions {
small = 20.dp,
medium = 24.dp,
large = 32.dp,
xLarge = 64.dp
)

internal val button = Button(
Expand Down

0 comments on commit 3c93949

Please sign in to comment.