List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.leo.tablayout.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TabView, defStyle, 0); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); if (attr == R.styleable.TabView_selected_indicator_width) { mSelectedIndicatorWidth = a.getDimensionPixelSize(attr, -1); } else if (attr == R.styleable.TabView_selected_indicator_height) { mSelectedIndicatorheight = a.getDimensionPixelSize(attr, -1); }/*from w ww .j a v a 2s .c om*/ } a.recycle(); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true); mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTabStrip = new SlidingTabStrip(context, mSelectedIndicatorWidth, mSelectedIndicatorheight); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); }
From source file:com.grottworkshop.gwsmaterialcalendarview.MaterialCalendarView.java
private static int getThemeAccentColor(Context context) { int colorAttr; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { colorAttr = android.R.attr.colorAccent; } else {//from w ww. ja v a 2 s . c om //Get colorAccent defined for AppCompat colorAttr = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); } TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(colorAttr, outValue, true); return outValue.data; }
From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java
/** * Configure the TextViews that will show the attachments of the new. * * @param textView TextView to be configured. * @param title Text shown in TextView * @param downloadLink Link attached to TextView. * @param fileType Type of file of the attachment. * @param context The context of activity. */// w ww . j a va 2 s . c om public static void configureTextView(TextView textView, String title, final String downloadLink, Attachment.FILE_TYPE fileType, final Context context) { final int TEXT_VIEW_MIN_HEIGHT = 40; final int TEXT_VIEW_MARGIN_TOP = 4; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(0, convertDpToPx(TEXT_VIEW_MARGIN_TOP, context), 0, 0); textView.setLayoutParams(params); textView.setText(title); textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); textView.setMinHeight(convertDpToPx(TEXT_VIEW_MIN_HEIGHT, context)); textView.setGravity(Gravity.CENTER_VERTICAL); switch (fileType) { case FILE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file, 0, 0, 0); break; case IMAGE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_photo, 0, 0, 0); break; case FOLDER: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_folder, 0, 0, 0); break; default: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_link, 0, 0, 0); break; } textView.setCompoundDrawablePadding(convertDpToPx(4, context)); TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true); textView.setBackgroundResource(typedValue.resourceId); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Navigator.getInstance().openUrl(context, downloadLink); } }); }
From source file:lewa.support.v7.internal.widget.AbsActionBarView.java
AbsActionBarView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); ///LEWA ADD BEGIN this.mContext = context; ///LEWA ADD END final TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(R.attr.actionBarPopupTheme, tv, true) && tv.resourceId != 0) { mPopupContext = new ContextThemeWrapper(context, tv.resourceId); } else {/*from w w w. j a v a 2s .c o m*/ mPopupContext = context; } }
From source file:com.android.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java
public ExpandedAlarmViewHolder(View itemView, boolean hasVibrator) { super(itemView); final Context context = itemView.getContext(); mHasVibrator = hasVibrator;/*from w w w . j av a2 s . co m*/ mDayOrder = DayOrderUtils.getDayOrder(context); final Resources.Theme theme = context.getTheme(); int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray typedArray = theme.obtainStyledAttributes(attrs); final LayerDrawable background = new LayerDrawable( new Drawable[] { ContextCompat.getDrawable(context, R.drawable.alarm_background_expanded), typedArray.getDrawable(0) }); itemView.setBackground(background); typedArray.recycle(); final int firstDay = Utils.getZeroIndexedFirstDayOfWeek(context); delete = (ImageButton) itemView.findViewById(R.id.delete); repeat = (CheckBox) itemView.findViewById(R.id.repeat_onoff); vibrate = (CheckBox) itemView.findViewById(R.id.vibrate_onoff); ringtone = (TextView) itemView.findViewById(R.id.choose_ringtone); editLabel = (TextView) itemView.findViewById(R.id.edit_label); repeatDays = (LinearLayout) itemView.findViewById(R.id.repeat_days); // Build button for each day. LayoutInflater mInflater = LayoutInflater.from(context); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final CompoundButton dayButton = (CompoundButton) mInflater.inflate(R.layout.day_button, repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i, firstDay)); dayButton.setContentDescription(Utils.getLongWeekday(i, firstDay)); repeatDays.addView(dayButton); dayButtons[i] = dayButton; } // Collapse handler itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); arrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); // Edit time handler clock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onClockClicked(getItemHolder().item); } }); // Edit label handler editLabel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onEditLabelClicked(getItemHolder().item); } }); // Vibrator checkbox handler vibrate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().setAlarmVibrationEnabled(getItemHolder().item, ((CheckBox) v).isChecked()); } }); // Ringtone editor handler ringtone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onRingtoneClicked(getItemHolder().item); } }); // Delete alarm handler delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onDeleteClicked(getItemHolder().item); v.announceForAccessibility(context.getString(R.string.alarm_deleted)); } }); // Repeat checkbox handler repeat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean checked = ((CheckBox) view).isChecked(); getAlarmTimeClickHandler().setAlarmRepeatEnabled(getItemHolder().item, checked); } }); // Day buttons handler for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final int buttonIndex = i; dayButtons[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isChecked = ((CompoundButton) view).isChecked(); getAlarmTimeClickHandler().setDayOfWeekEnabled(getItemHolder().item, isChecked, buttonIndex); } }); } }
From source file:com.wizardsofm.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java
public ExpandedAlarmViewHolder(View itemView, boolean hasVibrator) { super(itemView); final Context context = itemView.getContext(); mHasVibrator = hasVibrator;//from ww w . j a v a2 s . co m mDayOrder = DayOrderUtils.getDayOrder(context); final Resources.Theme theme = context.getTheme(); int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray typedArray = theme.obtainStyledAttributes(attrs); final LayerDrawable background = new LayerDrawable(new Drawable[] { ContextCompat.getDrawable(context, com.wizardsofm.deskclock.R.drawable.alarm_background_expanded), typedArray.getDrawable(0) }); itemView.setBackground(background); typedArray.recycle(); final int firstDay = Utils.getZeroIndexedFirstDayOfWeek(context); delete = (ImageButton) itemView.findViewById(com.wizardsofm.deskclock.R.id.delete); repeat = (CheckBox) itemView.findViewById(com.wizardsofm.deskclock.R.id.repeat_onoff); vibrate = (CheckBox) itemView.findViewById(com.wizardsofm.deskclock.R.id.vibrate_onoff); ringtone = (TextView) itemView.findViewById(com.wizardsofm.deskclock.R.id.choose_ringtone); editLabel = (TextView) itemView.findViewById(com.wizardsofm.deskclock.R.id.edit_label); repeatDays = (LinearLayout) itemView.findViewById(com.wizardsofm.deskclock.R.id.repeat_days); // Build button for each day. LayoutInflater mInflater = LayoutInflater.from(context); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final CompoundButton dayButton = (CompoundButton) mInflater .inflate(com.wizardsofm.deskclock.R.layout.day_button, repeatDays, false /* attachToRoot */); dayButton.setText(Utils.getShortWeekday(i, firstDay)); dayButton.setContentDescription(Utils.getLongWeekday(i, firstDay)); repeatDays.addView(dayButton); dayButtons[i] = dayButton; } // Collapse handler itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); arrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getItemHolder().collapse(); } }); // Edit time handler clock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onClockClicked(getItemHolder().item); } }); // Edit label handler editLabel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onEditLabelClicked(getItemHolder().item); } }); // Vibrator checkbox handler vibrate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().setAlarmVibrationEnabled(getItemHolder().item, ((CheckBox) v).isChecked()); } }); // Ringtone editor handler ringtone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getAlarmTimeClickHandler().onRingtoneClicked(getItemHolder().item); } }); // Delete alarm handler delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAlarmTimeClickHandler().onDeleteClicked(getItemHolder().item); v.announceForAccessibility(context.getString(com.wizardsofm.deskclock.R.string.alarm_deleted)); } }); // Repeat checkbox handler repeat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean checked = ((CheckBox) view).isChecked(); getAlarmTimeClickHandler().setAlarmRepeatEnabled(getItemHolder().item, checked); } }); // Day buttons handler for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final int buttonIndex = i; dayButtons[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isChecked = ((CompoundButton) view).isChecked(); getAlarmTimeClickHandler().setDayOfWeekEnabled(getItemHolder().item, isChecked, buttonIndex); } }); } }
From source file:com.android.messaging.ui.CustomHeaderViewPager.java
public CustomHeaderViewPager(final Context context, final AttributeSet attrs) { super(context, attrs); final LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.custom_header_view_pager, this, true); setOrientation(LinearLayout.VERTICAL); mTabstrip = (ViewPagerTabs) findViewById(R.id.tab_strip); mViewPager = (ViewPager) findViewById(R.id.pager); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); mDefaultTabStripSize = context.getResources().getDimensionPixelSize(tv.resourceId); }
From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java
private void parseStyle(Context context, AttributeSet attrs, int defStyle) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, com.layer.atlas.R.styleable.AtlasMessageComposer, com.layer.atlas.R.attr.AtlasMessageComposer, defStyle);/*from w ww . j ava2 s . c om*/ mEnabled = ta.getBoolean(com.layer.atlas.R.styleable.AtlasMessageComposer_android_enabled, true); this.mTextColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_text_black)); this.mTextSize = ta.getDimensionPixelSize(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextSize, context.getResources().getDimensionPixelSize(com.layer.atlas.R.dimen.atlas_text_size_input)); this.mTextStyle = ta.getInt(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextStyle, Typeface.NORMAL); String typeFaceName = ta.getString(com.layer.atlas.R.styleable.AtlasMessageComposer_inputTextTypeface); this.mTypeFace = typeFaceName != null ? Typeface.create(typeFaceName, mTextStyle) : null; this.mUnderlineColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputUnderlineColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_color_primary_blue)); this.mCursorColor = ta.getColor(com.layer.atlas.R.styleable.AtlasMessageComposer_inputCursorColor, context.getResources().getColor(com.layer.atlas.R.color.atlas_color_primary_blue)); this.mAttachmentSendersBackground = ta .getDrawable(com.layer.atlas.R.styleable.AtlasMessageComposer_attachmentSendersBackground); ta.recycle(); }
From source file:com.gelakinetic.mtgfam.helpers.ResultListAdapter.java
/** * Standard Constructor.//from w ww .ja v a 2 s . co m * * @param context The context where the ListView associated with this SimpleListItemFactory is running * @param cursor The database cursor. Can be null if the cursor is not available yet. * @param from A list of column names representing the data to bind to the UI. Can be null if the cursor is not * available yet. * @param to The views that should display column in the "from" parameter. These should all be TextViews. The * first N views in this list are given the values of the first N columns in the from parameter. * Can be null if the cursor is not available yet. */ public ResultListAdapter(Context context, Cursor cursor, String[] from, int[] to) { super(context, R.layout.result_list_card_row, cursor, from, to, 0); this.mFrom = from; this.mTo = to; this.mResources = context.getResources(); this.mTheme = context.getTheme(); this.mImgGetter = ImageGetterHelper.GlyphGetter(context); }
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static int getThemeForegroundColor(final Context context, int themeRes) { @SuppressWarnings("ConstantConditions") final TypedValue value = new TypedValue(); final Resources.Theme theme; if (themeRes != 0) { theme = context.getResources().newTheme(); theme.applyStyle(themeRes, false); } else {/*from ww w .j a va 2s . co m*/ theme = context.getTheme(); } if (!theme.resolveAttribute(android.R.attr.colorForeground, value, true)) { return 0; } if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { // windowBackground is a color return value.data; } else if (value.type == TypedValue.TYPE_REFERENCE) { return theme.getResources().getColor(value.resourceId); } return 0; }