Java 类android.support.v4.widget.TextViewCompat 实例源码
项目:mobile-store
文件:AppDetailsRecyclerViewAdapter.java
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, final String url, String formatArg) {
TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
if (formatArg == null) {
view.setText(resIdText);
} else {
String text = parent.getContext().getString(resIdText, formatArg);
view.setText(text);
}
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(view, resIdDrawable, 0, 0, 0);
parent.addView(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onLinkClicked(url);
}
});
}
项目:ScrollableNumberPicker
文件:ScrollableNumberPicker.java
private void initValueView() {
mValueTextView = (TextView) findViewById(R.id.text_value);
if (mValueTextAppearanceResId != INVALID_RES) {
TextViewCompat.setTextAppearance(mValueTextView, mValueTextAppearanceResId);
}
if (mValueTextColor != 0) {
mValueTextView.setTextColor(mValueTextColor);
}
if (mValueTextSize != INVALID_RES) {
mValueTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mValueTextSize);
}
LinearLayout.LayoutParams layoutParams = (LayoutParams) mValueTextView.getLayoutParams();
if (mOrientation == HORIZONTAL) {
layoutParams.setMargins(mValueMarginStart, 0, mValueMarginEnd, 0);
} else {
layoutParams.setMargins(0, mValueMarginStart, 0, mValueMarginEnd);
}
mValueTextView.setLayoutParams(layoutParams);
setValue();
}
项目:cwac-crossport
文件:TextInputLayout.java
void updateCounter(int length) {
boolean wasCounterOverflowed = mCounterOverflowed;
if (mCounterMaxLength == INVALID_MAX_LENGTH) {
mCounterView.setText(String.valueOf(length));
mCounterOverflowed = false;
} else {
mCounterOverflowed = length > mCounterMaxLength;
if (wasCounterOverflowed != mCounterOverflowed) {
TextViewCompat.setTextAppearance(mCounterView, mCounterOverflowed
? mCounterOverflowTextAppearance : mCounterTextAppearance);
}
mCounterView.setText(getContext().getString(R.string.character_counter_pattern,
length, mCounterMaxLength));
}
if (mEditText != null && wasCounterOverflowed != mCounterOverflowed) {
updateLabelState(false);
updateEditTextBackground();
}
}
项目:revolution-irc
文件:RecyclerViewScrollbar.java
public RecyclerViewScrollbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RecyclerViewScrollbar, defStyleAttr, 0);
mRecyclerViewId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_recyclerView, 0);
mScrollbarDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_scrollbarDrawable);
mLetterDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_letterDrawable);
int letterTextResId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_letterTextAppearance, 0);
mMinScrollbarHeight = ta.getDimensionPixelOffset(R.styleable.RecyclerViewScrollbar_minScrollbarHeight, 0);
ta.recycle();
mLetterView = new TextView(getContext());
mLetterView.setBackgroundDrawable(mLetterDrawable);
TextViewCompat.setTextAppearance(mLetterView, letterTextResId);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = GravityCompat.END;
mLetterView.setLayoutParams(params);
mLetterView.setGravity(Gravity.CENTER);
}
项目:kfaryarok-android
文件:MainActivity.java
@Override
public void onClickCard(View v, Update update) {
// if card is clicked and the line count is bigger than 3 (meaning it can be expanded/"dexpanded")
TextView tvText = v.findViewById(R.id.tv_updatecard_text);
View viewExpand = v.findViewById(R.id.view_updatecard_expand);
if (tvText.getLineCount() > 3) {
// if current max lines is 3, expand to 100 lines, and else "dexpand" back to 3
// it uses TextViewCompat instead of the given method for API 15 compatibility
if (TextViewCompat.getMaxLines(tvText) == 3) {
tvText.setMaxLines(100);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_up_grey_600_24dp);
} else {
tvText.setMaxLines(3);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_down_grey_600_24dp);
}
}
}
项目:CustomWidget
文件:DayView.java
/**
* 设置日期天数字体样式
*
* @param isSelected
*/
public void setDateTextAppearance(boolean isSelected) {
if (isSelected) {
if (itemStyle != null && itemStyle.getDateTextCheckedAppearance() > 0) {
TextViewCompat.setTextAppearance(dayText, itemStyle.getDateTextCheckedAppearance());
} else {
TextViewCompat.setTextAppearance(dayText, R.style.SelectedDayViewStyle);
}
} else {
if (itemStyle != null && itemStyle.getDateTextAppearance() > 0) {
TextViewCompat.setTextAppearance(dayText, itemStyle.getDateTextAppearance());
} else {
TextViewCompat.setTextAppearance(dayText, R.style.DefaultDayViewStyle);
}
}
}
项目:AndroidUtilCode
文件:ToastUtils.java
private static void show(final CharSequence text, final int duration) {
HANDLER.post(new Runnable() {
@Override
public void run() {
cancel();
sToast = Toast.makeText(Utils.getApp(), text, duration);
// solve the font of toast
TextView tvMessage = sToast.getView().findViewById(android.R.id.message);
TextViewCompat.setTextAppearance(tvMessage, android.R.style.TextAppearance);
tvMessage.setTextColor(msgColor);
sToast.setGravity(gravity, xOffset, yOffset);
setBg(tvMessage);
sToast.show();
}
});
}
项目:react-native-navigation
文件:CollapsingTextView.java
@SuppressLint("PrivateResource")
private void createDummyTextView(Context context) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), null,
R.styleable.Toolbar, R.attr.toolbarStyle, 0);
int titleTextAppearance =
a.getResourceId(R.styleable.Toolbar_titleTextAppearance, 0);
a.recycle();
dummy = new TextView(context);
dummy.setSingleLine();
dummy.setEllipsize(TextUtils.TruncateAt.END);
TextViewCompat.setTextAppearance(dummy, titleTextAppearance);
collapsedTextSize = dummy.getTextSize();
expendedTextSize = collapsedTextSize * TEXT_SCALE_FACTOR;
dummy.setTextSize(ViewUtils.convertPixelToSp(expendedTextSize));
dummy.setVisibility(INVISIBLE);
addView(dummy, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
项目:StraaS-android-sdk-sample
文件:StraasPlayerView.java
private void switchMode(boolean isLive) {
if (mIsLive == isLive) {
return;
}
mIsLive = isLive;
if (isLive) {
setContentSeekBarVisibility(GONE);
setSummaryViewerVisibility(INVISIBLE);
TextView live = (TextView) View.inflate(mThemeContext, R.layout.live_view, null);
Drawable drawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_live_player, null);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(live, drawable, null, null, null);
setCustomViewToColumn(live, CUSTOM_COLUMN_BOTTOM_LEFT);
} else {
setContentSeekBarVisibility(VISIBLE);
setSummaryViewerVisibility(VISIBLE);
removeViewFromCustomColumn(CUSTOM_COLUMN_BOTTOM_LEFT);
}
}
项目:xs-android-architecture
文件:SelectTextView.java
@Override
public void setSelected(boolean selected) {
if (selected){
TextViewCompat.setCompoundDrawablesRelative(
this,
null,
selectDrawable,
null,
null
);
this.setTextColor(selectColor);
}else {
TextViewCompat.setCompoundDrawablesRelative(
this,
null,
normalDrawable,
null,
null
);
this.setTextColor(normalColor);
}
super.setSelected(selected);
}
项目:PokeMVVM
文件:TableCardLayout.java
public void setData(Collection<Row> rows) {
gridLayout.removeViews(1, gridLayout.getChildCount() - 1);
for (Row row : rows) {
{
TextView nameView = new TextView(getContext());
TextViewCompat.setTextAppearance(nameView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
nameView.setText(row.name());
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
gridLayout.addView(nameView, params);
}
{
TextView valueView = new TextView(getContext());
TextViewCompat.setTextAppearance(valueView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
valueView.setText(row.value());
gridLayout.addView(valueView);
}
}
}
项目:BufferTextInputLayout
文件:BufferTextInputLayout.java
void updateCounter(int length) {
boolean wasCounterOverflowed = counterOverflowed;
if (counterMaxLength == INVALID_MAX_LENGTH) {
counterView.setText(String.valueOf(length));
counterOverflowed = false;
} else {
counterOverflowed = length > counterMaxLength;
if (wasCounterOverflowed != counterOverflowed) {
TextViewCompat.setTextAppearance(counterView, counterOverflowed ?
counterOverflowTextAppearance : counterTextAppearance);
}
setCounterText(length);
}
if (editText != null && wasCounterOverflowed != counterOverflowed) {
updateLabelState(false);
updateEditTextBackground();
}
}
项目:material-components-android
文件:TextInputLayoutTest.java
@UiThreadTest
@Test
public void testMaintainsStartEndCompoundDrawables() throws Throwable {
final Activity activity = activityTestRule.getActivity();
// Set a known set of test compound drawables on the EditText
final Drawable start = new ColorDrawable(Color.RED);
final Drawable top = new ColorDrawable(Color.GREEN);
final Drawable end = new ColorDrawable(Color.BLUE);
final Drawable bottom = new ColorDrawable(Color.BLACK);
final TextInputEditText editText = new TextInputEditText(activity);
TextViewCompat.setCompoundDrawablesRelative(editText, start, top, end, bottom);
// Now add the EditText to a TextInputLayout
TextInputLayout til = activity.findViewById(R.id.textinput_noedittext);
til.addView(editText);
// Finally assert that all of the drawables are untouched
final Drawable[] compoundDrawables = TextViewCompat.getCompoundDrawablesRelative(editText);
assertSame(start, compoundDrawables[0]);
assertSame(top, compoundDrawables[1]);
assertSame(end, compoundDrawables[2]);
assertSame(bottom, compoundDrawables[3]);
}
项目:material-components-android
文件:NavigationMenuItemView.java
@Override
public void setIcon(Drawable icon) {
if (icon != null) {
if (hasIconTintList) {
Drawable.ConstantState state = icon.getConstantState();
icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
DrawableCompat.setTintList(icon, iconTintList);
}
icon.setBounds(0, 0, iconSize, iconSize);
} else if (needsEmptyIcon) {
if (emptyDrawable == null) {
emptyDrawable =
ResourcesCompat.getDrawable(
getResources(), R.drawable.navigation_empty_icon, getContext().getTheme());
if (emptyDrawable != null) {
emptyDrawable.setBounds(0, 0, iconSize, iconSize);
}
}
icon = emptyDrawable;
}
TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null);
}
项目:material-components-android
文件:TextInputLayout.java
void setTextAppearanceCompatWithErrorFallback(TextView textView, @StyleRes int textAppearance) {
boolean useDefaultColor = false;
try {
TextViewCompat.setTextAppearance(textView, textAppearance);
if (VERSION.SDK_INT >= VERSION_CODES.M
&& textView.getTextColors().getDefaultColor() == Color.MAGENTA) {
// Caused by our theme not extending from Theme.Design*. On API 23 and
// above, unresolved theme attrs result in MAGENTA rather than an exception.
// Flag so that we use a decent default
useDefaultColor = true;
}
} catch (Exception e) {
// Caused by our theme not extending from Theme.Design*. Flag so that we use
// a decent default
useDefaultColor = true;
}
if (useDefaultColor) {
// Probably caused by our theme not extending from Theme.Design*. Instead
// we manually set something appropriate
TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat_Caption);
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.error_color_material));
}
}
项目:py-eventos-android
文件:TrackScheduleListFragment.java
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
Event event = DatabaseManager.toEvent(cursor, holder.event);
holder.event = event;
holder.time.setText(timeDateFormat.format(event.getStartTime()));
if ((currentTime != -1L) && event.isRunningAtTime(currentTime)) {
// Contrast colors for running event
holder.time.setBackgroundColor(timeRunningBackgroundColor);
holder.time.setTextColor(timeRunningForegroundColor);
} else {
// Normal colors
holder.time.setBackgroundColor(timeBackgroundColor);
holder.time.setTextColor(timeForegroundColor);
}
holder.title.setText(event.getTitle());
int bookmarkDrawable = DatabaseManager.toBookmarkStatus(cursor) ? R.drawable.ic_bookmark_grey600_24dp : 0;
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.title, 0, 0, bookmarkDrawable, 0);
String personsSummary = event.getPersonsSummary();
holder.persons.setText(personsSummary);
holder.persons.setVisibility(TextUtils.isEmpty(personsSummary) ? View.GONE : View.VISIBLE);
holder.room.setText(event.getRoomName());
}
项目:py-eventos-android
文件:MainActivity.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_main_menu, parent, false);
convertView.setOnClickListener(sectionClickListener);
}
Section section = getItem(position);
convertView.setSelected(section == currentSection);
TextView tv = (TextView) convertView.findViewById(R.id.section_text);
SpannableString sectionTitle = new SpannableString(getString(section.getTitleResId()));
Drawable sectionIcon = getResources().getDrawable(section.getIconResId());
if (section == currentSection) {
// Special color for the current section
sectionTitle.setSpan(new ForegroundColorSpan(currentSectionForegroundColor), 0, sectionTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// We need to mutate the drawable before applying the ColorFilter, or else all the similar drawable instances will be tinted.
sectionIcon.mutate().setColorFilter(currentSectionForegroundColor, PorterDuff.Mode.SRC_IN);
}
tv.setText(sectionTitle);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(tv, sectionIcon, null, null, null);
return convertView;
}
项目:py-eventos-android
文件:EventsAdapter.java
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
Event event = DatabaseManager.toEvent(cursor, holder.event);
holder.event = event;
holder.title.setText(event.getTitle());
int bookmarkDrawable = DatabaseManager.toBookmarkStatus(cursor) ? R.drawable.ic_bookmark_grey600_24dp : 0;
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.title, 0, 0, bookmarkDrawable, 0);
String personsSummary = event.getPersonsSummary();
holder.persons.setText(personsSummary);
holder.persons.setVisibility(TextUtils.isEmpty(personsSummary) ? View.GONE : View.VISIBLE);
holder.trackName.setText(event.getTrack().getName());
Date startTime = event.getStartTime();
Date endTime = event.getEndTime();
String startTimeString = (startTime != null) ? timeDateFormat.format(startTime) : "?";
String endTimeString = (endTime != null) ? timeDateFormat.format(endTime) : "?";
String details;
if (showDay) {
details = String.format("%1$s, %2$s ― %3$s | %4$s", event.getDay().getShortName(), startTimeString, endTimeString, event.getRoomName());
} else {
details = String.format("%1$s ― %2$s | %3$s", startTimeString, endTimeString, event.getRoomName());
}
holder.details.setText(details);
}
项目:JumpGo
文件:TabsFragment.java
private void updateViewHolderAppearance(@NonNull LightningViewHolder viewHolder, boolean isForeground) {
if (isForeground) {
Drawable foregroundDrawable = null;
if (!mDrawerTabs) {
foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap);
if (!mIsIncognito && mColorMode) {
foregroundDrawable.setColorFilter(mUiController.getUiColor(), PorterDuff.Mode.SRC_IN);
}
}
TextViewCompat.setTextAppearance(viewHolder.txtTitle, R.style.boldText);
if (!mDrawerTabs) {
DrawableUtils.setBackground(viewHolder.layout, foregroundDrawable);
}
} else {
TextViewCompat.setTextAppearance(viewHolder.txtTitle, R.style.normalText);
if (!mDrawerTabs) {
DrawableUtils.setBackground(viewHolder.layout, mBackgroundTabDrawable);
}
}
}
项目:SwipeRecyclerView
文件:SwipeMenuView.java
private TextView createTitle(SwipeMenuItem item) {
TextView textView = new TextView(getContext());
textView.setText(item.getText());
textView.setGravity(Gravity.CENTER);
int textSize = item.getTextSize();
if (textSize > 0)
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
ColorStateList textColor = item.getTitleColor();
if (textColor != null)
textView.setTextColor(textColor);
int textAppearance = item.getTextAppearance();
if (textAppearance != 0)
TextViewCompat.setTextAppearance(textView, textAppearance);
Typeface typeface = item.getTextTypeface();
if (typeface != null)
textView.setTypeface(typeface);
return textView;
}
项目:FMTech
文件:NavigationMenuItemView.java
public void setIcon(Drawable paramDrawable)
{
Drawable.ConstantState localConstantState;
if (paramDrawable != null)
{
localConstantState = paramDrawable.getConstantState();
if (localConstantState != null) {
break label52;
}
}
for (;;)
{
paramDrawable = DrawableCompat.wrap(paramDrawable).mutate();
paramDrawable.setBounds(0, 0, this.mIconSize, this.mIconSize);
DrawableCompat.setTintList(paramDrawable, this.mIconTintList);
TextViewCompat.setCompoundDrawablesRelative$16207aff(this.mTextView, paramDrawable);
return;
label52:
paramDrawable = localConstantState.newDrawable();
}
}
项目:JumpGo
文件:TabsFragment.java
private void updateViewHolderAppearance(@NonNull LightningViewHolder viewHolder, boolean isForeground) {
if (isForeground) {
Drawable foregroundDrawable = null;
if (!mDrawerTabs) {
foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap);
if (!mIsIncognito && mColorMode) {
foregroundDrawable.setColorFilter(mUiController.getUiColor(), PorterDuff.Mode.SRC_IN);
}
}
TextViewCompat.setTextAppearance(viewHolder.txtTitle, R.style.boldText);
if (!mDrawerTabs) {
DrawableUtils.setBackground(viewHolder.layout, foregroundDrawable);
}
} else {
TextViewCompat.setTextAppearance(viewHolder.txtTitle, R.style.normalText);
if (!mDrawerTabs) {
DrawableUtils.setBackground(viewHolder.layout, mBackgroundTabDrawable);
}
}
}
项目:edx-app-android
文件:AuthorLayoutViewHolder.java
public AuthorLayoutViewHolder(View itemView) {
profileRow = (ViewGroup) itemView;
profileImageView = (ImageView) itemView.findViewById(R.id.profile_image);
authorTextView = (TextView) itemView.findViewById(R.id.discussion_author_text_view);
dateTextView = (TextView) itemView.findViewById(R.id.discussion_date_text_view);
answerTextView = (TextView) itemView.findViewById(R.id.discussion_responses_answer_text_view);
final Context context = answerTextView.getContext();
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
answerTextView,
new IconDrawable(context, FontAwesomeIcons.fa_check_square_o)
.sizeRes(context, R.dimen.edx_base)
.colorRes(context, R.color.edx_success_accent),
null, null, null);
RoboGuice.getInjector(context).injectMembers(this);
}
项目:edx-app-android
文件:EditUserProfileFragment.java
private static TextView createField(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull final FormField field, @NonNull final String value, boolean readOnly, @NonNull View.OnClickListener onClickListener) {
final TextView textView = (TextView) inflater.inflate(R.layout.edit_user_profile_field, parent, false);
final SpannableString formattedValue = new SpannableString(value);
formattedValue.setSpan(new ForegroundColorSpan(parent.getResources().getColor(R.color.edx_brand_gray_base)), 0, formattedValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ResourceUtil.getFormattedString(parent.getResources(), R.string.edit_user_profile_field, new HashMap<String, CharSequence>() {{
put("label", field.getLabel());
put("value", formattedValue);
}}));
Context context = parent.getContext();
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
textView, null, null, new IconDrawable(context, FontAwesomeIcons.fa_angle_right)
.colorRes(context, R.color.edx_brand_gray_back)
.sizeDp(context, 24), null);
if (readOnly) {
textView.setEnabled(false);
textView.setBackgroundColor(textView.getResources().getColor(R.color.edx_brand_gray_x_back));
} else {
textView.setOnClickListener(onClickListener);
}
parent.addView(textView);
return textView;
}
项目:edx-app-android
文件:DiscussionPostsSpinnerAdapter.java
@Override
@NonNull
public View getDropDownView(int position, @Nullable View convertView,
@NonNull ViewGroup parent) {
TextView textView = initTextView(position, convertView, parent);
if (textView != convertView) {
Drawable icon = createIcon();
StateListDrawable statefulIcon = new StateListDrawable();
statefulIcon.setBounds(icon.getBounds());
statefulIcon.addState(ACTIVATED_STATE_SET, icon);
TextViewCompat.setCompoundDrawablesRelative(
textView, statefulIcon, null, null, null);
}
ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
if (layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT) {
layoutParams.height = spinner.getHeight() -
spinner.getPaddingTop() - spinner.getPaddingBottom();
}
return textView;
}
项目:iosched
文件:NavigationMenuItemView.java
@Override
public void setIcon(Drawable icon) {
if (icon != null) {
if (mHasIconTintList) {
Drawable.ConstantState state = icon.getConstantState();
icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
DrawableCompat.setTintList(icon, mIconTintList);
}
icon.setBounds(0, 0, mIconSize, mIconSize);
} else if (mNeedsEmptyIcon) {
if (mEmptyDrawable == null) {
mEmptyDrawable =
ResourcesCompat.getDrawable(
getResources(), R.drawable.navigation_empty_icon, getContext().getTheme());
if (mEmptyDrawable != null) {
mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize);
}
}
icon = mEmptyDrawable;
}
TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, null, null);
}
项目:iosched
文件:TextInputLayout.java
void updateCounter(int length) {
boolean wasCounterOverflowed = mCounterOverflowed;
if (mCounterMaxLength == INVALID_MAX_LENGTH) {
mCounterView.setText(String.valueOf(length));
mCounterOverflowed = false;
} else {
mCounterOverflowed = length > mCounterMaxLength;
if (wasCounterOverflowed != mCounterOverflowed) {
TextViewCompat.setTextAppearance(
mCounterView,
mCounterOverflowed ? mCounterOverflowTextAppearance : mCounterTextAppearance);
}
mCounterView.setText(
getContext().getString(R.string.character_counter_pattern, length, mCounterMaxLength));
}
if (mEditText != null && wasCounterOverflowed != mCounterOverflowed) {
updateLabelState(false);
updateEditTextBackground();
}
}
项目:fosdem-companion-android
文件:MainActivity.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_main_menu, parent, false);
convertView.setOnClickListener(sectionClickListener);
}
Section section = getItem(position);
convertView.setSelected(section == currentSection);
TextView tv = convertView.findViewById(R.id.section_text);
SpannableString sectionTitle = new SpannableString(getString(section.getTitleResId()));
Drawable sectionIcon = AppCompatResources.getDrawable(MainActivity.this, section.getIconResId());
if (section == currentSection) {
// Special color for the current section
sectionTitle.setSpan(new ForegroundColorSpan(currentSectionForegroundColor), 0, sectionTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// We need to mutate the drawable before applying the ColorFilter, or else all the similar drawable instances will be tinted.
sectionIcon.mutate().setColorFilter(currentSectionForegroundColor, PorterDuff.Mode.SRC_IN);
}
tv.setText(sectionTitle);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(tv, sectionIcon, null, null, null);
return convertView;
}
项目:fosdem-companion-android
文件:EventsAdapter.java
@Override
public void onBindViewHolder(ViewHolder holder, Cursor cursor) {
Context context = holder.itemView.getContext();
Event event = DatabaseManager.toEvent(cursor, holder.event);
holder.event = event;
holder.title.setText(event.getTitle());
boolean isBookmarked = DatabaseManager.toBookmarkStatus(cursor);
Drawable bookmarkDrawable = isBookmarked
? AppCompatResources.getDrawable(context, R.drawable.ic_bookmark_grey600_24dp)
: null;
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.title, null, null, bookmarkDrawable, null);
holder.title.setContentDescription(isBookmarked
? context.getString(R.string.in_bookmarks_content_description, event.getTitle())
: null
);
String personsSummary = event.getPersonsSummary();
holder.persons.setText(personsSummary);
holder.persons.setVisibility(TextUtils.isEmpty(personsSummary) ? View.GONE : View.VISIBLE);
Track track = event.getTrack();
holder.trackName.setText(track.getName());
holder.trackName.setTextColor(ContextCompat.getColor(context, track.getType().getColorResId()));
holder.trackName.setContentDescription(context.getString(R.string.track_content_description, track.getName()));
bindDetails(holder, event);
}
项目:commcare-android
文件:FormLayoutHelpers.java
public static boolean determineNumberOfValidGroupLines(FormEntryActivity activity,
Rect newRootViewDimensions,
boolean hasGroupLabel,
boolean shouldHideGroupLabel) {
FrameLayout header = (FrameLayout)activity.findViewById(R.id.form_entry_header);
TextView groupLabel = ((TextView)header.findViewById(R.id.form_entry_group_label));
int numberOfGroupLinesAllowed =
getNumberOfGroupLinesAllowed(groupLabel, newRootViewDimensions, activity);
if (TextViewCompat.getMaxLines(groupLabel) != numberOfGroupLinesAllowed) {
shouldHideGroupLabel = numberOfGroupLinesAllowed == 0;
groupLabel.setMaxLines(numberOfGroupLinesAllowed);
updateGroupViewVisibility(header, groupLabel, hasGroupLabel, shouldHideGroupLabel);
}
return shouldHideGroupLabel;
}
项目:fdroidclient
文件:AppDetailsRecyclerViewAdapter.java
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, final String url, String formatArg) {
TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
if (formatArg == null) {
view.setText(resIdText);
} else {
String text = parent.getContext().getString(resIdText, formatArg);
view.setText(text);
}
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(view, resIdDrawable, 0, 0, 0);
parent.addView(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onLinkClicked(url);
}
});
}
项目:FullSizePopupSpinner
文件:FullSizePopupSpinner.java
public void setItems(final int[] itemsTextsResIds, final int[] itemsIconsResIds) {
mItemsTextsResIds = itemsTextsResIds;
mItemsIconsResIds = itemsIconsResIds;
if (mItemsTextsResIds != null && mSelectedItemPosition >= 0 && mSelectedItemPosition < mItemsTextsResIds.length)
setText(mItemsTextsResIds[mSelectedItemPosition]);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this, null, null, isPopupShown() ? mOpenedDrawable : mClosedDrawable, null);
}
项目:FullSizePopupSpinner
文件:FullSizePopupSpinner.java
public void setSelectedItemPosition(final int selectedItemPosition) {
int lastSelectedItemPosition = mSelectedItemPosition;
mSelectedItemPosition = selectedItemPosition;
final String itemText = mItemsTextsResIds != null && mSelectedItemPosition >= 0 && mSelectedItemPosition < mItemsTextsResIds.length ?
getResources().getString(mItemsTextsResIds[mSelectedItemPosition]) : null;
setText(itemText);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(FullSizePopupSpinner.this, null, null, mClosedDrawable, null);
if (mOnItemSelectedListener != null)
mOnItemSelectedListener.onItemSelected(FullSizePopupSpinner.this, selectedItemPosition, itemText, lastSelectedItemPosition);
}
项目:GitHub
文件:ToastUtils.java
private static void show(final CharSequence text, final int duration) {
HANDLER.post(new Runnable() {
@Override
public void run() {
cancel();
sToast = Toast.makeText(Utils.getApp(), text, duration);
// solve the font of toast
TextView tvMessage = (TextView) sToast.getView().findViewById(android.R.id.message);
TextViewCompat.setTextAppearance(tvMessage, android.R.style.TextAppearance);
tvMessage.setTextColor(msgColor);
setBgAndGravity();
sToast.show();
}
});
}
项目:mapbox-navigation-android
文件:InstructionView.java
/**
* Called after we bind the views, this will allow the step instruction {@link TextView}
* to automatically re-size based on the length of the text.
*/
private void initInstructionAutoSize() {
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingPrimaryText,
26, 30, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingSecondaryText,
20, 26, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingDistanceText,
16, 20, 1, TypedValue.COMPLEX_UNIT_SP);
}
项目:mapbox-navigation-android
文件:InstructionViewHolder.java
/**
* Called after we bind the views, this will allow the step instruction {@link TextView}
* to automatically re-size based on the length of the text.
*/
private void initInstructionAutoSize() {
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(stepPrimaryText,
26, 28, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(stepSecondaryText,
20, 26, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(stepDistanceText,
16, 20, 1, TypedValue.COMPLEX_UNIT_SP);
}
项目:mobile-store
文件:AppDetailsRecyclerViewAdapter.java
NoVersionsViewHolder(View view) {
super(view);
headerView = (TextView) view.findViewById(R.id.information);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_access_time_24dp_grey600, 0, 0, 0);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
explainIncompatibleVersions();
}
});
}
项目:cwac-crossport
文件:TextInputLayout.java
/**
* Sets the text color and size for the error message from the specified
* TextAppearance resource.
*
* @attr ref android.support.design.R.styleable#TextInputLayout_errorTextAppearance
*/
public void setErrorTextAppearance(@StyleRes int resId) {
mErrorTextAppearance = resId;
if (mErrorView != null) {
TextViewCompat.setTextAppearance(mErrorView, resId);
}
}
项目:cwac-crossport
文件:TextInputLayout.java
/**
* Whether the character counter functionality is enabled or not in this layout.
*
* @attr ref android.support.design.R.styleable#TextInputLayout_counterEnabled
*/
public void setCounterEnabled(boolean enabled) {
if (mCounterEnabled != enabled) {
if (enabled) {
mCounterView = new TextView(getContext());
mCounterView.setId(R.id.textinput_counter);
if (mTypeface != null) {
mCounterView.setTypeface(mTypeface);
}
mCounterView.setMaxLines(1);
try {
TextViewCompat.setTextAppearance(mCounterView, mCounterTextAppearance);
} catch (Exception e) {
// Probably caused by our theme not extending from Theme.Design*. Instead
// we manually set something appropriate
TextViewCompat.setTextAppearance(
mCounterView, android.R.style.TextAppearance_Material_Caption);
mCounterView.setTextColor(
ContextCompat.getColor(getContext(), R.color.design_textinput_error_color_light));
}
addIndicator(mCounterView, -1);
if (mEditText == null) {
updateCounter(0);
} else {
updateCounter(mEditText.getText().length());
}
} else {
removeIndicator(mCounterView);
mCounterView = null;
}
mCounterEnabled = enabled;
}
}
项目:revolution-irc
文件:ThemedTextView.java
public static void setupTextColor(TextView view, AttributeSet attrs) {
StyledAttributesHelper r = StyledAttributesHelper.obtainStyledAttributes(view.getContext(), attrs, THEME_ATTRS);
int colorResId = r.getResourceId(android.R.attr.textColor, 0);
if (colorResId == 0) {
int appearanceRes = r.getResourceId(android.R.attr.textAppearance, 0);
if (appearanceRes != 0) {
StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(
view.getContext(), appearanceRes, new int[] { android.R.attr.textColor });
colorResId = ta.getResourceId(android.R.attr.textColor, 0);
ta.recycle();
}
}
if (colorResId == R.color.colorPrimary)
view.setTextColor(ThemeHelper.getPrimaryColor(view.getContext()));
else if (colorResId == R.color.colorAccent)
view.setTextColor(ThemeHelper.getAccentColor(view.getContext()));
colorResId = r.getResourceId(android.R.attr.textColorLink, 0);
if (colorResId == R.color.colorAccent)
view.setLinkTextColor(ThemeHelper.getAccentColor(view.getContext()));
Drawable[] drawables = TextViewCompat.getCompoundDrawablesRelative(view);
boolean hasChange = false;
for (int i = 0; i < 4; i++) {
Drawable newDrawable = tintDrawable(view.getContext(), r, DRAWABLE_ATTRS[i], drawables[i]);
if (newDrawable != drawables[i]) {
drawables[i] = newDrawable;
hasChange = true;
}
}
if (hasChange)
TextViewCompat.setCompoundDrawablesRelative(view, drawables[0], drawables[1], drawables[2], drawables[3]);
r.recycle();
}