From ece309fbde3e65f1fc455e1fe016fac9c9859b38 Mon Sep 17 00:00:00 2001 From: aradxxx Date: Tue, 21 Oct 2025 21:40:34 +0400 Subject: [PATCH 1/2] Rename .java to .kt --- .../protect/card_locker/{UCropWrapper.java => UCropWrapper.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/protect/card_locker/{UCropWrapper.java => UCropWrapper.kt} (100%) diff --git a/app/src/main/java/protect/card_locker/UCropWrapper.java b/app/src/main/java/protect/card_locker/UCropWrapper.kt similarity index 100% rename from app/src/main/java/protect/card_locker/UCropWrapper.java rename to app/src/main/java/protect/card_locker/UCropWrapper.kt From 66646758a8a6d7b78252944649d6c78f1425d528 Mon Sep 17 00:00:00 2001 From: aradxxx Date: Tue, 21 Oct 2025 21:40:34 +0400 Subject: [PATCH 2/2] Convert UCropWrapper to kotlin --- .../java/protect/card_locker/UCropWrapper.kt | 187 ++++++++++-------- 1 file changed, 108 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/protect/card_locker/UCropWrapper.kt b/app/src/main/java/protect/card_locker/UCropWrapper.kt index 8a820e9da..caa326c76 100644 --- a/app/src/main/java/protect/card_locker/UCropWrapper.kt +++ b/app/src/main/java/protect/card_locker/UCropWrapper.kt @@ -1,93 +1,122 @@ -package protect.card_locker; +package protect.card_locker -import android.content.Intent; -import android.graphics.Color; -import android.graphics.Typeface; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.os.Bundle; -import android.view.View; -import android.view.Window; -import android.widget.FrameLayout; -import android.widget.LinearLayout; +import android.graphics.Color +import android.graphics.Typeface +import android.os.Build +import android.os.Bundle +import android.view.View +import android.widget.FrameLayout +import android.widget.LinearLayout +import androidx.appcompat.widget.AppCompatImageView +import androidx.core.content.ContextCompat +import androidx.core.graphics.ColorUtils +import androidx.core.view.WindowInsetsControllerCompat +import androidx.core.view.children +import com.google.android.material.color.MaterialColors +import com.google.android.material.textview.MaterialTextView +import com.yalantis.ucrop.UCropActivity -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.ColorUtils; -import androidx.core.view.WindowInsetsControllerCompat; +class UCropWrapper : UCropActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) -import com.google.android.material.color.MaterialColors; -import com.google.android.material.textview.MaterialTextView; -import com.yalantis.ucrop.UCropActivity; - -public class UCropWrapper extends UCropActivity { - public static final String UCROP_TOOLBAR_TYPEFACE_STYLE = "ucop_toolbar_typeface_style"; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Utils.applyWindowInsets(findViewById(android.R.id.content)); + Utils.applyWindowInsets(findViewById(android.R.id.content)) } - @Override - protected void onPostCreate(@Nullable Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - boolean darkMode = Utils.isDarkModeEnabled(this); - Window window = getWindow(); + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + val darkMode = Utils.isDarkModeEnabled(this) // setup status bar to look like the rest of the app - if (Build.VERSION.SDK_INT >= 23) { - if (window != null) { - View decorView = window.getDecorView(); - WindowInsetsControllerCompat wic = new WindowInsetsControllerCompat(window, decorView); - wic.setAppearanceLightStatusBars(!darkMode); - } - } else { - // icons are always white back then - if (window != null && !darkMode) { - window.setStatusBarColor(ColorUtils.compositeColors(Color.argb(127, 0, 0, 0), window.getStatusBarColor())); - } - } - + setupStatusBar(darkMode) // find and check views that we wish to color modify // for when we update ucrop or switch to another cropper - View check = findViewById(com.yalantis.ucrop.R.id.wrapper_controls); - if (check instanceof FrameLayout) { - FrameLayout controls = (FrameLayout) check; - check = findViewById(com.yalantis.ucrop.R.id.wrapper_states); - if (check instanceof LinearLayout) { - LinearLayout states = (LinearLayout) check; - for (int i = 0; i < controls.getChildCount(); i++) { - check = controls.getChildAt(i); - if (check instanceof AppCompatImageView) { - AppCompatImageView controlsBackgroundImage = (AppCompatImageView) check; - // everything gathered and are as expected, now perform color patching - Utils.patchColors(this); - int colorSurface = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, ContextCompat.getColor(this, R.color.md_theme_light_surface)); - int colorOnSurface = MaterialColors.getColor(this, com.google.android.material.R.attr.colorOnSurface, ContextCompat.getColor(this, R.color.md_theme_light_onSurface)); + checkViews(darkMode) + // change toolbar font + changeToolbarFont() + } - Drawable controlsBackgroundImageDrawable = controlsBackgroundImage.getBackground(); - controlsBackgroundImageDrawable.mutate(); - controlsBackgroundImageDrawable.setTint(darkMode ? colorOnSurface : colorSurface); - controlsBackgroundImage.setBackgroundDrawable(controlsBackgroundImageDrawable); - - states.setBackgroundColor(darkMode ? colorSurface : colorOnSurface); - break; - } - } - } + private fun setupStatusBar(darkMode: Boolean) { + if (window == null) { + return } - // change toolbar font - check = findViewById(com.yalantis.ucrop.R.id.toolbar_title); - if (check instanceof MaterialTextView) { - MaterialTextView toolbarTextview = (MaterialTextView) check; - Intent intent = getIntent(); - int style = intent.getIntExtra(UCROP_TOOLBAR_TYPEFACE_STYLE, -1); - if (style != -1) { - toolbarTextview.setTypeface(Typeface.defaultFromStyle(style)); - } + if (Build.VERSION.SDK_INT >= 23) { + val decorView = window.decorView + val wic = WindowInsetsControllerCompat(window, decorView) + wic.isAppearanceLightStatusBars = !darkMode + } else if (!darkMode) { + window.statusBarColor = ColorUtils.compositeColors( + Color.argb(127, 0, 0, 0), + window.statusBarColor + ) } } + + private fun checkViews(darkMode: Boolean) { + var view = findViewById(com.yalantis.ucrop.R.id.wrapper_controls) + if (view !is FrameLayout) { + return + } + + val controls = view + view = findViewById(com.yalantis.ucrop.R.id.wrapper_states) + if (view !is LinearLayout) { + return + } + val states = view + controls.children.firstOrNull { it is AppCompatImageView }?.let { + // everything gathered and are as expected, now perform color patching + Utils.patchColors(this) + val colorSurface = MaterialColors.getColor( + this, + com.google.android.material.R.attr.colorSurface, + ContextCompat.getColor( + this, + R.color.md_theme_light_surface + ) + ) + val colorOnSurface = MaterialColors.getColor( + this, + com.google.android.material.R.attr.colorOnSurface, + ContextCompat.getColor( + this, + R.color.md_theme_light_onSurface + ) + ) + + val controlsBackgroundImageDrawable = it.background + controlsBackgroundImageDrawable.mutate() + controlsBackgroundImageDrawable.setTint( + if (darkMode) { + colorOnSurface + } else { + colorSurface + } + ) + it.background = controlsBackgroundImageDrawable + states.setBackgroundColor( + if (darkMode) { + colorSurface + } else { + colorOnSurface + } + ) + } + } + + private fun changeToolbarFont() { + val toolbar = findViewById(com.yalantis.ucrop.R.id.toolbar_title) + if (toolbar !is MaterialTextView) { + return + } + + val style = intent.getIntExtra(UCROP_TOOLBAR_TYPEFACE_STYLE, -1) + if (style != -1) { + toolbar.setTypeface(Typeface.defaultFromStyle(style)) + } + } + + internal companion object { + const val UCROP_TOOLBAR_TYPEFACE_STYLE: String = "ucop_toolbar_typeface_style" + } }