Skip to content

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Jan 19, 2024
1 parent 2fedcb1 commit 91ba9bc
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import android.widget.TextView
import io.github.domi04151309.alwayson.R

class ChargingCircleActivity : OffActivity() {
companion object {
private const val ANIMATION_DELAY = 3000L
private const val ANIMATION_DURATION = 1000L
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_charging_circle)
Expand All @@ -41,4 +36,9 @@ class ChargingCircleActivity : OffActivity() {
}
}.start()
}

companion object {
private const val ANIMATION_DELAY = 3000L
private const val ANIMATION_DURATION = 1000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import android.widget.ImageView
import io.github.domi04151309.alwayson.R

class ChargingFlashActivity : OffActivity() {
companion object {
private const val ANIMATION_DELAY = 1500L
private const val ANIMATION_DURATION = 1000L
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_charging_flash)
Expand All @@ -28,4 +23,9 @@ class ChargingFlashActivity : OffActivity() {
}
}.start()
}

companion object {
private const val ANIMATION_DELAY = 1500L
private const val ANIMATION_DURATION = 1000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.helpers.IconHelper

class ChargingIOSActivity : OffActivity() {
companion object {
private const val TINY_DELAY = 10L
private const val ANIMATION_DELAY = 3000L
private const val ANIMATION_DURATION = 1000L
private const val FRACTIONAL_VIEW_POSITION = 8
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_charging_ios)
Expand Down Expand Up @@ -58,4 +51,11 @@ class ChargingIOSActivity : OffActivity() {
}
}.start()
}

companion object {
private const val TINY_DELAY = 10L
private const val ANIMATION_DELAY = 3000L
private const val ANIMATION_DURATION = 1000L
private const val FRACTIONAL_VIEW_POSITION = 8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import android.os.Looper
import android.view.WindowManager

class TurnOnScreenActivity : Activity() {
companion object {
private const val TINY_DELAY = 10L
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -35,4 +31,8 @@ class TurnOnScreenActivity : Activity() {
finish()
}, TINY_DELAY)
}

companion object {
private const val TINY_DELAY = 10L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,6 @@ import io.github.domi04151309.alwayson.services.NotificationService

@Suppress("TooManyFunctions")
class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListener {
companion object {
private const val TINY_DELAY: Long = 10
private const val SMALL_DELAY: Long = 300
private const val MILLISECONDS_PER_SECOND: Long = 1000
private const val MILLISECONDS_PER_MINUTE: Long = 60000
private const val ANIMATION_DURATION: Int = 10000
private const val SENSOR_DELAY_SLOW: Int = 1000000
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

fun finish() {
instance?.finish()
}
}

@JvmField
internal var servicesRunning: Boolean = false

Expand Down Expand Up @@ -607,4 +589,22 @@ class AlwaysOn : OffActivity(), NotificationService.OnNotificationsChangedListen
.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

fun finish() {
instance?.finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ import kotlin.math.abs

@Suppress("TooManyFunctions")
class AlwaysOnCustomView : View {
companion object {
private const val UPDATE_DELAY: Long = 60000
private const val NOTIFICATION_ROW_LENGTH: Int = 10
private const val NOTIFICATION_LIMIT: Int = 20
const val FLAG_CAPS_DATE: Int = 0
private const val FLAG_SAMSUNG_2: Int = 1
const val FLAG_BIG_DATE: Int = 1
const val FLAG_SAMSUNG_3: Int = 2
private const val FLAG_MULTILINE_CLOCK: Int = 3
const val FLAG_ANALOG_CLOCK: Int = 4
}

private lateinit var utils: Utils
private lateinit var timeFormat: SimpleDateFormat
private lateinit var dateFormat: SimpleDateFormat
Expand Down Expand Up @@ -105,7 +93,7 @@ class AlwaysOnCustomView : View {
init(context)
}

@Suppress("MagicNumber", "CyclomaticComplexMethod")
@Suppress("MagicNumber", "CyclomaticComplexMethod", "LongMethod")
private fun prepareTheme() {
when (utils.prefs.get(P.USER_THEME, P.USER_THEME_DEFAULT)) {
P.USER_THEME_ONEPLUS -> {
Expand All @@ -130,25 +118,39 @@ class AlwaysOnCustomView : View {
utils.mediumTextSize = utils.spToPx(25f)
utils.smallTextSize = utils.spToPx(18f)
when (utils.prefs.get(P.USER_THEME, P.USER_THEME_DEFAULT)) {
P.USER_THEME_GOOGLE -> utils.setFont(R.font.roboto_regular)
P.USER_THEME_GOOGLE -> {
utils.setFont(R.font.roboto_regular)
}
P.USER_THEME_SAMSUNG -> {
utils.setFont(R.font.roboto_light)
flags[FLAG_MULTILINE_CLOCK] = true
flags[FLAG_CAPS_DATE] = true
}

P.USER_THEME_SAMSUNG3 -> {
utils.setFont(R.font.roboto_regular)
flags[FLAG_SAMSUNG_3] = true
}

P.USER_THEME_80S -> utils.setFont(R.font.monoton_regular)
P.USER_THEME_FAST -> utils.setFont(R.font.faster_one_regular)
P.USER_THEME_FLOWER -> utils.setFont(R.font.akronim_regular)
P.USER_THEME_GAME -> utils.setFont(R.font.vt323_regular)
P.USER_THEME_HANDWRITTEN -> utils.setFont(R.font.patrick_hand_regular)
P.USER_THEME_JUNGLE -> utils.setFont(R.font.hanalei_regular)
P.USER_THEME_WESTERN -> utils.setFont(R.font.ewert_regular)
P.USER_THEME_80S -> {
utils.setFont(R.font.monoton_regular)
}
P.USER_THEME_FAST -> {
utils.setFont(R.font.faster_one_regular)
}
P.USER_THEME_FLOWER -> {
utils.setFont(R.font.akronim_regular)
}
P.USER_THEME_GAME -> {
utils.setFont(R.font.vt323_regular)
}
P.USER_THEME_HANDWRITTEN -> {
utils.setFont(R.font.patrick_hand_regular)
}
P.USER_THEME_JUNGLE -> {
utils.setFont(R.font.hanalei_regular)
}
P.USER_THEME_WESTERN -> {
utils.setFont(R.font.ewert_regular)
}
P.USER_THEME_ANALOG -> {
utils.setFont(R.font.roboto_regular)
flags[FLAG_MULTILINE_CLOCK] = true
Expand Down Expand Up @@ -313,7 +315,7 @@ class AlwaysOnCustomView : View {
return max(
max(
utils.viewHeight.toInt(),
(suggestedMinimumHeight + paddingTop + paddingBottom),
suggestedMinimumHeight + paddingTop + paddingBottom,
),
customBackground?.height ?: 0,
)
Expand Down Expand Up @@ -486,4 +488,16 @@ class AlwaysOnCustomView : View {
fun stopClockHandler() {
updateHandler.removeCallbacksAndMessages(null)
}

companion object {
private const val UPDATE_DELAY: Long = 60_000
private const val NOTIFICATION_ROW_LENGTH: Int = 10
private const val NOTIFICATION_LIMIT: Int = 20
const val FLAG_CAPS_DATE: Int = 0
private const val FLAG_SAMSUNG_2: Int = 1
const val FLAG_BIG_DATE: Int = 1
const val FLAG_SAMSUNG_3: Int = 2
private const val FLAG_MULTILINE_CLOCK: Int = 3
const val FLAG_ANALOG_CLOCK: Int = 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import io.github.domi04151309.alwayson.helpers.Global
class AlwaysOnOnActiveSessionsChangedListener(
private val view: AlwaysOnCustomView,
) : MediaSessionManager.OnActiveSessionsChangedListener {
companion object {
private const val MAX_STRING_LENGTH = 20
}

@JvmField
internal var controller: MediaController? = null

Expand Down Expand Up @@ -66,4 +62,8 @@ class AlwaysOnOnActiveSessionsChangedListener(
view.musicVisible = false
}
}

companion object {
private const val MAX_STRING_LENGTH = 20
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import android.hardware.SensorEventListener
class AlwaysOnSensorEventListener(
private val viewHolder: AlwaysOnViewHolder,
) : SensorEventListener {
companion object {
private const val ANIMATION_DURATION = 1000L
}

override fun onSensorChanged(event: SensorEvent) {
if (event.sensor.type == Sensor.TYPE_PROXIMITY) {
if (event.values[0] == event.sensor.maximumRange) {
Expand All @@ -27,4 +23,8 @@ class AlwaysOnSensorEventListener(
) {
// Do nothing.
}

companion object {
private const val ANIMATION_DURATION = 1000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.helpers.P

object Battery {
private const val PERCENT = "%"

internal fun drawIconAndPercentage(
canvas: Canvas,
utils: Utils,
Expand All @@ -19,7 +21,7 @@ object Battery {
batteryIcon,
(
utils.horizontalRelativePoint +
(utils.getPaint(utils.mediumTextSize).measureText("$batteryLevel%")).run {
utils.getPaint(utils.mediumTextSize).measureText(batteryLevel.toString() + PERCENT).run {
if (utils.paint.textAlign == Paint.Align.LEFT) {
this
} else {
Expand All @@ -41,7 +43,7 @@ object Battery {
)
utils.drawRelativeText(
canvas,
"$batteryLevel%",
batteryLevel.toString() + PERCENT,
utils.padding16,
utils.padding16,
utils.getPaint(
Expand Down Expand Up @@ -84,7 +86,7 @@ object Battery {
) {
utils.drawRelativeText(
canvas,
"$batteryLevel%",
batteryLevel.toString() + PERCENT,
utils.padding16,
utils.padding16,
utils.getPaint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object Clock {
val calendar = Calendar.getInstance()
utils.drawHand(
canvas,
(calendar[Calendar.HOUR_OF_DAY] % HOURS_ON_ANALOG_CLOCK) *
calendar[Calendar.HOUR_OF_DAY] % HOURS_ON_ANALOG_CLOCK *
MINUTES_PER_HOUR_ANGLE + calendar[Calendar.MINUTE],
true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ class Utils(
@JvmField
internal val context: Context,
) {
companion object {
private const val PADDING_2: Float = 2f
private const val PADDING_16: Float = 16f
private const val DRAWABLE_SIZE: Float = 24f
private const val HOUR_HAND_LENGTH: Float = .5f
private const val MINUTE_HAND_LENGTH: Float = .9f
private const val MINUTE_ANGLE_SCALE: Int = 30
}

@JvmField
internal var padding2 = 0

Expand Down Expand Up @@ -177,4 +168,13 @@ class Utils(
paint,
)
}

companion object {
private const val PADDING_2: Float = 2f
private const val PADDING_16: Float = 16f
private const val DRAWABLE_SIZE: Float = 24f
private const val HOUR_HAND_LENGTH: Float = .5f
private const val MINUTE_HAND_LENGTH: Float = .9f
private const val MINUTE_ANGLE_SCALE: Int = 30
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import io.github.domi04151309.alwayson.BuildConfig
import io.github.domi04151309.alwayson.R

class AboutActivity : BaseActivity() {
companion object {
private const val REPOSITORY: String = "Domi04151309/AlwaysOn"
private const val BRANCH: String = "master"
private const val REPOSITORY_URL: String = "https://github.com/$REPOSITORY"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand Down Expand Up @@ -113,4 +107,10 @@ class AboutActivity : BaseActivity() {
}
}
}

companion object {
private const val REPOSITORY: String = "Domi04151309/AlwaysOn"
private const val BRANCH: String = "master"
private const val REPOSITORY_URL: String = "https://github.com/$REPOSITORY"
}
}
Loading

0 comments on commit 91ba9bc

Please # to comment.