diff --git a/.gitignore b/.gitignore
index 796b96d..fcdace8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
/build
+.idea/
+.gradle/
+local.properties
+*.iml
\ No newline at end of file
diff --git a/README.md b/README.md
index fa2027e..e54c3bc 100644
--- a/README.md
+++ b/README.md
@@ -7,11 +7,34 @@
A full featured Color picker Library for Android! Just like the one in Photoshop!
+# Differences from original repository
+
+* Posted on jitpack.io instead of jcenter
+* Added a "no color" option (transparent color value)
+* Original bitmap generation was prone to crashes, which are instead caught in this fork's source code
+* Original HuePicker, OpacityPicker and SatValPicker have memory leaks, which are fixed in this fork's code
+* For the above changes, HuePicker provides the method `setBitmapGenerationFailedListener` which listens for bitmap generation failure; ColorPickerDialog uses this listener to automatically reattempt reloading the bitmap every second while the dialog is still showing
+* Migrated from legacy support library to AndroidX AppCompat v1.1.0, leaving inflation of the correct Button classes to the implementations of this library
+* Changed pressed state of SatValPicker to accent color
+
+Other internal changes:
+* Library updates: Gradle wrapper 3.3 -> 6.2.1; Gradle build tools 2.2.0 -> 3.6.1; Maven gradle plugin 1.5 -> 2.0; Compile/Target Android SDK level 25 -> 29; Min Android SDK level 11 -> 14; Android build tools 23.0.3 -> 29.0.3
+* Switched from deprecated `compile` to `api` in build.gradle
+* Fixed spelling mistake `dialod_edit_color_root.xml`
+* Removed application declaration from manifest to prevent transitive changes
+* Added missing items to .gitignore
+* Standard Android Studio source code formatting
+* Minor refactoring inside `onInterceptTouchEvent` of ScrollViews
+* Removed redundant `minSizePx` variable from HuePicker and OpacityPicker
+* Moved content from mipmap-xxxhdpi folder to mipmap to avoid related crashes
+* Renamed OrientedSeekBar `orientation` attribute to `cp_orientation` to avoid conflicts with `androidx.gridlayout` library
+
# Features
* Hue bar - Adjust hue using a slider
* Saturation & Value Box - Select the color from the Saturation & Value Box (like in Photoshop)
* Alpha bar - Adjust the alpha using a slider
+* "No color" option - Hidden by default, sets transparent color value
* Preview - You can see the current selected and previously picked colors side-by-side
* Edit each component individually - You can edit Hue, Saturation, Value, Red, Green and Blue components individually
* Fully customizable - By default, there are two themes(Light and Dark). But you can define your own theme to customize the whole ColorPicker
@@ -28,7 +51,7 @@ The library is posted on jcenter. So, just the following code should be enough t
Place this in your app module's build.gradle file:
```groovy
dependencies {
- compile 'com.azeesoft.lib.colorpicker:colorpicker:1.0.8@aar'
+ implementation 'com.azeesoft.lib.colorpicker:colorpicker:1.1.0@aar'
}
```
If there is any error while building the project using the above mentioned step, add the following code in that build.gradle file and build again:
@@ -72,6 +95,7 @@ After successful build, you can use ColorPickerDialog as a part of your project.
* cp_showOpacityBar (boolean) : Show/Hide Opacity Bar
* cp_showHexaDecimalValue (boolean) : Show/Hide Hexadecimal Value
* cp_showColorComponentsInfo (boolean) : Show/Hide Color components information(HSV, RGB, Alpha)
+ * cp_showNoColorOption (boolean) : Show/Hide No Color button shortcut for transparent color value
* cp_backgroundColor (color) : Background color for the dialog
* cp_hexaDecimalTextColor (color) : Text color for the Hexadecimal value
* cp_colorComponentsTextColor (color) : Text color for the Color components information(HSV, RGB, Alpha)
diff --git a/build.gradle b/build.gradle
index 1309158..7866cdb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,16 +2,27 @@ apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
+buildscript {
+ repositories {
+ jcenter()
+ mavenCentral()
+ google()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.6.1'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
+ }
+}
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.1"
+ compileSdkVersion 29
+ buildToolsVersion "29.0.3"
defaultConfig {
- minSdkVersion 11
- targetSdkVersion 23
- versionCode 9
- versionName "1.0.9"
+ minSdkVersion 14
+ targetSdkVersion 29
+ versionCode 10
+ versionName "1.1.0"
}
buildTypes {
release {
@@ -19,17 +30,15 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
-
}
-version = '1.0.9'
+version = '1.1.0'
group = "com.azeesoft.lib.colorpicker"
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:23.1.1'
- compile 'com.android.support:design:23.1.1'
+ api fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation 'junit:junit:4.12'
+ api "androidx.appcompat:appcompat:1.1.0"
}
task sourcesJar(type: Jar) {
@@ -48,23 +57,29 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}
+repositories {
+ jcenter()
+ mavenCentral()
+ google()
+}
+
artifacts {
archives javadocJar
archives sourcesJar
}
bintray {
-user = 'azeesoft'
+ user = 'azeesoft'
key = '3d45a2cb273fea293793d6f337b755bb2e121cfa'
pkg {
repo = 'maven'
name = 'com.azeesoft.lib.colorpicker'
version {
- name = 'CP-1.0.9'
+ name = 'CP-1.1.0'
desc = "Added additional check for saving and loading last color"
released = new Date()
- vcsTag = '1.0.9'
+ vcsTag = '1.1.0'
}
licenses = ['Apache-2.0']
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..2d8d1e4
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1 @@
+android.useAndroidX=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..13372ae
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..7f4421a
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Mar 15 13:37:37 AEST 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..9d82f78
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..8a0b282
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 3e45f49..7255f0b 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -1,9 +1 @@
-
* A modified dialog that allows the users to edit the colors in HSV or RGB modes */ public class ColorEditDialog extends Dialog { - public static final int MODE_HSV=1,MODE_RGB=2; + public static final int MODE_HSV = 1, MODE_RGB = 2; - private AppCompatButton doneButton,cancelButton; - private TextView name1,name2,name3,suffix1,suffix2,suffix3; - private EditText val1,val2,val3; + private Button doneButton, cancelButton; + private TextView name1, name2, name3, suffix1, suffix2, suffix3; + private EditText val1, val2, val3; private RelativeLayout colorEditorRoot; private OnColorEditedListener onColorEditedListener; - private int eAlpha=255; + private int eAlpha = 255; public ColorEditDialog(Context context) { super(context); @@ -42,25 +42,25 @@ public ColorEditDialog(Context context, int themeResId) { init(context); } - private void init(Context context){ + private void init(Context context) { getWindow().requestFeature(Window.FEATURE_NO_TITLE); - setContentView(LayoutInflater.from(context).inflate(R.layout.dialod_edit_color_root, null)); + setContentView(LayoutInflater.from(context).inflate(R.layout.dialog_edit_color_root, null)); - colorEditorRoot=(RelativeLayout)findViewById(R.id.colorEditorRoot); + colorEditorRoot = (RelativeLayout) findViewById(R.id.colorEditorRoot); - doneButton=(AppCompatButton)findViewById(R.id.doneEditing); - cancelButton=(AppCompatButton)findViewById(R.id.cancelEditing); - name1=(TextView)findViewById(R.id.name1); - name2=(TextView)findViewById(R.id.name2); - name3=(TextView)findViewById(R.id.name3); - suffix1=(TextView)findViewById(R.id.suffix1); - suffix2=(TextView)findViewById(R.id.suffix2); - suffix3=(TextView)findViewById(R.id.suffix3); - val1=(EditText)findViewById(R.id.val1); - val2=(EditText)findViewById(R.id.val2); - val3=(EditText)findViewById(R.id.val3); + doneButton = (Button) findViewById(R.id.doneEditing); + cancelButton = (Button) findViewById(R.id.cancelEditing); + name1 = (TextView) findViewById(R.id.name1); + name2 = (TextView) findViewById(R.id.name2); + name3 = (TextView) findViewById(R.id.name3); + suffix1 = (TextView) findViewById(R.id.suffix1); + suffix2 = (TextView) findViewById(R.id.suffix2); + suffix3 = (TextView) findViewById(R.id.suffix3); + val1 = (EditText) findViewById(R.id.val1); + val2 = (EditText) findViewById(R.id.val2); + val3 = (EditText) findViewById(R.id.val3); - setModeAndValues(MODE_HSV, "", "", "",255); + setModeAndValues(MODE_HSV, "", "", "", 255); cancelButton.setOnClickListener(new View.OnClickListener() { @Override @@ -70,11 +70,11 @@ public void onClick(View v) { }); } - public void setBackgroundColor(int color){ + public void setBackgroundColor(int color) { colorEditorRoot.setBackgroundColor(color); } - public void setFontColor(int color){ + public void setFontColor(int color) { name1.setTextColor(color); name2.setTextColor(color); name3.setTextColor(color); @@ -89,29 +89,30 @@ public void setFontColor(int color){ val3.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.SRC_ATOP); } - public void setDoneButtonColor(int color){ + public void setDoneButtonColor(int color) { doneButton.setTextColor(color); } - public void setCancelButtonColor(int color){ + public void setCancelButtonColor(int color) { cancelButton.setTextColor(color); } /** * Sets the Mode to either HSV or RGB and enters the current values - * @param mode MODE_HSV or MODE_RGB - * @param v1 value1 - Hue[0,360] or Red[0,255] - * @param v2 value2 - Sat[0,100] or Green[0,255] - * @param v3 value3 - Val[0,100] or Blue[0,255] + * + * @param mode MODE_HSV or MODE_RGB + * @param v1 value1 - Hue[0,360] or Red[0,255] + * @param v2 value2 - Sat[0,100] or Green[0,255] + * @param v3 value3 - Val[0,100] or Blue[0,255] * @param existingAlpha Alpha[0,255] */ - public void setModeAndValues(int mode,String v1,String v2,String v3,int existingAlpha){ - if(existingAlpha<0 || existingAlpha>255) - existingAlpha=255; + public void setModeAndValues(int mode, String v1, String v2, String v3, int existingAlpha) { + if (existingAlpha < 0 || existingAlpha > 255) + existingAlpha = 255; - eAlpha=existingAlpha; + eAlpha = existingAlpha; - if(mode==MODE_RGB){ + if (mode == MODE_RGB) { name1.setText("Red: "); name2.setText("Green: "); name3.setText("Blue: "); @@ -126,12 +127,12 @@ public void setModeAndValues(int mode,String v1,String v2,String v3,int existing @Override public void onClick(View v) { try { - int red=Integer.parseInt(val1.getText().toString()); - int green=Integer.parseInt(val2.getText().toString()); - int blue=Integer.parseInt(val3.getText().toString()); + int red = Integer.parseInt(val1.getText().toString()); + int green = Integer.parseInt(val2.getText().toString()); + int blue = Integer.parseInt(val3.getText().toString()); - if(red>=0 && red<=255 && green>=0 && green<=255 && blue>=0 && blue<=255){ - if(onColorEditedListener!=null){ + if (red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255) { + if (onColorEditedListener != null) { onColorEditedListener.onColorEdited(Color.argb(eAlpha, red, green, blue)); } @@ -143,10 +144,10 @@ public void onClick(View v) { e.printStackTrace(); } - Toast.makeText(getContext(),"Enter values between 0 and 255",Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "Enter values between 0 and 255", Toast.LENGTH_LONG).show(); } }); - }else{ + } else { name1.setText("Hue: "); name2.setText("Sat: "); name3.setText("Val: "); @@ -161,24 +162,24 @@ public void onClick(View v) { @Override public void onClick(View v) { try { - int hue=Integer.parseInt(val1.getText().toString()); - int sat=Integer.parseInt(val2.getText().toString()); - int val=Integer.parseInt(val3.getText().toString()); + int hue = Integer.parseInt(val1.getText().toString()); + int sat = Integer.parseInt(val2.getText().toString()); + int val = Integer.parseInt(val3.getText().toString()); - if(hue<0 || hue>360){ - Toast.makeText(getContext(),"Hue should be between 0"+"\u00b0"+" and 360"+"\u00b0",Toast.LENGTH_LONG).show(); + if (hue < 0 || hue > 360) { + Toast.makeText(getContext(), "Hue should be between 0" + "\u00b0" + " and 360" + "\u00b0", Toast.LENGTH_LONG).show(); return; } - if(sat<0 || sat>100 || val<0 || val>100){ - Toast.makeText(getContext(),"Sat and Val should be between 0% and 100%",Toast.LENGTH_LONG).show(); + if (sat < 0 || sat > 100 || val < 0 || val > 100) { + Toast.makeText(getContext(), "Sat and Val should be between 0% and 100%", Toast.LENGTH_LONG).show(); return; } - float[] hsv=new float[]{hue,(sat*1f)/100,(val*1f)/100}; + float[] hsv = new float[]{hue, (sat * 1f) / 100, (val * 1f) / 100}; - if(onColorEditedListener!=null){ - onColorEditedListener.onColorEdited(Color.HSVToColor(eAlpha,hsv)); + if (onColorEditedListener != null) { + onColorEditedListener.onColorEdited(Color.HSVToColor(eAlpha, hsv)); } dismiss(); @@ -187,7 +188,7 @@ public void onClick(View v) { } catch (NumberFormatException e) { e.printStackTrace(); - Toast.makeText(getContext(),"Enter numeric values",Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "Enter numeric values", Toast.LENGTH_LONG).show(); } } }); @@ -198,7 +199,7 @@ public void setOnColorEditedListener(OnColorEditedListener onColorEditedListener this.onColorEditedListener = onColorEditedListener; } - public interface OnColorEditedListener{ + public interface OnColorEditedListener { void onColorEdited(int color); } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatHorizontalScrollView.java b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatHorizontalScrollView.java index 774842e..c878d2d 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatHorizontalScrollView.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatHorizontalScrollView.java @@ -7,47 +7,45 @@ /** * Created by aziz titu2 on 2/10/2016. - *
+ * * Custom horizontal scrollview to wrap the ColorPickers in order to manage the TouchEvents efficiently - *
*
* To create custom themes, create a new style with any of the ColorPicker themes as parent and use the following attributes:
* cp_showOpacityBar: boolean
* cp_showHexaDecimalValue: boolean
* cp_showColorComponentsInfo: boolean
+ * cp_showNoColorOption: boolean
* cp_backgroundColor: color
* cp_hexaDecimalTextColor: color
* cp_colorComponentsTextColor: color
@@ -109,21 +112,22 @@ private ColorPickerDialog(Context context, int theme) {
* @param context Context
* @return Light themed ColorPickerDialog
*/
- public static ColorPickerDialog createColorPickerDialog(Context context){
- return new ColorPickerDialog(new ContextThemeWrapper(context,LIGHT_THEME), LIGHT_THEME);
+ public static ColorPickerDialog createColorPickerDialog(Context context) {
+ return new ColorPickerDialog(new ContextThemeWrapper(context, LIGHT_THEME), LIGHT_THEME);
}
/**
* Creates a Custom themed ColorPickerDialog
- *
+ *
* To create a light themed ColorPickerDialog, use ColorPickerDialog.createColorPickerDialog(context,ColorPickerDialog.LIGHT_THEME);
- *
+ *
* To create a dark themed ColorPickerDialog, use ColorPickerDialog.createColorPickerDialog(context,ColorPickerDialog.DARK_THEME);
- *
+ *
* To create custom themes, create a new style with any of the ColorPicker themes as parent and use the following attributes:
* cp_showOpacityBar: boolean
* cp_showHexaDecimalValue: boolean
* cp_showColorComponentsInfo: boolean
+ * cp_showNoColorOption: boolean
* cp_backgroundColor: color
* cp_hexaDecimalTextColor: color
* cp_colorComponentsTextColor: color
@@ -132,11 +136,11 @@ public static ColorPickerDialog createColorPickerDialog(Context context){
* cp_sliderThumbColor: color
*
* @param context Context
- * @param theme theme resId
+ * @param theme theme resId
* @return Custom themed ColorPickerDialog
*/
- public static ColorPickerDialog createColorPickerDialog(Context context,int theme){
- return new ColorPickerDialog(new ContextThemeWrapper(context,theme), theme);
+ public static ColorPickerDialog createColorPickerDialog(Context context, int theme) {
+ return new ColorPickerDialog(new ContextThemeWrapper(context, theme), theme);
}
@Override
@@ -144,7 +148,7 @@ public void show() {
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
super.show();
reloadLastColor();
- if(opacityPicker.getVisibility()!=View.VISIBLE)
+ if (opacityPicker.getVisibility() != View.VISIBLE)
opacityPicker.setProgress(255);
// init(getContext());
}
@@ -152,20 +156,20 @@ public void show() {
@Override
public void dismiss() {
super.dismiss();
- initColor=getLastColor(getContext());
- if(onClosedListener !=null){
+ initColor = getLastColor(getContext());
+ if (onClosedListener != null) {
onClosedListener.onClosed();
}
}
- private void init(final Context context){
+ private void init(final Context context) {
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- setContentView(LayoutInflater.from(context).inflate(R.layout.dialog_root, null));
+ setContentView(LayoutInflater.from(context).inflate(R.layout.dialog_color_picker_root, null));
setTitle("Pick a color");
- initColor=getLastColor(context);
+ initColor = getLastColor(context);
- colorEditDialog=new ColorEditDialog(context);
+ colorEditDialog = new ColorEditDialog(context);
colorEditDialog.setOnColorEditedListener(new ColorEditDialog.OnColorEditedListener() {
@Override
public void onColorEdited(int color) {
@@ -173,28 +177,27 @@ public void onColorEdited(int color) {
}
});
- huePicker=(HuePicker)findViewById(R.id.hueBar);
- opacityPicker=(OpacityPicker)findViewById(R.id.opacityBar);
- satValPicker=(SatValPicker)findViewById(R.id.satValBox);
- colorPreviewBox=(LinearLayout)findViewById(R.id.colorPreviewBox);
- oldColorPreviewBox=(LinearLayout)findViewById(R.id.oldColorPreviewBox);
- hexHolder=(RelativeLayout)findViewById(R.id.hexHolder);
- pickButton=(AppCompatButton)findViewById(R.id.pickButton);
- cancelButton=(AppCompatButton)findViewById(R.id.cancelButton);
- colorComponents=(RelativeLayout)findViewById(R.id.colorComponents);
- hsv=(RelativeLayout)findViewById(R.id.hsv);
- rgb=(RelativeLayout)findViewById(R.id.rgb);
- colorPickerRootView=(ColorPickerRootView)findViewById(R.id.colorPickerRoot);
- hexVal=(EditText)findViewById(R.id.hexVal);
-
+ huePicker = (HuePicker) findViewById(R.id.hueBar);
+ opacityPicker = (OpacityPicker) findViewById(R.id.opacityBar);
+ satValPicker = (SatValPicker) findViewById(R.id.satValBox);
+ colorPreviewBox = (LinearLayout) findViewById(R.id.colorPreviewBox);
+ oldColorPreviewBox = (LinearLayout) findViewById(R.id.oldColorPreviewBox);
+ hexHolder = (RelativeLayout) findViewById(R.id.hexHolder);
+ pickButton = (Button) findViewById(R.id.pickButton);
+ cancelButton = (Button) findViewById(R.id.cancelButton);
+ colorComponents = (RelativeLayout) findViewById(R.id.colorComponents);
+ hsv = (RelativeLayout) findViewById(R.id.hsv);
+ rgb = (RelativeLayout) findViewById(R.id.rgb);
+ colorPickerRootView = (ColorPickerRootView) findViewById(R.id.colorPickerRoot);
+ hexVal = (EditText) findViewById(R.id.hexVal);
- View hScrollView=findViewById(R.id.scrollView);
+ View hScrollView = findViewById(R.id.scrollView);
- if(hScrollView instanceof ColorPickerCompatScrollView)
- colorPickerCompatScrollView=(ColorPickerCompatScrollView)hScrollView;
- else if(hScrollView instanceof ColorPickerCompatHorizontalScrollView)
- colorPickerCompatHorizontalScrollView=(ColorPickerCompatHorizontalScrollView)hScrollView;
+ if (hScrollView instanceof ColorPickerCompatScrollView)
+ colorPickerCompatScrollView = (ColorPickerCompatScrollView) hScrollView;
+ else if (hScrollView instanceof ColorPickerCompatHorizontalScrollView)
+ colorPickerCompatHorizontalScrollView = (ColorPickerCompatHorizontalScrollView) hScrollView;
hexVal.setImeOptions(EditorInfo.IME_ACTION_GO);
hexVal.addTextChangedListener(new TextWatcher() {
@@ -219,16 +222,17 @@ public void afterTextChanged(Editable s) {
}
});
- hex=(TextView)findViewById(R.id.hex);
- hue=(TextView)findViewById(R.id.hue);
- sat=(TextView)findViewById(R.id.sat);
- val=(TextView)findViewById(R.id.val);
- red=(TextView)findViewById(R.id.red);
- green=(TextView)findViewById(R.id.green);
- blue=(TextView)findViewById(R.id.blue);
- alpha=(TextView)findViewById(R.id.alpha);
- hsvEditIcon=(ImageView)findViewById(R.id.hsvEditIcon);
- rgbEditIcon=(ImageView)findViewById(R.id.rgbEditIcon);
+ hex = (TextView) findViewById(R.id.hex);
+ hue = (TextView) findViewById(R.id.hue);
+ sat = (TextView) findViewById(R.id.sat);
+ val = (TextView) findViewById(R.id.val);
+ red = (TextView) findViewById(R.id.red);
+ green = (TextView) findViewById(R.id.green);
+ blue = (TextView) findViewById(R.id.blue);
+ alpha = (TextView) findViewById(R.id.alpha);
+ hsvEditIcon = (ImageView) findViewById(R.id.hsvEditIcon);
+ rgbEditIcon = (ImageView) findViewById(R.id.rgbEditIcon);
+ ivNoColor = (ImageView) findViewById(R.id.ivNoColor);
huePicker.setOnHuePickedListener(new HuePicker.OnHuePickedListener() {
@Override
@@ -237,6 +241,17 @@ public void onPicked(float hue) {
ColorPickerDialog.this.hue.setText("H: " + (int) hue + " \u00b0");
}
});
+ huePicker.setBitmapGenerationFailedListener(new HuePicker.BitmapGenerationFailedListener() {
+ @Override
+ public void onBitmapGenerationFailed() {
+ if (isShowing()) new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ huePicker.reloadBitmap();
+ }
+ }, 1000L);
+ }
+ });
huePicker.setMax(360);
huePicker.setProgress(0);
@@ -290,11 +305,11 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
try {
- String r=getPlainComponentValue(red.getText().toString());
- String g=getPlainComponentValue(green.getText().toString());
- String b=getPlainComponentValue(blue.getText().toString());
- int a=Integer.parseInt(getPlainComponentValue(alpha.getText().toString()));
- colorEditDialog.setModeAndValues(ColorEditDialog.MODE_RGB,r,g,b,a);
+ String r = getPlainComponentValue(red.getText().toString());
+ String g = getPlainComponentValue(green.getText().toString());
+ String b = getPlainComponentValue(blue.getText().toString());
+ int a = Integer.parseInt(getPlainComponentValue(alpha.getText().toString()));
+ colorEditDialog.setModeAndValues(ColorEditDialog.MODE_RGB, r, g, b, a);
colorEditDialog.show();
} catch (Exception e) {
e.printStackTrace();
@@ -322,60 +337,74 @@ public void onClick(View v) {
}
});
-// reloadLastColor();
+ ivNoColor.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (onColorPickedListener != null)
+ onColorPickedListener.onColorPicked(Color.TRANSPARENT, "#00ffffff");
+ dismiss();
+ }
+ });
+
+ //reloadLastColor();
applyTheme();
-
}
- private String getPlainComponentValue(String s){
- s=s.split(":",2)[1];
- s=s.replaceAll("%","");
- s=s.replaceAll("\u00b0","");
- return s.replaceAll(" ","");
+ private String getPlainComponentValue(String s) {
+ s = s.split(":", 2)[1];
+ s = s.replaceAll("%", "");
+ s = s.replaceAll("\u00b0", "");
+ return s.replaceAll(" ", "");
}
- private void hexValTyped(String s){
+ private void hexValTyped(String s) {
//System.out.println("Hexa typed: " + s);
try {
- int color=Color.parseColor("#"+s);
- if(opacityPicker.getVisibility()!=View.VISIBLE){
- if(s.length()==8){
- s=s.substring(2);
- color=Color.parseColor("#" + s);
+ int color = Color.parseColor("#" + s);
+ if (opacityPicker.getVisibility() != View.VISIBLE) {
+ if (s.length() == 8) {
+ s = s.substring(2);
+ color = Color.parseColor("#" + s);
}
}
- setCurrentColor(color,false);
+ setCurrentColor(color, false);
} catch (Exception e) {
e.printStackTrace();
}
}
- private void applyTheme(){
- if(colorPickerRootView.isFLAG_SHOW_HEX()){
+ private void applyTheme() {
+ if (colorPickerRootView.isFLAG_SHOW_HEX()) {
showHexaDecimalValue();
- }else{
+ } else {
hideHexaDecimalValue();
}
- if(colorPickerRootView.isFLAG_SHOW_COLOR_COMPS()){
+ if (colorPickerRootView.isFLAG_SHOW_COLOR_COMPS()) {
showColorComponentsInfo();
- }else{
+ } else {
hideColorComponentsInfo();
}
- int hexColor=colorPickerRootView.getFLAG_HEX_COLOR();
+ if (colorPickerRootView.isFLAG_SHOW_NO_COLOR_OPTION()) {
+ showNoColorOption();
+ } else {
+ hideNoColorOption();
+ }
+
+ int hexColor = colorPickerRootView.getFLAG_HEX_COLOR();
setHexaDecimalTextColor(hexColor);
- int compsColor=colorPickerRootView.getFLAG_COMPS_COLOR();
+ int compsColor = colorPickerRootView.getFLAG_COMPS_COLOR();
//System.out.println("CompsColor: " + compsColor);
setColorComponentsTextColor(compsColor);
- Drawable hsvIcon=getContext().getResources().getDrawable(R.drawable.ic_mode_edit_white_24dp);
- Drawable rgbIcon=getContext().getResources().getDrawable(R.drawable.ic_mode_edit_white_24dp);
- hsvEditIcon.setImageDrawable(Stools.tintDrawable(hsvIcon,compsColor));
- rgbEditIcon.setImageDrawable(Stools.tintDrawable(rgbIcon,compsColor));
+ Drawable hsvIcon = getContext().getResources().getDrawable(R.drawable.ic_mode_edit_white_24dp);
+ Drawable rgbIcon = getContext().getResources().getDrawable(R.drawable.ic_mode_edit_white_24dp);
+ hsvEditIcon.setImageDrawable(Stools.tintDrawable(hsvIcon, compsColor));
+ rgbEditIcon.setImageDrawable(Stools.tintDrawable(rgbIcon, compsColor));
setPositiveActionText(colorPickerRootView.getFLAG_POS_ACTION_TEXT());
setNegativeActionText(colorPickerRootView.getFLAG_NEG_ACTION_TEXT());
@@ -395,26 +424,26 @@ private void applyTheme(){
}
- private void reloadLastColor(){
+ private void reloadLastColor() {
reloadLastColor(initColor);
}
- private void reloadLastColor(int current_color){
- String lastHexVal=Stools.loadLastColor(getContext());
- if(lastHexVal!=null){
+ private void reloadLastColor(int current_color) {
+ String lastHexVal = Stools.loadLastColor(getContext());
+ if (lastHexVal != null) {
//System.out.println("LastColor: "+lastHexVal);
- int lastColor=Color.parseColor(lastHexVal);
+ int lastColor = Color.parseColor(lastHexVal);
oldColorPreviewBox.setBackgroundColor(lastColor);
}
setCurrentColor(current_color);
}
- private void setCurrentColor(int color){
+ private void setCurrentColor(int color) {
setCurrentColor(color, true);
}
- private void setCurrentColor(int color,boolean updateHexVal){
- float[] hsv=new float[3];
+ private void setCurrentColor(int color, boolean updateHexVal) {
+ float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
// huePicker.setCanUpdateHexVal(updateHexVal);
@@ -423,7 +452,7 @@ private void setCurrentColor(int color,boolean updateHexVal){
satValPicker.setSaturationAndValue(hsv[1], hsv[2], false);
- if(huePicker.getProgress()!=(int)hsv[0])
+ if (huePicker.getProgress() != (int) hsv[0])
huePicker.setProgress((int) hsv[0]);
else
satValPicker.refreshSatValPicker(huePicker.getProgress());
@@ -432,22 +461,22 @@ private void setCurrentColor(int color,boolean updateHexVal){
opacityPicker.setProgress(Color.alpha(color));
}
- private void refreshPreviewBox(int color,int opacity,boolean updateHexVal){
- color= Color.argb(opacity, Color.red(color), Color.green(color), Color.blue(color));
+ private void refreshPreviewBox(int color, int opacity, boolean updateHexVal) {
+ color = Color.argb(opacity, Color.red(color), Color.green(color), Color.blue(color));
colorPreviewBox.setBackgroundColor(color);
- mHexVal="#"+Integer.toHexString(color);
+ mHexVal = "#" + Integer.toHexString(color);
//System.out.println("Retrieved Color: " + color + " (#" + mHexVal + ")");
- mColor=color;
+ mColor = color;
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
sat.setText("S: " + (int) (hsv[1] * 100) + " %");
val.setText("V: " + (int) (hsv[2] * 100) + " %");
- if(updateHexVal)
+ if (updateHexVal)
setHexValText(mHexVal);
red.setText("R: " + Color.red(color));
@@ -456,29 +485,29 @@ private void refreshPreviewBox(int color,int opacity,boolean updateHexVal){
alpha.setText("A: " + Color.alpha(color));
}
- private void setHexValText(String s){
- s=s.replace("#","");
- skipHexValChange=true;
+ private void setHexValText(String s) {
+ s = s.replace("#", "");
+ skipHexValChange = true;
hexVal.setText(s);
}
/**
- * Register a callback to be invoked when the user picks a color by tapping the positive action
+ * Register a callback to be invoked when the user picks a color by tapping the positive action
*
* @param onColorPickedListener Listener to call when color is picked
*/
- public void setOnColorPickedListener(OnColorPickedListener onColorPickedListener){
- this.onColorPickedListener=onColorPickedListener;
+ public void setOnColorPickedListener(OnColorPickedListener onColorPickedListener) {
+ this.onColorPickedListener = onColorPickedListener;
}
/**
- * Register a callback to be invoked when the user closes the dialog
+ * Register a callback to be invoked when the user closes the dialog
*
* @param onClosedListener Listener to call when dialog is closed
*/
- public void setOnClosedListener(OnClosedListener onClosedListener){
+ public void setOnClosedListener(OnClosedListener onClosedListener) {
this.onClosedListener = onClosedListener;
}
@@ -489,7 +518,7 @@ public void setOnClosedListener(OnClosedListener onClosedListener){
* @param context Context
* @return Returns the last picked color as a hexadecimal String(Eg: #ff000000) or null if the last picked color doesn't exist
*/
- public static String getLastColorAsHexa(Context context){
+ public static String getLastColorAsHexa(Context context) {
return Stools.loadLastColor(context);
}
@@ -500,9 +529,9 @@ public static String getLastColorAsHexa(Context context){
* @param context Context
* @return Returns the last picked color or Transparent color if the last picked color doesn't exist
*/
- public static int getLastColor(Context context){
- String lastColorHex=Stools.loadLastColor(context);
- if(lastColorHex==null)
+ public static int getLastColor(Context context) {
+ String lastColorHex = Stools.loadLastColor(context);
+ if (lastColorHex == null)
return Color.parseColor("#00ffffff");
else
return Color.parseColor(lastColorHex);
@@ -510,26 +539,28 @@ public static int getLastColor(Context context){
/**
* Gets the currently selected color
+ *
* @return Returns the currently selected color in the ColorPicker
*/
- public int getCurrentColor(){
+ public int getCurrentColor() {
return mColor;
}
/**
* Gets the currently selected color as a String in hexadecimal form (Eg: #ff000000)
+ *
* @return Returns the currently selected color in the ColorPicker as a hexadecimal String (Eg: #ff000000)
*/
- public String getCurrentColorAsHexa(){
+ public String getCurrentColorAsHexa() {
return mHexVal;
}
/**
* Sets a pre-selected color in the ColorPicker when the dialog opens
*
- * @param color Hexadecimal String form of the color to be pre-selected in the ColorPicker when the dialog opens
+ * @param hexVal Hexadecimal String form of the color to be pre-selected in the ColorPicker when the dialog opens
*/
- public void setInitialColor(String hexVal){
+ public void setInitialColor(String hexVal) {
setInitialColor(Color.parseColor(hexVal));
}
@@ -539,8 +570,8 @@ public void setInitialColor(String hexVal){
*
* @param color Color to be pre-selected in the ColorPicker when the dialog opens
*/
- public void setInitialColor(int color){
- initColor=color;
+ public void setInitialColor(int color) {
+ initColor = color;
}
/**
@@ -548,8 +579,8 @@ public void setInitialColor(int color){
*
* @param color Color to be applied to the last color and current color in the ColorPicker
*/
- public void setLastColor(int color){
- setLastColor("#"+Integer.toHexString(color));
+ public void setLastColor(int color) {
+ setLastColor("#" + Integer.toHexString(color));
}
/**
@@ -557,67 +588,84 @@ public void setLastColor(int color){
*
* @param hexVal Hexadecimal String form of the color to be applied to the last color and current color in the ColorPicker
*/
- public void setLastColor(String hexVal){
+ public void setLastColor(String hexVal) {
Stools.saveLastColor(getContext(), hexVal);
- initColor=Color.parseColor(hexVal);
+ initColor = Color.parseColor(hexVal);
reloadLastColor();
}
/**
* Show the OpacityBar in the ColorPicker
*/
- public void showOpacityBar(){
+ public void showOpacityBar() {
opacityPicker.setVisibility(View.VISIBLE);
}
/**
* Hide the OpacityBar in the ColorPicker
*/
- public void hideOpacityBar(){
+ public void hideOpacityBar() {
opacityPicker.setVisibility(View.GONE);
+ alpha.setVisibility(View.GONE);
+ }
+
+ /**
+ * Show the no color (transparent) option in the ColorPicker
+ */
+ public void showNoColorOption() {
+ ivNoColor.setVisibility(View.VISIBLE);
+ }
+
+ /**
+ * Hide the no color (transparent) option in the ColorPicker
+ */
+ public void hideNoColorOption() {
+ ivNoColor.setVisibility(View.GONE);
}
/**
* Show the Hexadecimal value in the ColorPicker
*/
- public void showHexaDecimalValue(){
+ public void showHexaDecimalValue() {
hexHolder.setVisibility(View.VISIBLE);
}
/**
* Hide the Hexadecimal value in the ColorPicker
*/
- public void hideHexaDecimalValue(){
+ public void hideHexaDecimalValue() {
hexHolder.setVisibility(View.GONE);
}
/**
* Show the Color Components Information (Hue, Saturation, Value, Red, Gren, Blue, Alpha) in the ColorPicker
*/
- public void showColorComponentsInfo(){
+ public void showColorComponentsInfo() {
colorComponents.setVisibility(View.VISIBLE);
}
/**
* Hide the Color Components Information (Hue, Saturation, Value, Red, Gren, Blue, Alpha) in the ColorPicker
*/
- public void hideColorComponentsInfo(){
+ public void hideColorComponentsInfo() {
colorComponents.setVisibility(View.GONE);
}
/**
* Sets a Background color for the dialog
+ *
* @param color Color to use as background for the dialog
*/
- public void setBackgroundColor(int color){
+ public void setBackgroundColor(int color) {
colorPickerRootView.setBackgroundColor(color);
}
/**
* Sets the color of the hexadecimal value
+ *
* @param color Color to use for the hexadecimal value's text
*/
- public void setHexaDecimalTextColor(int color){
+ public void setHexaDecimalTextColor(int color) {
hex.setTextColor(color);
hexVal.setTextColor(color);
hexVal.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
@@ -625,9 +673,10 @@ public void setHexaDecimalTextColor(int color){
/**
* Sets the color of the Color components info
+ *
* @param color Color to use for the color components info's text
*/
- public void setColorComponentsTextColor(int color){
+ public void setColorComponentsTextColor(int color) {
hue.setTextColor(color);
sat.setTextColor(color);
val.setTextColor(color);
@@ -639,30 +688,34 @@ public void setColorComponentsTextColor(int color){
/**
* Sets the text value for the Positive action (Default is "Pick")
+ *
* @param s String to use as Positive action's text
*/
- public void setPositiveActionText(String s){
+ public void setPositiveActionText(String s) {
pickButton.setText(s);
}
/**
* Sets the color of the Positive action's text
+ *
* @param color Color to use for the Positive action's text
*/
- public void setPositiveActionTextColor(int color){
+ public void setPositiveActionTextColor(int color) {
pickButton.setTextColor(color);
}
/**
* Sets the text value for the Negative action (Default is "Cancel")
+ *
* @param s String to use as Negative action's text
*/
- public void setNegativeActionText(String s){
+ public void setNegativeActionText(String s) {
cancelButton.setText(s);
}
/**
* Sets the color of the Negative action's text
+ *
* @param color Color to use for the Negative action's text
*/
public void setNegativeActionTextColor(int color) {
@@ -671,14 +724,15 @@ public void setNegativeActionTextColor(int color) {
/**
* Sets the color of the Slider's thumb of both HuePicker and OpacityPicker
+ *
* @param color Color to use for the Slider's thumb of HuePicker and OpacityPicker
*/
- public void setSliderThumbColor(int color){
- Drawable hueThumbDrawable=getContext().getResources().getDrawable(R.drawable.slider_thumb);
- Drawable opacityThumbDrawable=getContext().getResources().getDrawable(R.drawable.slider_thumb);
+ public void setSliderThumbColor(int color) {
+ Drawable hueThumbDrawable = getContext().getResources().getDrawable(R.drawable.slider_thumb);
+ Drawable opacityThumbDrawable = getContext().getResources().getDrawable(R.drawable.slider_thumb);
- hueThumbDrawable=Stools.tintDrawable(hueThumbDrawable,color);
- opacityThumbDrawable=Stools.tintDrawable(opacityThumbDrawable,color);
+ hueThumbDrawable = Stools.tintDrawable(hueThumbDrawable, color);
+ opacityThumbDrawable = Stools.tintDrawable(opacityThumbDrawable, color);
huePicker.setThumb(hueThumbDrawable);
opacityPicker.setThumb(opacityThumbDrawable);
}
@@ -686,10 +740,11 @@ public void setSliderThumbColor(int color){
/**
* Interface definition for a callback to be invoked when the user picks a color by tapping the positive action
*/
- public interface OnColorPickedListener{
+ public interface OnColorPickedListener {
/**
* Called when the user picks a color by tapping the positive action
- * @param color Color picked by the user
+ *
+ * @param color Color picked by the user
* @param hexVal Color picked by the user in hexadecimal form
*/
void onColorPicked(int color, String hexVal);
diff --git a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerRootView.java b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerRootView.java
index 0891fe1..94d564c 100644
--- a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerRootView.java
+++ b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerRootView.java
@@ -15,7 +15,7 @@ public class ColorPickerRootView extends RelativeLayout {
private final int DEFAULT_TEXT_COLOR = Color.parseColor("#222222");
- private boolean FLAG_SHOW_HEX = true, FLAG_SHOW_COLOR_COMPS = true, FLAG_EDIT_HSV = true, FLAG_EDIT_RGB = true;
+ private boolean FLAG_SHOW_HEX = true, FLAG_SHOW_COLOR_COMPS = true, FLAG_SHOW_NO_COLOR_OPTION = false, FLAG_EDIT_HSV = true, FLAG_EDIT_RGB = true;
private int FLAG_HEX_COLOR, FLAG_COMPS_COLOR, FLAG_POSITIVE_COLOR, FLAG_NEGATIVE_COLOR, FLAG_SLIDER_THUMB_COLOR, FLAG_BACKGROUND_COLOR;
private String FLAG_POS_ACTION_TEXT = "PICK", FLAG_NEG_ACTION_TEXT = "CANCEL";
@@ -31,6 +31,7 @@ public ColorPickerRootView(Context context, AttributeSet attrs) {
try {
FLAG_SHOW_HEX = a.getBoolean(R.styleable.ColorPickerRootView_cp_showHexaDecimalValue, true);
FLAG_SHOW_COLOR_COMPS = a.getBoolean(R.styleable.ColorPickerRootView_cp_showColorComponentsInfo, true);
+ FLAG_SHOW_NO_COLOR_OPTION = a.getBoolean(R.styleable.ColorPickerRootView_cp_showNoColorOption, false);
FLAG_EDIT_HSV = a.getBoolean(R.styleable.ColorPickerRootView_cp_editHSV, true);
FLAG_EDIT_RGB = a.getBoolean(R.styleable.ColorPickerRootView_cp_editRGB, true);
FLAG_HEX_COLOR = a.getColor(R.styleable.ColorPickerRootView_cp_hexaDecimalTextColor, DEFAULT_TEXT_COLOR);
@@ -65,6 +66,10 @@ public boolean isFLAG_SHOW_COLOR_COMPS() {
return FLAG_SHOW_COLOR_COMPS;
}
+ public boolean isFLAG_SHOW_NO_COLOR_OPTION() {
+ return FLAG_SHOW_NO_COLOR_OPTION;
+ }
+
public int getFLAG_HEX_COLOR() {
return FLAG_HEX_COLOR;
}
diff --git a/src/main/java/com/azeesoft/lib/colorpicker/HuePicker.java b/src/main/java/com/azeesoft/lib/colorpicker/HuePicker.java
index 26811b2..66b7274 100644
--- a/src/main/java/com/azeesoft/lib/colorpicker/HuePicker.java
+++ b/src/main/java/com/azeesoft/lib/colorpicker/HuePicker.java
@@ -1,26 +1,28 @@
package com.azeesoft.lib.colorpicker;
import android.content.Context;
+import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
+import android.os.AsyncTask;
+import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.SeekBar;
+import java.lang.ref.WeakReference;
+
/**
* Created by aziz titu2 on 2/9/2016.
- *
+ *
* A modified {@link OrientedSeekBar} that draws the HueRange as its background
*/
public class HuePicker extends OrientedSeekBar {
- private static final int MIN_SIZE_DIP = 200;
- private boolean canUpdateHexVal=true;
+ private boolean canUpdateHexVal = true;
- private static int minSizePx;
private OnHuePickedListener onHuePickedListener;
-
- Context mContext;
+ private BitmapGenerationFailedListener bitmapGenerationFailedListener;
public HuePicker(Context context) {
super(context);
@@ -32,29 +34,26 @@ public HuePicker(Context context, AttributeSet attrs) {
init(context);
}
-
private void init(Context context) {
- minSizePx = (int) Stools.dipToPixels(context, MIN_SIZE_DIP);
- mContext = context;
// setThumb(mContext.getResources().getDrawable(R.drawable.thumb));
// measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED);
//System.out.println("Width1: " + getMeasuredWidth());
//System.out.println("Height1: " + getMeasuredHeight());
- ViewTreeObserver vto = getViewTreeObserver();
+ final ViewTreeObserver vto = getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
- HuePicker.this.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ } else {
+ getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
/*int width = HuePicker.this.getMeasuredWidth();
int height = HuePicker.this.getMeasuredHeight();
//System.out.println("Width2: " + width);
//System.out.println("Height2: " + height);*/
-
- if(orientation==ORIENTATION_HORIZONTAL)
- setProgressDrawable(new BitmapDrawable(BitmapsGenerator.getHueBitmap(getMeasuredWidth(), getMeasuredHeight())));
- else
- setProgressDrawable(new BitmapDrawable(BitmapsGenerator.getHueBitmap(getMeasuredHeight(), getMeasuredWidth())));
+ reloadBitmap();
}
});
@@ -75,19 +74,15 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});
-
-
}
-
- public void setHue(float hue){
+ public void setHue(float hue) {
if (onHuePickedListener != null)
onHuePickedListener.onPicked(hue);
}
-
- public void setOnHuePickedListener(OnHuePickedListener onHuePickedListener){
- this.onHuePickedListener=onHuePickedListener;
+ public void setOnHuePickedListener(OnHuePickedListener onHuePickedListener) {
+ this.onHuePickedListener = onHuePickedListener;
}
public boolean isCanUpdateHexVal() {
@@ -98,8 +93,47 @@ public void setCanUpdateHexVal(boolean canUpdateHexVal) {
this.canUpdateHexVal = canUpdateHexVal;
}
+ public void reloadBitmap() {
+ new HueChanger(getMeasuredWidth(), getMeasuredHeight()).execute();
+ }
+
+ public void setBitmapGenerationFailedListener(BitmapGenerationFailedListener listener) {
+ bitmapGenerationFailedListener = listener;
+ }
- public interface OnHuePickedListener{
+ public interface BitmapGenerationFailedListener {
+ void onBitmapGenerationFailed();
+ }
+
+ public interface OnHuePickedListener {
void onPicked(float hue);
}
+
+ private class HueChanger extends AsyncTask
* A modified {@link OrientedSeekBar} to select Opacity
*/
public class OpacityPicker extends OrientedSeekBar {
- private static final int MIN_SIZE_DIP = 200;
+ private boolean canUpdateHexVal = true;
- private static int minSizePx;
private OnOpacityPickedListener onOpacityPickedListener;
- private boolean canUpdateHexVal=true;
- Context mContext;
-
-
public OpacityPicker(Context context) {
super(context);
init(context);
@@ -35,9 +30,9 @@ public OpacityPicker(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OpacityPicker, 0, 0);
try {
- if(a.getBoolean(R.styleable.OpacityPicker_cp_showOpacityBar, true)){
+ if (a.getBoolean(R.styleable.OpacityPicker_cp_showOpacityBar, true)) {
setVisibility(View.VISIBLE);
- }else{
+ } else {
setVisibility(View.GONE);
}
} finally {
@@ -47,8 +42,6 @@ public OpacityPicker(Context context, AttributeSet attrs) {
private void init(Context context) {
- minSizePx = (int) Stools.dipToPixels(context, MIN_SIZE_DIP);
- mContext = context;
setMax(255);
// setThumb(mContext.getResources().getDrawable(R.drawable.thumb));
@@ -92,11 +85,11 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
- public void setOnOpacityPickedListener(OnOpacityPickedListener onOpacityPickedListener){
- this.onOpacityPickedListener=onOpacityPickedListener;
+ public void setOnOpacityPickedListener(OnOpacityPickedListener onOpacityPickedListener) {
+ this.onOpacityPickedListener = onOpacityPickedListener;
}
- public void setOp(int opacity){
+ public void setOp(int opacity) {
if (onOpacityPickedListener != null)
onOpacityPickedListener.onPicked(opacity);
}
@@ -115,7 +108,7 @@ public void setCanUpdateHexVal(boolean canUpdateHexVal) {
this.canUpdateHexVal = canUpdateHexVal;
}
- public interface OnOpacityPickedListener{
+ public interface OnOpacityPickedListener {
void onPicked(int opacity);
}
}
diff --git a/src/main/java/com/azeesoft/lib/colorpicker/OrientedSeekBar.java b/src/main/java/com/azeesoft/lib/colorpicker/OrientedSeekBar.java
index ccc1407..a77a987 100644
--- a/src/main/java/com/azeesoft/lib/colorpicker/OrientedSeekBar.java
+++ b/src/main/java/com/azeesoft/lib/colorpicker/OrientedSeekBar.java
@@ -3,71 +3,70 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
-import android.support.v7.widget.AppCompatSeekBar;
import android.util.AttributeSet;
import android.view.MotionEvent;
+import androidx.appcompat.widget.AppCompatSeekBar;
+
/**
* Created by aziz titu2 on 2/11/2016.
- *
* XML:
+ * Use
+ * or
+ * orientation=vertical