mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
fix styles
This commit is contained in:
@@ -19,7 +19,7 @@ class LawnchairAlphabeticalAppsList<T>(
|
||||
context: T,
|
||||
appsStore: AllAppsStore<T>,
|
||||
workProfileManager: WorkProfileManager?,
|
||||
privateProfileManager: PrivateProfileManager
|
||||
privateProfileManager: PrivateProfileManager,
|
||||
) : AlphabeticalAppsList<T>(context, appsStore, workProfileManager, privateProfileManager)
|
||||
where T : Context, T : ActivityContext {
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.view.ViewGroup
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import app.lawnchair.launcher
|
||||
import app.lawnchair.search.adapter.SHORTCUT
|
||||
import app.lawnchair.search.adapter.SearchTargetCompat
|
||||
import app.lawnchair.search.model.SearchResultActionCallBack
|
||||
import app.lawnchair.util.runOnMainThread
|
||||
|
||||
@@ -24,7 +24,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Room.databaseBuilder(
|
||||
context,
|
||||
AppDatabase::class.java,
|
||||
"preferences"
|
||||
"preferences",
|
||||
).build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ import com.android.launcher3.pm.PackageInstallInfo.STATUS_INSTALLED
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
import com.android.launcher3.util.MainThreadInitializedObject
|
||||
import com.android.launcher3.util.SafeCloseable
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.plus
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
|
||||
class IconOverrideRepository(private val context: Context) : SafeCloseable {
|
||||
|
||||
@@ -64,9 +64,13 @@ class IconOverrideRepository(private val context: Context) : SafeCloseable {
|
||||
|
||||
private fun updatePackageIcons(target: ComponentKey) {
|
||||
val model = LauncherAppState.getInstance(context).model
|
||||
model.onPackageStateChanged(PackageInstallInfo.fromState(
|
||||
STATUS_INSTALLED,
|
||||
target.componentName.packageName, target.user))
|
||||
model.onPackageStateChanged(
|
||||
PackageInstallInfo.fromState(
|
||||
STATUS_INSTALLED,
|
||||
target.componentName.packageName,
|
||||
target.user,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package app.lawnchair.overview
|
||||
|
||||
object TaskShortcutFactory {
|
||||
|
||||
}
|
||||
object TaskShortcutFactory
|
||||
|
||||
@@ -32,6 +32,7 @@ import app.lawnchair.hotseat.HotseatMode
|
||||
import app.lawnchair.icons.CustomAdaptiveIconDrawable
|
||||
import app.lawnchair.icons.shape.IconShape
|
||||
import app.lawnchair.icons.shape.IconShapeManager
|
||||
import app.lawnchair.preferences.PreferenceManager as LawnchairPreferenceManager
|
||||
import app.lawnchair.qsb.providers.QsbSearchProvider
|
||||
import app.lawnchair.search.algorithms.LawnchairSearchAlgorithm
|
||||
import app.lawnchair.search.algorithms.data.WebSearchProvider
|
||||
@@ -47,6 +48,7 @@ import com.android.launcher3.InvariantDeviceProfile
|
||||
import com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.graphics.IconShape as L3IconShape
|
||||
import com.android.launcher3.util.DynamicResource
|
||||
import com.android.launcher3.util.MainThreadInitializedObject
|
||||
import com.android.launcher3.util.SafeCloseable
|
||||
@@ -59,8 +61,6 @@ import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.encodeToString
|
||||
import app.lawnchair.preferences.PreferenceManager as LawnchairPreferenceManager
|
||||
import com.android.launcher3.graphics.IconShape as L3IconShape
|
||||
|
||||
class PreferenceManager2 private constructor(private val context: Context) : PreferenceManager, SafeCloseable {
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import app.lawnchair.preferences.PreferenceManager
|
||||
import app.lawnchair.util.MainThreadInitializedObject
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.topjohnwu.superuser.ipc.RootService
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -16,8 +18,6 @@ import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.plus
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
class RootHelperManager(private val context: Context) {
|
||||
private val scope = MainScope() + CoroutineName("RootHelperManager")
|
||||
|
||||
@@ -55,7 +55,7 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
|
||||
}
|
||||
|
||||
override fun doSearch(query: String, callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) {
|
||||
appState.model.enqueueModelUpdateTask(object: LauncherModel.ModelUpdateTask {
|
||||
appState.model.enqueueModelUpdateTask(object : LauncherModel.ModelUpdateTask {
|
||||
override fun execute(app: ModelTaskController, dataModel: BgDataModel, apps: AllAppsList) {
|
||||
coroutineScope.launch(Dispatchers.Main) {
|
||||
val results = getResult(apps.data, query)
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.android.launcher3.LauncherModel
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter
|
||||
import com.android.launcher3.model.AllAppsList
|
||||
import com.android.launcher3.model.CacheDataUpdatedTask
|
||||
import com.android.launcher3.model.BgDataModel
|
||||
import com.android.launcher3.model.ModelTaskController
|
||||
import com.android.launcher3.model.data.AppInfo
|
||||
|
||||
@@ -8,9 +8,9 @@ import com.android.launcher3.model.data.AppInfo
|
||||
import com.android.launcher3.popup.PopupPopulator
|
||||
import com.android.launcher3.search.StringMatcherUtility
|
||||
import com.android.launcher3.shortcuts.ShortcutRequest
|
||||
import java.util.Locale
|
||||
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||
import me.xdrop.fuzzywuzzy.algorithms.WeightedRatio
|
||||
import java.util.Locale
|
||||
|
||||
object SearchUtils {
|
||||
fun normalSearch(apps: List<AppInfo>, query: String, maxResultsCount: Int, hiddenApps: Set<String>, hiddenAppsInSearch: String): List<AppInfo> {
|
||||
|
||||
@@ -16,9 +16,9 @@ import app.lawnchair.smartspace.model.SmartspaceTarget
|
||||
import app.lawnchair.smartspace.provider.SmartspaceProvider
|
||||
import app.lawnchair.util.repeatOnAttached
|
||||
import com.android.launcher3.R
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class BcSmartspaceView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
||||
@@ -23,13 +23,13 @@ import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_TASK
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.icons.BitmapInfo
|
||||
import com.android.launcher3.model.data.AppInfo as ModelAppInfo
|
||||
import com.android.launcher3.model.data.ItemInfo
|
||||
import com.android.launcher3.popup.SystemShortcut
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
import com.android.launcher3.util.PackageManagerHelper
|
||||
import com.patrykmichalik.opto.core.firstBlocking
|
||||
import java.net.URISyntaxException
|
||||
import com.android.launcher3.model.data.AppInfo as ModelAppInfo
|
||||
|
||||
class LawnchairShortcut {
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ import com.android.launcher3.util.Themes
|
||||
import com.android.systemui.shared.system.QuickStepContract
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import com.patrykmichalik.opto.core.firstBlocking
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.json.JSONArray
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.system.exitProcess
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.json.JSONArray
|
||||
|
||||
fun <T, A> ensureOnMainThread(creator: (A) -> T): (A) -> T = { it ->
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
|
||||
@@ -102,7 +102,7 @@ class LauncherPreviewView(
|
||||
emptyList(),
|
||||
"",
|
||||
null,
|
||||
null
|
||||
null,
|
||||
)
|
||||
MAIN_EXECUTOR.execute {
|
||||
renderView(previewContext, mBgDataModel, mWidgetProvidersMap)
|
||||
|
||||
@@ -29,9 +29,8 @@ import androidx.dynamicanimation.animation.DynamicAnimation;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.taskbar.TaskbarActivityContext;
|
||||
import com.android.launcher3.taskbar.TaskbarDragLayer;
|
||||
|
||||
import app.lawnchair.bubbles.DismissView;
|
||||
import app.lawnchair.common.MagnetizedObject;
|
||||
import com.android.wm.shell.common.bubbles.DismissView;
|
||||
import com.android.wm.shell.common.magnetictarget.MagnetizedObject;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,9 +30,9 @@ import androidx.dynamicanimation.animation.FloatPropertyCompat;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.wm.shell.common.bubbles.DismissCircleView;
|
||||
import com.android.wm.shell.common.bubbles.DismissView;
|
||||
|
||||
import app.lawnchair.animation.PhysicsAnimator;
|
||||
import app.lawnchair.bubbles.DismissView;
|
||||
|
||||
/**
|
||||
* The animator performs the bubble animations while dragging and coordinates
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package app.lawnchair.bubbles
|
||||
package com.android.wm.shell.common.bubbles
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
@@ -35,9 +35,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation
|
||||
import androidx.dynamicanimation.animation.SpringForce.DAMPING_RATIO_LOW_BOUNCY
|
||||
import androidx.dynamicanimation.animation.SpringForce.STIFFNESS_LOW
|
||||
import app.lawnchair.animation.PhysicsAnimator
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.wm.shell.common.bubbles.DismissCircleView
|
||||
import com.android.wm.shell.shared.animation.PhysicsAnimator
|
||||
|
||||
/**
|
||||
* View that handles interactions between DismissCircleView and BubbleStackView.
|
||||
@@ -51,27 +49,27 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
* @see [setup] method
|
||||
*/
|
||||
data class Config(
|
||||
/** The resource id to set on the dismiss target circle view */
|
||||
val dismissViewResId: Int,
|
||||
/** dimen resource id of the dismiss target circle view size */
|
||||
@DimenRes val targetSizeResId: Int,
|
||||
/** dimen resource id of the icon size in the dismiss target */
|
||||
@DimenRes val iconSizeResId: Int,
|
||||
/** dimen resource id of the bottom margin for the dismiss target */
|
||||
@DimenRes var bottomMarginResId: Int,
|
||||
/** dimen resource id of the height for dismiss area gradient */
|
||||
@DimenRes val floatingGradientHeightResId: Int,
|
||||
/** color resource id of the dismiss area gradient color */
|
||||
@ColorRes val floatingGradientColorResId: Int,
|
||||
/** drawable resource id of the dismiss target background */
|
||||
@DrawableRes val backgroundResId: Int,
|
||||
/** drawable resource id of the icon for the dismiss target */
|
||||
@DrawableRes val iconResId: Int
|
||||
/** The resource id to set on the dismiss target circle view */
|
||||
val dismissViewResId: Int,
|
||||
/** dimen resource id of the dismiss target circle view size */
|
||||
@DimenRes val targetSizeResId: Int,
|
||||
/** dimen resource id of the icon size in the dismiss target */
|
||||
@DimenRes val iconSizeResId: Int,
|
||||
/** dimen resource id of the bottom margin for the dismiss target */
|
||||
@DimenRes var bottomMarginResId: Int,
|
||||
/** dimen resource id of the height for dismiss area gradient */
|
||||
@DimenRes val floatingGradientHeightResId: Int,
|
||||
/** color resource id of the dismiss area gradient color */
|
||||
@ColorRes val floatingGradientColorResId: Int,
|
||||
/** drawable resource id of the dismiss target background */
|
||||
@DrawableRes val backgroundResId: Int,
|
||||
/** drawable resource id of the icon for the dismiss target */
|
||||
@DrawableRes val iconResId: Int
|
||||
)
|
||||
|
||||
companion object {
|
||||
private const val SHOULD_SETUP =
|
||||
"The view isn't ready. Should be called after `setup`"
|
||||
"The view isn't ready. Should be called after `setup`"
|
||||
private val TAG = DismissView::class.simpleName
|
||||
}
|
||||
|
||||
@@ -83,18 +81,18 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
private val spring = PhysicsAnimator.SpringConfig(STIFFNESS_LOW, DAMPING_RATIO_LOW_BOUNCY)
|
||||
private val DISMISS_SCRIM_FADE_MS = 200L
|
||||
private var wm: WindowManager =
|
||||
context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
private var gradientDrawable: GradientDrawable? = null
|
||||
|
||||
private val GRADIENT_ALPHA: IntProperty<GradientDrawable> =
|
||||
object : IntProperty<GradientDrawable>("alpha") {
|
||||
override fun setValue(d: GradientDrawable, percent: Int) {
|
||||
d.alpha = percent
|
||||
}
|
||||
override fun get(d: GradientDrawable): Int {
|
||||
return d.alpha
|
||||
}
|
||||
object : IntProperty<GradientDrawable>("alpha") {
|
||||
override fun setValue(d: GradientDrawable, percent: Int) {
|
||||
d.alpha = percent
|
||||
}
|
||||
override fun get(d: GradientDrawable): Int {
|
||||
return d.alpha
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
setClipToPadding(false)
|
||||
@@ -115,9 +113,9 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
|
||||
// Setup layout
|
||||
layoutParams = LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
resources.getDimensionPixelSize(config.floatingGradientHeightResId),
|
||||
Gravity.BOTTOM)
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
resources.getDimensionPixelSize(config.floatingGradientHeightResId),
|
||||
Gravity.BOTTOM)
|
||||
updatePadding()
|
||||
|
||||
// Setup gradient
|
||||
@@ -129,10 +127,10 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
circle.setup(config.backgroundResId, config.iconResId, config.iconSizeResId)
|
||||
val targetSize: Int = resources.getDimensionPixelSize(config.targetSizeResId)
|
||||
circle.layoutParams = LayoutParams(targetSize, targetSize,
|
||||
Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
|
||||
Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
|
||||
// Initial position with circle offscreen so it's animated up
|
||||
circle.translationY = resources.getDimensionPixelSize(config.floatingGradientHeightResId)
|
||||
.toFloat()
|
||||
.toFloat()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +142,7 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
isShowing = true
|
||||
setVisibility(View.VISIBLE)
|
||||
val alphaAnim = ObjectAnimator.ofInt(gradientDrawable, GRADIENT_ALPHA,
|
||||
gradientDrawable.alpha, 255)
|
||||
gradientDrawable.alpha, 255)
|
||||
alphaAnim.setDuration(DISMISS_SCRIM_FADE_MS)
|
||||
alphaAnim.start()
|
||||
|
||||
@@ -163,7 +161,7 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
val gradientDrawable = checkExists(gradientDrawable) ?: return
|
||||
isShowing = false
|
||||
val alphaAnim = ObjectAnimator.ofInt(gradientDrawable, GRADIENT_ALPHA,
|
||||
gradientDrawable.alpha, 0)
|
||||
gradientDrawable.alpha, 0)
|
||||
alphaAnim.setDuration(DISMISS_SCRIM_FADE_MS)
|
||||
alphaAnim.start()
|
||||
animator
|
||||
@@ -198,12 +196,12 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
val gradientColor = ContextCompat.getColor(context, color)
|
||||
val alpha = 0.7f * 255
|
||||
val gradientColorWithAlpha = Color.argb(alpha.toInt(),
|
||||
Color.red(gradientColor),
|
||||
Color.green(gradientColor),
|
||||
Color.blue(gradientColor))
|
||||
Color.red(gradientColor),
|
||||
Color.green(gradientColor),
|
||||
Color.blue(gradientColor))
|
||||
val gd = GradientDrawable(
|
||||
GradientDrawable.Orientation.BOTTOM_TOP,
|
||||
intArrayOf(gradientColorWithAlpha, Color.TRANSPARENT))
|
||||
GradientDrawable.Orientation.BOTTOM_TOP,
|
||||
intArrayOf(gradientColorWithAlpha, Color.TRANSPARENT))
|
||||
gd.setDither(true)
|
||||
gd.setAlpha(0)
|
||||
return gd
|
||||
@@ -213,7 +211,7 @@ class DismissView(context: Context) : FrameLayout(context) {
|
||||
val config = checkExists(config) ?: return
|
||||
val insets: WindowInsets = wm.getCurrentWindowMetrics().getWindowInsets()
|
||||
val navInset = insets.getInsetsIgnoringVisibility(
|
||||
WindowInsets.Type.navigationBars())
|
||||
WindowInsets.Type.navigationBars())
|
||||
setPadding(0, 0, 0, navInset.bottom +
|
||||
resources.getDimensionPixelSize(config.bottomMarginResId))
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
@@ -14,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package app.lawnchair.common
|
||||
package com.android.wm.shell.common.magnetictarget
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
@@ -150,7 +149,7 @@ abstract class MagnetizedObject<T : Any>(
|
||||
private val velocityTracker: VelocityTracker = VelocityTracker.obtain()
|
||||
private val vibrator: Vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
private val vibrationAttributes: VibrationAttributes = VibrationAttributes.createForUsage(
|
||||
VibrationAttributes.USAGE_TOUCH)
|
||||
VibrationAttributes.USAGE_TOUCH)
|
||||
|
||||
private var touchDown = PointF()
|
||||
private var touchSlop = 0
|
||||
@@ -191,7 +190,7 @@ abstract class MagnetizedObject<T : Any>(
|
||||
* was flung, and a callback you must call after your animation completes.
|
||||
*/
|
||||
var animateStuckToTarget: (MagneticTarget, Float, Float, Boolean, (() -> Unit)?) -> Unit =
|
||||
::animateStuckToTargetInternal
|
||||
::animateStuckToTargetInternal
|
||||
|
||||
/**
|
||||
* Sets whether forcefully flinging the object vertically towards a target causes it to be
|
||||
@@ -264,7 +263,7 @@ abstract class MagnetizedObject<T : Any>(
|
||||
|
||||
/** Default spring configuration to use for animating the object into a target. */
|
||||
var springConfig = PhysicsAnimator.SpringConfig(
|
||||
SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_NO_BOUNCY)
|
||||
SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_NO_BOUNCY)
|
||||
|
||||
/**
|
||||
* Spring configuration to use to spring the object into a target specifically when it's flung
|
||||
@@ -357,23 +356,23 @@ abstract class MagnetizedObject<T : Any>(
|
||||
|
||||
val targetObjectIsInMagneticFieldOf = associatedTargets.firstOrNull { target ->
|
||||
val distanceFromTargetCenter = hypot(
|
||||
ev.rawX - target.centerOnDisplayX(),
|
||||
ev.rawY - target.centerOnDisplayY())
|
||||
ev.rawX - target.centerOnDisplayX(),
|
||||
ev.rawY - target.centerOnDisplayY())
|
||||
distanceFromTargetCenter < target.magneticFieldRadiusPx
|
||||
}
|
||||
|
||||
// If we aren't currently stuck to a target, and we're in the magnetic field of a target,
|
||||
// we're newly stuck.
|
||||
val objectNewlyStuckToTarget =
|
||||
!objectStuckToTarget && targetObjectIsInMagneticFieldOf != null
|
||||
!objectStuckToTarget && targetObjectIsInMagneticFieldOf != null
|
||||
|
||||
// If we are currently stuck to a target, we're in the magnetic field of a target, and that
|
||||
// target isn't the one we're currently stuck to, then touch events have moved into a
|
||||
// adjacent target's magnetic field.
|
||||
val objectMovedIntoDifferentTarget =
|
||||
objectStuckToTarget &&
|
||||
targetObjectIsInMagneticFieldOf != null &&
|
||||
targetObjectIsStuckTo != targetObjectIsInMagneticFieldOf
|
||||
objectStuckToTarget &&
|
||||
targetObjectIsInMagneticFieldOf != null &&
|
||||
targetObjectIsStuckTo != targetObjectIsInMagneticFieldOf
|
||||
|
||||
if (objectNewlyStuckToTarget || objectMovedIntoDifferentTarget) {
|
||||
velocityTracker.computeCurrentVelocity(1000)
|
||||
@@ -402,9 +401,9 @@ abstract class MagnetizedObject<T : Any>(
|
||||
// move the object out of the target using its own movement logic.
|
||||
cancelAnimations()
|
||||
magnetListener.onUnstuckFromTarget(
|
||||
targetObjectIsStuckTo!!, this,
|
||||
velocityTracker.xVelocity, velocityTracker.yVelocity,
|
||||
wasFlungOut = false)
|
||||
targetObjectIsStuckTo!!, this,
|
||||
velocityTracker.xVelocity, velocityTracker.yVelocity,
|
||||
wasFlungOut = false)
|
||||
targetObjectIsStuckTo = null
|
||||
|
||||
vibrateIfEnabled(VibrationEffect.EFFECT_TICK)
|
||||
@@ -426,8 +425,8 @@ abstract class MagnetizedObject<T : Any>(
|
||||
// the upward direction, tell the listener so the object can be animated out of
|
||||
// the target.
|
||||
magnetListener.onUnstuckFromTarget(
|
||||
targetObjectIsStuckTo!!, this,
|
||||
velX, velY, wasFlungOut = true)
|
||||
targetObjectIsStuckTo!!, this,
|
||||
velX, velY, wasFlungOut = true)
|
||||
} else {
|
||||
// If the object is stuck and not flung away, it was released inside the target.
|
||||
magnetListener.onReleasedInTarget(targetObjectIsStuckTo!!, this)
|
||||
@@ -510,10 +509,10 @@ abstract class MagnetizedObject<T : Any>(
|
||||
|
||||
// Animate to the center of the target.
|
||||
animator
|
||||
.spring(xProperty, xProperty.getValue(underlyingObject) + xDiff, velX,
|
||||
springConfig)
|
||||
.spring(yProperty, yProperty.getValue(underlyingObject) + yDiff, velY,
|
||||
springConfig)
|
||||
.spring(xProperty, xProperty.getValue(underlyingObject) + xDiff, velX,
|
||||
springConfig)
|
||||
.spring(yProperty, yProperty.getValue(underlyingObject) + yDiff, velY,
|
||||
springConfig)
|
||||
|
||||
if (physicsAnimatorUpdateListener != null) {
|
||||
animator.addUpdateListener(physicsAnimatorUpdateListener!!)
|
||||
@@ -548,8 +547,8 @@ abstract class MagnetizedObject<T : Any>(
|
||||
// Whether velocity is sufficient, depending on whether we're flinging into a target at the
|
||||
// top or the bottom of the screen.
|
||||
val velocitySufficient =
|
||||
if (rawY < target.centerOnDisplayY()) velY > flingToTargetMinVelocity
|
||||
else velY < flingToTargetMinVelocity
|
||||
if (rawY < target.centerOnDisplayY()) velY > flingToTargetMinVelocity
|
||||
else velY < flingToTargetMinVelocity
|
||||
|
||||
if (!velocitySufficient) {
|
||||
return false
|
||||
@@ -589,7 +588,7 @@ abstract class MagnetizedObject<T : Any>(
|
||||
// Update the touch slop, since the configuration may have changed.
|
||||
if (associatedTargets.size > 0) {
|
||||
touchSlop =
|
||||
ViewConfiguration.get(associatedTargets[0].targetView.context).scaledTouchSlop
|
||||
ViewConfiguration.get(associatedTargets[0].targetView.context).scaledTouchSlop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,8 +631,8 @@ abstract class MagnetizedObject<T : Any>(
|
||||
// Add half of the target size to get the center, and subtract translation since the
|
||||
// target could be animating in while we're doing this calculation.
|
||||
centerOnScreen.set(
|
||||
tempLoc[0] + targetView.width / 2f - targetView.translationX,
|
||||
tempLoc[1] + targetView.height / 2f - targetView.translationY)
|
||||
tempLoc[0] + targetView.width / 2f - targetView.translationX,
|
||||
tempLoc[1] + targetView.height / 2f - targetView.translationY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,10 +681,10 @@ abstract class MagnetizedObject<T : Any>(
|
||||
@JvmStatic
|
||||
fun <T : View> magnetizeView(view: T): MagnetizedObject<T> {
|
||||
return object : MagnetizedObject<T>(
|
||||
view.context,
|
||||
view,
|
||||
DynamicAnimation.TRANSLATION_X,
|
||||
DynamicAnimation.TRANSLATION_Y) {
|
||||
view.context,
|
||||
view,
|
||||
DynamicAnimation.TRANSLATION_X,
|
||||
DynamicAnimation.TRANSLATION_Y) {
|
||||
override fun getWidth(underlyingObject: T): Float {
|
||||
return underlyingObject.width.toFloat()
|
||||
}
|
||||
Reference in New Issue
Block a user