diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..376f7bb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true +[*] +# Most of the standard properties are supported +indent_size=2 +max_line_length=100 \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 6c24897..fe90718 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ github: skydoves -custom: ["https://www.paypal.me/skydoves", "https://www.buymeacoffee.com/skydoves"] +custom: ["https://www.android.skydoves.me/", "https://kotlin.skydoves.me/", "https://github.com/doveletter"] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0377071 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gradle" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index e47cef2..d67397f 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,24 +1,51 @@ name: Android CI on: - push: - branches: - - master + push: + branches: [ main ] + pull_request: + branches: [ main ] jobs: - build: - + lint: + name: Spotless check runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: adopt + java-version: 17 + - name: spotless + run: ./gradlew spotlessCheck + build: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Make Gradle executable - run: chmod +x ./gradlew - - name: Build with Gradle - run: ./gradlew build - - name: Build Debug APK - run: ./gradlew assembleDebug + - uses: actions/checkout@v4 + + - name: set up JDK + uses: actions/setup-java@v4 + with: + distribution: adopt + java-version: 17 + + - name: Cache Gradle and wrapper + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Make Gradle executable + run: chmod +x ./gradlew + + - name: Build with Gradle + run: | + ./gradlew --scan --stacktrace \ + assemble -x :benchmark:pixel6api31Setup -x :benchmark:pixel6api31NonMinifiedReleaseAndroidTest -x :benchmark:collectNonMinifiedReleaseBaselineProfile diff --git a/.github/workflows/baseline-profile.yml b/.github/workflows/baseline-profile.yml new file mode 100644 index 0000000..274642f --- /dev/null +++ b/.github/workflows/baseline-profile.yml @@ -0,0 +1,75 @@ +# Workflow name +name: baseline-profiles + +# Workflow title +run-name: ${{ github.actor }} requested a workflow + +# This should be a manual trigger so this actions gets executed every time make a new pull request. +# Change this event to what suits your project best. +# Read more at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows +on: + workflow_dispatch: + +# Environment variables (Optional) +# Small projects might have signingConfigs locally. This could lead to failures on GitHub Actions. +# If that's the case, upload your properties defined locally to GitHub Secrets. + +# On your signingConfigs, you can recover GitHub Secrets using: variable = System.getenv("VARIABLE") + +# Then uncomment this block properly defining your uploaded variables +# env: +# VARIABLE: ${{ secrets.VARIABLE }} + +# Read more at https://docs.github.com/en/actions/security-guides/encrypted-secrets + +# Jobs to executed on GitHub machines +jobs: + + # Job name + generate-baseline-profiles: + + # Operating system where the job gets to be executed + runs-on: macos-latest + + # Job steps + steps: + + # Checks your code out on the machine + - uses: actions/checkout@v4 + + # Sets java up + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + # Sets gradle up + - name: Setup Gradle + uses: gradle/gradle-build-action@v3.5.0 + + # Grants execute permission to gradle (safety step) + - name: Grant Permissions to gradlew + run: chmod +x gradlew + + # This allows us to build most of what we need without the emulator running + # and using resources + - name: Build app and benchmark + run: ./gradlew :app:assembleBenchmark + + # Cleans managed device if previously settle and space currently is not available + - name: Clean Managed Devices + run: ./gradlew cleanManagedDevices --unused-only + + # Generates Baseline Profile + - name: Generate Baseline Profile + run: ./gradlew generateBaselineProfile -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile -Pandroid.experimental.testOptions.managedDevices.setupTimeoutMinutes=20 -Dorg.gradle.workers.max=4 + + # Create Pull Request + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + commit-message: "Generate baseline profiles" + title: "Generate baseline profiles" + delete-branch: true + reviewers: skydoves + branch: actions/baseline-profiles diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml new file mode 100644 index 0000000..f1a9555 --- /dev/null +++ b/.github/workflows/publish-docs.yml @@ -0,0 +1,26 @@ +name: Publish Docs +on: + push: + branches: + - main + +permissions: + contents: write + +jobs: + deploy: + runs-on: macos-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: 3.x + - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + - uses: actions/cache@v5 + with: + key: mkdocs-material-${{ env.cache_id }} + path: .cache + restore-keys: | + mkdocs-material- + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..88f0a3c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,36 @@ +name: Publish + +on: + release: + types: [ released ] + workflow_dispatch: + +jobs: + publish: + name: Snapshot build and publish + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 17 + + - name: Grant Permission to Execute Gradle + run: chmod +x gradlew + + - name: Release build + run: ./gradlew assemble --scan -x :benchmark:pixel6api31Setup -x :benchmark:pixel6api31NonMinifiedReleaseAndroidTest -x :benchmark:collectNonMinifiedReleaseBaselineProfile + + - name: Publish to MavenCentral + run: | + ./gradlew publishAllPublicationsToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} diff --git a/.gitignore b/.gitignore index 79dcce7..3e50cba 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ # Java class files *.class +# Kotlin +.kotlin + # Generated files bin/ gen/ @@ -40,6 +43,10 @@ captures/ .idea/gradle.xml .idea/dictionaries .idea/libraries +app/.idea/ + +# Mac +*.DS_Store # Keystore files *.jks @@ -53,4 +60,7 @@ google-services.json # Freeline freeline.py freeline/ -freeline_project_description.json \ No newline at end of file +freeline_project_description.json + +# MkDocs +site/ diff --git a/README.md b/README.md index 0146ccb..d77ca32 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@

ColorPickerView


-🎨 ColorPickerView implements getting HSV colors, ARGB values, Hex color codes from
-any image drawables or your gallery pictures by tapping on the desired color.
-Supports alpha & brightness slider bar, dialog, and saving & restoring selected data. +🎨 ColorPickerView enables you to obtain HSV colors, ARGB values, and Hex color codes from image drawables or your gallery pictures with a simple tap on the desired color. It offers additional features such as alpha and brightness slider bars, dialog support, and the ability to save and restore selected data.


+ Google
License - API + API Build Status - Codacy Android Weekly Javadoc


@@ -20,23 +18,20 @@ Supports alpha & brightness slider bar, dialog, and saving & restoring selected

+## ColorPicker Compose + +If you're looking to implement a color picker in your Compose project, you can use [colorpicker-compose](https://github.com/skydoves/colorpicker-compose) instead. + ## Including in your project -[![Download](https://api.bintray.com/packages/devmagician/maven/colorpickerview/images/download.svg) ](https://bintray.com/devmagician/maven/colorpickerview/_latestVersion) [![Maven Central](https://img.shields.io/maven-central/v/com.github.skydoves/colorpickerview.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.skydoves%22%20AND%20a:%22colorpickerview%22) -[![Jitpack](https://jitpack.io/v/skydoves/ColorPickerView.svg)](https://jitpack.io/#skydoves/ColorPickerView) + ### Gradle -Add below codes to your **root** `build.gradle` file (not your module build.gradle file). -```gradle -allprojects { - repositories { - jcenter() - } -} -``` -And add below dependency code to your **module**'s `build.gradle` file. + +Add the dependency below to your module's `build.gradle` file: + ```gradle dependencies { - implementation "com.github.skydoves:colorpickerview:2.2.2" + implementation("com.github.skydoves:colorpickerview:2.4.0") } ``` @@ -62,15 +57,16 @@ __[7. ColorPickerView Methods](https://github.com/skydoves/ColorPickerView#color __[8. Other Libraries](https://github.com/skydoves/ColorPickerView#other-libraries)__
## Usage -Add following XML namespace inside your XML layout file. +Add the following XML namespace inside your XML layout file. ```gradle xmlns:app="http://schemas.android.com/apk/res-auto" ``` ### ColorPickerView in XML layout -We can use `ColorPickerView` without any customized attributes.
-This `ColorPickerView` will be initialized with the default HSV color palette and default selector. + +You can simply use `ColorPickerView` by defining it on your XML files. This `ColorPickerView` will be initialized with the default HSV color palette and the default selector. + ```gradle ``` -### Attribute descriptions -We can customize the palette image and selector or various options using the below attributes. +### Attributes + +You can customize the palette image and selector or various options using the below attributes: + ```gradle app:palette="@drawable/palette" // sets a custom palette image. -app:selector="@drawable/wheel" // sets a custom selector image. +app:selector="@drawable/colorpickerview_wheel" // sets a custom selector image. app:selector_size="32dp" // sets a width & height size of the selector. -app:alpha_selector="0.8" // sets an alpha of thr selector. +app:alpha_selector="0.8" // sets an alpha of the selector. app:alpha_flag="0.8" // sets an alpha of the flag. app:actionMode="last" // sets action mode 'always' or 'last'. // set an initial position of the selector using a specific color. This attribute will work with only a default HSV palette. @@ -94,7 +92,8 @@ app:debounceDuration="200" // sets a debounce duration of the invoking color lis ``` ### ColorListener -`ColorListener` is invoked when tapped by a user or selected a position by a function. +`ColorListener` is triggered when a user taps the `ColorPickerView` or when a position is selected using a function. + ```java colorPickerView.setColorListener(new ColorListener() { @Override @@ -106,8 +105,8 @@ colorPickerView.setColorListener(new ColorListener() { ``` ### ColorEnvelope -`ColorEnvelope` is a wrapper class of color models for providing more variety of color models.
-We can get HSV color value, Hex string code, ARGB value from the `ColorEnvelope`. +`ColorEnvelope` is a versatile wrapper class for color models, offering a wide range of color-related data. It provides access to HSV color values, Hex string codes, and ARGB values. + ```java colorEnvelope.getColor() // returns a integer color. colorEnvelope.getHexCode() // returns a hex code string. @@ -115,7 +114,8 @@ colorEnvelope.getArgb() // returns a argb integer array. ``` ### ColorEnvelope Listener -`ColorEnvelopeListener` extends `ColorListener` and it provides `ColorEnvelope` as a parameter. +`ColorEnvelopeListener` extends `ColorListener` and offers `ColorEnvelope` as a parameter, granting access to a variety of color values. + ```java colorPickerView.setColorListener(new ColorEnvelopeListener() { @Override @@ -127,45 +127,56 @@ colorPickerView.setColorListener(new ColorEnvelopeListener() { ``` ### Palette -If we do not set any customized palette, the default palette drawable is the `ColorHsvPalette`.
-We can move and select a point on the palette using a specific color using the below methods. +If you do not set any custom palette, the default palette will be the `ColorHsvPalette`.
+You can manually select a specific point for the selector by specifying a particular color value using the following methods: + ```java colorPickerView.selectByHsvColor(color); colorPickerView.selectByHsvColorRes(R.color.colorPrimary); ``` -We can change the default palette as a desired image drawable using the below method.
-But if we change the palette using another drawable, we can not use the `selectByHsvColor` method. + +You can change the default palette as a desired image drawable using the method below:
+ ```java colorPickerView.setPaletteDrawable(drawable); ``` -If we want to change back to the default palette, we can change it using the below method. + +If you wish to revert to the default HSV palette, you can do so using the method below: + ```java colorPickerView.setHsvPaletteDrawable(); ``` ### ActionMode -`ActionMode` is an option restrict to invoke the `ColorListener` by user actions. + +`ActionMode` is an option that restricts the invocation of the ColorListener based on user actions. + ```java colorPickerView.setActionMode(ActionMode.LAST); // ColorListener will be invoked when the finger is released. ``` ### Debounce -Only emits color values to the listener if a particular timespan has passed without it emitting using `debounceDuration` attribute. -We can set the `debounceDuration` on our xml layout file. + +If you want to emit color values to the listener with a particular delay, you can utilize `debounceDuration` attribute in your XML layout file: + ```xml -app:debounceDuration="150" +app:debounceDuration="150" ``` -Or we can set it programmatically. + +Or you can set it programmatically. + ```java colorPickerView.setDebounceDuration(150); ``` ### Create using builder -This is how to create `ColorPickerView`'s instance using `ColorPickerView.Builder` class. + +You can create an instance of `ColorPickerView` using `ColorPickerView.Builder` class like the example below: + ```java ColorPickerView colorPickerView = new ColorPickerView.Builder(context) .setColorListener(colorListener) - .setPreferenceName("MyColorPicker"); + .setPreferenceName("MyColorPicker") .setActionMode(ActionMode.LAST) .setAlphaSlideBar(alphaSlideBar) .setBrightnessSlideBar(brightnessSlideBar) @@ -176,19 +187,21 @@ ColorPickerView colorPickerView = new ColorPickerView.Builder(context) ``` ### Initial color -We can set an initial color and set positions of selector and slideBars based on the initial color.
-This function will work only with a default HSV palette.
-If we set preference name using the `setPreferenceName` method, this function will work only once. +You can define an initial color and position the selector and slide bars based on that initial color. Please note that this function is compatible only with the default HSV palette. Additionally, if you set a preference name using the `setPreferenceName` method, this function will work only once. + ```gradle app:initialColor="@color/colorPrimary" ``` -Or we can use this method programmatically. + +Or you can use this method programmatically. + ```java .setInitialColor(color); .setInitialColorRes(R.color.colorPrimary); ``` ### Restore and save + This is how to restore the state of `ColorPickerView`.
`setPreferenceName()` method restores all of the saved states (selector, color) automatically. @@ -197,17 +210,21 @@ colorPickerView.setPreferenceName("MyColorPicker"); ``` This is how to save the states of `ColorPickerView`.
-`setLifecycleOwner()` method saves all of the states automatically when the lifecycleOwner is destroy. +The `setLifecycleOwner()` method saves all of the states automatically when the `lifecycleOwner` is destroyed. + ```java colorPickerView.setLifecycleOwner(this); ``` -Or we can save the states manually using the below method. + +Or you can save the states manually using the method below: + ```java ColorPickerPreferenceManager.getInstance(this).saveColorPickerData(colorPickerView); ``` ### Manipulate and clear -We can manipulate and clear the saved states using `ColorPickerPreferenceManager`. +You can manipulate and clear the saved states using `ColorPickerPreferenceManager`. + ```java ColorPickerPreferenceManager manager = ColorPickerPreferenceManager.getInstance(this); manager.setColor("MyColorPicker", Color.RED); // manipulates the saved color data. @@ -218,20 +235,26 @@ manager.restoreColorPickerData(colorPickerView); // restores the saved states ma ``` ### Palette from Gallery -Here is how to get a bitmap drawable from the gallery image and set it to the palette.

+Here is an example of how to get a bitmap drawable from the gallery image and set it to the palette.

+ -Declare below permission on your `AndroidManifest.xml` file. +Declare the permission below on your `AndroidManifest.xml` file: + ```gradle ``` -The below codes will start the Gallery and we can choose the desired image. + +The codes below will start the Gallery and you can choose any desired images: + ```java Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY); ``` -In the `onActivityResult`, we can get a bitmap drawable from the gallery and set it as the palette. And We can change the palette image of the `ColorPickerView` using the `setPaletteDrawable` method. + +In the `onActivityResult`, you can get a bitmap drawable from the gallery and set it as the palette. You can also change the palette image of the `ColorPickerView` using the `setPaletteDrawable` method. + ```java try { final Uri imageUri = data.getData(); @@ -245,7 +268,8 @@ try { ``` ## AlphaSlideBar -AlphaSlideBar changes the transparency of the selected color.

+ +`AlphaSlideBar` adjusts the transparency value of the selected color.

`AlphaSlideBar` in XML layout @@ -254,17 +278,20 @@ AlphaSlideBar changes the transparency of the selected color.

android:id="@+id/alphaSlideBar" android:layout_width="match_parent" android:layout_height="wrap_content" - app:selector_AlphaSlideBar="@drawable/wheel" // sets a customized selector drawable. + app:selector_AlphaSlideBar="@drawable/colorpickerview_wheel" // sets a customized selector drawable. app:borderColor_AlphaSlideBar="@android:color/darker_gray" // sets a color of the border. app:borderSize_AlphaSlideBar="5"/> // sets a size of the border. ``` -We can attach and connect the `AlphaSlideBar` to our `ColorPickerView` using `attachAlphaSlider` method. + +You can attach and connect the `AlphaSlideBar` to your `ColorPickerView` using the `attachAlphaSlider` method. ```java AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar); colorPickerView.attachAlphaSlider(alphaSlideBar); ``` -We can make it vertically using the below attributes. + +If you want to implement a vertical style of sliders, you can achieve it with the `rotation` attributes. + ```gradle android:layout_width="280dp" // width must set a specific width size. android:layout_height="wrap_content" @@ -272,7 +299,8 @@ android:rotation="90" ``` ## BrightnessSlideBar -BrightnessSlideBar changes the brightness of the selected color.

+ +`BrightnessSlideBar` adjusts the brightness of the selected color.

`BrightnessSlideBar` in XML layout @@ -281,17 +309,20 @@ BrightnessSlideBar changes the brightness of the selected color.

android:id="@+id/brightnessSlide" android:layout_width="match_parent" android:layout_height="wrap_content" - app:selector_BrightnessSlider="@drawable/wheel" // sets a customized selector drawable. + app:selector_BrightnessSlider="@drawable/colorpickerview_wheel" // sets a customized selector drawable. app:borderColor_BrightnessSlider="@android:color/darker_gray" // sets a color of the border. app:borderSize_BrightnessSlider="5"/> // sets a size of the border. ``` -We can attach and connect the `BrightnessSlideBar` to our `ColorPickerView` using `attachBrightnessSlider` method. + +You can attach and connect the `BrightnessSlideBar` to your `ColorPickerView` using `attachBrightnessSlider` method. ```java BrightnessSlideBar brightnessSlideBar = findViewById(R.id.brightnessSlide); colorPickerView.attachBrightnessSlider(brightnessSlideBar); ``` -We can make it vertically using the below attributes. + +If you want to implement a vertical style of sliders, you can achieve it with the `rotation` attributes. + ```gradle android:layout_width="280dp" // width must set a specific width size. android:layout_height="wrap_content" @@ -328,7 +359,8 @@ new ColorPickerDialog.Builder(this) .show(); ``` -we can get an instance of `ColorPickerView` from the `ColorPickerView.Builder` and we can customize it.
+You can get an instance of `ColorPickerView` from the `ColorPickerView.Builder` and customize it by your preferences.
+ ```java ColorPickerView colorPickerView = builder.getColorPickerView(); colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag)); // sets a custom flagView @@ -336,9 +368,9 @@ builder.show(); // shows the dialog ``` ## FlagView -We can implement showing a `FlagView` above and below on the selector.
-This library provides `BubbleFlagView` by default as we can see the [previews](https://github.com/skydoves/ColorPickerView#colorpickerview).
-Here is the example code for implementing it. +You can implement displaying `FlagView` over the selector.
+This library provides `BubbleFlagView` by default as you can see in the [previews](https://github.com/skydoves/ColorPickerView#colorpickerview).
+Here is an example code for displaying a bubble flag view, which indicates what color value was selected. ```java BubbleFlag bubbleFlag = new BubbleFlag(this); @@ -346,11 +378,13 @@ bubbleFlag.setFlagMode(FlagMode.FADE); colorPickerView.setFlagView(bubbleFlag); ``` -We can also fully customize the `FlagView` like below.
+You can also fully customize the `FlagView` like the example below:
+ ![flag0](https://user-images.githubusercontent.com/24237865/45364191-75fe4780-b614-11e8-81a5-04690a4392db.jpg) ![flag1](https://user-images.githubusercontent.com/24237865/45364194-75fe4780-b614-11e8-844c-136d14c91560.jpg)
-First, We need a customized layout like below. +First, create a custom XML layout like the example below: + ```gradle - ``` -Second, we need to create a class that extends `FlagView`. Here is an example code. +Next, you should create a class that extends `FlagView`: + ```java public class CustomFlag extends FlagView { @@ -405,14 +440,15 @@ public class CustomFlag extends FlagView { } ``` -And last, set the `FlagView` to the `ColorPickerView` using the `setFlagView` method. +As you can see in the above code, you can observe and update the layout inside the `onRefresh` method. Lastly, set the `FlagView` to the `ColorPickerView` using the `setFlagView` method: ```java colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag)); ``` ### FlagMode -`FlagMode` is an option to decides the visibility action of the `FlagView`. +`FlagMode` is an option that decides the visibility action of the `FlagView`. + ```java colorPickerView.setFlagMode(FlagMode.ALWAYS); // showing always by tapping and dragging. colorPickerView.setFlagMode(FlagMode.LAST); // showing only when finger released. @@ -449,8 +485,8 @@ setInitialColor(@ColorInt int color) | void | changes selector's selected point setInitialColorRes(@ColorRes int resource) | void | changes selector's selected point by a specific color initially using a color resource. setActionMode(ActionMode) | void | sets the color listener's trigger action mode. setFlagView(FlagView flagView) | void | sets `FlagView` on `ColorPickerView`. -attachAlphaSlider | void | linking an `AlphaSlideBar` on the `ColorPickerView`. -attachBrightnessSlider | void | linking an `BrightnessSlideBar` on the `ColorPickerView`. +attachAlphaSlider | void | links an `AlphaSlideBar` to the `ColorPickerView`. +attachBrightnessSlider | void | links a `BrightnessSlideBar` to the `ColorPickerView`. ## Other Libraries Here are other ColorPicker related libraries! diff --git a/app/api/app.api b/app/api/app.api new file mode 100644 index 0000000..fb4cc23 --- /dev/null +++ b/app/api/app.api @@ -0,0 +1,19 @@ +public class com/skydoves/colorpickerviewdemo/CustomFlagView : com/skydoves/colorpickerview/flag/FlagView { + public fun (Landroid/content/Context;I)V + public fun onFlipped (Ljava/lang/Boolean;)V + public fun onRefresh (Lcom/skydoves/colorpickerview/ColorEnvelope;)V +} + +public class com/skydoves/colorpickerviewdemo/MainActivity : androidx/appcompat/app/AppCompatActivity { + public fun ()V + protected fun onActivityResult (IILandroid/content/Intent;)V + public fun onBackPressed ()V + protected fun onCreate (Landroid/os/Bundle;)V + public fun overflowMenu (Landroid/view/View;)V +} + +public class com/skydoves/colorpickerviewdemo/PowerMenuUtils { + public fun ()V + public static fun getPowerMenu (Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lcom/skydoves/powermenu/OnMenuItemClickListener;)Lcom/skydoves/powermenu/PowerMenu; +} + diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 9a691ed..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -// Designed and developed by 2019 skydoves (Jaewoong Eum) -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -apply plugin: 'com.android.application' -apply from: "$rootDir/dependencies.gradle" - -android { - compileSdkVersion versions.compileSdk - defaultConfig { - applicationId "com.skydoves.colorpickerviewdemo" - minSdkVersion versions.minSdk - targetSdkVersion versions.compileSdk - versionCode versions.versionCode - versionName versions.versionName - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation "com.google.android.material:material:$versions.googleMaterial" - implementation "com.github.skydoves:powermenu:$versions.powermenu" - implementation "com.jakewharton.timber:timber:$versions.timber" - implementation project(":colorpickerview") -} - -tasks.withType(Javadoc).all { enabled = false } - -apply from: "$rootDir/spotless.gradle" diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..c6c393e --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,67 @@ +// Designed and developed by 2017 skydoves (Jaewoong Eum) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import com.skydoves.colorpicker.Configuration + +@Suppress("DSL_SCOPE_VIOLATION") +plugins { + id(libs.plugins.android.application.get().pluginId) + id(libs.plugins.kotlin.android.get().pluginId) + id(libs.plugins.baseline.profile.get().pluginId) +} + +android { + compileSdk = Configuration.compileSdk + namespace = "com.skydoves.colorpickerviewdemo" + defaultConfig { + applicationId = "com.skydoves.colorpickerviewdemo" + minSdk = Configuration.minSdk + targetSdk = Configuration.targetSdk + versionCode = Configuration.versionCode + versionName = Configuration.versionName + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + lint { + abortOnError = false + } + buildTypes { + create("benchmark") { + initWith(buildTypes.getByName("release")) + signingConfig = signingConfigs.getByName("debug") + matchingFallbacks += listOf("release") + isDebuggable = false + } + } +} + +kotlin { + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) + } +} + +dependencies { + implementation(project(":colorpickerview")) + + implementation(libs.androidx.material) + implementation(libs.timber) + implementation(libs.powermenu) + + baselineProfile(project(":benchmark")) +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cc3e710..1e136c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,21 @@ + + xmlns:tools="http://schemas.android.com/tools"> @@ -13,11 +27,13 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="AllowBackup,GoogleAppIndexingWarning"> - + - \ No newline at end of file + diff --git a/app/src/main/java/com/skydoves/colorpickerviewdemo/CustomFlagView.java b/app/src/main/java/com/skydoves/colorpickerviewdemo/CustomFlagView.java new file mode 100644 index 0000000..3fa8643 --- /dev/null +++ b/app/src/main/java/com/skydoves/colorpickerviewdemo/CustomFlagView.java @@ -0,0 +1,51 @@ +/* + * Designed and developed by 2017 skydoves (Jaewoong Eum) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.skydoves.colorpickerviewdemo; + +import android.content.Context; +import android.widget.TextView; + +import com.skydoves.colorpickerview.AlphaTileView; +import com.skydoves.colorpickerview.ColorEnvelope; +import com.skydoves.colorpickerview.flag.FlagView; + +public class CustomFlagView extends FlagView { + + private TextView textView; + private AlphaTileView alphaTileView; + + public CustomFlagView(Context context, int layout) { + super(context, layout); + textView = findViewById(R.id.flag_color_code); + alphaTileView = findViewById(R.id.flag_color_layout); + } + + @Override + public void onRefresh(ColorEnvelope colorEnvelope) { + textView.setText("#" + colorEnvelope.getHexCode()); + alphaTileView.setPaintColor(colorEnvelope.getColor()); + } + + @Override + public void onFlipped(Boolean isFlipped) { + if (isFlipped) { + textView.setRotation(180f); + } else { + textView.setRotation(0f); + } + } +} diff --git a/app/src/main/java/com/skydoves/colorpickerviewdemo/MainActivity.java b/app/src/main/java/com/skydoves/colorpickerviewdemo/MainActivity.java index 1176c0e..8861297 100644 --- a/app/src/main/java/com/skydoves/colorpickerviewdemo/MainActivity.java +++ b/app/src/main/java/com/skydoves/colorpickerviewdemo/MainActivity.java @@ -26,8 +26,10 @@ import android.os.Bundle; import android.view.View; import android.widget.TextView; + import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; + import com.skydoves.colorpickerview.AlphaTileView; import com.skydoves.colorpickerview.ColorEnvelope; import com.skydoves.colorpickerview.ColorPickerDialog; @@ -40,8 +42,10 @@ import com.skydoves.powermenu.OnMenuItemClickListener; import com.skydoves.powermenu.PowerMenu; import com.skydoves.powermenu.PowerMenuItem; + import java.io.FileNotFoundException; import java.io.InputStream; + import timber.log.Timber; public class MainActivity extends AppCompatActivity { @@ -52,33 +56,34 @@ public class MainActivity extends AppCompatActivity { private boolean FLAG_SELECTOR = false; private PowerMenu powerMenu; - private OnMenuItemClickListener powerMenuItemClickListener = - new OnMenuItemClickListener() { - @Override - public void onItemClick(int position, PowerMenuItem item) { - switch (position) { - case 1: - palette(); - break; - case 2: - paletteFromGallery(); - break; - case 3: - selector(); - break; - case 4: - dialog(); - break; + private final OnMenuItemClickListener powerMenuItemClickListener = + new OnMenuItemClickListener<>() { + @Override + public void onItemClick(int position, PowerMenuItem item) { + switch (position) { + case 0: { + palette(); + break; } - powerMenu.dismiss(); + case 1: { + paletteFromGallery(); + break; + } + case 2: + selector(); + break; + case 3: + dialog(); + break; } - }; + powerMenu.dismiss(); + } + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Timber.plant(new Timber.DebugTree()); powerMenu = PowerMenuUtils.getPowerMenu(this, this, powerMenuItemClickListener); @@ -87,11 +92,11 @@ protected void onCreate(Bundle savedInstanceState) { bubbleFlag.setFlagMode(FlagMode.FADE); colorPickerView.setFlagView(bubbleFlag); colorPickerView.setColorListener( - (ColorEnvelopeListener) - (envelope, fromUser) -> { - Timber.d("color: %s", envelope.getHexCode()); - setLayoutColor(envelope); - }); + (ColorEnvelopeListener) + (envelope, fromUser) -> { + Timber.d("color: %s", envelope.getHexCode()); + setLayoutColor(envelope); + }); // attach alphaSlideBar final AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar); @@ -117,12 +122,16 @@ private void setLayoutColor(ColorEnvelope envelope) { alphaTileView.setPaintColor(envelope.getColor()); } - /** shows the popup menu for changing options.. */ + /** + * shows the popup menu for changing options.. + */ public void overflowMenu(View view) { powerMenu.showAsAnchorLeftTop(view); } - /** changes palette image using drawable resource. */ + /** + * changes palette image using drawable resource. + */ private void palette() { if (FLAG_PALETTE) { colorPickerView.setHsvPaletteDrawable(); @@ -132,34 +141,40 @@ private void palette() { FLAG_PALETTE = !FLAG_PALETTE; } - /** changes palette image from a gallery image. */ + /** + * changes palette image from a gallery image. + */ private void paletteFromGallery() { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1000); } - /** changes selector image using drawable resource. */ + /** + * changes selector image using drawable resource. + */ private void selector() { if (FLAG_SELECTOR) { - colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel)); + colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, com.skydoves.colorpickerview.R.drawable.colorpickerview_wheel)); } else { colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel_dark)); } FLAG_SELECTOR = !FLAG_SELECTOR; } - /** shows ColorPickerDialog */ + /** + * shows ColorPickerDialog + */ private void dialog() { ColorPickerDialog.Builder builder = - new ColorPickerDialog.Builder(this) - .setTitle("ColorPicker Dialog") - .setPreferenceName("Test") - .setPositiveButton( - getString(R.string.confirm), - (ColorEnvelopeListener) (envelope, fromUser) -> setLayoutColor(envelope)) - .setNegativeButton( - getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss()); + new ColorPickerDialog.Builder(this) + .setTitle("ColorPicker Dialog") + .setPreferenceName("Test") + .setPositiveButton( + getString(R.string.confirm), + (ColorEnvelopeListener) (envelope, fromUser) -> setLayoutColor(envelope)) + .setNegativeButton( + getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss()); builder.getColorPickerView().setFlagView(new BubbleFlag(this)); builder.show(); } diff --git a/colorpickerview/src/main/res/drawable/wheel.png b/app/src/main/res/drawable/wheel.png similarity index 100% rename from colorpickerview/src/main/res/drawable/wheel.png rename to app/src/main/res/drawable/wheel.png diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 80662a3..d99c994 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,19 @@ + + app:selector="@drawable/colorpickerview_wheel" /> + app:selector_AlphaSlideBar="@drawable/colorpickerview_wheel" /> + app:selector_BrightnessSlider="@drawable/colorpickerview_wheel" /> + + + + + + + diff --git a/app/src/main/res/layout/layout_header.xml b/app/src/main/res/layout/layout_header.xml index 061d279..5866375 100644 --- a/app/src/main/res/layout/layout_header.xml +++ b/app/src/main/res/layout/layout_header.xml @@ -1,4 +1,19 @@ + + - #F50057 + #FFF50057 #C51162 #3d95c9 #2B292B diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9108614..2c349aa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,22 @@ + + ColorPickerViewDemo select cancel Options - \ No newline at end of file + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f2417fc..e054bf5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,3 +1,19 @@ + +