android-notify 1.52.2__py3-none-any.whl → 1.52.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of android-notify might be problematic. Click here for more details.
- android_notify/sword.py +145 -118
- {android_notify-1.52.2.dist-info → android_notify-1.52.4.dist-info}/METADATA +1 -1
- {android_notify-1.52.2.dist-info → android_notify-1.52.4.dist-info}/RECORD +5 -5
- {android_notify-1.52.2.dist-info → android_notify-1.52.4.dist-info}/WHEEL +0 -0
- {android_notify-1.52.2.dist-info → android_notify-1.52.4.dist-info}/top_level.txt +0 -0
android_notify/sword.py
CHANGED
|
@@ -4,6 +4,7 @@ import traceback
|
|
|
4
4
|
import os
|
|
5
5
|
import threading
|
|
6
6
|
import re
|
|
7
|
+
import time
|
|
7
8
|
from .styles import NotificationStyles
|
|
8
9
|
|
|
9
10
|
DEV=0
|
|
@@ -36,7 +37,7 @@ except Exception as e:# pylint: disable=W0718
|
|
|
36
37
|
def run_on_ui_thread(func):
|
|
37
38
|
"""Fallback for Developing on PC"""
|
|
38
39
|
def wrapper(*args, **kwargs):
|
|
39
|
-
print("Simulating run on UI thread")
|
|
40
|
+
# print("Simulating run on UI thread")
|
|
40
41
|
return func(*args, **kwargs)
|
|
41
42
|
return wrapper
|
|
42
43
|
|
|
@@ -116,7 +117,7 @@ class Notification:
|
|
|
116
117
|
# if key not in non_string_keys: value = str(value) to fix
|
|
117
118
|
#non_string_keys=['progress_max_value','progress_current_value','callback','logs']
|
|
118
119
|
# TODO using default values to check types
|
|
119
|
-
|
|
120
|
+
|
|
120
121
|
# During Development (When running on PC)
|
|
121
122
|
logs=not ON_ANDROID
|
|
122
123
|
def __init__(self,**kwargs):
|
|
@@ -143,6 +144,7 @@ class Notification:
|
|
|
143
144
|
# Private (Don't Touch)
|
|
144
145
|
self.__id = self.__getUniqueID()
|
|
145
146
|
self.__setArgs(kwargs)
|
|
147
|
+
self.__update_timer = None # To Track progressbar last update (According to Android Docs Don't update bar to often, I also faced so issues when doing that)
|
|
146
148
|
|
|
147
149
|
if not ON_ANDROID:
|
|
148
150
|
return
|
|
@@ -157,11 +159,11 @@ class Notification:
|
|
|
157
159
|
Args:
|
|
158
160
|
new_title (str): New Notification Title
|
|
159
161
|
"""
|
|
160
|
-
self.title=new_title
|
|
162
|
+
self.title=str(new_title)
|
|
161
163
|
if self.logs:
|
|
162
|
-
print(f'new notification title: {
|
|
164
|
+
print(f'new notification title: {self.title}')
|
|
163
165
|
if ON_ANDROID:
|
|
164
|
-
self.__builder.setContentTitle(
|
|
166
|
+
self.__builder.setContentTitle(String(self.title))
|
|
165
167
|
|
|
166
168
|
def updateMessage(self,new_message):
|
|
167
169
|
"""Changes Old Message
|
|
@@ -169,40 +171,59 @@ class Notification:
|
|
|
169
171
|
Args:
|
|
170
172
|
new_message (str): New Notification Message
|
|
171
173
|
"""
|
|
172
|
-
self.message=new_message
|
|
174
|
+
self.message=str(new_message)
|
|
173
175
|
if self.logs:
|
|
174
|
-
print(f'new notification message: {
|
|
176
|
+
print(f'new notification message: {self.message}')
|
|
175
177
|
if ON_ANDROID:
|
|
176
|
-
self.__builder.setContentText(
|
|
178
|
+
self.__builder.setContentText(String(self.message))
|
|
177
179
|
|
|
178
180
|
def updateProgressBar(self,current_value,message:str=''):
|
|
179
|
-
"""current_value is the value to set progressbar, message defaults to last message
|
|
181
|
+
"""current_value is the value to set progressbar, message defaults to last message
|
|
182
|
+
|
|
183
|
+
NOTE: There is a 0.5sec delay
|
|
184
|
+
"""
|
|
180
185
|
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
# Cancel any existing timer before setting a new one
|
|
187
|
+
if self.__update_timer:
|
|
188
|
+
return False
|
|
183
189
|
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
def delayed_update():
|
|
191
|
+
self.__update_timer = None
|
|
192
|
+
if self.logs:
|
|
193
|
+
print(f'Progress Bar Update value: {current_value}')
|
|
186
194
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
self.progress_current_value = current_value
|
|
196
|
+
|
|
197
|
+
if not ON_ANDROID:
|
|
198
|
+
return False
|
|
199
|
+
self.__builder.setProgress(self.progress_max_value, current_value, False)
|
|
200
|
+
if message:
|
|
201
|
+
self.updateMessage(message)
|
|
202
|
+
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
203
|
+
return True
|
|
191
204
|
|
|
205
|
+
# Start a new timer that runs after 0.5 seconds
|
|
206
|
+
self.__update_timer = threading.Timer(0.5, delayed_update)
|
|
207
|
+
self.__update_timer.start()
|
|
208
|
+
|
|
192
209
|
def removeProgressBar(self,message=''):
|
|
193
210
|
"""message defaults to last message"""
|
|
194
211
|
|
|
212
|
+
if self.__update_timer:
|
|
213
|
+
self.__update_timer.cancel()
|
|
214
|
+
self.__update_timer = None
|
|
215
|
+
|
|
195
216
|
if self.logs:
|
|
196
217
|
print(f'removed progress bar with message: {self.message}')
|
|
197
218
|
|
|
198
219
|
if not ON_ANDROID:
|
|
199
|
-
return
|
|
220
|
+
return False
|
|
200
221
|
|
|
201
222
|
if message:
|
|
202
223
|
self.__builder.setContentText(String(message))
|
|
203
|
-
return True
|
|
204
224
|
self.__builder.setProgress(0, 0, False)
|
|
205
225
|
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
226
|
+
return True
|
|
206
227
|
|
|
207
228
|
def send(self,silent:bool=False):
|
|
208
229
|
"""Sends notification
|
|
@@ -226,6 +247,101 @@ class Notification:
|
|
|
226
247
|
print(f'channel_name: {self.channel_name}, Channel ID: {self.channel_id}, id: {self.__id}')
|
|
227
248
|
print('Can\'t Send Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" for Documentation.\n' if DEV else '\n') # pylint: disable=C0301
|
|
228
249
|
|
|
250
|
+
def addButton(self, text:str,on_release):
|
|
251
|
+
"""For adding action buttons
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
text (str): Text For Button
|
|
255
|
+
"""
|
|
256
|
+
if self.logs:
|
|
257
|
+
print('Added Button: ', text)
|
|
258
|
+
|
|
259
|
+
if not ON_ANDROID:
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
btn_id= self.__getIDForButton()
|
|
263
|
+
action = f"BTN_ACTION_{btn_id}"
|
|
264
|
+
|
|
265
|
+
action_intent = Intent(context, PythonActivity)
|
|
266
|
+
action_intent.setAction(action)
|
|
267
|
+
action_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
268
|
+
bundle = Bundle()
|
|
269
|
+
bundle.putString("title", self.title or 'Title Placeholder')
|
|
270
|
+
bundle.putInt("key_int", 123)
|
|
271
|
+
action_intent.putExtras(bundle)
|
|
272
|
+
action_intent.putExtra("button_id", btn_id)
|
|
273
|
+
|
|
274
|
+
self.btns_box[action] = on_release
|
|
275
|
+
# action_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
276
|
+
|
|
277
|
+
if self.logs:
|
|
278
|
+
print('Button id: ',btn_id)
|
|
279
|
+
pending_action_intent = PendingIntent.getActivity(
|
|
280
|
+
context,
|
|
281
|
+
0,
|
|
282
|
+
action_intent,
|
|
283
|
+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
|
284
|
+
)
|
|
285
|
+
# Convert text to CharSequence
|
|
286
|
+
action_text = cast('java.lang.CharSequence', String(text))
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# Add action with proper types
|
|
291
|
+
self.__builder.addAction(
|
|
292
|
+
int(context.getApplicationInfo().icon), # Cast icon to int
|
|
293
|
+
action_text, # CharSequence text
|
|
294
|
+
pending_action_intent # PendingIntent
|
|
295
|
+
)
|
|
296
|
+
# Set content intent for notification tap
|
|
297
|
+
self.__builder.setContentIntent(pending_action_intent)
|
|
298
|
+
|
|
299
|
+
@run_on_ui_thread
|
|
300
|
+
def addNotificationStyle(self,style:str,already_sent=False):
|
|
301
|
+
"""Adds Style to Notification
|
|
302
|
+
Version 1.51.2+ Exposes method to Users (Note): Always try to Call On UI Thread
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
style (str): required style
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
if not ON_ANDROID:
|
|
309
|
+
# TODO for logs when not on android and style related to imgs etraxct app path from buildozer.spec and print
|
|
310
|
+
return False
|
|
311
|
+
|
|
312
|
+
if style == NotificationStyles.BIG_TEXT:
|
|
313
|
+
big_text_style = NotificationCompatBigTextStyle() # pylint: disable=E0606
|
|
314
|
+
big_text_style.bigText(str(self.body))
|
|
315
|
+
self.__builder.setStyle(big_text_style)
|
|
316
|
+
|
|
317
|
+
elif style == NotificationStyles.INBOX:
|
|
318
|
+
inbox_style = NotificationCompatInboxStyle() # pylint: disable=E0606
|
|
319
|
+
for line in self.message.split("\n"):
|
|
320
|
+
inbox_style.addLine(str(line))
|
|
321
|
+
self.__builder.setStyle(inbox_style)
|
|
322
|
+
|
|
323
|
+
elif (style == NotificationStyles.LARGE_ICON and self.large_icon_path) or (style == NotificationStyles.BIG_PICTURE and self.big_picture_path):
|
|
324
|
+
img = self.large_icon_path if style == NotificationStyles.LARGE_ICON else self.big_picture_path
|
|
325
|
+
self.__buildImg(img, style)
|
|
326
|
+
|
|
327
|
+
elif style == NotificationStyles.BOTH_IMGS and (self.big_picture_path or self.large_icon_path):
|
|
328
|
+
if self.big_picture_path:
|
|
329
|
+
self.__buildImg(self.big_picture_path, NotificationStyles.BIG_PICTURE)
|
|
330
|
+
if self.large_icon_path:
|
|
331
|
+
self.__buildImg(self.large_icon_path, NotificationStyles.LARGE_ICON)
|
|
332
|
+
|
|
333
|
+
elif style == NotificationStyles.PROGRESS:
|
|
334
|
+
self.__builder.setContentTitle(String(self.title))
|
|
335
|
+
self.__builder.setContentText(String(self.message))
|
|
336
|
+
self.__builder.setProgress(self.progress_max_value, self.progress_current_value, False)
|
|
337
|
+
|
|
338
|
+
if already_sent:
|
|
339
|
+
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
340
|
+
|
|
341
|
+
return True
|
|
342
|
+
# elif style == 'custom':
|
|
343
|
+
# self.__builder = self.__doCustomStyle()
|
|
344
|
+
|
|
229
345
|
def __validateArgs(self,inputted_kwargs):
|
|
230
346
|
|
|
231
347
|
def checkInReference(inputted_keywords,accepteable_inputs,input_type):
|
|
@@ -297,51 +413,7 @@ class Notification:
|
|
|
297
413
|
self.__builder.setPriority(NotificationCompat.PRIORITY_DEFAULT if self.silent else NotificationCompat.PRIORITY_HIGH)
|
|
298
414
|
self.__builder.setOnlyAlertOnce(True)
|
|
299
415
|
self.__addIntentToOpenApp()
|
|
300
|
-
|
|
301
|
-
def addNotificationStyle(self,style:str,already_sent=False):
|
|
302
|
-
"""Adds Style to Notification
|
|
303
|
-
Version 1.51.2+ Exposes method to Users (Note): Always try to Call On UI Thread
|
|
304
|
-
|
|
305
|
-
Args:
|
|
306
|
-
style (str): required style
|
|
307
|
-
"""
|
|
308
|
-
|
|
309
|
-
if not ON_ANDROID:
|
|
310
|
-
# TODO for logs when not on android and style related to imgs etraxct app path from buildozer.spec and print
|
|
311
|
-
return
|
|
312
|
-
|
|
313
|
-
if style == NotificationStyles.BIG_TEXT:
|
|
314
|
-
big_text_style = NotificationCompatBigTextStyle() # pylint: disable=E0606
|
|
315
|
-
big_text_style.bigText(str(self.body))
|
|
316
|
-
self.__builder.setStyle(big_text_style)
|
|
317
|
-
|
|
318
|
-
elif style == NotificationStyles.INBOX:
|
|
319
|
-
inbox_style = NotificationCompatInboxStyle() # pylint: disable=E0606
|
|
320
|
-
for line in self.message.split("\n"):
|
|
321
|
-
inbox_style.addLine(str(line))
|
|
322
|
-
self.__builder.setStyle(inbox_style)
|
|
323
|
-
|
|
324
|
-
elif (style == NotificationStyles.LARGE_ICON and self.large_icon_path) or (style == NotificationStyles.BIG_PICTURE and self.big_picture_path):
|
|
325
|
-
img = self.large_icon_path if style == NotificationStyles.LARGE_ICON else self.big_picture_path
|
|
326
|
-
self.__buildImg(img, style)
|
|
327
|
-
|
|
328
|
-
elif style == NotificationStyles.BOTH_IMGS and (self.big_picture_path or self.large_icon_path):
|
|
329
|
-
if self.big_picture_path:
|
|
330
|
-
self.__buildImg(self.big_picture_path, NotificationStyles.BIG_PICTURE)
|
|
331
|
-
if self.large_icon_path:
|
|
332
|
-
self.__buildImg(self.large_icon_path, NotificationStyles.LARGE_ICON)
|
|
333
|
-
|
|
334
|
-
elif style == NotificationStyles.PROGRESS:
|
|
335
|
-
self.__builder.setContentTitle(String(self.title))
|
|
336
|
-
self.__builder.setContentText(String(self.message))
|
|
337
|
-
self.__builder.setProgress(self.progress_max_value, self.progress_current_value, False)
|
|
338
|
-
|
|
339
|
-
if already_sent:
|
|
340
|
-
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
341
|
-
|
|
342
|
-
# elif style == 'custom':
|
|
343
|
-
# self.__builder = self.__doCustomStyle()
|
|
344
|
-
|
|
416
|
+
|
|
345
417
|
# def __doCustomStyle(self):
|
|
346
418
|
# # TODO Will implement when needed
|
|
347
419
|
# return self.__builder
|
|
@@ -357,7 +429,7 @@ class Notification:
|
|
|
357
429
|
bitmap = self.__getImgFromPath(user_img)
|
|
358
430
|
if bitmap:
|
|
359
431
|
self.__applyNotificationImage(bitmap,img_style)
|
|
360
|
-
|
|
432
|
+
|
|
361
433
|
|
|
362
434
|
def __getImgFromPath(self, relative_path):
|
|
363
435
|
app_folder=os.path.join(app_storage_path(),'app') # pylint: disable=possibly-used-before-assignment
|
|
@@ -372,7 +444,8 @@ class Notification:
|
|
|
372
444
|
return BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri))
|
|
373
445
|
|
|
374
446
|
def __getImgFromURL(self,url,img_style):
|
|
375
|
-
|
|
447
|
+
if self.logs:
|
|
448
|
+
print("getting image from URL---")
|
|
376
449
|
try:
|
|
377
450
|
URL = autoclass('java.net.URL')
|
|
378
451
|
url = URL(url)
|
|
@@ -389,7 +462,8 @@ class Notification:
|
|
|
389
462
|
|
|
390
463
|
@run_on_ui_thread
|
|
391
464
|
def __applyNotificationImage(self,bitmap,img_style):
|
|
392
|
-
|
|
465
|
+
if self.logs:
|
|
466
|
+
print('appying notification image-------')
|
|
393
467
|
try:
|
|
394
468
|
if img_style == NotificationStyles.BIG_PICTURE:
|
|
395
469
|
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap) # pylint: disable=E0606
|
|
@@ -397,9 +471,11 @@ class Notification:
|
|
|
397
471
|
elif img_style == NotificationStyles.LARGE_ICON:
|
|
398
472
|
self.__builder.setLargeIcon(bitmap)
|
|
399
473
|
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
400
|
-
|
|
474
|
+
if self.logs:
|
|
475
|
+
print('Done adding image to notification-------')
|
|
401
476
|
except Exception as e:
|
|
402
|
-
|
|
477
|
+
img = self.large_icon_path if img_style == NotificationStyles.LARGE_ICON else self.big_picture_path
|
|
478
|
+
print(f'Failed adding Image of style: {img_style} || From path: {img}, Exception {e}')
|
|
403
479
|
print('could stop get Img from URL ',traceback.format_exc())
|
|
404
480
|
|
|
405
481
|
def __getUniqueID(self):
|
|
@@ -464,55 +540,6 @@ class Notification:
|
|
|
464
540
|
self.button_ids.append(btn_id)
|
|
465
541
|
return btn_id
|
|
466
542
|
|
|
467
|
-
def addButton(self, text:str,on_release):
|
|
468
|
-
"""For adding action buttons
|
|
469
|
-
|
|
470
|
-
Args:
|
|
471
|
-
text (str): Text For Button
|
|
472
|
-
"""
|
|
473
|
-
if self.logs:
|
|
474
|
-
print('Added Button: ', text)
|
|
475
|
-
|
|
476
|
-
if not ON_ANDROID:
|
|
477
|
-
return
|
|
478
|
-
|
|
479
|
-
btn_id= self.__getIDForButton()
|
|
480
|
-
action = f"BTN_ACTION_{btn_id}"
|
|
481
|
-
|
|
482
|
-
action_intent = Intent(context, PythonActivity)
|
|
483
|
-
action_intent.setAction(action)
|
|
484
|
-
action_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
485
|
-
bundle = Bundle()
|
|
486
|
-
bundle.putString("title", self.title or 'Title Placeholder')
|
|
487
|
-
bundle.putInt("key_int", 123)
|
|
488
|
-
action_intent.putExtras(bundle)
|
|
489
|
-
action_intent.putExtra("button_id", btn_id)
|
|
490
|
-
|
|
491
|
-
self.btns_box[action] = on_release
|
|
492
|
-
# action_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
493
|
-
|
|
494
|
-
if self.logs:
|
|
495
|
-
print('Button id: ',btn_id)
|
|
496
|
-
pending_action_intent = PendingIntent.getActivity(
|
|
497
|
-
context,
|
|
498
|
-
0,
|
|
499
|
-
action_intent,
|
|
500
|
-
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
|
501
|
-
)
|
|
502
|
-
# Convert text to CharSequence
|
|
503
|
-
action_text = cast('java.lang.CharSequence', String(text))
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
# Add action with proper types
|
|
508
|
-
self.__builder.addAction(
|
|
509
|
-
int(context.getApplicationInfo().icon), # Cast icon to int
|
|
510
|
-
action_text, # CharSequence text
|
|
511
|
-
pending_action_intent # PendingIntent
|
|
512
|
-
)
|
|
513
|
-
# Set content intent for notification tap
|
|
514
|
-
self.__builder.setContentIntent(pending_action_intent)
|
|
515
|
-
|
|
516
543
|
|
|
517
544
|
class NotificationHandler:
|
|
518
545
|
"""For Notification Operations """
|
|
@@ -2,8 +2,8 @@ android_notify/__init__.py,sha256=lcLjyfegXgU7cyGhfSphAOBipXwemrVkdYy3mcF6X5Y,17
|
|
|
2
2
|
android_notify/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
android_notify/core.py,sha256=B3gOgbLGGI6tz-Q_T2wmk74oggOSDX0Qz4lqj00vaFo,6114
|
|
4
4
|
android_notify/styles.py,sha256=3olKruhAbTrk5OzuhDnk_Pgpv8XYk8dWFmr48Q9rQVk,352
|
|
5
|
-
android_notify/sword.py,sha256=
|
|
6
|
-
android_notify-1.52.
|
|
7
|
-
android_notify-1.52.
|
|
8
|
-
android_notify-1.52.
|
|
9
|
-
android_notify-1.52.
|
|
5
|
+
android_notify/sword.py,sha256=IDJfEQxVvVgrjGhcH65jIwisiqAmvF3Z5blU5Kr4DQM,27117
|
|
6
|
+
android_notify-1.52.4.dist-info/METADATA,sha256=Hhbta-Y5iqq-wq-MLpM-db0-kGarwrCPYLqkuYDSMCI,13445
|
|
7
|
+
android_notify-1.52.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
8
|
+
android_notify-1.52.4.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
|
|
9
|
+
android_notify-1.52.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|