List of usage examples for android.content.res TypedArray getInt
public int getInt(@StyleableRes int index, int defValue)
From source file:com.bitflake.counter.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);//from w w w . ja v a 2s . co m textPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = this.sideItems; try { textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (textColor == null) { textColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, marqueeRepeatLimit); dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt(); boringMetrics = new BoringLayout.Metrics(); boringMetrics.ascent = fontMetricsInt.ascent; boringMetrics.bottom = fontMetricsInt.bottom; boringMetrics.descent = fontMetricsInt.descent; boringMetrics.leading = fontMetricsInt.leading; boringMetrics.top = fontMetricsInt.top; boringMetrics.width = itemWidth; setWillNotDraw(false); flingScrollerX = new OverScroller(context); adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; overscrollDistance = configuration.getScaledOverscrollDistance(); previousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); touchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, touchHelper); }
From source file:android.support.v7.widget.SwitchCompat.java
/** * Sets the switch text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. *//*from w w w .j a va 2s .c om*/ public void setSwitchTextAppearance(Context context, int resid) { TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.TextAppearance); ColorStateList colors; int ts; colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColor); if (colors != null) { mTextColors = colors; } else { // If no color set in TextAppearance, default to the view's textColor mTextColors = getTextColors(); } ts = appearance.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); if (ts != 0) { if (ts != mTextPaint.getTextSize()) { mTextPaint.setTextSize(ts); requestLayout(); } } int typefaceIndex, styleIndex; typefaceIndex = appearance.getInt(R.styleable.TextAppearance_android_typeface, -1); styleIndex = appearance.getInt(R.styleable.TextAppearance_android_textStyle, -1); setSwitchTypefaceByIndex(typefaceIndex, styleIndex); boolean allCaps = appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false); if (allCaps) { mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext()); } else { mSwitchTransformationMethod = null; } appearance.recycle(); }
From source file:android.support.v7ox.widget.SwitchCompat.java
/** * Sets the switch text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. *//* www.j a va2 s . c om*/ public void setSwitchTextAppearance(Context context, int resid) { TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.TextAppearance); ColorStateList colors; int ts; colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColor); if (colors != null) { mTextColors = colors; } else { // If no color set in TextAppearance, default to the view's textColor mTextColors = getTextColors(); } ts = appearance.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); if (ts != 0) { if (ts != mTextPaint.getTextSize()) { mTextPaint.setTextSize(ts); requestLayout(); } } int typefaceIndex, styleIndex; typefaceIndex = appearance.getInt(R.styleable.TextAppearance_android_typeface, -1); styleIndex = appearance.getInt(R.styleable.TextAppearance_android_textStyle, -1); setSwitchTypefaceByIndex(typefaceIndex, styleIndex); boolean allCaps = appearance.getBoolean(R.styleable.TextAppearance_textAllCaps_ox, false); if (allCaps) { mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext()); } else { mSwitchTransformationMethod = null; } appearance.recycle(); }
From source file:com.kuloud.android.calendarview.CalendarView.java
public CalendarView(Context context, AttributeSet attrs) { super(context, attrs); setClipChildren(false);/* w ww . ja va 2 s . c o m*/ setClipToPadding(false); pager = new ViewPager(getContext()); setupChildren(); titleChanger = new TitleChanger(topbar); titleChanger.setTitleFormatter(DEFAULT_TITLE_FORMATTER); adapter = new MonthPagerAdapter(this); pager.setAdapter(adapter); pager.setOnPageChangeListener(pageChangeListener); pager.setPageTransformer(false, new ViewPager.PageTransformer() { @Override public void transformPage(View page, float position) { position = (float) Math.sqrt(1 - Math.abs(position)); page.setAlpha(position); } }); adapter.setCallbacks(monthViewCallbacks); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CalendarView, 0, 0); try { int tileSize = a.getDimensionPixelSize(R.styleable.CalendarView_mcv_tileSize, -1); if (tileSize > 0) { setTileSize(tileSize); } setSelectionColor( a.getColor(R.styleable.CalendarView_mcv_selectionColor, getThemeAccentColor(context))); CharSequence[] array = a.getTextArray(R.styleable.CalendarView_mcv_weekDayLabels); if (array != null) { setWeekDayFormatter(new ArrayWeekDayFormatter(array)); } array = a.getTextArray(R.styleable.CalendarView_mcv_monthLabels); if (array != null) { setTitleFormatter(new MonthArrayTitleFormatter(array)); } setShowOtherDates(a.getBoolean(R.styleable.CalendarView_mcv_showOtherDates, false)); int firstDayOfWeek = a.getInt(R.styleable.CalendarView_mcv_firstDayOfWeek, -1); if (firstDayOfWeek < 0) { firstDayOfWeek = CalendarUtils.getInstance().getFirstDayOfWeek(); } setFirstDayOfWeek(firstDayOfWeek); } catch (Exception e) { e.printStackTrace(); } finally { if (a != null) { a.recycle(); } } currentMonth = CalendarDay.today(); setCurrentDate(currentMonth); }
From source file:com.owen.view.views.PieChart.java
/** * Class constructor taking a context and an attribute set. This constructor * is used by the layout engine to construct a {@link com.owen.view.views.PieChart} from a set of * XML attributes./* w ww. jav a 2 s .co m*/ * * @param context * @param attrs An attribute set which can contain attributes from * {@link PieChart} as well as attributes inherited * from {@link android.view.View}. */ public PieChart(Context context, AttributeSet attrs) { super(context, attrs); // attrs contains the raw values for the XML attributes // that were specified in the layout, which don't include // attributes set by styles or themes, and which may have // unresolved references. Call obtainStyledAttributes() // to get the final values for each attribute. // // This call uses R.styleable.PieChart, which is an array of // the custom attributes that were declared in attrs.xml. TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0); try { // Retrieve the values from the TypedArray and store into // fields of this class. // // The R.styleable.PieChart_* constants represent the index for // each custom attribute in the R.styleable.PieChart array. mShowText = a.getBoolean(R.styleable.PieChart_pie_showText, false); mTextY = a.getDimension(R.styleable.PieChart_pie_labelY, 0.0f); mTextWidth = a.getDimension(R.styleable.PieChart_pie_labelWidth, 0.0f); mTextHeight = a.getDimension(R.styleable.PieChart_pie_labelHeight, 0.0f); mTextPos = a.getInteger(R.styleable.PieChart_pie_labelPosition, 0); mTextColor = a.getColor(R.styleable.PieChart_pie_labelColor, 0xff000000); mHighlightStrength = a.getFloat(R.styleable.PieChart_pie_highlightStrength, 1.0f); mPieRotation = a.getInt(R.styleable.PieChart_pie_pieRotation, 0); mPointerRadius = a.getDimension(R.styleable.PieChart_pie_pointerRadius, 2.0f); mAutoCenterInSlice = a.getBoolean(R.styleable.PieChart_pie_autoCenterPointerInSlice, false); } finally { // release the TypedArray so that it can be reused. a.recycle(); } init(); }
From source file:com.android.launcher2.AsyncTaskCallback.java
public AppsCustomizePagedView(Context context, AttributeSet attrs) { super(context, attrs); mLayoutInflater = LayoutInflater.from(context); mPackageManager = context.getPackageManager(); mApps = new ArrayList<ApplicationInfo>(); mWidgets = new ArrayList<Object>(); mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache(); mCanvas = new Canvas(); mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>(); // Save the default widget preview background Resources resources = context.getResources(); mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0); mMaxAppCellCountX = a.getInt(R.styleable.AppsCustomizePagedView_maxAppCellCountX, -1); mMaxAppCellCountY = a.getInt(R.styleable.AppsCustomizePagedView_maxAppCellCountY, -1); mWidgetWidthGap = a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellWidthGap, 0); mWidgetHeightGap = a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellHeightGap, 0); mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2); mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2); mClingFocusedX = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedX, 0); mClingFocusedY = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedY, 0); a.recycle();/* ww w . j ava 2 s .co m*/ mWidgetSpacingLayout = new PagedViewCellLayout(getContext()); // The padding on the non-matched dimension for the default widget preview icons // (top + bottom) mFadeInAdjacentScreens = false; // Unless otherwise specified this view is important for accessibility. if (ViewCompat.getImportantForAccessibility(this) == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, View.IMPORTANT_FOR_ACCESSIBILITY_YES); } }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called from one of constructors of this view to perform its initialization. * <p>/*from w ww. j av a 2 s.c om*/ * 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("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mContext = context; setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); this.inflateHierarchy(context, R.layout.ui_search_view); this.mProgressBarAnimator = createProgressBarAnimator(); this.mDefaultRevealAnimationHandler = createRevealAnimationHandler(); ColorStateList tintList = null; PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SearchView_android_queryHint) { setQueryHint(typedArray.getText(index)); } else if (index == R.styleable.Ui_SearchView_uiTint) { tintList = typedArray.getColorStateList(index); } else if (index == R.styleable.Ui_SearchView_uiTintMode) { tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0), tintList != null ? PorterDuff.Mode.SRC_IN : null); } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) { mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) { mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) { final int resId = typedArray.getResourceId(index, 0); if (resId != 0) { mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context, resId); } } } typedArray.recycle(); } if (tintList != null || tintMode != null) { this.mTintInfo = new SearchTintInfo(); this.mTintInfo.tintList = tintList; this.mTintInfo.hasTintList = tintList != null; this.mTintInfo.tintMode = tintMode; this.mTintInfo.hasTintMode = tintMode != null; } final Resources.Theme theme = context.getTheme(); final TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) { if (mTintInfo == null) { this.mTintInfo = new SearchTintInfo(); } if (typedValue.resourceId > 0) { mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(), typedValue.resourceId, theme); } else { mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data); } mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null; } this.applyTint(); this.mRevealAnimationHandler = mDefaultRevealAnimationHandler; }
From source file:com.grottworkshop.gwsvectorsandboxlib.VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; // Account for any configuration changes. state.mChangingConfigurations |= Utils.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs(); final int tintMode = a.getInt(R.styleable.VectorDrawable_mv_tintMode, -1); if (tintMode != -1) { state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE); }/*from w w w. j av a2s .co m*/ final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_mv_tint); if (tint != null) { state.mTint = tint; } state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_mv_autoMirrored, state.mAutoMirrored); pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_mv_viewportWidth, pathRenderer.mViewportWidth); pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_mv_viewportHeight, pathRenderer.mViewportHeight); if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportWidth > 0"); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportHeight > 0"); } pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_mv_width, pathRenderer.mBaseWidth); pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_mv_height, pathRenderer.mBaseHeight); if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0"); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0"); } final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_mv_alpha, pathRenderer.getAlpha()); pathRenderer.setAlpha(alphaInFloat); final String name = a.getString(R.styleable.VectorDrawable_mv_name); if (name != null) { pathRenderer.mRootName = name; pathRenderer.mVGTargetsMap.put(name, pathRenderer); } }
From source file:com.john.main.VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; // Account for any configuration changes. state.mChangingConfigurations |= Utils.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs(); final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1); if (tintMode != -1) { state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE); }//w w w.java2 s.c o m final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint); if (tint != null) { state.mTint = tint; } state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored); pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth); pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight); if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportWidth > 0"); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportHeight > 0"); } pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth); pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight); if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0"); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0"); } final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha()); pathRenderer.setAlpha(alphaInFloat); final String name = a.getString(R.styleable.VectorDrawable_name); if (name != null) { pathRenderer.mRootName = name; pathRenderer.mVGTargetsMap.put(name, pathRenderer); } }
From source file:com.hippo.vector.VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; // Account for any configuration changes. state.mChangingConfigurations |= Utils.getChangingConfigurations(a); final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1); if (tintMode != -1) { state.mTintMode = Utils.parseTintMode(tintMode, Mode.SRC_IN); }/*from w w w . j a va 2 s . co m*/ final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint); if (tint != null) { state.mTint = tint; } state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored); setAllowCaching(a.getBoolean(R.styleable.VectorDrawable_allowCaching, true)); pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth); pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight); if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportWidth > 0"); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportHeight > 0"); } pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth); pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight); if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0"); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0"); } final int insetLeft = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetLeft, pathRenderer.mOpticalInsets.left); final int insetTop = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetTop, pathRenderer.mOpticalInsets.top); final int insetRight = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetRight, pathRenderer.mOpticalInsets.right); final int insetBottom = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetBottom, pathRenderer.mOpticalInsets.bottom); pathRenderer.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom); final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha()); pathRenderer.setAlpha(alphaInFloat); final String name = a.getString(R.styleable.VectorDrawable_name); if (name != null) { pathRenderer.mRootName = name; pathRenderer.mVGTargetsMap.put(name, pathRenderer); } }