List of usage examples for android.content.res TypedArray getDimensionPixelSize
public int getDimensionPixelSize(@StyleableRes int index, int defValue)
From source file:com.geely.testbottomsheets.CustomBottomSheetBehavior.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}.//from w ww. j av a 2s . c o m * @param attrs The {@link AttributeSet}. */ public CustomBottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Params); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.fjoglar.etsitnoticias.view.widget.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;/*from w w w . j a v a2s . c om*/ halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { interpolator = AnimUtils.getFastOutSlowInInterpolator(context); } else { interpolator = null; } // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.github.shareme.gwsinkpageindicator.library.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;//from w w w .j a v a 2 s . c om halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = new FastOutSlowInInterpolator(); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.pedrovgs.draggablepanel.DraggableView.java
/** * Initialize Transformer with a scalable or change width/height implementation. *//* w w w . j av a 2s.c om*/ private void initializeTransformer(TypedArray attributes) { topViewResize = attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE); TransformerFactory transformerFactory = new TransformerFactory(); transformer = transformerFactory.getTransformer(topViewResize, dragView, this); transformer.setViewHeight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height, DEFAULT_TOP_VIEW_HEIGHT)); transformer.setXScaleFactor( attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, DEFAULT_SCALE_FACTOR)); transformer.setYScaleFactor( attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, DEFAULT_SCALE_FACTOR)); transformer.setMarginRight(attributes .getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right, DEFAULT_TOP_VIEW_MARGIN)); transformer.setMarginBottom(attributes .getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom, DEFAULT_TOP_VIEW_MARGIN)); }
From source file:com.example.pierrechanson.prototypebottomsheet.BottomSheetBehaviorGoogleMapsLike.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}./*www . j a va 2s .co m*/ * @param attrs The {@link AttributeSet}. */ public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Params); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.homechart.app.commont.matertab.MaterialTabs.java
public MaterialTabs(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);//from w w w.j a va 2 s. c om setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // Get system attrs (android:textSize and android:textColor). TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(TEXT_COLOR_INDEX, tabTextSize); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, 0); tabTextColorUnselected = a.getColor(TEXT_COLOR_INDEX, textPrimaryColor); underlineColor = textPrimaryColor; indicatorColor = textPrimaryColor; int padding = a.getDimensionPixelSize(PADDING_INDEX, 0); paddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0); paddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0); a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.MaterialTabs); // Get custom attrs of MaterialTabs. indicatorColor = a.getColor(R.styleable.MaterialTabs_mtIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.MaterialTabs_mtUnderlineColor, underlineColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtUnderlineHeight, underlineHeight); tabPadding = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtTabPaddingLeftRight, tabPadding); sameWeightTabs = a.getBoolean(R.styleable.MaterialTabs_mtSameWeightTabs, sameWeightTabs); textAllCaps = a.getBoolean(R.styleable.MaterialTabs_mtTextAllCaps, textAllCaps); isPaddingMiddle = a.getBoolean(R.styleable.MaterialTabs_mtPaddingMiddle, isPaddingMiddle); tabTypefaceUnselectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextUnselectedStyle, Typeface.BOLD); tabTypefaceSelectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextSelectedStyle, Typeface.BOLD); tabTextColorSelected = a.getColor(R.styleable.MaterialTabs_mtTextColorSelected, textPrimaryColor); // Get custom attrs of MaterialRippleLayout. rippleColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleColor, MaterialRippleLayout.DEFAULT_COLOR); // Making default ripple highlight color the same as rippleColor but with 1/4 the alpha. rippleHighlightColor = Color.argb((int) (Color.alpha(rippleColor) * 0.25), Color.red(rippleColor), Color.green(rippleColor), Color.blue(rippleColor)); rippleHighlightColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleHighlightColor, rippleHighlightColor); rippleDiameterDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleDiameter, MaterialRippleLayout.DEFAULT_DIAMETER_DP); rippleOverlay = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleOverlay, MaterialRippleLayout.DEFAULT_RIPPLE_OVERLAY); rippleDuration = a.getInt(R.styleable.MaterialTabs_mtMrlRippleDuration, MaterialRippleLayout.DEFAULT_DURATION); rippleAlphaFloat = a.getFloat(R.styleable.MaterialTabs_mtMrlRippleAlpha, MaterialRippleLayout.DEFAULT_ALPHA); rippleDelayClick = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleDelayClick, MaterialRippleLayout.DEFAULT_DELAY_CLICK); rippleFadeDuration = a.getInteger(R.styleable.MaterialTabs_mtMrlRippleFadeDuration, MaterialRippleLayout.DEFAULT_FADE_DURATION); ripplePersistent = a.getBoolean(R.styleable.MaterialTabs_mtMrlRipplePersistent, MaterialRippleLayout.DEFAULT_PERSISTENT); rippleInAdapter = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleInAdapter, MaterialRippleLayout.DEFAULT_SEARCH_ADAPTER); rippleRoundedCornersDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleRoundedCorners, MaterialRippleLayout.DEFAULT_ROUNDED_CORNERS_DP); a.recycle(); setMarginBottomTabContainer(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.ezmeal.swipeytabs.SwipeyTabs.java
public SwipeyTabs(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeyTabs, defStyle, 0); //attr:The base set of attribute values //R.styleable.SwipeyTabs(array of int):The desired attributes to be retrieved. //defStyle:An attribute in the current theme that contains a reference to // a style resource that supplies defaults values for the StyledAttributes. mBottomBarColor = a.getColor(R.styleable.SwipeyTabs_bottomBarColor, mBottomBarColor); mBottomBarHeight = a.getDimensionPixelSize(R.styleable.SwipeyTabs_bottomBarHeight, 2); mTabIndicatorHeight = a.getDimensionPixelSize(R.styleable.SwipeyTabs_tabIndicatorHeight, 3); a.recycle();/* www . j ava 2 s. c o m*/ init(); }
From source file:com.freshdigitable.udonroad.ffab.IndicatableFFAB.java
public IndicatableFFAB(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final View v = View.inflate(context, R.layout.view_indicatable_ffab, this); indicator = (ActionIndicatorView) v.findViewById(R.id.iffab_indicator); ffab = (FlingableFAB) v.findViewById(R.id.iffab_ffab); ViewCompat.setElevation(indicator, ffab.getCompatElevation()); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IndicatableFFAB, defStyleAttr, R.style.Widget_FFAB_IndicatableFFAB); try {//from ww w . j a v a 2 s .com final Drawable fabIcon = a.getDrawable(R.styleable.IndicatableFFAB_fabIcon); ffab.setImageDrawable(fabIcon); final int fabTint = a.getColor(R.styleable.IndicatableFFAB_fabTint, NO_ID); if (fabTint != NO_ID) { ViewCompat.setBackgroundTintList(ffab, ColorStateList.valueOf(fabTint)); } final int indicatorTint = a.getColor(R.styleable.IndicatableFFAB_indicatorTint, 0); indicator.setBackgroundColor(indicatorTint); indicatorMargin = a.getDimensionPixelSize(R.styleable.IndicatableFFAB_marginFabToIndicator, 0); } finally { a.recycle(); } ffab.setOnTouchListener(new OnTouchListener() { private MotionEvent old; @Override public boolean onTouch(View view, MotionEvent motionEvent) { final int action = motionEvent.getAction(); if (action == MotionEvent.ACTION_DOWN) { old = MotionEvent.obtain(motionEvent); onStart(); return false; } final Direction direction = Direction.getDirection(old, motionEvent); if (action == MotionEvent.ACTION_MOVE) { onMoving(direction); } else if (action == MotionEvent.ACTION_UP) { old.recycle(); onFling(view.getHandler()); } return false; } private Direction prevSelected = Direction.UNDEFINED; public void onStart() { indicator.onActionLeave(prevSelected); prevSelected = Direction.UNDEFINED; indicator.setVisibility(View.VISIBLE); } public void onMoving(Direction direction) { if (prevSelected == direction) { return; } indicator.onActionLeave(prevSelected); if (isDirectionEnabled(direction)) { indicator.onActionSelected(direction); } prevSelected = direction; } private boolean isDirectionEnabled(Direction direction) { for (Direction d : enableDirections) { if (d == direction) { return true; } } return false; } public void onFling(Handler handler) { handler.postDelayed(new Runnable() { @Override public void run() { indicator.setVisibility(View.INVISIBLE); } }, 200); } }); if (isInEditMode()) { indicator.setVisibility(VISIBLE); } }
From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java
private void parseStyle(Context context, AttributeSet attrs, int defStyle) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, com.layer.atlas.R.styleable.AtlasMessageComposer, com.layer.atlas.R.attr.AtlasMessageComposer, defStyle);/* w w w . j a v a 2s.co m*/ mEnabled = ta.getBoolean(com.layer.atlas.R.styleable.AtlasMessageComposer_android_enabled, true); this.mTextColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_text_black)); this.mTextSize = ta.getDimensionPixelSize(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextSize, context.getResources().getDimensionPixelSize(com.layer.atlas.R.dimen.atlas_text_size_input)); this.mTextStyle = ta.getInt(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextStyle, Typeface.NORMAL); String typeFaceName = ta.getString(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextTypeface); this.mTypeFace = typeFaceName != null ? Typeface.create(typeFaceName, mTextStyle) : null; this.mUnderlineColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputUnderlineColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_color_primary_blue)); this.mCursorColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputCursorColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_color_primary_blue)); this.mAttachmentSendersBackground = ta .getDrawable(com.layer.atlas.R.styleable.AtlasMessageComposer_attachmentSendersBackground); ta.recycle(); }
From source file:com.example.administrator.smartbj.Drawer.MyNavigationView.java
public MyNavigationView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // ThemeUtils.checkAppCompatTheme(context); // Create the menu mMenu = new MyNavigationMenu2(context); // Custom attributes TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.NavigationView, defStyleAttr, android.support.design.R.style.Widget_Design_NavigationView); //noinspection deprecation setBackgroundDrawable(a.getDrawable(android.support.design.R.styleable.NavigationView_android_background)); if (a.hasValue(android.support.design.R.styleable.NavigationView_elevation)) { ViewCompat.setElevation(this, a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_elevation, 0)); }/*from w w w . ja v a2 s . c om*/ ViewCompat.setFitsSystemWindows(this, a.getBoolean(android.support.design.R.styleable.NavigationView_android_fitsSystemWindows, false)); mMaxWidth = a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_android_maxWidth, 0); final ColorStateList itemIconTint; if (a.hasValue(android.support.design.R.styleable.NavigationView_itemIconTint)) { itemIconTint = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemIconTint); } else { itemIconTint = createDefaultColorStateList(android.R.attr.textColorSecondary); } boolean textAppearanceSet = false; int textAppearance = 0; if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextAppearance)) { textAppearance = a.getResourceId(android.support.design.R.styleable.NavigationView_itemTextAppearance, 0); textAppearanceSet = true; } ColorStateList itemTextColor = null; if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextColor)) { itemTextColor = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemTextColor); } if (!textAppearanceSet && itemTextColor == null) { // If there isn't a text appearance set, we'll use a default text color itemTextColor = createDefaultColorStateList(android.R.attr.textColorPrimary); } final Drawable itemBackground = a .getDrawable(android.support.design.R.styleable.NavigationView_itemBackground); mMenu.setCallback(new MenuBuilder.Callback() { @Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { return mListener != null && mListener.onNavigationItemSelected(item); } @Override public void onMenuModeChange(MenuBuilder menu) { } }); mPresenter.setId(PRESENTER_NAVIGATION_VIEW_ID); mPresenter.initForMenu(context, mMenu); mPresenter.setItemIconTintList(itemIconTint); if (textAppearanceSet) { mPresenter.setItemTextAppearance(textAppearance); } mPresenter.setItemTextColor(itemTextColor); mPresenter.setItemBackground(itemBackground); mMenu.addMenuPresenter(mPresenter); addView((View) mPresenter.getMenuView(this)); if (a.hasValue(android.support.design.R.styleable.NavigationView_menu)) { inflateMenu(a.getResourceId(android.support.design.R.styleable.NavigationView_menu, 0)); } if (a.hasValue(android.support.design.R.styleable.NavigationView_headerLayout)) { inflateHeaderView(a.getResourceId(android.support.design.R.styleable.NavigationView_headerLayout, 0)); } a.recycle(); }