Skip to content

Commit 2a16e47

Browse files
committed
Initial commit
0 parents  commit 2a16e47

31 files changed

+713
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetSelector.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/migrations.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# BT QS
2+
3+
Google changed Bluetooth QS tile in Android 14.
4+
I've been asked to make same simple tile as my previous [WiFi QS](https://github.com/rostopira/wifi_qs) project.
5+
6+
Target API 30 is required to allow this app to turn Bluetooth on and off without extra permission.
7+
I can't publish this in Google Play, since it requires minimum target API 33.
8+
9+
# FAQ
10+
11+
## I want Wi-Fi tile
12+
13+
Check out [WiFi QS](https://github.com/rostopira/wifi_qs).
14+
15+
## I want internet toggle
16+
17+
Nope, not possible without root.
18+
19+
## I have root
20+
21+
Use [Better Internet Tiles](https://play.google.com/store/apps/details?id=be.casperverswijvelt.unifiedinternetqs)
22+
23+
## I don't have root, what about Shizuku
24+
25+
Use [Better Internet Tiles](https://play.google.com/store/apps/details?id=be.casperverswijvelt.unifiedinternetqs)
26+
27+
I'm not going to rewrite it using shizuku
28+
29+
## I have feature request
30+
31+
I don't have time for that. PR's are welcome

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
}
4+
5+
android {
6+
namespace 'dev.rostopira.btqs'
7+
compileSdk 34
8+
9+
defaultConfig {
10+
applicationId "dev.rostopira.btqs"
11+
minSdk 30
12+
//noinspection ExpiredTargetSdkVersion
13+
targetSdk 30
14+
versionCode 1
15+
versionName "1.0"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
signingConfig signingConfigs.debug
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_9
27+
targetCompatibility JavaVersion.VERSION_1_9
28+
}
29+
}
30+
31+
dependencies {
32+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<uses-feature
6+
android:name="android.hardware.bluetooth"
7+
android:required="true"/>
8+
9+
<uses-permission android:name="android.permission.BLUETOOTH"/>
10+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
11+
12+
<application
13+
android:allowBackup="true"
14+
android:label="BT QS"
15+
android:supportsRtl="false"
16+
tools:ignore="MissingApplicationIcon">
17+
18+
<activity
19+
android:name=".LongPressReceiver"
20+
android:excludeFromRecents="true"
21+
android:exported="true">
22+
<intent-filter>
23+
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
24+
</intent-filter>
25+
</activity>
26+
27+
<service
28+
android:name=".BtTileService"
29+
android:label="BT QS"
30+
android:icon="@drawable/connected"
31+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
32+
android:exported="true">
33+
<intent-filter>
34+
<action android:name="android.service.quicksettings.action.QS_TILE"/>
35+
</intent-filter>
36+
</service>
37+
38+
</application>
39+
40+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.rostopira.btqs;
2+
3+
public enum BtState {
4+
DISABLED,
5+
ENABLED,
6+
CONNECTED,
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.rostopira.btqs;
2+
3+
public interface BtStateListener {
4+
void onBtStateChanged(BtState state, String deviceName);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dev.rostopira.btqs;
2+
3+
import android.annotation.SuppressLint;
4+
import android.bluetooth.BluetoothAdapter;
5+
import android.bluetooth.BluetoothDevice;
6+
import android.content.BroadcastReceiver;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.content.IntentFilter;
10+
import android.util.Log;
11+
12+
import java.lang.reflect.Method;
13+
import java.util.Set;
14+
15+
public class BtStateReceiver extends BroadcastReceiver {
16+
final BtStateListener listener;
17+
18+
BtStateReceiver(BtStateListener listener) {
19+
this.listener = listener;
20+
}
21+
22+
@SuppressLint("MissingPermission")
23+
@Override
24+
public void onReceive(Context context, Intent intent) {
25+
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
26+
if (!adapter.isEnabled()) {
27+
listener.onBtStateChanged(BtState.DISABLED, null);
28+
return;
29+
}
30+
final Set<BluetoothDevice> paired = adapter.getBondedDevices();
31+
for (BluetoothDevice device: paired) {
32+
if (isConnected(device)) {
33+
listener.onBtStateChanged(BtState.CONNECTED, device.getAlias());
34+
return;
35+
}
36+
}
37+
listener.onBtStateChanged(BtState.ENABLED, null);
38+
}
39+
40+
static BtStateReceiver createAndRegister(Context context, BtStateListener listener) {
41+
final BtStateReceiver receiver = new BtStateReceiver(listener);
42+
final IntentFilter intentFilter = new IntentFilter();
43+
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
44+
intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
45+
context.registerReceiver(receiver, intentFilter);
46+
return receiver;
47+
}
48+
49+
private static boolean isConnected(BluetoothDevice device) {
50+
try {
51+
//noinspection JavaReflectionMemberAccess
52+
final Method method = device.getClass().getMethod("isConnected");
53+
//noinspection DataFlowIssue
54+
return (Boolean) method.invoke(device);
55+
} catch (Exception e) {
56+
Log.e("BtStateReceiver", "Failed to check connection state", e);
57+
return false;
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package dev.rostopira.btqs;
2+
3+
import android.annotation.SuppressLint;
4+
import android.bluetooth.BluetoothAdapter;
5+
import android.graphics.drawable.Icon;
6+
import android.service.quicksettings.Tile;
7+
import android.service.quicksettings.TileService;
8+
9+
public class BtTileService extends TileService implements BtStateListener {
10+
BtStateReceiver btStateReceiver;
11+
12+
@Override
13+
public void onStartListening() {
14+
super.onStartListening();
15+
if (btStateReceiver != null) {
16+
return;
17+
}
18+
btStateReceiver = BtStateReceiver.createAndRegister(this, this);
19+
btStateReceiver.onReceive(this, null);
20+
}
21+
22+
@Override
23+
public void onBtStateChanged(BtState state, String deviceName) {
24+
final Tile tile = getQsTile();
25+
if (tile == null) {
26+
return;
27+
}
28+
tile.setLabel("Bluetooth");
29+
switch (state) {
30+
case DISABLED:
31+
tile.setIcon(Icon.createWithResource(this, R.drawable.disabled));
32+
tile.setSubtitle(getString(R.string.off));
33+
tile.setState(Tile.STATE_INACTIVE);
34+
break;
35+
case ENABLED:
36+
tile.setIcon(Icon.createWithResource(this, R.drawable.enabled));
37+
tile.setSubtitle(getString(R.string.disconnected));
38+
tile.setState(Tile.STATE_ACTIVE);
39+
break;
40+
case CONNECTED:
41+
tile.setIcon(Icon.createWithResource(this, R.drawable.connected));
42+
tile.setSubtitle(deviceName != null ? deviceName : getString(R.string.connected));
43+
tile.setState(Tile.STATE_ACTIVE);
44+
break;
45+
}
46+
tile.updateTile();
47+
}
48+
49+
@SuppressLint("MissingPermission")
50+
@Override
51+
public void onClick() {
52+
super.onClick();
53+
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
54+
if (adapter.isEnabled()) {
55+
adapter.disable();
56+
} else {
57+
adapter.enable();
58+
}
59+
}
60+
61+
@Override
62+
public void onStopListening() {
63+
super.onStopListening();
64+
if (btStateReceiver != null) {
65+
unregisterReceiver(btStateReceiver);
66+
btStateReceiver = null;
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dev.rostopira.btqs;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.provider.Settings;
7+
8+
public class LongPressReceiver extends Activity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
final Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
14+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
15+
startActivity(intent);
16+
finish();
17+
}
18+
19+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="960" android:viewportHeight="960">
2+
<path android:fillColor="#FFF" android:pathData="M440,880v-304L256,760l-56,-56 224,-224 -224,-224 56,-56 184,184v-304h40l228,228 -172,172 172,172L480,880h-40ZM520,384 L596,308 520,234v150ZM520,726 L596,652 520,576v150ZM200,540q-25,0 -42.5,-17.5T140,480q0,-25 17.5,-42.5T200,420q25,0 42.5,17.5T260,480q0,25 -17.5,42.5T200,540ZM760,540q-25,0 -42.5,-17.5T700,480q0,-25 17.5,-42.5T760,420q25,0 42.5,17.5T820,480q0,25 -17.5,42.5T760,540Z" />
3+
</vector>

0 commit comments

Comments
 (0)