diff options
author | Shriya Gupta <shrigupt@google.com> | 2023-03-01 09:06:31 +0000 |
---|---|---|
committer | Shriya Gupta <shrigupt@google.com> | 2023-03-03 13:28:55 +0000 |
commit | 1e1df41772c1712a6e227738214f6a6d5e5a04b2 (patch) | |
tree | f32ca34d5404f65039f8d7218076c35830ad5a67 /PermissionController/src/com/android/permissioncontroller/safetycenter | |
parent | 7dea6bd529edc43fa62e6afde89998c70aae87e0 (diff) | |
download | Permission-1e1df41772c1712a6e227738214f6a6d5e5a04b2.tar.gz |
Fix illustration width for device rotation
The IllustrationPreference from SettingsLib doesn't allow setting the image width greater than the image height. But to align with the other warning cards in Safety Center, we need the width to be greater than the height incase of device rotations / large-screen devices. Hence, changing to a custom implementation for the illustrations.
Note: It currently uses the placeholder images which might seem a bit expanded. These will be replaced with final assets from UX that are smaller in height.
Bug: 253171482
Test: atest SafetyCenterSubpagesTest
Change-Id: I1eef98708df96ef6c920cddf0d673bc537a2f02e
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/safetycenter')
2 files changed, 48 insertions, 4 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterSubpageFragment.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterSubpageFragment.kt index 992fac76d..84455a10a 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterSubpageFragment.kt +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterSubpageFragment.kt @@ -27,7 +27,6 @@ import com.android.permissioncontroller.safetycenter.ui.SafetyBrandChipPreferenc import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterUiData import com.android.safetycenter.resources.SafetyCenterResourcesContext import com.android.settingslib.widget.FooterPreference -import com.android.settingslib.widget.IllustrationPreference /** A fragment that represents a generic subpage in Safety Center. */ @RequiresApi(UPSIDE_DOWN_CAKE) @@ -35,7 +34,7 @@ class SafetyCenterSubpageFragment : SafetyCenterFragment() { private lateinit var sourceGroupId: String private lateinit var subpageBrandChip: SafetyBrandChipPreference - private lateinit var subpageIllustration: IllustrationPreference + private lateinit var subpageIllustration: SafetyIllustrationPreference private lateinit var subpageIssueGroup: PreferenceGroup private lateinit var subpageEntryGroup: PreferenceGroup private lateinit var subpageFooter: FooterPreference @@ -87,7 +86,7 @@ class SafetyCenterSubpageFragment : SafetyCenterFragment() { subpageIllustration.setVisible(false) } - subpageIllustration.setImageDrawable(drawable) + subpageIllustration.illustrationDrawable = drawable } private fun setupFooter() { @@ -107,7 +106,7 @@ class SafetyCenterSubpageFragment : SafetyCenterFragment() { val subpageDismissedIssues = uiData?.getMatchingDismissedIssues(sourceGroupId) subpageIllustration.isVisible = - subpageIssues.isNullOrEmpty() && subpageIllustration.imageDrawable != null + subpageIssues.isNullOrEmpty() && subpageIllustration.illustrationDrawable != null if (subpageIssues.isNullOrEmpty() && subpageDismissedIssues.isNullOrEmpty()) { Log.w(TAG, "$sourceGroupId doesn't have any matching SafetyCenterIssues") diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyIllustrationPreference.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyIllustrationPreference.kt new file mode 100644 index 000000000..da16cfa8b --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyIllustrationPreference.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * 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. + */ + +package com.android.permissioncontroller.safetycenter.ui + +import android.content.Context +import android.graphics.drawable.Drawable +import android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE +import android.util.AttributeSet +import android.widget.ImageView +import androidx.annotation.RequiresApi +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import com.android.permissioncontroller.R + +/** A preference that displays the illustration on a Safety Center subpage. */ +@RequiresApi(UPSIDE_DOWN_CAKE) +internal class SafetyIllustrationPreference(context: Context, attrs: AttributeSet) : + Preference(context, attrs) { + + init { + layoutResource = R.layout.preference_illustration + } + + var illustrationDrawable: Drawable? = null + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + val illustrationView = holder.findViewById(R.id.illustration_view) as ImageView + illustrationView.setImageDrawable(illustrationDrawable) + } +} |