add QuickTile support (#29)

This commit is contained in:
Joker 2017-07-28 21:18:19 +08:00 committed by PeratX
parent 17e5f5e132
commit 8dd6278337
2 changed files with 57 additions and 0 deletions

View File

@ -23,6 +23,15 @@
<action android:name="android.net.VpnService"/>
</intent-filter>
</service>
<service
android:name=".service.DaedalusTileService"
android:label="@string/app_name"
android:icon="@drawable/ic_security"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<receiver android:name=".receiver.BootBroadcastReceiver">
<intent-filter>

View File

@ -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();
}
}