mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Printer: allow printing incoming text shared to Gadgetbridge
Add a new NotificationType for received text. Add device specific settings to the printer coordinator, also add setting to print received text (defaults to on).
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ public class TextReceiverActivity extends AbstractGBActivity {
|
||||
notificationSpec.body = text;
|
||||
notificationSpec.sourceAppId = BuildConfig.APPLICATION_ID;
|
||||
notificationSpec.sourceName = appName;
|
||||
notificationSpec.type = NotificationType.UNKNOWN;
|
||||
notificationSpec.type = NotificationType.GADGETBRIDGE_TEXT_RECEIVER;
|
||||
|
||||
GBApplication.deviceService().onNotification(notificationSpec);
|
||||
finish();
|
||||
|
||||
+9
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettings;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCardAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||
@@ -79,6 +80,14 @@ public class ThermalPrinterCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceSpecificSettings getDeviceSpecificSettings(GBDevice device) {
|
||||
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
|
||||
|
||||
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_print_received_text);
|
||||
return deviceSpecificSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceCardAction> getCustomActions() {
|
||||
return Collections.singletonList(new ControlDeviceCardAction());
|
||||
|
||||
@@ -60,6 +60,7 @@ public enum NotificationType {
|
||||
TUMBLR,
|
||||
PINTEREST,
|
||||
YOUTUBE,
|
||||
GADGETBRIDGE_TEXT_RECEIVER,
|
||||
;
|
||||
|
||||
|
||||
@@ -120,6 +121,7 @@ public enum NotificationType {
|
||||
case YAHOO_MAIL:
|
||||
return "generic_email";
|
||||
case COL_REMINDER:
|
||||
case GADGETBRIDGE_TEXT_RECEIVER:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return "generic";
|
||||
|
||||
+14
@@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.thermalprinter;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
@@ -34,6 +35,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSett
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLESingleDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@@ -119,6 +121,18 @@ public class GenericThermalPrinterSupport extends AbstractBTLESingleDeviceSuppor
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
if(notificationSpec.type.equals(NotificationType.GADGETBRIDGE_TEXT_RECEIVER)) {
|
||||
final SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
|
||||
if(!prefs.getBoolean("pref_printer_print_received_text", false)) {
|
||||
LOG.info("Not printing received text, device preference forbids this.");
|
||||
return;
|
||||
}
|
||||
|
||||
//title is appName
|
||||
//body is the shared text
|
||||
// see TextReceiverActivity.java
|
||||
printImage(createBitmapFromString(notificationSpec.body), false, PrintAlignment.ALIGN_LEFT);
|
||||
}
|
||||
// printImage(createNotificationBitmap(notificationSpec), true, PrintAlignment.ALIGN_LEFT);
|
||||
}
|
||||
|
||||
|
||||
@@ -4165,4 +4165,5 @@
|
||||
<string name="pref_summary_time_interval">Restrict to specific intervals</string>
|
||||
<string name="prefs_key_enable_deprecated_notificationcollectormonitor_title">Enable the deprecated Notification Collector Monitor Service</string>
|
||||
<string name="prefs_key_enable_deprecated_notificationcollectormonitor_summary">Forces the usage of a second foreground service to keep the Notification monitor alive, activate this option if Gadgetbridge stops receiving notifications.\nPlease note that it might cause a second persistent notification to be shown.\nRestart the application after toggling.</string>
|
||||
<string name="pref_printer_print_received_text">Print text shared to Gadgetbridge</string>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:key="pref_printer_print_received_text"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_printer_print_received_text" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
Reference in New Issue
Block a user