Skip to content

Commit 8dce11e

Browse files
committed
sync IconClass, xmls, helper function and facade
1 parent 654e4ea commit 8dce11e

9 files changed

Lines changed: 69 additions & 15 deletions

File tree

android_notify/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from android_notify.config import get_python_activity, on_android_platform, get_python_activity_context
77
from android_notify.internal.permissions import has_notification_permission, ask_notification_permission
88
from android_notify.internal.java_classes import autoclass, BuildVersion, BitmapFactory, NotificationChannel, NotificationManagerCompat, NotificationCompat, NotificationCompatBuilder, \
9-
NotificationCompatBigTextStyle, NotificationCompatBigPictureStyle, NotificationCompatInboxStyle, IconCompat
9+
NotificationCompatBigTextStyle, NotificationCompatBigPictureStyle, NotificationCompatInboxStyle, IconClass
1010

1111

1212

@@ -61,7 +61,7 @@ def get_image_uri(relative_path):
6161
def get_icon_object(uri):
6262
context = get_python_activity_context()
6363
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri))
64-
return IconCompat.createWithBitmap(bitmap)
64+
return IconClass.createWithBitmap(bitmap)
6565

6666

6767
def insert_app_icon(builder, custom_icon_path):

android_notify/internal/facade.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,49 @@ class Uri:
106106
def __init__(self, package_name):
107107
logger.debug("FACADE_URI")
108108

109+
@classmethod
110+
def parse(cls, uri_string):
111+
logger.debug(f"[MOCK] Uri.parse called with uri_string={uri_string}")
112+
return cls
113+
114+
@classmethod
115+
def fromFile(cls, java_file):
116+
logger.debug(f"[MOCK] Uri.fromFile called with file={java_file}")
117+
return cls
118+
119+
120+
class AudioAttributes:
121+
CONTENT_TYPE_SONIFICATION = 4
122+
USAGE_NOTIFICATION = 5
123+
USAGE_ALARM = 4
124+
125+
126+
class AudioAttributesBuilder:
127+
def __init__(self):
128+
logger.debug("[MOCK] AudioAttributesBuilder initialized")
129+
130+
def setContentType(self, content_type):
131+
logger.debug(f"[MOCK] AudioAttributesBuilder.setContentType called with content_type={content_type}")
132+
return self
133+
134+
def setUsage(self, usage):
135+
logger.debug(f"[MOCK] AudioAttributesBuilder.setUsage called with usage={usage}")
136+
return self
137+
138+
def build(self):
139+
logger.debug("[MOCK] AudioAttributesBuilder.build called")
140+
return AudioAttributes()
141+
142+
143+
class File:
144+
def __init__(self, path):
145+
self.path = path
146+
logger.debug(f"[MOCK] File initialized with path={path}")
147+
148+
def getAbsolutePath(self):
149+
logger.debug(f"[MOCK] File.getAbsolutePath called, returning {self.path}")
150+
return self.path
151+
109152

110153
class NotificationManager:
111154
pass
@@ -146,10 +189,10 @@ def setVibrationPattern(self, list_of_numbers):
146189
logger.debug(f"[MOCK] NotificationChannel.setVibrationPattern called, list_of_numbers={list_of_numbers}")
147190

148191

149-
class IconCompat:
192+
class IconClass:
150193
@classmethod
151194
def createWithBitmap(cls, bitmap):
152-
logger.debug(f"[MOCK] IconCompat.createWithBitmap called with bitmap={bitmap}")
195+
logger.debug(f"[MOCK] IconClass.createWithBitmap called with bitmap={bitmap}")
153196

154197

155198
class Color:
@@ -402,6 +445,16 @@ def getPackageName():
402445
logger.debug("[MOCK] Context.getPackageName called")
403446
return None # TODO get package name from buildozer.spec file
404447

448+
@staticmethod
449+
def getExternalFilesDir(directory_type):
450+
logger.debug(f"[MOCK] Context.getExternalFilesDir called with type={directory_type}")
451+
return File("mock_external_files_dir")
452+
453+
@staticmethod
454+
def getExternalCacheDir():
455+
logger.debug("[MOCK] Context.getExternalCacheDir called")
456+
return File("mock_external_cache_dir")
457+
405458

406459
class PackageManager:
407460
@property

android_notify/internal/helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ def execute_callback(callback,arg, from_who="user"):
5454
else:
5555
callback()
5656
except Exception as on_permissions_result_callback_error:
57-
logger.exception(on_permissions_result_callback_error)
57+
logger.exception(on_permissions_result_callback_error)
58+
59+
def on_pydroid_app():
60+
return "ru.iiec.pydroid3" in os.path.dirname(os.path.abspath(__file__))

android_notify/internal/java_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def on_android_platform():
3737
Settings = autoclass("android.provider.Settings")
3838
Uri = autoclass("android.net.Uri")
3939
Manifest = autoclass('android.Manifest$permission')
40-
Color = autoclass('android.graphics.Color')
4140
Context = autoclass('android.content.Context')
41+
Color = autoclass('android.graphics.Color')
42+
IconClass = autoclass('androidx.core.graphics.drawable.IconCompat')
4243
except Exception as e:
4344
from .facade import *
4445
logger.exception("Didn't get Basic Java Classes")
@@ -48,7 +49,6 @@ def on_android_platform():
4849
NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
4950
NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
5051
NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
51-
IconCompat = autoclass('androidx.core.graphics.drawable.IconCompat')
5252

5353
# Notification Design
5454
NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')

android_notify/res/layout/an_colored_basic_large.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<TextView
88
android:id="@+id/title"
9-
style="@style/TextAppearance.Compat.Notification.Title"
109
android:layout_width="wrap_content"
1110
android:layout_height="0dp"
1211
android:layout_weight="1"

android_notify/res/layout/an_colored_basic_small.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<TextView
88
android:id="@+id/title"
9-
style="@style/TextAppearance.Compat.Notification.Title"
109
android:layout_width="wrap_content"
1110
android:layout_height="0dp"
1211
android:layout_weight="1"

android_notify/tests/flet/basic/src/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def get_image_uri(relative_path):
105105

106106
def get_icon_object(uri):
107107
BitmapFactory = autoclass('android.graphics.BitmapFactory')
108-
IconCompat = autoclass('androidx.core.graphics.drawable.IconCompat')
108+
IconClass = autoclass('android.graphics.drawable.Icon')
109109

110110
bitmap= BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri))
111-
return IconCompat.createWithBitmap(bitmap)
111+
return IconClass.createWithBitmap(bitmap)
112112

113113
def insert_app_icon(builder,custom_icon_path):
114114
if custom_icon_path:

android_notify/tests/flet/flet-working/src/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def get_image_uri(relative_path):
105105

106106
def get_icon_object(uri):
107107
BitmapFactory = autoclass('android.graphics.BitmapFactory')
108-
IconCompat = autoclass('androidx.core.graphics.drawable.IconCompat')
108+
IconClass = autoclass('android.graphics.drawable.Icon')
109109

110110
bitmap= BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri))
111-
return IconCompat.createWithBitmap(bitmap)
111+
return IconClass.createWithBitmap(bitmap)
112112

113113
def insert_app_icon(builder,custom_icon_path):
114114
if custom_icon_path:

android_notify/widgets/images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
from android_notify.config import app_storage_path, on_flet_app, on_android_platform, get_python_activity_context
7-
from android_notify.internal.java_classes import autoclass, BitmapFactory, Uri, BuildVersion, Color, IconCompat
7+
from android_notify.internal.java_classes import autoclass, BitmapFactory, Uri, BuildVersion, Color, IconClass
88
from android_notify.internal.helper import get_package_path
99
from android_notify.internal.logger import logger
1010

@@ -128,7 +128,7 @@ def set_small_icon_with_bitmap(bitmap, builder):
128128
logger.warning("Bitmap Insert as Icon Not available below Android 6")
129129
return False
130130
try:
131-
icon = IconCompat.createWithBitmap(bitmap)
131+
icon = IconClass.createWithBitmap(bitmap)
132132
builder.setSmallIcon(icon)
133133
return True
134134
except Exception as autoclass_icon_error:

0 commit comments

Comments
 (0)