本文整理汇总了Java中android.support.v4.text.BidiFormatter类的典型用法代码示例。如果您正苦于以下问题:Java BidiFormatter类的具体用法?Java BidiFormatter怎么用?Java BidiFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BidiFormatter类属于android.support.v4.text包,在下文中一共展示了BidiFormatter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppInfo
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
public static Single<AppInfo> getAppInfo(final Context context, String pkgName) {
return SingleJust.just(pkgName).map(new Function<String, AppInfo>() {
@Override
public AppInfo apply(String s) throws Exception {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(s, 0);
AppInfo info = new AppInfo();
info.packageName = packageInfo.packageName;
info.appName = BidiFormatter.getInstance()
.unicodeWrap(packageInfo.applicationInfo.loadLabel(packageManager)).toString();
info.time = Math.max(packageInfo.lastUpdateTime, packageInfo.firstInstallTime);
info.installTime = packageInfo.firstInstallTime;
info.updateTime = packageInfo.lastUpdateTime;
info.applicationInfo = packageInfo.applicationInfo;
LocalImageLoader.initAdd(context, info);
return info;
}
});
}
示例2: getArticleAge
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
private static String getArticleAge(SnippetArticle article) {
if (article.mPublishTimestampMilliseconds == 0) return "";
// DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.getDefault(). If this
// has never been called before it loads the current time zone from disk. In most likelihood
// this will have been called previously and the current time zone will have been cached,
// but in some cases (eg instrumentation tests) it will cause a strict mode violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
CharSequence relativeTimeSpan;
try {
long time = SystemClock.elapsedRealtime();
relativeTimeSpan =
DateUtils.getRelativeTimeSpanString(article.mPublishTimestampMilliseconds,
System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildTime",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// We add a dash before the elapsed time, e.g. " - 14 minutes ago".
return String.format(ARTICLE_AGE_FORMAT_STRING,
BidiFormatter.getInstance().unicodeWrap(relativeTimeSpan));
}
示例3: onCreate
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bidiformater_support);
String formattedText = String.format(text, phone);
TextView tv_sample = (TextView) findViewById(R.id.textview_without_bidiformatter);
tv_sample.setText(formattedText);
TextView tv_bidiformatter = (TextView) findViewById(R.id.textview_with_bidiformatter);
String wrappedPhone = BidiFormatter.getInstance(true /* rtlContext */).unicodeWrap(phone);
formattedText = String.format(text, wrappedPhone);
tv_bidiformatter.setText(formattedText);
}
示例4: updateStorageUsage
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
public void updateStorageUsage(long totalMemory, long lowMemory, long medMemory,
long highMemory) {
Context context = mColorBar.getContext();
BidiFormatter bidiFormatter = BidiFormatter.getInstance();
String sizeStr = bidiFormatter.unicodeWrap(
Formatter.formatShortFileSize(context, lowMemory));
mFreeSizeText.setText(context.getString(R.string.apps_list_header_memory, sizeStr));
sizeStr = bidiFormatter.unicodeWrap(
Formatter.formatShortFileSize(context, medMemory));
mCacheSizeText.setText(context.getString(R.string.apps_list_header_memory, sizeStr));
sizeStr = bidiFormatter.unicodeWrap(
Formatter.formatShortFileSize(context, highMemory));
mSystemSizeText.setText(context.getString(R.string.apps_list_header_memory, sizeStr));
mColorBar.setRatios((float) highMemory / (float) totalMemory,
(float) medMemory / (float) totalMemory,
(float) lowMemory / (float) totalMemory);
}
示例5: setChipText
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
public void setChipText(@Nullable CharSequence chipText) {
if (this.chipText != chipText) {
this.chipText = BidiFormatter.getInstance().unicodeWrap(chipText);
chipTextWidthDirty = true;
invalidateSelf();
onSizeChange();
}
}
示例6: onBindViewHolder
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
public void onBindViewHolder(SnippetArticle article) {
super.onBindViewHolder();
// No longer listen for offline status changes to the old article.
if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null);
mArticle = article;
updateLayout();
mHeadlineTextView.setText(mArticle.mTitle);
// DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.getDefault(). If this
// has never been called before it loads the current time zone from disk. In most likelihood
// this will have been called previously and the current time zone will have been cached,
// but in some cases (eg instrumentation tests) it will cause a strict mode violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
long time = SystemClock.elapsedRealtime();
CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString(
mArticle.mPublishTimestampMilliseconds, System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS);
RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildTime",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
// We format the publisher here so that having a publisher name in an RTL language
// doesn't mess up the formatting on an LTR device and vice versa.
String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING,
BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher), relativeTimeSpan);
mPublisherTextView.setText(publisherAttribution);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// The favicon of the publisher should match the TextView height.
int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mPublisherTextView.measure(widthSpec, heightSpec);
mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight();
mArticleSnippetTextView.setText(mArticle.mPreviewText);
// If there's still a pending thumbnail fetch, cancel it.
cancelImageFetch();
// If the article has a thumbnail already, reuse it. Otherwise start a fetch.
// mThumbnailView's visibility is modified in updateLayout().
if (mThumbnailView.getVisibility() == View.VISIBLE) {
if (mArticle.getThumbnailBitmap() != null) {
mThumbnailView.setImageBitmap(mArticle.getThumbnailBitmap());
} else {
mThumbnailView.setImageResource(R.drawable.ic_snippet_thumbnail_placeholder);
mImageCallback = new FetchImageCallback(this, mArticle);
mNewTabPageManager.getSuggestionsSource()
.fetchSuggestionImage(mArticle, mImageCallback);
}
}
// Set the favicon of the publisher.
try {
fetchFaviconFromLocalCache(new URI(mArticle.mUrl), true);
} catch (URISyntaxException e) {
setDefaultFaviconOnView();
}
mOfflineBadge.setVisibility(View.GONE);
if (SnippetsConfig.isOfflineBadgeEnabled()) {
Runnable offlineChecker = new Runnable() {
@Override
public void run() {
if (mArticle.getOfflinePageOfflineId() != null || mArticle.mIsDownloadedAsset) {
mOfflineBadge.setVisibility(View.VISIBLE);
}
}
};
mArticle.setOfflineStatusChangeRunnable(offlineChecker);
offlineChecker.run();
}
mRecyclerView.onSnippetBound(itemView);
}
示例7: getPublisherString
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
private static String getPublisherString(SnippetArticle article) {
// We format the publisher here so that having a publisher name in an RTL language
// doesn't mess up the formatting on an LTR device and vice versa.
return BidiFormatter.getInstance().unicodeWrap(article.mPublisher);
}
示例8: onMeasure
import android.support.v4.text.BidiFormatter; //导入依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Rect bounds = new Rect();
Drawable background = getBackground();
if (background != null) {
background.getPadding(bounds);
}
int wMode = MeasureSpec.getMode(widthMeasureSpec);
int maxW = MeasureSpec.getSize(widthMeasureSpec) - bounds.left - bounds.right;
TextView messageView = (TextView) getChildAt(0);
messageView.measure(MeasureSpec.makeMeasureSpec(maxW, wMode), heightMeasureSpec);
View timeView = getChildAt(1);
timeView.measure(MeasureSpec.makeMeasureSpec(maxW, wMode), heightMeasureSpec);
Layout textLayout = messageView.getLayout();
int contentW = messageView.getMeasuredWidth();
int timeW = timeView.getMeasuredWidth();
boolean isRtl = BidiFormatter.getInstance().isRtl(messageView.getText().toString());
if (messageView.getLayout().getLineCount() < 5 && !isRtl) {
contentW = 0;
for (int i = 0; i < textLayout.getLineCount(); i++) {
contentW = Math.max(contentW, (int) textLayout.getLineWidth(i));
}
}
int lastLineW = (int) textLayout.getLineWidth(textLayout.getLineCount() - 1);
if (isRtl) {
lastLineW = contentW;
}
int fullContentW, fullContentH;
if (isRtl) {
fullContentW = contentW;
fullContentH = messageView.getMeasuredHeight() + timeView.getMeasuredHeight();
} else {
if (lastLineW + timeW < contentW) {
// Nothing to do
fullContentW = contentW;
fullContentH = messageView.getMeasuredHeight();
} else if (lastLineW + timeW < maxW) {
fullContentW = lastLineW + timeW;
fullContentH = messageView.getMeasuredHeight();
} else {
fullContentW = contentW;
fullContentH = messageView.getMeasuredHeight() + timeView.getMeasuredHeight();
}
}
setMeasuredDimension(fullContentW + bounds.left + bounds.right, fullContentH + bounds.top + bounds.bottom);
}