From 8dd627833720c785395aa3e252501e76f6b3e23d Mon Sep 17 00:00:00 2001 From: Joker Date: Fri, 28 Jul 2017 21:18:19 +0800 Subject: [PATCH] add QuickTile support (#29) --- app/src/main/AndroidManifest.xml | 9 ++++ .../daedalus/service/DaedalusTileService.java | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 app/src/main/java/org/itxtech/daedalus/service/DaedalusTileService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 08e374d..b3021ef 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,15 @@ + + + + + diff --git a/app/src/main/java/org/itxtech/daedalus/service/DaedalusTileService.java b/app/src/main/java/org/itxtech/daedalus/service/DaedalusTileService.java new file mode 100644 index 0000000..b1e90a3 --- /dev/null +++ b/app/src/main/java/org/itxtech/daedalus/service/DaedalusTileService.java @@ -0,0 +1,48 @@ +package org.itxtech.daedalus.service; + +import android.content.Intent; +import android.os.Build; +import android.service.quicksettings.Tile; +import android.service.quicksettings.TileService; +import android.support.annotation.RequiresApi; + +import org.itxtech.daedalus.Daedalus; +import org.itxtech.daedalus.activity.MainActivity; + +/** + * Quick Tile Service + * Created by pcqpcq on 17/7/28. + */ +@RequiresApi(api = Build.VERSION_CODES.N) +public class DaedalusTileService extends TileService { + + @Override + public void onClick() { + Daedalus appContext = Daedalus.getInstance(); + boolean activate = appContext.isServiceActivated(); + + Intent intent = new Intent(appContext, MainActivity.class) + .setAction(Intent.ACTION_VIEW) + .putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_DEACTIVATE : MainActivity.LAUNCH_ACTION_ACTIVATE); + + startActivityAndCollapse(intent); + } + + @Override + public void onTileAdded() { + updateTile(); + } + + @Override + public void onStartListening() { + updateTile(); + } + + private void updateTile() { + boolean activate = Daedalus.getInstance().isServiceActivated(); + + Tile tile = getQsTile(); + tile.setState(activate ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); + tile.updateTile(); + } +}