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.along.altmcssd.pda.widget.viewpagerindicator.TitlePageIndicator.java
public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from ww w. j a va 2 s .com // Load defaults from resources final Resources res = getResources(); final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color); final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height); final int defaultFooterIndicatorStyle = res .getInteger(R.integer.default_title_indicator_footer_indicator_style); final float defaultFooterIndicatorHeight = res .getDimension(R.dimen.default_title_indicator_footer_indicator_height); final float defaultFooterIndicatorUnderlinePadding = res .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding); final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding); final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position); final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color); final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold); final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color); final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size); final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding); final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding); final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0); // Retrieve the colors to be used for this view and apply them. mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight); mFooterIndicatorStyle = IndicatorStyle.fromValue( a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle)); mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight); mFooterIndicatorUnderlinePadding = a.getDimension( R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding); mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding); mLinePosition = LinePosition .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition)); mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding); mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding); mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding); mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor); mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor); mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold); final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize); final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor); mPaintText.setTextSize(textSize); mPaintText.setAntiAlias(true); mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterLine.setStrokeWidth(mFooterLineHeight); mPaintFooterLine.setColor(footerColor); mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterIndicator.setColor(footerColor); Drawable background = a.getDrawable(R.styleable.TitlePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java
/** * ?// w w w . j av a2 s . c o m * @param context * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; //Load defaults from resources final Resources res = getResources(); final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color); final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color); final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color); final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height); final int defaultFooterIndicatorStyle = res .getInteger(R.integer.default_title_indicator_footer_indicator_style); final float defaultFooterIndicatorHeight = res .getDimension(R.dimen.default_title_indicator_footer_indicator_height); final float defaultFooterIndicatorUnderlinePadding = res .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding); final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding); final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position); final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold); final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size); final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding); final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding); final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0); //Retrieve the colors to be used for this view and apply them. mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight); mFooterIndicatorStyle = IndicatorStyle.fromValue( a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle)); mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight); mFooterIndicatorUnderlinePadding = a.getDimension( R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding); mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding); mLinePosition = LinePosition .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition)); mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding); mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding); mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding); mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor); mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor); mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold); final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize); final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor); mPaintText.setTextSize(textSize); mPaintText.setAntiAlias(true); mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterLine.setStrokeWidth(mFooterLineHeight); mPaintFooterLine.setColor(footerColor); mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterIndicator.setColor(footerColor); Drawable background = a.getDrawable(R.styleable.TitlePageIndicator_android_background); if (background != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(background); } else { setBackgroundDrawable(background); } } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:android.support.designox.widget.CoordinatorLayout.java
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr, R.style.Widget_Design_CoordinatorLayout); final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0); if (keylineArrayRes != 0) { final Resources res = context.getResources(); mKeylines = res.getIntArray(keylineArrayRes); final float density = res.getDisplayMetrics().density; final int count = mKeylines.length; for (int i = 0; i < count; i++) { mKeylines[i] *= density;//from ww w . j ava 2 s . c om } } mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground); a.recycle(); if (INSETS_HELPER != null) { INSETS_HELPER.setupForWindowInsets(this, new ApplyInsetsListener()); } super.setOnHierarchyChangeListener(new HierarchyChangeListener()); }
From source file:cc.flydev.launcher.Page.java
public PagedView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); setPageSpacing(a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0)); if (mPageSpacing < 0) { mAutoComputePageSpacing = mRecomputePageSpacing = true; }/*w w w .j av a2 s . com*/ mPageLayoutPaddingTop = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingTop, 0); mPageLayoutPaddingBottom = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingBottom, 0); mPageLayoutPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingLeft, 0); mPageLayoutPaddingRight = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingRight, 0); mPageLayoutWidthGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutWidthGap, 0); mPageLayoutHeightGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutHeightGap, 0); mPageIndicatorViewId = a.getResourceId(R.styleable.PagedView_pageIndicator, -1); a.recycle(); setHapticFeedbackEnabled(false); init(); }
From source file:com.android.leanlauncher.Workspace.java
/** * Used to inflate the Workspace from XML. * * @param context The application's context. * @param attrs The attributes set containing the Workspace's customization values. * @param defStyle Unused./*from w ww.ja va 2 s . c o m*/ */ public Workspace(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mOutlineHelper = HolographicOutlineHelper.obtain(context); mLauncher = (Launcher) context; final Resources res = getResources(); mWallpaperManager = WallpaperManager.getInstance(context); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0); mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; mOverviewModeShrinkFactor = grid.getOverviewModeScale(); a.recycle(); setOnHierarchyChangeListener(this); setHapticFeedbackEnabled(false); initWorkspace(); // Disable multitouch across the workspace/all apps/customize tray setMotionEventSplittingEnabled(true); setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); }
From source file:android.support.design.widget.CoordinatorLayout.java
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr, R.style.Widget_Design_CoordinatorLayout); final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0); if (keylineArrayRes != 0) { final Resources res = context.getResources(); mKeylines = res.getIntArray(keylineArrayRes); final float density = res.getDisplayMetrics().density; final int count = mKeylines.length; for (int i = 0; i < count; i++) { mKeylines[i] *= density;/*from www . ja v a 2 s . co m*/ } } mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground); a.recycle(); setupForInsets(); super.setOnHierarchyChangeListener(new HierarchyChangeListener()); }
From source file:cn.lry.animation.viewpager.ViewPager.java
public ViewPager(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPager, defStyle, 0); mOrientation = a.getInt(R.styleable.ViewPager_orientation, ORIENTATION_HORIZONTAL); a.recycle();/* w w w.j a va 2 s. c o m*/ initViewPager(); }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java
public ViewPager(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPager, defStyle, 0); mOrientation = a.getInt(R.styleable.ViewPager_orientation, ORIENTATION_HORIZONTAL); a.recycle();/*from w w w . ja v a2s .c o m*/ initViewPager(); }
From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java
/** * Called from one of constructors of this view to perform its initialization. * <p>//from www .j a v a 2s.co m * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ @SuppressWarnings("ConstantConditions") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.ensureRect(); this.ensureDecorator(); mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes); this.mAnimations = Animations.get(this); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SeekBar, defStyleAttr, defStyleRes); if (typedArray != null) { final Rect indicatorTextPadding = new Rect(); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SeekBar_android_enabled) { setEnabled(typedArray.getBoolean(index, true)); } else if (index == R.styleable.Ui_SeekBar_uiDiscrete) { setDiscrete(typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_SeekBar_uiDiscretePreviewEnabled) { setDiscretePreviewEnabled(typedArray.getBoolean(index, true)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalRatio) { setDiscreteIntervalRatio(typedArray.getFloat(index, mDiscreteIntervalRatio)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicator) { setDiscreteIndicator(typedArray.getResourceId(index, 0)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextAppearance) { setDiscreteIndicatorTextAppearance(typedArray.getResourceId(index, 0)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextGravity) { setDiscreteIndicatorTextGravity( typedArray.getInteger(index, DISCRETE_INDICATOR_TEXT_INFO.gravity)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingStart) { indicatorTextPadding.left = typedArray.getDimensionPixelSize(index, 0); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingTop) { indicatorTextPadding.top = typedArray.getDimensionPixelSize(index, 0); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingEnd) { indicatorTextPadding.right = typedArray.getDimensionPixelSize(index, 0); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingBottom) { indicatorTextPadding.bottom = typedArray.getDimensionPixelSize(index, 0); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkColor) { setDiscreteIntervalTickMarkColor(typedArray.getColorStateList(index)); } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkRadius) { setDiscreteIntervalTickMarkRadius(typedArray.getDimensionPixelSize(index, 0)); } } setDiscreteIndicatorTextPadding(indicatorTextPadding.left, indicatorTextPadding.top, indicatorTextPadding.right, indicatorTextPadding.bottom); typedArray.recycle(); } this.applyProgressTints(); this.applyThumbTint(); }
From source file:com.android.mylauncher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);//from w ww . j av a2s . c om setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; a.recycle(); setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }