-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f5ed51
commit abc3c22
Showing
11 changed files
with
290 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
app/src/main/java/info/plateaukao/quickrotate/FrontLightActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package info.plateaukao.quickrotate | ||
|
||
import android.app.Activity | ||
import android.app.AlertDialog | ||
import android.content.Context | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.SeekBar | ||
import androidx.annotation.RequiresApi | ||
import com.onyx.android.sdk.api.device.FrontLightController | ||
|
||
class FrontLightActivity : Activity() { | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
|
||
val dialog = AlertDialog.Builder(this) | ||
.setView(R.layout.front_light_adjust_layout) | ||
.show() | ||
dialog.window?.setLayout(300.dp(this), ViewGroup.LayoutParams.WRAP_CONTENT) | ||
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent); | ||
initViews(dialog) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun initViews(dialog: AlertDialog) { | ||
val seekbarTemperature = dialog.findViewById<SeekBar>(R.id.seekbar_light_temperature) | ||
val seekbarBrightness = dialog.findViewById<SeekBar>(R.id.seekbar_light_brightness) | ||
val toggleButton = dialog.findViewById<ImageView>(R.id.iv_frontlight) | ||
val isLightOn = FrontLightController.isColdLightOn(this) | ||
toggleButton.setImageResource(if (isLightOn) R.drawable.ic_light_on else R.drawable.ic_light_off) | ||
toggleButton.setOnClickListener { | ||
if (FrontLightController.isColdLightOn(this)) { | ||
enableFrontLight(false) | ||
toggleButton.setImageResource(R.drawable.ic_light_off) | ||
} else { | ||
enableFrontLight(true) | ||
toggleButton.setImageResource(R.drawable.ic_light_on) | ||
} | ||
} | ||
val warmButton = dialog.findViewById<ImageView>(R.id.iv_temperature) | ||
warmButton.setOnClickListener { seekbarTemperature.progress = 0 } | ||
|
||
seekbarBrightness.max = 500 | ||
seekbarBrightness.min = 0 | ||
seekbarBrightness.progress = FrontLightController.getColdLightConfigValue(this) + FrontLightController.getWarmLightConfigValue(this) | ||
|
||
var offSet = currentOffset | ||
seekbarTemperature.max = 100 | ||
seekbarTemperature.min = -100 | ||
seekbarTemperature.progress = offSet | ||
|
||
seekbarBrightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { | ||
FrontLightController.setColdLightDeviceValue(this@FrontLightActivity, progress / 2) | ||
FrontLightController.setWarmLightDeviceValue( | ||
this@FrontLightActivity, | ||
progress/2 + offSet | ||
) | ||
} | ||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar) {} | ||
|
||
override fun onStopTrackingTouch(seekBar: SeekBar) {} | ||
}) | ||
seekbarTemperature.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { | ||
val coldBrightness = | ||
FrontLightController.getColdLightConfigValue(this@FrontLightActivity) | ||
offSet = progress | ||
FrontLightController.setWarmLightDeviceValue( | ||
this@FrontLightActivity, | ||
coldBrightness + offSet | ||
) | ||
} | ||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar) {} | ||
|
||
override fun onStopTrackingTouch(seekBar: SeekBar) {} | ||
}) | ||
} | ||
|
||
private val currentOffset = FrontLightController.getWarmLightConfigValue(this) - | ||
FrontLightController.getColdLightConfigValue(this) | ||
|
||
private fun enableFrontLight(isEnabled: Boolean) { | ||
if (isEnabled) { | ||
FrontLightController.openColdLight() | ||
FrontLightController.openWarmLight() | ||
} else { | ||
FrontLightController.closeColdLight() | ||
FrontLightController.closeWarmLight() | ||
} | ||
} | ||
} | ||
|
||
fun Int.dp(context: Context): Int { | ||
val metrics = context.resources.displayMetrics | ||
return (this * (metrics.densityDpi / 160f)).toInt() | ||
} | ||
|
109 changes: 99 additions & 10 deletions
109
app/src/main/java/info/plateaukao/quickrotate/service/FrontLightTileService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,109 @@ | ||
package info.plateaukao.quickrotate.service | ||
|
||
import android.app.AlertDialog | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.service.quicksettings.TileService | ||
import java.util.* | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import android.widget.ImageView | ||
import android.widget.SeekBar | ||
import androidx.annotation.RequiresApi | ||
import com.onyx.android.sdk.api.device.FrontLightController | ||
import info.plateaukao.quickrotate.FrontLightActivity | ||
import info.plateaukao.quickrotate.R | ||
import info.plateaukao.quickrotate.dp | ||
|
||
class FrontLightTileService: TileService() { | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
override fun onClick() { | ||
// show an alert dialog with progress bar | ||
// when the progress bar is changed, send a broadcast to the service | ||
AlertDialog.Builder(this) | ||
.setTitle("Front Light") | ||
.setView(R.layout.front_light_dialog) | ||
.setPositiveButton("OK") { dialog, _ -> | ||
dialog.dismiss() | ||
val it = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) | ||
baseContext.sendBroadcast(it) | ||
|
||
startActivity( | ||
Intent(this, FrontLightActivity::class.java).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
} | ||
) | ||
// val dialog = AlertDialog.Builder(this) | ||
// .setView(R.layout.front_light_adjust_layout) | ||
// .create() | ||
// dialog.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) | ||
// dialog.show() | ||
// | ||
// dialog.window?.setLayout(300.dp(this), ViewGroup.LayoutParams.WRAP_CONTENT) | ||
// initViews(dialog) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun initViews(dialog: AlertDialog) { | ||
val seekbarTemperature = dialog.findViewById<SeekBar>(R.id.seekbar_light_temperature) | ||
val seekbarBrightness = dialog.findViewById<SeekBar>(R.id.seekbar_light_brightness) | ||
val toggleButton = dialog.findViewById<ImageView>(R.id.iv_frontlight) | ||
val isLightOn = FrontLightController.isColdLightOn(this) | ||
toggleButton.setImageResource(if (isLightOn) R.drawable.ic_light_on else R.drawable.ic_light_off) | ||
toggleButton.setOnClickListener { | ||
if (FrontLightController.isColdLightOn(this)) { | ||
enableFrontLight(false) | ||
toggleButton.setImageResource(R.drawable.ic_light_off) | ||
} else { | ||
enableFrontLight(true) | ||
toggleButton.setImageResource(R.drawable.ic_light_on) | ||
} | ||
} | ||
val warmButton = dialog.findViewById<ImageView>(R.id.iv_temperature) | ||
warmButton.setOnClickListener { seekbarTemperature.progress = 0 } | ||
|
||
seekbarBrightness.max = 500 | ||
seekbarBrightness.min = 0 | ||
seekbarBrightness.progress = FrontLightController.getColdLightConfigValue(this) + FrontLightController.getWarmLightConfigValue(this) | ||
|
||
var offSet = currentOffset | ||
seekbarTemperature.max = 100 | ||
seekbarTemperature.min = -100 | ||
seekbarTemperature.progress = offSet | ||
|
||
seekbarBrightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { | ||
FrontLightController.setColdLightDeviceValue(this@FrontLightTileService, progress / 2) | ||
FrontLightController.setWarmLightDeviceValue( | ||
this@FrontLightTileService, | ||
progress/2 + offSet | ||
) | ||
} | ||
.show() | ||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar) {} | ||
|
||
override fun onStopTrackingTouch(seekBar: SeekBar) {} | ||
}) | ||
seekbarTemperature.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { | ||
val coldBrightness = | ||
FrontLightController.getColdLightConfigValue(this@FrontLightTileService) | ||
offSet = progress | ||
FrontLightController.setWarmLightDeviceValue( | ||
this@FrontLightTileService, | ||
coldBrightness + offSet | ||
) | ||
} | ||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar) {} | ||
|
||
override fun onStopTrackingTouch(seekBar: SeekBar) {} | ||
}) | ||
} | ||
|
||
private val currentOffset = FrontLightController.getWarmLightConfigValue(this) - | ||
FrontLightController.getColdLightConfigValue(this) | ||
|
||
private fun enableFrontLight(isEnabled: Boolean) { | ||
if (isEnabled) { | ||
FrontLightController.openColdLight() | ||
FrontLightController.openWarmLight() | ||
} else { | ||
FrontLightController.closeColdLight() | ||
FrontLightController.closeWarmLight() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M18,5l0,-3l-12,0l0,1.17l1.83,1.83z"/> | ||
<path android:fillColor="@android:color/white" android:pathData="M16,11l2,-3l0,-1l-8.17,0l6.17,6.17z"/> | ||
<path android:fillColor="@android:color/white" android:pathData="M2.81,2.81L1.39,4.22L8,10.83V22h8v-3.17l3.78,3.78l1.41,-1.41L2.81,2.81z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M6,14l3,3v5h6v-5l3,-3V9H6V14zM11,2h2v3h-2V2zM3.5,5.88l1.41,-1.41l2.12,2.12L5.62,8L3.5,5.88zM16.96,6.59l2.12,-2.12l1.41,1.41L18.38,8L16.96,6.59z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M12,12.9l-2.13,2.09C9.31,15.55 9,16.28 9,17.06C9,18.68 10.35,20 12,20s3,-1.32 3,-2.94c0,-0.78 -0.31,-1.52 -0.87,-2.07L12,12.9z"/> | ||
<path android:fillColor="@android:color/white" android:pathData="M16,6l-0.44,0.55C14.38,8.02 12,7.19 12,5.3V2c0,0 -8,4 -8,11c0,2.92 1.56,5.47 3.89,6.86C7.33,19.07 7,18.1 7,17.06c0,-1.32 0.52,-2.56 1.47,-3.5L12,10.1l3.53,3.47c0.95,0.93 1.47,2.17 1.47,3.5c0,1.02 -0.31,1.96 -0.85,2.75c1.89,-1.15 3.29,-3.06 3.71,-5.3C20.52,10.97 18.79,7.62 16,6z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/transparent" | ||
tools:context=".FrontLightActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_width="400dp" | ||
android:layout_height="150dp" | ||
android:orientation="vertical" | ||
> | ||
android:paddingHorizontal="10dp"> | ||
|
||
<SeekBar | ||
android:id="@+id/seekbar_light_brightness" | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:max="10" | ||
android:progress="3" /> | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@+id/iv_frontlight" | ||
android:src="@drawable/ic_light_on" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_gravity="center"/> | ||
<SeekBar | ||
android:id="@+id/seekbar_light_brightness" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_weight="1" | ||
android:layout_gravity="center" /> | ||
|
||
<SeekBar | ||
android:id="@+id/seekbar_light_temperature" | ||
|
||
</LinearLayout> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:max="10" | ||
android:progress="3" /> | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@+id/iv_temperature" | ||
android:src="@drawable/ic_warm" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_gravity="center"/> | ||
<SeekBar | ||
android:id="@+id/seekbar_light_temperature" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_weight="1" | ||
android:layout_gravity="center"/> | ||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters