Git Product home page Git Product logo

android-colorpickerpreference's Introduction

ColorPickerPreference

Generally used classes by Daniel Nilsson. ColorPickerPreference class by Sergey Margaritov. Packed by Sergey Margaritov. Packed again and made Gradle compatible by Vincent Fischer.

Features

  • Color Area
  • Hue Slider
  • Alpha Slider (disabled by default)
  • Old & New Color
  • Color Preview in Preferences List

Requirements

Tested with APIv7, but maybe will work with early versions

Installation ===========

Through Gradle

You can now install this through Gradle with a simple:
implementation 'net.margaritov.preference.colorpicker.ColorPickerPreference:ColorPickerPreference:1.0.0'

Android Studio

  1. Paste or clone this library into the /libs folder, in the root directory of your project. Create a new folder: /libs if not already present. (This step is not required - only for keeping cleaner project structure)
2) Edit settings.gradle by adding the library. You have also define a project directory for the library. Your settings.gradle should look like below:
include ':app', ':ColorPickerPreference'
project(':ColorPickerPreference').projectDir = new File('app/libs/ColorPickerPreference')
3) In app/build.gradle add the ColorPickerPreference library as a dependency:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:21.0.3'
    implementation project(":ColorPickerPreference")
}
  1. Sync project, clean and build. You can use the ColorPickerPreference library as part of your project now.

Eclipse

  1. Before you can add a ColorPickerPreference to your application, you must first add a library reference:
  2. Clone or download a copy of the library
  3. Import the library into Eclipse: File menu -> Import -> Existing Project into Workspace
  4. Open your application's project properties and add a library reference to ColorPickerPreference

Usage

You can see some tests inside

<net.margaritov.preference.colorpicker.ColorPickerPreference
    android:key="color1"
    android:title="@string/color1_title"
    android:summary="@string/color1_summary"
    android:defaultValue="@color/pumpkin_orange"    <!-- integer resources are also accepted -->
    alphaSlider="true"                              <!-- enable alpha slider via XML -->
/>

To enable Alpha Slider in your code use function: :: setAlphaSliderEnabled(boolean enable)

Screens

  • image
  • image

android-colorpickerpreference's People

Contributors

alexanderbh avatar attenzione avatar c0br4 avatar chrissmith avatar falcon4ever avatar insanityonabun avatar jayschwa avatar johnchrisdc avatar josegd avatar juderosario avatar rovo89 avatar stephanepechard avatar timothyjc avatar wubydax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-colorpickerpreference's Issues

Sample activity causing trouble because of its placement in the project tree

The sample activity to showcase the library capabilities (ColorPickerPreference/src/main/java/net/margaritov/preference/colorpicker/Test.java) and the manifest file where it is declared (ColorPickerPreference/src/main/AndroidManifest.xml) are placed alongside the library sources.

Since settings.gradle has include ':app', ':ColorPickerPreference', that manifest is merged with the main manifest of the app using the library.

As a result, an app that uses the library with the directory tree laid out here ends up with two launcher activities and two icons in the app drawer.

The workaround is commenting the entire <application> tag in the manifest, but it would be great to see the sample activity being placed in a different directory not being seen by Gradle - a usual practice in library code.

Prevent wrong chars in hex input

Please use the following attribute for view EditText hex_val to prevent wrong chars in hex input:
android:digits="0123456789ABCDEF"

Fatal Exception: java.lang.NullPointerException

In some devices(OS: 6.0.1, Galaxy A7), error occurs.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference
       at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1310)
       at android.graphics.Canvas.drawBitmap(Canvas.java:1445)
       at net.margaritov.preference.colorpicker.AlphaPatternDrawable.draw(AlphaPatternDrawable.java:57)
       at net.margaritov.preference.colorpicker.ColorPickerPanelView.onDraw(ColorPickerPanelView.java:86)
       at android.view.View.draw(View.java:17526)
       at android.view.View.updateDisplayListIfDirty(View.java:16519)
       at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3910)
       at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3890)
       at android.view.View.updateDisplayListIfDirty(View.java:16479)
       at android.view.View.draw(View.java:17295)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3926)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716)
       at android.view.View.updateDisplayListIfDirty(View.java:16514)
       at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3910)
       at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3890)
       at android.view.View.updateDisplayListIfDirty(View.java:16479)
       at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3910)
       at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3890)
       at android.view.View.updateDisplayListIfDirty(View.java:16479)
       at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3910)
       at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3890)
       at android.view.View.updateDisplayListIfDirty(View.java:16479)
       at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:325)
       at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:331)
       at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:366)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:3234)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3033)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2615)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1528)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7530)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
       at android.view.Choreographer.doCallbacks(Choreographer.java:686)
       at android.view.Choreographer.doFrame(Choreographer.java:622)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7329)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Error

Error sir on Aide 3.2
trying implements 'net.margaritov...error
trying implementation 'net.margaritov...error
tryning compile 'net.margaritov...not error but running the app error.
how to fix it sir
Screenshot_20190823-194935
Screenshot_20190823-194919

gradle fails to sync

* Where:
Script 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' line: 1

* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.github.dcendents.android-maven' not found.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating script.
	at ...
	at build_4bt5nm20qbc9qf92rw9f04bxy.run(/xxx/ColorPickerPreference/ColorPickerPreference/build.gradle:50)
	at ...
	at installv1_7fnondwfez6ilvn50dvvmy5zv.run(https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle:1)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
	... 154 more

https://github.com/dcendents/android-maven-gradle-plugin says that it is abandoned

Works on Android 1.5

I've tested this library on Android 1.6, and it seems to work fine. So you can probably change your min sdk to 4 :)

(Note, I tested the one on jcenter: com.robbypond:android-ColorPickerPreference:1.11.1)

Some parts of view is disappeared when screen is rotated

When "orientation" and "screenSize" is defined in Activity's configChanges and screen is rotated at Android 4.0+, some parts of view is disappeared. For example, AndroidManifest is following.






If "screenSize" is deleted from configChanges, it works properly.
Please look at the following screenshot which some part of view is disappeared.

<landscape -> portrait>
testcolorpicker_portrait

<portrait -> landscape>
testcolorpicker_landscape

Previews broken on ICS

Hey, I want to use this preference for my Android project. Unfortunately, the previews don't look quite right on ICS, they seem to have a bit of a checkered pattern on their sides.
Here's a screenshot.

This is the code I'm using:

<net.margaritov.preference.colorpicker.ColorPickerPreference
            android:defaultValue="#ff2525"
            android:dependency="sync_events"
            android:key="event_color"
            android:title="@string/calendar_color" />

Package name

Obviously you renamed your package name from com.att.preference.colorpicker to net.margaritov.preference.colorpicker, however you still have many references to the old package name within your code and xml files making the colorpicker crash.

Landscape Dialog width measured incorrectly

at least on Android 2.3 i got incorrect dialog width with a little bit free space on the right side.
Looked at source, it's seems that android doesn't measure latest width of root LinearLayout.
All children width (summary) is lower than dialog actual width.

need help :)

Typo in comment of ColorPickerPreference.java

In the comment of the class it says:

A preference type that allows a user to choose a time

but I'm pretty sure what I can see the user can choose a color not a time

Please change comment to:

A preference type that allows a user to choose a color

java.lang.NullPointerException

Hi,u guys.
Does anyone has this wired problem?

java.lang.NullPointerException
at com.xxx.xxx.preferences.widget.b.(ColorPickerDialog.java:50)

The pic.

image

Package is not avaliable in mavenCentral and jcenter is deprecated

If I delete jcenter (deprecated) repository from my build.gradle, add mavenCentral and add implementation 'net.margaritov.preference.colorpicker.ColorPickerPreference:ColorPickerPreference:1.0.0' I got the following error:

Failed to resolve: net.margaritov.preference.colorpicker.ColorPickerPreference:ColorPickerPreference:1.0.0

Unsupported major.minor version 52.0

Unsupported major.minor version 52.0
Today get this error in
MyPath\AndroidStudioProjects\MyApp\app\libs\ColorPickerPreference\ColorPickerPreference\build.gradle

before everything worked fine

How would I apply the integer?

If I usually use model.setColor(Color.BLUE); how would I use this instead? I've seen it used in a number of live wallpapers, I would just like to know how to do it. Thank you.

Color Preference default incorrect?

Likely my problem, but spent days on it.

The color preference works perfectly. It correctly reads the default color and displays it on the setting screen.

However, the statement in my code:

preferredcolour = mysharedPreferences.getInt("mechanism_color",R.integer.COLOR_Fuchsia);

Doesn't work properly unless I have manually selected a color. The preview screen shows Fuchsia but the code above returns a color very close to (but not exactly) black. Once I have set a color by hand, it works as expected. To recreate the problem, I have to delete the application from my phone so a new Preference file is re-created.

It is as if the Preference file is not being updated with the correct color value until after I have changed the color preference.

I don't know if its me or the code (very likely me), I have spent days seeing the same problem, can't even figure out a workaround, can anybody give me any idea how to fix it?

ColorPickerButton

One more request: could you make the widget that appears at the left of the preference label (the color "button") into a color button that can be used in other contexts (outside of preferences)? I'd like to use it in my layouts.

Thanks!

Selecting Color doesn't update preview

I have found a workaround that finishes the settings activity and restarts it. But is there a reason why in ColoPickerPreference the setImageBitmap(getPreviewBitmap()) does not reflect the change when a new color is selected?

If screen is rotated the preview box has the newly selected color.

ICS and Jellybean have this same effect.

Dialog theming

I've tried to modify the dialog theming but it doesn't works. I changed ColorPickerDialog constructor and now it works

public ColorPickerDialog(Context context, int initialColor) {
super(context, R.style.MyTheme);

License

Could you clarify the license? Can I use it in closed-source apps?

Getting forse close error

I am testing your code in LG optimas running on Android2.2
I am getting forse close error while opening your test activity.

Here is my logcat

01-06 11:36:15.379: W/dalvikvm(11949): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
01-06 11:36:15.419: E/AndroidRuntime(11949): FATAL EXCEPTION: main
01-06 11:36:15.419: E/AndroidRuntime(11949): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.margaritov.preference.colorpicker/net.margaritov.preference.colorpicker.Test}: android.view.InflateException: Binary XML file line #24: Error inflating class java.lang.reflect.Constructor
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.os.Looper.loop(Looper.java:123)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-06 11:36:15.419: E/AndroidRuntime(11949): at java.lang.reflect.Method.invokeNative(Native Method)
01-06 11:36:15.419: E/AndroidRuntime(11949): at java.lang.reflect.Method.invoke(Method.java:521)
01-06 11:36:15.419: E/AndroidRuntime(11949): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-06 11:36:15.419: E/AndroidRuntime(11949): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-06 11:36:15.419: E/AndroidRuntime(11949): at dalvik.system.NativeStart.main(Native Method)
01-06 11:36:15.419: E/AndroidRuntime(11949): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class java.lang.reflect.Constructor
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.createItem(GenericInflater.java:397)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.inflate(GenericInflater.java:326)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.inflate(GenericInflater.java:263)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:251)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:262)
01-06 11:36:15.419: E/AndroidRuntime(11949): at net.margaritov.preference.colorpicker.Test.onCreate(Test.java:31)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-06 11:36:15.419: E/AndroidRuntime(11949): ... 11 more
01-06 11:36:15.419: E/AndroidRuntime(11949): Caused by: java.lang.reflect.InvocationTargetException
01-06 11:36:15.419: E/AndroidRuntime(11949): at net.margaritov.preference.colorpicker.ColorPickerPreference.(ColorPickerPreference.java:56)
01-06 11:36:15.419: E/AndroidRuntime(11949): at java.lang.reflect.Constructor.constructNative(Native Method)
01-06 11:36:15.419: E/AndroidRuntime(11949): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.GenericInflater.createItem(GenericInflater.java:383)
01-06 11:36:15.419: E/AndroidRuntime(11949): ... 21 more
01-06 11:36:15.419: E/AndroidRuntime(11949): Caused by: android.content.res.Resources$NotFoundException: File #0000FF from drawable resource ID #0x0: .xml extension required
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.content.res.Resources.loadColorStateList(Resources.java:1824)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.content.res.TypedArray.getColor(TypedArray.java:319)
01-06 11:36:15.419: E/AndroidRuntime(11949): at net.margaritov.preference.colorpicker.ColorPickerPreference.onGetDefaultValue(ColorPickerPreference.java:67)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.Preference.(Preference.java:240)
01-06 11:36:15.419: E/AndroidRuntime(11949): at android.preference.Preference.(Preference.java:271)
01-06 11:36:15.419: E/AndroidRuntime(11949): ... 25 more

Setting defaultValue

Hello,
I have been using your ColorPicker in one of my projects and it's by far the best out there. Thank you very much!

I have noticed a little problem and I wanted to offer you a solution I programmed into my project.
There is a little kink in setting the color in attr defaultValue. If you set a color as actual integer, then it works fine, but if you set it as reference to resources, f.e. @color/someColor, you always get 0 in shared preferences. You also can't get it to set defaultValue using hex string.

Both problems are fixed by using this inside onGetDefaultValue method:

@Override
    protected Object onGetDefaultValue(TypedArray a, int index) {
        int colorInt;
        String mHexDefaultValue = a.getString(index);
        if (mHexDefaultValue != null) {
            colorInt = convertToColorInt(mHexDefaultValue);
            return colorInt;

    } else {
        return a.getColor(index, Color.BLACK);
    }
}

I have tested repeatedly and now it sets the actual integer value if you use either proper hex string (6 or 8 chars) or reference to resource color.

If you find this useful, feel free to include.

Thank you again for your great work,
Anna

Layout cut off in LDPI QVGA

When using this for my app, running the color picker dialog in QVGA/LDPI results in a partially cut off dialog window. I resolved this by hiding the title of the dialog on init.

requestWindowFeature(Window.FEATURE_NO_TITLE);

Not sure if anyone else will run into this issue.

Make alpha optional

This is the best implementation I've seen so far, congratulations!

It would be great if you could make the alpha slider optional (in the dialog and preference) for apps that do not need alpha support.

Feature request

  1. The caption of the color picker should be the title, not 'Color Picker'.

  2. Since the color picker already has a default value, there should be a button to restore the default value.

  3. The 'Press on color to apply' string should be parameterizable in order to provide a localized string.

Great work though, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.