List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
From source file:com.advaitaworld.widgets.FloatLabelLayout.java
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOrientation(VERTICAL);/*from w w w. j a v a 2 s . c om*/ final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout); int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft, dipsToPix(DEFAULT_LABEL_PADDING_LEFT)); int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop, dipsToPix(DEFAULT_LABEL_PADDING_TOP)); int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight, dipsToPix(DEFAULT_LABEL_PADDING_RIGHT)); int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom, dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM)); mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint); mLabel = new TextView(context); mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding); mLabel.setVisibility(INVISIBLE); mLabel.setText(mHint); ViewCompat.setPivotX(mLabel, 0f); ViewCompat.setPivotY(mLabel, 0f); mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance, android.R.style.TextAppearance_Small)); a.recycle(); addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mInterpolator = AnimationUtils.loadInterpolator(context, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in : android.R.anim.decelerate_interpolator); }
From source file:com.achep.base.dashboard.DashboardCategory.java
public DashboardCategory(Context context, AttributeSet attrs) { TypedArray sa = context.obtainStyledAttributes(attrs, R.styleable.DashboardTile); id = sa.getResourceId(R.styleable.DashboardTile_dashboard_id, CAT_ID_UNDEFINED); TypedValue tv = sa.peekValue(R.styleable.DashboardTile_dashboard_title); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { titleRes = tv.resourceId;//from w ww . j ava 2 s. c o m } else { title = tv.string; } } sa.recycle(); }
From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java
public FabTransition(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = null;/*ww w . j a v a 2 s . c om*/ try { a = context.obtainStyledAttributes(attrs, R.styleable.FabTransition); if (!a.hasValue(R.styleable.FabTransition_fabColor) || !a.hasValue(R.styleable.FabTransition_fabIcon)) { throw new IllegalArgumentException("Must provide both color & icon."); } color = a.getColor(R.styleable.FabTransition_fabColor, Color.TRANSPARENT); icon = a.getResourceId(R.styleable.FabTransition_fabIcon, 0); setPathMotion(new GravityArcMotion()); if (getDuration() < 0) { setDuration(DEFAULT_DURATION); } } finally { if (a != null) { a.recycle(); } } }
From source file:com.android.volley.ui.NetworkImageView.java
public NetworkImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, attrsArray); setDefaultImageResId(a.getResourceId(0, 0)); a.recycle();/*from w w w. j a v a 2s . c o m*/ }
From source file:androidx.navigation.fragment.NavHostFragment.java
@Override public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(context, attrs, savedInstanceState); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavHostFragment); final int graphId = a.getResourceId(R.styleable.NavHostFragment_navGraph, 0); final boolean defaultHost = a.getBoolean(R.styleable.NavHostFragment_defaultNavHost, false); if (graphId != 0) { setGraph(graphId);/* w w w .j ava2 s. c o m*/ } if (defaultHost) { mDefaultNavHost = true; } a.recycle(); }
From source file:alexander.martinz.libs.materialpreferences.MaterialPreference.java
protected TypedArray parseAttrs(Context context, AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialPreference); if (a == null) { Log.e(this.getClass().getSimpleName(), "Could not obtain typed array!"); return null; }//from w w w. j a v a2s . c o m mPrefKey = a.getString(R.styleable.MaterialPreference_prefKey); mPrefAsCard = a.getBoolean(R.styleable.MaterialPreference_prefAsCard, false); mResIdIcon = a.getResourceId(R.styleable.MaterialPreference_prefIcon, -1); mIconTintColor = a.getColor(R.styleable.MaterialPreference_prefIconTint, Integer.MIN_VALUE); mResIdTitle = a.getResourceId(R.styleable.MaterialPreference_prefTitle, -1); mResIdSummary = a.getResourceId(R.styleable.MaterialPreference_prefSummary, -1); mCardBackgroundColor = a.getColor(R.styleable.MaterialPreference_prefCardBackgroundColor, Integer.MIN_VALUE); return a; }
From source file:cn.qbcbyb.library.view.PagerTabStrip.java
public PagerTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setWillNotDraw(false);// w w w .jav a 2 s . c om setOrientation(LinearLayout.HORIZONTAL); // get custom attrs TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerTabStrip); indicatorDrawable = a.getResourceId(R.styleable.PagerTabStrip_indicatorDrawable, R.drawable.pager_indicator); a.recycle(); }
From source file:com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.java
public DpcPreferenceHelper(Context context, Preference preference, AttributeSet attrs) { mContext = context;/* w w w. ja va2 s .c o m*/ mPreference = preference; final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DpcPreference); mMinSdkVersion = a.getInt(R.styleable.DpcPreference_minSdkVersion, 0); if (attrs == null) { // Be more lenient when creating the preference from code mMinSdkVersion = Build.VERSION_CODES.LOLLIPOP; } if (mMinSdkVersion == 0) { throw new RuntimeException("testdpc:minSdkVersion must be specified."); } // noinspection ResourceType mAdminConstraint = a.getInt(R.styleable.DpcPreference_admin, ADMIN_DEFAULT); // noinspection ResourceType mUserConstraint = a.getInt(R.styleable.DpcPreference_user, USER_DEFAULT); a.recycle(); }
From source file:com.android.messaging.ui.ViewPagerTabs.java
public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*from w ww . j a va 2 s .c o m*/ 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(); // enable shadow casting from view bounds if (OsUtil.isAtLeastL()) { setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setRect(0, 0, view.getWidth(), view.getHeight()); } }); } }
From source file:com.alex.view.loop.IndicatorView.java
public IndicatorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // ?//from ww w . j ava2 s . c o m TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView); normalBp = drawableToBitamp(ta.getDrawable(R.styleable.IndicatorView_normalDrawable)); selectBp = drawableToBitamp(ta.getDrawable(R.styleable.IndicatorView_selectDrawable)); mInterval = ta.getDimensionPixelOffset(R.styleable.IndicatorView_indicatorInterval, 6); normalColor = ta.getColor(R.styleable.IndicatorView_normalColor, Color.GRAY); selectColor = ta.getColor(R.styleable.IndicatorView_selectColor, Color.RED); mRadius = ta.getInteger(R.styleable.IndicatorView_indicatorRadius, 6); isCirculate = ta.getBoolean(R.styleable.IndicatorView_isCirculate, true); ta.recycle(); // ? init(); }