List of usage examples for android.content.res TypedArray getColor
@ColorInt public int getColor(@StyleableRes int index, @ColorInt int defValue)
From source file:com.community.yuequ.bottombar.BottomBar.java
private void populateAttributes(Context context, AttributeSet attrs) { primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary); screenWidth = MiscUtils.getScreenWidth(getContext()); tenDp = MiscUtils.dpToPixel(getContext(), 10); maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0); try {/*from ww w .j av a2 s . c om*/ tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0); isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false); behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE); inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1); activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1); @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor); int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor; inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor); activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor); badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED); titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0); titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace)); showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true); } finally { ta.recycle(); } }
From source file:com.appeaser.sublimepickerlibrary.recurrencepicker.RecurrenceOptionCreator.java
void initializeLayout() { int weekButtonUnselectedTextColor, weekButtonSelectedTextColor, weekButtonSelectedCircleColor; final TypedArray a = getContext().obtainStyledAttributes(R.styleable.RecurrenceOptionCreator); try {/*from w w w . j a v a 2 s. co m*/ mHeaderBackgroundColor = a.getColor(R.styleable.RecurrenceOptionCreator_spHeaderBackground, 0); int endDateFormat = a.getInt(R.styleable.RecurrenceOptionCreator_spEndDateFormat, 1); mEndDateFormatter = DateFormat.getDateInstance( endDateFormat == 0 ? DateFormat.SHORT : DateFormat.MEDIUM, Locale.getDefault()); weekButtonUnselectedTextColor = a.getColor( R.styleable.RecurrenceOptionCreator_spWeekButtonUnselectedTextColor, SUtils.COLOR_ACCENT); weekButtonSelectedTextColor = a.getColor( R.styleable.RecurrenceOptionCreator_spWeekButtonSelectedTextColor, SUtils.COLOR_TEXT_PRIMARY_INVERSE); weekButtonSelectedCircleColor = a.getColor( R.styleable.RecurrenceOptionCreator_spWeekButtonSelectedCircleColor, SUtils.COLOR_ACCENT); } finally { a.recycle(); } mResources = getResources(); LayoutInflater.from(getContext()).inflate(R.layout.recurrence_picker, this); mRecurrencePicker = findViewById(R.id.recurrence_picker); mDateOnlyPicker = (RecurrenceEndDatePicker) findViewById(R.id.date_only_picker); mDateOnlyPicker.setVisibility(View.GONE); // OK/Cancel buttons mButtonLayout = (DecisionButtonLayout) findViewById(R.id.roc_decision_button_layout); mButtonLayout.applyOptions(mButtonLayoutCallback); SUtils.setViewBackground(findViewById(R.id.freqSpinnerHolder), mHeaderBackgroundColor, SUtils.CORNER_TOP_LEFT | SUtils.CORNER_TOP_RIGHT); /** EFrequency Spinner {Repeat daily, Repeat weekly, Repeat monthly, Repeat yearly} **/ mFreqSpinner = (Spinner) findViewById(R.id.freqSpinner); mFreqSpinner.setOnItemSelectedListener(this); ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getContext(), R.array.recurrence_freq, R.layout.roc_freq_spinner_item); freqAdapter.setDropDownViewResource(R.layout.roc_spinner_dropdown_item); mFreqSpinner.setAdapter(freqAdapter); Drawable freqSpinnerBg = ContextCompat.getDrawable(getContext(), R.drawable.abc_spinner_mtrl_am_alpha); PorterDuffColorFilter cfFreqSpinner = new PorterDuffColorFilter(SUtils.COLOR_TEXT_PRIMARY_INVERSE, PorterDuff.Mode.SRC_IN); if (freqSpinnerBg != null) { freqSpinnerBg.setColorFilter(cfFreqSpinner); SUtils.setViewBackground(mFreqSpinner, freqSpinnerBg); } mInterval = (EditText) findViewById(R.id.interval); mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) { @Override void onChange(int v) { if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) { mModel.interval = v; updateIntervalText(); mInterval.requestLayout(); } } }); mIntervalPreText = (TextView) findViewById(R.id.intervalPreText); mIntervalPostText = (TextView) findViewById(R.id.intervalPostText); /** End Spinner {Forever, Until a date, For a number of events} **/ mEndNeverStr = mResources.getString(R.string.recurrence_end_continously); mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label); mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label); mEndSpinnerArray.add(mEndNeverStr); mEndSpinnerArray.add(mEndDateLabel); mEndSpinnerArray.add(mEndCountLabel); mEndSpinner = (Spinner) findViewById(R.id.endSpinner); mEndSpinner.setOnItemSelectedListener(this); mEndSpinnerAdapter = new EndSpinnerAdapter(getContext(), mEndSpinnerArray, R.layout.roc_end_spinner_item, R.id.spinner_item, R.layout.roc_spinner_dropdown_item); mEndSpinner.setAdapter(mEndSpinnerAdapter); mEndCount = (EditText) findViewById(R.id.endCount); mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) { @Override void onChange(int v) { if (mModel.endCount != v) { mModel.endCount = v; updateEndCountText(); mEndCount.requestLayout(); } } }); mPostEndCount = (TextView) findViewById(R.id.postEndCount); mEndDateTextView = (TextView) findViewById(R.id.endDate); mEndDateTextView.setOnClickListener(this); SUtils.setViewBackground(mEndDateTextView, SUtils.createButtonBg(getContext(), SUtils.COLOR_BUTTON_NORMAL, SUtils.COLOR_CONTROL_HIGHLIGHT)); // set default & checked state colors WeekButton.setStateColors(weekButtonUnselectedTextColor, weekButtonSelectedTextColor); // AOSP code handled this differently. It has been refactored to // let Android decide if we have enough space to show // all seven 'WeekButtons' inline. In this case, 'mWeekGroup2' // will be null (see @layout-w460dp/week_buttons). mWeekGroup = (LinearLayout) findViewById(R.id.weekGroup); mWeekGroup2 = (LinearLayout) findViewById(R.id.weekGroup2); // Only non-null when available width is < 460dp // Used only for positioning 'WeekButtons' in two rows // of 4 & 3. View eighthWeekDay = findViewById(R.id.week_day_8); if (eighthWeekDay != null) eighthWeekDay.setVisibility(View.INVISIBLE); // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7 //String[] dayOfWeekString = new DateFormatSymbols().getWeekdays(); mMonthRepeatByDayOfWeekStrs = new String[7][]; // from Time.SUNDAY as 0 through Time.SATURDAY as 6 mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun); mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon); mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues); mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed); mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs); mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri); mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat); // In Time.java day of week order e.g. Sun = 0 int idx = RecurrenceUtils.getFirstDayOfWeek(); // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7 String[] dayOfWeekString = new DateFormatSymbols().getShortWeekdays(); // CheckableDrawable's width & height int expandedWidthHeight = mResources.getDimensionPixelSize(R.dimen.week_button_state_on_circle_size); WeekButton[] tempWeekButtons = new WeekButton[7]; tempWeekButtons[0] = (WeekButton) findViewById(R.id.week_day_1); tempWeekButtons[1] = (WeekButton) findViewById(R.id.week_day_2); tempWeekButtons[2] = (WeekButton) findViewById(R.id.week_day_3); tempWeekButtons[3] = (WeekButton) findViewById(R.id.week_day_4); tempWeekButtons[4] = (WeekButton) findViewById(R.id.week_day_5); tempWeekButtons[5] = (WeekButton) findViewById(R.id.week_day_6); tempWeekButtons[6] = (WeekButton) findViewById(R.id.week_day_7); for (int i = 0; i < mWeekByDayButtons.length; i++) { mWeekByDayButtons[idx] = tempWeekButtons[i]; SUtils.setViewBackground(mWeekByDayButtons[idx], new CheckableDrawable(weekButtonSelectedCircleColor, false, expandedWidthHeight)); mWeekByDayButtons[idx].setTextColor(weekButtonUnselectedTextColor); mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]); mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]); mWeekByDayButtons[idx].setOnCheckedChangeListener(this); if (++idx >= 7) { idx = 0; } } mMonthRepeatByRadioGroup = (RadioGroup) findViewById(R.id.monthGroup); mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this); mRepeatMonthlyByNthDayOfWeek = (RadioButton) findViewById(R.id.repeatMonthlyByNthDayOfTheWeek); mRepeatMonthlyByNthDayOfMonth = (RadioButton) findViewById(R.id.repeatMonthlyByNthDayOfMonth); }
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. *//*from w w w.ja va 2 s. c o m*/ 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: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 av a 2 s .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("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:bottombar.BottomBar.java
private void populateAttributes(Context context, AttributeSet attrs) { primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary); screenWidth = MiscUtils.getScreenWidth(getContext()); tenDp = MiscUtils.dpToPixel(getContext(), 10); maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0); try {/* w ww .j a v a2s . c om*/ tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0); isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false); behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE); inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1); activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1); @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor); int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor; inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor); activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor); badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED); hideBadgeWhenActive = ta.getBoolean(R.styleable.BottomBar_bb_badgesHideWhenActive, true); titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0); titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace)); showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true); } finally { ta.recycle(); } }
From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java
/** * Read out the attributes from the given attribute set and initialize whatever they represent. * * @param attributeArray typed array containing the attribute values from the XML file *//* w ww . j a va 2s . c o m*/ private void setupAttributes(TypedArray attributeArray) { String series1Name = attributeArray.getString(R.styleable.RollingGraphView_series1name); if (series1Name == null) { seriesNames = null; } else { String series2Name = attributeArray.getString(R.styleable.RollingGraphView_series2name); if (series2Name == null) { seriesNames = new String[] { series1Name }; } else { String series3Name = attributeArray.getString(R.styleable.RollingGraphView_series3name); if (series3Name == null) { seriesNames = new String[] { series1Name, series2Name }; } else { String series4Name = attributeArray.getString(R.styleable.RollingGraphView_series4name); if (series4Name == null) { seriesNames = new String[] { series1Name, series2Name, series3Name }; } else { seriesNames = new String[] { series1Name, series2Name, series3Name, series4Name }; } } } maxValues = attributeArray.getInt(R.styleable.RollingGraphView_maxValues, -1); seriesPaints = new Paint[seriesNames.length]; seriesPaints[0] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[0] .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series1color, 0xFFFF0000)); seriesPaints[0].setStrokeWidth(attributeArray .getDimension(R.styleable.RollingGraphView_series1thickness, 1 /* dp */ * displayDensity)); seriesPaints[0].setTextSize( attributeArray.getDimension(R.styleable.RollingGraphView_label1textSize, 14 * displayDensity)); if (seriesPaints.length > 1) { seriesPaints[1] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[1] .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series2color, 0xFFFF0000)); seriesPaints[1].setStrokeWidth(attributeArray .getDimension(R.styleable.RollingGraphView_series2thickness, 1 /* dp */ * displayDensity)); seriesPaints[1].setTextSize(attributeArray.getDimension(R.styleable.RollingGraphView_label2textSize, 14 * displayDensity)); if (seriesPaints.length > 2) { seriesPaints[2] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[2].setColor( attributeArray.getColor(R.styleable.RollingGraphView_series3color, 0xFFFF0000)); seriesPaints[2].setStrokeWidth(attributeArray.getDimension( R.styleable.RollingGraphView_series3thickness, 1 /* dp */ * displayDensity)); seriesPaints[2].setTextSize(attributeArray .getDimension(R.styleable.RollingGraphView_label3textSize, 14 * displayDensity)); if (seriesPaints.length > 3) { seriesPaints[3] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[3].setColor( attributeArray.getColor(R.styleable.RollingGraphView_series4color, 0xFFFF0000)); seriesPaints[3].setStrokeWidth(attributeArray.getDimension( R.styleable.RollingGraphView_series4thickness, 1 /* dp */ * displayDensity)); seriesPaints[3].setTextSize(attributeArray .getDimension(R.styleable.RollingGraphView_label4textSize, 14 * displayDensity)); } } } background = getBackground(); if (background == null) { background = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.white)); } } horizontal = attributeArray.getInt(R.styleable.RollingGraphView_android_orientation, 0) == 0; }
From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java
/** * ?//from w ww. j a v a2 s. c o m * @param attrs */ private void init(AttributeSet attrs) { mCollapsedStatus = new SparseBooleanArray(); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines, MAX_COLLAPSED_LINES); mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION); mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable); mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable); textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse); textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand); showExpandCollapseDrawable = typedArray .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true); if (showExpandCollapseDrawable) { if (mExpandDrawable == null) { mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down); } if (mCollapseDrawable == null) { mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up); } } if (TextUtils.isEmpty(textCollapse)) { textCollapse = getContext().getString(R.string.shink); } if (TextUtils.isEmpty(textExpand)) { textExpand = getContext().getString(R.string.expand); } contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor, ContextCompat.getColor(getContext(), R.color.light_gray)); contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, DisplayUtil.sp2px(14)); collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor, ContextCompat.getColor(getContext(), R.color.main_color)); collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, DisplayUtil.sp2px(14)); grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT); typedArray.recycle(); // enforces vertical orientation setOrientation(LinearLayout.VERTICAL); // default visibility is gone setVisibility(GONE); }
From source file:com.facebook.widget.LikeView.java
private void parseAttributes(AttributeSet attrs) { if (attrs == null || getContext() == null) { return;/* w ww. java 2s . c o m*/ } TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_like_view); if (a == null) { return; } objectId = Utility.coerceValueIfNullOrEmpty(a.getString(R.styleable.com_facebook_like_view_object_id), null); likeViewStyle = Style.fromInt(a.getInt(R.styleable.com_facebook_like_view_style, Style.DEFAULT.getValue())); if (likeViewStyle == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'style'"); } auxiliaryViewPosition = AuxiliaryViewPosition .fromInt(a.getInt(R.styleable.com_facebook_like_view_auxiliary_view_position, AuxiliaryViewPosition.DEFAULT.getValue())); if (auxiliaryViewPosition == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'auxiliary_view_position'"); } horizontalAlignment = HorizontalAlignment.fromInt(a.getInt( R.styleable.com_facebook_like_view_horizontal_alignment, HorizontalAlignment.DEFAULT.getValue())); if (horizontalAlignment == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'horizontal_alignment'"); } foregroundColor = a.getColor(R.styleable.com_facebook_like_view_foreground_color, NO_FOREGROUND_COLOR); a.recycle(); }
From source file:com.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java
public TitlePageIndicator(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); // 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 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); // Retrieve styles attributes final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, R.style.Widget_TitlePageIndicator); // Retrieve the colors to be used for this view and apply them. this.mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight);/*from w ww . ja va2 s . c o m*/ this.mFooterIndicatorStyle = IndicatorStyle.fromValue( a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle)); this.mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight); this.mFooterIndicatorUnderlinePadding = a.getDimension( R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding); this.mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding); this.mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding); this.mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding); this.mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor); this.mColorText = a.getColor(R.styleable.TitlePageIndicator_textColor, defaultTextColor); this.mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold); final float textSize = a.getDimension(R.styleable.TitlePageIndicator_textSize, defaultTextSize); final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor); this.mPaintText = new Paint(); this.mPaintText.setTextSize(textSize); this.mPaintText.setAntiAlias(true); this.mPaintFooterLine = new Paint(); this.mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE); this.mPaintFooterLine.setStrokeWidth(this.mFooterLineHeight); this.mPaintFooterLine.setColor(footerColor); this.mPaintFooterIndicator = new Paint(); this.mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE); this.mPaintFooterIndicator.setColor(footerColor); a.recycle(); this.mPath = new Path(); }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
private void init(Context context, AttributeSet attrs) { detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from ww w . ja v a2 s. co m*/ public boolean onDown(MotionEvent event) { boolean isMarkerInChord = false; int fret = NO_FRET, string = -1; fret = getSelectedFret(event); string = getSelectedString(event); touchEventMarker = new ChordMarker(string, fret, NO_FINGER); return true; } @Override public void onLongPress(MotionEvent event) { if (editable && touchEventMarker != null && chord != null && chord.contains(touchEventMarker)) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(GuitarChordView.this, InputMethodManager.SHOW_IMPLICIT); } } }); chord = new Chord(); showFretNumbers = true; showFingerNumbers = true; editable = false; stringCount = 6; listeners = new ArrayList<>(); fretNumberListeners = new ArrayList<>(); stringListeners = new ArrayList<>(); touchEventMarker = null; mutedText = MUTED_TEXT; openStringText = OPEN_STRING_TEXT; initPaint(); if (attrs != null) { //TODO handle custom attribute values TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.GuitarChordView, 0, 0); try { bridgeNutColor = a.getColor(R.styleable.GuitarChordView_bridgeNutColor, DEFAULT_COLOR); bridgeNutPaint.setColor(bridgeNutColor); fretMarkerColor = a.getColor(R.styleable.GuitarChordView_fretMarkerColor, DEFAULT_COLOR); fretMarkerPaint.setColor(fretMarkerColor); stringColor = a.getColor(R.styleable.GuitarChordView_stringColor, DEFAULT_COLOR); stringPaint.setColor(stringColor); fretNumberColor = a.getColor(R.styleable.GuitarChordView_fretNumberColor, DEFAULT_COLOR); fretNumberPaint.setColor(fretNumberColor); stringMarkerColor = a.getColor(R.styleable.GuitarChordView_stringMarkerColor, DEFAULT_COLOR); stringMarkerPaint.setColor(stringMarkerColor); noteColor = a.getColor(R.styleable.GuitarChordView_noteColor, DEFAULT_COLOR); notePaint.setColor(noteColor); noteNumberColor = a.getColor(R.styleable.GuitarChordView_noteNumberColor, WHITE); noteNumberPaint.setColor(noteNumberColor); barLineColor = a.getColor(R.styleable.GuitarChordView_barLineColor, DEFAULT_COLOR); barLinePaint.setColor(barLineColor); mutedText = a.getString(R.styleable.GuitarChordView_mutedText); mutedText = (mutedText == null) ? MUTED_TEXT : mutedText; openStringText = a.getString(R.styleable.GuitarChordView_openStringText); openStringText = (openStringText == null) ? OPEN_STRING_TEXT : openStringText; stringCount = a.getInt(R.styleable.GuitarChordView_stringAmount, 6); editable = a.getBoolean(R.styleable.GuitarChordView_editable, false); showFingerNumbers = a.getBoolean(R.styleable.GuitarChordView_showFingerNumbers, true); showFretNumbers = a.getBoolean(R.styleable.GuitarChordView_showFretNumbers, true); } catch (Exception e) { e.printStackTrace(); } finally { a.recycle(); } } }