From 902a70ee837a4dc5e0e9eb08876137830e3c166a Mon Sep 17 00:00:00 2001 From: fabian Date: Sat, 31 Jan 2026 19:21:57 +0100 Subject: [PATCH 1/2] better logs --- android_notify/widgets/texts.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/android_notify/widgets/texts.py b/android_notify/widgets/texts.py index d50bedd..871dadb 100644 --- a/android_notify/widgets/texts.py +++ b/android_notify/widgets/texts.py @@ -3,7 +3,7 @@ """ from android_notify.config import on_android_platform -from android_notify.internal.java_classes import autoclass, String, NotificationCompatBigTextStyle, NotificationCompatInboxStyle +from android_notify.internal.java_classes import String, NotificationCompatBigTextStyle, NotificationCompatInboxStyle def set_big_text(builder, body, title="", summary=""): @@ -48,8 +48,10 @@ def set_title(builder, title, using_layout=False): :param title: New Notification Title :param using_layout: Whether to use layout or not """ - + def log(): + logger.info(f'new notification title: {title}') if not on_android_platform(): + log() return None if using_layout: @@ -58,7 +60,7 @@ def set_title(builder, title, using_layout=False): else: builder.setContentTitle(String(title)) - logger.info(f'new notification title: {title}') + log() return None @@ -69,8 +71,11 @@ def set_message(builder, message, using_layout=False): :param message: New Notification message :param using_layout: Whether to use layout or not """ + def log(): + logger.info(f'new notification message: {message}') if not on_android_platform(): + log() return None if using_layout: @@ -79,7 +84,7 @@ def set_message(builder, message, using_layout=False): else: builder.setContentText(String(message)) - logger.info(f'new notification message: {message}') + log() return None @@ -116,6 +121,7 @@ def setLayoutText(layout, text_id, text, color): def set_custom_colors(builder, title, message, title_color, message_color): # Load layout + from android_notify.internal.java_classes import autoclass NotificationCompatDecoratedCustomViewStyle = autoclass( 'android.app.Notification$DecoratedCustomViewStyle') From 70cc4d90efc7d00efdc60ad19ce18fd21d673fe7 Mon Sep 17 00:00:00 2001 From: fabian Date: Sat, 31 Jan 2026 19:23:36 +0100 Subject: [PATCH 2/2] facade improvements to run on PC and fill_args replaces start_building --- android_notify/internal/facade.py | 96 +++++++++++++------ android_notify/sword.py | 11 ++- .../tests/test_notification_permission.py | 2 - 3 files changed, 77 insertions(+), 32 deletions(-) diff --git a/android_notify/internal/facade.py b/android_notify/internal/facade.py index b755866..558cede 100644 --- a/android_notify/internal/facade.py +++ b/android_notify/internal/facade.py @@ -3,8 +3,10 @@ Also For Reference of Available Methods """ +from enum import IntFlag, auto from android_notify.internal.logger import logger + class Bundle: def putString(self, key, value): logger.debug(f"[MOCK] Bundle.putString called with key={key}, value={value}") @@ -19,11 +21,16 @@ def __new__(cls, value): return str.__new__(cls, value) -class Intent: - FLAG_ACTIVITY_NEW_TASK = 'FACADE_FLAG_ACTIVITY_NEW_TASK' - CATEGORY_DEFAULT = 'FACADE_FLAG_CATEGORY_DEFAULT' + + +class Intent(IntFlag): + NONE = 0 + FLAG_ACTIVITY_CLEAR_TOP = auto() + FLAG_ACTIVITY_NEW_TASK = auto() + FLAG_ACTIVITY_SINGLE_TOP = auto() def __init__(self, context='', activity=''): + self.IS = "FACADE" self.obj = {} logger.debug(f"[MOCK] Intent initialized with context={context}, activity={activity}") @@ -132,12 +139,13 @@ def getId(self): def setSound(self, sound_uri, _): logger.debug(f"[MOCK] NotificationChannel.setSound called, sound_uri={sound_uri}") - def enableVibration(self,state): + def enableVibration(self, state): logger.debug(f"[MOCK] NotificationChannel.enableVibration called, state={state}") - def setVibrationPattern(self,list_of_numbers): + def setVibrationPattern(self, list_of_numbers): logger.debug(f"[MOCK] NotificationChannel.setVibrationPattern called, list_of_numbers={list_of_numbers}") + class IconCompat: @classmethod def createWithBitmap(cls, bitmap): @@ -175,6 +183,7 @@ class NotificationManagerCompat: IMPORTANCE_MIN = '' IMPORTANCE_NONE = '' + class AndroidNotification: DEFAULT_ALL = 3 PRIORITY_HIGH = 4 @@ -182,6 +191,7 @@ class AndroidNotification: PRIORITY_LOW = '' PRIORITY_MIN = '' + class NotificationCompat: DEFAULT_ALL = 3 PRIORITY_HIGH = 4 @@ -201,76 +211,97 @@ def __init__(self, context, channel_id): self.mActions = MActions() logger.debug(f"[MOCK] NotificationCompatBuilder initialized with context={context}, channel_id={channel_id}") - def setProgress(self, max_value, current_value, endless): + @classmethod + def setProgress(cls, max_value, current_value, endless): logger.debug(f"[MOCK] setProgress called with max={max_value}, current={current_value}, endless={endless}") - def setStyle(self, style): + @classmethod + def setStyle(cls, style): logger.debug(f"[MOCK] setStyle called with style={style}") - def setContentTitle(self, title): + @classmethod + def setContentTitle(cls, title): logger.debug(f"[MOCK] setContentTitle called with title={title}") - def setContentText(self, text): + @classmethod + def setContentText(cls, text): logger.debug(f"[MOCK] setContentText called with text={text}") - def setSmallIcon(self, icon): + @classmethod + def setSmallIcon(cls, icon): logger.debug(f"[MOCK] setSmallIcon called with icon={icon}") - def setLargeIcon(self, icon): + @classmethod + def setLargeIcon(cls, icon): logger.debug(f"[MOCK] setLargeIcon called with icon={icon}") - def setAutoCancel(self, auto_cancel: bool): + @classmethod + def setAutoCancel(cls, auto_cancel: bool): logger.debug(f"[MOCK] setAutoCancel called with auto_cancel={auto_cancel}") - def setPriority(self, priority): + @classmethod + def setPriority(cls, priority): logger.debug(f"[MOCK] setPriority called with priority={priority}") - def setDefaults(self, defaults): + @classmethod + def setDefaults(cls, defaults): logger.debug(f"[MOCK] setDefaults called with defaults={defaults}") - def setOngoing(self, persistent: bool): + @classmethod + def setOngoing(cls, persistent: bool): logger.debug(f"[MOCK] setOngoing called with persistent={persistent}") - def setOnlyAlertOnce(self, state): + @classmethod + def setOnlyAlertOnce(cls, state): logger.debug(f"[MOCK] setOnlyAlertOnce called with state={state}") - def build(self): + @classmethod + def build(cls): logger.debug("[MOCK] build called") - def setContentIntent(self, pending_action_intent: PendingIntent): + @classmethod + def setContentIntent(cls, pending_action_intent: PendingIntent): logger.debug(f"[MOCK] setContentIntent called with {pending_action_intent}") - def addAction(self, icon_int, action_text, pending_action_intent): + @classmethod + def addAction(cls, icon_int, action_text, pending_action_intent): logger.debug( f"[MOCK] addAction called with icon={icon_int}, text={action_text}, intent={pending_action_intent}" ) - def setShowWhen(self, state): + @classmethod + def setShowWhen(cls, state): logger.debug(f"[MOCK] setShowWhen called with state={state}") - def setWhen(self, time_ms): + @classmethod + def setWhen(cls, time_ms): logger.debug(f"[MOCK] setWhen called with time_ms={time_ms}") - def setCustomContentView(self, layout): + @classmethod + def setCustomContentView(cls, layout): logger.debug(f"[MOCK] setCustomContentView called with layout={layout}") - def setCustomBigContentView(self, layout): + @classmethod + def setCustomBigContentView(cls, layout): logger.debug(f"[MOCK] setCustomBigContentView called with layout={layout}") - def setSubText(self, text): + @classmethod + def setSubText(cls, text): logger.debug(f"[MOCK] setSubText called with text={text}") - def setColor(self, color: Color) -> None: + @classmethod + def setColor(cls, color: Color) -> None: logger.debug(f"[MOCK] setColor called with color={color}") - def setVibrate(self, state) -> None: + @classmethod + def setVibrate(cls, state) -> None: logger.debug(f"[MOCK] setVibrate called with state={state}") class NotificationCompatBigTextStyle: - def bigText(self, body): + def bigText(cls, body): logger.debug(f"[MOCK] NotificationCompatBigTextStyle.bigText called with body={body}") - return self + return cls def setBigContentTitle(self, title): logger.debug(f"[MOCK] NotificationCompatBigTextStyle.setBigContentTitle called with title={title}") @@ -334,6 +365,15 @@ def mActivity(): logger.debug("[MOCK] mActivity used") return MActivity() + @staticmethod + def startForeground(notification_id, builder_build, foreground_type): + logger.debug( + f"[MOCK] startForeground called with notification_id={notification_id}, builder.build()={builder_build}, foreground_type={foreground_type}") + + def setAutoRestartService(self): + logger.debug("[MOCK] setAutoRestartService called") + return self + class DummyIcon: icon = 101 diff --git a/android_notify/sword.py b/android_notify/sword.py index 10b7b9e..d7ab576 100644 --- a/android_notify/sword.py +++ b/android_notify/sword.py @@ -114,6 +114,8 @@ def setData(self, data_object:dict): :param data_object: :return: """ + if not on_android_platform(): + return self.__called_set_data = True self.data_object = data_object action_name = str(self.name or self.__id) @@ -413,7 +415,7 @@ def send(self, silent: bool = False, persistent=False, close_on_click=True): """ self.silent = silent or self.silent if on_android_platform(): - self.start_building(persistent, close_on_click) + self.fill_args(persistent=persistent, close_on_click=close_on_click) dispatch_notification(notification_id=self.__id, builder=self.builder, passed_check=self.passed_check) self.__send_logs() @@ -426,6 +428,7 @@ def send_(self, silent: bool = False, persistent=False, close_on_click=True): persistent (bool): True To not remove Notification When User hits clears All notifications button close_on_click (bool): True if you want Notification to be removed when clicked """ + # TODO: Remove this method - Check if Device is Android 12 or less and log to use regular .send() self.passed_check = True self.send(silent, persistent, close_on_click) @@ -591,7 +594,11 @@ def setSound(self, res_sound_name): return set_sound(self.builder, res_sound_name) - def start_building(self, persistent=False, close_on_click=True, silent: bool = False): + def fill_args(self, silent: bool = False, persistent=False, close_on_click=True): + """Name Makes More sense than start_building""" + return self.start_building(silent, persistent , close_on_click) + + def start_building(self, silent: bool = False, persistent=False, close_on_click=True): # Main use is for foreground service, bypassing .notify in .send method to let service.startForeground(...) send it self.silent = silent or self.silent if not on_android_platform(): diff --git a/android_notify/tests/test_notification_permission.py b/android_notify/tests/test_notification_permission.py index 6b10fac..20ee106 100644 --- a/android_notify/tests/test_notification_permission.py +++ b/android_notify/tests/test_notification_permission.py @@ -1,5 +1,3 @@ -# android_notify/tests/basic_notification_actions.py - from android_notify import NotificationHandler from android_notify.internal.permissions import ask_notification_permission from android_notify.core import asks_permission_if_needed