android.util.FloatMath#ceil ( )源码实例Demo

下面列出了android.util.FloatMath#ceil ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zhangshangwuda   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码2 项目: barterli_android   文件: LinePageIndicator.java
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码6 项目: KlyphMessenger   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码7 项目: narrate-android   文件: LinePageIndicator.java
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码9 项目: monolog-android   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码10 项目: Klyph   文件: LinePageIndicator.java
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码12 项目: UltimateAndroid   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码13 项目: android-project-wo2b   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码14 项目: Klyph   文件: LinePageIndicator.java
/**
 * 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);
}
 
源代码15 项目: DroidDLNA   文件: GPlayer.java
@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);
}
 
源代码16 项目: Example-of-Cocos2DX   文件: Cocos2dxBitmap.java
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;
}
 
源代码17 项目: zidoorecorder   文件: WheelView.java
/**
 * 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;
}
 
源代码18 项目: Gizwits-SmartSocket_Android   文件: WheelView.java
/**
 * 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;
}
 
源代码19 项目: JotaTextEditor   文件: BoringLayout.java
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;
    }
}
 
源代码20 项目: JotaTextEditor   文件: BoringLayout.java
/**
 * 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;
    }
}