android-notify 1.32.1__py3-none-any.whl → 1.40.1__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 CHANGED
@@ -67,6 +67,7 @@ class Notification:
67
67
  :param logs: Defaults to True
68
68
  """
69
69
  notification_ids=[]
70
+ button_ids=[]
70
71
  style_values=[
71
72
  '','simple',
72
73
  'progress','big_text',
@@ -80,7 +81,7 @@ class Notification:
80
81
  'style':'simple',
81
82
  'big_picture_path':'',
82
83
  'large_icon_path':'',
83
- 'progress_max_value': 100,
84
+ 'progress_max_value': 0,
84
85
  'progress_current_value': 0,
85
86
  'channel_name':'Default Channel',
86
87
  'channel_id':'default_channel',
@@ -97,22 +98,22 @@ class Notification:
97
98
  self.large_icon_path=''
98
99
  self.big_picture_path=''
99
100
  self.progress_current_value=0
100
- self.progress_max_value=100
101
+ self.progress_max_value=0
101
102
  # Advance Options
102
- self.channel_name=''
103
- self.channel_id=''
103
+ self.channel_name='Default Channel'
104
+ self.channel_id='default_channel'
104
105
  self.silent=False
105
106
  # During Dev on PC
106
107
  self.logs=self.logs
107
108
  # Private (Don't Touch)
108
109
  self.__id = self.__getUniqueID()
109
110
  self.__setArgs(kwargs)
110
- self.__builder=None
111
111
  if not ON_ANDROID:
112
112
  return
113
113
  # TODO make send method wait for __asks_permission_if_needed method
114
114
  self.__asks_permission_if_needed()
115
115
  self.notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
116
+ self.__builder=NotificationCompatBuilder(context, self.channel_id)# pylint: disable=E0606
116
117
 
117
118
  def updateTitle(self,new_title):
118
119
  """Changes Old Title
@@ -136,6 +137,11 @@ class Notification:
136
137
 
137
138
  def updateProgressBar(self,current_value,message:str=''):
138
139
  """message defaults to last message"""
140
+ if not ON_ANDROID:
141
+ return
142
+
143
+ if self.logs:
144
+ print(f'Progress Bar Update value: {current_value}')
139
145
  self.__builder.setProgress(self.progress_max_value, current_value, False)
140
146
  if message:
141
147
  self.__builder.setContentText(String(message))
@@ -159,16 +165,12 @@ class Notification:
159
165
  self.__startNotificationBuild()
160
166
  self.notification_manager.notify(self.__id, self.__builder.build())
161
167
  elif self.logs:
162
- print(f"""
163
- Dev Notification Properties:
164
- title: '{self.title}'
165
- message: '{self.message}'
166
- large_icon_path: '{self.large_icon_path}'
167
- big_picture_path: '{self.big_picture_path}'
168
- style: '{self.style}'
169
- Silent: '{self.silent}'
170
- (Won't Print Logs When Complied,except if selected `Notification.logs=True`
171
- """)
168
+ string_to_display=''
169
+ for name,value in vars(self).items():
170
+ if value and name not in ['logs','_Notification__id']:
171
+ string_to_display += f'\n {name}: {value}'
172
+ string_to_display +="\n (Won't Print Logs When Complied,except if selected `Notification.logs=True`)"
173
+ print(string_to_display)
172
174
  if DEV:
173
175
  print(f'channel_name: {self.channel_name}, Channel ID: {self.channel_id}, id: {self.__id}')
174
176
  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
@@ -202,14 +204,14 @@ class Notification:
202
204
 
203
205
  def __setArgs(self,options_dict:dict):
204
206
  for key,value in options_dict.items():
205
- if key == 'channel_name':
206
- setattr(self,key, value[:40] if value else self.defaults[key])
207
- elif key == 'channel_id' and value:
208
- setattr(self,key, self.__generate_channel_id(value) if value else self.defaults[key])
209
-
210
- setattr(self,key, value if value else self.defaults[key])
211
-
212
- if "channel_id" not in options_dict and 'channel_name' in options_dict:
207
+ if key == 'channel_name' and value.strip():
208
+ setattr(self,key, value[:40])
209
+ elif key == 'channel_id' and value.strip(): # If user input's a channel id (i format properly)
210
+ setattr(self,key, self.__generate_channel_id(value))
211
+ else:
212
+ setattr(self,key, value if value else self.defaults[key])
213
+
214
+ if "channel_id" not in options_dict and 'channel_name' in options_dict: # if User doesn't input channel id but inputs channel_name
213
215
  setattr(self,'channel_id', self.__generate_channel_id(options_dict['channel_name']))
214
216
 
215
217
  def __startNotificationBuild(self):
@@ -219,8 +221,10 @@ class Notification:
219
221
 
220
222
  def __createBasicNotification(self):
221
223
  # Notification Channel (Required for Android 8.0+)
224
+ # print("THis is cchannel is ",self.channel_id) #"BLAH"
222
225
  if BuildVersion.SDK_INT >= 26 and self.notification_manager.getNotificationChannel(self.channel_id) is None:
223
226
  importance=NotificationManagerCompat.IMPORTANCE_DEFAULT if self.silent else NotificationManagerCompat.IMPORTANCE_HIGH # pylint: disable=possibly-used-before-assignment
227
+ # importance = 3 or 4
224
228
  channel = NotificationChannel(
225
229
  self.channel_id,
226
230
  self.channel_name,
@@ -229,14 +233,13 @@ class Notification:
229
233
  self.notification_manager.createNotificationChannel(channel)
230
234
 
231
235
  # Build the notification
232
- self.__builder = NotificationCompatBuilder(context, self.channel_id)# pylint: disable=E0606
236
+ # self.__builder = NotificationCompatBuilder(context, self.channel_id)# pylint: disable=E0606
233
237
  self.__builder.setContentTitle(self.title)
234
238
  self.__builder.setContentText(self.message)
235
239
  self.__builder.setSmallIcon(context.getApplicationInfo().icon)
236
240
  self.__builder.setDefaults(NotificationCompat.DEFAULT_ALL) # pylint: disable=E0606
237
- if not self.silent:
238
- self.__builder.setPriority(NotificationCompat.PRIORITY_DEFAULT if self.silent else NotificationCompat.PRIORITY_HIGH)
239
-
241
+ self.__builder.setPriority(NotificationCompat.PRIORITY_DEFAULT if self.silent else NotificationCompat.PRIORITY_HIGH)
242
+ self.__addIntentToOpenApp()
240
243
  def __addNotificationStyle(self):
241
244
  # pylint: disable=trailing-whitespace
242
245
 
@@ -298,7 +301,7 @@ class Notification:
298
301
  reasonable_amount_of_notifications=101
299
302
  notification_id = random.randint(1, reasonable_amount_of_notifications)
300
303
  while notification_id in self.notification_ids:
301
- notification_id = random.randint(1, 100)
304
+ notification_id = random.randint(1, reasonable_amount_of_notifications)
302
305
  self.notification_ids.append(notification_id)
303
306
  return notification_id
304
307
 
@@ -349,8 +352,66 @@ class Notification:
349
352
  # Remove leading/trailing underscores
350
353
  channel_id = channel_id.strip('_')
351
354
  return channel_id[:50]
355
+ def __addIntentToOpenApp(self):
356
+ intent = Intent(context, PythonActivity)
357
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP)
358
+ pending_intent = PendingIntent.getActivity(
359
+ context, 0,
360
+ intent, PendingIntent.FLAG_IMMUTABLE if BuildVersion.SDK_INT >= 31 else PendingIntent.FLAG_UPDATE_CURRENT
361
+ )
362
+ self.__builder.setContentIntent(pending_intent)
363
+ self.__builder.setAutoCancel(True)
364
+
365
+ def __getIDForButton(self):
366
+ reasonable_amount_of_notifications=101
367
+ btn_id = random.randint(1, reasonable_amount_of_notifications)
368
+ while btn_id in self.button_ids:
369
+ btn_id = random.randint(1, reasonable_amount_of_notifications)
370
+ self.button_ids.append(btn_id)
371
+ return str(btn_id)
372
+
373
+ def addButton(self, text:str,on_release):
374
+ """For adding action buttons
375
+
376
+ Args:
377
+ text (str): Text For Button
378
+ """
379
+ if not ON_ANDROID:
380
+ return
381
+
382
+ if self.logs:
383
+ print('Added Button: '+text)
384
+ action_intent = Intent(context, PythonActivity)
385
+ action_intent.setAction("ACTION "+ self.__getIDForButton())
386
+ pending_action_intent = PendingIntent.getActivity(
387
+ context,
388
+ 0,
389
+ action_intent,
390
+ PendingIntent.FLAG_IMMUTABLE
391
+ )
392
+ # Convert text to CharSequence
393
+ action_text = cast('java.lang.CharSequence', String(text))
394
+ # Add action with proper types
395
+ self.__builder.addAction(
396
+ int(context.getApplicationInfo().icon), # Cast icon to int
397
+ action_text, # CharSequence text
398
+ pending_action_intent # PendingIntent
399
+ )
400
+ # Set content intent for notification tap
401
+ self.__builder.setContentIntent(pending_action_intent)
402
+ # on_release()
403
+
404
+ # def buttonsListener():
405
+ # """Handle notification button clicks"""
406
+ # try:
407
+ # intent = context.getIntent()
408
+ # action = context.getAction()
409
+ # print("The Action --> ",action)
410
+ # intent.setAction("")
411
+ # context.setIntent(intent)
412
+ # except Exception as e:
413
+ # print("Catching Intents Error ",e)
352
414
 
353
- # try:
354
415
  # notify=Notification(titl='My Title',channel_name='Go')#,logs=False)
355
416
  # # notify.channel_name='Downloads'
356
417
  # notify.message="Blah"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: android-notify
3
- Version: 1.32.1
3
+ Version: 1.40.1
4
4
  Summary: A Python package that simpilfies creating Android notifications in Kivy apps.
5
5
  Home-page: https://github.com/fector101/android-notify
6
6
  Author: Fabian
@@ -33,7 +33,7 @@ Requires-Dist: pyjnius>=1.4.2
33
33
 
34
34
  ## Features
35
35
 
36
- - Compatible with Android 8.0+.
36
+ - Also Compatible with Android 8.0+.
37
37
  - Supports including images in notifications.
38
38
  - Support for multiple notification styles:
39
39
  - [Simple](#basic-usage)
@@ -41,6 +41,7 @@ Requires-Dist: pyjnius>=1.4.2
41
41
  - [Big Picture](#notification-with-an-image-big-picture-style)
42
42
  - [Inbox](#inbox-notification-style)
43
43
  - [Large Icon](#notification-with-an-image-large-icon-style)
44
+ - [Buttons](#notification-with-buttons)
44
45
  - [Big Text](#big-text-notification-will-display-as-simple-text-if-device-dosent-support)
45
46
 
46
47
  This module automatically handles:
@@ -112,7 +113,8 @@ The library supports multiple notification styles:
112
113
  #### Progress Bar notification
113
114
 
114
115
  ```python
115
- import time
116
+ from kivy.clock import Clock
117
+
116
118
  notification = Notification(
117
119
  title="Downloading...",
118
120
  message="0% downloaded",
@@ -121,8 +123,7 @@ notification = Notification(
121
123
  progress_current_value=0
122
124
  )
123
125
  notification.send()
124
- time.sleep(350)
125
- notification.updateProgressBar(30, "30% downloaded")
126
+ Clock.schedule_once(lambda dt: notification.updateProgressBar(30, "30% downloaded"), 350)
126
127
  ```
127
128
 
128
129
  **Sample Image:**
@@ -161,22 +162,12 @@ notification.send()
161
162
  **Sample Image:**
162
163
  ![Inbox Notification sample](https://raw.githubusercontent.com/Fector101/android_notify/main/docs/imgs/inboxnoti.jpg)
163
164
 
164
- #### Big text notification (Will Display as simple text if Device dosen't support)
165
-
166
- ```python
167
- notification = Notification(
168
- title="Article",
169
- message="Long article content...",
170
- style="big_text"
171
- )
172
- ```
173
-
174
165
  #### Notification with an Image (Large Icon Style)
175
166
 
176
167
  ```python
177
168
  notification = Notification(
178
- title="Completed download",
179
- message="profile.jpg",
169
+ title="FabianDev_",
170
+ message="A twitter about some programming stuff",
180
171
  style="large_icon",
181
172
  large_icon_path="assets/imgs/profile.png"
182
173
  )
@@ -186,6 +177,38 @@ notification = Notification(
186
177
  **Sample Image:**
187
178
  ![large_icon img sample](https://raw.githubusercontent.com/Fector101/android_notify/main/docs/imgs/large_icon.jpg)
188
179
 
180
+ #### Notification with Buttons
181
+
182
+ ```python
183
+ notification = Notification(title="Jane Dough", message="How to use android-notify #coding #purepython")
184
+ def playVideo():
185
+ print('Playing Video')
186
+
187
+ def turnOffNoti():
188
+ print('Please Turn OFf Noti')
189
+
190
+ def watchLater():
191
+ print('Add to Watch Later')
192
+
193
+ notification.addButton(text="Play",on_release=playVideo)
194
+ notification.addButton(text="Turn Off",on_release=turnOffNoti)
195
+ notification.addButton(text="Watch Later",on_release=watchLater)
196
+ notification.send()
197
+ ```
198
+
199
+ **Sample Image:**
200
+ ![btns img sample](https://raw.githubusercontent.com/Fector101/android_notify/main/docs/imgs/btns.jpg)
201
+
202
+ #### Big text notification (Will Display as normal text if Device dosen't support)
203
+
204
+ ```python
205
+ notification = Notification(
206
+ title="Article",
207
+ message="Long article content...",
208
+ style="big_text"
209
+ )
210
+ ```
211
+
189
212
  ## Advanced Features
190
213
 
191
214
  ### Updating Notifications
@@ -2,8 +2,8 @@ android_notify/__init__.py,sha256=dAcsj7M_KHBOira9AVk4LtFFXRHTYsn6tza4Oz7T1MM,10
2
2
  android_notify/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  android_notify/core.py,sha256=hHzBnVw25x_WpMHp_HPKCuHEL2mQ7IHC_I3EqQZylas,6081
4
4
  android_notify/styles.py,sha256=I2p31qStg9DaML9U4nXRvdpGzpppK6RS-qlDKuOv_Tk,328
5
- android_notify/sword.py,sha256=8v28Q9x3CRRa3xDbHUd8629S5KvLy7xnjSygbqT-coQ,16271
6
- android_notify-1.32.1.dist-info/METADATA,sha256=1d_YFS42LSiHBl8gy6OBxJnvwliX7f2Lhv4euoVFzy0,10425
7
- android_notify-1.32.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
- android_notify-1.32.1.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
9
- android_notify-1.32.1.dist-info/RECORD,,
5
+ android_notify/sword.py,sha256=Z74sBX5kJ5kRDQTw4fviDV42TynJhLf2cr87tiuH8oQ,19042
6
+ android_notify-1.40.1.dist-info/METADATA,sha256=xbGSDRLfhTy6UcG287MKglrArMzjRs1LQGmz12JbTV4,11161
7
+ android_notify-1.40.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ android_notify-1.40.1.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
9
+ android_notify-1.40.1.dist-info/RECORD,,