Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();//from w w w  .  java2 s  . c o  m
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLine4 = (TextView) findViewById(R.id.line4);
    mLine5 = (TextView) findViewById(R.id.line5);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackStateCompat.STATE_PLAYING: // fall through
                case PlaybackStateCompat.STATE_BUFFERING:
                    controls.pause();
                    stopSeekbarUpdate();
                    break;
                case PlaybackStateCompat.STATE_PAUSED:
                case PlaybackStateCompat.STATE_STOPPED:
                    controls.play();
                    scheduleSeekbarUpdate();
                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(DateUtils.formatElapsedTime(progress / 1000));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopSeekbarUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress());
            scheduleSeekbarUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        //updateFromParams(getIntent());  //FIXME:  Why were they doing this???
    }

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);
}

From source file:com.afeng.xf.widget.snackbarlight.Light.java

/**
 * Make a Snackbar of {@link Light#TYPE_ERROR} to display a message.
 * The method {@link Light#make(View, CharSequence, Drawable, int, int, int)}
 * is called internal./*from w ww.j av a 2s . c  o m*/
 *
 * @param view The view to find a parent from.
 * @param text The message to display. Formatted text is supported.
 * @param duration How long to show the message.
 *                 Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}.
 * @return The Snackbar that will be displayed.
 */
public static Snackbar error(@NonNull View view, @NonNull CharSequence text, int duration) {
    Context context = view.getContext();
    return make(view, text,
            // DO NOT use the resource id directly.
            // It should be a resolved drawable or color.
            ContextCompat.getDrawable(context, R.drawable.ic_error_24dp),
            // getResources().getColor() is deprecated.
            ContextCompat.getColor(context, R.color.color_error),
            ContextCompat.getColor(context, android.R.color.white), duration);
}

From source file:br.ufrgs.ufrgsmapas.views.BuildingClusterRenderer.java

private static BitmapDescriptor scaleDown(Context context, int res) {

    BitmapDrawable bitmapDrawable = (BitmapDrawable) ContextCompat.getDrawable(context, res);
    Bitmap bitmap = bitmapDrawable.getBitmap();
    int iconSizePx = MeasureUtils.convertDpToPixel(ICON_SIZE_DP, context);

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, iconSizePx, iconSizePx, true);

    return BitmapDescriptorFactory.fromBitmap(scaledBitmap);
}

From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();/*from  w  w  w .j  av  a  2s. c o m*/
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackState.STATE_PLAYING: // fall through
                case PlaybackState.STATE_BUFFERING:
                    controls.pause();
                    stopSeekbarUpdate();
                    break;
                case PlaybackState.STATE_PAUSED:
                case PlaybackState.STATE_STOPPED:
                    controls.play();
                    scheduleSeekbarUpdate();
                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(Utils.formatMillis(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopSeekbarUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress());
            scheduleSeekbarUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        updateFromParams(getIntent());
    }

}

From source file:com.bilibili.magicasakura.widgets.AppCompatImageHelper.java

@Override
public void tint() {
    if (mImageTintResId == 0 || !setSupportImageTint(mImageTintResId)) {
        Drawable drawable = mTintManager.getDrawable(mImageResId);
        if (drawable == null) {
            drawable = mImageResId == 0 ? null : ContextCompat.getDrawable(mView.getContext(), mImageResId);
        }/*from   www  .j a  v a 2 s.c  om*/
        setImageDrawable(drawable);
    }
}

From source file:com.akalizakeza.apps.ishusho.activity.PostViewHolder.java

public void setLikeStatus(LikeStatus status, Context context) {
    mLikeIcon.setImageDrawable(ContextCompat.getDrawable(context,
            status == LikeStatus.LIKED ? R.drawable.ic_star_black_48dp : R.drawable.ic_star_border_black_48dp));
}

From source file:com.belatrixsf.allstars.ui.account.AccountFragment.java

private void setupViews() {
    accountCategoriesAdapter = new AccountSubCategoriesAdapter(this);
    recommendationRecyclerView.setAdapter(accountCategoriesAdapter);
    recommendationRecyclerView.addItemDecoration(new DividerItemDecoration(
            ContextCompat.getDrawable(getActivity(), android.R.drawable.divider_horizontal_bright)));
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setAutoMeasureEnabled(true);
    recommendationRecyclerView.setNestedScrollingEnabled(false);
    recommendationRecyclerView.setLayoutManager(linearLayoutManager);
}

From source file:com.dolbik.pavel.translater.fragments.translate.TranslateFragment.java

@Override
public void showHideFavoriteBtn(boolean flag, boolean isFavorite) {
    if (flag) {/*from  www. j  a v  a2 s . c  o  m*/
        if (isFavorite) {
            favorite.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_bookmark_yellow));
        } else {
            favorite.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_bookmark_grey));
        }
        favorite.setVisibility(View.VISIBLE);
    } else {
        favorite.setVisibility(View.GONE);
    }
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

private void init(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
    mArcWidth = getResources().getDimensionPixelSize(R.dimen.fp_progress_arc_stroke_width);
    mFabIcon = getDrawable();//from   w w  w .j a  va2 s. c o m
    mAccentColor = fetchAccentColor();

    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FabProgress, defStyleAttr, 0);
    try {
        mArcColor = attr.getColor(R.styleable.FabProgress_fp_arcColor,
                ContextCompat.getColor(context, R.color.green_500));
        mUseRoundedStroke = attr.getBoolean(R.styleable.FabProgress_fp_roundedStroke, false);
        mCompleteIcon = attr.getDrawable(R.styleable.FabProgress_fp_finalIcon);
        if (mCompleteIcon == null) {
            mCompleteIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_done_white_24dp);
        }
        mIsReusable = attr.getBoolean(R.styleable.FabProgress_fp_reusable, false);
    } finally {
        attr.recycle();
    }

    if (!Utils.isRunningLollipopAndHigher()) {
        setFakeShadowPadding(context, attrs, defStyleAttr);
    }

    setupPaint();
    setupAnimations();
}

From source file:com.einzig.ipst2.activities.PSDetailsActivity.java

/**
 * Add additional UI components for an accepted portal submission
 *
 * @param portal Portal being viewed cast to a PortalAccepted for convenience
 *///from w w  w.  j  ava  2s.com
private void buildAcceptedUI(PortalAccepted portal) {
    buildRespondedUI(portal);
    portalStatusImage.setBackgroundColor(ContextCompat.getColor(this, R.color.accepted));
    portalStatusImage.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_check));
    LinearLayout acceptedLayout = (LinearLayout) LayoutInflater.from(this)
            .inflate(R.layout.row_psdetails_accepted, extraLayout, false);
    ThemeHelper.styleView(acceptedLayout.findViewById(R.id.liveaddresslayout_acceptedrow), this);
    ThemeHelper.styleButton((Button) acceptedLayout.findViewById(R.id.viewonintelmapbutton_acceptedrow), this);

    ((TextView) acceptedLayout.findViewById(R.id.liveaddress_acceptedrow)).setText(portal.getLiveAddress());
    acceptedLayout.findViewById(R.id.viewonintelmapbutton_acceptedrow)
            .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    goToIntel();
                }
            });
    extraLayout.addView(acceptedLayout);
}