diff --git a/materialyoucolor/utils/platform_utils.py b/materialyoucolor/utils/platform_utils.py index 6043f8a..0e84142 100644 --- a/materialyoucolor/utils/platform_utils.py +++ b/materialyoucolor/utils/platform_utils.py @@ -29,8 +29,9 @@ QuantizeCelebi = None autoclass = None +_is_android = "ANDROID_ARGUMENT" in os.environ -try: +if _is_android: from jnius import autoclass from android import mActivity @@ -38,8 +39,6 @@ BuildVERSION = autoclass("android.os.Build$VERSION") context = mActivity.getApplicationContext() WallpaperManager = autoclass("android.app.WallpaperManager").getInstance(mActivity) -except Exception: - pass try: from PIL import Image @@ -73,16 +72,6 @@ WALLPAPER_CACHE = {} -def _is_android() -> bool: - try: - from android import mActivity - - return True - except Exception as e: - pass - return False - - def save_and_resize_bitmap(drawable, path): CompressFormat = autoclass("android.graphics.Bitmap$CompressFormat") FileOutputStream = autoclass("java.io.FileOutputStream") @@ -217,11 +206,10 @@ def get_dynamic_scheme( ) -> DynamicScheme: logger = lambda message: message_logger(logger_head + " : " + message) - is_android = _is_android() selected_scheme = None selected_color = None - if is_android: + if _is_android: # For Android 12 and 12+ if BuildVERSION.SDK_INT >= 31: selected_scheme = _get_android_12_above( @@ -297,7 +285,7 @@ def get_dynamic_scheme( # TODO: Think about getting data from bitmap pixel_array = [ image_data[_] - for _ in range(0, pixel_len, dynamic_color_quality if not is_android else 1) + for _ in range(0, pixel_len, dynamic_color_quality if not _is_android else 1) ] logger( f"Created an array of pixels from a "