Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function2 not found #18

Open
ubedthaheem opened this issue May 15, 2021 · 3 comments
Open

Function2 not found #18

ubedthaheem opened this issue May 15, 2021 · 3 comments

Comments

@ubedthaheem
Copy link

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
Copy link
Owner

@Dhaval2404
Copy link
Owner

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

@ubedthaheem
Copy link
Author

`
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants