├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tomergoldst
│ │ └── hoverviewdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── tomergoldst
│ │ │ └── hoverviewdemo
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable
│ │ └── box_shape_drawable.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── hover_view.xml
│ │ ├── 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
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── tomergoldst
│ └── hoverviewdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── hoverview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tomergoldst
│ │ └── hoverview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── tomergoldst
│ │ │ └── hoverview
│ │ │ ├── Coordinates.java
│ │ │ ├── DefaultHoverViewAnimator.java
│ │ │ ├── HoverView.java
│ │ │ ├── HoverViewAnimator.java
│ │ │ ├── HoverViewManager.java
│ │ │ ├── UiUtils.java
│ │ │ └── ViewCoordinatesFinder.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── tomergoldst
│ └── hoverview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # hoverview
2 | Add popup view near any other view with ease
3 |
4 |
5 |
6 | ## Instructions
7 |
8 | 1. Add a dependency to your app build.gradle
9 | ```groovy
10 | dependencies {
11 | compile 'com.tomergoldst.android:hoverview:1.0.2'
12 | }
13 | ```
14 |
15 | 2. Create an HoverViewManager object
16 | ```java
17 | HoverViewManager mHoverViewManager;
18 | mHoverViewManager = new HoverViewManager();
19 | ```
20 |
21 | 3. Create your custom view to show. In following example we have created a TextView layout named `hover_view.xml` and customized it like this:
22 | ```xml
23 |
24 |
33 |
34 | ```
35 | Important: Do not use layout_margin
36 |
37 | 4. Use the HoverView Builder to construct your hoverview
38 | ```java
39 | View view = LayoutInflater.from(this).inflate(R.layout.hover_view, mRootLayout, false);
40 | HoverView.Builder builder = new HoverView.Builder(this, mTextView, mRootLayout, view, HoverView.POSITION_ABOVE);
41 | ```
42 | 'mTextView' here is the view which near it the hover view will be shown and 'mRootLayout' is the layout where the hoverview will be added to.
43 | The root layout must be of RelativeLayout, FrameLayout or similar. LinearLayout won't work but you can always wrap your LinearLayout
44 | with another layout. Prefer to pass in a layout which is higher in the xml tree as this will give the
45 | hoverview more visible space.
46 |
47 | 5. Use HoverViewManager to show the hoverview
48 |
49 | IMPORTANT: This must be called after the layout has been drawn
50 | You can override the 'onWindowFocusChanged()' of an Activity and show there, Start a delayed runnable from onStart() , React to user action or any other method that works for you
51 | ```java
52 | mHoverViewManager.show(builder.build());
53 | ```
54 |
55 | Each hoverview is dismissable by clicking on it, if you want to dismiss an hoverview from code there are a few options, The most simple way is to do the following
56 | ```java
57 | mHoverViewManager.findAndDismiss(mTextView);
58 | ```
59 | Where 'mTextView' is the same view we asked to position an hoverview near it
60 |
61 | If you want to react when hoverview has been dismissed, Implement HoverViewManager.HoverViewListener interface and use appropriate HoverViewManager constructor
62 | ```java
63 | public class MainActivity extends AppCompatActivity implements HoverViewManager.HoverViewListener
64 | .
65 | .
66 | @Override
67 | protected void onCreate(Bundle savedInstanceState) {
68 | mHoverViewManager = new HoverViewManager(this);
69 | }
70 | .
71 | .
72 | @Override
73 | public void onHoverViewDismissed(View view, int anchorViewId, boolean byUser) {
74 | Log.d(TAG, "hoverview near anchor view " + anchorViewId + " dismissed");
75 |
76 | if (anchorViewId == R.id.text_view) {
77 | // Do something when an hoverview near view with id "R.id.text_view" has been dismissed
78 | }
79 | }
80 | ```
81 |
82 | ### License
83 | ```
84 | Copyright 2016 Tomer Goldstein
85 |
86 | Licensed under the Apache License, Version 2.0 (the "License");
87 | you may not use this file except in compliance with the License.
88 | You may obtain a copy of the License at
89 |
90 | http://www.apache.org/licenses/LICENSE-2.0
91 |
92 | Unless required by applicable law or agreed to in writing, software
93 | distributed under the License is distributed on an "AS IS" BASIS,
94 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95 | See the License for the specific language governing permissions and
96 | limitations under the License.
97 | ```
98 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | applicationId "com.tomergoldst.hoverviewdemo"
8 | minSdkVersion 14
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | implementation 'com.android.support:appcompat-v7:28.0.0'
29 | testImplementation 'junit:junit:4.12'
30 | implementation project(path: ':hoverview')
31 | }
32 |
--------------------------------------------------------------------------------
/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 C:\Users\Tomer\AppData\Local\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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tomergoldst/hoverviewdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverviewdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.tomergoldst.hoverviewdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tomergoldst/hoverviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverviewdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.RadioButton;
10 | import android.widget.RelativeLayout;
11 | import android.widget.TextView;
12 |
13 | import com.tomergoldst.hoverview.HoverView;
14 | import com.tomergoldst.hoverview.HoverViewManager;
15 |
16 | public class MainActivity extends AppCompatActivity implements
17 | HoverViewManager.HoverViewListener,
18 | View.OnClickListener
19 | {
20 | private static final String TAG = MainActivity.class.getSimpleName();
21 |
22 | HoverViewManager mHoverViewManager;
23 | RelativeLayout mRootLayout;
24 | RelativeLayout mParentLayout;
25 | TextView mTextView;
26 |
27 | Button mAboveBtn;
28 | Button mBelowBtn;
29 | Button mLeftToBtn;
30 | Button mRightToBtn;
31 |
32 | RadioButton mAlignRight;
33 | RadioButton mAlignLeft;
34 | RadioButton mAlignCenter;
35 |
36 | @HoverView.Align int mAlign = HoverView.ALIGN_CENTER;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_main);
42 |
43 | mRootLayout = findViewById(R.id.root_layout);
44 | mParentLayout = findViewById(R.id.parent_layout);
45 | mTextView = findViewById(R.id.text_view);
46 |
47 | mHoverViewManager = new HoverViewManager(this);
48 |
49 | mAboveBtn = findViewById(R.id.button_above);
50 | mBelowBtn = findViewById(R.id.button_below);
51 | mLeftToBtn = findViewById(R.id.button_left_to);
52 | mRightToBtn = findViewById(R.id.button_right_to);
53 |
54 | mAboveBtn.setOnClickListener(this);
55 | mBelowBtn.setOnClickListener(this);
56 | mLeftToBtn.setOnClickListener(this);
57 | mRightToBtn.setOnClickListener(this);
58 |
59 | mAlignCenter = findViewById(R.id.button_align_center);
60 | mAlignLeft = findViewById(R.id.button_align_left);
61 | mAlignRight = findViewById(R.id.button_align_right);
62 |
63 | mAlignCenter.setOnClickListener(this);
64 | mAlignLeft.setOnClickListener(this);
65 | mAlignRight.setOnClickListener(this);
66 |
67 | mAlignCenter.setChecked(true);
68 |
69 | }
70 |
71 | @Override
72 | public void onWindowFocusChanged(boolean hasFocus) {
73 | super.onWindowFocusChanged(hasFocus);
74 |
75 | View view = LayoutInflater.from(this).inflate(R.layout.hover_view, mRootLayout, false);
76 |
77 | HoverView.Builder builder = new HoverView.Builder(this,
78 | mTextView,
79 | mRootLayout,
80 | view,
81 | HoverView.POSITION_ABOVE);
82 | builder.setAlign(mAlign);
83 | mHoverViewManager.show(builder.build());
84 | }
85 |
86 |
87 |
88 | @Override
89 | public void onHoverViewDismissed(View view, int anchorViewId, boolean byUser) {
90 | Log.d(TAG, "hoverview near anchor view " + anchorViewId + " dismissed");
91 |
92 | if (anchorViewId == R.id.text_view) {
93 | // Do something when an hoverview near view with id "R.id.text_view" has been dismissed
94 | }
95 | }
96 |
97 | @Override
98 | public void onClick(View view) {
99 | HoverView.Builder builder;
100 |
101 | View hoverView = LayoutInflater.from(this).inflate(R.layout.hover_view, mRootLayout, false);
102 |
103 | switch (view.getId()){
104 | case R.id.button_above:
105 | mHoverViewManager.findAndDismiss(mTextView);
106 | builder = new HoverView.Builder(this, mTextView, mRootLayout, hoverView, HoverView.POSITION_ABOVE);
107 | builder.setAlign(mAlign);
108 | mHoverViewManager.show(builder.build());
109 | break;
110 | case R.id.button_below:
111 | mHoverViewManager.findAndDismiss(mTextView);
112 | builder = new HoverView.Builder(this, mTextView, mRootLayout, hoverView, HoverView.POSITION_BELOW);
113 | builder.setAlign(mAlign);
114 | mHoverViewManager.show(builder.build());
115 | break;
116 | case R.id.button_left_to:
117 | mHoverViewManager.findAndDismiss(mTextView);
118 | builder = new HoverView.Builder(this, mTextView, mRootLayout, hoverView, HoverView.POSITION_LEFT_TO);
119 | mHoverViewManager.show(builder.build());
120 | break;
121 | case R.id.button_right_to:
122 | mHoverViewManager.findAndDismiss(mTextView);
123 | builder = new HoverView.Builder(this, mTextView, mRootLayout, hoverView, HoverView.POSITION_RIGHT_TO);
124 | mHoverViewManager.show(builder.build());
125 | break;
126 | case R.id.button_align_center:
127 | mAlign = HoverView.ALIGN_CENTER;
128 | break;
129 | case R.id.button_align_left:
130 | mAlign = HoverView.ALIGN_LEFT;
131 | break;
132 | case R.id.button_align_right:
133 | mAlign = HoverView.ALIGN_RIGHT;
134 | break;
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/box_shape_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
10 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
22 |
23 |
29 |
30 |
38 |
39 |
47 |
48 |
49 |
57 |
58 |
66 |
67 |
68 |
69 |
80 |
81 |
88 |
89 |
96 |
97 |
104 |
105 |
106 |
107 |
112 |
113 |
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/hover_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Hoverview Demo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tomergoldst/hoverviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverviewdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.2.1'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | google()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomergoldst/hoverview/bd2e20d735ca27573b73812050ba86174ffdbac3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 14 20:12:57 IST 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/hoverview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/hoverview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | bintrayRepo = 'maven'
5 | bintrayName = 'hoverview'
6 |
7 | publishedGroupId = 'com.tomergoldst.android'
8 | libraryName = 'Hoverview'
9 | artifact = 'hoverview'
10 |
11 | libraryDescription = 'Add popup view near any other view with ease'
12 |
13 | siteUrl = 'https://github.com/tomergoldst/hoverview'
14 | gitUrl = 'https://github.com/tomergoldst/hoverview/hoverview.git'
15 |
16 | libraryVersion = '1.0.2'
17 |
18 | developerId = 'tomergoldst'
19 | developerName = 'Tomer Goldstein'
20 | developerEmail = 'tomergoldst2@gmail.com'
21 |
22 | licenseName = 'The Apache Software License, Version 2.0'
23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
24 | allLicenses = ["Apache-2.0"]
25 | }
26 |
27 | android {
28 | compileSdkVersion 28
29 |
30 | defaultConfig {
31 | minSdkVersion 14
32 | targetSdkVersion 28
33 | versionCode 3
34 | versionName "1.0.2"
35 |
36 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
37 |
38 | }
39 | buildTypes {
40 | release {
41 | minifyEnabled false
42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43 | }
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation fileTree(dir: 'libs', include: ['*.jar'])
49 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
50 | exclude group: 'com.android.support', module: 'support-annotations'
51 | })
52 | implementation 'com.android.support:appcompat-v7:28.0.0'
53 | testImplementation 'junit:junit:4.12'
54 | }
55 |
56 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
57 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
58 |
--------------------------------------------------------------------------------
/hoverview/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 C:\Users\Tomer\AppData\Local\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 |
--------------------------------------------------------------------------------
/hoverview/src/androidTest/java/com/tomergoldst/hoverview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.tomergoldst.hoverview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/hoverview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/Coordinates.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017 Tomer Goldstein
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package com.tomergoldst.hoverview;
18 |
19 | import android.view.View;
20 |
21 | /**
22 | * Created by Tomer on 30/06/2016.
23 | *
24 | */
25 | public class Coordinates {
26 |
27 | int left;
28 | int top;
29 | int right;
30 | int bottom;
31 |
32 | public Coordinates(View view){
33 | int[] location = new int[2];
34 | view.getLocationOnScreen(location);
35 | left = location[0];
36 | right = left + view.getWidth();;
37 | top = location[1];
38 | bottom = top + view.getHeight();
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/DefaultHoverViewAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017 Tomer Goldstein
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package com.tomergoldst.hoverview;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.animation.ObjectAnimator;
22 | import android.animation.PropertyValuesHolder;
23 | import android.animation.ValueAnimator;
24 | import android.view.View;
25 | import android.view.animation.AnticipateOvershootInterpolator;
26 | import android.view.animation.OvershootInterpolator;
27 |
28 | /**
29 | * Created by Tomer on 18/06/2016.
30 | */
31 | class DefaultHoverViewAnimator implements HoverViewAnimator {
32 |
33 | @Override
34 | public ValueAnimator popup(final View view, final long duration) {
35 | view.setAlpha(0);
36 | view.setVisibility(View.VISIBLE);
37 |
38 | ObjectAnimator popup = ObjectAnimator.ofPropertyValuesHolder(view,
39 | PropertyValuesHolder.ofFloat("alpha", 0f, 1f),
40 | PropertyValuesHolder.ofFloat("scaleX", 0f, 1f),
41 | PropertyValuesHolder.ofFloat("scaleY", 0f, 1f));
42 | popup.setDuration(duration);
43 | popup.setInterpolator(new OvershootInterpolator());
44 |
45 | return popup;
46 | }
47 |
48 | @Override
49 | public ValueAnimator popout(final View view, final long duration, final AnimatorListenerAdapter animatorListenerAdapter) {
50 | ObjectAnimator popout = ObjectAnimator.ofPropertyValuesHolder(view,
51 | PropertyValuesHolder.ofFloat("alpha", 1f, 0f),
52 | PropertyValuesHolder.ofFloat("scaleX", 1f, 0f),
53 | PropertyValuesHolder.ofFloat("scaleY", 1f, 0f));
54 | popout.setDuration(duration);
55 | popout.addListener(new AnimatorListenerAdapter() {
56 | @Override
57 | public void onAnimationEnd(Animator animation) {
58 | super.onAnimationEnd(animation);
59 | view.setVisibility(View.GONE);
60 | if (animatorListenerAdapter != null) {
61 | animatorListenerAdapter.onAnimationEnd(animation);
62 | }
63 | }
64 | });
65 | popout.setInterpolator(new AnticipateOvershootInterpolator());
66 |
67 | return popout;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/HoverView.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Copyright 2017 Tomer Goldstein
4 |
5 | Licensed under the Apache License, Version 2.0 (the "License");
6 | you may not use this file except in compliance with the License.
7 | You may obtain a copy of the License at
8 |
9 | http://www.apache.org/licenses/LICENSE-2.0
10 |
11 | Unless required by applicable law or agreed to in writing, software
12 | distributed under the License is distributed on an "AS IS" BASIS,
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | See the License for the specific language governing permissions and
15 | limitations under the License.
16 | */
17 | package com.tomergoldst.hoverview;
18 |
19 | import android.content.Context;
20 | import android.support.annotation.IntDef;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 |
24 | /**
25 | * Created by Tomer on 01/07/2016.
26 | *
27 | *
28 | */
29 | public class HoverView {
30 |
31 | @IntDef({POSITION_ABOVE, POSITION_BELOW, POSITION_LEFT_TO, POSITION_RIGHT_TO})
32 | public @interface Position {}
33 | public static final int POSITION_ABOVE = 0;
34 | public static final int POSITION_BELOW = 1;
35 | public static final int POSITION_LEFT_TO = 3;
36 | public static final int POSITION_RIGHT_TO = 4;
37 |
38 | @IntDef({ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT})
39 | public @interface Align {}
40 | public static final int ALIGN_CENTER = 0;
41 | public static final int ALIGN_LEFT = 1;
42 | public static final int ALIGN_RIGHT = 2;
43 |
44 | private Context mContext;
45 | private View mAnchorView;
46 | private ViewGroup mRootViewGroup;
47 | private @Position int mPosition;
48 | private @Align int mAlign;
49 | private int mOffsetX;
50 | private int mOffsetY;
51 | private View mView;
52 |
53 | public HoverView(Builder builder){
54 | mContext = builder.mContext;
55 | mAnchorView = builder.mAnchorView;
56 | mRootViewGroup = builder.mRootViewGroup;
57 | mPosition = builder.mPosition;
58 | mAlign = builder.mAlign;
59 | mOffsetX = builder.mOffsetX;
60 | mOffsetX = builder.mOffsetX;
61 | mOffsetY = builder.mOffsetY;
62 | mView = builder.mView;
63 | }
64 |
65 | public Context getContext() {
66 | return mContext;
67 | }
68 |
69 | public View getAnchorView() {
70 | return mAnchorView;
71 | }
72 |
73 | public ViewGroup getRootView() {
74 | return mRootViewGroup;
75 | }
76 |
77 | public int getPosition() {
78 | return mPosition;
79 | }
80 |
81 | public int getAlign() {
82 | return mAlign;
83 | }
84 |
85 | public int getOffsetX() {
86 | return mOffsetX;
87 | }
88 |
89 | public int getOffsetY() {
90 | return mOffsetY;
91 | }
92 |
93 | public boolean positionedLeftTo(){
94 | return POSITION_LEFT_TO == mPosition;
95 | }
96 |
97 | public boolean positionedRightTo(){
98 | return POSITION_RIGHT_TO == mPosition;
99 | }
100 |
101 | public boolean positionedAbove(){
102 | return POSITION_ABOVE == mPosition;
103 | }
104 |
105 | public boolean positionedBelow(){
106 | return POSITION_BELOW == mPosition;
107 | }
108 |
109 | public boolean alignedCenter(){
110 | return ALIGN_CENTER == mAlign;
111 | }
112 |
113 | public boolean alignedLeft(){
114 | return ALIGN_LEFT == mAlign;
115 | }
116 |
117 | public boolean alignedRight(){
118 | return ALIGN_RIGHT == mAlign;
119 | }
120 |
121 | public void setPosition(@Position int position){
122 | mPosition = position;
123 | }
124 |
125 | public View getView() {
126 | return mView;
127 | }
128 |
129 | public void setView(View view) {
130 | mView = view;
131 | }
132 |
133 | public static class Builder {
134 | private Context mContext;
135 | private View mAnchorView;
136 | private ViewGroup mRootViewGroup;
137 | private @Position int mPosition;
138 | private @Align int mAlign;
139 | private int mOffsetX;
140 | private int mOffsetY;
141 | private View mView;
142 |
143 | /**
144 | * @param context context
145 | * @param anchorView the view which near it we want to put the tip
146 | * @param root a class extends ViewGroup which the created tip view will be added to
147 | * @param view view to show
148 | * @param position put the tip above / below / left to / right to
149 | */
150 | public Builder(Context context, View anchorView, ViewGroup root, View view, @Position int position){
151 | mContext = context;
152 | mAnchorView = anchorView;
153 | mRootViewGroup = root;
154 | mPosition = position;
155 | mAlign = ALIGN_CENTER;
156 | mOffsetX = 0;
157 | mOffsetY = 0;
158 | mView = view;
159 | }
160 |
161 | public Builder setPosition(@Position int position){
162 | mPosition = position;
163 | return this;
164 | }
165 |
166 | public Builder setAlign(@Align int align){
167 | mAlign = align;
168 | return this;
169 | }
170 |
171 | /**
172 | * @param offset offset to move the tip on x axis after tip was positioned
173 | * @return offset
174 | */
175 | public Builder setOffsetX(int offset){
176 | mOffsetX = offset;
177 | return this;
178 | }
179 |
180 | /**
181 | * @param offset offset to move the tip on y axis after tip was positioned
182 | * @return offset
183 | */
184 | public Builder setOffsetY(int offset){
185 | mOffsetY = offset;
186 | return this;
187 | }
188 |
189 | public Builder setView(View view) {
190 | mView = view;
191 | return this;
192 | }
193 |
194 | public HoverView build(){
195 | return new HoverView(this);
196 | }
197 |
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/HoverViewAnimator.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverview;
2 |
3 | import android.animation.AnimatorListenerAdapter;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.view.View;
7 |
8 | /**
9 | * Animator for the tooltip view.
10 | */
11 | public interface HoverViewAnimator {
12 | /**
13 | * Object animator for the tooltip view to pop-up.
14 | * @param view The tooltip view.
15 | * @param duration Duration for the animator.
16 | * @return ObjectAnimator
17 | */
18 | ValueAnimator popup(final View view, final long duration);
19 |
20 | /**
21 | * Object animator for the tooltip view to pop-out/hide.
22 | * @param view The tooltip view.
23 | * @param duration Duration for the animator.
24 | * @param animatorListenerAdapter The animator listener adapter to listen for animation event.
25 | * @return ObjectAnimator
26 | */
27 | ValueAnimator popout(final View view, final long duration, final AnimatorListenerAdapter animatorListenerAdapter);
28 | }
29 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/HoverViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017 Tomer Goldstein
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package com.tomergoldst.hoverview;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.graphics.Point;
22 | import android.support.annotation.NonNull;
23 | import android.support.annotation.Nullable;
24 | import android.util.Log;
25 | import android.view.View;
26 |
27 | import java.util.HashMap;
28 | import java.util.Map;
29 |
30 | public class HoverViewManager {
31 |
32 | private static final String TAG = HoverViewManager.class.getSimpleName();
33 |
34 | private static final int DEFAULT_ANIM_DURATION = 400;
35 |
36 | // Parameter for managing view creation or reuse
37 | private Map mHoverViewsMap = new HashMap<>();
38 |
39 | private int mAnimationDuration;
40 |
41 | @Nullable
42 | private HoverViewListener mListener;
43 |
44 | @NonNull
45 | private HoverViewAnimator mHoverViewAnimator;
46 |
47 | public interface HoverViewListener {
48 | void onHoverViewDismissed(View view, int anchorViewId, boolean byUser);
49 | }
50 |
51 | public HoverViewManager(){
52 | mAnimationDuration = DEFAULT_ANIM_DURATION;
53 | mHoverViewAnimator = new DefaultHoverViewAnimator();
54 | }
55 |
56 | public HoverViewManager(HoverViewListener listener){
57 | this();
58 | mListener = listener;
59 | }
60 |
61 | /**
62 | * Set a custom hover view animator to override show and hide animation.
63 | * @param animator HoverViewAnimator
64 | */
65 | public void setHoverVIewAnimator(@NonNull HoverViewAnimator animator) {
66 | mHoverViewAnimator = animator;
67 | }
68 |
69 | public View show(HoverView hoverView) {
70 | View view = create(hoverView);
71 | if (view == null) {
72 | return null;
73 | }
74 |
75 | // animate view visibility
76 | mHoverViewAnimator.popup(view, mAnimationDuration).start();
77 |
78 | return view;
79 | }
80 |
81 | private View create(HoverView hoverView) {
82 |
83 | if (hoverView.getAnchorView() == null) {
84 | Log.e(TAG, "Unable to create a hoverview, anchor view is null");
85 | return null;
86 | }
87 |
88 | if (hoverView.getRootView() == null) {
89 | Log.e(TAG, "Unable to create a hoverview, root layout is null");
90 | return null;
91 | }
92 |
93 | // only one hoverview is allowed near an anchor view at the same time, thus
94 | // reuse hoverview if already exist
95 | if (mHoverViewsMap.containsKey(hoverView.getAnchorView().getId())) {
96 | return mHoverViewsMap.get(hoverView.getAnchorView().getId()).getView();
97 | }
98 |
99 | // init view parameters
100 | hoverView.getView().setVisibility(View.INVISIBLE);
101 |
102 | // on RTL languages replace sides
103 | if (UiUtils.isRtl()) {
104 | switchHoverViewSidePosition(hoverView);
105 | }
106 |
107 | // add hoverview to root layout
108 | hoverView.getRootView().addView(hoverView.getView());
109 |
110 | // find where to position the hoverview
111 | Point point = ViewCoordinatesFinder.getCoordinates(hoverView);
112 |
113 | // move hoverview to correct position
114 | moveHoverViewToCorrectPosition(hoverView.getView(), point);
115 |
116 | // set dismiss on click
117 | hoverView.getView().setOnClickListener(new View.OnClickListener() {
118 | @Override
119 | public void onClick(View view) {
120 | dismiss(view, true);
121 | }
122 | });
123 |
124 | // bind hoverview with anchorView id
125 | int anchorViewId = hoverView.getAnchorView().getId();
126 | hoverView.getView().setTag(anchorViewId);
127 |
128 | // insert hoverview to map by 'anchorView' id
129 | mHoverViewsMap.put(anchorViewId, hoverView);
130 |
131 | return hoverView.getView();
132 |
133 | }
134 |
135 | private void moveHoverViewToCorrectPosition(View view, Point p) {
136 | Coordinates coordinates = new Coordinates(view);
137 | int translationX = p.x - coordinates.left;
138 | int translationY = p.y - coordinates.top;
139 | view.setTranslationX(!UiUtils.isRtl() ? translationX : -translationX);
140 | view.setTranslationY(translationY);
141 | }
142 |
143 | private void switchHoverViewSidePosition(HoverView hoverView) {
144 | if (hoverView.positionedLeftTo()) {
145 | hoverView.setPosition(HoverView.POSITION_RIGHT_TO);
146 | } else if (hoverView.positionedRightTo()) {
147 | hoverView.setPosition(HoverView.POSITION_LEFT_TO);
148 | }
149 | }
150 |
151 | public void setAnimationDuration(int duration){
152 | mAnimationDuration = duration;
153 | }
154 |
155 | public boolean dismiss(View view, boolean byUser) {
156 | if (view != null && isVisible(view)) {
157 | int key = (int) view.getTag();
158 | HoverView hoverView = mHoverViewsMap.get(key);
159 | mHoverViewsMap.remove(key);
160 | animateDismiss(hoverView, byUser);
161 | return true;
162 | }
163 | return false;
164 | }
165 |
166 | public boolean dismiss(Integer key) {
167 | return mHoverViewsMap.containsKey(key) && dismiss(mHoverViewsMap.get(key).getView(), false);
168 | }
169 |
170 | public View find(Integer key) {
171 | if (mHoverViewsMap.containsKey(key)) {
172 | return mHoverViewsMap.get(key).getView();
173 | }
174 | return null;
175 | }
176 |
177 | public boolean findAndDismiss(final View anchorView) {
178 | View view = find(anchorView.getId());
179 | return view != null && dismiss(view, false);
180 | }
181 |
182 | public void clear() {
183 | if (!mHoverViewsMap.isEmpty()) {
184 | for (Map.Entry entry : mHoverViewsMap.entrySet()) {
185 | dismiss(entry.getValue().getView(), false);
186 | }
187 | }
188 | mHoverViewsMap.clear();
189 | }
190 |
191 | private void animateDismiss(final HoverView hoverView, final boolean byUser) {
192 | mHoverViewAnimator.popout(hoverView.getView(), mAnimationDuration, new AnimatorListenerAdapter() {
193 | @Override
194 | public void onAnimationEnd(Animator animation) {
195 | super.onAnimationEnd(animation);
196 | hoverView.getRootView().removeView(hoverView.getView());
197 | if (mListener != null){
198 | mListener.onHoverViewDismissed(hoverView.getView(),
199 | (Integer) hoverView.getView().getTag(), byUser);
200 | }
201 | }
202 | }).start();
203 | }
204 |
205 | public boolean isVisible(View view) {
206 | return view.getVisibility() == View.VISIBLE;
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/UiUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017 Tomer Goldstein
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package com.tomergoldst.hoverview;
18 |
19 | import java.util.Locale;
20 |
21 | /**
22 | * Created by Tomer on 01/07/2016.
23 | */
24 | class UiUtils {
25 |
26 | static boolean isRtl(){
27 | Locale defLocal = Locale.getDefault();
28 | return Character.getDirectionality(defLocal.getDisplayName(defLocal).charAt(0))
29 | == Character.DIRECTIONALITY_RIGHT_TO_LEFT;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/hoverview/src/main/java/com/tomergoldst/hoverview/ViewCoordinatesFinder.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017 Tomer Goldstein
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package com.tomergoldst.hoverview;
18 |
19 | import android.graphics.Point;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 |
23 | /**
24 | * Created by Tomer on 01/07/2016.
25 | */
26 | class ViewCoordinatesFinder {
27 |
28 | /**
29 | * return the top left coordinates for positioning the view
30 | *
31 | * @param hoverview - hoverview object
32 | * @return point
33 | */
34 | static Point getCoordinates(HoverView hoverview) {
35 | Point point = new Point();
36 | final Coordinates anchorViewCoordinates = new Coordinates(hoverview.getAnchorView());
37 | final Coordinates rootCoordinates = new Coordinates(hoverview.getRootView());
38 |
39 | View view = hoverview.getView();
40 | view.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
41 |
42 | switch (hoverview.getPosition()) {
43 | case HoverView.POSITION_ABOVE:
44 | point = getPositionAbove(view, hoverview,
45 | anchorViewCoordinates, rootCoordinates);
46 | break;
47 | case HoverView.POSITION_BELOW:
48 | point = getPositionBelow(view, hoverview,
49 | anchorViewCoordinates, rootCoordinates);
50 | break;
51 | case HoverView.POSITION_LEFT_TO:
52 | point = getPositionLeftTo(view, hoverview,
53 | anchorViewCoordinates, rootCoordinates);
54 | break;
55 | case HoverView.POSITION_RIGHT_TO:
56 | point = getPositionRightTo(view, hoverview,
57 | anchorViewCoordinates, rootCoordinates);
58 | break;
59 | }
60 |
61 | // add user defined offset values
62 | point.x += UiUtils.isRtl() ? -hoverview.getOffsetX() : hoverview.getOffsetX();
63 | point.y += hoverview.getOffsetY();
64 |
65 | // coordinates retrieved are relative to 0,0 of the root layout
66 | // added view to root is subject to root padding
67 | // we need to subtract the top and left padding of root from coordinates. to adjust
68 | // top left view coordinates
69 | point.x -= hoverview.getRootView().getPaddingLeft();
70 | point.y -= hoverview.getRootView().getPaddingTop();
71 |
72 | return point;
73 |
74 | }
75 |
76 | private static Point getPositionRightTo(View view, HoverView hoverView, Coordinates anchorViewCoordinates, Coordinates rootLocation) {
77 | Point point = new Point();
78 | point.x = anchorViewCoordinates.right;
79 | AdjustRightToOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
80 | point.y = anchorViewCoordinates.top + getYCenteringOffset(view, hoverView);
81 | return point;
82 | }
83 |
84 | private static Point getPositionLeftTo(View view, HoverView hoverView, Coordinates anchorViewCoordinates, Coordinates rootLocation) {
85 | Point point = new Point();
86 | point.x = anchorViewCoordinates.left - view.getMeasuredWidth();
87 | AdjustLeftToOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
88 | point.y = anchorViewCoordinates.top + getYCenteringOffset(view, hoverView);
89 | return point;
90 | }
91 |
92 | private static Point getPositionBelow(View view, HoverView hoverView, Coordinates anchorViewCoordinates, Coordinates rootLocation) {
93 | Point point = new Point();
94 | point.x = anchorViewCoordinates.left + getXOffset(view, hoverView);
95 | if (hoverView.alignedCenter()) {
96 | AdjustHorizontalCenteredOutOfBounds(view, hoverView.getRootView(), point, rootLocation);
97 | } else if (hoverView.alignedLeft()){
98 | AdjustHorizontalLeftAlignmentOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
99 | } else if (hoverView.alignedRight()){
100 | AdjustHorizontalRightAlignmentOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
101 | }
102 | point.y = anchorViewCoordinates.bottom;
103 | return point;
104 | }
105 |
106 | private static Point getPositionAbove(View view, HoverView hoverView,
107 | Coordinates anchorViewCoordinates, Coordinates rootLocation) {
108 | Point point = new Point();
109 | point.x = anchorViewCoordinates.left + getXOffset(view, hoverView);
110 | if (hoverView.alignedCenter()) {
111 | AdjustHorizontalCenteredOutOfBounds(view, hoverView.getRootView(), point, rootLocation);
112 | } else if (hoverView.alignedLeft()){
113 | AdjustHorizontalLeftAlignmentOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
114 | } else if (hoverView.alignedRight()){
115 | AdjustHorizontalRightAlignmentOutOfBounds(view, hoverView.getRootView(), point, anchorViewCoordinates, rootLocation);
116 | }
117 | point.y = anchorViewCoordinates.top - view.getMeasuredHeight();
118 | return point;
119 | }
120 |
121 | private static void AdjustRightToOutOfBounds(View view, ViewGroup root, Point point, Coordinates anchorViewCoordinates, Coordinates rootLocation) {
122 | ViewGroup.LayoutParams params = view.getLayoutParams();
123 | int availableSpace = rootLocation.right - root.getPaddingRight() - anchorViewCoordinates.right;
124 | if (point.x + view.getMeasuredWidth() > rootLocation.right - root.getPaddingRight()){
125 | params.width = availableSpace;
126 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
127 | view.setLayoutParams(params);
128 | measureViewWithFixedWidth(view, params.width);
129 | }
130 | }
131 |
132 | private static void AdjustLeftToOutOfBounds(View view, ViewGroup root, Point point, Coordinates anchorViewCoordinates, Coordinates rootLocation) {
133 | ViewGroup.LayoutParams params = view.getLayoutParams();
134 | int rootLeft = rootLocation.left + root.getPaddingLeft();
135 | if (point.x < rootLeft){
136 | int availableSpace = anchorViewCoordinates.left - rootLeft;
137 | point.x = rootLeft;
138 | params.width = availableSpace;
139 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
140 | view.setLayoutParams(params);
141 | measureViewWithFixedWidth(view, params.width);
142 | }
143 | }
144 |
145 | private static void AdjustHorizontalRightAlignmentOutOfBounds(View view, ViewGroup root,
146 | Point point, Coordinates anchorViewCoordinates,
147 | Coordinates rootLocation) {
148 | ViewGroup.LayoutParams params = view.getLayoutParams();
149 | int rootLeft = rootLocation.left + root.getPaddingLeft();
150 | if (point.x < rootLeft){
151 | int availableSpace = anchorViewCoordinates.right - rootLeft;
152 | point.x = rootLeft;
153 | params.width = availableSpace;
154 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
155 | view.setLayoutParams(params);
156 | measureViewWithFixedWidth(view, params.width);
157 | }
158 | }
159 |
160 | private static void AdjustHorizontalLeftAlignmentOutOfBounds(View view, ViewGroup root,
161 | Point point, Coordinates anchorViewCoordinates,
162 | Coordinates rootLocation) {
163 | ViewGroup.LayoutParams params = view.getLayoutParams();
164 | int rootRight = rootLocation.right - root.getPaddingRight();
165 | if (point.x + view.getMeasuredWidth() > rootRight){
166 | params.width = rootRight - anchorViewCoordinates.left;
167 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
168 | view.setLayoutParams(params);
169 | measureViewWithFixedWidth(view, params.width);
170 | }
171 | }
172 |
173 | private static void AdjustHorizontalCenteredOutOfBounds(View view, ViewGroup root,
174 | Point point, Coordinates rootLocation) {
175 | ViewGroup.LayoutParams params = view.getLayoutParams();
176 | int rootWidth = root.getWidth() - root.getPaddingLeft() - root.getPaddingRight();
177 | if (view.getMeasuredWidth() > rootWidth) {
178 | point.x = rootLocation.left + root.getPaddingLeft();
179 | params.width = rootWidth;
180 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
181 | view.setLayoutParams(params);
182 | measureViewWithFixedWidth(view, rootWidth);
183 | }
184 | }
185 |
186 |
187 | private static void measureViewWithFixedWidth(View view, int width) {
188 | view.measure(View.MeasureSpec.makeMeasureSpec(width,
189 | View.MeasureSpec.EXACTLY), ViewGroup.LayoutParams.WRAP_CONTENT);
190 | }
191 |
192 | /**
193 | * calculate the amount of movement need to be taken inorder to align view
194 | * on X axis according to "align" parameter
195 | * @return int
196 | */
197 | private static int getXOffset(View view, HoverView hoverView) {
198 | int offset;
199 |
200 | switch (hoverView.getAlign()) {
201 | case HoverView.ALIGN_CENTER:
202 | offset = ((hoverView.getAnchorView().getWidth() - view.getMeasuredWidth()) / 2);
203 | break;
204 | case HoverView.ALIGN_LEFT:
205 | offset = 0;
206 | break;
207 | case HoverView.ALIGN_RIGHT:
208 | offset = hoverView.getAnchorView().getWidth() - view.getMeasuredWidth();
209 | break;
210 | default:
211 | offset = 0;
212 | break;
213 | }
214 |
215 | return offset;
216 | }
217 |
218 | /**
219 | * calculate the amount of movement need to be taken inorder to center view
220 | * on Y axis
221 | * @return int
222 | */
223 | private static int getYCenteringOffset(View view, HoverView hoverView) {
224 | return (hoverView.getAnchorView().getHeight() - view.getMeasuredHeight()) / 2;
225 | }
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/hoverview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HoverView
3 |
4 |
--------------------------------------------------------------------------------
/hoverview/src/test/java/com/tomergoldst/hoverview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tomergoldst.hoverview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':hoverview'
2 |
--------------------------------------------------------------------------------