From da6ad14d7fb5a40194ab8ed10062a927dffa9b0d Mon Sep 17 00:00:00 2001 From: Ansh Dadwal Date: Sat, 23 Dec 2023 11:42:16 +0530 Subject: [PATCH] Use `mActivity` provided by `android` --- kivymd/toast/androidtoast.py | 4 ++-- kivymd/utils/get_wallpaper.py | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/kivymd/toast/androidtoast.py b/kivymd/toast/androidtoast.py index 54c813bc3..1ab9b4e2e 100644 --- a/kivymd/toast/androidtoast.py +++ b/kivymd/toast/androidtoast.py @@ -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") @@ -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() diff --git a/kivymd/utils/get_wallpaper.py b/kivymd/utils/get_wallpaper.py index 76d6fb3d6..bc570df41 100644 --- a/kivymd/utils/get_wallpaper.py +++ b/kivymd/utils/get_wallpaper.py @@ -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,