本文整理汇总了Java中android.util.TypedValue.COMPLEX_UNIT_PX属性的典型用法代码示例。如果您正苦于以下问题:Java TypedValue.COMPLEX_UNIT_PX属性的具体用法?Java TypedValue.COMPLEX_UNIT_PX怎么用?Java TypedValue.COMPLEX_UNIT_PX使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.util.TypedValue
的用法示例。
在下文中一共展示了TypedValue.COMPLEX_UNIT_PX属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue</p>
*
* @param unit 单位
* @param value 值
* @param metrics DisplayMetrics
* @return 转换结果
*/
public static float applyDimension(final int unit, final float value, final DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例2: setText
@Override public void setText(@Nullable CharSequence text, BufferType type) {
EmojiProvider provider = EmojiProvider.getInstance(getContext());
EmojiParser.CandidateList candidates = provider.getCandidates(text);
if (scaleEmojis && candidates != null && candidates.allEmojis) {
int emojis = candidates.size();
float scale = 1.0f;
if (emojis <= 8) scale += 0.25f;
if (emojis <= 6) scale += 0.25f;
if (emojis <= 4) scale += 0.25f;
if (emojis <= 2) scale += 0.25f;
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize * scale);
} else if (scaleEmojis) {
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize);
}
if (useSystemEmoji()) {
super.setText(text, type);
return;
}
source = EmojiProvider.getInstance(getContext()).emojify(candidates, text, this);
setTextEllipsized(source);
}
示例3: adjustTextSize
private void adjustTextSize(String string) {
if (!mInitiallized) {
return;
}
int startSize = (int) mMinTextSize;
int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom()
- getCompoundPaddingTop();
mWidthLimit = getMeasuredWidth() - getCompoundPaddingLeft()
- getCompoundPaddingRight();
mAvailableSpaceRect.right = mWidthLimit;
mAvailableSpaceRect.bottom = heightLimit;
super.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
efficientTextSizeSearch(startSize, (int) mMaxTextSize,
mSizeTester, mAvailableSpaceRect));
}
示例4: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue</p>
*
* @param unit 单位
* @param value 值
* @param metrics DisplayMetrics
* @return 转换结果
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例5: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例6: getUnit
@PixelValue.PixelUnit
private static int getUnit(String s) throws ParametersParseException {
switch (s.toLowerCase()) {
default:
throw new ParametersParseException("Unknown unit " + s);
case "px":
return TypedValue.COMPLEX_UNIT_PX;
case "dp":
case "dip":
return TypedValue.COMPLEX_UNIT_DIP;
case "sp":
return TypedValue.COMPLEX_UNIT_SP;
case "em":
return PixelValue.EM;
}
}
示例7: adjustTextSize
private void adjustTextSize(String string) {
if (!mInitiallized) {
return;
}
int startSize = (int) mMinTextSize;
int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom()
- getCompoundPaddingTop();
mWidthLimit = getMeasuredWidth() - getCompoundPaddingLeft()
- getCompoundPaddingRight();
mAvailableSpaceRect.right = mWidthLimit;
mAvailableSpaceRect.bottom = heightLimit;
super.setTextSize(TypedValue.COMPLEX_UNIT_PX,
efficientTextSizeSearch(startSize,
(int) mMaxTextSize,
mSizeTester,
mAvailableSpaceRect));
}
示例8: resetTextSize
/**
* Reset the text to the original size
*/
public void resetTextSize() {
if (mTextSize > 0) {
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
mMaxTextSize = mTextSize;
}
}
示例9: resetTextSize
/**
* Reset the text to the original size
*/
public void resetTextSize() {
if (mTextSize > 0) {
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
mMaxTextSize = mTextSize;
}
}
示例10: PixelValue
public PixelValue(float value, @PixelUnit int unit) {
if (unit == EM) {
this.value = value * 16;
this.unit = TypedValue.COMPLEX_UNIT_PX;
} else {
this.value = value;
this.unit = unit;
}
}
示例11: getPxValue
public final float getPxValue() {
switch (unit) {
case EM:
return this.value / 16.f;
case TypedValue.COMPLEX_UNIT_PX:
return this.value;
case TypedValue.COMPLEX_UNIT_SP:
return ParametersUtils.spToPx(this.value);
case TypedValue.COMPLEX_UNIT_DIP:
return ParametersUtils.dpToPx(this.value);
default:
return value;
}
}
示例12: toPixel
@NonNull
public static PixelValue toPixel(@NonNull Object object) throws ParametersParseException {
int unit = TypedValue.COMPLEX_UNIT_PX;
if (object instanceof String) {
String string = (String) object;
if (string.length() == 0 || (string.equals("@"))) {
throw new ParametersParseException("wrong when parse pixel");
}
if (string.charAt(0) == '@' && string.length() > 1) {
String resId = string.substring(1);
Context context = ContextProvider.getApplicationRef();
if (context != null) {
float size = ResourceUtils.getDimension(resId, ContextProvider
.getApplicationRef());
return new PixelValue(size);
} else {
throw new ParametersParseException("wrong when parse pixel");
}
}
StringBuilder unitString = new StringBuilder(5);
int i = string.length() - 1;
for (; i > 0; i--) {
char c = string.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
unitString.append(c);
} else {
break;
}
}
unit = getUnit(unitString.reverse().toString());
float value = 0;
value = toFloat(string.substring(0, i + 1));
return new PixelValue(value, unit);
} else {
return new PixelValue(toFloat(object), unit);
}
}
示例13: resizeText
/**
* Resizes this view's text size with respect to its width and height
* (minus padding).
*/
private void resizeText() {
final int availableHeightPixels = getHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
final int availableWidthPixels = getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
final CharSequence text = getText();
// Safety check
// (Do not resize if the view does not have dimensions or if there is no text)
if (text == null
|| text.length() <= 0
|| availableHeightPixels <= 0
|| availableWidthPixels <= 0
|| mMaxTextSizePixels <= 0) {
return;
}
float targetTextSizePixels = mMaxTextSizePixels;
int targetTextHeightPixels = getTextHeightPixels(text, availableWidthPixels, targetTextSizePixels);
// Until we either fit within our TextView
// or we have reached our minimum text size,
// incrementally try smaller sizes
while (targetTextHeightPixels > availableHeightPixels
&& targetTextSizePixels > mMinTextSizePixels) {
targetTextSizePixels = Math.max(
targetTextSizePixels - 2,
mMinTextSizePixels);
targetTextHeightPixels = getTextHeightPixels(
text,
availableWidthPixels,
targetTextSizePixels);
}
// If we have reached our minimum text size and the text still doesn't fit,
// append an ellipsis
// (NOTE: Auto-ellipsize doesn't work hence why we have to do it here)
// depending on the value of getEllipsize())
if (getEllipsize() != null
&& targetTextSizePixels == mMinTextSizePixels
&& targetTextHeightPixels > availableHeightPixels) {
// Make a copy of the original TextPaint object for measuring
TextPaint textPaintCopy = new TextPaint(getPaint());
textPaintCopy.setTextSize(targetTextSizePixels);
// Measure using a StaticLayout instance
StaticLayout staticLayout = new StaticLayout(
text,
textPaintCopy,
availableWidthPixels,
Layout.Alignment.ALIGN_NORMAL,
mLineSpacingMultiplier,
mLineSpacingExtra,
false);
// Check that we have a least one line of rendered text
if (staticLayout.getLineCount() > 0) {
// Since the line at the specific vertical position would be cut off,
// we must trim up to the previous line and add an ellipsis
int lastLine = staticLayout.getLineForVertical(availableHeightPixels) - 1;
if (lastLine >= 0) {
int startOffset = staticLayout.getLineStart(lastLine);
int endOffset = staticLayout.getLineEnd(lastLine);
float lineWidthPixels = staticLayout.getLineWidth(lastLine);
float ellipseWidth = textPaintCopy.measureText(mEllipsis);
// Trim characters off until we have enough room to draw the ellipsis
while (availableWidthPixels < lineWidthPixels + ellipseWidth) {
endOffset--;
lineWidthPixels = textPaintCopy.measureText(
text.subSequence(startOffset, endOffset + 1).toString());
}
setText(text.subSequence(0, endOffset) + mEllipsis);
}
}
}
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, targetTextSizePixels);
// Some devices try to auto adjust line spacing, so force default line spacing
super.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
}
示例14: fromPx
public Builder fromPx(float fromSize) { unit = TypedValue.COMPLEX_UNIT_PX; return from(fromSize); }
示例15: toPx
public Builder toPx(float toSize) { unit = TypedValue.COMPLEX_UNIT_PX; return to(toSize); }