本文整理汇总了Java中android.util.FloatMath.ceil方法的典型用法代码示例。如果您正苦于以下问题:Java FloatMath.ceil方法的具体用法?Java FloatMath.ceil怎么用?Java FloatMath.ceil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.FloatMath
的用法示例。
在下文中一共展示了FloatMath.ceil方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例5: 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);
}
示例6: measureHeight
import android.util.FloatMath; //导入方法依赖的package包/类
private int measureHeight(int measureSpec) {
float result;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == 1073741824) {
result = (float) specSize;
} else {
result = (this.mPaintSelected.getStrokeWidth() + ((float) getPaddingTop())) + (
(float) getPaddingBottom());
if (specMode == Integer.MIN_VALUE) {
result = Math.min(result, (float) specSize);
}
}
return (int) FloatMath.ceil(result);
}
示例7: loadThumbnail
import android.util.FloatMath; //导入方法依赖的package包/类
public synchronized Bitmap loadThumbnail() {
BitmapFactory.Options options = decodeImageBounds(file);
int w = options.outWidth;
int h = options.outHeight;
if (w < 0) {
return null;
}
// Target max dimensions: 150 x 100 (w x h)
float divider = Math.max(w / 150f, h / 100f);
options.inJustDecodeBounds = false;
// Use inSampleSize to get close to target dimension
if (divider >= 16) {
options.inSampleSize = 16;
} else if (divider >= 8) {
options.inSampleSize = 8;
} else if (divider >= 4) {
options.inSampleSize = 4;
} else if (divider >= 2) {
options.inSampleSize = 2;
}
// Match the target dimension by scaling
divider = divider / options.inSampleSize;
options.inScaled = true;
options.inTargetDensity = getResources().getDisplayMetrics().densityDpi;
options.inDensity = (int) FloatMath.ceil(options.inTargetDensity * divider);
return BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
示例8: dip2px
import android.util.FloatMath; //导入方法依赖的package包/类
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);
}
示例9: limitImageSize
import android.util.FloatMath; //导入方法依赖的package包/类
/**
* Limits the given file to fit in the memory of this device. If the image is
* larger, resizes it and stores it into a temporary file on SD card.
*
* @param origImage Image file to be checked
* @return the original file, if it was within limits, otherwise the new file
*/
private File limitImageSize(File origImage) {
BitmapFactory.Options options = decodeImageBounds(origImage);
int pixelCount = options.outWidth * options.outHeight;
// If image is small enough, return original file reference
int maxPixels = MemoryUtil.getMaxImagePixelCount(getApplication());
if (pixelCount <= maxPixels) {
// Selected image is small enough, not resizing
return origImage;
}
// Need to resize image, but first verify target directory exists
if (!FileUtil.verifyImageDir()) {
Log.e(CustomMaps.LOG_TAG, "Failed to create directory for resized image file " +
FileUtil.getTmpImagePath());
// Attempt to use full size image
return origImage;
}
// Prepare factory options to scale image into suitable size
options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
// Compute necessary scaling factor
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
options.inTargetDensity = metrics.densityDpi;
options.inDensity =
(int) FloatMath.ceil(FloatMath.sqrt(pixelCount / (float) maxPixels) * metrics.densityDpi);
options.inScaled = true;
// Garbage collect to maximize available memory for resizing
System.gc();
Bitmap image = null;
try {
// Load resized image (may throw OutOfMemoryError)
image = BitmapFactory.decodeFile(origImage.getAbsolutePath(), options);
if (image == null) {
Log.e(CustomMaps.LOG_TAG, String.format("Failed to read image: %s, size: %.2f MP",
origImage.getAbsolutePath(), pixelCount / 1e6f));
return origImage;
}
// Successfully resized, save into temporary file
FileOutputStream out = new FileOutputStream(FileUtil.getTmpImageFile());
image.compress(Bitmap.CompressFormat.JPEG, 85, out);
out.close();
// Release memory used by the image
image.recycle();
image = null;
// Copy orientation information, and return resized image
File resizedImage = FileUtil.getTmpImageFile();
copyImageOrientation(origImage, resizedImage);
return resizedImage;
} catch (OutOfMemoryError err) {
Log.e(CustomMaps.LOG_TAG, "Failed to resize large image", err);
} catch (IOException ex) {
Log.e(CustomMaps.LOG_TAG, "Failed to save resized image", ex);
} finally {
if (image != null && !image.isRecycled()) {
image.recycle();
}
}
// Resize or save image failed, return full size image
return origImage;
}