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 @@ - - - - - - - + \ No newline at end of file diff --git a/src/main/java/com/azeesoft/lib/colorpicker/BitmapsGenerator.java b/src/main/java/com/azeesoft/lib/colorpicker/BitmapsGenerator.java index b23e8e3..8e4a440 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/BitmapsGenerator.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/BitmapsGenerator.java @@ -6,62 +6,66 @@ /** * Created by aziz titu2 on 2/10/2016. - *

+ *

* Base class for generating Bitmaps for the Color Pickers */ -public class BitmapsGenerator { +class BitmapsGenerator { - - /**Gets a rectangular Bitmap representing the hue range (0-360) - * @param width width of the HuePicker + /** + * Gets a rectangular Bitmap representing the hue range (0-360) + * + * @param width width of the HuePicker * @param height height of the HuePicker - * @return A rectangular Bitmap representing the hue range (0-360) + * @return A rectangular Bitmap representing the hue range (0-360), or null if failed */ - public static Bitmap getHueBitmap(int width,int height) { + static Bitmap getHueBitmap(int width, int height) { //System.out.println("Width2: " + width); //System.out.println("Height2: " + height); + try { + Bitmap hueBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); - Bitmap hueBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); - - for (int x = 0; x < width; x++) { - float hue = 0; - if (width > height) { - hue = (x * 360f) / width; - } - for (int y = 0; y < height; y++) { - if (width <= height) { - hue = (y * 360f) / height; + for (int x = 0; x < width; x++) { + float hue = 0; + if (width > height) { + hue = (x * 360f) / width; } + for (int y = 0; y < height; y++) { + if (width <= height) { + hue = (y * 360f) / height; + } - float[] hsv = new float[]{hue, 1, 1}; + float[] hsv = new float[]{hue, 1, 1}; - hueBitmap.setPixel(x, y, Color.HSVToColor(hsv)); + hueBitmap.setPixel(x, y, Color.HSVToColor(hsv)); + } } - } - - return hueBitmap; + return hueBitmap; + } catch (Throwable t) { + return null; + } } - - /**Gets a Rectangular Bitmap representing the Gradient of Sat and Val copied from the given BitmapDrawable for the given Hue + /** + * Gets a Rectangular Bitmap representing the Gradient of Sat and Val copied from the given BitmapDrawable for the given Hue + * * @param bitmapDrawable A BitmapDrawable to use as a base for the gradient of Sat and Val - * @param hue Value of Hue to use for the bitmap generation of SatVal Gradient bitmap - * @param width Width of the SatValPicker - * @param height Height of the SatValPicker - * @param skipCount Number of pixels to skip when generating Bitmap (increasing this results in faster bitmap generation but reduces bitmap quality) + * @param hue Value of Hue to use for the bitmap generation of SatVal Gradient bitmap + * @param width Width of the SatValPicker + * @param height Height of the SatValPicker + * @param skipCount Number of pixels to skip when generating Bitmap (increasing this results in faster bitmap generation but reduces bitmap quality) * @return A Rectangular Bitmap representing the Gradient of Sat and Val copied from the given BitmapDrawable for the given Hue */ @Deprecated - public static Bitmap getSatValBitmapFrom(BitmapDrawable bitmapDrawable,float hue, int width, int height, int skipCount){ - int[] pixels=new int[width*height]; - Bitmap bitmap=bitmapDrawable.getBitmap(); + public static Bitmap getSatValBitmapFrom(BitmapDrawable bitmapDrawable, float hue, int width, int height, int skipCount) { + int[] pixels = new int[width * height]; + Bitmap bitmap = bitmapDrawable.getBitmap(); bitmap.getPixels(pixels, 0, width, 0, 0, width, height); - for(int i=0;i=(width*height)) - break; + if (pix >= (width * height)) + break; - float sat = (x) / (float)width; - float val = ((height - y)) / (float)height; + float sat = (x) / (float) width; + float val = ((height - y)) / (float) height; - float[] hsv = new float[]{hue, sat, val}; + float[] hsv = new float[]{hue, sat, val}; - int color= Color.HSVToColor(hsv); - for(int m=0;m=(width*height)) - break; + int color = Color.HSVToColor(hsv); + for (int m = 0; m < skipCount; m++) { + if (pix >= (width * height)) + break; // //System.out.println("Filling..."); - if((x+m)=(width*height)) - break; + for (int n = 0; n < skipCount; n++) { + if (pix >= (width * height)) + break; // //System.out.println("Filling..."); - for (int x = 0; x < width; x++) { - colors[pix]=colors[pix-width]; - pix++; + for (int x = 0; x < width; x++) { + colors[pix] = colors[pix - width]; + pix++; + } } } - } - - hueBitmap.setPixels(colors, 0, width, 0, 0, width, height); - return hueBitmap; + satValBitmap.setPixels(colors, 0, width, 0, 0, width, height); + return satValBitmap; + } catch (Throwable t) { + return null; + } } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/ColorEditDialog.java b/src/main/java/com/azeesoft/lib/colorpicker/ColorEditDialog.java index e4b2bb4..a2ef2e9 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/ColorEditDialog.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/ColorEditDialog.java @@ -4,10 +4,10 @@ import android.content.Context; import android.graphics.Color; import android.graphics.PorterDuff; -import android.support.v7.widget.AppCompatButton; import android.view.LayoutInflater; import android.view.View; import android.view.Window; +import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.TextView; @@ -15,22 +15,22 @@ /** * Created by aziz titu2 on 2/11/2016. - * + *

* 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 - *

+ *

* This should also be set for the pickers using setColorPickerCompatHorizontalScrollView() method of the pickers - *

+ *

* Wrapping them in a normal horizontal scrollview will result in bugs */ public class ColorPickerCompatHorizontalScrollView extends HorizontalScrollView { - private boolean isScrollDisabled=false; + private boolean isScrollDisabled; public ColorPickerCompatHorizontalScrollView(Context context) { super(context); - isScrollDisabled=false; + isScrollDisabled = false; } public ColorPickerCompatHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); - isScrollDisabled=false; + isScrollDisabled = false; } public ColorPickerCompatHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - isScrollDisabled=false; + isScrollDisabled = false; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if(isScrollDisabled) - return false; - return super.onInterceptTouchEvent(ev); + return !isScrollDisabled && super.onInterceptTouchEvent(ev); } /** * Use it to disable the scroll and allow child views to get touch events - *

+ *

* Make sure to enable the scroll when the child view doesn't need to get the touch events * * @param b disable(true) / enable(false) */ - public void setScrollDisabled(boolean b){ - isScrollDisabled=b; + public void setScrollDisabled(boolean b) { + isScrollDisabled = b; } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatScrollView.java b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatScrollView.java index e593ffa..a89de5e 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatScrollView.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerCompatScrollView.java @@ -7,47 +7,45 @@ /** * Created by aziz titu2 on 2/10/2016. - *

+ *

* Custom scrollview to wrap the ColorPickers in order to manage the TouchEvents efficiently - *

+ *

* This should also be set for the pickers using setColorPickerCompatScrollView() method of the pickers - *

+ *

* Wrapping them in a normal scrollview will result in bugs */ public class ColorPickerCompatScrollView extends ScrollView { - private boolean isScrollDisabled=false; + private boolean isScrollDisabled; public ColorPickerCompatScrollView(Context context) { super(context); - isScrollDisabled=false; + isScrollDisabled = false; } public ColorPickerCompatScrollView(Context context, AttributeSet attrs) { super(context, attrs); - isScrollDisabled=false; + isScrollDisabled = false; } public ColorPickerCompatScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - isScrollDisabled=false; + isScrollDisabled = false; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if(isScrollDisabled) - return false; - return super.onInterceptTouchEvent(ev); + return !isScrollDisabled && super.onInterceptTouchEvent(ev); } /** * Use it to disable the scroll and allow child views to get touch events - *

+ *

* Make sure to enable the scroll when the child view doesn't need to get the touch events * * @param b disable(true) / enable(false) */ - public void setScrollDisabled(boolean b){ - isScrollDisabled=b; + public void setScrollDisabled(boolean b) { + isScrollDisabled = b; } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerDialog.java b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerDialog.java index 128aa89..079f161 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerDialog.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/ColorPickerDialog.java @@ -6,8 +6,8 @@ import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.support.v7.view.ContextThemeWrapper; -import android.support.v7.widget.AppCompatButton; +import android.os.Handler; +import android.os.Looper; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -15,25 +15,28 @@ import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; +import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.appcompat.view.ContextThemeWrapper; /** * Created by aziz titu2 on 2/10/2016. - *

+ *

* A modified dialog that contains the color picking tools within itself - *

+ *

* Use createColorPickerDialog(Context context) or createColorPickerDialog(Context context,int theme) to instantiate this class *

* 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
@@ -46,24 +49,23 @@ public class ColorPickerDialog extends Dialog { /** * Default resource for the Light themed Color Picker */ - public static final int LIGHT_THEME=R.style.ColorPicker_Light; + public static final int LIGHT_THEME = R.style.ColorPicker_Light; /** * Default resource for the Dark themed Color Picker */ - public static final int DARK_THEME= R.style.ColorPicker_Dark; - + public static final int DARK_THEME = R.style.ColorPicker_Dark; private HuePicker huePicker; private OpacityPicker opacityPicker; private SatValPicker satValPicker; - private LinearLayout colorPreviewBox,oldColorPreviewBox; + private LinearLayout colorPreviewBox, oldColorPreviewBox; private EditText hexVal; - private TextView hex,hue,sat,val,red,green,blue,alpha; - private ImageView hsvEditIcon,rgbEditIcon; - private AppCompatButton pickButton,cancelButton; - private RelativeLayout colorComponents,hexHolder,hsv,rgb; + private TextView hex, hue, sat, val, red, green, blue, alpha; + private ImageView hsvEditIcon, rgbEditIcon, ivNoColor; + private Button pickButton, cancelButton; + private RelativeLayout colorComponents, hexHolder, hsv, rgb; private ColorPickerCompatScrollView colorPickerCompatScrollView; private ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView; private ColorPickerRootView colorPickerRootView; @@ -71,10 +73,10 @@ public class ColorPickerDialog extends Dialog { private int initColor; - private boolean skipHexValChange=false; + private boolean skipHexValChange = false; - private int mColor=Color.parseColor("#ffffffff"); - private String mHexVal="#ffffffff"; + private int mColor = Color.parseColor("#ffffffff"); + private String mHexVal = "#ffffffff"; private OnColorPickedListener onColorPickedListener; private OnClosedListener onClosedListener; @@ -85,20 +87,21 @@ private ColorPickerDialog(Context context) { } private ColorPickerDialog(Context context, int theme) { - super(context,theme); + super(context, theme); init(context); } /** * Creates a Light themed ColorPickerDialog - *

+ *

* 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
@@ -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 { + + private WeakReference contextRef = new WeakReference<>(getContext()); + private int width; + private int height; + + private HueChanger(int width, int height) { + this.width = width; + this.height = height; + } + + @Override + protected BitmapDrawable doInBackground(Float... params) { + boolean horizontal = orientation == ORIENTATION_HORIZONTAL; + Bitmap bitmap = BitmapsGenerator.getHueBitmap(horizontal ? width : height, horizontal ? height : width); + Context context = contextRef.get(); + return bitmap != null && context != null ? new BitmapDrawable(context.getResources(), bitmap) : null; + } + + @Override + protected void onPostExecute(BitmapDrawable bitmapDrawable) { + if (bitmapDrawable != null) + setProgressDrawable(bitmapDrawable); + else + bitmapGenerationFailedListener.onBitmapGenerationFailed(); + } + } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/OpacityPicker.java b/src/main/java/com/azeesoft/lib/colorpicker/OpacityPicker.java index 5f133f0..f51e215 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/OpacityPicker.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/OpacityPicker.java @@ -9,20 +9,15 @@ /** * Created by aziz titu2 on 2/10/2016. - * + *

* 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. - *

+ *

* A modified {@link AppCompatSeekBar} which can be used both Horizontally as well as Vertically - *

+ *

* To specify the orientation: - *

+ *

* Java:

- * setOrientation(int orientation);

- * + * setOrientation(int orientation);

+ *

* XML:

- * attribute 'orientation'

- * - * Use

- * orientation=horizontal

- * - * or

- * - * orientation=vertical

+ * attribute 'orientation'

+ *

+ * Use

+ * orientation=horizontal

+ *

+ * or

+ *

+ * orientation=vertical

*/ public class OrientedSeekBar extends AppCompatSeekBar { - protected static final int ORIENTATION_HORIZONTAL=1,ORIENTATION_VERTICAL=2; + protected static final int ORIENTATION_HORIZONTAL = 1, ORIENTATION_VERTICAL = 2; - protected int orientation=ORIENTATION_HORIZONTAL; + protected int orientation = ORIENTATION_HORIZONTAL; private OnSeekBarChangeListener seekBarChangeListener; private ColorPickerCompatScrollView colorPickerCompatScrollView; private ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView; - public OrientedSeekBar(Context context) { super(context); } public OrientedSeekBar(Context context, AttributeSet attrs) { super(context, attrs); - TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.OrientedSeekBar, 0, 0); - + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OrientedSeekBar, 0, 0); try { - orientation = a.getInt(R.styleable.OrientedSeekBar_orientation, ORIENTATION_HORIZONTAL); + orientation = a.getInt(R.styleable.OrientedSeekBar_cp_orientation, ORIENTATION_HORIZONTAL); } finally { a.recycle(); } } - @Override - public void setOnSeekBarChangeListener(OnSeekBarChangeListener mListener){ + public void setOnSeekBarChangeListener(OnSeekBarChangeListener mListener) { this.seekBarChangeListener = mListener; super.setOnSeekBarChangeListener(mListener); } + @SuppressWarnings("SuspiciousNameCombination") @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if(orientation==ORIENTATION_HORIZONTAL){ + if (orientation == ORIENTATION_HORIZONTAL) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight()); - }else{ + } else { super.onMeasure(heightMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); } @@ -75,16 +74,15 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { - if(orientation==ORIENTATION_HORIZONTAL) + if (orientation == ORIENTATION_HORIZONTAL) super.onSizeChanged(w, h, oldw, oldh); else super.onSizeChanged(h, w, oldh, oldw); } - @Override protected synchronized void onDraw(Canvas c) { - if(orientation!=ORIENTATION_HORIZONTAL){ + if (orientation != ORIENTATION_HORIZONTAL) { c.rotate(-90); c.translate(-getHeight(), 0); @@ -96,12 +94,10 @@ protected synchronized void onDraw(Canvas c) { @Override public boolean onTouchEvent(MotionEvent event) { - if(orientation==ORIENTATION_HORIZONTAL) - { + if (orientation == ORIENTATION_HORIZONTAL) { return super.onTouchEvent(event); } - //Only if orientation is vertical if (!isEnabled()) { return false; @@ -110,8 +106,7 @@ public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { // is = true; - int i = 0; - i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); + int i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); setProgress(i); //setProgress(getMax() - (int) (getMax() * event.getY() / getHeight())); onSizeChanged(getWidth(), getHeight(), 0, 0); @@ -123,8 +118,7 @@ public boolean onTouchEvent(MotionEvent event) { break; } case MotionEvent.ACTION_MOVE: { - int i = 0; - i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); + int i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); setProgress(i); //setProgress(getMax() - (int) (getMax() * event.getY() / getHeight())); onSizeChanged(getWidth(), getHeight(), 0, 0); @@ -133,9 +127,8 @@ public boolean onTouchEvent(MotionEvent event) { break; } case MotionEvent.ACTION_UP: { - int i = 0; + int i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); // is = false; - i = getMax() - (int) Math.ceil((getMax() * event.getY() / getHeight())); setProgress(i); //setProgress(getMax() - (int) (getMax() * event.getY() / getHeight())); onSizeChanged(getWidth(), getHeight(), 0, 0); @@ -190,33 +183,33 @@ public synchronized void setProgress(int progress) { onSizeChanged(getWidth(), getHeight(), 0, 0); } - private void disableScroll(){ - if(colorPickerCompatScrollView!=null) + private void disableScroll() { + if (colorPickerCompatScrollView != null) colorPickerCompatScrollView.setScrollDisabled(true); - if(colorPickerCompatHorizontalScrollView!=null) + if (colorPickerCompatHorizontalScrollView != null) colorPickerCompatHorizontalScrollView.setScrollDisabled(true); } - private void enableScroll(){ - if(colorPickerCompatScrollView!=null) + private void enableScroll() { + if (colorPickerCompatScrollView != null) colorPickerCompatScrollView.setScrollDisabled(false); - - if(colorPickerCompatHorizontalScrollView!=null) + if (colorPickerCompatHorizontalScrollView != null) colorPickerCompatHorizontalScrollView.setScrollDisabled(false); } - public void setColorPickerCompatScrollView(ColorPickerCompatScrollView colorPickerCompatScrollView){ - this.colorPickerCompatScrollView=colorPickerCompatScrollView; + public void setColorPickerCompatScrollView(ColorPickerCompatScrollView colorPickerCompatScrollView) { + this.colorPickerCompatScrollView = colorPickerCompatScrollView; } - public void setColorPickerCompatHorizontalScrollView(ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView){ - this.colorPickerCompatHorizontalScrollView=colorPickerCompatHorizontalScrollView; + public void setColorPickerCompatHorizontalScrollView(ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView) { + this.colorPickerCompatHorizontalScrollView = colorPickerCompatHorizontalScrollView; } /** * Sets the orientation of the seekbar + * * @param orientation Use ORIENTATION_HORIZONTAL or ORIENTATION_VERTICAL (Default is ORIENTATION_HORIZONTAL) */ public void setOrientation(int orientation) { diff --git a/src/main/java/com/azeesoft/lib/colorpicker/SatValPicker.java b/src/main/java/com/azeesoft/lib/colorpicker/SatValPicker.java index 3036fd8..b9aebc8 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/SatValPicker.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/SatValPicker.java @@ -1,38 +1,37 @@ package com.azeesoft.lib.colorpicker; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; -import android.os.Build; import android.util.AttributeSet; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import java.lang.ref.WeakReference; + /** * Created by aziz titu2 on 2/9/2016. */ public class SatValPicker extends ViewGroup { + private static final int SKIP_COUNT_DIP = 2; private static final int MIN_SIZE_DIP = 200; -// public static boolean canScroll=true; - private boolean firstDraw,pendingUpdateSatVal=false; - private boolean canUpdateHexVal=true; - private int minSizePx,mWidth,mHeight; - private float mHue=0,mSat=0,mVal=1,pointerX,pointerY; - private Context mContext; + private int skipCount = SKIP_COUNT_DIP; + private boolean firstDraw, pendingUpdateSatVal = false; + private boolean canUpdateHexVal = true; + private int minSizePx, mWidth, mHeight; + private float mHue = 0, mSat = 0, mVal = 1, pointerX, pointerY; private OnColorSelectedListener onColorSelectedListener; private ImageView thumb; private ColorPickerCompatScrollView colorPickerCompatScrollView; private ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView; - public int skipCount=10; - public SatValPicker(Context context) { super(context); init(context); @@ -107,13 +106,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { size = Math.min(w, h); } size = Math.max(size, minSizePx); - setMeasuredDimension(size, size); + setMeasuredDimension(size, size / 2); - mWidth=getMeasuredWidth(); - mHeight=getMeasuredHeight(); + mWidth = getMeasuredWidth(); + mHeight = getMeasuredHeight(); //System.out.println("init sat val measures: " + mWidth + "," + mHeight); - if(firstDraw) { - firstDraw=false; + if (firstDraw) { + firstDraw = false; refreshSatValPicker(mHue); } } @@ -124,18 +123,18 @@ protected synchronized void onDraw(Canvas canvas) { } public void init(Context context) { - mContext = context; + skipCount = (int) Stools.dipToPixels(context, SKIP_COUNT_DIP); minSizePx = (int) Stools.dipToPixels(context, MIN_SIZE_DIP); - firstDraw=true; - pendingUpdateSatVal=false; + firstDraw = true; + pendingUpdateSatVal = false; - thumb=(ImageView) LayoutInflater.from(mContext).inflate(R.layout.sat_val_thumb,null); + thumb = new ImageView(context); + thumb.setImageResource(R.drawable.thumb); - thumb.setPivotX(Stools.dipToPixels(mContext, 6)); - thumb.setPivotY(Stools.dipToPixels(mContext, 6)); + thumb.setPivotX(Stools.dipToPixels(getContext(), 6)); + thumb.setPivotY(Stools.dipToPixels(getContext(), 6)); addView(thumb); - } @Override @@ -157,41 +156,39 @@ public boolean onTouchEvent(MotionEvent event) { // return super.onTouchEvent(event); } - private void disableScroll(){ - if(colorPickerCompatScrollView!=null) + private void disableScroll() { + if (colorPickerCompatScrollView != null) colorPickerCompatScrollView.setScrollDisabled(true); - if(colorPickerCompatHorizontalScrollView!=null) + if (colorPickerCompatHorizontalScrollView != null) colorPickerCompatHorizontalScrollView.setScrollDisabled(true); } - private void enableScroll(){ - if(colorPickerCompatScrollView!=null) + private void enableScroll() { + if (colorPickerCompatScrollView != null) colorPickerCompatScrollView.setScrollDisabled(false); - if(colorPickerCompatHorizontalScrollView!=null) + if (colorPickerCompatHorizontalScrollView != null) colorPickerCompatHorizontalScrollView.setScrollDisabled(false); } - private void placePointer(float x, float y){ - if(mWidth>0 && mHeight>0){ - if(x<0) - x=0; - else if(x>mWidth) - x=mWidth; - - if(y<0) - y=0; - else if(y>mHeight) - y=mHeight; - - thumb.setX(x - Stools.dipToPixels(mContext,6)); - thumb.setY(y - Stools.dipToPixels(mContext, 6)); - if(y 0 && mHeight > 0) { + if (x < 0) + x = 0; + else if (x > mWidth) + x = mWidth; + + if (y < 0) + y = 0; + else if (y > mHeight) + y = mHeight; + + thumb.setX(x - Stools.dipToPixels(getContext(), 6)); + thumb.setY(y - Stools.dipToPixels(getContext(), 6)); + int thumbResId = y < mHeight / 2 ? R.drawable.thumb : R.drawable.thumb_white; + thumb.setImageDrawable(getContext().getResources().getDrawable(thumbResId, getContext().getTheme())); retrieveColorAt(x, y); @@ -200,92 +197,62 @@ else if(y>mHeight) //System.out.println("AshY: " + y); } - private void retrieveColorAt(float x, float y){ + private void retrieveColorAt(float x, float y) { - pointerX=x; - pointerY=y; + pointerX = x; + pointerY = y; - mSat = (x) / (float)mWidth; - mVal = ((mHeight - y)) / (float)mHeight; + mSat = (x) / (float) mWidth; + mVal = ((mHeight - y)) / (float) mHeight; onColorRetrieved(mHue, mSat, mVal); } - private void onColorRetrieved(float hue,float sat,float val){ - int color=Color.HSVToColor(new float[]{hue, sat, val}); + private void onColorRetrieved(float hue, float sat, float val) { + int color = Color.HSVToColor(new float[]{hue, sat, val}); - if(onColorSelectedListener !=null){ + if (onColorSelectedListener != null) { onColorSelectedListener.onColorSelected(color, "#" + Integer.toHexString(color)); } } - public void setOnColorSelectedListener(OnColorSelectedListener onColorSelectedListener){ + public void setOnColorSelectedListener(OnColorSelectedListener onColorSelectedListener) { this.onColorSelectedListener = onColorSelectedListener; } - public void setSaturationAndValue(float sat,float val){ - setSaturationAndValue(sat, val,true); + public void setSaturationAndValue(float sat, float val) { + setSaturationAndValue(sat, val, true); } - public void setSaturationAndValue(float sat,float val,boolean apply){ + public void setSaturationAndValue(float sat, float val, boolean apply) { //System.out.println("Ash Sat Val: "+ sat+" " + val); //System.out.println("Ash mWidth mHeight: "+ mWidth+" "+mHeight); - if((mWidth<=0 || mHeight<=0) || !apply){ - mSat=sat; - mVal=val; - pendingUpdateSatVal=true; - }else + if ((mWidth <= 0 || mHeight <= 0) || !apply) { + mSat = sat; + mVal = val; + pendingUpdateSatVal = true; + } else placePointer(sat * mWidth, mHeight - (val * mHeight)); } public void refreshSatValPicker(float hue) { - mHue=hue; + mHue = hue; //System.out.println("Refreshing with Hue: "+hue); // mCanvas.drawBitmap(getSatValBitmap(hue), 0, 0, null); - class SatValChanger extends AsyncTask { - float hue; - - @Override - protected BitmapDrawable doInBackground(Float... params) { -// //System.out.println("sat val measures: "+mWidth+","+mHeight); - hue=params[0]; - return new BitmapDrawable(BitmapsGenerator.getSatValBitmap(hue,mWidth,mHeight,skipCount)); - } - - @Override - protected void onPostExecute(BitmapDrawable bitmapDrawable) { - super.onPostExecute(bitmapDrawable); - -// if(Math.abs(hue-mHue)<40) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - setBackground(bitmapDrawable); - } else { - setBackgroundDrawable(bitmapDrawable); - } - - if(pendingUpdateSatVal) - placePointer(mSat * mWidth, mHeight - (mVal * mHeight)); - else - retrieveColorAt(pointerX, pointerY); - } - } - - - if(mWidth>0 && mHeight>0) + if (mWidth > 0 && mHeight > 0) new SatValChanger().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, hue); - } - public void setColorPickerCompatScrollView(ColorPickerCompatScrollView colorPickerCompatScrollView){ - this.colorPickerCompatScrollView=colorPickerCompatScrollView; + public void setColorPickerCompatScrollView(ColorPickerCompatScrollView colorPickerCompatScrollView) { + this.colorPickerCompatScrollView = colorPickerCompatScrollView; } - public void setColorPickerCompatHorizontalScrollView(ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView){ - this.colorPickerCompatHorizontalScrollView=colorPickerCompatHorizontalScrollView; + public void setColorPickerCompatHorizontalScrollView(ColorPickerCompatHorizontalScrollView colorPickerCompatHorizontalScrollView) { + this.colorPickerCompatHorizontalScrollView = colorPickerCompatHorizontalScrollView; } public boolean isCanUpdateHexVal() { @@ -300,4 +267,30 @@ public interface OnColorSelectedListener { void onColorSelected(int color, String hexVal); } + private class SatValChanger extends AsyncTask { + + private WeakReference contextRef = new WeakReference<>(getContext()); + private float hue; + + @Override + protected BitmapDrawable doInBackground(Float... params) { +// //System.out.println("sat val measures: "+mWidth+","+mHeight); + hue = params[0]; + Bitmap bitmap = BitmapsGenerator.getSatValBitmap(hue, mWidth, mHeight, skipCount); + Context context = contextRef.get(); + return bitmap != null && context != null ? new BitmapDrawable(context.getResources(), bitmap) : null; + } + + @Override + protected void onPostExecute(BitmapDrawable bitmapDrawable) { +// if(Math.abs(hue-mHue)<40) + if (bitmapDrawable != null) + setBackground(bitmapDrawable); + + if (pendingUpdateSatVal) + placePointer(mSat * mWidth, mHeight - (mVal * mHeight)); + else + retrieveColorAt(pointerX, pointerY); + } + } } diff --git a/src/main/java/com/azeesoft/lib/colorpicker/Stools.java b/src/main/java/com/azeesoft/lib/colorpicker/Stools.java index 3fd6164..f6e523d 100644 --- a/src/main/java/com/azeesoft/lib/colorpicker/Stools.java +++ b/src/main/java/com/azeesoft/lib/colorpicker/Stools.java @@ -14,11 +14,12 @@ */ public class Stools { - private final static String SP_KEY_LAST_COLOR="lastColor"; + private final static String SP_KEY_LAST_COLOR = "lastColor"; /** * Converts Density pixels(dp) to Pixels - * @param context Context + * + * @param context Context * @param dipValue dp value to convert * @return Pixels */ @@ -33,12 +34,12 @@ public static float dipToPixels(Context context, float dipValue) { * @param context Context * @param hexaVal Color to store in hexadecimal form (Eg: #ff000000 or #000000) */ - public static void saveLastColor(Context context,String hexaVal){ + public static void saveLastColor(Context context, String hexaVal) { try { Color.parseColor(hexaVal); - SharedPreferences sharedPreferences=context.getSharedPreferences("colpick", Context.MODE_PRIVATE); - SharedPreferences.Editor editor=sharedPreferences.edit(); - editor.putString(SP_KEY_LAST_COLOR,hexaVal); + SharedPreferences sharedPreferences = context.getSharedPreferences("colpick", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(SP_KEY_LAST_COLOR, hexaVal); editor.commit(); } catch (Exception e) { e.printStackTrace(); @@ -47,13 +48,14 @@ public static void saveLastColor(Context context,String hexaVal){ /** * Gets the color stored in Shared Preferences as the last picked color or null if it doesn't exist + * * @param context Context * @return Last picked color in hexadecimal form (Eg: #ff000000 or #000000) or null if it doesn't exist */ - public static String loadLastColor(Context context){ + public static String loadLastColor(Context context) { try { - SharedPreferences sharedPreferences=context.getSharedPreferences("colpick", Context.MODE_PRIVATE); - String s=sharedPreferences.getString(SP_KEY_LAST_COLOR,null); + SharedPreferences sharedPreferences = context.getSharedPreferences("colpick", Context.MODE_PRIVATE); + String s = sharedPreferences.getString(SP_KEY_LAST_COLOR, null); Color.parseColor(s); return s; } catch (Exception e) { @@ -64,19 +66,20 @@ public static String loadLastColor(Context context){ /** * Applies a tint on the drawable with the given color + * * @param drawable Drawable to apply the tint on - * @param color Color to apply as tint on the drawable + * @param color Color to apply as tint on the drawable * @return Tinted drawable */ - public static Drawable tintDrawable(Drawable drawable,int color){ - int red = (color & 0xFF0000) / 0xFFFF; + public static Drawable tintDrawable(Drawable drawable, int color) { + int red = (color & 0xFF0000) / 0xFFFF; int green = (color & 0xFF00) / 0xFF; - int blue = color & 0xFF; + int blue = color & 0xFF; - float[] matrix = { 0, 0, 0, 0, red, + float[] matrix = {0, 0, 0, 0, red, 0, 0, 0, 0, green, 0, 0, 0, 0, blue, - 0, 0, 0, 1, 0 }; + 0, 0, 0, 1, 0}; ColorFilter colorFilter = new ColorMatrixColorFilter(matrix); if (drawable != null) { diff --git a/src/main/res/drawable/no_color.xml b/src/main/res/drawable/no_color.xml new file mode 100644 index 0000000..f0fa572 --- /dev/null +++ b/src/main/res/drawable/no_color.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/opacity_box_bg.xml b/src/main/res/drawable/opacity_box_bg.xml index 43f6580..9a5ab4e 100644 --- a/src/main/res/drawable/opacity_box_bg.xml +++ b/src/main/res/drawable/opacity_box_bg.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/src/main/res/drawable/opacity_box_bg_land.xml b/src/main/res/drawable/opacity_box_bg_land.xml index 43421c1..fea2b2a 100644 --- a/src/main/res/drawable/opacity_box_bg_land.xml +++ b/src/main/res/drawable/opacity_box_bg_land.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/src/main/res/drawable/opacity_gradient_bg.xml b/src/main/res/drawable/opacity_gradient_bg.xml index 3f3646b..a8e9a43 100644 --- a/src/main/res/drawable/opacity_gradient_bg.xml +++ b/src/main/res/drawable/opacity_gradient_bg.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/src/main/res/drawable/opacity_gradient_bg_land.xml b/src/main/res/drawable/opacity_gradient_bg_land.xml index a0303f8..397ef46 100644 --- a/src/main/res/drawable/opacity_gradient_bg_land.xml +++ b/src/main/res/drawable/opacity_gradient_bg_land.xml @@ -2,7 +2,7 @@ + android:angle="0" + android:endColor="@android:color/black" + android:startColor="@android:color/transparent" /> \ No newline at end of file diff --git a/src/main/res/drawable/slider_thumb.xml b/src/main/res/drawable/slider_thumb.xml index ba8642b..71a756f 100644 --- a/src/main/res/drawable/slider_thumb.xml +++ b/src/main/res/drawable/slider_thumb.xml @@ -1,8 +1,8 @@ - + + android:width="4dp" + android:height="30dp" /> \ No newline at end of file diff --git a/src/main/res/drawable/slider_thumb_deprecated.xml b/src/main/res/drawable/slider_thumb_deprecated.xml index 086c32c..f0ecd25 100644 --- a/src/main/res/drawable/slider_thumb_deprecated.xml +++ b/src/main/res/drawable/slider_thumb_deprecated.xml @@ -1,8 +1,8 @@ - + + android:height="5dp" /> \ No newline at end of file diff --git a/src/main/res/drawable/thumb.xml b/src/main/res/drawable/thumb.xml index 7a4112c..8ee8a6c 100644 --- a/src/main/res/drawable/thumb.xml +++ b/src/main/res/drawable/thumb.xml @@ -1,7 +1,5 @@ - - - + + \ No newline at end of file diff --git a/src/main/res/drawable/thumb_pressed.xml b/src/main/res/drawable/thumb_pressed.xml index 4bcc7e9..1b0fe4c 100644 --- a/src/main/res/drawable/thumb_pressed.xml +++ b/src/main/res/drawable/thumb_pressed.xml @@ -1,8 +1,8 @@ - - - + android:shape="oval"> + + \ No newline at end of file diff --git a/src/main/res/drawable/thumb_unpressed.xml b/src/main/res/drawable/thumb_unpressed.xml index 64cea5d..84ce9a5 100644 --- a/src/main/res/drawable/thumb_unpressed.xml +++ b/src/main/res/drawable/thumb_unpressed.xml @@ -1,7 +1,10 @@ - - + android:shape="oval"> + + \ No newline at end of file diff --git a/src/main/res/drawable/thumb_white.xml b/src/main/res/drawable/thumb_white.xml index 4d494b0..8970f5b 100644 --- a/src/main/res/drawable/thumb_white.xml +++ b/src/main/res/drawable/thumb_white.xml @@ -1,7 +1,5 @@ - - - + + \ No newline at end of file diff --git a/src/main/res/drawable/thumb_white_pressed.xml b/src/main/res/drawable/thumb_white_pressed.xml index 4bcc7e9..1b0fe4c 100644 --- a/src/main/res/drawable/thumb_white_pressed.xml +++ b/src/main/res/drawable/thumb_white_pressed.xml @@ -1,8 +1,8 @@ - - - + android:shape="oval"> + + \ No newline at end of file diff --git a/src/main/res/drawable/thumb_white_unpressed.xml b/src/main/res/drawable/thumb_white_unpressed.xml index 2f2ef9d..ee6cd3a 100644 --- a/src/main/res/drawable/thumb_white_unpressed.xml +++ b/src/main/res/drawable/thumb_white_unpressed.xml @@ -1,7 +1,10 @@ - - + android:shape="oval"> + + \ No newline at end of file diff --git a/src/main/res/drawable/transparent.xml b/src/main/res/drawable/transparent.xml index 1682b24..ee06301 100644 --- a/src/main/res/drawable/transparent.xml +++ b/src/main/res/drawable/transparent.xml @@ -1,5 +1,4 @@ - - + \ No newline at end of file diff --git a/src/main/res/layout-land/dialog_color_picker.xml b/src/main/res/layout-land/dialog_color_picker.xml index 2ddab9a..1e035af 100644 --- a/src/main/res/layout-land/dialog_color_picker.xml +++ b/src/main/res/layout-land/dialog_color_picker.xml @@ -4,111 +4,124 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:showIn="@layout/dialog_root" - app:layout_behavior="@string/appbar_scrolling_view_behavior"> + app:layout_behavior="@string/appbar_scrolling_view_behavior" + tools:showIn="@layout/dialog_color_picker_root"> + android:layout_marginBottom="@dimen/activity_vertical_margin"> - + + app:cp_orientation="vertical" + tools:ignore="UnusedAttribute" /> + android:thumb="@drawable/slider_thumb" + app:cp_orientation="vertical" /> + android:layout_toRightOf="@+id/opacityBar"> + android:layout_alignParentLeft="false" + android:layout_centerHorizontal="true" + android:layout_marginLeft="10dp"> + + + android:scaleType="matrix" + android:src="@mipmap/checker" /> + android:layout_height="wrap_content" + android:layout_toRightOf="@id/ivNoColor" + android:orientation="horizontal"> + android:orientation="horizontal" /> + android:orientation="horizontal"> @@ -117,161 +130,168 @@ + android:layout_centerHorizontal="true" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"> + android:layout_centerInParent="true" + android:orientation="horizontal"> + android:textSize="17sp" /> + + + android:layout_centerHorizontal="true" + android:layout_marginTop="50dp"> + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:layout_height="wrap_content"> + android:layout_marginTop="12dp" + android:layout_marginRight="10dp" + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="H: 0 \u0b0" /> + android:text="S: " /> + android:text="V: " /> + + + android:layout_height="wrap_content"> + android:layout_marginLeft="5dp" + android:src="@drawable/ic_mode_edit_white_24dp" /> + android:layout_marginTop="12dp" + android:layout_marginRight="10dp" + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="R: " /> + android:text="G: " /> + android:text="B: " /> + + android:layout_height="wrap_content"> + android:layout_marginTop="12dp" + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="A: " /> + + - + diff --git a/src/main/res/layout-land/dialog_root.xml b/src/main/res/layout-land/dialog_color_picker_root.xml similarity index 78% rename from src/main/res/layout-land/dialog_root.xml rename to src/main/res/layout-land/dialog_color_picker_root.xml index c16b35b..96bfe33 100644 --- a/src/main/res/layout-land/dialog_root.xml +++ b/src/main/res/layout-land/dialog_color_picker_root.xml @@ -1,9 +1,9 @@ + android:orientation="vertical"> - + + - + android:textColor="#4b51d3" /> - + android:background="#0000" + android:text="Cancel" + android:textColor="#d5481b" /> + \ No newline at end of file diff --git a/src/main/res/layout/dialog_color_picker.xml b/src/main/res/layout/dialog_color_picker.xml index 14eadc3..ad49c1e 100644 --- a/src/main/res/layout/dialog_color_picker.xml +++ b/src/main/res/layout/dialog_color_picker.xml @@ -6,100 +6,111 @@ android:layout_height="match_parent" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" - tools:showIn="@layout/activity_main" - app:layout_behavior="@string/appbar_scrolling_view_behavior"> + app:layout_behavior="@string/appbar_scrolling_view_behavior" + tools:showIn="@layout/dialog_color_picker_root"> + android:layout_marginRight="@dimen/activity_horizontal_margin"> + tools:ignore="UnusedAttribute" /> + android:splitTrack="false" + android:thumb="@drawable/slider_thumb" /> + android:layout_centerHorizontal="true" + android:layout_marginTop="10dp"> + + + android:layout_marginLeft="20dp" + android:layout_toRightOf="@id/ivNoColor"> + android:scaleType="matrix" + android:src="@mipmap/checker" /> + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:orientation="horizontal" /> + android:orientation="horizontal"> @@ -108,169 +119,175 @@ + android:layout_toRightOf="@+id/preview"> + android:layout_centerInParent="true" + android:orientation="horizontal"> + android:text="#" + android:textSize="20sp" /> + android:textSize="20sp" /> + + + + android:layout_marginTop="20dp"> + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:layout_height="wrap_content"> + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="H: 0 \u0b0" /> + android:text="S: " /> + android:text="V: " /> + + android:layout_height="wrap_content"> + android:layout_marginLeft="10dp" + android:src="@drawable/ic_mode_edit_white_24dp" /> + android:layout_marginTop="14dp" + android:layout_marginRight="10dp" + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="R: " /> + android:text="G: " /> + android:text="B: " /> + android:layout_height="wrap_content"> + android:layout_marginTop="14dp" + android:layout_marginRight="10dp" + android:measureWithLargestChild="true" + android:orientation="vertical"> + android:text="A: " /> + + - + diff --git a/src/main/res/layout/dialog_root.xml b/src/main/res/layout/dialog_color_picker_root.xml similarity index 79% rename from src/main/res/layout/dialog_root.xml rename to src/main/res/layout/dialog_color_picker_root.xml index f0dd1c9..19acd47 100644 --- a/src/main/res/layout/dialog_root.xml +++ b/src/main/res/layout/dialog_color_picker_root.xml @@ -1,9 +1,9 @@ + android:orientation="vertical"> - + + - + android:textColor="#4b51d3" /> - + android:background="#0000" + android:text="Cancel" + android:textColor="#d5481b" /> + \ No newline at end of file diff --git a/src/main/res/layout/dialog_edit_color.xml b/src/main/res/layout/dialog_edit_color.xml index 906ce08..25799fa 100644 --- a/src/main/res/layout/dialog_edit_color.xml +++ b/src/main/res/layout/dialog_edit_color.xml @@ -1,104 +1,109 @@ + android:layout_centerInParent="true" + android:orientation="vertical"> + android:layout_centerHorizontal="true" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:inputType="numberSigned" /> + android:text="%" /> + + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:inputType="numberSigned" /> + android:text="%" /> + + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:inputType="numberSigned" /> + android:text="%" /> + + + - + android:textColor="#4b51d3" /> - + android:background="#0000" + android:text="Cancel" + android:textColor="#d5481b" /> + + \ No newline at end of file diff --git a/src/main/res/layout/dialod_edit_color_root.xml b/src/main/res/layout/dialog_edit_color_root.xml similarity index 91% rename from src/main/res/layout/dialod_edit_color_root.xml rename to src/main/res/layout/dialog_edit_color_root.xml index 29ac084..70295ac 100644 --- a/src/main/res/layout/dialod_edit_color_root.xml +++ b/src/main/res/layout/dialog_edit_color_root.xml @@ -1,9 +1,9 @@ - + + diff --git a/src/main/res/layout/sat_val_thumb.xml b/src/main/res/layout/sat_val_thumb.xml index a2954d5..5c5a220 100644 --- a/src/main/res/layout/sat_val_thumb.xml +++ b/src/main/res/layout/sat_val_thumb.xml @@ -1,6 +1,5 @@ - \ No newline at end of file + android:layout_width="12dp" + android:layout_height="12dp" + android:src="@drawable/thumb" /> \ No newline at end of file diff --git a/src/main/res/mipmap-xxxhdpi/checker.png b/src/main/res/mipmap/checker.png similarity index 100% rename from src/main/res/mipmap-xxxhdpi/checker.png rename to src/main/res/mipmap/checker.png diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index 3a5b221..5d8ec54 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -1,29 +1,30 @@ - - - + + + - + - - - - - + + + + + + - - - - - + + + + + \ No newline at end of file diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index 672c288..2fea9f0 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -1,23 +1,10 @@ - - - -