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

Create Tooltips.java #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions library/src/main/java/com/tooltip/Tooltips.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Created by Migue-GR. on 13/04/2018.
* @MigueNightcore
*/

public class Tooltips {

public static void showToolTip(View v, int gravity, String message, final int code, final boolean[] TOOLTIPS_ON_SCREEN, Tooltip[] TOOLTIP){
if(!TOOLTIPS_ON_SCREEN[code]) {
closeTooltips(code, TOOLTIPS_ON_SCREEN, TOOLTIP);
TOOLTIP[code] = new Tooltip.Builder(v)
.setText(message + " ×")
.setTextColor(Color.WHITE)
.setBackgroundColor(Color.BLACK)
.setGravity(gravity)
.setTextStyle(1)
.setCornerRadius(8f)
.setDismissOnClick(true)
.setOnDismissListener(
new OnDismissListener() {
@Override
public void onDismiss() {
TOOLTIPS_ON_SCREEN[code] = false;
}
})
.show();
TOOLTIPS_ON_SCREEN[code] = true;
dismissTooltips(code, TOOLTIP);
}
}

//Close tooltip when the time ends
private static void dismissTooltips(final int cod, final Tooltip[] TOOLTIP) {
new CountDownTimer(5000, 1000) {

public void onTick(long millisUntilFinished) {
//code
}

public void onFinish() {
TOOLTIP[cod].dismiss();
}

}.start();
}

//Close Tooltips if is necessary
private static void closeTooltips(int cod, final boolean[] TOOLTIPS_ON_SCREEN, Tooltip[] TOOLTIP) {
for(int i = 0; i < TOOLTIPS_ON_SCREEN.length; i++){
if(TOOLTIPS_ON_SCREEN[i] && i == cod){
TOOLTIP[i].dismiss();
}
}
}
}