Git Product home page Git Product logo

Comments (6)

thelittlefireman avatar thelittlefireman commented on August 26, 2024

Hi,
same issue.

Fatal Exception: java.lang.IllegalStateException: The activity must implement ColorPickerDialogListener
       at com.jaredrummler.android.colorpicker.ColorPickerDialog.onColorSelected(ColorPickerDialog.java:583)
       at com.jaredrummler.android.colorpicker.ColorPickerDialog.access$000(ColorPickerDialog.java:68)
       at com.jaredrummler.android.colorpicker.ColorPickerDialog$2.onClick(ColorPickerDialog.java:190)
       at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:224)
       at android.app.ActivityThread.main(ActivityThread.java:7520)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

I think you should add the setColorPickerDialogListener(....) to the builder because there is a thread concurrency and sometimes the listener is null ==> if (colorPickerDialogListener != null)

Original source code :

private void onColorSelected(int color) {
    if (colorPickerDialogListener != null) {
      Log.w(TAG, "Using deprecated listener which may be remove in future releases");
      colorPickerDialogListener.onColorSelected(dialogId, color);
      return;
    }
    Activity activity = getActivity();
    if (activity instanceof ColorPickerDialogListener) {
      ((ColorPickerDialogListener) activity).onColorSelected(dialogId, color);
    } else {
      throw new IllegalStateException("The activity must implement ColorPickerDialogListener");
    }
  }

My code :

ColorPickerDialog colorPickerDialog = ColorPickerDialog.newBuilder()
                    .setColorShape(CIRCLE)
                    .setDialogType(ColorPickerDialog.TYPE_PRESETS)
                    .setAllowCustom(true)
                    .setAllowPresets(true)
                    .setColor(mEDTColor)
                    .create();
            colorPickerDialog.setColorPickerDialogListener(new ColorPickerDialogListener() {
                @Override
                public void onColorSelected(int dialogId, int color) {
                    mEDTColor = color;
                    mCircularImageViewEDTColor.setImageDrawable(new ColorDrawable(mEDTColor));
                }

                @Override
                public void onDialogDismissed(int dialogId) {

                }
            });
            colorPickerDialog.show(getSupportFragmentManager(), "COLOR_PICKER_EDT");

from colorpicker.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 26, 2024

@thelittlefireman Is this a part of your own fork?

from colorpicker.

thelittlefireman avatar thelittlefireman commented on August 26, 2024

@AndroidDeveloperLB Nop i use the official repo implementation 'com.jaredrummler:colorpicker:1.1.0' :)

from colorpicker.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 26, 2024

@thelittlefireman Is this a working workaround?
Can you please show a sample of how to use it (zip file of a POC project) ?

from colorpicker.

thelittlefireman avatar thelittlefireman commented on August 26, 2024

This is not a workaround. I just show on the original code where the issue seems to be.

A small possible workaround is to implement implements ColorPickerDialogListener on the activity and use
colorPickerDialog.setColorPickerDialogListener(this);

from colorpicker.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 26, 2024

@thelittlefireman Sorry. Can you please show a POC of this, then?

from colorpicker.

Related Issues (20)

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.