├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── florent37
│ │ └── github
│ │ └── com
│ │ └── viewtooltip
│ │ └── MainActivity.java
├── build.gradle
└── proguard-rules.pro
├── viewtooltip
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── florent37
│ │ └── viewtooltip
│ │ └── ViewTooltip.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .github
└── FUNDING.yml
├── medias
├── small.gif
├── autoHide.gif
├── autoHide.mp4
├── clickToHide.gif
├── clickToHide.mp4
├── with_border.gif
└── clip_screen_large.gif
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── install-v1.gradle
├── bintray-java-v1.gradle
└── bintray-android-v1.gradle
├── publish.sh
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/viewtooltip/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':viewtooltip'
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | ko_fi: FlorentChampigny
2 | github: florent37
--------------------------------------------------------------------------------
/medias/small.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/small.gif
--------------------------------------------------------------------------------
/medias/autoHide.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/autoHide.gif
--------------------------------------------------------------------------------
/medias/autoHide.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/autoHide.mp4
--------------------------------------------------------------------------------
/medias/clickToHide.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/clickToHide.gif
--------------------------------------------------------------------------------
/medias/clickToHide.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/clickToHide.mp4
--------------------------------------------------------------------------------
/medias/with_border.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/with_border.gif
--------------------------------------------------------------------------------
/medias/clip_screen_large.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/medias/clip_screen_large.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/viewtooltip/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/florent37/ViewTooltip/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/publish.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | . ~/.bash_profile
3 | ./gradlew clean
4 | ./gradlew :viewtooltip:assembleDebug
5 | ./gradlew :viewtooltip:install
6 | ./gradlew :viewtooltip:bintrayUpload
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 02 11:43:41 EDT 2018
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-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion project.COMPILE_SDK
5 |
6 | defaultConfig {
7 | minSdkVersion project.MIN_SDK
8 | targetSdkVersion project.TARGET_SDK
9 |
10 | applicationId "florent37.github.com.viewtooltip"
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | }
15 |
16 | dependencies {
17 | implementation 'androidx.appcompat:appcompat:1.0.2'
18 | implementation 'com.github.florent37:viewtooltip:1.1.8'
19 | //implementation project(path: ':viewtooltip')
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ViewTooltip
3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut vestibulum enim. Donec ultrices nisl a sollicitudin gravida. Cras ipsum dolor, vulputate eget ex eget, suscipit sollicitudin mi. Aenean cursus augue quis aliquam pellentesque. Nunc at malesuada enim. Nam mauris sapien, condimentum a tortor eget, mollis dapibus dui. Ut elementum, turpis non tristique molestie, nunc metus rhoncus ante, vitae vulputate quam felis ut mauris. Cras vel varius metus. Fusce ut erat in tortor scelerisque cursus. Morbi laoreet risus urna, quis vestibulum ante tempus vitae. Sed consectetur est eu metus pretium, eget rutrum odio ornare. Etiam malesuada eu tellus vel egestas. Integer vitae turpis imperdiet, faucibus felis sit amet, ornare sem.
4 |
5 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/gradle.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/viewtooltip/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/viewtooltip/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion project.COMPILE_SDK
5 |
6 | defaultConfig {
7 | minSdkVersion project.MIN_SDK
8 | targetSdkVersion project.TARGET_SDK
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | }
13 |
14 | dependencies {
15 | compileOnly 'androidx.appcompat:appcompat:1.0.2'
16 | }
17 |
18 | ext {
19 | bintrayRepo = 'maven'
20 | bintrayName = 'viewtooltip'
21 | orgName = 'florent37'
22 |
23 | publishedGroupId = 'com.github.florent37'
24 | libraryName = 'ViewTooltip'
25 | artifact = 'viewtooltip'
26 |
27 | libraryDescription = 'ViewTooltip'
28 |
29 | siteUrl = 'https://github.com/florent37/ViewTooltip'
30 | gitUrl = 'https://github.com/florent37/ViewTooltip.git'
31 |
32 | libraryVersion = rootProject.ext.libraryVersion
33 |
34 | developerId = 'florent37'
35 | developerName = 'florent37'
36 | developerEmail = 'champigny.florent@gmail.com'
37 |
38 | licenseName = 'The Apache Software License, Version 2.0'
39 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
40 | allLicenses = ["Apache-2.0"]
41 | }
42 |
43 |
44 | apply from: rootProject.file('gradle/install-v1.gradle')
45 | apply from: rootProject.file('gradle/bintray-android-v1.gradle')
46 |
--------------------------------------------------------------------------------
/gradle/install-v1.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 |
3 | group = publishedGroupId // Maven Group ID for the artifact
4 |
5 | install {
6 | repositories.mavenInstaller {
7 | // This generates POM.xml with proper parameters
8 | pom {
9 | project {
10 | packaging 'aar'
11 | groupId publishedGroupId
12 | artifactId artifact
13 |
14 | // Add your description here
15 | name libraryName
16 | description libraryDescription
17 | url siteUrl
18 |
19 | // Set your license
20 | licenses {
21 | license {
22 | name licenseName
23 | url licenseUrl
24 | }
25 | }
26 | developers {
27 | developer {
28 | id developerId
29 | name developerName
30 | email developerEmail
31 | }
32 | }
33 | scm {
34 | connection gitUrl
35 | developerConnection gitUrl
36 | url siteUrl
37 |
38 | }
39 | }
40 | }
41 | }
42 | }
43 |
44 | //from https://github.com/workarounds/bundler/blob/master/gradle/install-v1.gradle
--------------------------------------------------------------------------------
/gradle/bintray-java-v1.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 |
3 | version = libraryVersion
4 |
5 | task sourcesJar(type: Jar) {
6 | from sourceSets.main.allSource
7 | classifier = 'sources'
8 | }
9 |
10 | task javadocJar(type: Jar, dependsOn: javadoc) {
11 | classifier = 'javadoc'
12 | from javadoc.destinationDir
13 | }
14 | artifacts {
15 | archives javadocJar
16 | archives sourcesJar
17 | }
18 |
19 | // Bintray
20 |
21 | def _user = System.getenv("BINTRAY_USER")
22 | def _key = System.getenv("BINTRAY_API_KEY")
23 | def _passphrase = System.getenv("BINTRAY_PASSPHRASE")
24 |
25 | if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){
26 | Properties properties = new Properties()
27 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
28 |
29 | _user = properties.getProperty("bintray.user")
30 | _key = properties.getProperty("bintray.apikey");
31 | _passphrase = properties.getProperty("bintray.gpg.password")
32 | }
33 |
34 | bintray {
35 | user = _user
36 | key = _key
37 |
38 | configurations = ['archives']
39 | pkg {
40 | repo = bintrayRepo
41 | name = bintrayName
42 | desc = libraryDescription
43 | userOrg = orgName
44 | websiteUrl = siteUrl
45 | vcsUrl = gitUrl
46 | licenses = ['Apache-2.0']
47 | publish = true
48 | publicDownloadNumbers = true
49 | version {
50 | desc = libraryDescription
51 | gpg {
52 | sign = true //Determines whether to GPG sign the files. The default is false
53 | passphrase = _passphrase
54 | //Optional. The passphrase for GPG signing'
55 | }
56 | }
57 | }
58 | }
59 |
60 | //from https://github.com/workarounds/bundler/blob/master/gradle/bintray-java-v1.gradle
--------------------------------------------------------------------------------
/gradle/bintray-android-v1.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 |
3 | version = libraryVersion
4 |
5 | task sourcesJar(type: Jar) {
6 | from android.sourceSets.main.java.srcDirs
7 | classifier = 'sources'
8 | }
9 |
10 | task javadoc(type: Javadoc) {
11 | source = android.sourceSets.main.java.srcDirs
12 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
13 | }
14 |
15 | task javadocJar(type: Jar, dependsOn: javadoc) {
16 | classifier = 'javadoc'
17 | from javadoc.destinationDir
18 | }
19 | artifacts {
20 | //archives javadocJar
21 | archives sourcesJar
22 | }
23 |
24 | def _user = System.getenv("BINTRAY_USER")
25 | def _key = System.getenv("BINTRAY_API_KEY")
26 | def _passphrase = System.getenv("BINTRAY_PASSPHRASE")
27 |
28 | if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){
29 | Properties properties = new Properties()
30 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
31 |
32 | _user = properties.getProperty("bintray.user")
33 | _key = properties.getProperty("bintray.apikey");
34 | _passphrase = properties.getProperty("bintray.gpg.password")
35 | }
36 |
37 | // Bintray
38 |
39 | bintray {
40 | user = _user
41 | key = _key
42 | override = true
43 | configurations = ['archives']
44 | pkg {
45 | repo = bintrayRepo
46 | name = bintrayName
47 | desc = libraryDescription
48 | userOrg = orgName
49 | websiteUrl = siteUrl
50 | vcsUrl = gitUrl
51 | licenses = allLicenses
52 | publish = true
53 | publicDownloadNumbers = true
54 | version {
55 | desc = libraryDescription
56 | gpg {
57 | sign = true //Determines whether to GPG sign the files. The default is false
58 | passphrase = _passphrase
59 | //Optional. The passphrase for GPG signing'
60 | }
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
17 |
18 |
29 |
30 |
35 |
36 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
65 |
66 |
73 |
74 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ViewTooltip
2 |
3 | [](https://www.github.com/florent37/ViewTooltip)
4 |
5 | ```java
6 | ViewTooltip
7 | .on(this, editText)
8 | .autoHide(true, 1000)
9 | .corner(30)
10 | .position(ViewTooltip.Position.RIGHT)
11 | .text("Right")
12 | .show();
13 | ```
14 |
15 |
16 |
17 |
18 |
19 |
20 | # Download
21 |
22 |
23 |
24 | [  ](https://bintray.com/florent37/maven/viewtooltip/_latestVersion)
25 | ```java
26 | dependencies {
27 | implementation 'com.github.florent37:viewtooltip:(last version)'
28 | }
29 | ```
30 |
31 | # Methods
32 |
33 | [](https://www.github.com/florent37/ViewTooltip)
34 |
35 | ```java
36 | ViewTooltip
37 | .on(this, editText)
38 |
39 | .autoHide(true / false, 1000)
40 | .clickToHide(true / false)
41 |
42 | .align(START / CENTER)
43 |
44 | .position(TOP / LEFT / RIGHT / BOTTOM)
45 |
46 | .text("The text")
47 |
48 | .textColor(Color.WHITE)
49 | .color(Color.BLACK)
50 |
51 | .corner(10)
52 |
53 | .arrowWidth(15)
54 | .arrowHeight(15)
55 |
56 | .distanceWithView(0)
57 |
58 | //change the opening animation
59 | .animation(new ViewTooltip.TooltipAnimation(){...})
60 |
61 | //listeners
62 | .onDisplay(new ViewTooltip.ListenerDisplay() {
63 | @Override
64 | public void onDisplay(View view) {
65 |
66 | }
67 | })
68 | .onHide(new ViewTooltip.ListenerHide() {
69 | @Override
70 | public void onHide(View view) {
71 |
72 | }
73 | })
74 | .show();
75 | ```
76 |
77 | # Prevent view to not be outside screen
78 |
79 | ViewTooltip will not allow to be outside of screen,
80 | it will automatically adjust his size
81 |
82 | [](https://www.github.com/florent37/ViewTooltip)
83 |
84 | # History
85 |
86 | # 1.2.0
87 | - Compatible with AndroidX
88 |
89 | # 1.1.7
90 | - Set text as Int
91 | - Added shadowColor
92 |
93 | # 1.1.5
94 | - Use Fragment V4
95 | - Added aistanceWithView
96 |
97 | # 1.1.4
98 | - Added arrowWidth / arrowHeight
99 |
100 | ## 1.1.3
101 | - Fix align bottom, text out of screen
102 |
103 | ## 1.1.1
104 | - Added shadow
105 |
106 | ## 1.0.8
107 | - Clip tooltip to screen (top / bottom)
108 | - Text format HTML
109 |
110 | ## 1.0.6
111 | - Fix align
112 |
113 | ## 1.0.5
114 | - .customView()
115 | - .remove()
116 |
117 | ## 1.0.3
118 | - Clip tooltip to screen width
119 |
120 | ## 1.0.2
121 | - Added corner
122 |
123 | # Credits
124 |
125 | Author: Florent Champigny
126 |
127 | Blog : [http://www.tutos-android-france.com/](http://www.www.tutos-android-france.com/)
128 |
129 | Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/)
130 |
131 |
132 |
133 |
134 |
135 |
136 |
138 |
139 |
140 |
142 |
143 |
144 |
146 |
147 |
148 |
149 | ## Third Party Bindings
150 |
151 | ### React Native
152 | You may now use this library with [React Native](https://github.com/facebook/react-native) via the module [here](https://github.com/prscX/react-native-tooltips)
153 |
154 |
155 | License
156 | --------
157 |
158 | Copyright 2017 Florent37, Inc.
159 |
160 | Licensed under the Apache License, Version 2.0 (the "License");
161 | you may not use this file except in compliance with the License.
162 | You may obtain a copy of the License at
163 |
164 | http://www.apache.org/licenses/LICENSE-2.0
165 |
166 | Unless required by applicable law or agreed to in writing, software
167 | distributed under the License is distributed on an "AS IS" BASIS,
168 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
169 | See the License for the specific language governing permissions and
170 | limitations under the License.
171 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/florent37/github/com/viewtooltip/MainActivity.java:
--------------------------------------------------------------------------------
1 | package florent37.github.com.viewtooltip;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.LinearGradient;
5 | import android.graphics.Paint;
6 | import android.graphics.Shader;
7 | import android.os.Bundle;
8 |
9 | import androidx.annotation.ColorInt;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.EditText;
14 |
15 | import com.github.florent37.viewtooltip.ViewTooltip;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 |
19 | @ColorInt
20 | public static final int BLUE = 0xFF0FB8B3;
21 |
22 | @ColorInt
23 | public static final int GREEN = 0xFF5BBD76;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | final EditText editText = (EditText) findViewById(R.id.editText);
31 |
32 | findViewById(R.id.left).setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | //final CheckBox customView = new CheckBox(MainActivity.this);
36 | //customView.setText("test");
37 | ViewTooltip
38 | .on(editText)
39 | // .customView(customView)
40 | .position(ViewTooltip.Position.LEFT)
41 | .arrowSourceMargin(0)
42 | .arrowTargetMargin(0)
43 | .text(getResources().getString(R.string.lorem))
44 | .clickToHide(true)
45 | .autoHide(false, 0)
46 | .color(createPaint())
47 | .animation(new ViewTooltip.FadeTooltipAnimation(500))
48 | .onDisplay(new ViewTooltip.ListenerDisplay() {
49 | @Override
50 | public void onDisplay(View view) {
51 | Log.d("ViewTooltip", "onDisplay");
52 | }
53 | })
54 | .onHide(new ViewTooltip.ListenerHide() {
55 | @Override
56 | public void onHide(View view) {
57 | Log.d("ViewTooltip", "onHide");
58 | }
59 | })
60 | .show();
61 | }
62 | });
63 |
64 | findViewById(R.id.right).setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | ViewTooltip
68 | .on(editText)
69 | .autoHide(true, 1000)
70 | .position(ViewTooltip.Position.RIGHT)
71 | .text(getResources().getString(R.string.lorem))
72 | .show();
73 | }
74 | });
75 |
76 | findViewById(R.id.top).setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | ViewTooltip
80 | .on(editText)
81 | .margin(50, 0, 50, 0)
82 | .position(ViewTooltip.Position.TOP)
83 | .text(getResources().getString(R.string.lorem))
84 | .show();
85 | }
86 | });
87 |
88 | findViewById(R.id.bottom).setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View v) {
91 | final ViewTooltip.TooltipView viewTooltip = ViewTooltip
92 | .on(editText)
93 | .color(Color.BLACK)
94 | .distanceWithView(0)
95 | .arrowHeight(0)
96 | .arrowWidth(0)
97 | .padding(20, 20, 20, 20)
98 | .margin(50, 0, 50, 0)
99 | .position(ViewTooltip.Position.BOTTOM)
100 | .align(ViewTooltip.ALIGN.START)
101 | .text(getResources().getString(R.string.lorem))
102 | .show();
103 |
104 | //viewTooltip.close();
105 | }
106 | });
107 |
108 | findViewById(R.id.bottomRight).setOnClickListener(new View.OnClickListener() {
109 | @Override
110 | public void onClick(View v) {
111 | ViewTooltip
112 | .on(v)
113 | .color(Color.BLACK)
114 | .position(ViewTooltip.Position.TOP)
115 | .text("bottomRight bottomRight bottomRight")
116 | .show();
117 | }
118 | });
119 |
120 | findViewById(R.id.bottomLeft).setOnClickListener(new View.OnClickListener() {
121 | @Override
122 | public void onClick(View v) {
123 | ViewTooltip
124 | .on(v)
125 | .color(Color.BLACK)
126 | .position(ViewTooltip.Position.TOP)
127 | .text("bottomLeft bottomLeft bottomLeft")
128 | .show();
129 | }
130 | });
131 | }
132 |
133 | private Paint createPaint() {
134 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
135 | paint.setShader(new LinearGradient(0, 0, 0, 600, BLUE, GREEN, Shader.TileMode.CLAMP));
136 | paint.setStyle(Paint.Style.FILL);
137 | return paint;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/viewtooltip/src/main/java/com/github/florent37/viewtooltip/ViewTooltip.java:
--------------------------------------------------------------------------------
1 | package com.github.florent37.viewtooltip;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.app.Activity;
6 | import android.content.Context;
7 | import android.content.ContextWrapper;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.Point;
13 | import android.graphics.Rect;
14 | import android.graphics.RectF;
15 | import android.graphics.Typeface;
16 |
17 | import androidx.annotation.ColorInt;
18 | import androidx.annotation.StringRes;
19 | import androidx.core.widget.NestedScrollView;
20 | import androidx.fragment.app.DialogFragment;
21 | import androidx.fragment.app.Fragment;
22 |
23 | import android.text.Html;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 | import android.view.ViewTreeObserver;
27 | import android.view.Window;
28 | import android.widget.FrameLayout;
29 | import android.widget.TextView;
30 |
31 | import java.util.Arrays;
32 |
33 | /**
34 | * Created by florentchampigny on 02/06/2017.
35 | */
36 |
37 | public class ViewTooltip {
38 |
39 | private View rootView;
40 | private final View view;
41 | private final TooltipView tooltip_view;
42 |
43 | private ViewTooltip(MyContext myContext, View view) {
44 | this.view = view;
45 | this.tooltip_view = new TooltipView(myContext.getContext());
46 | final NestedScrollView scrollParent = findScrollParent(view);
47 | if (scrollParent != null) {
48 | scrollParent.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
49 | @Override
50 | public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
51 | tooltip_view.setTranslationY(tooltip_view.getTranslationY() - (scrollY - oldScrollY));
52 | }
53 | });
54 | }
55 | }
56 |
57 | private ViewTooltip(MyContext myContext, View rootView, View view) {
58 | this.rootView = rootView;
59 | this.view = view;
60 | this.tooltip_view = new TooltipView(myContext.getContext());
61 | final NestedScrollView scrollParent = findScrollParent(view);
62 | if (scrollParent != null) {
63 | scrollParent.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
64 | @Override
65 | public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
66 | tooltip_view.setTranslationY(tooltip_view.getTranslationY() - (scrollY - oldScrollY));
67 | }
68 | });
69 | }
70 | }
71 |
72 | private ViewTooltip(View view) {
73 | this(new MyContext(getActivityContext(view.getContext())), view);
74 | }
75 |
76 | public static ViewTooltip on(final View view) {
77 | return new ViewTooltip(new MyContext(getActivityContext(view.getContext())), view);
78 | }
79 |
80 | public static ViewTooltip on(Fragment fragment, final View view) {
81 | return new ViewTooltip(new MyContext(fragment), view);
82 | }
83 |
84 | public static ViewTooltip on(Activity activity, final View view) {
85 | return new ViewTooltip(new MyContext(getActivityContext(activity)), view);
86 | }
87 |
88 | public static ViewTooltip on(Activity activity, final View rootView, final View view) {
89 | return new ViewTooltip(new MyContext(getActivityContext(activity)), rootView, view);
90 | }
91 |
92 | private NestedScrollView findScrollParent(View view) {
93 | if (view.getParent() == null || !(view.getParent() instanceof View)) {
94 | return null;
95 | } else if (view.getParent() instanceof NestedScrollView) {
96 | return ((NestedScrollView) view.getParent());
97 | } else {
98 | return findScrollParent(((View) view.getParent()));
99 | }
100 | }
101 |
102 | private static Activity getActivityContext(Context context) {
103 | while (context instanceof ContextWrapper) {
104 | if (context instanceof Activity) {
105 | return (Activity) context;
106 | }
107 | context = ((ContextWrapper) context).getBaseContext();
108 | }
109 | return null;
110 | }
111 |
112 | public ViewTooltip position(Position position) {
113 | this.tooltip_view.setPosition(position);
114 | return this;
115 | }
116 |
117 | public ViewTooltip withShadow(boolean withShadow) {
118 | this.tooltip_view.setWithShadow(withShadow);
119 | return this;
120 | }
121 |
122 | public ViewTooltip shadowColor(@ColorInt int shadowColor) {
123 | this.tooltip_view.setShadowColor(shadowColor);
124 | return this;
125 | }
126 |
127 | public ViewTooltip customView(View customView) {
128 | this.tooltip_view.setCustomView(customView);
129 | return this;
130 | }
131 |
132 | public ViewTooltip customView(int viewId) {
133 | this.tooltip_view.setCustomView(((Activity) view.getContext()).findViewById(viewId));
134 | return this;
135 | }
136 |
137 | public ViewTooltip arrowWidth(int arrowWidth) {
138 | this.tooltip_view.setArrowWidth(arrowWidth);
139 | return this;
140 | }
141 |
142 | public ViewTooltip arrowHeight(int arrowHeight) {
143 | this.tooltip_view.setArrowHeight(arrowHeight);
144 | return this;
145 | }
146 |
147 | public ViewTooltip arrowSourceMargin(int arrowSourceMargin) {
148 | this.tooltip_view.setArrowSourceMargin(arrowSourceMargin);
149 | return this;
150 | }
151 |
152 | public ViewTooltip arrowTargetMargin(int arrowTargetMargin) {
153 | this.tooltip_view.setArrowTargetMargin(arrowTargetMargin);
154 | return this;
155 | }
156 |
157 | public ViewTooltip align(ALIGN align) {
158 | this.tooltip_view.setAlign(align);
159 | return this;
160 | }
161 |
162 | public TooltipView show() {
163 | final Context activityContext = tooltip_view.getContext();
164 | if (activityContext != null && activityContext instanceof Activity) {
165 | final ViewGroup decorView = rootView != null ?
166 | (ViewGroup) rootView :
167 | (ViewGroup) ((Activity) activityContext).getWindow().getDecorView();
168 |
169 | view.postDelayed(new Runnable() {
170 | @Override
171 | public void run() {
172 | final Rect rect = new Rect();
173 | view.getGlobalVisibleRect(rect);
174 |
175 | final Rect rootGlobalRect = new Rect();
176 | final Point rootGlobalOffset = new Point();
177 | decorView.getGlobalVisibleRect(rootGlobalRect, rootGlobalOffset);
178 |
179 | int[] location = new int[2];
180 | view.getLocationOnScreen(location);
181 | rect.left = location[0];
182 | if (rootGlobalOffset != null) {
183 | rect.top -= rootGlobalOffset.y;
184 | rect.bottom -= rootGlobalOffset.y;
185 | rect.left -= rootGlobalOffset.x;
186 | rect.right -= rootGlobalOffset.x;
187 | }
188 |
189 | decorView.addView(tooltip_view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
190 |
191 | tooltip_view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
192 | @Override
193 | public boolean onPreDraw() {
194 |
195 | tooltip_view.setup(rect, decorView.getWidth());
196 |
197 | tooltip_view.getViewTreeObserver().removeOnPreDrawListener(this);
198 |
199 | return false;
200 | }
201 | });
202 | }
203 | }, 100);
204 | }
205 | return tooltip_view;
206 | }
207 |
208 | public void close(){
209 | tooltip_view.close();
210 | }
211 |
212 | public ViewTooltip duration(long duration) {
213 | this.tooltip_view.setDuration(duration);
214 | return this;
215 | }
216 |
217 | public ViewTooltip color(int color) {
218 | this.tooltip_view.setColor(color);
219 | return this;
220 | }
221 |
222 | public ViewTooltip color(Paint paint) {
223 | this.tooltip_view.setPaint(paint);
224 | return this;
225 | }
226 |
227 | public ViewTooltip onDisplay(ListenerDisplay listener) {
228 | this.tooltip_view.setListenerDisplay(listener);
229 | return this;
230 | }
231 |
232 | public ViewTooltip onHide(ListenerHide listener) {
233 | this.tooltip_view.setListenerHide(listener);
234 | return this;
235 | }
236 |
237 | public ViewTooltip padding(int left, int top, int right, int bottom) {
238 | this.tooltip_view.paddingTop = top;
239 | this.tooltip_view.paddingBottom = bottom;
240 | this.tooltip_view.paddingLeft = left;
241 | this.tooltip_view.paddingRight = right;
242 | return this;
243 | }
244 |
245 | public ViewTooltip animation(TooltipAnimation tooltipAnimation) {
246 | this.tooltip_view.setTooltipAnimation(tooltipAnimation);
247 | return this;
248 | }
249 |
250 | public ViewTooltip text(String text) {
251 | this.tooltip_view.setText(text);
252 | return this;
253 | }
254 |
255 | public ViewTooltip text(@StringRes int text) {
256 | this.tooltip_view.setText(text);
257 | return this;
258 | }
259 |
260 | public ViewTooltip corner(int corner) {
261 | this.tooltip_view.setCorner(corner);
262 | return this;
263 | }
264 |
265 | public ViewTooltip textColor(int textColor) {
266 | this.tooltip_view.setTextColor(textColor);
267 | return this;
268 | }
269 |
270 | public ViewTooltip textTypeFace(Typeface typeface) {
271 | this.tooltip_view.setTextTypeFace(typeface);
272 | return this;
273 | }
274 |
275 | public ViewTooltip textSize(int unit, float textSize) {
276 | this.tooltip_view.setTextSize(unit, textSize);
277 | return this;
278 | }
279 |
280 | public ViewTooltip margin(int left, int top, int right, int bottom) {
281 | this.tooltip_view.setMargin(left, top, right, bottom);
282 | return this;
283 | }
284 |
285 | public ViewTooltip setTextGravity (int textGravity) {
286 | this.tooltip_view.setTextGravity(textGravity);
287 | return this;
288 | }
289 |
290 | public ViewTooltip clickToHide(boolean clickToHide) {
291 | this.tooltip_view.setClickToHide(clickToHide);
292 | return this;
293 | }
294 |
295 | public ViewTooltip autoHide(boolean autoHide, long duration) {
296 | this.tooltip_view.setAutoHide(autoHide);
297 | this.tooltip_view.setDuration(duration);
298 | return this;
299 | }
300 |
301 | public ViewTooltip distanceWithView(int distance) {
302 | this.tooltip_view.setDistanceWithView(distance);
303 | return this;
304 | }
305 |
306 | public ViewTooltip border(int color,float width){
307 | Paint borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
308 | borderPaint.setColor(color);
309 | borderPaint.setStyle(Paint.Style.STROKE);
310 | borderPaint.setStrokeWidth(width);
311 | this.tooltip_view.setBorderPaint(borderPaint);
312 | return this;
313 | }
314 |
315 | public enum Position {
316 | LEFT,
317 | RIGHT,
318 | TOP,
319 | BOTTOM,
320 | }
321 |
322 | public enum ALIGN {
323 | START,
324 | CENTER,
325 | END
326 | }
327 |
328 | public interface TooltipAnimation {
329 | void animateEnter(View view, Animator.AnimatorListener animatorListener);
330 |
331 | void animateExit(View view, Animator.AnimatorListener animatorListener);
332 | }
333 |
334 | public interface ListenerDisplay {
335 | void onDisplay(View view);
336 | }
337 |
338 | public interface ListenerHide {
339 | void onHide(View view);
340 | }
341 |
342 | public static class FadeTooltipAnimation implements TooltipAnimation {
343 |
344 | private long fadeDuration = 400;
345 |
346 | public FadeTooltipAnimation() {
347 | }
348 |
349 | public FadeTooltipAnimation(long fadeDuration) {
350 | this.fadeDuration = fadeDuration;
351 | }
352 |
353 | @Override
354 | public void animateEnter(View view, Animator.AnimatorListener animatorListener) {
355 | view.setAlpha(0);
356 | view.animate().alpha(1).setDuration(fadeDuration).setListener(animatorListener);
357 | }
358 |
359 | @Override
360 | public void animateExit(View view, Animator.AnimatorListener animatorListener) {
361 | view.animate().alpha(0).setDuration(fadeDuration).setListener(animatorListener);
362 | }
363 | }
364 |
365 | public static class TooltipView extends FrameLayout {
366 |
367 | private static final int MARGIN_SCREEN_BORDER_TOOLTIP = 30;
368 | private int arrowHeight = 15;
369 | private int arrowWidth = 15;
370 | private int arrowSourceMargin = 0;
371 | private int arrowTargetMargin = 0;
372 | protected View childView;
373 | private int color = Color.parseColor("#1F7C82");
374 | private Path bubblePath;
375 | private Paint bubblePaint;
376 | private Paint borderPaint;
377 | private Position position = Position.BOTTOM;
378 | private ALIGN align = ALIGN.CENTER;
379 | private boolean clickToHide;
380 | private boolean autoHide = true;
381 | private long duration = 4000;
382 |
383 | private ListenerDisplay listenerDisplay;
384 |
385 | private ListenerHide listenerHide;
386 |
387 | private TooltipAnimation tooltipAnimation = new FadeTooltipAnimation();
388 |
389 | private int corner = 30;
390 |
391 | private int paddingTop = 20;
392 | private int paddingBottom = 30;
393 | private int paddingRight = 30;
394 | private int paddingLeft = 30;
395 |
396 | private int marginTop = 0;
397 | private int marginBottom = 0;
398 | private int marginRight = 0;
399 | private int marginLeft = 0;
400 |
401 | int shadowPadding = 4;
402 | int shadowWidth = 8;
403 |
404 | private Rect viewRect;
405 | private int distanceWithView = 0;
406 | private int shadowColor = Color.parseColor("#aaaaaa");
407 |
408 | public TooltipView(Context context) {
409 | super(context);
410 | setWillNotDraw(false);
411 |
412 | this.childView = new TextView(context);
413 | ((TextView) childView).setTextColor(Color.WHITE);
414 | addView(childView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
415 | childView.setPadding(0, 0, 0, 0);
416 |
417 | bubblePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
418 | bubblePaint.setColor(color);
419 | bubblePaint.setStyle(Paint.Style.FILL);
420 |
421 | borderPaint = null;
422 |
423 | setLayerType(LAYER_TYPE_SOFTWARE, bubblePaint);
424 |
425 | setWithShadow(true);
426 |
427 | }
428 |
429 | public void setCustomView(View customView) {
430 | this.removeView(childView);
431 | this.childView = customView;
432 | addView(childView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
433 | }
434 |
435 | public void setColor(int color) {
436 | this.color = color;
437 | bubblePaint.setColor(color);
438 | postInvalidate();
439 | }
440 |
441 | public void setShadowColor(int color) {
442 | this.shadowColor = color;
443 | postInvalidate();
444 | }
445 |
446 | public void setMargin(int left, int top, int right, int bottom) {
447 | this.marginLeft = left;
448 | this.marginTop = top;
449 | this.marginRight = right;
450 | this.marginBottom = top;
451 |
452 | childView.setPadding(childView.getPaddingLeft() + left, childView.getPaddingTop() + top, childView.getPaddingRight() + right, childView.getPaddingBottom() + bottom);
453 | postInvalidate();
454 | }
455 |
456 | public void setPaint(Paint paint) {
457 | bubblePaint = paint;
458 | setLayerType(LAYER_TYPE_SOFTWARE, paint);
459 | postInvalidate();
460 | }
461 |
462 | public void setPosition(Position position) {
463 | this.position = position;
464 | switch (position){
465 | case TOP:
466 | setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom + arrowHeight);
467 | break;
468 | case BOTTOM:
469 | setPadding(paddingLeft, paddingTop + arrowHeight, paddingRight, paddingBottom);
470 | break;
471 | case LEFT:
472 | setPadding(paddingLeft, paddingTop, paddingRight + arrowHeight, paddingBottom);
473 | break;
474 | case RIGHT:
475 | setPadding(paddingLeft + arrowHeight, paddingTop, paddingRight, paddingBottom);
476 | break;
477 | }
478 | postInvalidate();
479 | }
480 |
481 | public void setAlign(ALIGN align) {
482 | this.align = align;
483 | postInvalidate();
484 | }
485 |
486 | public void setText(String text) {
487 | if (childView instanceof TextView) {
488 | ((TextView) this.childView).setText(Html.fromHtml(text));
489 | }
490 | postInvalidate();
491 | }
492 |
493 | public void setText(int text) {
494 | if (childView instanceof TextView) {
495 | ((TextView) this.childView).setText(text);
496 | }
497 | postInvalidate();
498 | }
499 |
500 | public void setTextColor(int textColor) {
501 | if (childView instanceof TextView) {
502 | ((TextView) this.childView).setTextColor(textColor);
503 | }
504 | postInvalidate();
505 | }
506 |
507 | public int getArrowHeight() {
508 | return arrowHeight;
509 | }
510 |
511 | public void setArrowHeight(int arrowHeight) {
512 | this.arrowHeight = arrowHeight;
513 | postInvalidate();
514 | }
515 |
516 | public int getArrowWidth() {
517 | return arrowWidth;
518 | }
519 |
520 | public void setArrowWidth(int arrowWidth) {
521 | this.arrowWidth = arrowWidth;
522 | postInvalidate();
523 | }
524 |
525 | public int getArrowSourceMargin() {
526 | return arrowSourceMargin;
527 | }
528 |
529 | public void setArrowSourceMargin(int arrowSourceMargin) {
530 | this.arrowSourceMargin = arrowSourceMargin;
531 | postInvalidate();
532 | }
533 |
534 | public int getArrowTargetMargin() {
535 | return arrowTargetMargin;
536 | }
537 |
538 | public void setArrowTargetMargin(int arrowTargetMargin) {
539 | this.arrowTargetMargin = arrowTargetMargin;
540 | postInvalidate();
541 | }
542 |
543 | public void setTextTypeFace(Typeface textTypeFace) {
544 | if (childView instanceof TextView) {
545 | ((TextView) this.childView).setTypeface(textTypeFace);
546 | }
547 | postInvalidate();
548 | }
549 |
550 | public void setTextSize(int unit, float size) {
551 | if (childView instanceof TextView) {
552 | ((TextView) this.childView).setTextSize(unit, size);
553 | }
554 | postInvalidate();
555 | }
556 |
557 | public void setTextGravity(int textGravity) {
558 | if (childView instanceof TextView) {
559 | ((TextView) this.childView).setGravity(textGravity);
560 | }
561 | postInvalidate();
562 | }
563 |
564 | public void setClickToHide(boolean clickToHide) {
565 | this.clickToHide = clickToHide;
566 | }
567 |
568 | public void setCorner(int corner) {
569 | this.corner = corner;
570 | }
571 |
572 | @Override
573 | protected void onSizeChanged(int width, int height, int oldw, int oldh) {
574 | super.onSizeChanged(width, height, oldw, oldh);
575 |
576 | bubblePath = drawBubble(new RectF(shadowPadding, shadowPadding, width - shadowPadding * 2, height - shadowPadding * 2), corner, corner, corner, corner);
577 | }
578 |
579 | @Override
580 | protected void onDraw(Canvas canvas) {
581 | super.onDraw(canvas);
582 |
583 | if (bubblePath != null) {
584 | canvas.drawPath(bubblePath, bubblePaint);
585 | if(borderPaint != null){
586 | canvas.drawPath(bubblePath,borderPaint);
587 | }
588 | }
589 | }
590 |
591 | public void setListenerDisplay(ListenerDisplay listener) {
592 | this.listenerDisplay = listener;
593 | }
594 |
595 | public void setListenerHide(ListenerHide listener) {
596 | this.listenerHide = listener;
597 | }
598 |
599 | public void setTooltipAnimation(TooltipAnimation tooltipAnimation) {
600 | this.tooltipAnimation = tooltipAnimation;
601 | }
602 |
603 | protected void startEnterAnimation() {
604 | tooltipAnimation.animateEnter(this, new AnimatorListenerAdapter() {
605 | @Override
606 | public void onAnimationEnd(Animator animation) {
607 | super.onAnimationEnd(animation);
608 | if (listenerDisplay != null) {
609 | listenerDisplay.onDisplay(TooltipView.this);
610 | }
611 | }
612 | });
613 | }
614 |
615 | protected void startExitAnimation(final Animator.AnimatorListener animatorListener) {
616 | tooltipAnimation.animateExit(this, new AnimatorListenerAdapter() {
617 | @Override
618 | public void onAnimationEnd(Animator animation) {
619 | super.onAnimationEnd(animation);
620 | animatorListener.onAnimationEnd(animation);
621 | if (listenerHide != null) {
622 | listenerHide.onHide(TooltipView.this);
623 | }
624 | }
625 | });
626 | }
627 |
628 | protected void handleAutoRemove() {
629 | if (clickToHide) {
630 | setOnClickListener(new OnClickListener() {
631 | @Override
632 | public void onClick(View v) {
633 | if (clickToHide) {
634 | remove();
635 | }
636 | }
637 | });
638 | }
639 |
640 | if (autoHide) {
641 | postDelayed(new Runnable() {
642 | @Override
643 | public void run() {
644 | remove();
645 | }
646 | }, duration);
647 | }
648 | }
649 |
650 | public void remove() {
651 | startExitAnimation(new AnimatorListenerAdapter() {
652 | @Override
653 | public void onAnimationEnd(Animator animation) {
654 | super.onAnimationEnd(animation);
655 | removeNow();
656 | }
657 | });
658 | }
659 |
660 | public void setDuration(long duration) {
661 | this.duration = duration;
662 | }
663 |
664 | public void setAutoHide(boolean autoHide) {
665 | this.autoHide = autoHide;
666 | }
667 |
668 | public void setupPosition(Rect rect) {
669 |
670 | int x, y;
671 |
672 | if (position == Position.LEFT || position == Position.RIGHT) {
673 | if (position == Position.LEFT) {
674 | x = rect.left - getWidth() - distanceWithView;
675 | } else {
676 | x = rect.right + distanceWithView;
677 | }
678 | y = rect.top + getAlignOffset(getHeight(), rect.height());
679 | } else {
680 | if (position == Position.BOTTOM) {
681 | y = rect.bottom + distanceWithView;
682 | } else { // top
683 | y = rect.top - getHeight() - distanceWithView;
684 | }
685 | x = rect.left + getAlignOffset(getWidth(), rect.width());
686 | }
687 |
688 | setTranslationX(x);
689 | setTranslationY(y);
690 | }
691 |
692 | private int getAlignOffset(int myLength, int hisLength) {
693 | switch (align) {
694 | case END: return hisLength - myLength;
695 | case CENTER: return (hisLength - myLength) / 2;
696 | }
697 | return 0;
698 | }
699 |
700 | private Path drawBubble(RectF myRect, float topLeftDiameter, float topRightDiameter, float bottomRightDiameter, float bottomLeftDiameter) {
701 | final Path path = new Path();
702 |
703 | if(viewRect == null)
704 | return path;
705 |
706 | topLeftDiameter = topLeftDiameter < 0 ? 0 : topLeftDiameter;
707 | topRightDiameter = topRightDiameter < 0 ? 0 : topRightDiameter;
708 | bottomLeftDiameter = bottomLeftDiameter < 0 ? 0 : bottomLeftDiameter;
709 | bottomRightDiameter = bottomRightDiameter < 0 ? 0 : bottomRightDiameter;
710 |
711 | final float spacingLeft = this.position == Position.RIGHT ? arrowHeight : marginLeft;
712 | final float spacingTop = this.position == Position.BOTTOM ? arrowHeight : marginTop;
713 | final float spacingRight = this.position == Position.LEFT ? arrowHeight : marginRight;
714 | final float spacingBottom = this.position == Position.TOP ? arrowHeight : marginBottom;
715 |
716 | final float left = spacingLeft + myRect.left;
717 | final float top = spacingTop + myRect.top;
718 | final float right = myRect.right - spacingRight;
719 | final float bottom = myRect.bottom - spacingBottom;
720 | final float centerX = viewRect.centerX() - getX();
721 |
722 | final float arrowSourceX = (Arrays.asList(Position.TOP, Position.BOTTOM).contains(this.position))
723 | ? centerX + arrowSourceMargin
724 | : centerX;
725 | final float arrowTargetX = (Arrays.asList(Position.TOP, Position.BOTTOM).contains(this.position))
726 | ? centerX + arrowTargetMargin
727 | : centerX;
728 | final float arrowSourceY = (Arrays.asList(Position.RIGHT, Position.LEFT).contains(this.position))
729 | ? bottom / 2f - arrowSourceMargin
730 | : bottom / 2f;
731 | final float arrowTargetY = (Arrays.asList(Position.RIGHT, Position.LEFT).contains(this.position))
732 | ? bottom / 2f - arrowTargetMargin
733 | : bottom / 2f;
734 |
735 | path.moveTo(left + topLeftDiameter / 2f, top);
736 | //LEFT, TOP
737 |
738 | if (position == Position.BOTTOM) {
739 | path.lineTo(arrowSourceX - arrowWidth, top);
740 | path.lineTo(arrowTargetX, myRect.top);
741 | path.lineTo(arrowSourceX + arrowWidth, top);
742 | }
743 | path.lineTo(right - topRightDiameter / 2f, top);
744 |
745 | path.quadTo(right, top, right, top + topRightDiameter / 2);
746 | //RIGHT, TOP
747 |
748 | if (position == Position.LEFT) {
749 | path.lineTo(right, arrowSourceY - arrowWidth);
750 | path.lineTo(myRect.right, arrowTargetY);
751 | path.lineTo(right, arrowSourceY + arrowWidth);
752 | }
753 | path.lineTo(right, bottom - bottomRightDiameter / 2);
754 |
755 | path.quadTo(right, bottom, right - bottomRightDiameter / 2, bottom);
756 | //RIGHT, BOTTOM
757 |
758 | if (position == Position.TOP) {
759 | path.lineTo(arrowSourceX + arrowWidth, bottom);
760 | path.lineTo(arrowTargetX, myRect.bottom);
761 | path.lineTo(arrowSourceX - arrowWidth, bottom);
762 | }
763 | path.lineTo(left + bottomLeftDiameter / 2, bottom);
764 |
765 | path.quadTo(left, bottom, left, bottom - bottomLeftDiameter / 2);
766 | //LEFT, BOTTOM
767 |
768 | if (position == Position.RIGHT) {
769 | path.lineTo(left, arrowSourceY + arrowWidth);
770 | path.lineTo(myRect.left, arrowTargetY);
771 | path.lineTo(left, arrowSourceY - arrowWidth);
772 | }
773 | path.lineTo(left, top + topLeftDiameter / 2);
774 |
775 | path.quadTo(left, top, left + topLeftDiameter / 2, top);
776 |
777 | path.close();
778 |
779 | return path;
780 | }
781 |
782 | public boolean adjustSize(Rect rect, int screenWidth) {
783 |
784 | final Rect r = new Rect();
785 | getGlobalVisibleRect(r);
786 |
787 | boolean changed = false;
788 | final ViewGroup.LayoutParams layoutParams = getLayoutParams();
789 | if (position == Position.LEFT && getWidth() > rect.left) {
790 | layoutParams.width = rect.left - MARGIN_SCREEN_BORDER_TOOLTIP - distanceWithView;
791 | changed = true;
792 | } else if (position == Position.RIGHT && rect.right + getWidth() > screenWidth) {
793 | layoutParams.width = screenWidth - rect.right - MARGIN_SCREEN_BORDER_TOOLTIP - distanceWithView;
794 | changed = true;
795 | } else if (position == Position.TOP || position == Position.BOTTOM) {
796 | int adjustedLeft = rect.left;
797 | int adjustedRight = rect.right;
798 |
799 | if((rect.centerX() + getWidth() / 2f) > screenWidth){
800 | float diff = (rect.centerX() + getWidth() / 2f) - screenWidth;
801 |
802 | adjustedLeft -= diff;
803 | adjustedRight -= diff;
804 |
805 | setAlign(ALIGN.CENTER);
806 | changed = true;
807 | }else if((rect.centerX() - getWidth() / 2f) < 0){
808 | float diff = -(rect.centerX() - getWidth() / 2f);
809 |
810 | adjustedLeft += diff;
811 | adjustedRight += diff;
812 |
813 | setAlign(ALIGN.CENTER);
814 | changed = true;
815 | }
816 |
817 | if(adjustedLeft < 0){
818 | adjustedLeft = 0;
819 | }
820 |
821 | if(adjustedRight > screenWidth){
822 | adjustedRight = screenWidth;
823 | }
824 |
825 | rect.left = adjustedLeft;
826 | rect.right = adjustedRight;
827 | }
828 |
829 | setLayoutParams(layoutParams);
830 | postInvalidate();
831 | return changed;
832 | }
833 |
834 | private void onSetup(Rect myRect) {
835 | setupPosition(myRect);
836 |
837 | bubblePath = drawBubble(new RectF(shadowPadding, shadowPadding, getWidth() - shadowPadding * 2f, getHeight() - shadowPadding * 2f), corner, corner, corner, corner);
838 | startEnterAnimation();
839 |
840 | handleAutoRemove();
841 | }
842 |
843 | public void setup(final Rect viewRect, int screenWidth) {
844 | this.viewRect = new Rect(viewRect);
845 | final Rect myRect = new Rect(viewRect);
846 |
847 | final boolean changed = adjustSize(myRect, screenWidth);
848 | if (!changed) {
849 | onSetup(myRect);
850 | } else {
851 | getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
852 | @Override
853 | public boolean onPreDraw() {
854 | onSetup(myRect);
855 | getViewTreeObserver().removeOnPreDrawListener(this);
856 | return false;
857 | }
858 | });
859 | }
860 | }
861 |
862 | public void close() {
863 | remove();
864 | }
865 |
866 | public void removeNow() {
867 | if (getParent() != null) {
868 | final ViewGroup parent = ((ViewGroup) getParent());
869 | parent.removeView(TooltipView.this);
870 | }
871 | }
872 |
873 | public void closeNow() {
874 | removeNow();
875 | }
876 |
877 | public void setWithShadow(boolean withShadow) {
878 | if(withShadow){
879 | bubblePaint.setShadowLayer(shadowWidth, 0, 0, shadowColor);
880 | } else {
881 | bubblePaint.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
882 | }
883 | }
884 |
885 | public void setDistanceWithView(int distanceWithView) {
886 | this.distanceWithView = distanceWithView;
887 | }
888 |
889 | public void setBorderPaint(Paint borderPaint) {
890 | this.borderPaint = borderPaint;
891 | postInvalidate();
892 | }
893 | }
894 |
895 | public static class MyContext {
896 | private Fragment fragment;
897 | private Context context;
898 | private Activity activity;
899 |
900 | public MyContext(Activity activity) {
901 | this.activity = activity;
902 | }
903 |
904 | public MyContext(Fragment fragment) {
905 | this.fragment = fragment;
906 | }
907 |
908 | public MyContext(Context context) {
909 | this.context = context;
910 | }
911 |
912 | public Context getContext() {
913 | if (activity != null) {
914 | return activity;
915 | } else {
916 | return ((Context) fragment.getActivity());
917 | }
918 | }
919 |
920 | public Activity getActivity() {
921 | if (activity != null) {
922 | return activity;
923 | } else {
924 | return fragment.getActivity();
925 | }
926 | }
927 |
928 |
929 | public Window getWindow() {
930 | if (activity != null) {
931 | return activity.getWindow();
932 | } else {
933 | if (fragment instanceof DialogFragment) {
934 | return ((DialogFragment) fragment).getDialog().getWindow();
935 | }
936 | return fragment.getActivity().getWindow();
937 | }
938 | }
939 | }
940 | }
941 |
--------------------------------------------------------------------------------