List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
From source file:com.ant.sunshine.app.fragments.ForecastFragment.java
@Override public void onInflate(Context activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.ForecastFragment, 0, 0); mChoiceMode = a.getInt(R.styleable.ForecastFragment_android_choiceMode, AbsListView.CHOICE_MODE_NONE); mAutoSelectView = a.getBoolean(R.styleable.ForecastFragment_autoSelectView, false); mHoldForTransition = a.getBoolean(R.styleable.ForecastFragment_sharedElementTransitions, false); a.recycle();/*from ww w. j ava 2 s .com*/ }
From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java
public EmojiPalettesView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); final int keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0); mFunctionalKeyBackgroundId = keyboardViewAttr .getResourceId(R.styleable.KeyboardView_functionalKeyBackground, keyBackgroundId); mSpacebarBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_spacebarBackground, keyBackgroundId);/*ww w . j a va 2 s . c om*/ keyboardViewAttr.recycle(); final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(context, null /* editorInfo */); final Resources res = context.getResources(); mEmojiLayoutParams = new EmojiLayoutParams(res); builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype()); builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), mEmojiLayoutParams.mEmojiKeyboardHeight); final KeyboardLayoutSet layoutSet = builder.build(); final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context), res, layoutSet, emojiPalettesViewAttr); mCategoryIndicatorEnabled = emojiPalettesViewAttr .getBoolean(R.styleable.EmojiPalettesView_categoryIndicatorEnabled, false); mCategoryIndicatorDrawableResId = emojiPalettesViewAttr .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorDrawable, 0); mCategoryIndicatorBackgroundResId = emojiPalettesViewAttr .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorBackground, 0); mCategoryPageIndicatorColor = emojiPalettesViewAttr .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorColor, 0); mCategoryPageIndicatorBackground = emojiPalettesViewAttr .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0); emojiPalettesViewAttr.recycle(); mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener(); }
From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java
public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionMode, defStyle, 0); setBackgroundDrawable(a.getDrawable(R.styleable.SherlockActionMode_background)); mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_titleTextStyle, 0); mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_subtitleTextStyle, 0); mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionMode_height, 0); mSplitBackground = a.getDrawable(R.styleable.SherlockActionMode_backgroundSplit); a.recycle();//from w w w. j av a 2s. com }
From source file:android.support.wear.widget.drawer.WearableDrawerView.java
private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { if (attrs == null) { return;//from w w w .ja v a 2 s. c o m } TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.WearableDrawerView, defStyleAttr, R.style.Widget_Wear_WearableDrawerView); Drawable background = getDrawable(context, typedArray, R.styleable.WearableDrawerView_android_background); int elevation = typedArray.getDimensionPixelSize(R.styleable.WearableDrawerView_android_elevation, 0); setBackground(background); setElevation(elevation); mContentResId = typedArray.getResourceId(R.styleable.WearableDrawerView_drawerContent, 0); mPeekResId = typedArray.getResourceId(R.styleable.WearableDrawerView_peekView, 0); mCanAutoPeek = typedArray.getBoolean(R.styleable.WearableDrawerView_enableAutoPeek, mCanAutoPeek); typedArray.recycle(); }
From source file:com.albedinsky.android.support.ui.widget.FrameLayoutWidget.java
/** * Creates a new instance of FrameLayoutWidget within the given <var>context</var>. * * @param context Context in which will be this view presented. * @param attrs Set of Xml attributes used to configure the new instance of this view. * @param defStyleAttr An attribute which contains a reference to a default style resource for * this view within a theme of the given context. */// w w w.j ava2 s . co m public FrameLayoutWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ViewGroup, defStyleAttr, 0); if (typedArray != null) { this.processTintValues(context, typedArray); typedArray.recycle(); } this.applyBackgroundTint(); }
From source file:com.albedinsky.android.support.ui.widget.LinearLayoutWidget.java
/** * Creates a new instance of LinearLayoutWidget within the given <var>context</var>. * * @param context Context in which will be this view presented. * @param attrs Set of Xml attributes used to configure the new instance of this view. * @param defStyleAttr An attribute which contains a reference to a default style resource for * this view within a theme of the given context. *///from ww w . j ava 2 s. co m public LinearLayoutWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ViewGroup, defStyleAttr, 0); if (typedArray != null) { this.processTintValues(context, typedArray); typedArray.recycle(); } this.applyBackgroundTint(); }
From source file:com.albedinsky.android.support.ui.widget.RelativeLayoutWidget.java
/** * Creates a new instance of RelativeLayoutWidget within the given <var>context</var>. * * @param context Context in which will be this view presented. * @param attrs Set of Xml attributes used to configure the new instance of this view. * @param defStyleAttr An attribute which contains a reference to a default style resource for * this view within a theme of the given context. *//*from w ww .ja v a 2 s. com*/ public RelativeLayoutWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ViewGroup, defStyleAttr, 0); if (typedArray != null) { this.processTintValues(context, typedArray); typedArray.recycle(); } this.applyBackgroundTint(); }
From source file:com.ahao.preferencelibrary.preference.DialogPreference.java
@Override protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { super.init(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr, defStyleRes);//from w ww. j a va2s . co m mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle); if (mDialogTitle == null) { // Fallback on the regular title of the preference // (the one that is seen in the list) mDialogTitle = getTitle(); } mDialogMessage = a.getString(R.styleable.DialogPreference_dialogMessage); mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon); mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText); mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText); mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId); a.recycle(); }
From source file:ch.berta.fabio.fabprogress.FabProgress.java
/** * We are using private resources here in order to get the fab size. This is hacky but the * alternative would be that the user needs to specify the fab size two times in the XML. * TODO: only needed as long as we support api <21, because of the space the shadow drawable takes up * * @param context the context to obtain the style attributes * @param attrs the attribute set * @param defStyleAttr the style attr/*from www .ja va 2s.co m*/ */ @SuppressLint("PrivateResource") private void setFakeShadowPadding(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) { TypedArray attrFab = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0); try { final Resources res = getResources(); int size = attrFab.getInt(R.styleable.FloatingActionButton_fabSize, SIZE_NORMAL); if (size == SIZE_MINI) { mFabSize = res.getDimensionPixelSize(R.dimen.fp_fab_size_mini); } else { mFabSize = res.getDimensionPixelSize(R.dimen.fp_fab_size_normal); } } finally { attrFab.recycle(); } final int maxContentSize = (int) getResources().getDimension(R.dimen.fp_fab_content_size); final int contentPadding = (mFabSize - maxContentSize) / 2; mShadowPadding.left = getPaddingLeft() - contentPadding; mShadowPadding.top = getPaddingTop() - contentPadding; mShadowPadding.right = getPaddingEnd() - contentPadding; mShadowPadding.bottom = getPaddingBottom() - contentPadding; }
From source file:com.astuetz.viewpager.extensions.ScrollingTabsView.java
public ScrollingTabsView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); this.mContext = context; mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop); mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom); mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0); mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor); mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop, mDividerMarginTop);/* w w w . j ava2s. c om*/ mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom, mDividerMarginBottom); mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable); a.recycle(); this.setHorizontalScrollBarEnabled(false); this.setHorizontalFadingEdgeEnabled(false); mContainer = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mContainer.setLayoutParams(params); mContainer.setOrientation(LinearLayout.HORIZONTAL); this.addView(mContainer); }