Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**
     * The popup width is determined by the minimum width excluding content
     * (usually the width of the pointy mark and padding), the maximum width
     * (usually the width of the screen), a desired width (including content),
     * the width of the anchor and the position along the anchor at which the
     * pointy mark should point. Normally the popup takes the desired width or
     * the maximum width, unless the target arrow would otherwise be positioned
     * outside of the popup, in which case the popup is expanded to include the
     * pointy mark.
        
     * @param minWidth - the minimum width of the popup (not including content)
     * @param maxWidth - the maximum width of the popup
     * @param desiredWidth - the desired with of the popup (including content)
     * @param anchorWidth - the width of the anchor view
     * @param target - the position on the anchor at which the pointy mark should point
     */
    public static int getPopupWidth(int minWidth, int maxWidth, int desiredWidth, int anchorWidth, float target) {
        // Minimum width as a percentage of the anchor width
        final double width = 2 * Math.abs(0.5 - target);

        // Minimum width as an absolute value
        int popupWidth = (int) (anchorWidth * width) + minWidth;

        // Make sure not smaller than the minimum width
        popupWidth = popupWidth > desiredWidth ? popupWidth : desiredWidth;

        // Make sure not larger than the max width
        return popupWidth > maxWidth ? maxWidth : popupWidth;
    }
}