List of usage examples for android.content.res TypedArray getDrawable
@Nullable public Drawable getDrawable(@StyleableRes int index)
From source file:com.cnh.library.materialdrawer.view.BezelImageView.java
public BezelImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Attribute initialization final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, R.style.BezelImageView);//from w w w . ja v a 2 s. com mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_biv_maskDrawable); if (mMaskDrawable != null) { mMaskDrawable.setCallback(this); } mDrawCircularShadow = a.getBoolean(R.styleable.BezelImageView_biv_drawCircularShadow, true); mSelectorColor = a.getColor(R.styleable.BezelImageView_biv_selectorOnPress, 0); a.recycle(); // Other initialization mBlackPaint = new Paint(); mBlackPaint.setColor(0xff000000); mMaskedPaint = new Paint(); mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // Always want a cache allocated. mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Create a desaturate color filter for pressed state. ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); mDesaturateColorFilter = new ColorMatrixColorFilter(cm); //create a selectorFilter if we already have a color if (mSelectorColor != 0) { this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP); } }
From source file:com.money.manager.ex.adapter.CategoryExpandableListAdapter.java
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { CategoryListItemViewHolderGroup holder; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(mLayout, null); holder = new CategoryListItemViewHolderGroup(convertView); convertView.setTag(holder);//from w w w . j ava 2 s . c o m } else { holder = (CategoryListItemViewHolderGroup) convertView.getTag(); } // prevent exceptions. todo: Find out how this happens in the first place. if (mCategories.size() == 0) return convertView; Category category = mCategories.get(groupPosition); holder.text1.setText(category.getName()); // Selector if (mShowSelector) { holder.selector.setVisibility(View.VISIBLE); // set the tag to be the group position holder.selector.setTag(category.getId()); holder.selector.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String tag = v.getTag().toString(); Integer groupId = Integer.parseInt(tag); setIdGroupChecked(groupId); // close closeFragment(); } }); } else { holder.selector.setVisibility(View.GONE); } if (holder.collapseImageView != null) { TypedArray expandableListViewStyle = getContext().getTheme() .obtainStyledAttributes(new int[] { android.R.attr.expandableListViewStyle }); TypedArray groupIndicator = getContext().getTheme().obtainStyledAttributes( expandableListViewStyle.getResourceId(0, 0), new int[] { android.R.attr.groupIndicator }); Drawable drawable = groupIndicator.getDrawable(0); holder.collapseImageView.setImageDrawable(drawable); expandableListViewStyle.recycle(); groupIndicator.recycle(); boolean hasChildren = getChildrenCount(groupPosition) != 0; if (!hasChildren) { holder.collapseImageView.setVisibility(View.INVISIBLE); } else { holder.collapseImageView.setVisibility(View.VISIBLE); if (drawable != null) { drawable.setState(isExpanded ? expandedStateSet : emptyStateSet); } } } return convertView; }
From source file:com.github.andrewlord1990.materialandroid.component.grid.GridItemView.java
private void loadIcon(TypedArray typedAttrs) { Drawable icon = typedAttrs.getDrawable(R.styleable.MDGridItemView_md_grid_icon); setIcon(icon);/*from w w w . j a v a2s.c om*/ @IconGravity int iconGravity = typedAttrs.getInt(R.styleable.MDGridItemView_md_grid_icon_gravity, ICON_GRAVITY_START); this.iconGravity = iconGravity; }
From source file:com.bobomee.android.tab_navigator.recyclerview.FlexibleDividerDecoration.java
protected FlexibleDividerDecoration(Builder builder) { if (builder.mPaintProvider != null) { mDividerType = DividerType.PAINT; mPaintProvider = builder.mPaintProvider; } else if (builder.mColorProvider != null) { mDividerType = DividerType.COLOR; mColorProvider = builder.mColorProvider; mPaint = new Paint(); setSizeProvider(builder);/* ww w.j a v a2 s .c om*/ } else { mDividerType = DividerType.DRAWABLE; if (builder.mDrawableProvider == null) { TypedArray a = builder.mContext.obtainStyledAttributes(ATTRS); final Drawable divider = a.getDrawable(0); a.recycle(); mDrawableProvider = new DrawableProvider() { @Override public Drawable drawableProvider(int position, RecyclerView parent) { return divider; } }; } else { mDrawableProvider = builder.mDrawableProvider; } mSizeProvider = builder.mSizeProvider; } mVisibilityProvider = builder.mVisibilityProvider; mShowLastDivider = builder.mShowLastDivider; mPositionInsideItem = builder.mPositionInsideItem; }
From source file:com.reginald.swiperefresh.sample.ViewPagerDemoActivity.java
private void setupViewPagerViews() { mRecyclerView = new RecyclerView(this); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new GridLayoutManager(this, 2); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { Drawable mDivider;/*w w w . ja v a 2 s . c o m*/ { final TypedArray a = ViewPagerDemoActivity.this .obtainStyledAttributes(new int[] { android.R.attr.listDivider }); mDivider = a.getDrawable(0); a.recycle(); } @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDraw(c, parent, state); final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } }); // specify an adapter (see also next example) mRecyclerViewAdapter = new MyAdapter(Cheeses.randomList(LIST_ITEM_COUNT)); mRecyclerView.setAdapter(mRecyclerViewAdapter); mListView = new ListView(this); mListAdapter = new ArrayAdapter<String>(this, R.layout.demo_list_item, R.id.item_text, Cheeses.randomList(LIST_ITEM_COUNT)); mListView.setAdapter(mListAdapter); viewPagerViews.add(mListView); viewPagerViews.add(mRecyclerView); viewPagerTitles.add("ListView"); viewPagerTitles.add("RecyclerView"); }
From source file:com.eu.inmite.android.lib.dialogs.BaseDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = new Dialog(getActivity(), R.style.SDL_Dialog); // custom dialog background final TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.DialogStyle, R.attr.sdlDialogStyle, 0);// w ww . j a v a 2s .c o m Drawable dialogBackground = a.getDrawable(R.styleable.DialogStyle_dialogBackground); a.recycle(); dialog.getWindow().setBackgroundDrawable(dialogBackground); return dialog; }
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;// ww w . j av a2s .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.fastbootmobile.encore.app.adapters.PlaylistListAdapter.java
@Override public void onBindViewHolder(final ViewHolder holder, int position) { final int itemViewType = getItemViewType(position); if (itemViewType == VIEW_TYPE_HEADER) { SpecialViewHolder specialHolder = (SpecialViewHolder) holder; specialHolder.cardFavorites.setOnClickListener(new View.OnClickListener() { @Override// w ww . j av a 2 s. c o m public void onClick(View v) { Context ctx = v.getContext(); Intent intent = PlaylistActivity.craftIntent(ctx, AutoPlaylistHelper.REF_SPECIAL_FAVORITES, null); ctx.startActivity(intent); } }); specialHolder.cardMostPlayed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context ctx = v.getContext(); Intent intent = PlaylistActivity.craftIntent(ctx, AutoPlaylistHelper.REF_SPECIAL_MOST_PLAYED, null); ctx.startActivity(intent); } }); } else if (itemViewType == VIEW_TYPE_REGULAR) { final Playlist item = mPlaylists.get(position - 1); holder.tvPlaylistName.setText(item.getName()); holder.ivCover.loadArtForPlaylist(item); if (item.isLoaded() || item.getSongsCount() > 0) { ProviderConnection provider = PluginsLookup.getDefault().getProvider(item.getProvider()); if (provider != null) { holder.tvPlaylistDesc .setText(String.format("%s / %s", holder.tvPlaylistDesc.getContext().getResources().getQuantityString( R.plurals.xx_songs, item.getSongsCount(), item.getSongsCount()), provider.getProviderName())); } holder.ivOfflineStatus.setVisibility(View.VISIBLE); switch (item.getOfflineStatus()) { case BoundEntity.OFFLINE_STATUS_NO: holder.ivOfflineStatus.setVisibility(View.GONE); break; case BoundEntity.OFFLINE_STATUS_DOWNLOADING: holder.ivOfflineStatus.setImageResource(R.drawable.ic_sync_in_progress); break; case BoundEntity.OFFLINE_STATUS_ERROR: holder.ivOfflineStatus.setImageResource(R.drawable.ic_sync_problem); break; case BoundEntity.OFFLINE_STATUS_PENDING: holder.ivOfflineStatus.setImageResource(R.drawable.ic_track_download_pending); break; case BoundEntity.OFFLINE_STATUS_READY: holder.ivOfflineStatus.setImageResource(R.drawable.ic_track_downloaded); break; } } else { holder.tvPlaylistDesc.setText(null); holder.ivOfflineStatus.setVisibility(View.GONE); } final int dragState = holder.getDragStateFlags(); if (((dragState & RecyclerViewDragDropManager.STATE_FLAG_IS_UPDATED) != 0)) { int bgColor = 0; if ((dragState & RecyclerViewDragDropManager.STATE_FLAG_IS_ACTIVE) != 0) { bgColor = 0xFFDDDDDD; } else if ((dragState & RecyclerViewDragDropManager.STATE_FLAG_DRAGGING) != 0) { bgColor = 0xFFAAAAAA; } if (bgColor != 0) { holder.container.setBackgroundColor(bgColor); } else { int[] attrs = new int[] { android.R.attr.selectableItemBackground /* index 0 */ }; TypedArray ta = holder.container.getContext().obtainStyledAttributes(attrs); Drawable drawableFromTheme = ta.getDrawable(0 /* index */); ta.recycle(); holder.container.setBackground(drawableFromTheme); } } holder.container.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context ctx = v.getContext(); Intent intent = PlaylistActivity.craftIntent(ctx, item, ((MaterialTransitionDrawable) holder.ivCover.getDrawable()).getFinalDrawable() .getBitmap()); if (Utils.hasLollipop()) { ActivityOptions opt = ActivityOptions.makeSceneTransitionAnimation((Activity) ctx, holder.ivCover, "itemImage"); ctx.startActivity(intent, opt.toBundle()); } else { ctx.startActivity(intent); } } }); } }
From source file:com.mishiranu.dashchan.util.DrawerToggle.java
private Drawable getThemeUpIndicatorObsolete() { if (C.API_JELLY_BEAN_MR2) { TypedArray a = activity.getActionBar().getThemedContext().obtainStyledAttributes(null, THEME_ATTRS, android.R.attr.actionBarStyle, 0); Drawable result = a.getDrawable(0); a.recycle();//from w ww . ja v a 2 s. com return result; } else { TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS); Drawable result = a.getDrawable(0); a.recycle(); return result; } }
From source file:com.nextgis.libngui.dialog.StyledDialogFragment.java
@Nullable @Override//from w w w . jav a2 s. c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // http://stackoverflow.com/a/15496425 LayoutInflater localInflater = inflater.cloneInContext(mContext); View view = localInflater.inflate(R.layout.sdf_layout, container, false); mBaseView = (RelativeLayout) view.findViewById(R.id.base); mTitleView = (LinearLayout) view.findViewById(R.id.title); mTitleIconView = (ImageView) view.findViewById(R.id.title_icon); mTitleTextView = (TextView) view.findViewById(R.id.title_text); mTitleDivider = view.findViewById(R.id.title_divider); mDialogBodyScroll = (ScrollView) view.findViewById(R.id.dialog_body_scroll); mDialogBodyLayoutScrolled = (LinearLayout) view.findViewById(R.id.dialog_body_scrolled); mDialogBodyLayout = (LinearLayout) view.findViewById(R.id.dialog_body); mButtons = (LinearLayout) view.findViewById(R.id.buttons); mButtonPositive = (Button) view.findViewById(R.id.button_positive); mButtonNegative = (Button) view.findViewById(R.id.button_negative); if (null != mMessageId) { setMessageView(); mMessage.setText(mMessageId); } if (null != mMessageText) { setMessageView(); mMessage.setText(mMessageText); } if (null != mView) { if (mAddScrollForView) { mDialogBodyScroll.setVisibility(View.VISIBLE); mDialogBodyLayoutScrolled.addView(mView); } else { mDialogBodyLayout.setVisibility(View.VISIBLE); mDialogBodyLayout.addView(mView); } } if (getShowsDialog()) { // http://stackoverflow.com/a/9409391 int[] attrs = new int[] { R.attr.sdf_background }; TypedArray ta = mContext.obtainStyledAttributes(attrs); Drawable background = ta.getDrawable(0); ta.recycle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mBaseView.setBackground(background); } else { mBaseView.setBackgroundDrawable(background); } mTitleView.setVisibility(View.VISIBLE); if (null != mIconId) { mTitleIconView.setVisibility(View.VISIBLE); mTitleIconView.setImageResource(mIconId); } if (null != mTitleId) { mTitleTextView.setText(mTitleId); } if (null != mTitleText) { mTitleTextView.setText(mTitleText); } if (null != mTitleDividerVisibility) { mTitleDivider.setVisibility(mTitleDividerVisibility); } if (null != mPositiveTextId) { mButtons.setVisibility(View.VISIBLE); mButtonPositive.setVisibility(View.VISIBLE); mButtonPositive.setText(mPositiveTextId); } if (null != mPositiveText) { mButtons.setVisibility(View.VISIBLE); mButtonPositive.setVisibility(View.VISIBLE); mButtonPositive.setText(mPositiveText); } if (null != mNegativeTextId) { mButtons.setVisibility(View.VISIBLE); mButtonNegative.setVisibility(View.VISIBLE); mButtonNegative.setText(mNegativeTextId); } if (null != mNegativeText) { mButtons.setVisibility(View.VISIBLE); mButtonNegative.setVisibility(View.VISIBLE); mButtonNegative.setText(mNegativeText); } if (null != mOnPositiveClickedListener) { mButtons.setVisibility(View.VISIBLE); mButtonPositive.setVisibility(View.VISIBLE); mButtonPositive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != mOnPositiveClickedListener) { mOnPositiveClickedListener.onPositiveClicked(); } dismiss(); } }); } if (null != mOnNegativeClickedListener) { mButtons.setVisibility(View.VISIBLE); mButtonNegative.setVisibility(View.VISIBLE); mButtonNegative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != mOnNegativeClickedListener) { mOnNegativeClickedListener.onNegativeClicked(); } dismiss(); } }); } } return view; }