List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.facebook.FacebookButtonBase.java
private void parseTextAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { final int colorResources[] = { android.R.attr.textColor, }; final TypedArray colorAttrs = context.getTheme().obtainStyledAttributes(attrs, colorResources, defStyleAttr, defStyleRes);/* w ww. ja v a 2 s . co m*/ try { setTextColor(colorAttrs.getColor(0, Color.WHITE)); } finally { colorAttrs.recycle(); } final int gravityResources[] = { android.R.attr.gravity, }; final TypedArray gravityAttrs = context.getTheme().obtainStyledAttributes(attrs, gravityResources, defStyleAttr, defStyleRes); try { setGravity(gravityAttrs.getInt(0, Gravity.CENTER)); } finally { gravityAttrs.recycle(); } final int attrsResources[] = { android.R.attr.textSize, android.R.attr.textStyle, android.R.attr.text, }; final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr, defStyleRes); try { setTextSize(TypedValue.COMPLEX_UNIT_PX, a.getDimensionPixelSize(0, 0)); setTypeface(Typeface.defaultFromStyle(a.getInt(1, Typeface.BOLD))); setText(a.getString(2)); } finally { a.recycle(); } }
From source file:com.discord.chipsview.ChipsView.java
private void initAttr(Context context, AttributeSet attrs) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ChipsView, 0, 0); try {// w ww. ja v a2 s . c om mMaxHeight = a.getDimensionPixelSize(R.styleable.ChipsView_cv_max_height, DEFAULT_MAX_HEIGHT); mVerticalSpacing = a.getDimensionPixelSize(R.styleable.ChipsView_cv_vertical_spacing, (int) (DEFAULT_VERTICAL_SPACING * mDensity)); mChipsColor = a.getColor(R.styleable.ChipsView_cv_color, ContextCompat.getColor(context, android.R.color.darker_gray)); mChipsColorClicked = a.getColor(R.styleable.ChipsView_cv_color_clicked, ContextCompat.getColor(context, android.R.color.white)); mChipsBgColor = a.getColor(R.styleable.ChipsView_cv_bg_color, ContextCompat.getColor(context, android.R.color.white)); mChipsBgColorClicked = a.getColor(R.styleable.ChipsView_cv_bg_color_clicked, ContextCompat.getColor(context, android.R.color.holo_blue_dark)); mChipsTextColor = a.getColor(R.styleable.ChipsView_cv_text_color, Color.BLACK); mChipsTextColorClicked = a.getColor(R.styleable.ChipsView_cv_text_color_clicked, Color.WHITE); mChipsPlaceholderResId = a.getResourceId(R.styleable.ChipsView_cv_icon_placeholder, 0); mChipsDeleteResId = a.getResourceId(R.styleable.ChipsView_cv_icon_delete, R.drawable.drawable_chip_delete); mChipsSearchTextColor = a.getColor(R.styleable.ChipsView_cv_search_text_color, Color.BLACK); mChipsSearchTextSize = a.getDimensionPixelSize(R.styleable.ChipsView_cv_search_text_size, 49); mChipLayout = a.getResourceId(R.styleable.ChipsView_cv_chip_layout, R.layout.view_chip_default); } finally { a.recycle(); } }
From source file:com.github.fountaingeyser.typefacecompat.FactoryTypefaceCompat.java
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { View result = null;//from w w w .jav a 2 s . com // Allow base factory to try and create a view first if (mBaseFactory != null) { result = mBaseFactory.onCreateView(parent, name, context, attrs); } if (result instanceof TextView) { TextView textView = (TextView) result; String fontFamily = null; int style = 0; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0); TypedArray appearance = null; int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1); a.recycle(); if (ap != -1) { appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance); } if (appearance != null) { fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily); style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0); appearance.recycle(); } a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0); if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) { fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily); style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0); } a.recycle(); if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) { Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style); if (tf != null) { textView.setTypeface(tf); } } } return result; }
From source file:com.ickphum.android.isoview.IsoCanvas.java
public IsoCanvas(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IsoCanvas, defStyle, defStyle); try {//from ww w .ja v a2s .c o m mBackgroundLineColor = a.getColor(R.styleable.IsoCanvas_backgroundLineColor, mBackgroundLineColor); } finally { a.recycle(); } mPaints[0] = new Paint(); mPaints[0].setColor(Color.CYAN); mPaints[0].setStyle(Paint.Style.FILL); float mHalfWidth = (float) 4.9; float mHalfHeight = (float) 5.6; float quarter_height = mHalfHeight / 2; for (int i = 0; i < 3; i++) { mPaths[i] = new Path(); } mPaths[0].moveTo(0, 0); mPaths[0].lineTo(-mHalfWidth, -quarter_height); mPaths[0].lineTo(-mHalfWidth, quarter_height); mPaths[0].lineTo(0, quarter_height * 2); mPaths[0].setFillType(Path.FillType.WINDING); mPaths[1].moveTo(0, 0); mPaths[1].lineTo(10, 0); mPaths[1].lineTo(10, 10); mPaths[1].lineTo(0, 10); mPaths[1].lineTo(0, 0); mPaths[1].setFillType(Path.FillType.WINDING); initPaints(); // Sets up interactions if (!this.isInEditMode()) { mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); } }
From source file:io.github.hidroh.materialistic.widget.StoryView.java
public StoryView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoryView); mIsLocal = ta.getBoolean(R.styleable.StoryView_local, false); TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorTertiary, android.R.attr.textColorSecondary, R.attr.colorCardBackground, R.attr.colorCardHighlight }); mTertiaryTextColorResId = ContextCompat.getColor(context, a.getResourceId(0, 0)); mSecondaryTextColorResId = ContextCompat.getColor(context, a.getResourceId(1, 0)); mBackgroundColor = ContextCompat.getColor(context, a.getResourceId(2, 0)); mHighlightColor = ContextCompat.getColor(context, a.getResourceId(3, 0)); mPromotedColorResId = ContextCompat.getColor(context, R.color.greenA700); mHotColorResId = ContextCompat.getColor(context, R.color.orange500); mAccentColorResId = ContextCompat.getColor(getContext(), AppUtils.getThemedResId(getContext(), R.attr.colorAccent)); mCommentDrawable = DrawableCompat//from w w w. j a v a 2 s .co m .wrap(ContextCompat.getDrawable(context, R.drawable.ic_comment_white_24dp).mutate()); DrawableCompat.setTint(mCommentDrawable, mAccentColorResId); inflate(context, mIsLocal ? R.layout.local_story_view : R.layout.story_view, this); mBackground = findViewById(R.id.background); mBackground.setBackgroundColor(mBackgroundColor); mVoteSwitcher = (ViewSwitcher) findViewById(R.id.vote_switcher); mRankTextView = (TextView) findViewById(R.id.rank); mScoreTextView = (TextView) findViewById(R.id.score); mBookmarked = findViewById(R.id.bookmarked); mPostedTextView = (TextView) findViewById(R.id.posted); mTitleTextView = (TextView) findViewById(R.id.title); mSourceTextView = (TextView) findViewById(R.id.source); mCommentButton = (TextView) findViewById(R.id.comment); mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null); mMoreButton = findViewById(R.id.button_more); // replace with bounded ripple as unbounded ripple requires container bg // http://b.android.com/155880 mMoreButton.setBackgroundResource(AppUtils.getThemedResId(context, R.attr.selectableItemBackground)); ta.recycle(); a.recycle(); }
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static Context getActionBarThemedContext(Context base, int themeId, int accentColor) { final int actionBarThemeId; if (isDarkTheme(themeId) || TwidereColorUtils.getYIQLuminance(accentColor) <= ACCENT_COLOR_THRESHOLD) { actionBarThemeId = R.style.Theme_Twidere_Dark; } else {/* w w w . j a va 2 s . com*/ actionBarThemeId = R.style.Theme_Twidere_Light; } final Resources.Theme baseTheme = base.getTheme(); final Resources.Theme actionBarTheme = base.getResources().newTheme(); actionBarTheme.setTo(baseTheme); actionBarTheme.applyStyle(actionBarThemeId, true); final ActionBarContextThemeWrapper actionBarContext = new ActionBarContextThemeWrapper(base, actionBarThemeId); actionBarContext.getTheme().setTo(actionBarTheme); return actionBarContext; }
From source file:com.joaquimley.faboptions.FabOptions.java
public FabOptions(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mIsOpen = false;/*from www .jav a2 s. co m*/ initViews(context); setInitialFabIcon(); TypedArray fabOptionsAttributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FabOptions, 0, 0); styleComponent(context, fabOptionsAttributes); inflateButtonsFromAttrs(context, fabOptionsAttributes); }
From source file:eu.faircode.netguard.AccessAdapter.java
public AccessAdapter(Context context, Cursor cursor) { super(context, cursor, 0); colVersion = cursor.getColumnIndex("version"); colProtocol = cursor.getColumnIndex("protocol"); colDaddr = cursor.getColumnIndex("daddr"); colDPort = cursor.getColumnIndex("dport"); colTime = cursor.getColumnIndex("time"); colAllowed = cursor.getColumnIndex("allowed"); colBlock = cursor.getColumnIndex("block"); TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary }); try {//w w w . jav a 2s . co m colorText = ta.getColor(0, 0); } finally { ta.recycle(); } TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data; context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; }
From source file:com.github.pockethub.ui.view.DotPageIndicator.java
/** * Instantiates the view and it's values * @param context//from w w w .java 2s . com * @param attrs */ public DotPageIndicator(Context context, AttributeSet attrs) { super(context, attrs); if (isInEditMode()) return; Resources res = getResources(); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotPageIndicator, 0, 0); try { PAINT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColorSelected, getColor(res, android.R.color.secondary_text_light, context.getTheme()))); PAINT_NOT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColor, getColor(res, android.R.color.secondary_text_dark, context.getTheme()))); dotSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, res.getDisplayMetrics()); dotRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, res.getDisplayMetrics()); dotRadius = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotRadius, (int) dotRadius); dotSpacing = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotSpacing, (int) dotSpacing); } finally { a.recycle(); } dotAlpha = PAINT_SELECTED.getAlpha(); }
From source file:com.github.pockethub.android.ui.view.DotPageIndicator.java
/** * Instantiates the view and it's values * @param context//w w w . ja v a 2 s .c o m * @param attrs */ public DotPageIndicator(Context context, AttributeSet attrs) { super(context, attrs); if (isInEditMode()) { return; } Resources res = getResources(); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotPageIndicator, 0, 0); try { PAINT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColorSelected, getColor(res, android.R.color.secondary_text_light, context.getTheme()))); PAINT_NOT_SELECTED.setColor(a.getColor(R.styleable.DotPageIndicator_dotColor, getColor(res, android.R.color.secondary_text_dark, context.getTheme()))); dotSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, res.getDisplayMetrics()); dotRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, res.getDisplayMetrics()); dotRadius = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotRadius, (int) dotRadius); dotSpacing = a.getDimensionPixelSize(R.styleable.DotPageIndicator_dotSpacing, (int) dotSpacing); } finally { a.recycle(); } dotAlpha = PAINT_SELECTED.getAlpha(); }