Add Service and show clock on second screen
This commit is contained in:
parent
41af400d40
commit
9fb0609156
@ -12,10 +12,14 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.CatFlipScreen"
|
||||
tools:targetApi="31">
|
||||
<service
|
||||
android:name=".FlipScreenService"
|
||||
android:enabled="true"
|
||||
android:exported="false"/>
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.CatFlipScreen">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -0,0 +1,41 @@
|
||||
package net.mezimmah.catflipscreen
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.MediaRouter
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
|
||||
class FlipScreenService : Service() {
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
TODO("Return the communication channel to the service.")
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
showPresentationScreen()
|
||||
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
private fun showPresentationScreen() {
|
||||
val selectedRoute =
|
||||
(this.getSystemService(Context.MEDIA_ROUTER_SERVICE) as MediaRouter).getSelectedRoute(1)
|
||||
val presentationDisplay = selectedRoute?.presentationDisplay
|
||||
val mPresentation =
|
||||
PresentationScreen(this, presentationDisplay)
|
||||
Log.i("StatusBar", "Showing presentation on display: $presentationDisplay")
|
||||
try {
|
||||
mPresentation.requestWindowFeature(1)
|
||||
mPresentation.show()
|
||||
Log.i("StatusBar", "Showing presentation.")
|
||||
} catch (e: Exception) {
|
||||
Log.w(
|
||||
"StatusBar",
|
||||
"Couldn't show presentation! Display was removed in the meantime.",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.mezimmah.catflipscreen
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
@ -26,7 +27,9 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
startService(Intent(this, FlipScreenService::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.mezimmah.catflipscreen
|
||||
|
||||
import android.app.Presentation
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.Display
|
||||
|
||||
class PresentationScreen(outerContext: Context?, display: Display?) :
|
||||
Presentation(outerContext, display) {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(R.layout.layout_screen)
|
||||
|
||||
}
|
||||
}
|
17
app/src/main/res/layout/layout_screen.xml
Normal file
17
app/src/main/res/layout/layout_screen.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@color/black"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="96dp">
|
||||
|
||||
<TextClock
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:format12Hour="hh:mm"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="28sp"
|
||||
android:textAlignment="center"
|
||||
android:text="@string/app_name"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user