/** * Adds a rectangular outline to a view. This can be useful when you want to add a shadow * to a transparent view. See b/16856049. * @param view view that the outline is added to * @param res The resources file. */ public static void addRectangularOutlineProvider(View view, Resources res) { if (CompatUtils.isLollipopCompatible()) { view.setOutlineProvider(RECT_OUTLINE_PROVIDER); } }
/** * Return {@code true} if a contact ID is from the contacts provider on the enterprise profile. */ public static boolean isEnterpriseContactId(long contactId) { if (CompatUtils.isLollipopCompatible()) { return Contacts.isEnterpriseContactId(contactId); } else { // copied from ContactsContract.Contacts.isEnterpriseContactId return (contactId >= ENTERPRISE_CONTACT_ID_BASE) && (contactId < ContactsContract.Profile.MIN_ID); } } }
/** * Configures the floating action button, clipping it to a circle and setting its translation z. * @param view The float action button's view. * @param res The resources file. */ public static void setupFloatingActionButton(View view, Resources res) { if (CompatUtils.isLollipopCompatible()) { view.setOutlineProvider(OVAL_OUTLINE_PROVIDER); view.setTranslationZ( res.getDimensionPixelSize(R.dimen.floating_action_button_translation_z)); } }
public static String formatNumber( String phoneNumber, String phoneNumberE164, String defaultCountryIso) { if (CompatUtils.isLollipopCompatible()) { return PhoneNumberUtils.formatNumber(phoneNumber, phoneNumberE164, defaultCountryIso); } else { // This method was deprecated in API level 21, so it's only used on pre-L SDKs. return PhoneNumberUtils.formatNumber(phoneNumber); } }
public static String normalizeNumber(String phoneNumber) { if (CompatUtils.isLollipopCompatible()) { return PhoneNumberUtils.normalizeNumber(phoneNumber); } else { return normalizeNumberInternal(phoneNumber); } }
public static PhoneNumberFormattingTextWatcher newInstance(String countryCode) { if (CompatUtils.isLollipopCompatible()) { return new PhoneNumberFormattingTextWatcher(countryCode); } return new PhoneNumberFormattingTextWatcher(); } }
/** * Return a {@link CharSequence} that best describes the given type, possibly substituting * the given label value for TYPE_CUSTOM. */ public static CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if (CompatUtils.isLollipopCompatible()) { return Event.getTypeLabel(res, type, label); } else { return getTypeLabelInternal(res, type, label); } }
public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true); mSidePadding = (int) (getResources().getDisplayMetrics().density * TAB_SIDE_PADDING_IN_DPS); final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); mTextSize = a.getDimensionPixelSize(0, 0); mTextStyle = a.getInt(1, 0); mTextColor = a.getColorStateList(2); mTextAllCaps = a.getBoolean(3, false); mTabStrip = new ViewPagerTabStrip(context); addView(mTabStrip, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); a.recycle(); if (CompatUtils.isLollipopCompatible()) { // enable shadow casting from view bounds setOutlineProvider(VIEW_BOUNDS_OUTLINE_PROVIDER); } }
public static TtsSpan createTtsSpan(String phoneNumber) { if (CompatUtils.isMarshmallowCompatible()) { return PhoneNumberUtils.createTtsSpan(phoneNumber); } else if (CompatUtils.isLollipopCompatible()) { return createTtsSpanLollipop(phoneNumber); } else { return null; } }
/** * Set drawable resources directly for the drawable resource of the photo view. * * @param drawableId Id of drawable resource. */ public void setDrawableResource(int drawableId) { ImageView photo = getPhotoView(); photo.setScaleType(ImageView.ScaleType.CENTER); final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId); final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color); if (CompatUtils.isLollipopCompatible()) { photo.setImageDrawable(drawable); photo.setImageTintList(ColorStateList.valueOf(iconColor)); } else { final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate(); DrawableCompat.setTint(drawableWrapper, iconColor); photo.setImageDrawable(drawableWrapper); } }
/** * Returns the quick contact badge, creating it if necessary. */ public QuickContactBadge getQuickContact() { if (!mQuickContactEnabled) { throw new IllegalStateException("QuickContact is disabled for this view"); } if (mQuickContact == null) { mQuickContact = new QuickContactBadge(getContext()); if (CompatUtils.isLollipopCompatible()) { mQuickContact.setOverlay(null); } mQuickContact.setLayoutParams(getDefaultPhotoLayoutParams()); if (mNameTextView != null) { mQuickContact.setContentDescription(getContext().getString( R.string.description_quick_contact_for, mNameTextView.getText())); } addView(mQuickContact); mPhotoViewWidthAndHeightAreReady = false; } return mQuickContact; }
/** * Returns the text view for the contact name, creating it if necessary. */ public TextView getNameTextView() { if (mNameTextView == null) { mNameTextView = new TextView(getContext()); mNameTextView.setSingleLine(true); mNameTextView.setEllipsize(getTextEllipsis()); mNameTextView.setTextColor(mNameTextViewTextColor); mNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNameTextViewTextSize); // Manually call setActivated() since this view may be added after the first // setActivated() call toward this whole item view. mNameTextView.setActivated(isActivated()); mNameTextView.setGravity(Gravity.CENTER_VERTICAL); mNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); mNameTextView.setId(R.id.cliv_name_textview); if (CompatUtils.isLollipopCompatible()) { mNameTextView.setElegantTextHeight(false); } addView(mNameTextView); } return mNameTextView; }
/** * Returns the text view for the data text, creating it if necessary. */ public TextView getDataView() { if (mDataView == null) { mDataView = new TextView(getContext()); mDataView.setSingleLine(true); mDataView.setEllipsize(getTextEllipsis()); mDataView.setTextAppearance(getContext(), R.style.TextAppearanceSmall); mDataView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); mDataView.setActivated(isActivated()); mDataView.setId(R.id.cliv_data_view); if (CompatUtils.isLollipopCompatible()) { mDataView.setElegantTextHeight(false); } addView(mDataView); } return mDataView; }
boolean isBusiness) { mContactPhoto.assignContactUri(contactUri); if (CompatUtils.isLollipopCompatible()) { mContactPhoto.setOverlay(null);