类android.util.FloatMath源码实例Demo

下面列出了怎么用android.util.FloatMath的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: WayHoo   文件: 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 项目: KlyphMessenger   文件: 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);
}
 
源代码3 项目: narrate-android   文件: 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);
}
 
源代码4 项目: barterli_android   文件: 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 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);
}
 
源代码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 项目: WayHoo   文件: 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 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 项目: android-open-project-demo   文件: BitmapUtils.java
public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) {		
	Options options = new Options();
	options.inJustDecodeBounds = true;
	
	BitmapFactory.decodeFile(filePath, options);
	
	// Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = (int)FloatMath.floor(((float)height / reqHeight)+0.5f); //Math.round((float)height / (float)reqHeight);
        } else {
            inSampleSize = (int)FloatMath.floor(((float)width / reqWidth)+0.5f); //Math.round((float)width / (float)reqWidth);
        }
    }
    
    options.inSampleSize = inSampleSize;
    options.inJustDecodeBounds = false;
    	    
    return BitmapFactory.decodeFile(filePath, options);
}
 
源代码10 项目: Earlybird   文件: Cocos2dxBitmap.java
private static TextProperty computeTextProperty(final String string,
		final int width, final int height, final Paint paint) {
	final FontMetricsInt fm = paint.getFontMetricsInt();
	final int h = (int) Math.ceil(fm.bottom - fm.top);
	int maxContentWidth = 0;

	final String[] lines = Cocos2dxBitmap.splitString(string, width,
			height, paint);

	if (width != 0) {
		maxContentWidth = width;
	} else {
		/* Compute the max width. */
		int temp = 0;
		for (final String line : lines) {
			temp = (int) FloatMath.ceil(paint.measureText(line, 0,
					line.length()));
			if (temp > maxContentWidth) {
				maxContentWidth = temp;
			}
		}
	}

	return new TextProperty(maxContentWidth, h, lines);
}
 
源代码11 项目: android-discourse   文件: 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);
}
 
源代码12 项目: Atomic   文件: 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 = 0;
    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 项目: Example-of-Cocos2DX   文件: Cocos2dxBitmap.java
private static TextProperty computeTextProperty(final String string,
		final int width, final int height, final Paint paint) {
	final FontMetricsInt fm = paint.getFontMetricsInt();
	final int h = (int) Math.ceil(fm.bottom - fm.top);
	int maxContentWidth = 0;

	final String[] lines = Cocos2dxBitmap.splitString(string, width,
			height, paint);

	if (width != 0) {
		maxContentWidth = width;
	} else {
		/* Compute the max width. */
		int temp = 0;
		for (final String line : lines) {
			temp = (int) FloatMath.ceil(paint.measureText(line, 0,
					line.length()));
			if (temp > maxContentWidth) {
				maxContentWidth = temp;
			}
		}
	}

	return new TextProperty(maxContentWidth, h, lines);
}
 
源代码14 项目: AndroidCacheFoundation   文件: 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);
}
 
源代码15 项目: Huochexing12306   文件: Shake2Share.java
public void onSensorChanged(SensorEvent event) {
	long currentTime = System.currentTimeMillis();
	long diffTime = currentTime - mLastUpdateTime;
	if (diffTime > UPDATE_INTERVAL) {
		if(mLastUpdateTime != 0) {
			float x = event.values[0];
			float y = event.values[1];
			float z = event.values[2];
			float deltaX = x - mLastX;
			float deltaY = y - mLastY;
			float deltaZ = z - mLastZ;
			float delta = FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / diffTime * 10000;
			if (delta > SHAKE_THRESHOLD) {
				if (!shaken) {
					shaken = true;
					finish();
				}

				if (listener != null) {
					listener.onShake();
				}
			}
			mLastX = x;
			mLastY = y;
			mLastZ = z;
		}
		mLastUpdateTime = currentTime;
	}
}
 
源代码16 项目: PanoramaGL   文件: PLHotspot.java
/**calculate methods*/

protected PLPosition convertPitchAndYawToPosition(float pitch, float yaw)
{
	float r = this.getZ(), pr = (90.0f - pitch) * PLConstants.kToRadians, yr = -yaw * PLConstants.kToRadians;
	float x = r * FloatMath.sin(pr) * FloatMath.cos(yr);
	float y = r * FloatMath.sin(pr) * FloatMath.sin(yr);
	float z = r * FloatMath.cos(pr);
	return PLPosition.PLPositionMake(y, z, x);
}
 
源代码17 项目: MiBandDecompiled   文件: b.java
private float a(MotionEvent motionevent)
{
    if (motionevent.getPointerCount() < 2)
    {
        return 0.0F;
    } else
    {
        float f1 = motionevent.getX(0) - motionevent.getX(1);
        float f2 = motionevent.getY(0) - motionevent.getY(1);
        return FloatMath.sqrt(f1 * f1 + f2 * f2);
    }
}
 
源代码18 项目: PanoramaGL   文件: PLVector3.java
public void normalize()
{
	float magnitude = (x * x + y * y + z * z);
	if (magnitude == 0)
		return;
	float mult = (1.0f / FloatMath.sqrt(magnitude));            
	x *= mult;
	y *= mult;
	z *= mult;
}
 
源代码19 项目: Pi-Locker   文件: AmbilWarnaPrefWidgetView.java
public AmbilWarnaPrefWidgetView(Context context, AttributeSet attrs) {
	super(context, attrs);
	
	float density = context.getResources().getDisplayMetrics().density;
	rectSize = FloatMath.floor(24.f * density + 0.5f);
	strokeWidth = FloatMath.floor(1.f * density + 0.5f);

	paint = new Paint();
	paint.setColor(0xffffffff);
	paint.setStyle(Style.STROKE);
	paint.setStrokeWidth(strokeWidth);
}
 
源代码20 项目: BigApp_Discuz_Android   文件: PicViewer.java
/**
    * 两点的距离
    */
   @SuppressLint("FloatMath")
private float spacing(MotionEvent event) {
       float x = event.getX(0) - event.getX(1);
       float y = event.getY(0) - event.getY(1);
       return FloatMath.sqrt(x * x + y * y);
   }
 
public float getSegmentLength(final int pSegmentIndex) {
	final float[] coordinatesX = this.mXs;
	final float[] coordinatesY = this.mYs;

	final int nextSegmentIndex = pSegmentIndex + 1;

	final float dx = coordinatesX[pSegmentIndex] - coordinatesX[nextSegmentIndex];
	final float dy = coordinatesY[pSegmentIndex] - coordinatesY[nextSegmentIndex];

	return FloatMath.sqrt(dx * dx + dy * dy);
}
 
源代码22 项目: mobile-manager-tool   文件: MathUtils.java
/**
 * Rotates p1 around p2 by angle degrees.
 * @param p1
 * @param p2
 * @param angle
 */
public void rotate(PointF p1, PointF p2, float angle) {
	float px = p1.x;
	float py = p1.y;
	float ox = p2.x;
	float oy = p2.y;
	p1.x = (FloatMath.cos(angle) * (px-ox) - FloatMath.sin(angle) * (py-oy) + ox);
	p1.y = (FloatMath.sin(angle) * (px-ox) + FloatMath.cos(angle) * (py-oy) + oy);
}
 
源代码23 项目: AndroidLinkup   文件: Shake2Share.java
public void onSensorChanged(SensorEvent event) {
	long currentTime = System.currentTimeMillis();
	long diffTime = currentTime - mLastUpdateTime;
	if (diffTime > UPDATE_INTERVAL) {
		if(mLastUpdateTime != 0) {
			float x = event.values[0];
			float y = event.values[1];
			float z = event.values[2];
			float deltaX = x - mLastX;
			float deltaY = y - mLastY;
			float deltaZ = z - mLastZ;
			float delta = FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / diffTime * 10000;
			if (delta > SHAKE_THRESHOLD) { // 当加速度的差值大于指定的阈值,认为这是一个摇晃
				if (!shaken) {
					shaken = true;
					finish();
				}

				if (listener != null) {
					listener.onShake();
				}
			}
			mLastX = x;
			mLastY = y;
			mLastZ = z;
		}
		mLastUpdateTime = currentTime;
	}
}
 
源代码24 项目: android-open-project-demo   文件: BitmapUtils.java
public static BitmapSize getScaledSize(int originalWidth, int originalHeight, int numPixels) {
	float ratio = (float)originalWidth/originalHeight;
	
	int scaledHeight = (int)FloatMath.sqrt((float)numPixels/ratio);
	int scaledWidth = (int)(ratio * FloatMath.sqrt((float)numPixels/ratio));
			
	return new BitmapSize(scaledWidth, scaledHeight);
}
 
public static float[] rotateAroundCenter(final float[] pVertices, final float pRotation, final float pRotationCenterX, final float pRotationCenterY) {
	if(pRotation != 0) {
		final float rotationRad = MathUtils.degToRad(pRotation);
		final float sinRotationRad = FloatMath.sin(rotationRad);
		final float cosRotationInRad = FloatMath.cos(rotationRad);

		for(int i = pVertices.length - 2; i >= 0; i -= 2) {
			final float pX = pVertices[i];
			final float pY = pVertices[i + 1];
			pVertices[i] = pRotationCenterX + (cosRotationInRad * (pX - pRotationCenterX) - sinRotationRad * (pY - pRotationCenterY));
			pVertices[i + 1] = pRotationCenterY + (sinRotationRad * (pX - pRotationCenterX) + cosRotationInRad * (pY - pRotationCenterY));
		}
	}
	return pVertices;
}
 
源代码26 项目: geoar-app   文件: TriangleFeature.java
@Override
	public void onCreateInGLESThread() {
		
		final int numOfVertices = (numBorderPoints+2) * 3;
		final int numOfColors = (numBorderPoints+2) * 4;
//		final int numOfTexCoords = (numBorderPoints+2) * 2;
		
		final float[] vertices = new float[numOfVertices];
		final float[] colors = new float[numOfColors];
		final float[] normals = new float[numOfVertices];
//		final float[] texCoords = new float[numOfTexCoords];
		
		for (int i = 3, point = 0; i < numOfVertices; i += 3, point++) {
			float radians = (float) Math.toRadians(360.f - point * 360.f / numBorderPoints);
			vertices[i] 	= FloatMath.cos(radians);
			vertices[i + 2] = FloatMath.sin(radians);

			normals[i + 1] = 1.0f;
		}
		
		/** set color coordinates - first point is in the middle */
		colors[0] = 1.0f;
		colors[3] = 1.0f;
		for (int i = 4; i < numOfColors; i += 4) {
			colors[i] = 1.0f;
			colors[i + 3] = 0.1f;
		}
		
		setRenderObjectives(vertices, colors, normals, null);
	}
 
源代码27 项目: LB-Launcher   文件: BitmapUtils.java
public static int computeSampleSizeLarger(float scale) {
    int initialSize = (int) FloatMath.floor(1f / scale);
    if (initialSize <= 1) return 1;

    return initialSize <= 8
            ? Utils.prevPowerOf2(initialSize)
            : initialSize / 8 * 8;
}
 
源代码28 项目: PowerFileExplorer   文件: 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;
    }
}
 
源代码29 项目: PowerFileExplorer   文件: 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;
    }
}
 
源代码30 项目: letv   文件: Util.java
public static int dip2px(Context paramContext, float paramFloat) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) paramContext).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    return (int) FloatMath.ceil(localDisplayMetrics.density * paramFloat);
}