mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
improved activity hand handling
This commit is contained in:
parent
a2060470f8
commit
90f685c1a7
@ -106,6 +106,8 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
private HashMap<String, Long> notificationBurstPrevention = new HashMap<>();
|
private HashMap<String, Long> notificationBurstPrevention = new HashMap<>();
|
||||||
private HashMap<String, Long> notificationOldRepeatPrevention = new HashMap<>();
|
private HashMap<String, Long> notificationOldRepeatPrevention = new HashMap<>();
|
||||||
|
|
||||||
|
public static ArrayList<String> notificationStack = new ArrayList<>();
|
||||||
|
|
||||||
private long activeCallPostTime;
|
private long activeCallPostTime;
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@ -223,6 +225,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||||
|
notificationStack.clear();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +244,9 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
public void onNotificationPosted(StatusBarNotification sbn) {
|
public void onNotificationPosted(StatusBarNotification sbn) {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
notificationStack.remove(sbn.getPackageName());
|
||||||
|
notificationStack.add(sbn.getPackageName());
|
||||||
|
|
||||||
if (GBApplication.isRunningLollipopOrLater()) {
|
if (GBApplication.isRunningLollipopOrLater()) {
|
||||||
if ("call".equals(sbn.getNotification().category) && prefs.getBoolean("notification_support_voip_calls", false)) {
|
if ("call".equals(sbn.getNotification().category) && prefs.getBoolean("notification_support_voip_calls", false)) {
|
||||||
handleCallNotification(sbn);
|
handleCallNotification(sbn);
|
||||||
@ -384,7 +390,6 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
}else {
|
}else {
|
||||||
LOG.info("This app might show old/duplicate notifications. notification.when is 0 for " + source);
|
LOG.info("This app might show old/duplicate notifications. notification.when is 0 for " + source);
|
||||||
}
|
}
|
||||||
|
|
||||||
GBApplication.deviceService().onNotification(notificationSpec);
|
GBApplication.deviceService().onNotification(notificationSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,6 +635,8 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||||
LOG.info("Notification removed: " + sbn.getPackageName());
|
LOG.info("Notification removed: " + sbn.getPackageName());
|
||||||
|
|
||||||
|
notificationStack.remove(sbn.getPackageName());
|
||||||
|
|
||||||
Object lookupObject = mNotificationHandleLookup.lookupByValue(sbn.getPostTime());;
|
Object lookupObject = mNotificationHandleLookup.lookupByValue(sbn.getPostTime());;
|
||||||
if(lookupObject == null){
|
if(lookupObject == null){
|
||||||
LOG.debug("removed notification not found");
|
LOG.debug("removed notification not found");
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
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;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
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;
|
||||||
@ -23,15 +20,14 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Queue;
|
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;
|
||||||
@ -40,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInf
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfig;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
@ -121,10 +118,6 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
|
|
||||||
private boolean useActivityHand;
|
private boolean useActivityHand;
|
||||||
|
|
||||||
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"));
|
||||||
@ -147,8 +140,6 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
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() {
|
||||||
@ -234,13 +225,14 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
requestQueue.add(new SetCurrentStepCountRequest((int) (999999 * calculateNotificationProgress())));
|
requestQueue.add(new SetCurrentStepCountRequest((int) (999999 * calculateNotificationProgress())));
|
||||||
}else {
|
} else {
|
||||||
requestQueue.add(new SetCurrentStepCountRequest(0));
|
requestQueue.add(new SetCurrentStepCountRequest(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Request initialRequest = new GetStepGoalRequest();
|
Request initialRequest = new GetStepGoalRequest();
|
||||||
|
|
||||||
builder.read(getCharacteristic(UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb")))
|
builder
|
||||||
|
// .read(getCharacteristic(UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb")))
|
||||||
.read(getCharacteristic(UUID.fromString("00002a24-0000-1000-8000-00805f9b34fb")))
|
.read(getCharacteristic(UUID.fromString("00002a24-0000-1000-8000-00805f9b34fb")))
|
||||||
.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")))
|
||||||
@ -280,51 +272,52 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
if (mode == AudioManager.RINGER_MODE_SILENT) return;
|
if (mode == AudioManager.RINGER_MODE_SILENT) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean enforceActivityHandNotification = config.getHour() == -1 && config.getMin() == -1;
|
||||||
|
|
||||||
|
showNotificationsByAllActive(enforceActivityHandNotification);
|
||||||
|
|
||||||
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.add(Integer.valueOf(notificationSpec.getId()));
|
|
||||||
showNotificationCountOnActivityHand();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteNotification(int id) {
|
public void onDeleteNotification(int id) {
|
||||||
super.onDeleteNotification(id);
|
super.onDeleteNotification(id);
|
||||||
|
|
||||||
StatusBarNotification[] notifications = new StatusBarNotification[0];
|
showNotificationsByAllActive(true);
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
|
||||||
showNotificationsByAllActive();
|
|
||||||
}else{
|
|
||||||
notificationStack.remove(Integer.valueOf(id));
|
|
||||||
showNotificationCountOnActivityHand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showNotificationsByAllActive(boolean enforceByNotification) {
|
||||||
|
if(!this.useActivityHand);
|
||||||
|
double progress = calculateNotificationProgress();
|
||||||
|
showNotificationCountOnActivityHand(progress);
|
||||||
|
|
||||||
|
if(enforceByNotification){
|
||||||
|
queueWrite(
|
||||||
|
new PlayNotificationRequest(
|
||||||
|
PlayNotificationRequest.VibrationType.NO_VIBE,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
(int) (progress * 180)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
private void showNotificationsByAllActive() {
|
|
||||||
showNotificationCountOnActivityHand(calculateNotificationProgress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
private double calculateNotificationProgress() {
|
||||||
private double calculateNotificationProgress(){
|
HashMap<PackageConfig, Boolean> configs = new HashMap<>(0);
|
||||||
StatusBarNotification[] notifications;
|
for (PackageConfig config : helper.getSettings()) {
|
||||||
notifications = notificationManager.getActiveNotifications();
|
configs.put(config, false);
|
||||||
|
}
|
||||||
ArrayList<PackageConfig> configs = helper.getSettings();
|
|
||||||
|
|
||||||
double notificationProgress = 0;
|
double notificationProgress = 0;
|
||||||
|
|
||||||
for(StatusBarNotification notification : notifications){
|
for (String notificationPackage : NotificationListener.notificationStack) {
|
||||||
for(PackageConfig packageConfig : configs){
|
for (PackageConfig packageConfig : configs.keySet()) {
|
||||||
if(packageConfig.getPackageName().equals(notification.getPackageName())){
|
if(configs.get(packageConfig)) continue;
|
||||||
|
if (packageConfig.getPackageName().equals(notificationPackage)) {
|
||||||
notificationProgress += 0.25;
|
notificationProgress += 0.25;
|
||||||
configs.remove(packageConfig);
|
configs.put(packageConfig, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,11 +331,8 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNotificationCountOnActivityHand() {
|
|
||||||
showNotificationCountOnActivityHand(notificationStack.size() / 4.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playNotification(PackageConfig config) {
|
private void playNotification(PackageConfig config) {
|
||||||
|
if(config.getMin() == -1 && config.getHour() == -1 && config.getVibration() == PlayNotificationRequest.VibrationType.NO_VIBE) return;
|
||||||
queueWrite(new PlayNotificationRequest(config.getVibration(), config.getHour(), config.getMin()));
|
queueWrite(new PlayNotificationRequest(config.getVibration(), config.getHour(), config.getMin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,11 +344,10 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
private SetTimeRequest prepareSetTimeRequest() {
|
private SetTimeRequest prepareSetTimeRequest() {
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
TimeZone zone = new GregorianCalendar().getTimeZone();
|
TimeZone zone = new GregorianCalendar().getTimeZone();
|
||||||
SetTimeRequest request = new SetTimeRequest(
|
return new SetTimeRequest(
|
||||||
(int) (millis / 1000 + timeOffset * 60),
|
(int) (millis / 1000 + timeOffset * 60),
|
||||||
(short) (millis % 1000),
|
(short) (millis % 1000),
|
||||||
(short) ((zone.getRawOffset() + zone.getDSTSavings()) / 60000));
|
(short) ((zone.getRawOffset() + zone.getDSTSavings()) / 60000));
|
||||||
return request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -398,20 +387,16 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTestNewFunction() {
|
public void onTestNewFunction() {
|
||||||
//downloadActivityFiles();
|
float random = (float)Math.random();
|
||||||
//queueWrite(new GetCurrentStepCountRequest());
|
setActivityHand(random);
|
||||||
// queueWrite(new EventStreamRequest((short)4));
|
queueWrite(
|
||||||
// queueWrite(new OTAEraseRequest(0));
|
new PlayNotificationRequest(
|
||||||
// queueWrite(new OTAResetRequest());
|
PlayNotificationRequest.VibrationType.NO_VIBE,
|
||||||
// new UploadFileRequest((short)00, new byte[]{0x01, 0x00, 0x08, 0x01, 0x01, 0x0C, 0x00, (byte)0xBD, 0x01, 0x30, 0x71, (byte)0xFF, 0x05, 0x00, 0x01, 0x00});
|
-1,
|
||||||
// queueWrite(new ActivityPointGetRequest());
|
-1,
|
||||||
long millis = System.currentTimeMillis();
|
(int) (random * 180)
|
||||||
int secs = (int) (millis / 1000 * 60);
|
)
|
||||||
//queueWrite(new SetCountdownSettings(secs, secs + 10, (short) 120));
|
);
|
||||||
//queueWrite(new GetCountdownSettingsRequest());
|
|
||||||
|
|
||||||
// queueWrite(new AnimationRequest());
|
|
||||||
queueWrite(new SetCurrentStepCountRequest(1000000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void overwriteButtons() {
|
private void overwriteButtons() {
|
||||||
@ -733,7 +718,7 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
queueWrite(new MoveHandsRequest(false, minute, hour, (short) -1));
|
queueWrite(new MoveHandsRequest(false, minute, hour, (short) -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void vibrate(int vibration) {
|
private void vibrate(PlayNotificationRequest.VibrationType vibration) {
|
||||||
queueWrite(new PlayNotificationRequest(vibration, -1, -1));
|
queueWrite(new PlayNotificationRequest(vibration, -1, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,7 +731,16 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
Object extra = intent.getExtras().get("EXTRA_PROGRESS");
|
Object extra = intent.getExtras().get("EXTRA_PROGRESS");
|
||||||
float progress = (float) extra;
|
float progress = (float) extra;
|
||||||
setActivityHand(progress);
|
setActivityHand(progress);
|
||||||
}catch (Exception e){
|
|
||||||
|
queueWrite(
|
||||||
|
new PlayNotificationRequest(
|
||||||
|
PlayNotificationRequest.VibrationType.NO_VIBE,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
(int) (progress * 180)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.debug("trash extra should be number 0.0-1.0");
|
logger.debug("trash extra should be number 0.0-1.0");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user