Dhaval2404 / ColorPicker

🎨 Color Picker Library for Android
Apache License 2.0
277 stars 39 forks source link

Function2 not found #18

Open ubedthaheem opened 3 years ago

ubedthaheem commented 3 years ago

Summary

while using ColorPicker, there is an error which says : cannot access Function2 on .setOnColorListener(new ColorListener())

Code to reproduce

*frgmnts\ColorPickerFragment.java:94: error: cannot access Function2 .setColorListener(new ColorListener() { ^ class file for kotlin.jvm.functions.Function2 not found

Installation method

implementation from Github repo.

SDK version

Gradle version: 4.2.1

Dhaval2404 commented 3 years ago

Seems like you're using it from Java.

Please check below sample code https://github.com/Dhaval2404/ColorPicker/blob/master/app/src/main/kotlin/com/github/dhaval2404/colorpicker/sample/ColorPickerFragmentJava.java

Dhaval2404 commented 3 years ago

Please share the full source code, So I can help you to fix the syntax error

ubedthaheem commented 3 years ago

` package com.ubedthaheem.app.ui.frgmnts;

import android.app.Activity; import android.os.Bundle;

import androidx.annotation.NonNull; import androidx.fragment.app.Fragment;

import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.Toast;

import com.github.dhaval2404.colorpicker.ColorPickerDialog; import com.github.dhaval2404.colorpicker.listener.ColorListener; import com.github.dhaval2404.colorpicker.model.ColorShape; import com.google.android.material.appbar.AppBarLayout; import com.ubedthaheem.app.R; import com.ubedthaheem.app.ui.utils.GlobalMethods; import com.ubedthaheem.app.ui.utils.SharedPrefManager;

public class ColorPickerFragment extends Fragment { private static final String TAG = "My_ColorFrag";

private ImageView cFontNight, cFontDay, cBodyNight, cBodyDay;
private String colorFontNight, colorFontDay, colorBodyNight, colorBodyDay;
private String SELECTED_COLOR;
private SharedPrefManager prefManager;
private AppBarLayout appBarLayout;
private GlobalMethods methods;
private View parent_view;
private Activity activity;
private ImageButton backBtn;

public ColorPickerFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_color_picker, container, false);
    cFontDay = root.findViewById(R.id.colorFrag_fontColorBg);
    cFontNight = root.findViewById(R.id.colorFrag_fontColorBgNight);
    cBodyDay = root.findViewById(R.id.colorFrag_bodyColorBg);
    cBodyNight = root.findViewById(R.id.colorFrag_bodyColorBgNight);
    appBarLayout = root.findViewById(R.id.colorFrag_appbarlayout);
    parent_view = root.findViewById(R.id.colorFrag_parentView);
    backBtn = root.findViewById(R.id.colorFrag_backBtn);
    return root;
}

@Override
public void onViewCreated(@NonNull View view,  Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    activity = getActivity();
    methods = new GlobalMethods(getContext());
    prefManager = SharedPrefManager.getInstance(getContext());
    colorFontDay = prefManager.getDefaultColors("colorFontDay");
    colorFontNight = prefManager.getDefaultColors("colorFontNight");
    colorBodyDay = prefManager.getDefaultColors("colorBodyDay");
    colorBodyNight = prefManager.getDefaultColors("colorBodyNight");

    cFontDay.setOnClickListener(v -> picColorFor(colorFontDay));
    cFontNight.setOnClickListener(v -> picColorFor(colorFontNight));

    backBtn.setOnClickListener(v -> activity.onBackPressed());
    cBodyDay.setOnClickListener(v -> picColorFor(colorBodyDay));

}

private void picColorFor(String defaultColor){

    new ColorPickerDialog
            .Builder(activity)
            .setTitle("PickTheme")
            .setColorShape(ColorShape.SQAURE)
            .setDefaultColor(defaultColor)
            .setColorListener(new ColorListener() {
                @Override
                public void onColorSelected(int color, @NonNull String colorHex) {
                    // Handle Color Selection
                    Toast.makeText(activity, "selected color code : " + colorHex, Toast.LENGTH_SHORT).show();
                }
            })
            .show();
}

}` above code is of my fragment.