├── .gitignore
├── LICENSE.txt
├── README.md
├── build.gradle
├── example
├── .gitignore
├── build.gradle
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── venmo
│ │ └── view
│ │ └── tooltip
│ │ └── example
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── venmo
│ │ └── view
│ │ └── tooltip
│ │ └── example
│ │ └── TooltipActivity.java
│ └── res
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── layout
│ └── activity_tooltip.xml
│ ├── menu
│ └── tooltip.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── gradle.properties
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── venmo
│ │ │ └── view
│ │ │ ├── ArrowAlignment.java
│ │ │ ├── ArrowAlignmentHelper.java
│ │ │ ├── ArrowLocation.java
│ │ │ ├── BottomArrowLocation.java
│ │ │ ├── TooltipView.java
│ │ │ └── TopArrowLocation.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── dimens.xml
│ └── test
│ └── java
│ └── com
│ └── venmo
│ └── view
│ ├── AbstractShadowViewAssert.java
│ ├── Assertions.java
│ ├── ShadowViewAssert.java
│ └── TooltipViewTest.java
├── sample.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea
4 | .DS_Store
5 | /build
6 | *.iml
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Venmo
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TooltipView
2 |
3 | A dead simple way to to add tooltips to your Android app.
4 |
5 | ```xml
6 |
16 | ```
17 |
18 | Here are the attribute options:
19 | ```
20 | app:tooltipColor="#66009900"
21 | app:anchoredView="@id/anchored_view"
22 | app:arrowWidth="120dp"
23 | app:arrowHeight="120dp"
24 | app:cornerRadius="16dp"
25 | app:arrowAlignmentOffset="32dp"
26 | app:arrowAlignment="end"
27 | app:arrowLocation="top"
28 | ```
29 |
30 | Screenshot:
31 | 
32 |
33 | # Download
34 | ```groovy
35 | compile 'com.venmo.view.tooltip:tooltip:0.1.2@aar'
36 | ```
37 |
38 | ## TODO
39 | - tooltips on the sides of the bubble
40 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:1.2.3'
7 | }
8 | }
9 |
10 | allprojects {
11 | repositories {
12 | jcenter()
13 | }
14 | }
15 |
16 | task wrapper(type: Wrapper) {
17 | gradleVersion = '2.4'
18 | }
19 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.venmo.view.tooltip.example"
9 | minSdkVersion 14
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | }
15 |
16 | dependencies {
17 | compile project(':library')
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/com/venmo/view/tooltip/example/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view.tooltip.example;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/example/src/main/java/com/venmo/view/tooltip/example/TooltipActivity.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view.tooltip.example;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 |
8 |
9 | public class TooltipActivity extends Activity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_tooltip);
15 | }
16 |
17 |
18 | @Override
19 | public boolean onCreateOptionsMenu(Menu menu) {
20 | // Inflate the menu; this adds items to the action bar if it is present.
21 | getMenuInflater().inflate(R.menu.tooltip, menu);
22 | return true;
23 | }
24 |
25 | @Override
26 | public boolean onOptionsItemSelected(MenuItem item) {
27 | // Handle action bar item clicks here. The action bar will
28 | // automatically handle clicks on the Home/Up button, so long
29 | // as you specify a parent activity in AndroidManifest.xml.
30 | int id = item.getItemId();
31 | if (id == R.id.action_settings) {
32 | return true;
33 | }
34 | return super.onOptionsItemSelected(item);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/venmo/tooltip-view/160beab4abdf20b721a2987eca4f8717e27ea73d/example/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_tooltip.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
24 |
25 |
33 |
34 |
44 |
45 |
52 |
53 |
63 |
64 |
72 |
73 |
82 |
83 |
92 |
93 |
--------------------------------------------------------------------------------
/example/src/main/res/menu/tooltip.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Example
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=0.1.2
2 | VERSION_CODE=1
3 | GROUP=com.venmo.view.tooltip
4 |
5 | POM_DESCRIPTION=Dead simple Android Tooltip Views
6 | POM_URL=https://github.com/venmo/tooltip-view
7 | POM_SCM_URL=https://github.com/venmo/tooltip-view
8 | POM_SCM_CONNECTION=scm:git@github.com:venmo/tooltip-view.git
9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:venmo/tooltip-view.git
10 | POM_LICENCE_NAME=MIT License
11 | POM_LICENCE_URL=https://github.com/venmo/tooltip-view/blob/master/LICENSE.txt
12 | POM_LICENCE_DIST=repo
13 | POM_DEVELOPER_ID=ronshapiro
14 | POM_DEVELOPER_NAME=Ron Shapiro
15 |
16 | org.gradle.daemon=true
17 | org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/venmo/tooltip-view/160beab4abdf20b721a2987eca4f8717e27ea73d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Nov 22 20:05:53 EST 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | import com.android.builder.core.BuilderConstants
2 |
3 | apply plugin: 'com.android.library'
4 |
5 | android {
6 | compileSdkVersion 22
7 | buildToolsVersion "22.0.1"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 22
12 | }
13 | }
14 |
15 | dependencies {
16 | compile 'com.android.support:support-annotations:22.2.1'
17 | testCompile 'junit:junit:4.11'
18 | testCompile 'org.robolectric:robolectric:3.0'
19 | testCompile 'com.squareup.assertj:assertj-android:1.0.0'
20 | }
21 |
22 | android.libraryVariants.all { variant ->
23 | def name = variant.buildType.name
24 | if (!name.equals(BuilderConstants.DEBUG)) {
25 | def task = project.tasks.create "jar${name.capitalize()}", Jar
26 | task.dependsOn variant.javaCompile
27 | task.from variant.javaCompile.destinationDir
28 | artifacts.add('archives', task);
29 | }
30 | }
31 |
32 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=TooltipView
2 | POM_ARTIFACT_ID=tooltip
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/ArrowAlignment.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | public enum ArrowAlignment {
4 | START(0), CENTER(1), END(2), ANCHORED_VIEW(3);
5 |
6 | private final int value;
7 |
8 | ArrowAlignment(int value) {
9 | this.value = value;
10 | }
11 |
12 | public static ArrowAlignment getAlignment(int value) {
13 | for (ArrowAlignment alignment : values()) {
14 | if (value == alignment.getValue()) {
15 | return alignment;
16 | }
17 | }
18 | throw new IllegalArgumentException("No matching ArrowAlignment with value: " +value);
19 | }
20 |
21 | public int getValue() {
22 | return value;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/ArrowAlignmentHelper.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.graphics.RectF;
4 | import android.view.View;
5 |
6 | public final class ArrowAlignmentHelper {
7 |
8 | public static float calculateArrowMidPoint(TooltipView view, RectF rectF) {
9 | int offset = view.getAlignmentOffset();
10 | float middle = 0f;
11 |
12 | switch (view.getArrowAlignment()) {
13 | case START:
14 | middle = offset == 0 ? rectF.width() / 4 : offset;
15 | break;
16 | case CENTER:
17 | middle = rectF.width() / 2;
18 | if (offset > 0)
19 | throw new IllegalArgumentException(
20 | "Offsets are not support when the tooltip arrow is anchored in the middle of the view.");
21 | break;
22 | case END:
23 | middle = rectF.width();
24 | middle -= (offset == 0 ? rectF.width() / 4 : offset);
25 | break;
26 | case ANCHORED_VIEW:
27 | middle = rectF.width() / 2;
28 | if (view.getAnchoredViewId() != View.NO_ID) {
29 | View anchoredView = ((View) view.getParent())
30 | .findViewById(view.getAnchoredViewId());
31 | middle += anchoredView.getX() + anchoredView.getWidth() / 2 - view.getX()
32 | - view.getWidth() / 2;
33 | }
34 | break;
35 | }
36 | return middle;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/ArrowLocation.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.graphics.Canvas;
4 |
5 | interface ArrowLocation {
6 |
7 | void configureDraw(TooltipView view, Canvas canvas);
8 | }
9 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/BottomArrowLocation.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.RectF;
7 | import android.view.View;
8 |
9 | import static android.graphics.Path.Direction;
10 |
11 | class BottomArrowLocation implements ArrowLocation {
12 |
13 | @Override
14 | public void configureDraw(TooltipView view, Canvas canvas) {
15 | view.setTooltipPath(new Path());
16 | RectF rectF = new RectF(canvas.getClipBounds());
17 | rectF.bottom -= view.getArrowHeight();
18 | view.getTooltipPath()
19 | .addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(), Direction.CW);
20 |
21 | float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF);
22 |
23 | view.getTooltipPath().moveTo(middle, view.getHeight());
24 | int arrowDx = view.getArrowWidth() / 2;
25 | view.getTooltipPath().lineTo(middle - arrowDx, rectF.bottom);
26 | view.getTooltipPath().lineTo(middle + arrowDx, rectF.bottom);
27 | view.getTooltipPath().close();
28 |
29 | view.setPaint(new Paint(Paint.ANTI_ALIAS_FLAG));
30 | view.getTooltipPaint().setColor(view.getTooltipColor());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/TooltipView.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.support.annotation.ColorRes;
11 | import android.support.annotation.DimenRes;
12 | import android.support.annotation.IdRes;
13 | import android.support.annotation.NonNull;
14 | import android.support.annotation.StyleableRes;
15 | import android.util.AttributeSet;
16 | import android.view.View;
17 | import android.widget.TextView;
18 |
19 | public class TooltipView extends TextView {
20 |
21 | private static final int NOT_PRESENT = Integer.MIN_VALUE;
22 | private int arrowHeight;
23 | private int arrowWidth;
24 | private int cornerRadius;
25 | private @IdRes int anchoredViewId;
26 | private @ColorRes int tooltipColor;
27 | private ArrowLocation arrowLocation;
28 | private ArrowAlignment arrowAlignment;
29 | private int alignmentOffset;
30 | private int arrowPositioning;
31 | private Paint paint;
32 | private Path tooltipPath;
33 |
34 | public TooltipView(Context context) {
35 | super(context);
36 | init(null, 0);
37 | }
38 |
39 | public TooltipView(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | init(attrs, 0);
42 | }
43 |
44 | public TooltipView(Context context, AttributeSet attrs, int defStyle) {
45 | super(context, attrs, defStyle);
46 | init(attrs, defStyle);
47 | }
48 |
49 | private void init(AttributeSet attrs, int defStyle) {
50 | Resources res = getResources();
51 | TypedArray a = getContext().obtainStyledAttributes(
52 | attrs, R.styleable.TooltipView, defStyle, 0);
53 | try {
54 | anchoredViewId = a.getResourceId(R.styleable.TooltipView_anchoredView, View.NO_ID);
55 | tooltipColor = a.getColor(R.styleable.TooltipView_tooltipColor, Color.TRANSPARENT);
56 | cornerRadius = getDimension(a, R.styleable.TooltipView_cornerRadius,
57 | R.dimen.tooltip_default_corner_radius);
58 | arrowHeight = getDimension(a, R.styleable.TooltipView_arrowHeight,
59 | R.dimen.tooltip_default_arrow_height);
60 | arrowWidth = getDimension(a, R.styleable.TooltipView_arrowWidth,
61 | R.dimen.tooltip_default_arrow_width);
62 | arrowPositioning = a.getInteger(R.styleable.TooltipView_arrowLocation,
63 | res.getInteger(R.integer.tooltip_default_arrow_location));
64 | arrowLocation = arrowPositioning == 0 ? new TopArrowLocation()
65 | : new BottomArrowLocation();
66 | arrowAlignment = ArrowAlignment.getAlignment(
67 | a.getInteger(R.styleable.TooltipView_arrowAlignment, res.getInteger(
68 | R.integer.tooltip_default_arrow_alignment)));
69 | alignmentOffset = getDimension(a, R.styleable.TooltipView_arrowAlignmentOffset,
70 | R.dimen.tooltip_default_offset);
71 | } finally {
72 | a.recycle();
73 | }
74 | }
75 |
76 | @Override
77 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
78 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
79 | setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + arrowHeight);
80 | }
81 |
82 | @Override
83 | public void invalidate() {
84 | super.invalidate();
85 | tooltipPath = null;
86 | paint = null;
87 | }
88 |
89 | @Override
90 | protected void onDraw(@NonNull Canvas canvas) {
91 | if (tooltipPath == null || paint == null) {
92 | arrowLocation.configureDraw(this, canvas);
93 | }
94 | canvas.drawPath(tooltipPath, paint);
95 | super.onDraw(canvas);
96 | }
97 |
98 | Paint getTooltipPaint() {
99 | return paint;
100 | }
101 |
102 | void setPaint(Paint paint) {
103 | this.paint = paint;
104 | }
105 |
106 | Path getTooltipPath() {
107 | return tooltipPath;
108 | }
109 |
110 | void setTooltipPath(Path tooltipPath) {
111 | this.tooltipPath = tooltipPath;
112 | }
113 |
114 | public int getArrowHeight() {
115 | return arrowHeight;
116 | }
117 |
118 | public void setArrowHeight(int arrowHeight) {
119 | this.arrowHeight = arrowHeight;
120 | invalidate();
121 | }
122 |
123 | public void setArrowHeightResource(@DimenRes int resId) {
124 | arrowHeight = getResources().getDimensionPixelSize(resId);
125 | invalidate();
126 | }
127 |
128 | public int getArrowWidth() {
129 | return arrowWidth;
130 | }
131 |
132 | public void setArrowWidth(int arrowWidth) {
133 | this.arrowWidth = arrowWidth;
134 | invalidate();
135 | }
136 |
137 | public void setArrowWidthResource(@DimenRes int resId) {
138 | arrowWidth = getResources().getDimensionPixelSize(resId);
139 | invalidate();
140 | }
141 |
142 | public int getCornerRadius() {
143 | return cornerRadius;
144 | }
145 |
146 | public void setCornerRadius(int cornerRadius) {
147 | this.cornerRadius = cornerRadius;
148 | invalidate();
149 | }
150 |
151 | public void setCornerRadiusResource(@DimenRes int resId) {
152 | cornerRadius = getResources().getDimensionPixelSize(resId);
153 | invalidate();
154 | }
155 |
156 | public int getAnchoredViewId() {
157 | return anchoredViewId;
158 | }
159 |
160 | public void setAnchoredViewId(@IdRes int anchoredViewId) {
161 | this.anchoredViewId = anchoredViewId;
162 | invalidate();
163 | }
164 |
165 | public int getTooltipColor() {
166 | return tooltipColor;
167 | }
168 |
169 | public void setTooltipColor(int tooltipColor) {
170 | this.tooltipColor = tooltipColor;
171 | invalidate();
172 | }
173 |
174 | public void setArrowPositioning(int arrowPositioning) {
175 | this.arrowPositioning = arrowPositioning;
176 | invalidate();
177 | }
178 |
179 | public ArrowAlignment getArrowAlignment() {
180 | return arrowAlignment;
181 | }
182 |
183 | public void setArrowAlignment(ArrowAlignment arrowAlignment) {
184 | this.arrowAlignment = arrowAlignment;
185 | invalidate();
186 | }
187 |
188 | public int getAlignmentOffset() {
189 | return alignmentOffset;
190 | }
191 |
192 | public void setAlignmentOffset(int offset) {
193 | this.alignmentOffset = offset;
194 | invalidate();
195 | }
196 |
197 | public void setAlignmentOffsetResource(@DimenRes int resId) {
198 | this.alignmentOffset = getResources().getDimensionPixelSize(resId);
199 | invalidate();
200 | }
201 |
202 | private int getDimension(TypedArray a, @StyleableRes int styleableId,
203 | @DimenRes int defaultDimension) {
204 | int result = a.getDimensionPixelSize(styleableId, NOT_PRESENT);
205 | if (result == NOT_PRESENT) {
206 | result = getResources().getDimensionPixelSize(defaultDimension);
207 | }
208 | return result;
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/library/src/main/java/com/venmo/view/TopArrowLocation.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.RectF;
7 | import android.view.View;
8 |
9 | import static android.graphics.Path.Direction;
10 |
11 | class TopArrowLocation implements ArrowLocation {
12 |
13 | @Override
14 | public void configureDraw(TooltipView view, Canvas canvas) {
15 | view.setTooltipPath(new Path());
16 | RectF rectF = new RectF(canvas.getClipBounds());
17 | rectF.top += view.getArrowHeight();
18 |
19 | view.getTooltipPath().addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(),
20 | Direction.CW);
21 |
22 | float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF);
23 |
24 | view.getTooltipPath().moveTo(middle, 0f);
25 | int arrowDx = view.getArrowWidth() / 2;
26 | view.getTooltipPath().lineTo(middle - arrowDx, rectF.top);
27 | view.getTooltipPath().lineTo(middle + arrowDx, rectF.top);
28 | view.getTooltipPath().close();
29 |
30 | view.setPaint(new Paint(Paint.ANTI_ALIAS_FLAG));
31 | view.getTooltipPaint().setColor(view.getTooltipColor());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 8dp
3 | 16dp
4 | 4dp
5 | 0dp
6 | 1
7 | 3
8 |
--------------------------------------------------------------------------------
/library/src/test/java/com/venmo/view/AbstractShadowViewAssert.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import org.assertj.core.api.AbstractAssert;
4 | import org.robolectric.shadows.ShadowView;
5 |
6 | import static org.assertj.core.api.Assertions.assertThat;
7 |
8 | public abstract class AbstractShadowViewAssert, A extends ShadowView>
9 | extends AbstractAssert {
10 |
11 | protected AbstractShadowViewAssert(A actual, Class selfType) {
12 | super(actual, selfType);
13 | }
14 |
15 | public S wasInvalidated() {
16 | isNotNull();
17 | assertThat(actual.wasInvalidated())
18 | .overridingErrorMessage("Expected view to be invalidated but was not")
19 | .isTrue();
20 | return myself;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/library/src/test/java/com/venmo/view/Assertions.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import org.robolectric.shadows.ShadowView;
4 |
5 | /** Assertions for testing Robolectric Shadow classes. */
6 | public final class Assertions {
7 |
8 | public static ShadowViewAssert assertThat(ShadowView actual) {
9 | return new ShadowViewAssert(actual);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/library/src/test/java/com/venmo/view/ShadowViewAssert.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import org.robolectric.shadows.ShadowView;
4 |
5 | public class ShadowViewAssert extends AbstractShadowViewAssert {
6 | public ShadowViewAssert(ShadowView actual) {
7 | super(actual, ShadowViewAssert.class);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/library/src/test/java/com/venmo/view/TooltipViewTest.java:
--------------------------------------------------------------------------------
1 | package com.venmo.view;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.annotation.IdRes;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.robolectric.Robolectric;
10 | import org.robolectric.RobolectricGradleTestRunner;
11 | import org.robolectric.annotation.Config;
12 | import org.robolectric.shadows.ShadowView;
13 |
14 | import static com.venmo.view.Assertions.assertThat;
15 | import static org.robolectric.Shadows.shadowOf;
16 |
17 | @RunWith(RobolectricGradleTestRunner.class)
18 | @Config(constants = BuildConfig.class,
19 | sdk = 21,
20 | manifest = "build/intermediates/manifests/androidTest/debug/AndroidManifest.xml")
21 | public class TooltipViewTest {
22 |
23 | private static final @IdRes int sampleId = 234;
24 |
25 | private TooltipView createView() {
26 | Context context = Robolectric.buildActivity(Activity.class).create().get();
27 | return new TooltipView(context);
28 | }
29 |
30 | @Test
31 | public void settersInvalidateView() {
32 | TooltipView view = createView();
33 | ShadowView shadow = shadowOf(view);
34 | shadow.clearWasInvalidated();
35 |
36 | view.setAnchoredViewId(sampleId);
37 | assertThat(shadow).wasInvalidated();
38 | shadow.clearWasInvalidated();
39 |
40 | view.setArrowHeight(123);
41 | assertThat(shadow).wasInvalidated();
42 | shadow.clearWasInvalidated();
43 |
44 | view.setArrowHeightResource(R.dimen.tooltip_default_arrow_height);
45 | assertThat(shadow).wasInvalidated();
46 | shadow.clearWasInvalidated();
47 |
48 | view.setArrowWidth(123);
49 | assertThat(shadow).wasInvalidated();
50 | shadow.clearWasInvalidated();
51 |
52 | view.setArrowWidthResource(R.dimen.tooltip_default_arrow_width);
53 | assertThat(shadow).wasInvalidated();
54 | shadow.clearWasInvalidated();
55 |
56 | view.setCornerRadius(123);
57 | assertThat(shadow).wasInvalidated();
58 | shadow.clearWasInvalidated();
59 |
60 | view.setCornerRadiusResource(R.dimen.tooltip_default_corner_radius);
61 | assertThat(shadow).wasInvalidated();
62 | shadow.clearWasInvalidated();
63 |
64 | view.setTooltipColor(123);
65 | assertThat(shadow).wasInvalidated();
66 | shadow.clearWasInvalidated();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/venmo/tooltip-view/160beab4abdf20b721a2987eca4f8717e27ea73d/sample.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library', ':example'
2 |
--------------------------------------------------------------------------------