Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

Expand All @@ -16,3 +16,5 @@ allprojects {
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}


2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
buildToolsVersion "25.0.3"

defaultConfig {
applicationId "com.venmo.view.tooltip.example"
Expand Down

This file was deleted.

10 changes: 6 additions & 4 deletions example/src/main/res/layout/activity_tooltip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:gravity="center_horizontal"
android:text="Don't get it?"
app:tooltipColor="#66009900"
app:anchoredView="@id/header_1" />
app:arrowLocation="3"/>

<TextView
android:id="@id/header_1"
Expand Down Expand Up @@ -78,7 +78,8 @@
android:layout_below="@id/header_3"
app:cornerRadius="40dp"
app:tooltipColor="#999900cc"
app:arrowHeight="40dp" />
app:arrowHeight="40dp"
app:arrowAlignment="center"/>

<com.venmo.view.TooltipView
android:layout_width="160dp"
Expand All @@ -87,6 +88,7 @@
android:layout_toRightOf="@id/big_bubble_1"
android:layout_marginTop="16dp"
app:tooltipColor="#999900cc"
app:arrowWidth="120dp"
app:arrowHeight="60dp" />
app:arrowWidth="10dp"
app:arrowHeight="10dp"
app:arrowLocation="1"/>
</RelativeLayout>
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip


5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 14
Expand All @@ -29,4 +29,5 @@ android.libraryVariants.all { variant ->
}
}

apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'

22 changes: 14 additions & 8 deletions library/src/main/java/com/venmo/view/ArrowAlignmentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,37 @@

public final class ArrowAlignmentHelper {

public static float calculateArrowMidPoint(TooltipView view, RectF rectF) {
public static float calculateArrowMidPoint(TooltipView view, RectF rectF, boolean isHorizontal) {
int offset = view.getAlignmentOffset();
float middle = 0f;

float length = isHorizontal ? rectF.width() : rectF.height();
switch (view.getArrowAlignment()) {
case START:
middle = offset == 0 ? rectF.width() / 4 : offset;
middle = offset == 0 ? length / 4 : offset;
break;
case CENTER:
middle = rectF.width() / 2;
middle = length / 2;
if (offset > 0)
throw new IllegalArgumentException(
"Offsets are not support when the tooltip arrow is anchored in the middle of the view.");
break;
case END:
middle = rectF.width();
middle -= (offset == 0 ? rectF.width() / 4 : offset);
middle = length;
middle -= (offset == 0 ? length / 4 : offset);
break;
case ANCHORED_VIEW:
middle = rectF.width() / 2;
middle = length / 2;
if (view.getAnchoredViewId() != View.NO_ID) {
View anchoredView = ((View) view.getParent())
.findViewById(view.getAnchoredViewId());
middle += anchoredView.getX() + anchoredView.getWidth() / 2 - view.getX()
- view.getWidth() / 2;
if (isHorizontal) {
middle += anchoredView.getX() + anchoredView.getWidth() / 2 - view.getX()
- view.getWidth() / 2;
} else {
middle += anchoredView.getY() + anchoredView.getHeight() / 2 - view.getY()
- view.getHeight() / 2;
}
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;

import static android.graphics.Path.Direction;

Expand All @@ -18,7 +17,7 @@ public void configureDraw(TooltipView view, Canvas canvas) {
view.getTooltipPath()
.addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(), Direction.CW);

float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF);
float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF,true);

view.getTooltipPath().moveTo(middle, view.getHeight());
int arrowDx = view.getArrowWidth() / 2;
Expand Down
37 changes: 37 additions & 0 deletions library/src/main/java/com/venmo/view/LeftArrowLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.venmo.view;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

import static android.graphics.Path.Direction;

class LeftArrowLocation implements ArrowLocation {

@Override
public void configureDraw(TooltipView view, Canvas canvas) {
Path tooltipPath = new Path();
view.setTooltipPath(tooltipPath);
RectF rectF = new RectF(canvas.getClipBounds());
rectF.left += view.getArrowHeight();

rectF.top += 1;
rectF.bottom -= 1;
rectF.left += 1;
rectF.right -= 1;

tooltipPath.addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(), Direction.CW);

float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF, false);
tooltipPath.moveTo(0f, middle);
int arrowDy = view.getArrowWidth() / 2;
tooltipPath.lineTo(rectF.left, middle - arrowDy);
tooltipPath.lineTo(rectF.left, middle + arrowDy);
tooltipPath.close();

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(view.getTooltipColor());
view.setPaint(paint);
}
}
37 changes: 37 additions & 0 deletions library/src/main/java/com/venmo/view/RightArrowLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.venmo.view;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

import static android.graphics.Path.Direction;

class RightArrowLocation implements ArrowLocation {

@Override
public void configureDraw(TooltipView view, Canvas canvas) {
Path tooltipPath = new Path();
view.setTooltipPath(tooltipPath);
RectF rectF = new RectF(canvas.getClipBounds());
rectF.right -= view.getArrowHeight();

rectF.top += 1;
rectF.bottom -= 1;
rectF.left += 1;
rectF.right -= 1;

tooltipPath.addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(), Direction.CW);

float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF, false);
tooltipPath.moveTo(view.getWidth(), middle);
int arrowDy = view.getArrowWidth() / 2;
tooltipPath.lineTo(rectF.right, middle - arrowDy);
tooltipPath.lineTo(rectF.right, middle + arrowDy);
tooltipPath.close();

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(view.getTooltipColor());
view.setPaint(paint);
}
}
40 changes: 34 additions & 6 deletions library/src/main/java/com/venmo/view/TooltipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ public class TooltipView extends TextView {
private int arrowHeight;
private int arrowWidth;
private int cornerRadius;
private @IdRes int anchoredViewId;
private @ColorRes int tooltipColor;
private
@IdRes
int anchoredViewId;
private
@ColorRes
int tooltipColor;
private ArrowLocation arrowLocation;
private ArrowAlignment arrowAlignment;
private int alignmentOffset;
private int arrowPositioning;
private Paint paint;
private Path tooltipPath;
public static final int LEFT = 1, TOP = 2, RIGHT = 3, BOTTOM = 4;

public TooltipView(Context context) {
super(context);
Expand Down Expand Up @@ -61,8 +66,20 @@ private void init(AttributeSet attrs, int defStyle) {
R.dimen.tooltip_default_arrow_width);
arrowPositioning = a.getInteger(R.styleable.TooltipView_arrowLocation,
res.getInteger(R.integer.tooltip_default_arrow_location));
arrowLocation = arrowPositioning == 0 ? new TopArrowLocation()
: new BottomArrowLocation();
switch (arrowPositioning) {
case LEFT:
arrowLocation = new LeftArrowLocation();
break;
case TOP:
arrowLocation = new TopArrowLocation();
break;
case RIGHT:
arrowLocation = new RightArrowLocation();
break;
case BOTTOM:
arrowLocation = new BottomArrowLocation();
break;
}
arrowAlignment = ArrowAlignment.getAlignment(
a.getInteger(R.styleable.TooltipView_arrowAlignment, res.getInteger(
R.integer.tooltip_default_arrow_alignment)));
Expand All @@ -76,7 +93,18 @@ private void init(AttributeSet attrs, int defStyle) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + arrowHeight);
int widthOffset = 0, heightOffset = 0;
switch (arrowPositioning) {
case TOP:
case BOTTOM:
heightOffset = arrowHeight;
break;
case LEFT:
case RIGHT:
widthOffset = arrowHeight;
break;
}
setMeasuredDimension(getMeasuredWidth()+widthOffset, getMeasuredHeight() + heightOffset);
}

@Override
Expand Down Expand Up @@ -200,7 +228,7 @@ public void setAlignmentOffsetResource(@DimenRes int resId) {
}

private int getDimension(TypedArray a, @StyleableRes int styleableId,
@DimenRes int defaultDimension) {
@DimenRes int defaultDimension) {
int result = a.getDimensionPixelSize(styleableId, NOT_PRESENT);
if (result == NOT_PRESENT) {
result = getResources().getDimensionPixelSize(defaultDimension);
Expand Down
16 changes: 8 additions & 8 deletions library/src/main/java/com/venmo/view/TopArrowLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;

import static android.graphics.Path.Direction;

class TopArrowLocation implements ArrowLocation {

@Override
public void configureDraw(TooltipView view, Canvas canvas) {
view.setTooltipPath(new Path());
Path tooltipPath = new Path();
view.setTooltipPath(tooltipPath);
RectF rectF = new RectF(canvas.getClipBounds());
rectF.top += view.getArrowHeight();

view.getTooltipPath().addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(),
tooltipPath.addRoundRect(rectF, view.getCornerRadius(), view.getCornerRadius(),
Direction.CW);

float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF);
float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rectF,true);

view.getTooltipPath().moveTo(middle, 0f);
tooltipPath.moveTo(middle, 0f);
int arrowDx = view.getArrowWidth() / 2;
view.getTooltipPath().lineTo(middle - arrowDx, rectF.top);
view.getTooltipPath().lineTo(middle + arrowDx, rectF.top);
view.getTooltipPath().close();
tooltipPath.lineTo(middle - arrowDx, rectF.top);
tooltipPath.lineTo(middle + arrowDx, rectF.top);
tooltipPath.close();

view.setPaint(new Paint(Paint.ANTI_ALIAS_FLAG));
view.getTooltipPaint().setColor(view.getTooltipColor());
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<dimen name="tooltip_default_arrow_width">16dp</dimen>
<dimen name="tooltip_default_corner_radius">4dp</dimen>
<dimen name="tooltip_default_offset">0dp</dimen>
<integer name="tooltip_default_arrow_location">1</integer>
<integer name="tooltip_default_arrow_location">2</integer>
<integer name="tooltip_default_arrow_alignment">3</integer>
</resources>