Skip to content

Commit

Permalink
refactor: use Activity to make sure the refresh mode change is fast e…
Browse files Browse the repository at this point in the history
…nough.
  • Loading branch information
plateaukao committed May 28, 2022
1 parent e58a0b6 commit 4b75285
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 25 deletions.
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ android {
}

buildTypes {
releaseDebuggable {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
release {
minifyEnabled true
shrinkResources true
Expand All @@ -27,6 +32,9 @@ android {

dependencies {
implementation 'com.onyx.android.sdk:onyxsdk-device:1.2.6'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<activity
android:name=".RefreshModeActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -29,6 +33,7 @@
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>

<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
Expand All @@ -42,6 +47,7 @@
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>

<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,8 @@ package info.plateaukao.quickrotate

import android.content.Intent
import android.service.quicksettings.TileService
import com.onyx.android.sdk.api.device.epd.UpdateOption
import com.onyx.android.sdk.device.BaseDevice
import com.onyx.android.sdk.device.Device

open class BaseRefreshModeTileService : TileService() {
protected var device: BaseDevice? = null

override fun onStartListening() {
device = Device.currentDevice()
}

override fun onStopListening() {
device = null
}

@Suppress("DEPRECATION")
override fun onClick() {
super.onClick()
baseContext.sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
}
override fun onClick() = baseContext.sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package info.plateaukao.quickrotate

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.onyx.android.sdk.api.device.epd.UpdateOption
import com.onyx.android.sdk.device.Device

private val device = Device.currentDevice

class RefreshModeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleIntent()
finish()
}

private fun handleIntent() {
val updateOption = findUpdateOption(intent.getIntExtra(ARG_UPDATE_OPTION, UpdateOption.NORMAL.ordinal))
device.systemRefreshMode = updateOption
}

private fun findUpdateOption(value: Int): UpdateOption =
UpdateOption.values().firstOrNull { it.ordinal == value } ?: UpdateOption.NORMAL

companion object {
private const val ARG_UPDATE_OPTION = "update_option"

fun createIntent(context: Context, option: UpdateOption): Intent {
return Intent(context, RefreshModeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ARG_UPDATE_OPTION, option.ordinal)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.onyx.android.sdk.api.device.epd.UpdateOption
class RefreshModeFastQualityTileService : BaseRefreshModeTileService() {
override fun onClick() {
super.onClick()
device?.systemRefreshMode = UpdateOption.FAST_QUALITY
startActivity(RefreshModeActivity.createIntent(this, UpdateOption.FAST_QUALITY))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.onyx.android.sdk.api.device.epd.UpdateOption
class RefreshModeFastTileService : BaseRefreshModeTileService() {
override fun onClick() {
super.onClick()
device?.systemRefreshMode = UpdateOption.FAST
startActivity(RefreshModeActivity.createIntent(this, UpdateOption.FAST))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.onyx.android.sdk.api.device.epd.UpdateOption
class RefreshModeNormalTileService : BaseRefreshModeTileService() {
override fun onClick() {
super.onClick()
device?.systemRefreshMode = UpdateOption.NORMAL
startActivity(RefreshModeActivity.createIntent(this, UpdateOption.NORMAL))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.onyx.android.sdk.api.device.epd.UpdateOption
class RefreshModeTileService : BaseRefreshModeTileService() {
override fun onClick() {
super.onClick()
device?.systemRefreshMode =
if (EpdController.isInFastMode()) UpdateOption.NORMAL else UpdateOption.FAST
val option = if (EpdController.isInFastMode()) UpdateOption.NORMAL else UpdateOption.FAST
startActivity(RefreshModeActivity.createIntent(this, option))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.onyx.android.sdk.api.device.epd.UpdateOption
class RefreshModeXTileService : BaseRefreshModeTileService() {
override fun onClick() {
super.onClick()
device?.systemRefreshMode = UpdateOption.FAST_X
startActivity(RefreshModeActivity.createIntent(this, UpdateOption.FAST_X))
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_refresh_mode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RefreshModeActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
Expand Down

0 comments on commit 4b75285

Please sign in to comment.