Merge "Adjust clock carousel guideline margin" into udc-dev
diff --git a/res/layout/keyguard_quick_affordance.xml b/res/layout/keyguard_quick_affordance.xml
index 1e5c339..a86489a 100644
--- a/res/layout/keyguard_quick_affordance.xml
+++ b/res/layout/keyguard_quick_affordance.xml
@@ -62,8 +62,10 @@
android:id="@id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
android:textColor="@color/text_color_primary"
- android:singleLine="true"
+ android:maxLines="2"
+ android:hyphenationFrequency="normal"
android:ellipsize="end"
android:text="Placeholder for stable size calculation, please do not remove."
tools:ignore="HardcodedText" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c023924..40142d1 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -34,7 +34,7 @@
<string name="clock_picker_entry_content_description">Change a custom clock</string>
<!-- Title of a section of the customization picker where the user can configure Clock face. [CHAR LIMIT=19] -->
- <string name="clock_settings_title">Clock Settings</string>
+ <string name="clock_settings_title">Clock color & size</string>
<!-- Title of a section of the customization picker where the user can configure clock color and size. [CHAR LIMIT=20] -->
<string name="clock_color_and_size_title">Clock color & size</string>
@@ -360,14 +360,7 @@
enabled. The dialog contains a list of instructions that the user needs to take in order to
enable the option before it can be selected again. [CHAR LIMIT=NONE].
-->
- <string name="keyguard_affordance_enablement_dialog_headline">Shortcut unavailable</string>
-
- <!--
- Supporting text for a popup dialog shown when the user attempts to select an option that is not
- currently enabled. The dialog contains a list of instructions that the user needs to take in
- order to enable the option before it can be selected again. [CHAR LIMIT=NONE].
- -->
- <string name="keyguard_affordance_enablement_dialog_title">To select `<xliff:g id="appName" example="Wallet">%1$s</xliff:g>` check the following</string>
+ <string name="keyguard_affordance_enablement_dialog_headline">Can\'t add shortcut</string>
<!--
Template for an action that opens a specific app. [CHAR LIMIT=16]
diff --git a/src/com/android/customization/module/CustomizationInjector.kt b/src/com/android/customization/module/CustomizationInjector.kt
index b943925..b3400bc 100644
--- a/src/com/android/customization/module/CustomizationInjector.kt
+++ b/src/com/android/customization/module/CustomizationInjector.kt
@@ -50,10 +50,7 @@
fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry
- fun getClockPickerInteractor(
- context: Context,
- lifecycleOwner: LifecycleOwner
- ): ClockPickerInteractor
+ fun getClockPickerInteractor(context: Context): ClockPickerInteractor
fun getClockSectionViewModel(
context: Context,
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt
index b23d912..6c747d7 100644
--- a/src/com/android/customization/module/ThemePickerInjector.kt
+++ b/src/com/android/customization/module/ThemePickerInjector.kt
@@ -134,7 +134,7 @@
),
getFlags(),
getClockCarouselViewModelFactory(
- getClockPickerInteractor(activity.applicationContext, activity),
+ getClockPickerInteractor(activity.applicationContext),
),
getClockViewFactory(activity),
getDarkModeSnapshotRestorer(activity),
@@ -181,7 +181,7 @@
@Synchronized
override fun getUserEventLogger(context: Context): ThemesUserEventLogger {
return if (userEventLogger != null) userEventLogger as ThemesUserEventLogger
- else StatsLogUserEventLogger(context).also { userEventLogger = it }
+ else StatsLogUserEventLogger(context.applicationContext).also { userEventLogger = it }
}
@Synchronized
@@ -211,8 +211,7 @@
this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context)
this[KEY_COLOR_PICKER_SNAPSHOT_RESTORER] =
getColorPickerSnapshotRestorer(context, getWallpaperColorsViewModel())
- this[KEY_CLOCKS_SNAPSHOT_RESTORER] =
- getClockPickerSnapshotRestorer(context, lifecycleOwner)
+ this[KEY_CLOCKS_SNAPSHOT_RESTORER] = getClockPickerSnapshotRestorer(context)
}
}
@@ -230,6 +229,7 @@
}
override fun getWallpaperInteractor(context: Context): WallpaperInteractor {
+ val appContext = context.applicationContext
return wallpaperInteractor
?: WallpaperInteractor(
repository =
@@ -237,16 +237,16 @@
scope = getApplicationCoroutineScope(),
client =
WallpaperClientImpl(
- context = context,
+ context = appContext,
infoFactory = getCurrentWallpaperInfoFactory(context),
wallpaperManager = WallpaperManager.getInstance(context)
),
- wallpaperPreferences = getPreferences(context = context),
+ wallpaperPreferences = getPreferences(context = appContext),
backgroundDispatcher = Dispatchers.IO,
),
shouldHandleReload = {
TextUtils.equals(
- getColorCustomizationManager(context).currentColorSource,
+ getColorCustomizationManager(appContext).currentColorSource,
ColorOptionsProvider.COLOR_SOURCE_PRESET
)
}
@@ -268,7 +268,7 @@
): KeyguardQuickAffordancePickerViewModel.Factory {
return keyguardQuickAffordancePickerViewModelFactory
?: KeyguardQuickAffordancePickerViewModel.Factory(
- context,
+ context.applicationContext,
getKeyguardQuickAffordancePickerInteractor(context),
getWallpaperInteractor(context),
getCurrentWallpaperInfoFactory(context),
@@ -280,11 +280,12 @@
context: Context
): KeyguardQuickAffordancePickerInteractor {
val client = getKeyguardQuickAffordancePickerProviderClient(context)
+ val appContext = context.applicationContext
return KeyguardQuickAffordancePickerInteractor(
KeyguardQuickAffordancePickerRepository(client, Dispatchers.IO),
client
) {
- getKeyguardQuickAffordanceSnapshotRestorer(context)
+ getKeyguardQuickAffordanceSnapshotRestorer(appContext)
}
}
@@ -292,7 +293,7 @@
context: Context
): CustomizationProviderClient {
return customizationProviderClient
- ?: CustomizationProviderClientImpl(context, Dispatchers.IO).also {
+ ?: CustomizationProviderClientImpl(context.applicationContext, Dispatchers.IO).also {
customizationProviderClient = it
}
}
@@ -321,6 +322,7 @@
private fun getNotificationsInteractor(
context: Context,
): NotificationsInteractor {
+ val appContext = context.applicationContext
return notificationsInteractor
?: NotificationsInteractor(
repository =
@@ -329,7 +331,7 @@
backgroundDispatcher = Dispatchers.IO,
secureSettingsRepository = getSecureSettingsRepository(context),
),
- snapshotRestorer = { getNotificationsSnapshotRestorer(context) },
+ snapshotRestorer = { getNotificationsSnapshotRestorer(appContext) },
)
.also { notificationsInteractor = it }
}
@@ -348,7 +350,7 @@
override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry {
return (clockRegistryProvider
?: ClockRegistryProvider(
- context = context,
+ context = context.applicationContext,
coroutineScope = getApplicationCoroutineScope(),
mainDispatcher = Dispatchers.Main,
backgroundDispatcher = Dispatchers.IO,
@@ -359,18 +361,19 @@
override fun getClockPickerInteractor(
context: Context,
- lifecycleOwner: LifecycleOwner,
): ClockPickerInteractor {
+ val appContext = context.applicationContext
return clockPickerInteractor
?: ClockPickerInteractor(
repository =
ClockPickerRepositoryImpl(
secureSettingsRepository = getSecureSettingsRepository(context),
- registry = getClockRegistry(context, lifecycleOwner),
+ // TODO (b/285978251): remove second argument once b/285348630 is fixed
+ registry = getClockRegistry(context, context as LifecycleOwner),
scope = getApplicationCoroutineScope(),
mainDispatcher = Dispatchers.Main,
),
- snapshotRestorer = { getClockPickerSnapshotRestorer(context, lifecycleOwner) },
+ snapshotRestorer = { getClockPickerSnapshotRestorer(appContext) },
)
.also { clockPickerInteractor = it }
}
@@ -380,7 +383,7 @@
lifecycleOwner: LifecycleOwner
): ClockSectionViewModel {
return clockSectionViewModel
- ?: ClockSectionViewModel(context, getClockPickerInteractor(context, lifecycleOwner))
+ ?: ClockSectionViewModel(context.applicationContext, getClockPickerInteractor(context))
.also { clockSectionViewModel = it }
}
@@ -422,10 +425,9 @@
private fun getClockPickerSnapshotRestorer(
context: Context,
- lifecycleOwner: LifecycleOwner
): ClockPickerSnapshotRestorer {
return clockPickerSnapshotRestorer
- ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context, lifecycleOwner)).also {
+ ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context)).also {
clockPickerSnapshotRestorer = it
}
}
@@ -434,15 +436,16 @@
context: Context,
wallpaperColorsViewModel: WallpaperColorsViewModel,
): ColorPickerInteractor {
+ val appContext = context.applicationContext
return colorPickerInteractor
?: ColorPickerInteractor(
repository =
ColorPickerRepositoryImpl(
wallpaperColorsViewModel,
- getColorCustomizationManager(context)
+ getColorCustomizationManager(appContext)
),
snapshotRestorer = {
- getColorPickerSnapshotRestorer(context, wallpaperColorsViewModel)
+ getColorPickerSnapshotRestorer(appContext, wallpaperColorsViewModel)
}
)
.also { colorPickerInteractor = it }
@@ -454,7 +457,7 @@
): ColorPickerViewModel.Factory {
return colorPickerViewModelFactory
?: ColorPickerViewModel.Factory(
- context,
+ context.applicationContext,
getColorPickerInteractor(context, wallpaperColorsViewModel),
)
.also { colorPickerViewModelFactory = it }
@@ -481,10 +484,11 @@
fun getDarkModeSnapshotRestorer(
context: Context,
): DarkModeSnapshotRestorer {
+ val appContext = context.applicationContext
return darkModeSnapshotRestorer
?: DarkModeSnapshotRestorer(
- context = context,
- manager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager,
+ context = appContext,
+ manager = appContext.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager,
backgroundDispatcher = Dispatchers.IO,
)
.also { darkModeSnapshotRestorer = it }
@@ -521,8 +525,8 @@
): ClockSettingsViewModel.Factory {
return clockSettingsViewModelFactory
?: ClockSettingsViewModel.Factory(
- context,
- getClockPickerInteractor(context, lifecycleOwner),
+ context.applicationContext,
+ getClockPickerInteractor(context),
getColorPickerInteractor(
context,
wallpaperColorsViewModel,
@@ -548,6 +552,7 @@
private fun getGridInteractor(
context: Context,
): GridInteractor {
+ val appContext = context.applicationContext
return gridInteractor
?: GridInteractor(
applicationScope = getApplicationCoroutineScope(),
@@ -557,7 +562,7 @@
manager = GridOptionsManager.getInstance(context),
backgroundDispatcher = Dispatchers.IO,
),
- snapshotRestorer = { getGridSnapshotRestorer(context) },
+ snapshotRestorer = { getGridSnapshotRestorer(appContext) },
)
.also { gridInteractor = it }
}
diff --git a/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModel.kt b/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModel.kt
index 008a125..8a65522 100644
--- a/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModel.kt
+++ b/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModel.kt
@@ -35,7 +35,7 @@
(selectedColorId, selectedClockSize) ->
val colorText =
clockColorMap[selectedColorId]?.colorName
- ?: context.getString(R.string.default_theme_title)
+ ?: appContext.getString(R.string.default_theme_title)
val sizeText =
when (selectedClockSize) {
ClockSize.SMALL -> appContext.getString(R.string.clock_size_small)
diff --git a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
index 9729661..b17af80 100644
--- a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
+++ b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
@@ -80,7 +80,7 @@
name = name,
iconResourceId = iconResourceId,
isEnabled = isEnabled,
- enablementInstructions = enablementInstructions ?: emptyList(),
+ enablementExplanation = enablementExplanation ?: "",
enablementActionText = enablementActionText,
enablementActionIntent = enablementActionIntent,
configureIntent = configureIntent,
diff --git a/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt b/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
index 5ca7d56..e53f790 100644
--- a/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
@@ -31,8 +31,8 @@
@DrawableRes val iconResourceId: Int,
/** Whether this quick affordance is enabled. */
val isEnabled: Boolean,
- /** If not enabled, the list of user-visible steps to re-enable it. */
- val enablementInstructions: List<String>,
+ /** If not enabled, the user-visible message explaining why. */
+ val enablementExplanation: String,
/**
* If not enabled, an optional label for a button that takes the user to a destination where
* they can re-enable it.
diff --git a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 08cb756..f832cde 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -261,7 +261,7 @@
showEnablementDialog(
icon = affordanceIcon,
name = affordance.name,
- instructions = affordance.enablementInstructions,
+ explanation = affordance.enablementExplanation,
actionText = affordance.enablementActionText,
actionIntent = affordance.enablementActionIntent,
)
@@ -346,7 +346,7 @@
private fun showEnablementDialog(
icon: Drawable,
name: String,
- instructions: List<String>,
+ explanation: String,
actionText: String?,
actionIntent: Intent?,
) {
@@ -358,39 +358,38 @@
contentDescription = null,
),
headline = Text.Resource(R.string.keyguard_affordance_enablement_dialog_headline),
- supportingText =
- Text.Loaded(
- applicationContext.getString(
- R.string.keyguard_affordance_enablement_dialog_title,
- name
- )
- ),
- message =
- Text.Loaded(
- buildString {
- instructions.forEachIndexed { index, instruction ->
- if (index > 0) {
- append('\n')
- }
-
- append(instruction)
- }
- }
- ),
+ message = Text.Loaded(explanation),
buttons =
- listOf(
- ButtonViewModel(
- text = actionText?.let { Text.Loaded(actionText) }
- ?: Text.Resource(
- R.string
- .keyguard_affordance_enablement_dialog_dismiss_button,
+ buildList {
+ add(
+ ButtonViewModel(
+ text =
+ Text.Resource(
+ if (actionText != null) {
+ // This is not the only button on the dialog.
+ R.string.cancel
+ } else {
+ // This is the only button on the dialog.
+ R.string
+ .keyguard_affordance_enablement_dialog_dismiss_button
+ }
),
- style = ButtonStyle.Primary,
- onClicked = {
- actionIntent?.let { intent -> requestActivityStart(intent) }
- }
- ),
- ),
+ style = ButtonStyle.Secondary,
+ ),
+ )
+
+ if (actionText != null) {
+ add(
+ ButtonViewModel(
+ text = Text.Loaded(actionText),
+ style = ButtonStyle.Primary,
+ onClicked = {
+ actionIntent?.let { intent -> requestActivityStart(intent) }
+ }
+ ),
+ )
+ }
+ },
)
}
diff --git a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
index d51f411..3f10674 100644
--- a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
+++ b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
@@ -248,7 +248,7 @@
val dialog = collectLastValue(underTest.dialog)
val activityStartRequest = collectLastValue(underTest.activityStartRequests)
- val enablementInstructions = listOf("instruction1", "instruction2")
+ val enablementExplanation = "enablementExplanation"
val enablementActionText = "enablementActionText"
val packageName = "packageName"
val action = "action"
@@ -261,7 +261,7 @@
name = "disabled",
iconResourceId = 1,
isEnabled = false,
- enablementInstructions = enablementInstructions,
+ enablementExplanation = enablementExplanation,
enablementActionText = enablementActionText,
enablementActionIntent = enablementActionIntent,
)
@@ -275,15 +275,14 @@
.isEqualTo(Icon.Loaded(FakeCustomizationProviderClient.ICON_1, null))
assertThat(dialog()?.headline)
.isEqualTo(Text.Resource(R.string.keyguard_affordance_enablement_dialog_headline))
- assertThat(dialog()?.message)
- .isEqualTo(Text.Loaded(enablementInstructions.joinToString("\n")))
- assertThat(dialog()?.buttons?.size).isEqualTo(1)
- assertThat(dialog()?.buttons?.first()?.text)
- .isEqualTo(Text.Loaded(enablementActionText))
+ assertThat(dialog()?.message).isEqualTo(Text.Loaded(enablementExplanation))
+ assertThat(dialog()?.buttons?.size).isEqualTo(2)
+ assertThat(dialog()?.buttons?.first()?.text).isEqualTo(Text.Resource(R.string.cancel))
+ assertThat(dialog()?.buttons?.get(1)?.text).isEqualTo(Text.Loaded(enablementActionText))
// When the button is clicked, we expect an intent of the given enablement action
// component name to be emitted.
- dialog()?.buttons?.first()?.onClicked?.invoke()
+ dialog()?.buttons?.get(1)?.onClicked?.invoke()
assertThat(activityStartRequest()?.`package`).isEqualTo(packageName)
assertThat(activityStartRequest()?.action).isEqualTo(action)