List of usage examples for android.content.res TypedArray hasValue
public boolean hasValue(@StyleableRes int index)
From source file:android.support.design.widget.CustomCollapsingTextHelper.java
public void setCollapsedSubAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mCollapsedSubColor = a.getColorStateList(R.styleable.TextAppearance_android_textColor); }//from w w w . java 2s. c o m if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mCollapsedSubSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) mCollapsedSubSize); } a.recycle(); }
From source file:io.plaidapp.ui.widget.FabOverlapTextView.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView); float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, getResources().getDisplayMetrics()); setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT)); setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0)); setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0)); if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) { final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance, android.R.style.TextAppearance); TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance); paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK)); paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize, (int) defaultTextSize)); if (atp.hasValue(R.styleable.FontTextAppearance_font)) { paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font))); }/*from w w w .j a va2s . c o m*/ atp.recycle(); } if (a.hasValue(R.styleable.FabOverlapTextView_font)) { setFont(a.getString(R.styleable.FabOverlapTextView_font)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) { setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) { setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize, (int) defaultTextSize)); } lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0); topPaddingHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_topPaddingHint, 0); breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy, Layout.BREAK_STRATEGY_BALANCED); a.recycle(); }
From source file:io.plaidapp.core.ui.widget.CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setWillNotDraw(false);//from www.j ava 2 s.c om paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout); final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // first check if all insets set the same titleInsetStart = titleInsetEnd = titleInsetBottom = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInset, 0); titleInsetTop = titleInsetStart; if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetStart)) { final int insetStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetStart, 0); if (isRtl) { titleInsetEnd = insetStart; } else { titleInsetStart = insetStart; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetTop)) { titleInsetTop = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetTop, 0); } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetEnd)) { final int insetEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetEnd, 0); if (isRtl) { titleInsetStart = insetEnd; } else { titleInsetEnd = insetEnd; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetBottom)) { titleInsetBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetBottom, 0); } // first check TextAppearance for text attributes if (a.hasValue(R.styleable.CollapsingTitleLayout_android_textAppearance)) { final int textAppearanceId = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance, android.R.style.TextAppearance); TypedArray ta = getContext().obtainStyledAttributes(textAppearanceId, R.styleable.CollapsingTitleLayout); // default collapsedTextSize to regular android:textSize in the TextAppearance collapsedTextSize = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_android_textSize, 0); parseTextAttrs(ta); ta.recycle(); } // then check view for text attributes parseTextAttrs(a); a.recycle(); }
From source file:com.tr4android.support.extension.typeface.TypefaceCompatFactory.java
/** * This method is responsible for creating the correct subclass of View given the xml element name * via AppCompat's layout inflater and afterwards sets the correct typeface if needed. * * @param parent The future parent of the returned view. Note that this may be null. * @param name The fully qualified class name of the View to be create. * @param context The context the view is being created in. * @param attrs An AttributeSet of attributes to apply to the View. * @return The newly created view.//w w w. j a v a 2 s .co m * @since 0.1.1 * @deprecated */ @Deprecated @Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { View result = null; // Allow base factory to try and create a view first if (mBaseFactory != null) { result = mBaseFactory.onCreateView(parent, name, context, attrs); } if (result instanceof TextView) { TextView textView = (TextView) result; String fontFamily = null; int style = 0; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0); TypedArray appearance = null; int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1); a.recycle(); if (ap != -1) { appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance); } if (appearance != null) { fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily); style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0); appearance.recycle(); } a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0); if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) { fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily); style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0); } a.recycle(); if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) { Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style); if (tf != null) { textView.setTypeface(tf); } } } return result; }
From source file:com.muzakki.ahmad.widget.CollapsingTextHelper.java
void setCollapsedSubAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mCollapsedSubColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedSubColor); }/*www . ja v a2 s . c o m*/ if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mCollapsedSubSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) mCollapsedSubSize); } }
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView); float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, getResources().getDisplayMetrics()); setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT)); setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0)); setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0)); if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) { final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance, android.R.style.TextAppearance); TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance); paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK)); paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize, (int) defaultTextSize)); if (atp.hasValue(R.styleable.FontTextAppearance_font)) { paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font))); }/*from w w w .j a va 2s.c om*/ atp.recycle(); } if (a.hasValue(R.styleable.FabOverlapTextView_font)) { setFont(a.getString(R.styleable.FabOverlapTextView_font)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) { setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) { setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize, (int) defaultTextSize)); } lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0); unalignedTopPadding = getPaddingTop(); unalignedBottomPadding = getPaddingBottom(); breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy, Layout.BREAK_STRATEGY_BALANCED); a.recycle(); }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
void setExpandedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, android.support.v7.appcompat.R.styleable.TextAppearance); if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor)) { mExpandedTextColor = a.getColor( android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor, mExpandedTextColor); }// w w w.j a va 2 s . c o m if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize)) { mExpandedTextSize = a.getDimensionPixelSize( android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize, (int) mExpandedTextSize); } mExpandedShadowColor = a.getInt(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowColor, 0); mExpandedShadowDx = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDx, 0); mExpandedShadowDy = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDy, 0); mExpandedShadowRadius = a .getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowRadius, 0); a.recycle(); if (Build.VERSION.SDK_INT >= 16) { mExpandedTypeface = readFontFamilyTypeface(resId); } recalculate(); }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
void setCollapsedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, android.support.v7.appcompat.R.styleable.TextAppearance); if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor)) { mCollapsedTextColor = a.getColor( android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor, mCollapsedTextColor); }/* ww w . ja v a 2s . c o m*/ if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize)) { mCollapsedTextSize = a.getDimensionPixelSize( android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize, (int) mCollapsedTextSize); } mCollapsedShadowColor = a .getInt(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowColor, 0); mCollapsedShadowDx = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDx, 0); mCollapsedShadowDy = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDy, 0); mCollapsedShadowRadius = a .getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowRadius, 0); a.recycle(); if (Build.VERSION.SDK_INT >= 16) { mCollapsedTypeface = readFontFamilyTypeface(resId); } recalculate(); }
From source file:com.fimagena.filepicker.FilePickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_PARAMS)) { mParams = (BitSet) savedInstanceState.getSerializable(KEY_PARAMS); mStartPath = new File(savedInstanceState.getString(KEY_CURRENT_PATH)); } else {/*from www. j a v a 2 s . com*/ // read xml custom-attributes TypedArray attrArray = activity.obtainStyledAttributes(attrs, R.styleable.FilePickerFragment); mParams = new BitSet(4); mParams.set(SELECT_FILE, attrArray.getBoolean(R.styleable.FilePickerFragment_select_file, false)); mParams.set(SELECT_DIR, attrArray.getBoolean(R.styleable.FilePickerFragment_select_dir, false)); mParams.set(ALLOW_CREATE_DIR, attrArray.getBoolean(R.styleable.FilePickerFragment_allow_dir_create, false)); mParams.set(ALLOW_MULTIPLE_SELECT, attrArray.getBoolean(R.styleable.FilePickerFragment_allow_multiple, false)); if (!mParams.get(SELECT_FILE) && !mParams.get(SELECT_DIR)) mParams.set(SELECT_FILE, true); if (attrArray.hasValue(R.styleable.FilePickerFragment_start_path)) mStartPath = new File(attrArray.getText(R.styleable.FilePickerFragment_start_path).toString()); else mStartPath = Environment.getExternalStorageDirectory(); attrArray.recycle(); } }
From source file:br.liveo.searchliveo.SearchLiveo.java
private void initAttribute(Context context, AttributeSet attributeSet, int defStyleAttr) { TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.search_liveo, defStyleAttr, 0); if (attr != null) { try {/*w ww . j av a 2 s . c o m*/ if (attr.hasValue(R.styleable.search_liveo_search_liveo_hint)) { hint(attr.getString(R.styleable.search_liveo_search_liveo_hint)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_text_color)) { mEdtSearch.setTextColor(attr.getColor(R.styleable.search_liveo_search_liveo_text_color, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_hint_color)) { mEdtSearch .setHintTextColor(attr.getColor(R.styleable.search_liveo_search_liveo_hint_color, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_icon)) { setColorIcon(attr.getColor(R.styleable.search_liveo_search_liveo_color_icon, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_arrow)) { setColorIconArrow(attr.getColor(R.styleable.search_liveo_search_liveo_color_arrow, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_voice)) { setColorIconVoice(attr.getColor(R.styleable.search_liveo_search_liveo_color_voice, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_close)) { setColorIconClose(attr.getColor(R.styleable.search_liveo_search_liveo_color_close, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_background)) { mViewSearch.setBackgroundColor( attr.getColor(R.styleable.search_liveo_search_liveo_background, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_status_bar_show_color)) { setStatusBarShowColor( attr.getColor(R.styleable.search_liveo_search_liveo_status_bar_show_color, -1)); } if (attr.hasValue(R.styleable.search_liveo_search_liveo_status_bar_hide_color)) { setStatusBarHideColor( attr.getColor(R.styleable.search_liveo_search_liveo_status_bar_hide_color, -1)); } } finally { attr.recycle(); } } }