Giter Site home page Giter Site logo

douglasjunior / android-simple-tooltip Goto Github PK

View Code? Open in Web Editor NEW
766.0 19.0 192.0 991 KB

A simple library based on PopupWindow to create Tooltips on Android. ๐Ÿ’š

License: MIT License

Java 100.00%
android ui dialog popup-window tooltip animation kiss easy-to-use hacktoberfest

android-simple-tooltip's Introduction

Android Simple Tooltip

PT

Licence MIT Build Status Release Downloads Android Arsenal

A simple library based on PopupWindow to create Tooltips on Android.

Features

  • Working from Android 4.0 (API 14)
  • Simple to use: few parameters in a single line of code
  • Animation with speed and size control
  • Option to close with touch inside or outside of the tooltip.
  • Modal mode (prevents touch in the background)
  • Overlay (darkens the background highlighting the anchor)
  • Customizable arrow
  • Inflatable content from a View or XML layout.
  • Colors and dimensions customized by Builder or XML resources

Demo

Demo

Usage

Basic

View yourView = findViewById(R.id.your_view);

new SimpleTooltip.Builder(this)
    .anchorView(yourView)
    .text("Texto do Tooltip")
    .gravity(Gravity.END)
    .animated(true)
    .transparentOverlay(false)
    .build()
    .show();

Resources

<color name="simpletooltip_background">@color/colorAccent</color>
<color name="simpletooltip_text">@android:color/primary_text_light</color>
<color name="simpletooltip_arrow">@color/colorAccent</color>
<dimen name="simpletooltip_max_width">150dp</dimen>
<dimen name="simpletooltip_overlay_offset">10dp</dimen>
<dimen name="simpletooltip_margin">10dp</dimen>
<dimen name="simpletooltip_padding">8dp</dimen>
<dimen name="simpletooltip_arrow_width">30dp</dimen>
<dimen name="simpletooltip_arrow_height">15dp</dimen>
<dimen name="simpletooltip_animation_padding">4dp</dimen>
<integer name="simpletooltip_overlay_alpha">120</integer>
<integer name="simpletooltip_animation_duration">800</integer>
<style name="simpletooltip_default" parent="@android:style/TextAppearance.Medium"></style>

More info on the sample project and javadoc.

Download

Release

  1. Add it in your root build.gradle at the end of repositories:

    allprojects {
    	repositories {
    		...
    		maven { url "https://jitpack.io" }
    	}
    }
  2. Add the dependency in your app/build.gradle:

    dependencies {
        implementation 'com.github.douglasjunior:android-simple-tooltip:1.1.0'
    }

Snapshot

dependencies {
    implementation('com.github.douglasjunior:android-simple-tooltip:master-SNAPSHOT') {
        changing = true // Gradle will then check for updates every 24 hours
    }
}

Contribute

New features, bug fixes and improvements in the translation are welcome! For questions and suggestions use the issues.

Before submit your PR, run the gradle check.

./gradlew build connectedCheck

Become a Patron! Donate

Known issues

  1. If you close the Dialog/Activity without the Tooltip is closed, there may be the exception java.lang.IllegalArgumentException: Could not lock surface. This error occurs because the animation continue for a while after closing the Dialog/Activity. (This error does not impact the execution of the app)

  2. If you call tooltip.show() after Activity/Dialog is closed, there may be the exception android.view.WindowLeaked: Activity has leaked window android.widget.PopupWindow$PopupViewContainer that was originally added here. Read more. (This error does not impact the execution of the app)

  3. From API 24, Android has changed the behavior of PopupWindow in relation to the setClippingEnabled property, which causes the Popup to be cut off. Read more.

Star History

Star History Chart

Licence

The MIT License (MIT)

Copyright (c) 2016 Douglas Nassif Roma Junior

See the full licence file.

android-simple-tooltip's People

Contributors

douglasjunior avatar lionscribe avatar mario-dario avatar milos192 avatar tabassumlatif avatar volser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-simple-tooltip's Issues

Programmatically created content

I have successfully integrated your library as a plugin for DroidScript.

My question/problem is content (all content) is created dynamically. So, there are no resource IDs.

I can pass a object into the plugin (for example a LinearLayout) and want to use this inside the tooltip.

Can you direct me to a way to do this, even if it means changing source.

Thank you for this library!

view perform click called after dismissal

Is there any particular reason why v.performClick() is called at the beginning instead of the end of the method?

The reason is that I (i imagine many face the same) want to use the click of the view to also toggle the tooltip state.

imgViewInfoIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSimpleTooltip!=null && mSimpleTooltip.isShowing())
                {
                    mSimpleTooltip.dismiss();
                }else{
                mSimpleTooltip = new SimpleTooltip.Builder(getActivity())
                        .anchorView(imgViewInfoIcon)
                        .text(mFormDescription)
                        .gravity(Gravity.BOTTOM)
                        .animated(false)
                        .showArrow(true)
                        .transparentOverlay(false)
                        .build();
                    mSimpleTooltip.show();
                }
            }
        });

This should work. The thing is that the tooltip is being dismissed BEFORE the onclick is dispatched so it will always be false.

What happens now is that if i click on my info icon, then the tooltip displays. If i tap it again (which most users do, to close it) then the tooltip closes and opens in a flash.

ToolTip OnClickListener

Is it possible to have an option to know if the tooltip was dismissed from clicking it? I need to know if the tooltip was dismissed from clicking it instead of from touching another element on the screen.

I tried the dismissOnOutsideTouch(false), but i need the tooltip to disappear when user does other actions, so this approach is not perfect for me.

onDismiss() not working

hello!
i m calling tooltip.build().dismiss(); in my onBackpress() method but it gives me exception
my dismiss code is..

 if (tooltip != null && tooltip.isShowing()) {
        tooltip.dismiss();
    }

and exception is

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
                                                                        at android.view.ViewGroup.addViewInner(ViewGroup.java:3582)
                                                                        at android.view.ViewGroup.addView(ViewGroup.java:3435)
                                                                        at android.view.ViewGroup.addView(ViewGroup.java:3380)
                                                                        at android.view.ViewGroup.addView(ViewGroup.java:3356)
                                                                        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.configContentView(SimpleTooltip.java:265)
                                                                        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.init(SimpleTooltip.java:148)
                                                                        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.<init>(SimpleTooltip.java:143)
                                                                        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.<init>(SimpleTooltip.java:67)
                                                                        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip$Builder.build(SimpleTooltip.java:605)
                                                                        at com.sysops.thenx.fragment.WorkOut.onDetach(WorkOut.java:1438)
                                                                        at android.support.v4.app.Fragment.performDetach(Fragment.java:2436)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1443)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1523)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1598)
                                                                        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2145)
                                                                        at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
                                                                        at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:822)
                                                                        at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:775)
                                                                        at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:178)
                                                                        at com.sysops.thenx.activity.MainActivity.onBackPressed(MainActivity.java:162)
                                                                        at android.app.Activity.onKeyUp(Activity.java:2231)
                                                                        at android.view.KeyEvent.dispatch(KeyEvent.java:2706)
                                                                        at android.app.Activity.dispatchKeyEvent(Activity.java:2475)
                                                                        at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:547)
                                                                        at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                        at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)
                                                                        at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2019)
                                                                        at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4133)
                                                                        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4107)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3613)
                                                                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3663)
                                                                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3632)
                                                                        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3739)
                                                                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3640)
                                                                        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3796)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3613)
                                                                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3663)
                                                                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3632)
                                                                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3640)
                                                                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3613)
                                                                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3663)
                                                                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3632)
                                                                        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3772)
                                                                        at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3934)
                                                                        at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2019)
                                                                        at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1713)
                                                                    	at android.view.inputmethod.InputMethodM

please help me out thank you

Listview Item click listner don't work

tooltip having listview and i want to item click listner of listvew not work

This library use==>compile 'com.github.douglasjunior:android-simple-tooltip:0.2.0'

Listview lv=(Listview)**tooltip**.findViewById(R.id.lv);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Toast.makeText(MainActivity.this,  "hello" , Toast.LENGTH_SHORT).show();

            }
});

SimpleTooltip.java line 354, mPopupWindow.getContentView(): mPopupWindow is null

The issue is as follows:

Fatal Exception: java.lang.NullPointerException.

The stack trace:

io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip$9.onGlobalLayout(SimpleTooltip.java:483)
android.view.ViewTreeObserver.dispatchOnGlobalLayout (ViewTreeObserver.java:667)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2048)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1181)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:4943)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:776)

I don't know exactly how this occur. This issue could be fixed checking whether mPopupWindow is shown or null.

margin not working / Toolbar

I am trying to place the tooltip to the left of the toolbar in the actionbar (the 3 dots in the top right corner)
it covers up the 3 dots.
I tried with the margin method to push it over a bit but it doesnt do anything.
I tried the margin method with other views, just to test, and it didnt do anything easier.

new SimpleTooltip.Builder(this)
           .margin(Float.valueOf(100))
                .anchorView(toolbar)
                .text("Texto do Tooltip")
                .gravity(Gravity.END)
                .animated(true)
                .transparentOverlay(true)
                .arrowColor(Color.RED)
                .margin(Float.valueOf(16))
                .arrowDirection(ArrowDrawable.RIGHT)
                .build()
                .show();

Arrow overlaps with the content view

I'm using a semi-transparent background for the content view. The issue is shown on an attached image below:
screenshot 2016-11-10 16 40 15

I see it's caused by https://github.com/douglasjunior/android-simple-tooltip/blob/master/library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/SimpleTooltip.java#L420 (and a similar code bellow for Gravity.START). However, I can't figure out why do you add this 1px offset? And if this offset is required, how can I avoid overlapping? I've tried using padding like:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="1px"
        android:bottom="1px"
        android:left="1px"
        android:right="1px"
        android:drawable="@drawable/rounded_semitransparent_black" />
</layer-list>

But this workaround leads to another visual glitch (this time Android framework specific), so it's not an option:
screenshot 2016-11-14 14 57 13

Thank you for your awesome library!

token null is not valid

Seeing the following issue:

Fatal Exception: android.view.WindowManager$BadTokenException Unable to add window -- token null is not valid; is your activity running?

With the stack trace:

android.view.ViewRootImpl.setView (ViewRootImpl.java:576)
android.widget.PopupWindow.showAtLocation (PopupWindow.java:861)
io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip$1.run (SimpleTooltip.java:166)
android.os.Handler.handleCallback (Handler.java:739)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:703)

I suspect it may be something hitting when the app is interrupted and/or closed while in the process of spawning the tooltip, but I haven't had time to investigate yet. Thought I'd mention it, though.

This is with the latest version.

How to optimise the code instead each time calling same things

Hello Sir,
Below code is used as many time as we want to create a new tooltip.So rather than that, we can create a function and in that, we can pass a parameter as (String, int) for text and gravity.
Or maybe I am wrong so help me to figure out this problem.
new SimpleTooltip.Builder(this)
.anchorView(v)
.text(R.string.btn_animated)
.gravity(Gravity.TOP)
.animated(true)
.build()
.show();

Windows Leak Error

01-19 14:49:36.767 29017-29017/se.yo.android.bloglovin.dev E/WindowManager: android.view.WindowLeaked: Activity se.yo.android.bloglovincore.view.activity.FeedActivity has leaked window android.widget.PopupWindow$PopupDecorView{92cb78f V.E...... .......D 0,0-1120,412} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
        at android.widget.PopupWindow.invokePopup(PopupWindow.java:1378)
        at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1154)
        at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1121)
        at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip$1.run(SimpleTooltip.java:171)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

how to compile and run 22 api or below

its need 23 api to compile, my app cant move to 23 currently, and compiling below 23 not workng for this lib. can use 22 or below to avoid 23 sdk compilation in my project with this tooltip lib?

library include

Awesome little library - been looking for something like this for a while, and I think this is probably the best implementation of this functionality for Android that I've seen yet.

I'm not having much luck including it from jitpack.io, though. When I try, I get the following error:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve com.github.douglasjunior:android-simple-tooltip:0.1.1.
     Required by:
         test:app:unspecified
      > Could not resolve com.github.douglasjunior:android-simple-tooltip:0.1.1.
         > Could not get resource 'https://jitpack.io/com/github/douglasjunior/android-simple-tooltip/0.1.1/android-simple-tooltip-0.1.1.pom'.
            > Could not GET 'https://jitpack.io/com/github/douglasjunior/android-simple-tooltip/0.1.1/android-simple-tooltip-0.1.1.pom'.
               > peer not authenticated

Any idea what might be going wrong?

How to center text horizontally?

Hi! I've tried to override a style like:

<style name="simpletooltip_default" parent="@android:style/TextAppearance">
        <item name="android:gravity">center_horizontal</item>
        <item name="android:layout_centerHorizontal">true</item>
        <item name="android:layout_centerInParent">true</item>
    </style>

but nothing affects. Can you please help?

Why not give credit, keep license and not remove other attributes?

  • This lib is clearly a fork of https://github.com/sephiroth74/android-target-tooltip, I get it it doesn't have much support. But you should give credit when it's due. It's open source code why try to pass it as your own, don't take this in the wrong way, I'm just curious on how you stand on this ๐Ÿค”.

Also, you removed the ability to customize some stuff that was present on the original, other then that great job ๐Ÿ’ช.

java.lang.OutOfMemoryError

Hi there, I'm getting lots of out of memory errors. Can you please take a look

`Mar 4, 5:09 PM on app version 16
Samsung Galaxy Note2 (t03g), 2048MB RAM, Android 4.4
Report 1 of 3

java.lang.OutOfMemoryError:
at android.graphics.Bitmap.nativeCreate (Bitmap.java)
at android.graphics.Bitmap.createBitmap (Bitmap.java:928)
at android.graphics.Bitmap.createBitmap (Bitmap.java:901)
at android.graphics.Bitmap.createBitmap (Bitmap.java:868)
at io.github.douglasjunior.androidSimpleTooltip.OverlayView.createWindowFrame (OverlayView.java:81)
at io.github.douglasjunior.androidSimpleTooltip.OverlayView.dispatchDraw (OverlayView.java:68)
at android.view.View.draw (View.java:15413)
at android.view.View.getDisplayList (View.java:14301)
at android.view.View.getDisplayList (View.java:14343)
at android.view.View.draw (View.java:15124)
at android.view.ViewGroup.drawChild (ViewGroup.java:3309)
at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3146)
at android.view.View.draw (View.java:15413)
at android.widget.FrameLayout.draw (FrameLayout.java:472)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw (PhoneWindow.java:2583)
at android.view.View.getDisplayList (View.java:14301)
at android.view.View.getDisplayList (View.java:14343)
at android.view.HardwareRenderer$GlRenderer.buildDisplayList (HardwareRenderer.java:1570)
at android.view.HardwareRenderer$GlRenderer.draw (HardwareRenderer.java:1449)
at android.view.ViewRootImpl.draw (ViewRootImpl.java:2777)
at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2643)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2211)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1254)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6637)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:814)
at android.view.Choreographer.doCallbacks (Choreographer.java:614)
at android.view.Choreographer.doFrame (Choreographer.java:584)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:800)
at android.os.Handler.handleCallback (Handler.java:733)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:146)
at android.app.ActivityThread.main (ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative (Method.java)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
at dalvik.system.NativeStart.main (NativeStart.java)`

Is it compatible with Dialog.MinWidth themes?

Hi, thanks for this cool library. I have tried it in my app which uses Theme.AppCompat.Dialog.MinWidth, the app only covers 1/3 of the screen. When the tooltip triggers, it stretches the layout to fullscreen, once the tip is dismissed the layout goes back to normal.

I've tried many different ways to solve this, without success. I would appreciate if you could help me out.
Thanks in advance!

Arrow alignment

There is any way to achieve something like this:

screen shot 2017-08-18 at 20 42 40

Making the arrow align right and the tooltip width match parent?

Dismiss on button click

Let's say I have added this tooltip to a button view. Now I want to dismiss this tooltip only after I click the button.
There are only two ways to dismiss this tooltip:

  1. dismissOnInsideTouch
  2. dismissOnOutsideTouch

Is there any other way to dismiss this tooltip inside another view's click listener? for example:

final SimpleTooltip.Builder tut1 = new SimpleTooltip.Builder(this);
        tut1.anchorView(loveGoalMeterIV)
                .text("Texto do Tooltip")
                .gravity(Gravity.BOTTOM)
                .animated(true)
                .transparentOverlay(false)
                .dismissOnInsideTouch(false)
                .dismissOnOutsideTouch(false)
                .build()
                .show();

ImageView loveGoalMeterIV = findViewById(R.id.loveGoalMeterIV);

loveGoalMeterIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   tut1.hide()
            }
        });

how to give an index in a textview to keep the anchor point at?

Hi, i'm using spannable string and the issue is i've multiple tooltips required.
i need a solution to that, may be if i'd somehow pass an index of a textview, i'd get the textview at the correct position, since you've worked on this, could you guide what must i change?

Clickable view

can be element inner anchorView clickable with .modal(true) ?, I couldn't. I want to click only inner anchorView element.

how to compile and run 22 api or below

its need 23 api to compile, my app cant move to 23 currently, and compiling below 23 not workng for this lib. can use 22 or below to avoid 23 sdk compilation in my project with this tooltip lib?

Set custom font and size to text

Is there a way to set a custom font and font size in the for SimpleToolTip? I tried creating a layout file where the root view is a LinearLayout and it has one child, which is a TextView. The issue with this is that, there is a gap between the arrow and the content view. If it helps, below is my code and my layout view used as a contentView.

SimpleTooltip simpleTooltip = new SimpleTooltip.Builder(mContext)
                             .anchorView(mPartnershipLogIv)
                             .text("This is a tooltip being clicked!. Hello World! Second line. Third line. 4th line")
                             .gravity(Gravity.TOP)
                             .animated(false)
                             .textColor(ContextCompat.getColor(mContext, R.color.white))
                             .backgroundColor(ContextCompat.getColor(mContext, R.color.lagoon_dark))
                             .arrowColor(ContextCompat.getColor(mContext, R.color.lagoon_dark))
                             .transparentOverlay(false)
                             .dismissOnInsideTouch(true)
                             .dismissOnOutsideTouch(true)
                             .contentView(R.layout.tooltip_text_view, R.id.tooltipTv)
                             .build();
simpleTooltip.show();

xml file for R.layout.tooltip_text_view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tooltipTv"
        android:padding="@dimen/keyline_8dp"
        android:textSize="@dimen/textsize_14sp"
        android:textColor="@color/white"
        android:background="@color/lagoon_dark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

Scrolling issue

Hi
What should I do, if the user srcolls the layout with the view inside that is used to show a simple tooltip?

toolTip.dismiss() does not dismiss/hide the tooltip.

Hi @douglasjunior,

I have a similar kind of problem, I want to close my tooltip after 4 seconds, but I am not quite able to do that.

Below is my code:

SimpleToolTip simpleToolTip;
simpleToolTip = new SimpleTooltip.Builder(getContext())
        .anchorView(binding.toolTipAnchorView)
        .contentView(R.layout.tooltip_layout, R.id.tooltip_text)
        .text(R.string.tool_tip_add_sharing_text)
        .gravity(Gravity.TOP)
        .transparentOverlay(true)
        .build();
simpleToolTip.show();

new Handler.postDelayed(
    new Runnable() {
        @Override
        if(simpleToolTip.isShowing()) {
            simpleToolTi[p.dismiss();
        }
    }, 4000);

What happens here is, dismiss() is called the first time, but the tooltip does not actually hide from the screen.
How I know dismiss() is getting called is because the thread runs 3 more times and isShowing() returns false after the 1st time.

Please let me know the response at your earliest.

Thanks.

Overlay not working at times

Hi,

I am using the overlay with modal(true) tooltip in some of my screens and it works perfectly fine as needed. But in some fragment the overlay is not showing and even the modal is not working. I don't see any difference in the code as I am using the same code which works in other fragments. I have added the code below which I am using and also the screenshot of that screen where the overlay is not showing. Can you find out if there is any bug in that?

 new SimpleTooltip.Builder(baseActivity)
            .anchorView(img_camera)
            .text("Tap here to change your profile pic!!!")
            .textColor(ContextCompat.getColor(baseActivity, R.color.colorToolBar))
            .backgroundColor(ContextCompat.getColor(baseActivity, R.color.colorWhite))
            .gravity(Gravity.TOP)
            .dismissOnInsideTouch(true)
            .dismissOnOutsideTouch(false)
            .modal(true)
            .arrowColor(ContextCompat.getColor(baseActivity, R.color.colorWhite))
            .arrowHeight(25.0f)
            .arrowWidth(25.0f)
            .animated(true)
            .animationDuration(800)
            .transparentOverlay(false)
            .build()
            .show();

device-2018-03-18-164949

Thanks in advance.

Rare crash in OverlayView

I have logged some crashes from users in Crashlytics that I am unable to reproduce myself. It seems like the Bitmap in OverlayView is sometimes null when it is passed to Canvas.drawBitmap().

Again, I have no idea how to reproduce this. We've had 28 crashes from showing the tooltip about 70,000 times, so it happens about 0.005% of the time. Could be a race condition.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference
       at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1270)
       at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:257)
       at android.graphics.Canvas.drawBitmap(Canvas.java:1336)
       at io.github.douglasjunior.androidSimpleTooltip.OverlayView.dispatchDraw(OverlayView.java:70)
       at android.view.View.draw(View.java:17235)
       at android.view.View.updateDisplayListIfDirty(View.java:16197)
       at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3758)
       at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3738)
       at android.view.View.updateDisplayListIfDirty(View.java:16160)
       at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:676)
       at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:682)
       at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:796)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:2989)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2783)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2374)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1364)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6757)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:923)
       at android.view.Choreographer.doCallbacks(Choreographer.java:735)
       at android.view.Choreographer.doFrame(Choreographer.java:667)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:909)
       at android.os.Handler.handleCallback(Handler.java:755)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:6524)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

The tooltip is created like so:

myTooltip = new SimpleTooltip.Builder(this)
                .anchorView(myButton)
                .text(getResources().getString(R.string.MY_TOOLTIP_TEXT))
                .textColor(getResources().getColor(R.color.white))
                .backgroundColor(getResources().getColor(R.color.my_color))
                .arrowColor(getResources().getColor(R.color.my_color))
                .gravity(Gravity.TOP)
                .animated(true)
                .transparentOverlay(false)
                .onDismissListener(new SimpleTooltip.OnDismissListener() {
                    @Override
                    public void onDismiss(SimpleTooltip tooltip) {
                        lockScrollView = false;
                    }
                })
                .build();

The lockScrollView variable is a boolean that prevents an enclosing ScrollView from scrolling. It's probably unrelated to the crash, but here is how that works:

scrollView = (ObservableScrollView) findViewById(R.id.scrollview);
        scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return lockScrollView;
            }
        });

NullPointerException PopupWindow.getContentView()

if (dismissed) return; - Why this line is below mPopupWindow.getContentView() in SimpleTooltip.java?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.PopupWindow.getContentView()' on a null object reference
       at io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip$5.onGlobalLayout(SimpleTooltip.java:398)
       at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:982)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2460)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1487)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7450)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
       at android.view.Choreographer.doCallbacks(Choreographer.java:695)
       at android.view.Choreographer.doFrame(Choreographer.java:631)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7229)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Not getting any tooltip in ListView header's element in Fragment

i have used fragment and in fragment i have used ListView and in ListView i have added header and in header i have two element TextView and ImageView and i want to put tooltip in both ImageView and TextView
i have tried below code to show tooltip. but i'm not able to show it in header part of ListView.
so Please let me know if any suggestion..thanks

 new SimpleTooltip.Builder(getActivity())
                .anchorView(headerView.findViewById(R.id.textView_headerView))
                .text("Test")
                .gravity(Gravity.TOP)
                .animated(true)
                .transparentOverlay(false)
                .build()
                .show();

dismiss tooltip without any click

I am showing tooltip on menu item in fragment. I want it to show only when some specific menu item (say menu item A) is visible.

If menu item (A) is not visible I want it to dismiss without any click event.

This is my code-
if(item_search_map.isVisible()) {

                final View menuItemView = getActivity().findViewById(R.id.item_search_map);
                tooltip = new SimpleTooltip.Builder(getActivity());
               // new SimpleTooltip.Builder(getActivity())
                tooltip .anchorView(menuItemView)
                        .margin(R.dimen.simpletooltip_margin)
                        .text("See,travellers \n around you")
                        .textColor(Color.parseColor("#FFFFFF"))
                        .gravity(Gravity.START)
                        .backgroundColor(Color.parseColor("#B3555555"))
                        .dismissOnOutsideTouch(false)
                        .dismissOnInsideTouch(false)
                        .transparentOverlay(true)
                        .arrowColor(Color.parseColor("#B3555555"))
                        .build()
                        .show();
        } else {
        Log.d("else","dismiss");
        tooltip.onDismissListener(new SimpleTooltip.OnDismissListener() {
            @Override
            public void onDismiss(SimpleTooltip tooltip) {
                tooltip.dismiss();
            }
        });
    }

Stretching dialog and changing dialog size

Hi there, I'm displaying an activity as a dialog using dialog theme. It is appcompat activity. After triggered the the simple tool time, it is changing my dialog size. After triggering it, My dialog taking all the space available on screen. How can I resolve it?

Custom view height is cut on Android 24

Hey,

I have an issue on a Nvidia Shield K1 (Android 7.0). The height of a custom view is cut, when the anchor point is on the very top or very bottom of the screen.

On my phones / 10" tablet I don't have this problem.

Click outside of modal window closes modal

Hi

I'm trying your sample at commit 3a0e4d3 with this settings:

final SimpleTooltip tooltip = new SimpleTooltip.Builder(this)
.anchorView(v)
.text(R.string.btn_modal_custom)
.gravity(Gravity.TOP)
.dismissOnOutsideTouch(false)
.dismissOnInsideTouch(false)
.modal(true)
.animated(true)
.animationDuration(2000)
.animationPadding(SimpleTooltipUtils.pxFromDp(50))
.contentView(R.layout.tooltip_custom, R.id.tv_text)
.focusable(true)
.build();
final EditText ed = tooltip.findViewById(R.id.ed_text);
tooltip.findViewById(R.id.btn_next).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v2) {
if (tooltip.isShowing())
tooltip.dismiss();
new SimpleTooltip.Builder(v.getContext())
.anchorView(v)
.text(ed.getText())
.gravity(Gravity.BOTTOM)
.build()
.show();
}
});
tooltip.show();
It seems like dismissOnOutsideTouch do not work properly, when I click below the "modal custom" button, the modal popup disapear. I expected, it will stay visible. Thanks.
bug

it crashes when try to open other activity from tooltip display on a activity and does not close it

java.lang.IllegalArgumentException: width and height must be > 0
06-03 17:11:12.065 23299-23299/ W/System.err:     at android.graphics.Bitmap.createBitmap(Bitmap.java:836)
06-03 17:11:12.065 23299-23299/ W/System.err:     at android.graphics.Bitmap.createBitmap(Bitmap.java:815)
06-03 17:11:12.065 23299-23299/ W/System.err:     at android.graphics.Bitmap.createBitmap(Bitmap.java:782)
06-03 17:11:12.065 23299-23299/ W/System.err:     at io.github.douglasjunior.androidSimpleTooltip.OverlayView.createWindowFrame(OverlayView.java:72)
06-03 17:11:12.066 23299-23299/ W/System.err:     at io.github.douglasjunior.androidSimpleTooltip.OverlayView.dispatchDraw(OverlayView.java:65)

Text size change

Hey,
awesome library! Is there a way to change text size inside tooltip without using custom layout?

Thanks, have a nice day.

change text style to bold.

Hi

How can I change text style of text inside tooltip i.e. from normal to bold.

tooltip library version - compile 'com.github.douglasjunior:android-simple-tooltip:0.2.1'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.