worker8 / TourGuide

TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View
MIT License
2.63k stars 416 forks source link

getYForTooTip does not handle CENTER_VERTICAL gravity #59

Open peterosterlund2 opened 8 years ago

peterosterlund2 commented 8 years ago

I think the getYForTooTip method should look something like this:

private int getYForTooTip(int gravity, int toolTipMeasuredHeight, int targetViewY, float adjustment){
    int y;
    if ((gravity & Gravity.TOP) == Gravity.TOP) {

        if (((gravity & Gravity.LEFT) == Gravity.LEFT) || ((gravity & Gravity.RIGHT) == Gravity.RIGHT)) {
            y =  targetViewY - toolTipMeasuredHeight + (int)adjustment;
        } else {
            y =  targetViewY - toolTipMeasuredHeight - (int)adjustment;
        }
    } else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
        if (((gravity & Gravity.LEFT) == Gravity.LEFT) || ((gravity & Gravity.RIGHT) == Gravity.RIGHT)) {
            y =  targetViewY + mHighlightedView.getHeight() - (int) adjustment;
        } else {
            y =  targetViewY + mHighlightedView.getHeight() + (int) adjustment;
        }
    } else { // this is center
        if (((gravity & Gravity.LEFT) == Gravity.LEFT) || ((gravity & Gravity.RIGHT) == Gravity.RIGHT)) {
            y =  targetViewY + mHighlightedView.getHeight() / 2 - (int) adjustment;
        } else {
            y =  targetViewY + mHighlightedView.getHeight() / 2 + (int) adjustment;
        }
    }
    return y;
}
worker8 commented 8 years ago

Hi @peterosterlund2 Your code actually looks good, that should fix Gravity.BOTTOM, can you make a pull request?

I will then test and merge it.