Merge pull request #41 from chrjsorg/feature/chrjsorg/quicksettings-tile

Quicksettings Tile
This commit is contained in:
Tibor Kaputa 2017-11-30 15:28:06 +01:00 committed by GitHub
commit c34b5e9954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View File

@ -28,9 +28,10 @@
android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@ -83,5 +84,15 @@
android:name="android.appwidget.provider"
android:resource="@xml/widget_info"/>
</receiver>
<service
android:name=".helpers.MyTileService"
android:label="@string/app_launcher_name"
android:icon="@drawable/img_widget_preview"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
</application>
</manifest>

View File

@ -0,0 +1,33 @@
package com.simplemobiletools.flashlight.helpers
import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.support.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.N)
class MyTileService : TileService() {
override fun onClick() {
MyCameraImpl.newInstance(this).toggleFlashlight()
updateTile()
}
override fun onTileRemoved() {
if (MyCameraImpl.isFlashlightOn)
MyCameraImpl.newInstance(this).toggleFlashlight()
}
override fun onStartListening() {
updateTile()
}
override fun onTileAdded() {
updateTile()
}
private fun updateTile() {
qsTile.state = if (MyCameraImpl.isFlashlightOn) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
qsTile.updateTile()
}
}