本文整理匯總了Java中android.util.FloatMath類的典型用法代碼示例。如果您正苦於以下問題:Java FloatMath類的具體用法?Java FloatMath怎麽用?Java FloatMath使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FloatMath類屬於android.util包,在下文中一共展示了FloatMath類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: measureWidth
import android.util.FloatMath; //導入依賴的package包/類
/**
* 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);
}
示例2: measureHeight
import android.util.FloatMath; //導入依賴的package包/類
/**
* 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: measureWidth
import android.util.FloatMath; //導入依賴的package包/類
private int measureWidth(int measureSpec) {
float result;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == 1073741824 || this.mViewPager == null) {
result = (float) specSize;
} else {
int count = this.mViewPager.getAdapter().getCount();
result = (((float) (getPaddingLeft() + getPaddingRight())) + (((float) count) * this
.mLineWidth)) + (((float) (count - 1)) * this.mGapWidth);
if (specMode == Integer.MIN_VALUE) {
result = Math.min(result, (float) specSize);
}
}
return (int) FloatMath.ceil(result);
}
示例4: loadImage
import android.util.FloatMath; //導入依賴的package包/類
public static Bitmap loadImage(Context context, int resId, int imgWidth, int imgHeight){
Options opts = new Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeResource(context.getResources(), resId, opts);
final int height = opts.outHeight;
final int width = opts.outWidth;
int inSampleSize = 1;
if (height > imgHeight || width > imgWidth) {
if (width > height) {
inSampleSize = (int) FloatMath
.floor(((float) height / imgHeight) + 0.5f); // Math.round((float)height
} else {
inSampleSize = (int) FloatMath
.floor(((float) width / imgWidth) + 0.5f); // Math.round((float)width
}
}
opts.inSampleSize = inSampleSize;
opts.inJustDecodeBounds = false;
System.out.println("得到的縮放比例為:" + inSampleSize);
Bitmap copyImg = BitmapFactory.decodeResource(context.getResources(), resId, opts);
return copyImg;
}
示例5: measureWidth
import android.util.FloatMath; //導入依賴的package包/類
/**
* 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);
}
示例6: invalidateAfterUpdate
import android.util.FloatMath; //導入依賴的package包/類
private void invalidateAfterUpdate() {
View view = mView.get();
if (view == null) {
return;
}
View parent = (View) view.getParent();
if (parent == null) {
return;
}
view.setAnimation(this);
final RectF after = mAfter;
computeRect(after, view);
after.union(mBefore);
parent.invalidate(
(int) FloatMath.floor(after.left),
(int) FloatMath.floor(after.top),
(int) FloatMath.ceil(after.right),
(int) FloatMath.ceil(after.bottom));
}
示例7: invalidateAfterUpdate
import android.util.FloatMath; //導入依賴的package包/類
private void invalidateAfterUpdate() {
View view = mView.get();
if (view == null) {
return;
}
View parent = (View)view.getParent();
if (parent == null) {
return;
}
view.setAnimation(this);
final RectF after = mAfter;
computeRect(after, view);
after.union(mBefore);
parent.invalidate(
(int) FloatMath.floor(after.left),
(int) FloatMath.floor(after.top),
(int) FloatMath.ceil(after.right),
(int) FloatMath.ceil(after.bottom));
}
示例8: createHexagon
import android.util.FloatMath; //導入依賴的package包/類
private Path createHexagon(int size, int centerX, int centerY) {
final float section = (float) (2.0 * Math.PI / numberOfSides);
int radius = size / 2;
Path polygonPath = temporal;
polygonPath.reset();
polygonPath.moveTo((centerX + radius * FloatMath.cos(0)),
(centerY + radius * FloatMath.sin(0)));
for (int i = 1; i < numberOfSides; i++) {
polygonPath.lineTo((centerX + radius * FloatMath.cos(section * i)),
(centerY + radius * FloatMath.sin(section * i)));
}
polygonPath.close();
return polygonPath;
}
示例9: getSampledBitmap
import android.util.FloatMath; //導入依賴的package包/類
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: createScaleAnimation
import android.util.FloatMath; //導入依賴的package包/類
public static Animation createScaleAnimation(View view, int parentWidth, int parentHeight,
int toX, int toY) {
// Difference in X and Y
final int diffX = toX - view.getLeft();
final int diffY = toY - view.getTop();
// Calculate actual distance using pythagors
float diffDistance = FloatMath.sqrt((toX * toX) + (toY * toY));
float parentDistance = FloatMath
.sqrt((parentWidth * parentWidth) + (parentHeight * parentHeight));
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0f, 1f, 0f, Animation.ABSOLUTE,
diffX,
Animation.ABSOLUTE, diffY);
scaleAnimation.setFillAfter(true);
scaleAnimation.setInterpolator(new DecelerateInterpolator());
scaleAnimation.setDuration(Math.round(diffDistance / parentDistance
* Constants.SCALE_ANIMATION_DURATION_FULL_DISTANCE));
return scaleAnimation;
}
示例11: measureHeight
import android.util.FloatMath; //導入依賴的package包/類
/**
* 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 = 0;
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);
}
示例12: onPull
import android.util.FloatMath; //導入依賴的package包/類
/**
* A view should call this when content is pulled away from an edge by the user.
* This will update the state of the current visual effect and its associated animation.
* The host view should always {@link android.view.View#invalidate()} after this
* and draw the results accordingly.
*
* @param deltaDistance Change in distance since the last call. Values may be 0 (no change) to
* 1.f (full length of the view) or negative values to express change
* back toward the edge reached to initiate the effect.
* @param displacement The displacement from the starting side of the effect of the point
* initiating the pull. In the case of touch this is the finger position.
* Values may be from 0-1.
*/
public void onPull(float deltaDistance, float displacement) {
final long now = AnimationUtils.currentAnimationTimeMillis();
mTargetDisplacement = displacement;
if (mState == STATE_PULL_DECAY && now - mStartTime < mDuration) {
//動畫未完成 return
return;
}
if (mState != STATE_PULL) {
mGlowScaleY = Math.max(PULL_GLOW_BEGIN, mGlowScaleY);
}
mState = STATE_PULL;
mStartTime = now;
mDuration = PULL_TIME;
mPullDistance += deltaDistance;
final float absdd = Math.abs(deltaDistance);
mGlowAlpha = mGlowAlphaStart = Math.min(MAX_ALPHA,
mGlowAlpha + (absdd * PULL_DISTANCE_ALPHA_GLOW_FACTOR));
if (mPullDistance == 0) {
mGlowScaleY = mGlowScaleYStart = 0;
} else {
final float scale = Math.max(0, 1 - 1 /
FloatMath.sqrt(Math.abs(mPullDistance) * mBounds.height()) - 0.3f) / 0.7f;
mGlowScaleY = mGlowScaleYStart = scale;
}
mGlowAlphaFinish = mGlowAlpha;
mGlowScaleYFinish = mGlowScaleY;
}
示例13: onSensorChanged
import android.util.FloatMath; //導入依賴的package包/類
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;
}
}
示例14: spacing
import android.util.FloatMath; //導入依賴的package包/類
/**
* 兩點的距離
*/
@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);
}
示例15: a
import android.util.FloatMath; //導入依賴的package包/類
private float a(MotionEvent motionEvent) {
if (motionEvent.getPointerCount() < 2) {
return 0.0f;
}
float x = motionEvent.getX(0) - motionEvent.getX(1);
float y = motionEvent.getY(0) - motionEvent.getY(1);
return FloatMath.sqrt((x * x) + (y * y));
}