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.albedinsky.android.ui.navigation.NavigationLayout.java
/** * Called from one of constructors of this view to perform its initialization. * <p>/*from w w w . j a v a 2 s . c o 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("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { mLayoutInflater = LayoutInflater.from(context); int initialLayout = 0; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_NavigationLayout, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { int index = typedArray.getIndex(i); if (index == R.styleable.Ui_NavigationLayout_android_initialLayout) { initialLayout = typedArray.getResourceId(index, initialLayout); } else if (index == R.styleable.Ui_NavigationLayout_uiNavigationDrawerShadow) { final int resId = typedArray.getResourceId(index, -1); if (resId != -1) setDrawerShadow(resId, NAVIGATION_DRAWER_GRAVITY); } else if (index == R.styleable.Ui_NavigationLayout_uiColorScrim) { setScrimColor(typedArray.getColor(index, Color.TRANSPARENT)); } } typedArray.recycle(); } if (initialLayout != 0) { mLayoutInflater.inflate(initialLayout, this); this.handleInflationFinished(); } }
From source file:com.along.altmcssd.pda.widget.viewpagerindicator.UnderlinePageIndicator.java
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from w ww. j a v a 2s.co m final Resources res = getResources(); // Load defaults from resources final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.aosijia.dragonbutler.ui.widget.UnderlinePageIndicator.java
@SuppressWarnings("deprecation") public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/* w w w. j ava2 s .c o m*/ final Resources res = getResources(); //Load defaults from resources final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:banner.edgar.com.banner.UnderlinePageIndicator.java
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from w w w . j a va2s. com final Resources res = getResources(); //Load defaults from resources final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); }
From source file:com.appsimobile.appsii.module.appsiagenda.MonthView.java
public MonthView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MonthView, 0, R.style.MonthViewStyle); mDayOfWeekTypeface = a.getString(R.styleable.MonthView_monthview_dayOfWeekTypeface); mMonthTitleTypeface = a.getString(R.styleable.MonthView_monthview_monthTitleTypeface); mDayTextColor = a.getColor(R.styleable.MonthView_monthview_dayTextColor, 0xFF999999); mTodayNumberColor = a.getColor(R.styleable.MonthView_monthview_todayNumberColor, 0xFF33b5e5); mDisabledDayTextColor = a.getColor(R.styleable.MonthView_monthview_disabledDayTextColor, 0xFFcccccc); mMonthTitleColor = a.getColor(R.styleable.MonthView_monthview_monthTitleColor, 0xFFFFFFFF); mMonthTitleBGColor = a.getColor(R.styleable.MonthView_monthview_monthTitleBGColor, 0xFFF2F2F2); MINI_DAY_NUMBER_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_miniDayNumberTextSize, 24);/*w w w . j ava 2s. c o m*/ MONTH_LABEL_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_monthLabelTextSize, 24); MONTH_DAY_LABEL_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_monthDayLabelTextSize, 24); MONTH_HEADER_SIZE = a.getDimensionPixelOffset(R.styleable.MonthView_monthview_headerSize, 24); DAY_SELECTED_CIRCLE_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_daySelectedCircleSize, 24); mRowHeight = (a.getDimensionPixelOffset(R.styleable.MonthView_monthview_viewHeight, 24) - getMonthHeaderSize()) / MAX_NUM_ROWS; a.recycle(); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); if (!isInEditMode()) { // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; } else { mTouchHelper = null; } // Sets up any standard paints that will be used initView(); }
From source file:android.hqs.view.pager.indicator.UnderlinePageIndicator.java
/** * ?/* ww w . j av a2 s.c o m*/ * @param context * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; final Resources res = getResources(); //Load defaults from resources final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_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:com.albedinsky.android.support.ui.widget.ViewPagerWidget.java
/** * Creates a new instance of ViewPagerWidget 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 ww . ja va2s. com public ViewPagerWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ViewPager, defStyleAttr, 0); if (typedArray != null) { this.ensurePullController(); mPullController.setUpFromAttrs(context, attrs, defStyleAttr); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_Widget_ViewPager_android_background) { int resID = typedArray.getResourceId(index, -1); if (resID != -1) { setBackgroundResource(resID); } else { setBackgroundColor(typedArray.getColor(0, Color.TRANSPARENT)); } } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMargin) { setPageMargin(typedArray.getDimensionPixelSize(index, 0)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMarginDrawable) { setPageMarginDrawable(typedArray.getDrawable(index)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageSwipingEnabled) { updatePrivateFlags(PFLAG_PAGE_SWIPING_ENABLED, typedArray.getBoolean(index, true)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingEnabled) { updatePrivateFlags(PFLAG_PAGE_FLING_SWIPING_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingSensitivity) { this.mPageFlingSwipingSensitivity = Math.max(0, typedArray.getFloat(index, mPageFlingSwipingSensitivity)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiCurrentPage) { this.mCurrentPage = typedArray.getInteger(index, 0); } else if (index == R.styleable.Ui_Widget_ViewPager_uiOffScreenPageLimit) { setOffscreenPageLimit(typedArray.getInt(index, getOffscreenPageLimit())); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollDuration) { this.mPageScrollDuration = typedArray.getInteger(index, mPageScrollDuration); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollRelativeDurationEnabled) { updatePrivateFlags(PFLAG_PAGE_SCROLL_RELATIVE_DURATION_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPullEnabled) { setPullEnabled(typedArray.getBoolean(index, false)); } } } // Override default scroller so we can use custom durations for scroll if requested. this.mScroller = new WidgetScroller(context, SCROLLER_INTERPOLATOR); }
From source file:android.support.v7ox.app.AlertController.java
public AlertController(Context context, AppCompatDialog di, Window window) { mContext = context;/*from w ww . j a va 2 s . com*/ mDialog = di; mWindow = window; mHandler = new ButtonHandler(di); final TypedArray a = context.obtainStyledAttributes(null, R.styleable.AlertDialog, R.attr.alertDialogStyle_ox, 0); mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0); mButtonPanelSideLayout = a.getResourceId(R.styleable.AlertDialog_buttonPanelSideLayout, 0); mListLayout = a.getResourceId(R.styleable.AlertDialog_listLayout, 0); mMultiChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_multiChoiceItemLayout, 0); mSingleChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, 0); mListItemLayout = a.getResourceId(R.styleable.AlertDialog_listItemLayout, 0); a.recycle(); }
From source file:com.android.core.view.indicator.UnderlinePageIndicator.java
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from w w w . ja v a2 s . c o m final Resources res = getResources(); //Load defaults from resources final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); final float defaultLineWidth = 0f; //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); setLineWidth(a.getDimension(R.styleable.UnderlinePageIndicator_line_width, defaultLineWidth)); Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:android.support.v7.app.AlertController.java
public AlertController(Context context, AppCompatDialog di, Window window) { mContext = context;/*from ww w. j av a2 s . c o m*/ mDialog = di; mWindow = window; mHandler = new ButtonHandler(di); final TypedArray a = context.obtainStyledAttributes(null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0); mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0); mButtonPanelSideLayout = a.getResourceId(R.styleable.AlertDialog_buttonPanelSideLayout, 0); mListLayout = a.getResourceId(R.styleable.AlertDialog_listLayout, 0); mMultiChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_multiChoiceItemLayout, 0); mSingleChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, 0); mListItemLayout = a.getResourceId(R.styleable.AlertDialog_listItemLayout, 0); a.recycle(); /* We use a custom title so never request a window title */ di.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); }