martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

Way to place color picker in custom dialog #7

Closed DecoderMG closed 9 years ago

DecoderMG commented 9 years ago

First off love the library but we're working on an app that requires the color picker to be placed in a custom dialog. The dialog's layout is being inflated from an xml file. We have tried to add the view programatically as well and add the view via XML but the HueViewSat.java file throws a null pointer. The alpha and saturation views show up fine but the rest of the color picker fails to draw correctly< (old and current color, color selection view, etc.) We would like to stay away from using the library using the colorPreference method as well. Is there a current work around for this? Also the color picker is being placed on a LinearLayout with a ScrollView attached.

Below is our stack trace. java.lang.NullPointerException at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1269) at android.graphics.Canvas.drawBitmap(Canvas.java:1404) at com.rarepebble.colorpicker.HueSatView.onDraw_Original(HueSatView.java:162) at com.rarepebble.colorpicker.HueSatView.onDraw(HueSatView.java) at android.view.View.draw(View.java:16178) at android.view.View.draw(View.java:16090) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16088) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16088) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16088) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16088) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16181) at android.widget.ScrollView.draw(ScrollView.java:1712) at android.view.View.draw(View.java:16090) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16088) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16181) at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:431) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:428) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:511) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:499) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:499) at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:611) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:608) at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:365) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:608) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:630) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:643) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:585) at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:580) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Thanks in advance for the help!

DecoderMG commented 9 years ago

We've attached an image of the XML file as well as a picture of how it appears in the app. The project will successfully build but will not render correctly at runtime. colorpicker issue

As shown in the picture half of the color picker functionality is missing.

Any help would be greatly appreciated.

martin-stone commented 9 years ago

I'm looking into a proper fix for this, but a workaround is to give the view explicit dimensions (which you might want in a ScrollView anyway): Currently the "wrap_content" is causing the hue/sat view to collapse to zero height.

DecoderMG commented 9 years ago

This was the problem, thank you for the clarification Martin. We seem to be able to fix it by just defining a minHeight and minWidth based on screen size within the library code.

martin-stone commented 9 years ago

Fixed in 1.3.1