From e88084043db279190df59c84e4b1796d750101b3 Mon Sep 17 00:00:00 2001 From: Samartha K V Date: Sat, 16 Dec 2023 11:29:04 -0500 Subject: [PATCH 1/2] Fix button setColor * Move setBackground into setDrawable method * Add new method to set Button tint * Remove hardcoded path in gradle.properties * Update gitignore --- .gitignore | 2 +- ...roidx_arch_core_core_runtime_2_0_0_aar.xml | 12 ---- ...adle__androidx_core_core_ktx_1_2_0_aar.xml | 12 ---- ...eakcanary_leakcanary_android_2_9_1_aar.xml | 14 ----- ...nary_leakcanary_android_core_2_9_1_aar.xml | 15 ----- ...ary_leakcanary_android_utils_2_9_1_aar.xml | 14 ----- ...canary_leakcanary_object_watcher_2_9_1.xml | 13 ---- ...anary_object_watcher_android_2_9_1_aar.xml | 15 ----- ...ect_watcher_android_androidx_2_9_1_aar.xml | 14 ----- ..._object_watcher_android_core_2_9_1_aar.xml | 15 ----- ...er_android_support_fragments_2_9_1_aar.xml | 14 ----- ...e__com_squareup_leakcanary_shark_2_9_1.xml | 13 ---- ...quareup_leakcanary_shark_android_2_9_1.xml | 13 ---- ..._squareup_leakcanary_shark_graph_2_9_1.xml | 13 ---- ..._squareup_leakcanary_shark_hprof_2_9_1.xml | 13 ---- ...om_squareup_leakcanary_shark_log_2_9_1.xml | 13 ---- ..._jetbrains_kotlin_kotlin_stdlib_1_6_21.xml | 13 ---- ...ins_kotlin_kotlin_stdlib_common_1_6_21.xml | 13 ---- gradle.properties | 3 +- .../com/developer/kalert/KAlertDialog.java | 61 ++++++++++++------- 20 files changed, 40 insertions(+), 255 deletions(-) delete mode 100644 .idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml delete mode 100644 .idea/libraries/Gradle__androidx_core_core_ktx_1_2_0_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_core_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_utils_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_androidx_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_core_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_support_fragments_2_9_1_aar.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_shark_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_shark_android_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_shark_graph_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_shark_hprof_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__com_squareup_leakcanary_shark_log_2_9_1.xml delete mode 100644 .idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_6_21.xml delete mode 100644 .idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_6_21.xml diff --git a/.gitignore b/.gitignore index 32b1dd61..b2c8c080 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ output.json # IntelliJ *.iml -.idea/ +/.idea/ misc.xml deploymentTargetDropDown.xml render.experimental.xml diff --git a/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml b/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml deleted file mode 100644 index 806ea4b4..00000000 --- a/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__androidx_core_core_ktx_1_2_0_aar.xml b/.idea/libraries/Gradle__androidx_core_core_ktx_1_2_0_aar.xml deleted file mode 100644 index f14c928e..00000000 --- a/.idea/libraries/Gradle__androidx_core_core_ktx_1_2_0_aar.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_2_9_1_aar.xml deleted file mode 100644 index 0ef9a76f..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_2_9_1_aar.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_core_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_core_2_9_1_aar.xml deleted file mode 100644 index a1515135..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_core_2_9_1_aar.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_utils_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_utils_2_9_1_aar.xml deleted file mode 100644 index 0e5ed06f..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_android_utils_2_9_1_aar.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_2_9_1.xml deleted file mode 100644 index 57c70a1b..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_2_9_1_aar.xml deleted file mode 100644 index 288597e9..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_2_9_1_aar.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_androidx_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_androidx_2_9_1_aar.xml deleted file mode 100644 index 4af15e95..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_androidx_2_9_1_aar.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_core_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_core_2_9_1_aar.xml deleted file mode 100644 index 62da8b9b..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_core_2_9_1_aar.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_support_fragments_2_9_1_aar.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_support_fragments_2_9_1_aar.xml deleted file mode 100644 index 547d1dfc..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_leakcanary_object_watcher_android_support_fragments_2_9_1_aar.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_shark_2_9_1.xml deleted file mode 100644 index 7a67875a..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_android_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_shark_android_2_9_1.xml deleted file mode 100644 index 5bba0829..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_android_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_graph_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_shark_graph_2_9_1.xml deleted file mode 100644 index 49cbd8bc..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_graph_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_hprof_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_shark_hprof_2_9_1.xml deleted file mode 100644 index 586984c3..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_hprof_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_log_2_9_1.xml b/.idea/libraries/Gradle__com_squareup_leakcanary_shark_log_2_9_1.xml deleted file mode 100644 index 6d97df29..00000000 --- a/.idea/libraries/Gradle__com_squareup_leakcanary_shark_log_2_9_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_6_21.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_6_21.xml deleted file mode 100644 index e9f77dc3..00000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_6_21.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_6_21.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_6_21.xml deleted file mode 100644 index 5ea0bbf7..00000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_6_21.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e85f7ddf..4d28613c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,4 @@ android.useAndroidX=true android.defaults.buildfeatures.buildconfig=true android.nonTransitiveRClass=false android.nonFinalResIds=false -android.disableAutomaticComponentCreation=true -org.gradle.java.home=C\:\\Program Files\\Java\\jdk-11.0.12 \ No newline at end of file +android.disableAutomaticComponentCreation=true \ No newline at end of file diff --git a/library/src/main/java/com/developer/kalert/KAlertDialog.java b/library/src/main/java/com/developer/kalert/KAlertDialog.java index cf79d8f8..4fc0ce17 100644 --- a/library/src/main/java/com/developer/kalert/KAlertDialog.java +++ b/library/src/main/java/com/developer/kalert/KAlertDialog.java @@ -26,11 +26,13 @@ import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatButton; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; +import androidx.core.graphics.drawable.DrawableCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.load.DataSource; @@ -156,8 +158,8 @@ protected void onCreate(Bundle savedInstanceState) { setCancelText(mCancelText, cancelTextColor); setConfirmText(mConfirmText); setConfirmText(mConfirmText, confirmTextColor); - setConfirmButtonColor(mColor); - setCancelButtonColor(mCancelColor); + setConfirmButtonDrawable(mColor); + setCancelButtonDrawable(mCancelColor); //setButtonMatchingHeight(); changeAlertType(mAlertType, true); setInputFieldHint(mInputFieldHint); @@ -243,37 +245,37 @@ private void changeAlertType(int alertType, boolean fromCreate) { } switch (mAlertType) { case NORMAL_TYPE: - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case ERROR_TYPE: mErrorFrame.setVisibility(View.VISIBLE); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case SUCCESS_TYPE: mSuccessFrame.setVisibility(View.VISIBLE); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case WARNING_TYPE: mWarningFrame.setVisibility(View.VISIBLE); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case CUSTOM_IMAGE_TYPE: setCustomImage1(mCustomImgDrawable); setCustomImageColorFilter(drawableColor); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case URL_IMAGE_TYPE: setURLImage1(imageURL, displayType); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case PROGRESS_TYPE: mProgressFrame.setVisibility(View.VISIBLE); mConfirmButton.setVisibility(GONE); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; case INPUT_TYPE: showInputView(); - setConfirmButtonColor(mColor); + setConfirmButtonDrawable(mColor); break; } if (!fromCreate) { @@ -695,7 +697,21 @@ public void cancel() { dismissWithAnimation(true); } - private KAlertDialog setConfirmButtonColor(Drawable background) { + private KAlertDialog setConfirmButtonColor(@ColorInt int tintColor) { + if (mConfirmButton != null) { + DrawableCompat.setTint(mConfirmButton.getBackground(), tintColor); + } + return this; + } + + private KAlertDialog setCancelButtonColor(@ColorInt int tintColor) { + if (mCancelButton != null) { + DrawableCompat.setTint(mCancelButton.getBackground(), tintColor); + } + return this; + } + + private KAlertDialog setConfirmButtonDrawable(Drawable background) { mColor = background; if (mConfirmButton != null && mColor != null) { mConfirmButton.setBackground(mColor); @@ -703,7 +719,7 @@ private KAlertDialog setConfirmButtonColor(Drawable background) { return this; } - private KAlertDialog setCancelButtonColor(Drawable background) { + private KAlertDialog setCancelButtonDrawable(Drawable background) { mCancelColor = background; if (mCancelButton != null && mCancelColor != null) { mCancelButton.setBackground(mCancelColor); @@ -807,21 +823,20 @@ public KAlertDialog setConfirmText(String text, int color) { return this; } - public KAlertDialog confirmButtonColor(int color) { - //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return setConfirmButtonColor(ContextCompat.getDrawable(context, color)); - //}else { - //return setConfirmButtonColor(ContextCompat.getDrawable(context, color)); - //} + return setConfirmButtonColor(color); + } + + public KAlertDialog confirmButtonDrawable(int drawableResId) { + return setConfirmButtonDrawable(ContextCompat.getDrawable(context, drawableResId)); } public KAlertDialog cancelButtonColor(int color) { - //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return setCancelButtonColor(ContextCompat.getDrawable(context, color)); - //}else { - //return setCancelButtonColor(getContext().getResources().getDrawable(color)); - //} + return setCancelButtonColor(color); + } + + public KAlertDialog cancelButtonDrawable(int drawableResId) { + return setCancelButtonDrawable(ContextCompat.getDrawable(context, drawableResId)); } public KAlertDialog setTitleColor(int color) { From e264b77b296677b545532a20254fa893505eedaa Mon Sep 17 00:00:00 2001 From: Samartha K V Date: Sat, 16 Dec 2023 11:34:01 -0500 Subject: [PATCH 2/2] Fix variable names --- .../com/developer/kalert/KAlertDialog.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/library/src/main/java/com/developer/kalert/KAlertDialog.java b/library/src/main/java/com/developer/kalert/KAlertDialog.java index 4fc0ce17..84248df1 100644 --- a/library/src/main/java/com/developer/kalert/KAlertDialog.java +++ b/library/src/main/java/com/developer/kalert/KAlertDialog.java @@ -56,7 +56,7 @@ public class KAlertDialog extends AlertDialog implements View.OnClickListener { private ImageView mErrorX, mSuccessTick, mCustomImage, mCustomBigImage; private Drawable mCustomImgDrawable; private AppCompatButton mConfirmButton, mCancelButton; - private Drawable mColor, mCancelColor; + private Drawable mConfirmButtonDrawable, mCancelButtonDrawable; private View mDialogView; private FrameLayout mCustomViewContainer; //private ViewTreeObserver mCancelButtonObserver, mConfirmButtonObserver; @@ -158,8 +158,8 @@ protected void onCreate(Bundle savedInstanceState) { setCancelText(mCancelText, cancelTextColor); setConfirmText(mConfirmText); setConfirmText(mConfirmText, confirmTextColor); - setConfirmButtonDrawable(mColor); - setCancelButtonDrawable(mCancelColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); + setCancelButtonDrawable(mCancelButtonDrawable); //setButtonMatchingHeight(); changeAlertType(mAlertType, true); setInputFieldHint(mInputFieldHint); @@ -245,37 +245,37 @@ private void changeAlertType(int alertType, boolean fromCreate) { } switch (mAlertType) { case NORMAL_TYPE: - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case ERROR_TYPE: mErrorFrame.setVisibility(View.VISIBLE); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case SUCCESS_TYPE: mSuccessFrame.setVisibility(View.VISIBLE); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case WARNING_TYPE: mWarningFrame.setVisibility(View.VISIBLE); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case CUSTOM_IMAGE_TYPE: setCustomImage1(mCustomImgDrawable); setCustomImageColorFilter(drawableColor); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case URL_IMAGE_TYPE: setURLImage1(imageURL, displayType); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case PROGRESS_TYPE: mProgressFrame.setVisibility(View.VISIBLE); mConfirmButton.setVisibility(GONE); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; case INPUT_TYPE: showInputView(); - setConfirmButtonDrawable(mColor); + setConfirmButtonDrawable(mConfirmButtonDrawable); break; } if (!fromCreate) { @@ -712,17 +712,17 @@ private KAlertDialog setCancelButtonColor(@ColorInt int tintColor) { } private KAlertDialog setConfirmButtonDrawable(Drawable background) { - mColor = background; - if (mConfirmButton != null && mColor != null) { - mConfirmButton.setBackground(mColor); + mConfirmButtonDrawable = background; + if (mConfirmButton != null && mConfirmButtonDrawable != null) { + mConfirmButton.setBackground(mConfirmButtonDrawable); } return this; } private KAlertDialog setCancelButtonDrawable(Drawable background) { - mCancelColor = background; - if (mCancelButton != null && mCancelColor != null) { - mCancelButton.setBackground(mCancelColor); + mCancelButtonDrawable = background; + if (mCancelButton != null && mCancelButtonDrawable != null) { + mCancelButton.setBackground(mCancelButtonDrawable); } return this; }