From 72cf4b8ea7c35124cdb2ba0c00ed9cf47fdc8d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Guti=C3=A9rrez?= <35809824+Migue-GR@users.noreply.github.com> Date: Tue, 11 Sep 2018 02:40:36 -0500 Subject: [PATCH] Create Tooltips.java --- .../src/main/java/com/tooltip/Tooltips.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 library/src/main/java/com/tooltip/Tooltips.java diff --git a/library/src/main/java/com/tooltip/Tooltips.java b/library/src/main/java/com/tooltip/Tooltips.java new file mode 100644 index 0000000..f0ffe20 --- /dev/null +++ b/library/src/main/java/com/tooltip/Tooltips.java @@ -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(); + } + } + } +}