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

how to implement in java #20

Closed
ThreeMinutesFix opened this issue Jun 22, 2023 · 4 comments
Closed

how to implement in java #20

ThreeMinutesFix opened this issue Jun 22, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ThreeMinutesFix
Copy link

what is code to implement in java?

@ozgurg ozgurg added good first issue Good for newcomers enhancement New feature or request labels Jun 22, 2023
@ozgurg
Copy link
Owner

ozgurg commented Jun 22, 2023

Hi. The setup and layout usage are the same.

In your layout you can find the icon by its ID and use it like any other view.

<og.android.lib.toggleiconview.rounded.PlayPause
    android:id="@+id/playPause"
    android:layout_width="24dp"
    android:layout_height="24dp" />
ToggleIconView toggleIconView = (ToggleIconView) findViewById(R.id.playPause);

toggleIconView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        toggleIconView.toggle();
    }
});

toggleIconView.setOnCheckedChangeListener(new Function2<ToggleIconView, Boolean, Unit>() {
    @Override
    public Unit invoke(ToggleIconView view, Boolean isChecked) {
        Toast.makeText(getApplicationContext(), isChecked.toString(), Toast.LENGTH_SHORT).show();
        return null;
    }
});

// toggleIconView.toggle();
// toggleIconView.setChecked(...);
// toggleIconView.isChecked();
// toggleIconView.setCheckedContentDescription(...);
// toggleIconView.getCheckedContentDescription();
// toggleIconView.setCheckedTooltipText(...);
// toggleIconView.getCheckedTooltipText()

But if I can create an interface for onCheckedChangeListener, the code will make more sense when used with Java. I'll look into this.

@ozgurg ozgurg self-assigned this Jun 22, 2023
@ozgurg ozgurg closed this as completed in b7d234d Jun 22, 2023
@ozgurg
Copy link
Owner

ozgurg commented Jun 22, 2023

Hi. The setup and layout usage are the same.

In your layout you can find the icon by its ID and use it like any other view.

<og.android.lib.toggleiconview.rounded.PlayPause
    android:id="@+id/playPause"
    android:layout_width="24dp"
    android:layout_height="24dp" />
ToggleIconView toggleIconView = (ToggleIconView) findViewById(R.id.playPause);

toggleIconView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        toggleIconView.toggle();
    }
});

toggleIconView.setOnCheckedChangeListener(new Function2<ToggleIconView, Boolean, Unit>() {
    @Override
    public Unit invoke(ToggleIconView view, Boolean isChecked) {
        Toast.makeText(getApplicationContext(), isChecked.toString(), Toast.LENGTH_SHORT).show();
        return null;
    }
});

// toggleIconView.toggle();
// toggleIconView.setChecked(...);
// toggleIconView.isChecked();
// toggleIconView.setCheckedContentDescription(...);
// toggleIconView.getCheckedContentDescription();
// toggleIconView.setCheckedTooltipText(...);
// toggleIconView.getCheckedTooltipText()

But if I can create an interface for onCheckedChangeListener, the code will make more sense when used with Java. I'll look into this.

Hi again, I updated the library. Now you can use the listener like this:

toggleIconView.setOnCheckedChangeListener(new ToggleIconView.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(@NonNull ToggleIconView view, boolean isChecked) {
        Toast.makeText(getApplicationContext(), isChecked.toString(), Toast.LENGTH_SHORT).show();
    }
});

@ThreeMinutesFix
Copy link
Author

thankyou somuch.thankyou for creating this amazing lib i will implement and tell you the result on my app

@ThreeMinutesFix
Copy link
Author

worked
your implementation worked perfectly :)
video preview: https://res.cloudinary.com/djdle8unh/video/upload/v1687506760/video_2023-06-23_13-22-21_ulvcai.mp4
in xml icon was not displayed so i added it manaully.

<og.android.lib.toggleiconview.rounded.PlayPause android:id="@+id/playPause" android:layout_width="84dp" android:src="@drawable/rounded_play_to_pause" android:tint="@color/white" android:layout_height="84dp" />
Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants