Skip to content

Commit

Permalink
better and smoother apps view
Browse files Browse the repository at this point in the history
  • Loading branch information
MRfantastic3DGamer committed Sep 2, 2024
1 parent dc0ed05 commit 8c4c967
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.dhruv.angularapps"
minSdk = 29
targetSdk = 34
versionCode = 3
versionName = "3.0"
versionCode = 7
versionName = "7.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
71 changes: 64 additions & 7 deletions app/src/main/java/com/dhruv/angularapps/OverlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.dhruv.angularapps.settings_app.settings.sliderBottomPaddingKey
import com.dhruv.angularapps.settings_app.settings.sliderHeightKey
import com.dhruv.angularapps.settings_app.settings.sliderWidthKey
import com.dhruv.angularapps.settings_app.settings.touchOffsetKey
import com.dhruv.angularapps.views.AppsAreaView
import com.dhruv.angularapps.views.ItemValues
import com.dhruv.angularapps.views.PositionedLayoutView
import com.dhruv.angularapps.views.SliderView
Expand All @@ -63,6 +64,7 @@ class OverlayService : Service(), OnTouchListener{


private var slider: SliderView? = null
private var appsArea: AppsAreaView? = null
private var trigger: View? = null
private var triggerPrams: WindowManager.LayoutParams? = null

Expand Down Expand Up @@ -95,10 +97,14 @@ class OverlayService : Service(), OnTouchListener{
private var groupSelectionRadius = 70
private var groupBasePop = 30
private var groupSelectionPop = 70
private var appsAreaRadiusMax = 10f
private var appsPop = 60
private var appsPositioning = AppsIconsPositioning.IconCoordinatesGenerationScheme()
private var appsName = mapOf<String, String>()

private var bottomY = 2000f
private var topY = 0f
private val triggerAreaPadding = 90
private val perGroupNotchHeight:Int
get() = dpToPx((sliderHeight.toFloat() / groups.size).roundToInt())

Expand All @@ -109,6 +115,7 @@ class OverlayService : Service(), OnTouchListener{
// update groups
updateGroups()
updateSlider()
updateAppsArea()
handler.postDelayed(this, 8) // Roughly 60 FPS
}
}
Expand All @@ -120,6 +127,8 @@ class OverlayService : Service(), OnTouchListener{
* updated only while touch is in slider region
*/
private var triggerTouchYPos = 0f
private var clampedTriggerRelativeTouchYPos = 0f

private var sliderVisibility = 0f
private val sliderVisibilityAnimator = AnimatedFloat(0f, 300L){
sliderVisibility = it
Expand All @@ -135,6 +144,8 @@ class OverlayService : Service(), OnTouchListener{

appsManager.initialize(this)
appsManager.appsData.observeForever { appsName = it ?: emptyMap() }
bottomY = resources.displayMetrics.heightPixels - dpToPx(10).toFloat()
topY = dpToPxF(10)

if (Build.VERSION.SDK_INT >= 26) {
val CHANNEL_ID = "channel1"
Expand All @@ -160,6 +171,7 @@ class OverlayService : Service(), OnTouchListener{

triggerSetUp()
sliderSetUp()
appsAreaSetUp()
// debugSetUp()
groupsSetUp()
appsSetUp()
Expand Down Expand Up @@ -240,6 +252,23 @@ class OverlayService : Service(), OnTouchListener{
)
}

private fun appsAreaSetUp() {
appsArea = AppsAreaView(this).apply {
setOnTouchListener(overlayService)
z = 1000f
}
wm!!.addView(
appsArea,
WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
type,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT
)
)
}

private fun debugSetUp(){
// only for debugging
DebugText = TextView(this).apply {
Expand Down Expand Up @@ -329,6 +358,10 @@ class OverlayService : Service(), OnTouchListener{
visibility = VISIBLE
alpha = 0.3f
}
appsArea?.apply {
visibility = VISIBLE
alpha = 0.3f
}
sliderVisibilityAnimator.setTargetValue(1f)
groupsPositionedLayoutView?.apply {
visibility = VISIBLE
Expand Down Expand Up @@ -364,6 +397,7 @@ class OverlayService : Service(), OnTouchListener{
appsPositionedLayoutView?.apply { visibility = GONE }
sliderVisibilityAnimator.setTargetValue(0f)
slider?.apply { visibility = GONE }
appsArea?.apply { visibility = GONE }
labelText?.apply { visibility = GONE }
handler.removeCallbacks(updateRunnable)
launchAppIfPossible(touchOnSliderSide)
Expand All @@ -378,6 +412,8 @@ class OverlayService : Service(), OnTouchListener{
if (touchOnSliderSide) {
updateTrigger(Y)
triggerTouchYPos = Y
val triggerSelectionOverflow = dpToPxF(20)
clampedTriggerRelativeTouchYPos = clamp(triggerTouchYPos - triggerPrams!!.y, -triggerSelectionOverflow , dpToPxF(sliderHeight) + triggerSelectionOverflow)
}

if (touchOnSliderSide) {
Expand All @@ -386,7 +422,7 @@ class OverlayService : Service(), OnTouchListener{
val selectedGroupY = triggerPrams!!.y + ((groupSelection + 0.5f) * perGroupNotchHeight).roundToInt()
val selectedGroupOffset = Offset(
resources.displayMetrics.widthPixels - dpToPx(appsPop).toFloat(),
triggerTouchYPos
triggerPrams!!.y + clampedTriggerRelativeTouchYPos
)

if (groups.isNotEmpty() && groupSelection != -1){
Expand All @@ -401,20 +437,22 @@ class OverlayService : Service(), OnTouchListener{
sliderHeight = sliderHeight.toFloat(),
right = resources.displayMetrics.widthPixels - dpToPx(sliderWidthOnActive),
left = dpToPx(100),
Top = dpToPx(100).toFloat(),
Bot = resources.displayMetrics.heightPixels - dpToPx(100).toFloat(),
Top = dpToPxF(triggerAreaPadding),
Bot = bottomY - appSelectionRadius,
LabelHeight = 0f,
)
}
val touchOffset = Offset(X, Y)
val usedOffsets = usableData.offsets
appsAreaRadiusMax = (selectedGroupOffset - usedOffsets.last()).getDistance() + 60

val appSelectionResult = AppsIconsPositioning.getIconSelection(touchOffset, usedOffsets, 200f)
appSelection = appSelectionResult.selectedApp
updateApps(usedOffsets, appSelectionResult.selectionValues)
}

updateSlider()
updateAppsArea()
updateGroups()
updateLabel()

Expand All @@ -430,12 +468,14 @@ class OverlayService : Service(), OnTouchListener{
// region updation
private fun updateTrigger(touchY: Float) {
val yOffset = (touchY - initialTouchY).roundToInt()
var finalY = triggerPrams!!.y
if (initialY + yOffset < triggerPrams!!.y){
triggerPrams!!.y = initialY + yOffset
finalY = initialY + yOffset
}
else if (initialY + yOffset > triggerPrams!!.y + dpToPx(sliderHeight)){
triggerPrams!!.y = initialY + yOffset - dpToPx(sliderHeight)
finalY = initialY + yOffset - dpToPx(sliderHeight)
}
triggerPrams!!.y = clamp(finalY, topY.roundToInt() + dpToPx(triggerAreaPadding), (bottomY - dpToPxF(sliderHeight)).roundToInt() - dpToPx(triggerAreaPadding))
wm!!.updateViewLayout(trigger, triggerPrams)
}

Expand All @@ -444,7 +484,7 @@ class OverlayService : Service(), OnTouchListener{
val currentWidth = dpToPxF(sliderWidthOnActive) * sliderVisibility
updateVisuals(
Offset(width.toFloat() - currentWidth, triggerPrams!!.y.toFloat()),
selectionPos = triggerTouchYPos - triggerPrams!!.y,
selectionPos = clampedTriggerRelativeTouchYPos,
width = currentWidth,
height = dpToPxF(sliderHeight),
radius = 125f * sliderVisibility,
Expand All @@ -454,6 +494,23 @@ class OverlayService : Service(), OnTouchListener{
}
}

private fun updateAppsArea() {
appsArea?.apply {
val currentWidth = dpToPxF(sliderWidthOnActive) * sliderVisibility

updateVisuals(
Offset(width.toFloat() - currentWidth, triggerPrams!!.y.toFloat()),
selectionPos = clampedTriggerRelativeTouchYPos,
minRad = 140f * sliderVisibility,
maxRad = (appsAreaRadiusMax + appSelectionRadius) * sliderVisibility,
selectionPop = 60f * sliderVisibility,
vertexCount = 20,
bottomCutY = bottomY,
topCutY = topY
)
}
}

private fun updateGroups() {
groupsPositionedLayoutView?.apply {
updateValues(groups.size) { index ->
Expand All @@ -472,7 +529,7 @@ class OverlayService : Service(), OnTouchListener{
),
y = triggerPrams!!.y + lerp(
((index + 0.5f) * perGroupNotchHeight) - groupBaseRadius / 2,
triggerTouchYPos - triggerPrams!!.y,
clampedTriggerRelativeTouchYPos,
transitionValue
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class AppsIconsPositioning {
Bot: Float,
LabelHeight: Float,
): IconOffsetComputeResult {
// val top = if (sliderPosY > LabelHeight+50f) sliderPosY + 50f else Top
val bot = if (sliderPosY > LabelHeight+50f) Bot else sliderPosY + sliderHeight - 50f
if (allOffsets.isEmpty()) return IconOffsetComputeResult(0, allOffsets, emptyList())
val iconSizeOffset = Offset(2.5f, 2.5f)
Expand All @@ -139,14 +138,14 @@ class AppsIconsPositioning {
if (!(
(c.x > left)
&& (c.x < right)
// && (c.y > top)
&& (c.y > Top)
&& (c.y < bot)
)){
val skipStart: Int = j
while (!(
(c.x > left)
&& (c.x < right)
// && (c.y > top)
&& (c.y > Top)
&& (c.y < bot)
))
{
Expand Down
Loading

0 comments on commit 8c4c967

Please sign in to comment.