From deb0d4eb94b8b48ba6012d54b45e0f433ed81618 Mon Sep 17 00:00:00 2001 From: ciuc Date: Sun, 10 Aug 2025 11:22:04 +0300 Subject: [PATCH] Small enhancement to allow to define a callback with which some obejct can be previewd with the selected color in real time. - also upgraded everything to work with latest android stuff --- app/build.gradle | 15 +++++++------- app/src/main/AndroidManifest.xml | 3 ++- build.gradle | 3 ++- colorpicker/build.gradle | 17 ++++++++-------- .../colorpicker/ColorPickerPopUp.java | 20 +++++++++++++++++++ .../colorpicker/IPreviewCallback.java | 15 ++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 4 ++-- 7 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 colorpicker/src/main/java/com/mrudultora/colorpicker/IPreviewCallback.java diff --git a/app/build.gradle b/app/build.gradle index 2b1a240..ee95304 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,14 @@ plugins { } android { - compileSdkVersion 30 + namespace "com.mrudultora.colorpickerapp" + compileSdk 36 buildToolsVersion "30.0.2" defaultConfig { applicationId "com.mrudultora.colorpickerapp" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 36 versionCode 1 versionName "1.0" @@ -26,11 +27,11 @@ android { dependencies { - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.appcompat:appcompat:1.7.1' + implementation 'com.google.android.material:material:1.12.0' + implementation 'androidx.constraintlayout:constraintlayout:2.2.1' implementation project(path: ':colorpicker') testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1d93640..3992b40 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.ColorpickerApp"> - + diff --git a/build.gradle b/build.gradle index 4d24be2..dc327b9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. + buildscript { repositories { google() jcenter() } dependencies { - classpath "com.android.tools.build:gradle:4.1.1" + classpath "com.android.tools.build:gradle:8.10.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/colorpicker/build.gradle b/colorpicker/build.gradle index 5b85112..8433ac9 100644 --- a/colorpicker/build.gradle +++ b/colorpicker/build.gradle @@ -3,14 +3,15 @@ plugins { } android { - compileSdkVersion 30 + namespace "com.mrudultora.colorpicker" + compileSdkVersion 36 buildToolsVersion "30.0.2" defaultConfig { minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" + targetSdkVersion 35 + versionCode 2 + versionName "1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -25,9 +26,9 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.appcompat:appcompat:1.7.1' + implementation 'com.google.android.material:material:1.12.0' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' } \ No newline at end of file diff --git a/colorpicker/src/main/java/com/mrudultora/colorpicker/ColorPickerPopUp.java b/colorpicker/src/main/java/com/mrudultora/colorpicker/ColorPickerPopUp.java index 60764e9..75c39d7 100644 --- a/colorpicker/src/main/java/com/mrudultora/colorpicker/ColorPickerPopUp.java +++ b/colorpicker/src/main/java/com/mrudultora/colorpicker/ColorPickerPopUp.java @@ -65,6 +65,7 @@ public class ColorPickerPopUp extends View implements ViewTreeObserver.OnGlobalL private int selectedColor = Integer.MAX_VALUE; private int alpha = 255; private float[] currentColorsHSV = new float[]{1f, 1f, 1f}; + private IPreviewCallback previewCallback; public interface OnPickColorListener { void onColorPicked(int color); @@ -178,7 +179,9 @@ public boolean onTouch(View view, MotionEvent motionEvent) { setSaturation(1f / colorPickerView.getMeasuredWidth() * x); setValue(1f - (1f / colorPickerView.getMeasuredHeight() * y)); moveCursorColorPicker(); + int color = getCurrentColor(); viewNewColor.setBackgroundColor(getCurrentColor()); + preview(color); return true; } else if (hueImageView != null && view == hueImageView && isRequiredMotionEvent(motionEvent)) { float y = motionEvent.getY(); @@ -195,7 +198,9 @@ public boolean onTouch(View view, MotionEvent motionEvent) { setHue(hue); colorPickerView.setHue(getHue()); + int color = getCurrentColor(); viewNewColor.setBackgroundColor(getCurrentColor()); + preview(color); moveCursorHue(); updateAlphaOverlay(); return true; @@ -213,6 +218,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) { selectedColor = this.alpha << 24 | getCurrentColor() & 0x00FFFFFF; moveCursorAlpha(); viewNewColor.setBackgroundColor(selectedColor); + preview(selectedColor); return true; } return false; @@ -407,6 +413,20 @@ public ColorPickerPopUp setOnPickColorListener(OnPickColorListener onPickColorLi return this; } + /** + * A callback which can do stuff, like preview the color in the real object + * @param previewCallback + */ + public ColorPickerPopUp setPreviewCallback(IPreviewCallback previewCallback) { + this.previewCallback = previewCallback; + return this; + } + + private void preview(int color) { + if (previewCallback != null) { + previewCallback.preview(color); + } + } /** * Sets whether to show Alpha Channel or not. * Default value is true. diff --git a/colorpicker/src/main/java/com/mrudultora/colorpicker/IPreviewCallback.java b/colorpicker/src/main/java/com/mrudultora/colorpicker/IPreviewCallback.java new file mode 100644 index 0000000..d57a7f4 --- /dev/null +++ b/colorpicker/src/main/java/com/mrudultora/colorpicker/IPreviewCallback.java @@ -0,0 +1,15 @@ +package com.mrudultora.colorpicker; + +/** + * Interface which marks a preview callback. + * The callback can do much more than preview, + * but its main purpose is to actually show a preview + * of the object to be colored on the screen. + */ +public interface IPreviewCallback { + /** + * callback method. + * @param selectedColor + */ + void preview(int selectedColor); +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 51cfb33..8c1a1a1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 29 20:58:56 IST 2021 +#Sun Aug 10 09:43:21 EEST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip