mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-12 01:51:58 +01:00
using getActiveNotifications when possible
This commit is contained in:
parent
2ebafa9eda
commit
aeba34cc81
@ -1,5 +1,6 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@ -8,7 +9,9 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -28,6 +31,7 @@ import java.util.Queue;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -119,6 +123,8 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
|
|
||||||
ArrayList<Integer> notificationStack = new ArrayList<>();
|
ArrayList<Integer> notificationStack = new ArrayList<>();
|
||||||
|
|
||||||
|
NotificationManager notificationManager;
|
||||||
|
|
||||||
public QHybridSupport() {
|
public QHybridSupport() {
|
||||||
super(logger);
|
super(logger);
|
||||||
addSupportedService(UUID.fromString("3dda0001-957f-7d4a-34a6-74696673696d"));
|
addSupportedService(UUID.fromString("3dda0001-957f-7d4a-34a6-74696673696d"));
|
||||||
@ -136,9 +142,13 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter);
|
LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter);
|
||||||
fillResponseList();
|
fillResponseList();
|
||||||
|
|
||||||
|
helper = new PackageConfigHelper(GBApplication.getContext());
|
||||||
|
|
||||||
IntentFilter globalFilter = new IntentFilter();
|
IntentFilter globalFilter = new IntentFilter();
|
||||||
globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND);
|
globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND);
|
||||||
GBApplication.getContext().registerReceiver(globalCommandReceiver, globalFilter);
|
GBApplication.getContext().registerReceiver(globalCommandReceiver, globalFilter);
|
||||||
|
|
||||||
|
notificationManager = (NotificationManager) GBApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean supportsActivityHand() {
|
private boolean supportsActivityHand() {
|
||||||
@ -221,7 +231,12 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
requestQueue.add(new ActivityPointGetRequest());
|
requestQueue.add(new ActivityPointGetRequest());
|
||||||
requestQueue.add(prepareSetTimeRequest());
|
requestQueue.add(prepareSetTimeRequest());
|
||||||
requestQueue.add(new AnimationRequest());
|
requestQueue.add(new AnimationRequest());
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
requestQueue.add(new SetCurrentStepCountRequest((int) (999999 * calculateNotificationProgress())));
|
||||||
|
}else {
|
||||||
requestQueue.add(new SetCurrentStepCountRequest(0));
|
requestQueue.add(new SetCurrentStepCountRequest(0));
|
||||||
|
}
|
||||||
|
|
||||||
Request initialRequest = new GetStepGoalRequest();
|
Request initialRequest = new GetStepGoalRequest();
|
||||||
|
|
||||||
@ -230,10 +245,8 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
.read(getCharacteristic(UUID.fromString("00002a26-0000-1000-8000-00805f9b34fb")))
|
.read(getCharacteristic(UUID.fromString("00002a26-0000-1000-8000-00805f9b34fb")))
|
||||||
.read(getCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb")))
|
.read(getCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb")))
|
||||||
.notify(getCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb")), true)
|
.notify(getCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb")), true)
|
||||||
.write(getCharacteristic(initialRequest.getRequestUUID()), initialRequest.getRequestData())
|
.write(getCharacteristic(initialRequest.getRequestUUID()), initialRequest.getRequestData());
|
||||||
;
|
|
||||||
|
|
||||||
helper = new PackageConfigHelper(getContext());
|
|
||||||
getTimeOffset();
|
getTimeOffset();
|
||||||
|
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||||
@ -269,23 +282,64 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
|
|
||||||
playNotification(config);
|
playNotification(config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
|
showNotificationsByAllActive();
|
||||||
|
}else{
|
||||||
notificationStack.remove(Integer.valueOf(notificationSpec.getId()));
|
notificationStack.remove(Integer.valueOf(notificationSpec.getId()));
|
||||||
notificationStack.add(Integer.valueOf(notificationSpec.getId()));
|
notificationStack.add(Integer.valueOf(notificationSpec.getId()));
|
||||||
showNotificationCountOnActivityHand();
|
showNotificationCountOnActivityHand();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteNotification(int id) {
|
public void onDeleteNotification(int id) {
|
||||||
super.onDeleteNotification(id);
|
super.onDeleteNotification(id);
|
||||||
|
|
||||||
|
StatusBarNotification[] notifications = new StatusBarNotification[0];
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
|
showNotificationsByAllActive();
|
||||||
|
}else{
|
||||||
notificationStack.remove(Integer.valueOf(id));
|
notificationStack.remove(Integer.valueOf(id));
|
||||||
showNotificationCountOnActivityHand();
|
showNotificationCountOnActivityHand();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
|
private void showNotificationsByAllActive() {
|
||||||
|
showNotificationCountOnActivityHand(calculateNotificationProgress());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
|
private double calculateNotificationProgress(){
|
||||||
|
StatusBarNotification[] notifications;
|
||||||
|
notifications = notificationManager.getActiveNotifications();
|
||||||
|
|
||||||
|
ArrayList<PackageConfig> configs = helper.getSettings();
|
||||||
|
|
||||||
|
double notificationProgress = 0;
|
||||||
|
|
||||||
|
for(StatusBarNotification notification : notifications){
|
||||||
|
for(PackageConfig packageConfig : configs){
|
||||||
|
if(packageConfig.getPackageName().equals(notification.getPackageName())){
|
||||||
|
notificationProgress += 0.25;
|
||||||
|
configs.remove(packageConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return notificationProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showNotificationCountOnActivityHand(double progress) {
|
||||||
|
if (useActivityHand) {
|
||||||
|
setActivityHand(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showNotificationCountOnActivityHand() {
|
private void showNotificationCountOnActivityHand() {
|
||||||
if (useActivityHand) {
|
showNotificationCountOnActivityHand(notificationStack.size() / 4.0);
|
||||||
setActivityHand(notificationStack.size() / 4.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playNotification(PackageConfig config) {
|
private void playNotification(PackageConfig config) {
|
||||||
|
Loading…
Reference in New Issue
Block a user