Example usage for android.content.res ColorStateList valueOf

List of usage examples for android.content.res ColorStateList valueOf

Introduction

In this page you can find the example usage for android.content.res ColorStateList valueOf.

Prototype

@NonNull
public static ColorStateList valueOf(@ColorInt int color) 

Source Link

Usage

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void setColors(int color, View... views) {
    if (Build.VERSION.SDK_INT >= 27) {
        return;//from w  w w. ja  va2  s . c  om
    }
    for (View view : views) {
        if (view instanceof CheckBox) {
            CheckBox checkbox = (CheckBox) view;
            CompoundButtonCompat.setButtonTintList(checkbox, ColorStateList.valueOf(color));
        } else if (view instanceof FloatingActionButton) {
            //noinspection RedundantCast
            ((FloatingActionButton) view).setBackgroundTintList(ColorStateList.valueOf(color));
        } else if (view instanceof Button || view instanceof ImageButton) {
            Drawable background = view.getBackground();
            if (background != null) {
                background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            }
        } else if (view instanceof TextInputLayout) {
            UIUtils.colorTextInputLayout((TextInputLayout) view, color);
            // TODO: EditText's who are a child of TextInputLayout their line isn't colored correctly
        } else if (view instanceof EditText) {
            EditText editText = (EditText) view;
            editText.setHighlightColor(color); // When selecting text
            editText.setHintTextColor(color); // Text for the  hint message
            // Line under the textfield
            Drawable background = editText.getBackground();
            if (background != null) {
                DrawableCompat.setTint(background, color);
                editText.setBackground(background);
            }
            UIUtils.setCursorColor(editText, color);
        } else if (view instanceof CheckedTextView) {
            CheckedTextView ctv = (CheckedTextView) view;
            Drawable d = ctv.getCheckMarkDrawable();
            d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        } else if (view instanceof TextView) {
            ((TextView) view).setLinkTextColor(color);
        } else if (view instanceof SeekBar) {
            SeekBar sb = (SeekBar) view;
            Drawable progress = sb.getProgressDrawable();
            if (progress != null) {
                progress.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            }
            Drawable thumb = sb.getThumb();
            if (thumb != null) {
                thumb.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            }
        } else if (view instanceof ProgressBar) {
            ((ProgressBar) view).getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
        } else {
            L.d("Not coloring view: " + view.toString());
        }
    }
}

From source file:com.example.mego.adas.main.CarFragment.java

/**
 * Show a dialog that warns the user there are will lose the connection
 * if they continue leaving the app./*from   ww w.  j  a v a 2  s . co  m*/
 */
private void showLoseConnectionDialog(final String message) {
    // Create an AlertDialog.Builder and set the message, and click listeners
    // for the positive and negative buttons on the dialog.
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage(message);
    builder.setPositiveButton(R.string.yes, (dialog, which) -> {
        connectionState = 0;
        disconnectButton
                .setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
        communicator.disconnectListener(connectionState);
        if (NetworkUtil.isAvailableInternetConnection(getContext())) {
            connectionStateDatabaseReference.setValue(startState);
        }
    });

    builder.setNegativeButton(R.string.cancel, (dialog, which) -> {
        // User clicked the "Cancel" button, so dismiss the dialog
        // and continue in the BluetoothServerActivity
        if (dialog != null) {
            dialog.dismiss();
        }
    });

    //create and show the alert dialog
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:org.gateshipone.odyssey.views.NowPlayingView.java

/**
 * Updates all sub-views with the new pbs states
 *
 * @param info the new pbs states including the current track
 *//*ww  w . j  ava2  s .  c o m*/
private void updateStatus(NowPlayingInformation info) {

    // If called without a nowplayinginformation, ask the PBS directly for the information.
    // After the establishing of the service connection it can be that a track is playing and we've not yet received the NowPlayingInformation
    if (info == null) {
        try {
            info = mServiceConnection.getPBS().getNowPlayingInformation();
        } catch (RemoteException e) {
            e.printStackTrace();

            // an error occured so create a default instance to clear the view
            info = new NowPlayingInformation();
        }
    }

    // notify playlist has changed
    mPlaylistView.playlistChanged(info);

    // get current track
    TrackModel currentTrack = info.getCurrentTrack();

    // set tracktitle, album, artist and albumcover
    mTrackTitle.setText(currentTrack.getTrackName());

    // Check if the album title changed. If true, start the cover generator thread.
    if (!currentTrack.getTrackAlbumKey().equals(mLastAlbumKey)) {
        // get tint color
        int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_background_primary);

        Drawable drawable = getResources().getDrawable(R.drawable.cover_placeholder, null);
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, tintColor);

        // Show the placeholder image until the cover fetch process finishes
        mCoverImage.setImageDrawable(drawable);

        tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);

        drawable = getResources().getDrawable(R.drawable.cover_placeholder_96dp, null);
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, tintColor);

        // The same for the small header image
        mTopCoverImage.setImageDrawable(drawable);
        // Start the cover loader
        mCoverLoader.getImage(currentTrack);
    }
    // Save the name of the album for rechecking later
    mLastAlbumKey = currentTrack.getTrackAlbumKey();

    // Set the artist of the track
    String trackInformation = "";
    if (!currentTrack.getTrackArtistName().isEmpty() && !currentTrack.getTrackAlbumName().isEmpty()) {
        trackInformation = getResources().getString(R.string.track_title_template,
                currentTrack.getTrackArtistName(), currentTrack.getTrackAlbumName());
    } else if (!currentTrack.getTrackArtistName().isEmpty()) {
        trackInformation = currentTrack.getTrackArtistName();
    } else if (!currentTrack.getTrackAlbumName().isEmpty()) {
        trackInformation = currentTrack.getTrackAlbumName();
    }
    mTrackSubtitle.setText(trackInformation);

    // Calculate the margin to avoid cut off textviews
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mHeaderTextLayout
            .getLayoutParams();
    layoutParams.setMarginEnd((int) (mTopPlaylistButton.getWidth() * (1.0 - mDragOffset)));
    mHeaderTextLayout.setLayoutParams(layoutParams);

    // Set the track duration
    mDuration.setText(FormatHelper.formatTracktimeFromMS(getContext(), currentTrack.getTrackDuration()));

    // set up seekbar (set maximum value, track total duration)
    mPositionSeekbar.setMax((int) currentTrack.getTrackDuration());

    // update seekbar and elapsedview
    updateTrackPosition();

    // save the state
    mPlaybackServiceState = info.getPlayState();

    // update buttons

    // update play buttons
    switch (mPlaybackServiceState) {
    case PLAYING:
        mTopPlayPauseButton.setImageResource(R.drawable.ic_pause_48dp);
        mBottomPlayPauseButton.setImageResource(R.drawable.ic_pause_circle_fill_48dp);

        // start refresh task if view is visible
        if (mDragOffset == 0.0f) {
            startRefreshTask();
        }

        break;
    case PAUSE:
    case RESUMED:
    case STOPPED:
        mTopPlayPauseButton.setImageResource(R.drawable.ic_play_arrow_48dp);
        mBottomPlayPauseButton.setImageResource(R.drawable.ic_play_circle_fill_48dp);

        // stop refresh task
        stopRefreshTask();

        break;
    }

    // update repeat button
    switch (info.getRepeat()) {
    case REPEAT_OFF:
        mBottomRepeatButton.setImageResource(R.drawable.ic_repeat_24dp);
        mBottomRepeatButton.setImageTintList(ColorStateList
                .valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent)));
        break;
    case REPEAT_ALL:
        mBottomRepeatButton.setImageResource(R.drawable.ic_repeat_24dp);
        mBottomRepeatButton.setImageTintList(
                ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), android.R.attr.colorAccent)));
        break;
    case REPEAT_TRACK:
        mBottomRepeatButton.setImageResource(R.drawable.ic_repeat_one_24dp);
        mBottomRepeatButton.setImageTintList(
                ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), android.R.attr.colorAccent)));
        break;
    }

    // update random button
    switch (info.getRandom()) {
    case RANDOM_OFF:
        mBottomRandomButton.setImageTintList(ColorStateList
                .valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent)));
        break;
    case RANDOM_ON:
        mBottomRandomButton.setImageTintList(
                ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), android.R.attr.colorAccent)));
        break;
    }
}

From source file:com.android.contacts.list.ContactListItemView.java

private void addStarImageHeader() {
    mHeaderView = new ImageView(getContext());
    final ImageView headerImageView = (ImageView) mHeaderView;
    headerImageView.setImageDrawable(/*w  w w .j a v  a2s.c  om*/
            getResources().getDrawable(R.drawable.quantum_ic_star_vd_theme_24, getContext().getTheme()));
    headerImageView
            .setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_star_pink)));
    headerImageView.setContentDescription(getContext().getString(R.string.contactsFavoritesLabel));
    headerImageView.setVisibility(View.VISIBLE);
    addView(headerImageView);
}

From source file:org.gateshipone.malp.application.views.NowPlayingView.java

/**
     * Called after the layout inflater is finished.
     * Sets all global view variables to the ones inflated.
     *///w  w w. java2s. c o m
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        // Get both main views (header and bottom part)
        mHeaderView = findViewById(R.id.now_playing_headerLayout);
        mMainView = findViewById(R.id.now_playing_bodyLayout);

        // header buttons
        mTopPlayPauseButton = (ImageButton) findViewById(R.id.now_playing_topPlayPauseButton);
        mTopPlaylistButton = (ImageButton) findViewById(R.id.now_playing_topPlaylistButton);
        mTopMenuButton = (ImageButton) findViewById(R.id.now_playing_topMenuButton);

        // bottom buttons
        mBottomRepeatButton = (ImageButton) findViewById(R.id.now_playing_bottomRepeatButton);
        mBottomPreviousButton = (ImageButton) findViewById(R.id.now_playing_bottomPreviousButton);
        mBottomPlayPauseButton = (ImageButton) findViewById(R.id.now_playing_bottomPlayPauseButton);
        mBottomStopButton = (ImageButton) findViewById(R.id.now_playing_bottomStopButton);
        mBottomNextButton = (ImageButton) findViewById(R.id.now_playing_bottomNextButton);
        mBottomRandomButton = (ImageButton) findViewById(R.id.now_playing_bottomRandomButton);

        // Main cover image
        mCoverImage = (AlbumArtistView) findViewById(R.id.now_playing_cover);
        // Small header cover image
        mTopCoverImage = (ImageView) findViewById(R.id.now_playing_topCover);

        // View with the ListView of the playlist
        mPlaylistView = (CurrentPlaylistView) findViewById(R.id.now_playing_playlist);

        // view switcher for cover and playlist view
        mViewSwitcher = (ViewSwitcher) findViewById(R.id.now_playing_view_switcher);

        // Button container for the buttons shown if dragged up
        mDraggedUpButtons = (LinearLayout) findViewById(R.id.now_playing_layout_dragged_up);
        // Button container for the buttons shown if dragged down
        mDraggedDownButtons = (LinearLayout) findViewById(R.id.now_playing_layout_dragged_down);

        // textviews
        mTrackName = (TextView) findViewById(R.id.now_playing_trackName);
        // For marquee scrolling the TextView need selected == true
        mTrackName.setSelected(true);
        mTrackAdditionalInfo = (TextView) findViewById(R.id.now_playing_track_additional_info);
        // For marquee scrolling the TextView need selected == true
        mTrackAdditionalInfo.setSelected(true);

        mTrackNo = (TextView) findViewById(R.id.now_playing_text_track_no);
        mPlaylistNo = (TextView) findViewById(R.id.now_playing_text_playlist_no);
        mBitrate = (TextView) findViewById(R.id.now_playing_text_bitrate);
        mAudioProperties = (TextView) findViewById(R.id.now_playing_text_audio_properties);
        mTrackURI = (TextView) findViewById(R.id.now_playing_text_track_uri);

        // Textviews directly under the seekbar
        mElapsedTime = (TextView) findViewById(R.id.now_playing_elapsedTime);
        mDuration = (TextView) findViewById(R.id.now_playing_duration);

        mHeaderTextLayout = (LinearLayout) findViewById(R.id.now_playing_header_textLayout);

        // seekbar (position)
        mPositionSeekbar = (SeekBar) findViewById(R.id.now_playing_seekBar);
        mPositionSeekbar.setOnSeekBarChangeListener(new PositionSeekbarListener());

        mVolumeSeekbar = (SeekBar) findViewById(R.id.volume_seekbar);
        mVolumeIcon = (ImageView) findViewById(R.id.volume_icon);
        mVolumeIcon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                MPDCommandHandler.setVolume(0);
            }
        });
        mVolumeSeekbar.setMax(100);
        mVolumeSeekbar.setOnSeekBarChangeListener(new VolumeSeekBarListener());

        /* Volume control buttons */
        mVolumeIconButtons = (ImageView) findViewById(R.id.volume_icon_buttons);
        mVolumeIconButtons.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                MPDCommandHandler.setVolume(0);
            }
        });

        mVolumeText = (TextView) findViewById(R.id.volume_button_text);

        mVolumeMinus = (ImageButton) findViewById(R.id.volume_button_minus);

        mVolumeMinus.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                MPDCommandHandler.decreaseVolume();
            }
        });

        mVolumePlus = (ImageButton) findViewById(R.id.volume_button_plus);
        mVolumePlus.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                MPDCommandHandler.increaseVolume();
            }
        });

        /* Create two listeners that start a repeating timer task to repeat the volume plus/minus action */
        VolumeButtonLongClickListener plusListener = new VolumeButtonLongClickListener(
                VolumeButtonLongClickListener.LISTENER_ACTION.VOLUME_UP);
        VolumeButtonLongClickListener minusListener = new VolumeButtonLongClickListener(
                VolumeButtonLongClickListener.LISTENER_ACTION.VOLUME_DOWN);

        /* Set the listener to the plus/minus button */
        mVolumeMinus.setOnLongClickListener(minusListener);
        mVolumeMinus.setOnTouchListener(minusListener);

        mVolumePlus.setOnLongClickListener(plusListener);
        mVolumePlus.setOnTouchListener(plusListener);

        mVolumeSeekbarLayout = (LinearLayout) findViewById(R.id.volume_seekbar_layout);
        mVolumeButtonLayout = (LinearLayout) findViewById(R.id.volume_button_layout);

        // set dragging part default to bottom
        mDragOffset = 1.0f;
        mDraggedUpButtons.setVisibility(INVISIBLE);
        mDraggedDownButtons.setVisibility(VISIBLE);
        mDraggedUpButtons.setAlpha(0.0f);

        // add listener to top playpause button
        mTopPlayPauseButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                MPDCommandHandler.togglePause();
            }
        });

        // Add listeners to top playlist button
        mTopPlaylistButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                // get color for playlist button
                int color;
                if (mViewSwitcher.getCurrentView() != mPlaylistView) {
                    color = ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent);
                } else {
                    color = ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent);
                }

                // tint the button
                mTopPlaylistButton.setImageTintList(ColorStateList.valueOf(color));

                // toggle between cover and playlistview
                mViewSwitcher.showNext();

                // report the change of the view
                if (mDragStatusReceiver != null) {
                    // set view status
                    if (mViewSwitcher.getDisplayedChild() == 0) {
                        // cover image is shown
                        mDragStatusReceiver
                                .onSwitchedViews(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS.COVER_VIEW);
                    } else {
                        // playlist view is shown
                        mDragStatusReceiver
                                .onSwitchedViews(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS.PLAYLIST_VIEW);
                        mPlaylistView.jumpToCurrentSong();
                    }
                }
            }
        });

        // Add listener to top menu button
        mTopMenuButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showAdditionalOptionsMenu(v);
            }
        });

        // Add listener to bottom repeat button
        mBottomRepeatButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                if (null != mLastStatus) {
                    if (mLastStatus.getRepeat() == 0) {
                        MPDCommandHandler.setRepeat(true);
                    } else {
                        MPDCommandHandler.setRepeat(false);
                    }
                }
            }
        });

        // Add listener to bottom previous button
        mBottomPreviousButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                MPDCommandHandler.previousSong();

            }
        });

        // Add listener to bottom playpause button
        mBottomPlayPauseButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                MPDCommandHandler.togglePause();
            }
        });

        mBottomStopButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                MPDCommandHandler.stop();
            }
        });

        // Add listener to bottom next button
        mBottomNextButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                MPDCommandHandler.nextSong();
            }
        });

        // Add listener to bottom random button
        mBottomRandomButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                if (null != mLastStatus) {
                    if (mLastStatus.getRandom() == 0) {
                        MPDCommandHandler.setRandom(true);
                    } else {
                        MPDCommandHandler.setRandom(false);
                    }
                }
            }
        });

        mCoverImage.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), FanartActivity.class);
                getContext().startActivity(intent);
            }
        });
        mCoverImage.setVisibility(INVISIBLE);

        mCoverLoader = new CoverBitmapLoader(getContext(), new CoverReceiverClass());
    }

From source file:org.gateshipone.odyssey.views.NowPlayingView.java

/**
 * Set the viewswitcher of cover/playlist view to the requested state.
 *
 * @param view the view which should be displayed.
 *///from   w w  w  .  j  ava2  s.c o  m
public void setViewSwitcherStatus(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS view) {
    int color = 0;

    switch (view) {
    case COVER_VIEW:
        // change the view only if the requested view is not displayed
        if (mViewSwitcher.getCurrentView() != mCoverImage) {
            mViewSwitcher.showNext();
        }
        color = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);
        break;
    case PLAYLIST_VIEW:
        // change the view only if the requested view is not displayed
        if (mViewSwitcher.getCurrentView() != mPlaylistView) {
            mViewSwitcher.showNext();
        }
        color = ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent);
        break;
    }

    // tint the button according to the requested view
    mTopPlaylistButton.setImageTintList(ColorStateList.valueOf(color));
}

From source file:org.totschnig.myexpenses.util.Utils.java

@SuppressLint("NewApi")
public static void setBackgroundTintListOnFab(FloatingActionButton fab, int color) {
    fab.setBackgroundTintList(ColorStateList.valueOf(color));
    DrawableCompat.setTint(fab.getDrawable(), isBrightColor(color) ? Color.BLACK : Color.WHITE);
    fab.invalidate();/*www .j  a v a 2s  .  c  o  m*/
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Sets a single color used to draw the discrete interval's tick mark.
 *
 * @param color The desired color./*from   w  ww . j  a v a 2s  . co  m*/
 * @see R.attr#uiDiscreteIntervalTickMarkColor ui:uiDiscreteIntervalTickMarkColor
 */
public void setDiscreteIntervalTickMarkColor(@ColorInt int color) {
    setDiscreteIntervalTickMarkColor(ColorStateList.valueOf(color));
}

From source file:org.gateshipone.malp.application.views.NowPlayingView.java

private void updateMPDStatus(MPDCurrentStatus status) {
        MPDCurrentStatus.MPD_PLAYBACK_STATE state = status.getPlaybackState();

        // update play buttons
        switch (state) {
        case MPD_PLAYING:
            mTopPlayPauseButton.setImageResource(R.drawable.ic_pause_48dp);
            mBottomPlayPauseButton.setImageResource(R.drawable.ic_pause_circle_fill_48dp);

            break;
        case MPD_PAUSING:
        case MPD_STOPPED:
            mTopPlayPauseButton.setImageResource(R.drawable.ic_play_arrow_48dp);
            mBottomPlayPauseButton.setImageResource(R.drawable.ic_play_circle_fill_48dp);

            break;
        }/*from w  w w  .  j  a v a  2  s. co  m*/

        // update repeat button
        // FIXME with single playback
        switch (status.getRepeat()) {
        case 0:
            mBottomRepeatButton.setImageResource(R.drawable.ic_repeat_24dp);
            mBottomRepeatButton.setImageTintList(
                    ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent)));
            break;
        case 1:
            mBottomRepeatButton.setImageResource(R.drawable.ic_repeat_24dp);
            mBottomRepeatButton.setImageTintList(
                    ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), android.R.attr.colorAccent)));
            break;
        }

        // update random button
        switch (status.getRandom()) {
        case 0:
            mBottomRandomButton.setImageTintList(
                    ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent)));
            break;
        case 1:
            mBottomRandomButton.setImageTintList(
                    ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), android.R.attr.colorAccent)));
            break;
        }

        // Update position seekbar & textviews
        mPositionSeekbar.setMax(status.getTrackLength());
        mPositionSeekbar.setProgress(status.getElapsedTime());

        mElapsedTime.setText(FormatHelper.formatTracktimeFromS(status.getElapsedTime()));
        mDuration.setText(FormatHelper.formatTracktimeFromS(status.getTrackLength()));

        // Update volume seekbar
        int volume = status.getVolume();
        mVolumeSeekbar.setProgress(volume);

        if (volume >= 70) {
            mVolumeIcon.setImageResource(R.drawable.ic_volume_high_black_48dp);
            mVolumeIconButtons.setImageResource(R.drawable.ic_volume_high_black_48dp);
        } else if (volume >= 30 && volume < 70) {
            mVolumeIcon.setImageResource(R.drawable.ic_volume_medium_black_48dp);
            mVolumeIconButtons.setImageResource(R.drawable.ic_volume_medium_black_48dp);
        } else if (volume > 0 && volume < 30) {
            mVolumeIcon.setImageResource(R.drawable.ic_volume_low_black_48dp);
            mVolumeIconButtons.setImageResource(R.drawable.ic_volume_low_black_48dp);
        } else {
            mVolumeIcon.setImageResource(R.drawable.ic_volume_mute_black_48dp);
            mVolumeIconButtons.setImageResource(R.drawable.ic_volume_mute_black_48dp);
        }
        mVolumeIcon.setImageTintList(
                ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent)));
        mVolumeIconButtons.setImageTintList(
                ColorStateList.valueOf(ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent)));

        mVolumeText.setText(String.valueOf(volume) + '%');

        mPlaylistNo.setText(String.valueOf(status.getCurrentSongIndex() + 1)
                + getResources().getString(R.string.track_number_album_count_separator)
                + String.valueOf(status.getPlaylistLength()));

        mLastStatus = status;

        mBitrate.setText(status.getBitrate() + getResources().getString(R.string.bitrate_unit_kilo_bits));

        // Set audio properties string
        String properties = status.getSamplerate() + getResources().getString(R.string.samplerate_unit_hertz) + ' ';

        // Check for fancy new formats here (dsd, float = f)
        String sampleFormat = status.getBitDepth();

        if (sampleFormat.equals("8") || sampleFormat.equals("16") || sampleFormat.equals("24")
                || sampleFormat.equals("32")) {
            properties += status.getBitDepth() + getResources().getString(R.string.bitcount_unit) + ' ';
        } else if (sampleFormat.equals("f")) {
            properties += "float ";
        } else {
            properties += status.getBitDepth() + ' ';
        }

        properties += status.getChannelCount() + getResources().getString(R.string.channel_count_unit);
        mAudioProperties.setText(properties);
    }

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

private void toggleFabOn(FloatingActionButton fab) {
    TypedArray ta = this.getTheme().obtainStyledAttributes(R.styleable.ThemeStyles);
    fab.setBackgroundTintList(ColorStateList.valueOf(ta.getColor(R.styleable.ThemeStyles_fabButtonColor,
            getResources().getColor(R.color.primary_default))));
    fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_on));
}