Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit c34b5e99 authored by Tibor Kaputa's avatar Tibor Kaputa Committed by GitHub
Browse files

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

Quicksettings Tile
parents b10f73a6 2d5c6d22
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
@@ -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>
+33 −0
Original line number Diff line number Diff line
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()
    }
}