Example usage for android.app Activity getDrawable

List of usage examples for android.app Activity getDrawable

Introduction

In this page you can find the example usage for android.app Activity getDrawable.

Prototype

@Nullable
public final Drawable getDrawable(@DrawableRes int id) 

Source Link

Document

Returns a drawable object associated with a particular resource ID and styled for the current theme.

Usage

From source file:com.none.tom.simplerssreader.fragment.CurrentFeedFragment.java

@SuppressWarnings("ConstantConditions")
@Override//from   w  ww  . j a va2  s.c o  m
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_current_feed_recyclerview, container, false);

    final Activity activity = getActivity();

    mSwipeRefreshLayout = view.findViewById(R.id.CurrentFeedSwipeToRefreshLayout);

    mSwipeRefreshLayout.setColorSchemeColors(activity.getResources().getIntArray(R.array.color_palette));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            isFeedUpdateAvailable();
        }
    });

    final VerticalSpaceItemDecoration decor = new VerticalSpaceItemDecoration(activity);
    decor.setDrawable(activity.getDrawable(R.drawable.divider));

    mRecyclerView = view.findViewById(R.id.CurrentFeedRecyclerView);

    mRecyclerView.setLayoutManager(new CenterLayoutManager(activity));
    mRecyclerView.setAdapter(new CurrentFeedAdapter(activity));
    mRecyclerView.addItemDecoration(decor);

    super.onCreateView((CoordinatorLayout) view, mRecyclerView);

    return view;
}

From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java

static View setupGridView(Activity activity, View convertView, ViewGroup parent, ContentItem item, int state) {

    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(activity);
    }//from   w ww. j  a  v  a2  s . com

    MediaItemViewHolder holder;

    Integer cachedState = STATE_INVALID;

    if (convertView == null) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.media_grid_item, parent, false);
        holder = new MediaItemViewHolder();
        holder.layGrid = (RelativeLayout) convertView.findViewById(R.id.layGrid);
        holder.mImageBack = (ImageView) convertView.findViewById(R.id.imgBack);
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (MediaItemViewHolder) convertView.getTag();
        cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
    }
    GridView grid = (GridView) parent;
    int size = grid.getRequestedColumnWidth();

    holder.mTitleView.setText(item.toString());
    holder.mDescriptionView.setText(item.getSubtitle());
    int w = holder.layGrid.getLayoutParams().width;
    // holder.layGrid.setLayoutParams(new GridView.LayoutParams(w, w));
    holder.mImageBack.setLayoutParams(new RelativeLayout.LayoutParams(w, w));
    if (item.isContainer()) {
        holder.mImageBack.setImageResource(item.getDefaultResource());
    } else {
        Utils.downloadBitmap(activity.getResources(), item, holder.mImageBack);
    }

    // If the state of convertView is different, we need to adapt the view to the
    // new state.
    if (cachedState == null || cachedState != state) {
        switch (state) {
        case STATE_PLAYABLE:
            holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_play_arrow_black_36dp));
            holder.mImageView.setImageTintList(sColorStateNotPlaying);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) activity
                    .getDrawable(R.drawable.ic_equalizer_white_36dp);
            holder.mImageView.setImageDrawable(animation);
            holder.mImageView.setImageTintList(sColorStatePlaying);
            holder.mImageView.setVisibility(View.VISIBLE);
            if (animation != null)
                animation.start();
            break;
        case STATE_PAUSED:
            holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_equalizer1_white_36dp));
            holder.mImageView.setImageTintList(sColorStateNotPlaying);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        default:
            holder.mImageView.setVisibility(View.GONE);
        }
        convertView.setTag(R.id.tag_mediaitem_state_cache, state);
    }

    return convertView;
}