Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ColorpickerApp">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 9 additions & 8 deletions colorpicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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