Loading iconloaderlib/src/com/android/launcher3/icons/cache/CachedObject.java +3 −7 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.launcher3.icons.cache; import android.content.ComponentName; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.UserHandle; Loading @@ -29,10 +28,8 @@ import com.android.launcher3.icons.IconProvider; /** * A simple interface to represent an object which can be added to icon cache * * @param <T> Any subclass of the icon cache with which this object is associated */ public interface CachedObject<T extends BaseIconCache> { public interface CachedObject { /** * Returns the component name for the underlying object Loading @@ -47,13 +44,13 @@ public interface CachedObject<T extends BaseIconCache> { /** * Loads the user visible label for the provided object */ @Nullable CharSequence getLabel(PackageManager pm); @Nullable CharSequence getLabel(); /** * Loads the user visible icon for the provided object */ @Nullable default Drawable getFullResIcon(@NonNull T cache) { default Drawable getFullResIcon(@NonNull BaseIconCache cache) { return null; } Loading @@ -63,7 +60,6 @@ public interface CachedObject<T extends BaseIconCache> { @Nullable ApplicationInfo getApplicationInfo(); /** * Returns a persistable string that can be used to indicate indicate the correctness of the * cache for the provided item Loading iconloaderlib/src/com/android/launcher3/icons/cache/CachedObjectCachingLogic.kt +8 −15 Original line number Diff line number Diff line Loading @@ -24,30 +24,23 @@ import com.android.launcher3.icons.BitmapInfo import com.android.launcher3.icons.IconProvider /** Caching logic for ComponentWithLabelAndIcon */ class CachedObjectCachingLogic<T : BaseIconCache>(context: Context) : CachingLogic<CachedObject<T>> { object CachedObjectCachingLogic : CachingLogic<CachedObject> { private val pm = context.packageManager override fun getComponent(info: CachedObject): ComponentName = info.component override fun getComponent(info: CachedObject<T>): ComponentName = info.component override fun getUser(info: CachedObject): UserHandle = info.user override fun getUser(info: CachedObject<T>): UserHandle = info.user override fun getLabel(info: CachedObject): CharSequence? = info.label override fun getLabel(info: CachedObject<T>): CharSequence? = info.getLabel(pm) override fun loadIcon( context: Context, cache: BaseIconCache, info: CachedObject<T>, ): BitmapInfo { val d = info.getFullResIcon(cache as T) ?: return BitmapInfo.LOW_RES_INFO override fun loadIcon(context: Context, cache: BaseIconCache, info: CachedObject): BitmapInfo { val d = info.getFullResIcon(cache) ?: return BitmapInfo.LOW_RES_INFO cache.iconFactory.use { li -> return li.createBadgedIconBitmap(d, IconOptions().setUser(info.user)) } } override fun getApplicationInfo(info: CachedObject<T>) = info.applicationInfo override fun getApplicationInfo(info: CachedObject) = info.applicationInfo override fun getFreshnessIdentifier(item: CachedObject<T>, provider: IconProvider): String? = override fun getFreshnessIdentifier(item: CachedObject, provider: IconProvider): String? = item.getFreshnessIdentifier(provider) } msdllib/src/com/google/android/msdl/domain/EmptyMSDLPlayer.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.google.android.msdl.domain import com.google.android.msdl.data.model.FeedbackLevel import com.google.android.msdl.data.model.MSDLToken import com.google.android.msdl.logging.MSDLEvent /** An empty [MSDLPlayer] that was created without a [android.os.Vibrator] */ internal class EmptyMSDLPlayer : MSDLPlayer { override fun getSystemFeedbackLevel(): FeedbackLevel = FeedbackLevel.NO_FEEDBACK override fun playToken(token: MSDLToken, properties: InteractionProperties?) {} override fun getHistory(): List<MSDLEvent> = listOf() override fun toString(): String = "Empty MSDL player without a vibrator." } msdllib/src/com/google/android/msdl/domain/MSDLPlayer.kt +10 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.google.android.msdl.domain import android.os.Vibrator import android.util.Log import com.google.android.msdl.data.model.FeedbackLevel import com.google.android.msdl.data.model.HapticComposition import com.google.android.msdl.data.model.MSDLToken Loading Loading @@ -73,10 +74,18 @@ interface MSDLPlayer { * created using the support information from the given vibrator. */ fun createPlayer( vibrator: Vibrator, vibrator: Vibrator?, executor: Executor = Executors.newSingleThreadExecutor(), useHapticFeedbackForToken: Map<MSDLToken, Boolean>? = null, ): MSDLPlayer { // Return an empty player if no vibrator is available if (vibrator == null) { Log.w( "MSDLPlayer", "A null vibrator was used to create a MSDLPlayer. An empty player was created", ) return EmptyMSDLPlayer() } // Create repository val repository = MSDLRepositoryImpl() Loading msdllib/src/com/google/android/msdl/domain/MSDLPlayerImpl.kt +8 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,14 @@ internal class MSDLPlayerImpl( override fun getHistory(): List<MSDLEvent> = historyLogger.getHistory() override fun toString(): String = """ Default MSDL player implementation. Vibrator: $vibrator Repository: $repository """ .trimIndent() companion object { val REQUIRED_PRIMITIVES = listOf( Loading Loading
iconloaderlib/src/com/android/launcher3/icons/cache/CachedObject.java +3 −7 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.launcher3.icons.cache; import android.content.ComponentName; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.UserHandle; Loading @@ -29,10 +28,8 @@ import com.android.launcher3.icons.IconProvider; /** * A simple interface to represent an object which can be added to icon cache * * @param <T> Any subclass of the icon cache with which this object is associated */ public interface CachedObject<T extends BaseIconCache> { public interface CachedObject { /** * Returns the component name for the underlying object Loading @@ -47,13 +44,13 @@ public interface CachedObject<T extends BaseIconCache> { /** * Loads the user visible label for the provided object */ @Nullable CharSequence getLabel(PackageManager pm); @Nullable CharSequence getLabel(); /** * Loads the user visible icon for the provided object */ @Nullable default Drawable getFullResIcon(@NonNull T cache) { default Drawable getFullResIcon(@NonNull BaseIconCache cache) { return null; } Loading @@ -63,7 +60,6 @@ public interface CachedObject<T extends BaseIconCache> { @Nullable ApplicationInfo getApplicationInfo(); /** * Returns a persistable string that can be used to indicate indicate the correctness of the * cache for the provided item Loading
iconloaderlib/src/com/android/launcher3/icons/cache/CachedObjectCachingLogic.kt +8 −15 Original line number Diff line number Diff line Loading @@ -24,30 +24,23 @@ import com.android.launcher3.icons.BitmapInfo import com.android.launcher3.icons.IconProvider /** Caching logic for ComponentWithLabelAndIcon */ class CachedObjectCachingLogic<T : BaseIconCache>(context: Context) : CachingLogic<CachedObject<T>> { object CachedObjectCachingLogic : CachingLogic<CachedObject> { private val pm = context.packageManager override fun getComponent(info: CachedObject): ComponentName = info.component override fun getComponent(info: CachedObject<T>): ComponentName = info.component override fun getUser(info: CachedObject): UserHandle = info.user override fun getUser(info: CachedObject<T>): UserHandle = info.user override fun getLabel(info: CachedObject): CharSequence? = info.label override fun getLabel(info: CachedObject<T>): CharSequence? = info.getLabel(pm) override fun loadIcon( context: Context, cache: BaseIconCache, info: CachedObject<T>, ): BitmapInfo { val d = info.getFullResIcon(cache as T) ?: return BitmapInfo.LOW_RES_INFO override fun loadIcon(context: Context, cache: BaseIconCache, info: CachedObject): BitmapInfo { val d = info.getFullResIcon(cache) ?: return BitmapInfo.LOW_RES_INFO cache.iconFactory.use { li -> return li.createBadgedIconBitmap(d, IconOptions().setUser(info.user)) } } override fun getApplicationInfo(info: CachedObject<T>) = info.applicationInfo override fun getApplicationInfo(info: CachedObject) = info.applicationInfo override fun getFreshnessIdentifier(item: CachedObject<T>, provider: IconProvider): String? = override fun getFreshnessIdentifier(item: CachedObject, provider: IconProvider): String? = item.getFreshnessIdentifier(provider) }
msdllib/src/com/google/android/msdl/domain/EmptyMSDLPlayer.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.google.android.msdl.domain import com.google.android.msdl.data.model.FeedbackLevel import com.google.android.msdl.data.model.MSDLToken import com.google.android.msdl.logging.MSDLEvent /** An empty [MSDLPlayer] that was created without a [android.os.Vibrator] */ internal class EmptyMSDLPlayer : MSDLPlayer { override fun getSystemFeedbackLevel(): FeedbackLevel = FeedbackLevel.NO_FEEDBACK override fun playToken(token: MSDLToken, properties: InteractionProperties?) {} override fun getHistory(): List<MSDLEvent> = listOf() override fun toString(): String = "Empty MSDL player without a vibrator." }
msdllib/src/com/google/android/msdl/domain/MSDLPlayer.kt +10 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.google.android.msdl.domain import android.os.Vibrator import android.util.Log import com.google.android.msdl.data.model.FeedbackLevel import com.google.android.msdl.data.model.HapticComposition import com.google.android.msdl.data.model.MSDLToken Loading Loading @@ -73,10 +74,18 @@ interface MSDLPlayer { * created using the support information from the given vibrator. */ fun createPlayer( vibrator: Vibrator, vibrator: Vibrator?, executor: Executor = Executors.newSingleThreadExecutor(), useHapticFeedbackForToken: Map<MSDLToken, Boolean>? = null, ): MSDLPlayer { // Return an empty player if no vibrator is available if (vibrator == null) { Log.w( "MSDLPlayer", "A null vibrator was used to create a MSDLPlayer. An empty player was created", ) return EmptyMSDLPlayer() } // Create repository val repository = MSDLRepositoryImpl() Loading
msdllib/src/com/google/android/msdl/domain/MSDLPlayerImpl.kt +8 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,14 @@ internal class MSDLPlayerImpl( override fun getHistory(): List<MSDLEvent> = historyLogger.getHistory() override fun toString(): String = """ Default MSDL player implementation. Vibrator: $vibrator Repository: $repository """ .trimIndent() companion object { val REQUIRED_PRIMITIVES = listOf( Loading