[Sony Cross-Device General] wolfmannight:
Kotlin version of Illumination

Why Sony don't show how to use their cool apis...

If other apps not use some cool Sony's apis its useless to put hardware

Only Sony Music and Album app uses LED ILLUMINATION

putting HW only for two app is useless

Sony has really cool features in their HW.

Sony should show how to use their cool apis to get full outcome from Xperia.

There is lots of cool things inside Xperia. Just need to come out to their clients.

​

import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.AsyncTask

object IlluminationUtil {

private val RGB_LED_ON_TIME = 4000
private val MUSIC_BEAT_LED_ON_TIME = 600000

private val ILLUMINATION_SERVICE_COMPONENT = ComponentName("com.sonyericsson.illumination.service", "com.sonyericsson.illumination.service.IlluminationService")

class getIllumination(private val context: Context, private val rgb: Int, private val enableBeat: Boolean?) : AsyncTask<Long, Void, Any>() {

protected override fun doInBackground(vararg longs: Long?): Any? {
try {

if (rgb <= 0) {
if (enableBeat!!) {
startMusicBeatIllumination(context, rgb)
} else {
//stopMusicBeatIllumination(context)
//startRGBIllumination(context, rgb)
startMusicBeatIllumination(context, rgb)
}
}

} catch (e: Exception) {
e.printStackTrace()
}

return null
}
}

class stopIllumination(private val context: Context) : AsyncTask<Long, Void, Any>() {
override fun doInBackground(vararg p0: Long?) {
try {
stopMusicBeatIllumination(context)
} catch (e: Exception) {
e.printStackTrace()
}
}

}

@Throws(Exception::class)
fun startRGBIllumination(context: Context, rgb: Int) {
val intent = createIlluminationServiceIntent("com.sonyericsson.illumination.intent.action.START_LED")
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ID", "com.sonyericsson.illumination.intent.extra.value.BUTTON_RGB")
intent.putExtra("com.sonyericsson.illumination.intent.extra.PACKAGE_NAME", context.packageName)
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_COLOR", rgb)
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ON_TIME", RGB_LED_ON_TIME)
context.startService(intent)
}

@Throws(Exception::class)
private fun stopRGBIllumination(context: Context) {
val intent = createIlluminationServiceIntent("com.sonyericsson.illumination.intent.action.STOP_LED")
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ID", "com.sonyericsson.illumination.intent.extra.value.BUTTON_RGB")
intent.putExtra("com.sonyericsson.illumination.intent.extra.PACKAGE_NAME", context.packageName)
context.startService(intent)
}

@Throws(Exception::class)
fun startMusicBeatIllumination(context: Context, color: Int) {

startRGBIllumination(context, color)

val intent = createIlluminationServiceIntent("com.sonyericsson.illumination.intent.action.START_LED")
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ID", "com.sonyericsson.illumination.intent.extra.value.AUDIO")
intent.putExtra("com.sonyericsson.illumination.intent.extra.PACKAGE_NAME", context.packageName)
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_COLOR", color)
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ON_TIME", MUSIC_BEAT_LED_ON_TIME)
context.startService(intent)
}

@Throws(Exception::class)
fun stopMusicBeatIllumination(context: Context) {

stopRGBIllumination(context)

val intent = createIlluminationServiceIntent("com.sonyericsson.illumination.intent.action.STOP_LED")
intent.putExtra("com.sonyericsson.illumination.intent.extra.LED_ID", "com.sonyericsson.illumination.intent.extra.value.AUDIO")
intent.putExtra("com.sonyericsson.illumination.intent.extra.PACKAGE_NAME", context.packageName)
context.startService(intent)
}

@SuppressLint("WrongConstant")
private fun isIlluminationServiceAvailable(context: Context): Boolean {
val intent = createIlluminationServiceIntent("com.sonyericsson.illumination.intent.action.START_LED")
intent.putExtra("com.sonyericsson.illumination.intent.extra.PACKAGE_NAME", context.packageName)
return if (context.packageManager.resolveService(intent, 64) != null) {
true
} else false
}

private fun createIlluminationServiceIntent(intentAction: String): Intent {
val intent = Intent()
intent.component = ILLUMINATION_SERVICE_COMPONENT
intent.action = intentAction
return intent
}

}