Java Code Examples for android.util.FloatMath#ceil()

The following examples show how to use android.util.FloatMath#ceil() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinePageIndicator.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 2
Source File: LinePageIndicator.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 3
Source File: LinePageIndicator.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 4
Source File: LinePageIndicator.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 5
Source File: LinePageIndicator.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 6
Source File: LinePageIndicator.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 7
Source File: LinePageIndicator.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 8
Source File: LinePageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 9
Source File: LinePageIndicator.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 10
Source File: LinePageIndicator.java    From KlyphMessenger with MIT License 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 11
Source File: LinePageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 12
Source File: LinePageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 13
Source File: LinePageIndicator.java    From AndroidCacheFoundation with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the width of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
        //We were told how big to be
        result = specSize;
    } else {
        //Calculate the width according the views count
        final int count = mViewPager.getAdapter().getCount();
        result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 14
Source File: LinePageIndicator.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the height of this view
 *
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    float result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        //We were told how big to be
        result = specSize;
    } else {
        //Measure the height
        result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom();
        //Respect AT_MOST value if that was what is called for by measureSpec
        if (specMode == MeasureSpec.AT_MOST) {
            result = Math.min(result, specSize);
        }
    }
    return (int)FloatMath.ceil(result);
}
 
Example 15
Source File: GPlayer.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp) {
    Log.v(LOGTAG, "onPrepared Called");
    videoWidth = mp.getVideoWidth();
    videoHeight = mp.getVideoHeight();
    if (videoWidth > currentDisplay.getWidth() || videoHeight > currentDisplay.getHeight()) {
        float heightRatio = (float) videoHeight / (float) currentDisplay.getHeight();
        float widthRatio = (float) videoWidth / (float) currentDisplay.getWidth();
        if (heightRatio > 1 || widthRatio > 1) {
            if (heightRatio > widthRatio) {
                videoHeight = (int) FloatMath.ceil((float) videoHeight / (float) heightRatio);
                videoWidth = (int) FloatMath.ceil((float) videoWidth / (float) heightRatio);
            } else {
                videoHeight = (int) FloatMath.ceil((float) videoHeight / (float) widthRatio);
                videoWidth = (int) FloatMath.ceil((float) videoWidth / (float) widthRatio);
            }
        }
    }
    // surfaceView.setLayoutParams(new FrameLayout.LayoutParams(videoWidth,
    // videoHeight));
    mp.start();
    if (null != mMediaListener) {
        mMediaListener.start();
    }

    // mediaController.setMediaPlayer(this);
    // mediaController.setAnchorView(this.findViewById(R.id.gplayer_surfaceview));
    // mediaController.setEnabled(true);
    // mediaController.show(5000);
    mHandler.sendEmptyMessage(MEDIA_PLAYER_PREPARED);

    mHandler.sendEmptyMessage(MEDIA_PLAYER_PROGRESS_UPDATE);
    mHandler.sendEmptyMessageDelayed(MEDIA_PLAYER_HIDDEN_CONTROL, 10000);
}
 
Example 16
Source File: Cocos2dxBitmap.java    From Example-of-Cocos2DX with MIT License 4 votes vote down vote up
private static LinkedList<String> divideStringWithMaxWidth(
		final String string, final int maxWidth, final Paint paint) {
	final int charLength = string.length();
	int start = 0;
	int tempWidth = 0;
	final LinkedList<String> strList = new LinkedList<String>();

	/* Break a String into String[] by the width & should wrap the word. */
	for (int i = 1; i <= charLength; ++i) {
		tempWidth = (int) FloatMath.ceil(paint.measureText(string, start,
				i));
		if (tempWidth >= maxWidth) {
			final int lastIndexOfSpace = string.substring(0, i)
					.lastIndexOf(" ");

			if (lastIndexOfSpace != -1 && lastIndexOfSpace > start) {
				/* Should wrap the word. */
				strList.add(string.substring(start, lastIndexOfSpace));
				i = lastIndexOfSpace + 1; // skip space
			} else {
				/* Should not exceed the width. */
				if (tempWidth > maxWidth) {
					strList.add(string.substring(start, i - 1));
					/* Compute from previous char. */
					--i;
				} else {
					strList.add(string.substring(start, i));
				}
			}

			/* Remove spaces at the beginning of a new line. */
			while (i < charLength && string.charAt(i) == ' ') {
				++i;
			}

			start = i;
		}
	}

	/* Add the last chars. */
	if (start < charLength) {
		strList.add(string.substring(start));
	}

	return strList;
}
 
Example 17
Source File: WheelView.java    From zidoorecorder with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates control width and creates text layouts
 * 
 * @param widthSize
 *            the input layout width
 * @param mode
 *            the layout mode
 * @return the calculated control width
 */
private int calculateLayoutWidth(int widthSize, int mode) {
	initResourcesIfNecessary();

	int width = widthSize;

	int maxLength = getMaxTextLength();
	if (maxLength > 0) {
		float textWidth = FloatMath.ceil(Layout.getDesiredWidth("0",
				itemsPaint));
		itemsWidth = (int) (maxLength * textWidth);
	} else {
		itemsWidth = 0;
	}
	itemsWidth += ADDITIONAL_ITEMS_SPACE; // make it some more

	labelWidth = 0;
	if (label != null && label.length() > 0) {
		labelWidth = (int) FloatMath.ceil(Layout.getDesiredWidth(label,
				valuePaint));
	}

	boolean recalculate = false;
	if (mode == MeasureSpec.EXACTLY) {
		width = widthSize;
		recalculate = true;
	} else {
		//调节水平居中
		width = itemsWidth + labelWidth +  PADDING+18;
		if (labelWidth > 0) {
			width += LABEL_OFFSET;
		}

		// Check against our minimum width
		width = Math.max(width, getSuggestedMinimumWidth());

		if (mode == MeasureSpec.AT_MOST && widthSize < width) {
			width = widthSize;
			recalculate = true;
		}
	}

	if (recalculate) {
		// recalculate width
		//调节居中的
		int pureWidth = width - LABEL_OFFSET -PADDING-8;
		if (pureWidth <= 0) {
			itemsWidth = labelWidth = 0;
		}
		if (labelWidth > 0) {
			double newWidthItems = (double) itemsWidth * pureWidth
					/ (itemsWidth + labelWidth);
			itemsWidth = (int) newWidthItems;
			labelWidth = pureWidth - itemsWidth;
		} else {
			itemsWidth = pureWidth + LABEL_OFFSET; // no label
		}
	}

	if (itemsWidth > 0) {
		createLayouts(itemsWidth, labelWidth);
	}

	return width;
}
 
Example 18
Source File: WheelView.java    From Gizwits-SmartSocket_Android with MIT License 4 votes vote down vote up
/**
 * Calculates control width and creates text layouts.
 *
 * @param widthSize the input layout width
 * @param mode      the layout mode
 * @return the calculated control width
 */
private int calculateLayoutWidth(int widthSize, int mode) {
    initResourcesIfNecessary();

    int width = widthSize;

    int maxLength = getMaxTextLength();
    if (maxLength > 0) {
        float textWidth = FloatMath.ceil(Layout.getDesiredWidth("0", itemsPaint));
        itemsWidth = (int) (maxLength * textWidth);
    } else {
        itemsWidth = 0;
    }
    itemsWidth += ADDITIONAL_ITEMS_SPACE; // make it some more

    labelWidth = 0;
    if (label != null && label.length() > 0) {
        labelWidth = (int) FloatMath.ceil(Layout.getDesiredWidth(label, valuePaint));
    }

    boolean recalculate = false;
    if (mode == MeasureSpec.EXACTLY) {
        width = widthSize;
        recalculate = true;
    } else {
        width = itemsWidth + labelWidth + 2 * PADDING;
        if (labelWidth > 0) {
            width += LABEL_OFFSET;
        }

        // Check against our minimum width
        width = Math.max(width, getSuggestedMinimumWidth());

        if (mode == MeasureSpec.AT_MOST && widthSize < width) {
            width = widthSize;
            recalculate = true;
        }
    }

    if (recalculate) {
        // recalculate width
        int pureWidth = width - LABEL_OFFSET - 2 * PADDING;
        if (pureWidth <= 0) {
            itemsWidth = labelWidth = 0;
        }
        if (labelWidth > 0) {
            double newWidthItems = (double) itemsWidth * pureWidth
                    / (itemsWidth + labelWidth);
            itemsWidth = (int) newWidthItems;
            labelWidth = pureWidth - itemsWidth;
        } else {
            itemsWidth = pureWidth + LABEL_OFFSET; // no label
        }
    }

    if (itemsWidth > 0) {
        createLayouts(itemsWidth, labelWidth);
    }

    return width;
}
 
Example 19
Source File: BoringLayout.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
void init(CharSequence source,
                        TextPaint paint, int outerwidth,
                        Alignment align,
                        float spacingmult, float spacingadd,
                        BoringLayout.Metrics metrics, boolean includepad,
                        boolean trustWidth) {
    int spacing;

    if (source instanceof String && align == Layout.Alignment.ALIGN_NORMAL) {
        mDirect = source.toString();
    } else {
        mDirect = null;
    }

    mPaint = paint;

    if (includepad) {
        spacing = metrics.bottom - metrics.top;
    } else {
        spacing = metrics.descent - metrics.ascent;
    }

    if (spacingmult != 1 || spacingadd != 0) {
        spacing = (int)(spacing * spacingmult + spacingadd + 0.5f);
    }

    mBottom = spacing;

    if (includepad) {
        mDesc = spacing + metrics.top;
    } else {
        mDesc = spacing + metrics.ascent;
    }

    if (trustWidth) {
        mMax = metrics.width;
    } else {
        /*
         * If we have ellipsized, we have to actually calculate the
         * width because the width that was passed in was for the
         * full text, not the ellipsized form.
         */
        synchronized (sTemp) {
            mMax = (int) (FloatMath.ceil(Styled.measureText(paint, sTemp,
                                            source, 0, source.length(),
                                            null)));
        }
    }

    if (includepad) {
        mTopPadding = metrics.top - metrics.ascent;
        mBottomPadding = metrics.bottom - metrics.descent;
    }
}
 
Example 20
Source File: BoringLayout.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
/**
 * Returns null if not boring; the width, ascent, and descent in the
 * provided Metrics object (or a new one if the provided one was null)
 * if boring.
 */
public static Metrics isBoring(CharSequence text, TextPaint paint,
                               Metrics metrics) {
    char[] temp = TextUtils.obtain(500);
    int len = text.length();
    boolean boring = true;

    outer:
    for (int i = 0; i < len; i += 500) {
        int j = i + 500;

        if (j > len)
            j = len;

        TextUtils.getChars(text, i, j, temp, 0);

        int n = j - i;

        for (int a = 0; a < n; a++) {
            char c = temp[a];

            if (c == '\n' || c == '\t' || c >= FIRST_RIGHT_TO_LEFT) {
                boring = false;
                break outer;
            }
        }
    }

    TextUtils.recycle(temp);

    if (boring && text instanceof Spanned) {
        Spanned sp = (Spanned) text;
        Object[] styles = sp.getSpans(0, text.length(), ParagraphStyle.class);
        if (styles.length > 0) {
            boring = false;
        }
    }

    if (boring) {
        Metrics fm = metrics;
        if (fm == null) {
            fm = new Metrics();
        }

        int wid;

        synchronized (sTemp) {
            wid = (int) (FloatMath.ceil(Styled.measureText(paint, sTemp,
                                            text, 0, text.length(), fm)));
        }
        fm.width = wid;
        return fm;
    } else {
        return null;
    }
}