-
Notifications
You must be signed in to change notification settings - Fork 82
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
Showing
4 changed files
with
107 additions
and
0 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
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
91 changes: 91 additions & 0 deletions
91
app/src/main/java/org/koreader/launcher/device/lights/TolinoNtxNoWarmthController.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,91 @@ | ||
package org.koreader.launcher.device.lights | ||
|
||
import android.app.Activity | ||
import android.provider.Settings | ||
import android.util.Log | ||
import org.koreader.launcher.device.Ioctl | ||
import org.koreader.launcher.device.LightsInterface | ||
|
||
/* Special controller for Tolino Page 2 | ||
* | ||
* Same as `./TolinoNtxController.kt` but without warmth support. | ||
*/ | ||
|
||
class TolinoNtxNoWarmthController : Ioctl(), LightsInterface { | ||
|
||
companion object { | ||
private const val TAG = "Lights" | ||
private const val BRIGHTNESS_MAX = 255 | ||
private const val MIN = 0 | ||
private const val NTX_IO_FILE = "/dev/ntx_io" | ||
} | ||
|
||
override fun getPlatform(): String { | ||
return "tolino" | ||
} | ||
|
||
override fun hasFallback(): Boolean { | ||
return false | ||
} | ||
|
||
override fun hasWarmth(): Boolean { | ||
return false | ||
} | ||
|
||
override fun needsPermission(): Boolean { | ||
return false | ||
} | ||
|
||
override fun enableFrontlightSwitch(activity: Activity): Int { | ||
return 1 | ||
} | ||
|
||
override fun getBrightness(activity: Activity): Int { | ||
return try { | ||
Settings.System.getInt(activity.applicationContext.contentResolver, | ||
"screen_brightness") | ||
} catch (e: Exception) { | ||
Log.w(TAG, e.toString()) | ||
0 | ||
} | ||
} | ||
|
||
override fun getWarmth(activity: Activity): Int { | ||
Log.w(TAG, "getWarmth: not implemented") | ||
return 0 | ||
} | ||
|
||
override fun setBrightness(activity: Activity, brightness: Int) { | ||
if (brightness < MIN || brightness > BRIGHTNESS_MAX) { | ||
Log.w(TAG, "brightness value of of range: $brightness") | ||
return | ||
} | ||
Log.v(TAG, "Setting brightness to $brightness") | ||
try { | ||
Settings.System.putInt(activity.applicationContext.contentResolver, | ||
"screen_brightness", brightness) | ||
} catch (e: Exception) { | ||
Log.w(TAG, "$e") | ||
} | ||
} | ||
|
||
override fun setWarmth(activity: Activity, warmth: Int) { | ||
Log.w(TAG, "ignoring setWarmth: not implemented") | ||
} | ||
|
||
override fun getMinWarmth(): Int { | ||
return 0 | ||
} | ||
|
||
override fun getMaxWarmth(): Int { | ||
return 0 | ||
} | ||
|
||
override fun getMinBrightness(): Int { | ||
return MIN | ||
} | ||
|
||
override fun getMaxBrightness(): Int { | ||
return BRIGHTNESS_MAX | ||
} | ||
} |