Skip to content

Commit

Permalink
Use mActivity provided by android
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos committed Dec 23, 2023
1 parent 2641325 commit da6ad14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions kivymd/toast/androidtoast.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def show_toast(self):
f"{platform.capitalize()} platform does not support Android Toast"
)

from android import mActivity
from android.runnable import run_on_ui_thread
from jnius import autoclass

activity = autoclass("org.kivy.android.PythonActivity").mActivity
Toast = autoclass("android.widget.Toast")
String = autoclass("java.lang.String")

Expand All @@ -77,6 +77,6 @@ def toast(text, length_long=False, gravity=0, y=0, x=0):
"""

duration = Toast.LENGTH_SHORT if length_long else Toast.LENGTH_LONG
t = Toast.makeText(activity, String(text), duration)
t = Toast.makeText(mActivity, String(text), duration)
t.setGravity(gravity, x, y)
t.show()
11 changes: 2 additions & 9 deletions kivymd/utils/get_wallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ def get_wallpaper(
if platform == "android":
try:
from jnius import autoclass, cast
from android import mActivity

PythonActivity = autoclass("org.kivy.android.PythonActivity")
CompressFormat = autoclass("android.graphics.Bitmap$CompressFormat")
FileOutputStream = autoclass("java.io.FileOutputStream")
CurrentActivity = cast(
"android.app.Activity", PythonActivity.mActivity
)
WallpaperManager = autoclass("android.app.WallpaperManager")
Context = cast(
"android.content.Context",
CurrentActivity.getApplicationContext(),
)

Context = mActivity.getApplicationContext()
mWallpaperManager = WallpaperManager.getInstance(Context)
mWallpaperManager.getBitmap().compress(
CompressFormat.PNG,
Expand Down

0 comments on commit da6ad14

Please sign in to comment.