Fix Kotlin warnings
MediaArtworkProcessor change to use new WindowContext. Still suppressing deprecation in DetailDialog. Test: build Test: atest MediaArtworkProcessorTest Bug: 149787017 Change-Id: I9288076ac29077e90a978e8e5ee38080992a15ca
This commit is contained in:
@@ -135,7 +135,7 @@ class ControlsFavoritePersistenceWrapper(
|
||||
}
|
||||
|
||||
private fun parseXml(parser: XmlPullParser): List<ControlInfo> {
|
||||
var type = 0
|
||||
var type: Int
|
||||
val infos = mutableListOf<ControlInfo>()
|
||||
while (parser.next().also { type = it } != XmlPullParser.END_DOCUMENT) {
|
||||
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
|
||||
|
||||
@@ -58,13 +58,13 @@ class AppAdapter(
|
||||
private var listOfServices = emptyList<CandidateInfo>()
|
||||
|
||||
private val callback = object : ControlsListingController.ControlsListingCallback {
|
||||
override fun onServicesUpdated(list: List<CandidateInfo>) {
|
||||
override fun onServicesUpdated(candidates: List<CandidateInfo>) {
|
||||
backgroundExecutor.execute {
|
||||
val collator = Collator.getInstance(resources.getConfiguration().locale)
|
||||
val collator = Collator.getInstance(resources.configuration.locales[0])
|
||||
val localeComparator = compareBy<CandidateInfo, CharSequence>(collator) {
|
||||
it.loadLabel()
|
||||
}
|
||||
listOfServices = list.sortedWith(localeComparator)
|
||||
listOfServices = candidates.sortedWith(localeComparator)
|
||||
uiExecutor.execute(::notifyDataSetChanged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class ControlsFavoritingActivity @Inject constructor(
|
||||
target: RecyclerView.ViewHolder
|
||||
): Boolean {
|
||||
return currentModel?.onMoveItem(
|
||||
viewHolder.adapterPosition, target.adapterPosition) != null
|
||||
viewHolder.layoutPosition, target.layoutPosition) != null
|
||||
}
|
||||
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {}
|
||||
|
||||
@@ -45,6 +45,6 @@ interface ControlsListingController :
|
||||
|
||||
@FunctionalInterface
|
||||
interface ControlsListingCallback {
|
||||
fun onServicesUpdated(list: List<CandidateInfo>)
|
||||
fun onServicesUpdated(candidates: List<CandidateInfo>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
||||
private val listingCallback = object : ControlsListingController.ControlsListingCallback {
|
||||
override fun onServicesUpdated(candidates: List<CandidateInfo>) {
|
||||
bgExecutor.execute {
|
||||
val collator = Collator.getInstance(context.getResources()
|
||||
.getConfiguration().locale)
|
||||
val collator = Collator.getInstance(context.resources.configuration.locales[0])
|
||||
val localeComparator = compareBy<CandidateInfo, CharSequence>(collator) {
|
||||
it.loadLabel()
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class DetailDialog(
|
||||
val intent: PendingIntent
|
||||
) : Dialog(parentContext) {
|
||||
|
||||
lateinit var activityView: ActivityView
|
||||
var activityView: ActivityView
|
||||
|
||||
val stateCallback: ActivityView.StateCallback = object : ActivityView.StateCallback() {
|
||||
override fun onActivityViewReady(view: ActivityView) {
|
||||
@@ -61,24 +61,28 @@ class DetailDialog(
|
||||
override fun onTaskRemovalStarted(taskId: Int) {}
|
||||
}
|
||||
|
||||
init {
|
||||
val window = getWindow()
|
||||
window.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
@Suppress("DEPRECATION")
|
||||
private fun Window.setWindowParams() {
|
||||
requestFeature(Window.FEATURE_NO_TITLE)
|
||||
|
||||
// Inflate the decor view, so the attributes below are not overwritten by the theme.
|
||||
window.getDecorView()
|
||||
window.getAttributes().systemUiVisibility =
|
||||
(window.getAttributes().systemUiVisibility
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
|
||||
decorView
|
||||
attributes.systemUiVisibility =
|
||||
(attributes.systemUiVisibility
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
|
||||
|
||||
window.setLayout(MATCH_PARENT, MATCH_PARENT)
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
|
||||
or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
|
||||
or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
|
||||
window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY)
|
||||
window.getAttributes().setFitInsetsTypes(0 /* types */)
|
||||
setLayout(MATCH_PARENT, MATCH_PARENT)
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
|
||||
addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
|
||||
or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
|
||||
or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
|
||||
setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY)
|
||||
getAttributes().setFitInsetsTypes(0 /* types */)
|
||||
}
|
||||
|
||||
init {
|
||||
getWindow()?.setWindowParams()
|
||||
|
||||
setContentView(R.layout.controls_detail_dialog)
|
||||
|
||||
@@ -89,9 +93,9 @@ class DetailDialog(
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
val attrs = getWindow().getAttributes()
|
||||
attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
getWindow().setAttributes(attrs)
|
||||
val attrs = getWindow()?.attributes
|
||||
attrs?.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
getWindow()?.attributes = attrs
|
||||
|
||||
activityView.setCallback(stateCallback)
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class ToggleRangeBehavior : Behavior {
|
||||
|
||||
val gestureListener = ToggleRangeGestureListener(cvh.layout)
|
||||
val gestureDetector = GestureDetector(context, gestureListener)
|
||||
cvh.layout.setOnTouchListener({ v: View, e: MotionEvent ->
|
||||
cvh.layout.setOnTouchListener { _: View, e: MotionEvent ->
|
||||
if (gestureDetector.onTouchEvent(e)) {
|
||||
return@setOnTouchListener true
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class ToggleRangeBehavior : Behavior {
|
||||
}
|
||||
|
||||
return@setOnTouchListener false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun bind(cws: ControlWithState) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Point
|
||||
import android.graphics.Rect
|
||||
import android.renderscript.Allocation
|
||||
import android.renderscript.Element
|
||||
@@ -27,9 +26,11 @@ import android.renderscript.RenderScript
|
||||
import android.renderscript.ScriptIntrinsicBlur
|
||||
import android.util.Log
|
||||
import android.util.MathUtils
|
||||
import android.util.Size
|
||||
import android.view.WindowManager
|
||||
import com.android.internal.annotations.VisibleForTesting
|
||||
import com.android.internal.graphics.ColorUtils
|
||||
import com.android.systemui.statusbar.notification.MediaNotificationProcessor
|
||||
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -41,10 +42,9 @@ private const val DOWNSAMPLE = 6
|
||||
@Singleton
|
||||
class MediaArtworkProcessor @Inject constructor() {
|
||||
|
||||
private val mTmpSize = Point()
|
||||
private var mArtworkCache: Bitmap? = null
|
||||
|
||||
fun processArtwork(context: Context, artwork: Bitmap): Bitmap? {
|
||||
fun processArtwork(context: Context, artwork: Bitmap, windowType: Int): Bitmap? {
|
||||
if (mArtworkCache != null) {
|
||||
return mArtworkCache
|
||||
}
|
||||
@@ -54,9 +54,9 @@ class MediaArtworkProcessor @Inject constructor() {
|
||||
var output: Allocation? = null
|
||||
var inBitmap: Bitmap? = null
|
||||
try {
|
||||
context.display.getSize(mTmpSize)
|
||||
val size = getWindowSize(context, windowType)
|
||||
val rect = Rect(0, 0, artwork.width, artwork.height)
|
||||
MathUtils.fitRect(rect, Math.max(mTmpSize.x / DOWNSAMPLE, mTmpSize.y / DOWNSAMPLE))
|
||||
MathUtils.fitRect(rect, Math.max(size.width / DOWNSAMPLE, size.height / DOWNSAMPLE))
|
||||
inBitmap = Bitmap.createScaledBitmap(artwork, rect.width(), rect.height(),
|
||||
true /* filter */)
|
||||
// Render script blurs only support ARGB_8888, we need a conversion if we got a
|
||||
@@ -98,4 +98,15 @@ class MediaArtworkProcessor @Inject constructor() {
|
||||
mArtworkCache?.recycle()
|
||||
mArtworkCache = null
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun getWindowSize(context: Context, windowType: Int): Size {
|
||||
val windowContext = context.display?.let {
|
||||
context.createDisplayContext(it)
|
||||
.createWindowContext(windowType, null)
|
||||
} ?: run { throw NullPointerException("Display is null") }
|
||||
val windowManager = windowContext.getSystemService(WindowManager::class.java)
|
||||
?: run { throw NullPointerException("Null window manager") }
|
||||
return windowManager.currentWindowMetrics.size
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ import android.provider.DeviceConfig.Properties;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
|
||||
@@ -668,7 +669,8 @@ public class NotificationMediaManager implements Dumpable {
|
||||
};
|
||||
|
||||
private Bitmap processArtwork(Bitmap artwork) {
|
||||
return mMediaArtworkProcessor.processArtwork(mContext, artwork);
|
||||
return mMediaArtworkProcessor.processArtwork(mContext, artwork,
|
||||
WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE);
|
||||
}
|
||||
|
||||
@MainThread
|
||||
|
||||
@@ -132,7 +132,6 @@ class FloatingContentCoordinator @Inject constructor() {
|
||||
*
|
||||
* @param content The content that has moved.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun onContentMoved(content: FloatingContent) {
|
||||
|
||||
// Ignore calls when we are currently resolving conflicts, since those calls are from
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
|
||||
package com.android.systemui.statusbar
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Point
|
||||
import android.testing.AndroidTestingRunner
|
||||
import android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@@ -32,6 +31,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
private const val WIDTH = 200
|
||||
private const val HEIGHT = 200
|
||||
private const val WINDOW_TYPE = TYPE_NOTIFICATION_SHADE
|
||||
|
||||
@RunWith(AndroidTestingRunner::class)
|
||||
@SmallTest
|
||||
@@ -46,10 +46,10 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
|
||||
fun setUp() {
|
||||
processor = MediaArtworkProcessor()
|
||||
|
||||
val point = Point()
|
||||
context.display.getSize(point)
|
||||
screenWidth = point.x
|
||||
screenHeight = point.y
|
||||
val size = processor.getWindowSize(context, WINDOW_TYPE)
|
||||
|
||||
screenWidth = size.width
|
||||
screenHeight = size.height
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -63,7 +63,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
|
||||
val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888)
|
||||
Canvas(artwork).drawColor(Color.BLUE)
|
||||
// WHEN the background is created from the artwork
|
||||
val background = processor.processArtwork(context, artwork)!!
|
||||
val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!!
|
||||
// THEN the background has the size of the screen that has been downsamples
|
||||
assertThat(background.height).isLessThan(screenHeight)
|
||||
assertThat(background.width).isLessThan(screenWidth)
|
||||
@@ -76,8 +76,8 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
|
||||
val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888)
|
||||
Canvas(artwork).drawColor(Color.BLUE)
|
||||
// WHEN the background is processed twice
|
||||
val background1 = processor.processArtwork(context, artwork)!!
|
||||
val background2 = processor.processArtwork(context, artwork)!!
|
||||
val background1 = processor.processArtwork(context, artwork, WINDOW_TYPE)!!
|
||||
val background2 = processor.processArtwork(context, artwork, WINDOW_TYPE)!!
|
||||
// THEN the two bitmaps are the same
|
||||
// Note: This is currently broken and trying to use caching causes issues
|
||||
assertThat(background1).isNotSameAs(background2)
|
||||
@@ -89,7 +89,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
|
||||
val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ALPHA_8)
|
||||
Canvas(artwork).drawColor(Color.BLUE)
|
||||
// WHEN the background is created from the artwork
|
||||
val background = processor.processArtwork(context, artwork)!!
|
||||
val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!!
|
||||
// THEN the background has Config ARGB_8888
|
||||
assertThat(background.config).isEqualTo(Bitmap.Config.ARGB_8888)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
|
||||
// AND the artwork is recycled
|
||||
artwork.recycle()
|
||||
// WHEN the background is created from the artwork
|
||||
val background = processor.processArtwork(context, artwork)
|
||||
val background = processor.processArtwork(context, artwork, WINDOW_TYPE)
|
||||
// THEN the processed bitmap is null
|
||||
assertThat(background).isNull()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user