Skip to content

Commit

Permalink
Update detekt config
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Jan 21, 2024
1 parent dd3500d commit e894f68
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 92 deletions.
2 changes: 1 addition & 1 deletion app/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ comments:
complexity:
active: true
CognitiveComplexMethod:
active: false
active: true
threshold: 15
ComplexCondition:
active: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import android.content.pm.ActivityInfo
import android.media.AudioManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import androidx.preference.PreferenceManager
import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.helpers.Global
import io.github.domi04151309.alwayson.helpers.Root
import io.github.domi04151309.alwayson.receivers.AdminReceiver
import java.lang.Exception

@SuppressLint("Registered")
open class OffActivity : Activity() {
Expand Down Expand Up @@ -58,13 +55,8 @@ open class OffActivity : Activity() {

override fun onPause() {
super.onPause()
@Suppress("TooGenericExceptionCaught")
try {
(getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
.moveTaskToFront(taskId, 0)
} catch (exception: Exception) {
Log.w(Global.LOG_TAG, exception.toString())
}
(getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
.moveTaskToFront(taskId, 0)
}

protected fun turnOnScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.actions.OffActivity
import io.github.domi04151309.alwayson.custom.DoubleTapDetector
import io.github.domi04151309.alwayson.custom.LongPressDetector
import io.github.domi04151309.alwayson.helpers.AnimationHelper
import io.github.domi04151309.alwayson.helpers.Global
import io.github.domi04151309.alwayson.helpers.P
import io.github.domi04151309.alwayson.helpers.Root
Expand All @@ -47,9 +46,6 @@ class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListen
@JvmField
internal var servicesRunning: Boolean = false

@JvmField
internal var screenSize: Float = 0F

private var offsetX: Float = 0f
internal lateinit var viewHolder: AlwaysOnViewHolder
internal lateinit var prefs: P
Expand Down Expand Up @@ -361,66 +357,7 @@ class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListen
}

// Animation
val animationHelper = AnimationHelper(offsetX)
val animationDelay =
prefs.get(
"ao_animation_delay",
2,
) * MILLISECONDS_PER_MINUTE + ANIMATION_DURATION + MILLISECONDS_PER_SECOND
animationThread =
object : Thread() {
override fun run() {
try {
while (viewHolder.customView.height == 0) sleep(TINY_DELAY)
screenSize = calculateScreenSize()
runOnUiThread {
viewHolder.customView.translationY = screenSize / FRACTIONAL_VIEW_POSITION
}
while (!isInterrupted) {
sleep(animationDelay)
runOnUiThread {
animationHelper.animate(
viewHolder.customView,
screenSize / 2,
ANIMATION_DURATION,
)
if (prefs.get(
P.SHOW_FINGERPRINT_ICON,
P.SHOW_FINGERPRINT_ICON_DEFAULT,
)
) {
animationHelper.animate(
viewHolder.fingerprintIcn,
FINGERPRINT_ICON_BURN_IN_OFFSET,
ANIMATION_DURATION,
)
}
}
sleep(animationDelay)
runOnUiThread {
animationHelper.animate(
viewHolder.customView,
screenSize / FRACTIONAL_VIEW_POSITION,
ANIMATION_DURATION,
)
if (prefs.get(
P.SHOW_FINGERPRINT_ICON,
P.SHOW_FINGERPRINT_ICON_DEFAULT,
)
) {
animationHelper.animate(
viewHolder.fingerprintIcn,
0f,
ANIMATION_DURATION,
)
}
}
}
} catch (exception: InterruptedException) {
Log.w(Global.LOG_TAG, exception.toString())
}
}
}
animationThread = AlwaysOnAnimationThread(this, viewHolder, offsetX)
animationThread.start()

// DoubleTap
Expand All @@ -437,7 +374,7 @@ class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListen

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
screenSize = calculateScreenSize()
(animationThread as? AlwaysOnAnimationThread)?.updateScreenSize()
}

@Suppress("LongMethod")
Expand Down Expand Up @@ -582,24 +519,11 @@ class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListen
}
}

internal fun calculateScreenSize(): Float {
val size = Point()
(getSystemService(Context.DISPLAY_SERVICE) as DisplayManager)
.getDisplay(Display.DEFAULT_DISPLAY)
.getSize(size)
return (size.y - viewHolder.customView.height).toFloat()
}

companion object {
private const val TINY_DELAY: Long = 10
private const val SMALL_DELAY: Long = 300
private const val MILLISECONDS_PER_SECOND: Long = 1_000
private const val MILLISECONDS_PER_MINUTE: Long = 60_000
private const val ANIMATION_DURATION: Int = 10_000
private const val SENSOR_DELAY_SLOW: Int = 1_000_000
private const val MINIMUM_ANIMATION_DURATION: Int = 100
private const val FRACTIONAL_VIEW_POSITION: Int = 4
private const val FINGERPRINT_ICON_BURN_IN_OFFSET: Float = 64f
private const val HALF: Float = 0.5f
private var instance: AlwaysOn? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.github.domi04151309.alwayson.actions.alwayson

import android.app.Activity
import android.content.Context
import android.graphics.Point
import android.hardware.display.DisplayManager
import android.util.Log
import android.view.Display
import io.github.domi04151309.alwayson.helpers.AnimationHelper
import io.github.domi04151309.alwayson.helpers.Global
import io.github.domi04151309.alwayson.helpers.P

class AlwaysOnAnimationThread(
private val activity: Activity,
private val viewHolder: AlwaysOnViewHolder,
offsetX: Float,
) : Thread() {
private val animationHelper = AnimationHelper(offsetX)
private val animationDelay =
P.getPreferences(activity).getInt(
"ao_animation_delay",
2,
) * MILLISECONDS_PER_MINUTE + ANIMATION_DURATION + MILLISECONDS_PER_SECOND
private var screenSize: Float = 0F

fun updateScreenSize() {
val size = Point()
(activity.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager)
.getDisplay(Display.DEFAULT_DISPLAY)
.getSize(size)
screenSize = (size.y - viewHolder.customView.height).toFloat()
}

private fun preAnimation() {
while (viewHolder.customView.height == 0) sleep(TINY_DELAY)
updateScreenSize()
activity.runOnUiThread {
viewHolder.customView.translationY = screenSize / FRACTIONAL_VIEW_POSITION
}
}

private fun animationCycle() {
sleep(animationDelay)
activity.runOnUiThread {
animationHelper.animate(
viewHolder.customView,
screenSize / 2,
ANIMATION_DURATION,
)
if (P.getPreferences(activity).getBoolean(
P.SHOW_FINGERPRINT_ICON,
P.SHOW_FINGERPRINT_ICON_DEFAULT,
)
) {
animationHelper.animate(
viewHolder.fingerprintIcn,
FINGERPRINT_ICON_BURN_IN_OFFSET,
ANIMATION_DURATION,
)
}
}
sleep(animationDelay)
activity.runOnUiThread {
animationHelper.animate(
viewHolder.customView,
screenSize / FRACTIONAL_VIEW_POSITION,
ANIMATION_DURATION,
)
if (P.getPreferences(activity).getBoolean(
P.SHOW_FINGERPRINT_ICON,
P.SHOW_FINGERPRINT_ICON_DEFAULT,
)
) {
animationHelper.animate(
viewHolder.fingerprintIcn,
0f,
ANIMATION_DURATION,
)
}
}
}

override fun run() {
try {
preAnimation()
while (!isInterrupted) {
animationCycle()
}
} catch (exception: InterruptedException) {
Log.w(Global.LOG_TAG, exception.toString())
}
}

companion object {
private const val TINY_DELAY: Long = 10
private const val MILLISECONDS_PER_SECOND: Long = 1_000
private const val MILLISECONDS_PER_MINUTE: Long = 60_000
private const val ANIMATION_DURATION: Int = 10_000
private const val FRACTIONAL_VIEW_POSITION: Int = 4
private const val FINGERPRINT_ICON_BURN_IN_OFFSET: Float = 64f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class AlwaysOnCustomView : View {
/*
* On measure
*/
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod", "CognitiveComplexMethod")
private fun measureHeight(): Int {
utils.viewHeight = 0f
utils.viewHeight += paddingTop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class NotificationService : NotificationListenerService() {
if (sentRecently) return

sentRecently = true
@Suppress("TooGenericExceptionCaught")
try {
val apps = ArrayList<String>(detailed.size)
detailed = activeNotifications
Expand All @@ -81,7 +80,7 @@ class NotificationService : NotificationListenerService() {
)
}
}
} catch (exception: Exception) {
} catch (exception: SecurityException) {
Log.e(Global.LOG_TAG, exception.toString())
count = 0
icons = arrayListOf()
Expand Down

0 comments on commit e894f68

Please sign in to comment.