├── demo
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── xml
│ │ │ └── demopreference.xml
│ │ └── layout
│ │ │ └── main.xml
│ │ ├── java
│ │ └── yuku
│ │ │ └── ambilwarna
│ │ │ └── demo
│ │ │ ├── AmbilWarnaDemoPreferenceActivity.java
│ │ │ └── AmbilWarnaDemoActivity.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── proguard-rules.pro
├── library
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ ├── drawable-mdpi
│ │ │ ├── ambilwarna_hue.png
│ │ │ ├── ambilwarna_cursor.png
│ │ │ ├── ambilwarna_target.png
│ │ │ ├── ambilwarna_arrow_down.png
│ │ │ ├── ambilwarna_arrow_right.png
│ │ │ └── ambilwarna_alphacheckered.png
│ │ ├── drawable-hdpi
│ │ │ ├── ambilwarna_cursor.png
│ │ │ ├── ambilwarna_target.png
│ │ │ ├── ambilwarna_arrow_down.png
│ │ │ └── ambilwarna_arrow_right.png
│ │ ├── drawable-ldpi
│ │ │ ├── ambilwarna_cursor.png
│ │ │ ├── ambilwarna_target.png
│ │ │ ├── ambilwarna_arrow_down.png
│ │ │ └── ambilwarna_arrow_right.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ambilwarna_cursor.png
│ │ │ ├── ambilwarna_target.png
│ │ │ ├── ambilwarna_arrow_down.png
│ │ │ └── ambilwarna_arrow_right.png
│ │ ├── values-land
│ │ │ └── dimen.xml
│ │ ├── values-xlarge-land
│ │ │ └── dimen.xml
│ │ ├── values
│ │ │ ├── attrs.xml
│ │ │ └── dimen.xml
│ │ ├── drawable
│ │ │ └── ambilwarna_alphacheckered_tiled.xml
│ │ ├── layout
│ │ │ ├── ambilwarna_pref_widget.xml
│ │ │ └── ambilwarna_dialog.xml
│ │ └── layout-land
│ │ │ └── ambilwarna_dialog.xml
│ │ └── java
│ │ └── yuku
│ │ └── ambilwarna
│ │ ├── widget
│ │ ├── AmbilWarnaPrefWidgetView.java
│ │ └── AmbilWarnaPreference.java
│ │ ├── AmbilWarnaSquare.java
│ │ └── AmbilWarnaDialog.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .gitignore
├── Ambilwarna-logotype4.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── LICENSE
├── gradle.properties
├── gradlew.bat
├── android-mvn-push.gradle
├── README.md
└── gradlew
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo', ':library'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | .idea
4 | *.iml
5 | .DS_Store
6 | /build
7 |
--------------------------------------------------------------------------------
/Ambilwarna-logotype4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/Ambilwarna-logotype4.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_hue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_hue.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ambilwarna_cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-hdpi/ambilwarna_cursor.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ambilwarna_target.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-hdpi/ambilwarna_target.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-ldpi/ambilwarna_cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-ldpi/ambilwarna_cursor.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-ldpi/ambilwarna_target.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-ldpi/ambilwarna_target.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_cursor.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_target.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_target.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ambilwarna_cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-xhdpi/ambilwarna_cursor.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ambilwarna_target.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-xhdpi/ambilwarna_target.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ambilwarna_arrow_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-hdpi/ambilwarna_arrow_down.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-ldpi/ambilwarna_arrow_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-ldpi/ambilwarna_arrow_down.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_arrow_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_arrow_down.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ambilwarna_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-hdpi/ambilwarna_arrow_right.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-ldpi/ambilwarna_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-ldpi/ambilwarna_arrow_right.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_arrow_right.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ambilwarna_arrow_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-xhdpi/ambilwarna_arrow_down.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ambilwarna_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-xhdpi/ambilwarna_arrow_right.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ambilwarna_alphacheckered.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yukuku/ambilwarna/HEAD/library/src/main/res/drawable-mdpi/ambilwarna_alphacheckered.png
--------------------------------------------------------------------------------
/library/src/main/res/values-land/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 240dp
4 | 120dp
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values-xlarge-land/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 240dp
4 | 240dp
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/ambilwarna_alphacheckered_tiled.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 240dp
4 | 240dp
5 | 30dp
6 | 8dp
7 |
8 |
--------------------------------------------------------------------------------
/demo/src/main/java/yuku/ambilwarna/demo/AmbilWarnaDemoPreferenceActivity.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna.demo;
2 |
3 | import android.os.Bundle;
4 | import android.preference.PreferenceActivity;
5 |
6 | public class AmbilWarnaDemoPreferenceActivity extends PreferenceActivity {
7 | @Override
8 | public void onCreate(Bundle savedInstanceState) {
9 | super.onCreate(savedInstanceState);
10 |
11 | addPreferencesFromResource(R.xml.demopreference);
12 | }
13 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2009-2015 Yuku
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion propCompileSdkVersion
5 |
6 | defaultConfig {
7 | minSdkVersion propMinSdkVersion
8 | targetSdkVersion propTargetSdkVersion
9 | versionCode propVersionCode
10 | versionName propVersionName
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | apply from: '../android-mvn-push.gradle'
21 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion propCompileSdkVersion
5 |
6 | defaultConfig {
7 | applicationId 'yuku.ambilwarna.demo'
8 | minSdkVersion propMinSdkVersion
9 | targetSdkVersion propTargetSdkVersion
10 | versionCode propVersionCode
11 | versionName propVersionName
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile project(':library')
23 | }
24 |
--------------------------------------------------------------------------------
/demo/src/main/res/xml/demopreference.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
11 |
16 |
--------------------------------------------------------------------------------
/demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Developer/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Developer/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/library/src/main/res/layout/ambilwarna_pref_widget.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/library/src/main/java/yuku/ambilwarna/widget/AmbilWarnaPrefWidgetView.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Paint.Style;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 |
10 | public class AmbilWarnaPrefWidgetView extends View {
11 | Paint paint;
12 | float rectSize;
13 | float strokeWidth;
14 |
15 | public AmbilWarnaPrefWidgetView(Context context, AttributeSet attrs) {
16 | super(context, attrs);
17 |
18 | float density = context.getResources().getDisplayMetrics().density;
19 | rectSize = (float) Math.floor(24.f * density + 0.5f);
20 | strokeWidth = (float) Math.floor(1.f * density + 0.5f);
21 |
22 | paint = new Paint();
23 | paint.setColor(0xffffffff);
24 | paint.setStyle(Style.STROKE);
25 | paint.setStrokeWidth(strokeWidth);
26 | }
27 |
28 | @Override protected void onDraw(Canvas canvas) {
29 | super.onDraw(canvas);
30 |
31 | canvas.drawRect(strokeWidth, strokeWidth, rectSize - strokeWidth, rectSize - strokeWidth, paint);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
19 |
20 |
24 |
25 |
29 |
30 |
--------------------------------------------------------------------------------
/library/src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.ComposeShader;
8 | import android.graphics.LinearGradient;
9 | import android.graphics.Paint;
10 | import android.graphics.PorterDuff;
11 | import android.graphics.Shader;
12 | import android.graphics.Shader.TileMode;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 |
16 | public class AmbilWarnaSquare extends View {
17 | Paint paint;
18 | Shader luar;
19 | final float[] color = { 1.f, 1.f, 1.f };
20 |
21 | public AmbilWarnaSquare(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public AmbilWarnaSquare(Context context, AttributeSet attrs, int defStyle) {
26 | super(context, attrs, defStyle);
27 | }
28 |
29 | @SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) {
30 | super.onDraw(canvas);
31 | if (paint == null) {
32 | paint = new Paint();
33 | luar = new LinearGradient(0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
34 | }
35 | int rgb = Color.HSVToColor(color);
36 | Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
37 | ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
38 | paint.setShader(shader);
39 | canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
40 | }
41 |
42 | void setHue(float hue) {
43 | color[0] = hue;
44 | invalidate();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/demo/src/main/java/yuku/ambilwarna/demo/AmbilWarnaDemoActivity.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna.demo;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 | import yuku.ambilwarna.AmbilWarnaDialog;
10 |
11 | public class AmbilWarnaDemoActivity extends Activity {
12 | TextView text1;
13 | int color = 0xffffff00;
14 |
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.main);
19 |
20 | final View button1 = findViewById(R.id.button1);
21 | final View button2 = findViewById(R.id.button2);
22 | final View button3 = findViewById(R.id.button3);
23 | text1 = (TextView) findViewById(R.id.text1);
24 | displayColor();
25 |
26 | button1.setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View v) {
29 | openDialog(false);
30 | }
31 | });
32 |
33 | button2.setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View v) {
36 | openDialog(true);
37 | }
38 | });
39 |
40 | button3.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | startActivity(new Intent(getApplicationContext(), AmbilWarnaDemoPreferenceActivity.class));
44 | }
45 | });
46 | }
47 |
48 | void openDialog(boolean supportsAlpha) {
49 | AmbilWarnaDialog dialog = new AmbilWarnaDialog(AmbilWarnaDemoActivity.this, color, supportsAlpha, new AmbilWarnaDialog.OnAmbilWarnaListener() {
50 | @Override
51 | public void onOk(AmbilWarnaDialog dialog, int color) {
52 | Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show();
53 | AmbilWarnaDemoActivity.this.color = color;
54 | displayColor();
55 | }
56 |
57 | @Override
58 | public void onCancel(AmbilWarnaDialog dialog) {
59 | Toast.makeText(getApplicationContext(), "cancel", Toast.LENGTH_SHORT).show();
60 | }
61 | });
62 | dialog.show();
63 | }
64 |
65 | void displayColor() {
66 | text1.setText(String.format("Current color: 0x%08x", color));
67 | }
68 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/android-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | if (!(hasProperty("nexusUsername") && hasProperty("nexusPassword"))) {
2 | return;
3 | }
4 |
5 | apply plugin: 'maven'
6 | apply plugin: 'signing'
7 |
8 | afterEvaluate { project ->
9 | project.version = android.defaultConfig.versionName
10 | project.group = 'com.github.yukuku'
11 |
12 | uploadArchives {
13 | repositories {
14 | mavenDeployer {
15 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
16 |
17 | pom.artifactId = 'ambilwarna'
18 |
19 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
20 | authentication(userName: nexusUsername, password: nexusPassword)
21 | }
22 |
23 | pom.project {
24 | name 'AmbilWarna'
25 | packaging 'aar'
26 | description 'Android Color Picker aka AmbilWarna library ("Pick a Color" in Indonesian)'
27 | url 'https://github.com/yukuku/ambilwarna'
28 |
29 | scm {
30 | url 'https://github.com/yukuku/ambilwarna'
31 | connection 'scm:git@github.com:yukuku/ambilwarna.git'
32 | developerConnection 'scm:git@github.com:yukuku/ambilwarna.git'
33 | }
34 |
35 | licenses {
36 | license {
37 | name 'The Apache Software License, Version 2.0'
38 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
39 | distribution 'repo'
40 | }
41 | }
42 |
43 | developers {
44 | developer {
45 | id 'yukuku'
46 | name 'yukuku'
47 | }
48 | }
49 | }
50 | }
51 | }
52 | }
53 |
54 | signing {
55 | required { gradle.taskGraph.hasTask("uploadArchives") }
56 | sign configurations.archives
57 | }
58 |
59 | task androidJavadocs(type: Javadoc) {
60 | source = android.sourceSets.main.java.srcDirs
61 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
62 |
63 | options {
64 | linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
65 | }
66 | }
67 |
68 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
69 | classifier = 'javadoc'
70 | from androidJavadocs.destinationDir
71 | }
72 |
73 | task androidSourcesJar(type: Jar) {
74 | classifier = 'sources'
75 | from android.sourceSets.main.java.srcDirs
76 | }
77 |
78 | artifacts {
79 | archives androidSourcesJar
80 | archives androidJavadocsJar
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | Android Color Picker
4 | ====================
5 |
6 | [](https://maven-badges.herokuapp.com/maven-central/com.github.yukuku/ambilwarna)
7 |
8 | aka `AmbilWarna` library ("Pick a Color" in Indonesian)
9 |
10 | moved from http://code.google.com/p/yuku-android-util/
11 |
12 | This is a small library for your application to enable the users to select an arbitrary color. It is used in the free Bible applications for Android (http://www.bibleforandroid.com).
13 |
14 | It is also used by:
15 | * 1,000,000+ downloads app DigiClock Widget
16 | * 100,000+ downloads app Banner
17 | * 10,000+ downloads app Memento
18 |
19 | If your application has a feature to customize the color of some background, text, or maybe for a painting application where the user can select different colors for painting or filling, then `AmbilWarna` is suitable for you.
20 |
21 |
22 | Adding it to your project
23 | ===========
24 |
25 | Android Studio 3.0 and above:
26 |
27 | ```groovy
28 | dependencies {
29 | implementation 'com.github.yukuku:ambilwarna:2.0.1'
30 | }
31 | ```
32 |
33 | Android Studio 2.3.* and lower:
34 |
35 | ```groovy
36 | dependencies {
37 | compile 'com.github.yukuku:ambilwarna:2.0.1'
38 | }
39 | ```
40 |
41 | Screenshots
42 | ===========
43 |
44 |
45 |
46 |
47 | How to use the dialog
48 | =====================
49 |
50 | Create a color picker dialog by calling the following constructor, and then show it.
51 |
52 | AmbilWarnaDialog(Context context, int color, OnAmbilWarnaListener listener)
53 |
54 | Alpha is also supported by passing the 3rd parameter `supportsAlpha`:
55 |
56 | AmbilWarnaDialog(Context context, int color, boolean supportsAlpha, OnAmbilWarnaListener listener)
57 |
58 | Example:
59 |
60 | // initialColor is the initially-selected color to be shown in the rectangle on the left of the arrow.
61 | // for example, 0xff000000 is black, 0xff0000ff is blue. Please be aware of the initial 0xff which is the alpha.
62 | AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, initialColor, new OnAmbilWarnaListener() {
63 | @Override
64 | public void onOk(AmbilWarnaDialog dialog, int color) {
65 | // color is the color selected by the user.
66 | }
67 |
68 | @Override
69 | public void onCancel(AmbilWarnaDialog dialog) {
70 | // cancel was selected by the user
71 | }
72 |
73 | dialog.show();
74 |
75 | How to use it as a Preference
76 | =============================
77 |
78 | 
79 |
80 | Very simple. It works like a `DialogPreference` that stores an Integer to the shared preferences file.
81 |
82 | Just add the following to the preferences xml file.
83 |
84 |
88 |
89 | To enable alpha, use the application attribute `supportsAlpha`, as follows:
90 |
91 |
94 |
95 |
100 |
101 |
102 | Contributors
103 | ============
104 |
105 | * Pascal Cans (noobs.com)
106 | * Justin Warner (One Rainboot Studio)
107 | * Logo design by [anaufalm](https://github.com/anaufalm)
108 |
109 |
--------------------------------------------------------------------------------
/library/src/main/java/yuku/ambilwarna/widget/AmbilWarnaPreference.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.os.Parcel;
6 | import android.os.Parcelable;
7 | import android.preference.Preference;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import yuku.ambilwarna.AmbilWarnaDialog;
12 | import yuku.ambilwarna.R;
13 |
14 | public class AmbilWarnaPreference extends Preference {
15 | private final boolean supportsAlpha;
16 | int value;
17 |
18 | public AmbilWarnaPreference(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 |
21 | final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AmbilWarnaPreference);
22 | supportsAlpha = ta.getBoolean(R.styleable.AmbilWarnaPreference_supportsAlpha, false);
23 |
24 | setWidgetLayoutResource(R.layout.ambilwarna_pref_widget);
25 | }
26 |
27 | @Override protected void onBindView(View view) {
28 | super.onBindView(view);
29 |
30 | // Set our custom views inside the layout
31 | final View box = view.findViewById(R.id.ambilwarna_pref_widget_box);
32 | if (box != null) {
33 | box.setBackgroundColor(value);
34 | }
35 | }
36 |
37 | @Override protected void onClick() {
38 | new AmbilWarnaDialog(getContext(), value, supportsAlpha, new AmbilWarnaDialog.OnAmbilWarnaListener() {
39 | @Override public void onOk(AmbilWarnaDialog dialog, int color) {
40 | if (!callChangeListener(color)) return; // They don't want the value to be set
41 | value = color;
42 | persistInt(value);
43 | notifyChanged();
44 | }
45 |
46 | @Override public void onCancel(AmbilWarnaDialog dialog) {
47 | // nothing to do
48 | }
49 | }).show();
50 | }
51 |
52 | public void forceSetValue(int value) {
53 | this.value = value;
54 | persistInt(value);
55 | notifyChanged();
56 | }
57 |
58 | @Override protected Object onGetDefaultValue(TypedArray a, int index) {
59 | // This preference type's value type is Integer, so we read the default value from the attributes as an Integer.
60 | return a.getInteger(index, 0);
61 | }
62 |
63 | @Override protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
64 | if (restoreValue) { // Restore state
65 | value = getPersistedInt(value);
66 | } else { // Set state
67 | int value = (Integer) defaultValue;
68 | this.value = value;
69 | persistInt(value);
70 | }
71 | }
72 |
73 | /*
74 | * Suppose a client uses this preference type without persisting. We
75 | * must save the instance state so it is able to, for example, survive
76 | * orientation changes.
77 | */
78 | @Override protected Parcelable onSaveInstanceState() {
79 | final Parcelable superState = super.onSaveInstanceState();
80 | if (isPersistent()) return superState; // No need to save instance state since it's persistent
81 |
82 | final SavedState myState = new SavedState(superState);
83 | myState.value = value;
84 | return myState;
85 | }
86 |
87 | @Override protected void onRestoreInstanceState(Parcelable state) {
88 | if (!state.getClass().equals(SavedState.class)) {
89 | // Didn't save state for us in onSaveInstanceState
90 | super.onRestoreInstanceState(state);
91 | return;
92 | }
93 |
94 | // Restore the instance state
95 | SavedState myState = (SavedState) state;
96 | super.onRestoreInstanceState(myState.getSuperState());
97 | this.value = myState.value;
98 | notifyChanged();
99 | }
100 |
101 | /**
102 | * SavedState, a subclass of {@link android.preference.Preference.BaseSavedState}, will store the state
103 | * of MyPreference, a subclass of Preference.
104 | *
105 | * It is important to always call through to super methods.
106 | */
107 | private static class SavedState extends BaseSavedState {
108 | int value;
109 |
110 | public SavedState(Parcel source) {
111 | super(source);
112 | value = source.readInt();
113 | }
114 |
115 | @Override public void writeToParcel(Parcel dest, int flags) {
116 | super.writeToParcel(dest, flags);
117 | dest.writeInt(value);
118 | }
119 |
120 | public SavedState(Parcelable superState) {
121 | super(superState);
122 | }
123 |
124 | @SuppressWarnings("unused") public static final Creator CREATOR = new Creator() {
125 | public SavedState createFromParcel(Parcel in) {
126 | return new SavedState(in);
127 | }
128 |
129 | public SavedState[] newArray(int size) {
130 | return new SavedState[size];
131 | }
132 | };
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/library/src/main/res/layout-land/ambilwarna_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
24 |
27 |
28 |
32 |
33 |
38 |
39 |
40 |
47 |
50 |
51 |
55 |
56 |
61 |
62 |
63 |
70 |
72 |
77 |
86 |
87 |
95 |
96 |
102 |
103 |
110 |
111 |
117 |
118 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/ambilwarna_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
24 |
25 |
33 |
34 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
70 |
71 |
80 |
81 |
84 |
85 |
89 |
90 |
95 |
96 |
97 |
103 |
104 |
107 |
108 |
112 |
113 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/library/src/main/java/yuku/ambilwarna/AmbilWarnaDialog.java:
--------------------------------------------------------------------------------
1 | package yuku.ambilwarna;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.DialogInterface.OnCancelListener;
7 | import android.graphics.Color;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.ViewTreeObserver;
14 | import android.widget.ImageView;
15 | import android.widget.RelativeLayout;
16 |
17 | public class AmbilWarnaDialog {
18 | public interface OnAmbilWarnaListener {
19 | void onCancel(AmbilWarnaDialog dialog);
20 |
21 | void onOk(AmbilWarnaDialog dialog, int color);
22 | }
23 |
24 | final AlertDialog dialog;
25 | private final boolean supportsAlpha;
26 | final OnAmbilWarnaListener listener;
27 | final View viewHue;
28 | final AmbilWarnaSquare viewSatVal;
29 | final ImageView viewCursor;
30 | final ImageView viewAlphaCursor;
31 | final View viewOldColor;
32 | final View viewNewColor;
33 | final View viewAlphaOverlay;
34 | final ImageView viewTarget;
35 | final ImageView viewAlphaCheckered;
36 | final ViewGroup viewContainer;
37 | final float[] currentColorHsv = new float[3];
38 | int alpha;
39 |
40 | /**
41 | * Create an AmbilWarnaDialog.
42 | *
43 | * @param context activity context
44 | * @param color current color
45 | * @param listener an OnAmbilWarnaListener, allowing you to get back error or OK
46 | */
47 | public AmbilWarnaDialog(final Context context, int color, OnAmbilWarnaListener listener) {
48 | this(context, color, false, listener);
49 | }
50 |
51 | /**
52 | * Create an AmbilWarnaDialog.
53 | *
54 | * @param context activity context
55 | * @param color current color
56 | * @param supportsAlpha whether alpha/transparency controls are enabled
57 | * @param listener an OnAmbilWarnaListener, allowing you to get back error or OK
58 | */
59 | public AmbilWarnaDialog(final Context context, int color, boolean supportsAlpha, OnAmbilWarnaListener listener) {
60 | this.supportsAlpha = supportsAlpha;
61 | this.listener = listener;
62 |
63 | if (!supportsAlpha) { // remove alpha if not supported
64 | color = color | 0xff000000;
65 | }
66 |
67 | Color.colorToHSV(color, currentColorHsv);
68 | alpha = Color.alpha(color);
69 |
70 | final View view = LayoutInflater.from(context).inflate(R.layout.ambilwarna_dialog, null);
71 | viewHue = view.findViewById(R.id.ambilwarna_viewHue);
72 | viewSatVal = (AmbilWarnaSquare) view.findViewById(R.id.ambilwarna_viewSatBri);
73 | viewCursor = (ImageView) view.findViewById(R.id.ambilwarna_cursor);
74 | viewOldColor = view.findViewById(R.id.ambilwarna_oldColor);
75 | viewNewColor = view.findViewById(R.id.ambilwarna_newColor);
76 | viewTarget = (ImageView) view.findViewById(R.id.ambilwarna_target);
77 | viewContainer = (ViewGroup) view.findViewById(R.id.ambilwarna_viewContainer);
78 | viewAlphaOverlay = view.findViewById(R.id.ambilwarna_overlay);
79 | viewAlphaCursor = (ImageView) view.findViewById(R.id.ambilwarna_alphaCursor);
80 | viewAlphaCheckered = (ImageView) view.findViewById(R.id.ambilwarna_alphaCheckered);
81 |
82 | { // hide/show alpha
83 | viewAlphaOverlay.setVisibility(supportsAlpha? View.VISIBLE: View.GONE);
84 | viewAlphaCursor.setVisibility(supportsAlpha? View.VISIBLE: View.GONE);
85 | viewAlphaCheckered.setVisibility(supportsAlpha? View.VISIBLE: View.GONE);
86 | }
87 |
88 | viewSatVal.setHue(getHue());
89 | viewOldColor.setBackgroundColor(color);
90 | viewNewColor.setBackgroundColor(color);
91 |
92 | viewHue.setOnTouchListener(new View.OnTouchListener() {
93 | @Override
94 | public boolean onTouch(View v, MotionEvent event) {
95 | if (event.getAction() == MotionEvent.ACTION_MOVE
96 | || event.getAction() == MotionEvent.ACTION_DOWN
97 | || event.getAction() == MotionEvent.ACTION_UP) {
98 |
99 | float y = event.getY();
100 | if (y < 0.f) y = 0.f;
101 | if (y > viewHue.getMeasuredHeight()) {
102 | y = viewHue.getMeasuredHeight() - 0.001f; // to avoid jumping the cursor from bottom to top.
103 | }
104 | float hue = 360.f - 360.f / viewHue.getMeasuredHeight() * y;
105 | if (hue == 360.f) hue = 0.f;
106 | setHue(hue);
107 |
108 | // update view
109 | viewSatVal.setHue(getHue());
110 | moveCursor();
111 | viewNewColor.setBackgroundColor(getColor());
112 | updateAlphaView();
113 | return true;
114 | }
115 | return false;
116 | }
117 | });
118 |
119 | if (supportsAlpha) viewAlphaCheckered.setOnTouchListener(new View.OnTouchListener() {
120 | @Override
121 | public boolean onTouch(View v, MotionEvent event) {
122 | if ((event.getAction() == MotionEvent.ACTION_MOVE)
123 | || (event.getAction() == MotionEvent.ACTION_DOWN)
124 | || (event.getAction() == MotionEvent.ACTION_UP)) {
125 |
126 | float y = event.getY();
127 | if (y < 0.f) {
128 | y = 0.f;
129 | }
130 | if (y > viewAlphaCheckered.getMeasuredHeight()) {
131 | y = viewAlphaCheckered.getMeasuredHeight() - 0.001f; // to avoid jumping the cursor from bottom to top.
132 | }
133 | final int a = Math.round(255.f - ((255.f / viewAlphaCheckered.getMeasuredHeight()) * y));
134 | AmbilWarnaDialog.this.setAlpha(a);
135 |
136 | // update view
137 | moveAlphaCursor();
138 | int col = AmbilWarnaDialog.this.getColor();
139 | int c = a << 24 | col & 0x00ffffff;
140 | viewNewColor.setBackgroundColor(c);
141 | return true;
142 | }
143 | return false;
144 | }
145 | });
146 | viewSatVal.setOnTouchListener(new View.OnTouchListener() {
147 | @Override
148 | public boolean onTouch(View v, MotionEvent event) {
149 | if (event.getAction() == MotionEvent.ACTION_MOVE
150 | || event.getAction() == MotionEvent.ACTION_DOWN
151 | || event.getAction() == MotionEvent.ACTION_UP) {
152 |
153 | float x = event.getX(); // touch event are in dp units.
154 | float y = event.getY();
155 |
156 | if (x < 0.f) x = 0.f;
157 | if (x > viewSatVal.getMeasuredWidth()) x = viewSatVal.getMeasuredWidth();
158 | if (y < 0.f) y = 0.f;
159 | if (y > viewSatVal.getMeasuredHeight()) y = viewSatVal.getMeasuredHeight();
160 |
161 | setSat(1.f / viewSatVal.getMeasuredWidth() * x);
162 | setVal(1.f - (1.f / viewSatVal.getMeasuredHeight() * y));
163 |
164 | // update view
165 | moveTarget();
166 | viewNewColor.setBackgroundColor(getColor());
167 |
168 | return true;
169 | }
170 | return false;
171 | }
172 | });
173 |
174 | dialog = new AlertDialog.Builder(context)
175 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
176 | @Override
177 | public void onClick(DialogInterface dialog, int which) {
178 | if (AmbilWarnaDialog.this.listener != null) {
179 | AmbilWarnaDialog.this.listener.onOk(AmbilWarnaDialog.this, getColor());
180 | }
181 | }
182 | })
183 | .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
184 | @Override
185 | public void onClick(DialogInterface dialog, int which) {
186 | if (AmbilWarnaDialog.this.listener != null) {
187 | AmbilWarnaDialog.this.listener.onCancel(AmbilWarnaDialog.this);
188 | }
189 | }
190 | })
191 | .setOnCancelListener(new OnCancelListener() {
192 | // if back button is used, call back our listener.
193 | @Override
194 | public void onCancel(DialogInterface paramDialogInterface) {
195 | if (AmbilWarnaDialog.this.listener != null) {
196 | AmbilWarnaDialog.this.listener.onCancel(AmbilWarnaDialog.this);
197 | }
198 |
199 | }
200 | })
201 | .create();
202 | // kill all padding from the dialog window
203 | dialog.setView(view, 0, 0, 0, 0);
204 |
205 | // move cursor & target on first draw
206 | ViewTreeObserver vto = view.getViewTreeObserver();
207 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
208 | @Override
209 | public void onGlobalLayout() {
210 | moveCursor();
211 | if (AmbilWarnaDialog.this.supportsAlpha) moveAlphaCursor();
212 | moveTarget();
213 | if (AmbilWarnaDialog.this.supportsAlpha) updateAlphaView();
214 | view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
215 | }
216 | });
217 | }
218 |
219 | protected void moveCursor() {
220 | float y = viewHue.getMeasuredHeight() - (getHue() * viewHue.getMeasuredHeight() / 360.f);
221 | if (y == viewHue.getMeasuredHeight()) y = 0.f;
222 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) viewCursor.getLayoutParams();
223 | layoutParams.leftMargin = (int) (viewHue.getLeft() - Math.floor(viewCursor.getMeasuredWidth() / 2) - viewContainer.getPaddingLeft());
224 | layoutParams.topMargin = (int) (viewHue.getTop() + y - Math.floor(viewCursor.getMeasuredHeight() / 2) - viewContainer.getPaddingTop());
225 | viewCursor.setLayoutParams(layoutParams);
226 | }
227 |
228 | protected void moveTarget() {
229 | float x = getSat() * viewSatVal.getMeasuredWidth();
230 | float y = (1.f - getVal()) * viewSatVal.getMeasuredHeight();
231 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) viewTarget.getLayoutParams();
232 | layoutParams.leftMargin = (int) (viewSatVal.getLeft() + x - Math.floor(viewTarget.getMeasuredWidth() / 2) - viewContainer.getPaddingLeft());
233 | layoutParams.topMargin = (int) (viewSatVal.getTop() + y - Math.floor(viewTarget.getMeasuredHeight() / 2) - viewContainer.getPaddingTop());
234 | viewTarget.setLayoutParams(layoutParams);
235 | }
236 |
237 | protected void moveAlphaCursor() {
238 | final int measuredHeight = this.viewAlphaCheckered.getMeasuredHeight();
239 | float y = measuredHeight - ((this.getAlpha() * measuredHeight) / 255.f);
240 | final RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.viewAlphaCursor.getLayoutParams();
241 | layoutParams.leftMargin = (int) (this.viewAlphaCheckered.getLeft() - Math.floor(this.viewAlphaCursor.getMeasuredWidth() / 2) - this.viewContainer.getPaddingLeft());
242 | layoutParams.topMargin = (int) ((this.viewAlphaCheckered.getTop() + y) - Math.floor(this.viewAlphaCursor.getMeasuredHeight() / 2) - this.viewContainer.getPaddingTop());
243 |
244 | this.viewAlphaCursor.setLayoutParams(layoutParams);
245 | }
246 |
247 | private int getColor() {
248 | final int argb = Color.HSVToColor(currentColorHsv);
249 | return alpha << 24 | (argb & 0x00ffffff);
250 | }
251 |
252 | private float getHue() {
253 | return currentColorHsv[0];
254 | }
255 |
256 | private float getAlpha() {
257 | return this.alpha;
258 | }
259 |
260 | private float getSat() {
261 | return currentColorHsv[1];
262 | }
263 |
264 | private float getVal() {
265 | return currentColorHsv[2];
266 | }
267 |
268 | private void setHue(float hue) {
269 | currentColorHsv[0] = hue;
270 | }
271 |
272 | private void setSat(float sat) {
273 | currentColorHsv[1] = sat;
274 | }
275 |
276 | private void setAlpha(int alpha) {
277 | this.alpha = alpha;
278 | }
279 |
280 | private void setVal(float val) {
281 | currentColorHsv[2] = val;
282 | }
283 |
284 | public void show() {
285 | dialog.show();
286 | }
287 |
288 | public AlertDialog getDialog() {
289 | return dialog;
290 | }
291 |
292 | private void updateAlphaView() {
293 | final GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
294 | Color.HSVToColor(currentColorHsv), 0x0
295 | });
296 | viewAlphaOverlay.setBackgroundDrawable(gd);
297 | }
298 | }
299 |
--------------------------------------------------------------------------------