List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint
public static void setTint(Drawable drawable, int i)
From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java
private void updateBackground() { @ColorInt/*from w w w . ja v a 2 s. co m*/ int background; @ColorInt int backgroundNext; @ColorInt int backgroundDark; @ColorInt int backgroundDarkNext; if (position == getCount()) { background = Color.TRANSPARENT; backgroundNext = Color.TRANSPARENT; backgroundDark = Color.TRANSPARENT; backgroundDarkNext = Color.TRANSPARENT; } else { background = ContextCompat.getColor(IntroActivity.this, getBackground(position)); backgroundNext = ContextCompat.getColor(IntroActivity.this, getBackground(Math.min(position + 1, getCount() - 1))); background = ColorUtils.setAlphaComponent(background, 0xFF); backgroundNext = ColorUtils.setAlphaComponent(backgroundNext, 0xFF); try { backgroundDark = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position)); } catch (Resources.NotFoundException e) { backgroundDark = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background); } try { backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(Math.min(position + 1, getCount() - 1))); } catch (Resources.NotFoundException e) { backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background); } } if (position + positionOffset >= adapter.getCount() - 1) { backgroundNext = ColorUtils.setAlphaComponent(background, 0x00); backgroundDarkNext = ColorUtils.setAlphaComponent(backgroundDark, 0x00); } background = (Integer) evaluator.evaluate(positionOffset, background, backgroundNext); backgroundDark = (Integer) evaluator.evaluate(positionOffset, backgroundDark, backgroundDarkNext); miFrame.setBackgroundColor(background); float[] backgroundDarkHsv = new float[3]; Color.colorToHSV(backgroundDark, backgroundDarkHsv); //Slightly darken the background color a bit for more contrast backgroundDarkHsv[2] *= 0.95; int backgroundDarker = Color.HSVToColor(backgroundDarkHsv); miPagerIndicator.setPageIndicatorColor(backgroundDarker); ViewCompat.setBackgroundTintList(miButtonNext, ColorStateList.valueOf(backgroundDarker)); ViewCompat.setBackgroundTintList(miButtonBack, ColorStateList.valueOf(backgroundDarker)); @ColorInt int backgroundButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? ContextCompat.getColor(this, android.R.color.white) : backgroundDarker; ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(0), ColorStateList.valueOf(backgroundButtonCta)); ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(1), ColorStateList.valueOf(backgroundButtonCta)); int iconColor; if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) { //Light background iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_light); } else { //Dark background iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_dark); } miPagerIndicator.setCurrentPageIndicatorColor(iconColor); DrawableCompat.setTint(miButtonNext.getDrawable(), iconColor); DrawableCompat.setTint(miButtonBack.getDrawable(), iconColor); @ColorInt int textColorButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? backgroundDarker : iconColor; ((Button) miButtonCta.getChildAt(0)).setTextColor(textColorButtonCta); ((Button) miButtonCta.getChildAt(1)).setTextColor(textColorButtonCta); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(backgroundDark); if (position == adapter.getCount()) { getWindow().setNavigationBarColor(Color.TRANSPARENT); } else if (position + positionOffset >= adapter.getCount() - 1) { TypedValue typedValue = new TypedValue(); TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.navigationBarColor }); int defaultNavigationBarColor = a.getColor(0, Color.BLACK); a.recycle(); int navigationBarColor = (Integer) evaluator.evaluate(positionOffset, defaultNavigationBarColor, Color.TRANSPARENT); getWindow().setNavigationBarColor(navigationBarColor); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int systemUiVisibility = getWindow().getDecorView().getSystemUiVisibility(); int flagLightStatusBar = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) { //Light background systemUiVisibility |= flagLightStatusBar; } else { //Dark background systemUiVisibility &= ~flagLightStatusBar; } getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility); } } }
From source file:com.linkbubble.ui.ContentView.java
void updateColors(Integer color) { themeColor = color;/*from ww w . j a va 2 s . com*/ int textColor; int bgColor; if (color == null || !Settings.get().getThemeToolbar()) { textColor = Settings.get().getThemedTextColor(); bgColor = Settings.get().getThemedContentViewColor(); mCaretView.setBackground(getResources() .getDrawable(Settings.get().getDarkThemeEnabled() ? R.drawable.content_view_caret_dark : R.drawable.content_view_caret_white)); } else { // Calculate text color based on contrast with background: // https://24ways.org/2010/calculating-color-contrast/ int yiq = (Color.red(color) * 299 + Color.green(color) * 587 + Color.blue(color) * 114) / 1000; textColor = yiq >= 128 ? Settings.COLOR_BLACK : Settings.COLOR_WHITE; bgColor = color; Drawable d = getTintableDrawable(R.drawable.content_view_caret_white, false); DrawableCompat.setTint(d, color); mCaretView.setBackground(d); } mToolbarLayout.setBackgroundColor(bgColor); mTitleTextView.setTextColor(textColor); mUrlTextView.setTextColor(textColor); metUrl.setBackgroundColor(bgColor); metUrl.setTextColor(textColor); mContentEditUrl.setBackgroundColor(bgColor); for (Drawable d : mTintableDrawables) { DrawableCompat.setTint(d, textColor); } mArticleModeButton.updateTheme(color); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
/** * Sets the menu button's color./*from w w w. j a va 2 s . c o m*/ * * @param color the color to be applied to the * left menu button. */ public void setLeftActionIconColor(int color) { mLeftActionIconColor = color; mMenuBtnDrawable.setColor(color); DrawableCompat.setTint(mIconBackArrow, color); DrawableCompat.setTint(mIconSearch, color); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
/** * Sets the clear button's color.//from w w w. j a v a2 s. c om * * @param color the color to be applied to the * clear button. */ public void setClearBtnColor(int color) { mClearBtnColor = color; DrawableCompat.setTint(mIconClear, mClearBtnColor); }
From source file:com.zhengde163.netguard.ActivityMain.java
private void menu_legend() { TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOn, tv, true); int colorOn = tv.data; getTheme().resolveAttribute(R.attr.colorOff, tv, true); int colorOff = tv.data; // Create view LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.legend, null, false); ImageView ivWifiOn = (ImageView) view.findViewById(R.id.ivWifiOn); ImageView ivWifiOff = (ImageView) view.findViewById(R.id.ivWifiOff); ImageView ivOtherOn = (ImageView) view.findViewById(R.id.ivOtherOn); ImageView ivOtherOff = (ImageView) view.findViewById(R.id.ivOtherOff); ImageView ivScreenOn = (ImageView) view.findViewById(R.id.ivScreenOn); ImageView ivHostAllowed = (ImageView) view.findViewById(R.id.ivHostAllowed); ImageView ivHostBlocked = (ImageView) view.findViewById(R.id.ivHostBlocked); ImageView ivClose = (ImageView) view.findViewById(R.id.ivClose); ivClose.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a v a 2 s. c om public void onClick(View v) { dialogLegend.dismiss(); } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable()); Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable()); Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable()); Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable()); Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable()); Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable()); Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable()); DrawableCompat.setTint(wrapWifiOn, colorOn); DrawableCompat.setTint(wrapWifiOff, colorOff); DrawableCompat.setTint(wrapOtherOn, colorOn); DrawableCompat.setTint(wrapOtherOff, colorOff); DrawableCompat.setTint(wrapScreenOn, colorOn); DrawableCompat.setTint(wrapHostAllowed, colorOn); DrawableCompat.setTint(wrapHostBlocked, colorOff); } // Show dialog dialogLegend = new AlertDialog.Builder(this).setView(view).setCancelable(true) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogLegend = null; } }).create(); dialogLegend.show(); }
From source file:com.master.metehan.filtereagle.ActivityMain.java
private void menu_legend() { TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOn, tv, true); int colorOn = tv.data; getTheme().resolveAttribute(R.attr.colorOff, tv, true); int colorOff = tv.data; // Create view LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.legend, null, false); ImageView ivWifiOn = (ImageView) view.findViewById(R.id.ivWifiOn); ImageView ivWifiOff = (ImageView) view.findViewById(R.id.ivWifiOff); ImageView ivOtherOn = (ImageView) view.findViewById(R.id.ivOtherOn); ImageView ivOtherOff = (ImageView) view.findViewById(R.id.ivOtherOff); ImageView ivScreenOn = (ImageView) view.findViewById(R.id.ivScreenOn); ImageView ivHostAllowed = (ImageView) view.findViewById(R.id.ivHostAllowed); ImageView ivHostBlocked = (ImageView) view.findViewById(R.id.ivHostBlocked); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable()); Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable()); Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable()); Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable()); Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable()); Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable()); Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable()); DrawableCompat.setTint(wrapWifiOn, colorOn); DrawableCompat.setTint(wrapWifiOff, colorOff); DrawableCompat.setTint(wrapOtherOn, colorOn); DrawableCompat.setTint(wrapOtherOff, colorOff); DrawableCompat.setTint(wrapScreenOn, colorOn); DrawableCompat.setTint(wrapHostAllowed, colorOn); DrawableCompat.setTint(wrapHostBlocked, colorOff); }//from w w w . j av a2s.com // Show dialog dialogLegend = new AlertDialog.Builder(this).setView(view).setCancelable(true) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogLegend = null; } }).create(); dialogLegend.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 a v a2 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.mobicage.rogerthat.util.ui.UIUtils.java
public static void setColors(int color, View... views) { if (Build.VERSION.SDK_INT >= 27) { return;//from w ww. j ava 2s . co m } 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: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();/*from w w w . j a va 2 s . com*/ }
From source file:im.getsocial.testapp.MainActivity.java
private void updateToolbarBackButton(ListViewMenu currentMenu) { if (listViewMenuAdapter.isRootMenu()) { toolbar.setNavigationIcon(null); userInfoView.setVisibility(View.VISIBLE); } else {/*from w w w .j a va 2s .c om*/ userInfoView.setVisibility(View.GONE); toolbar.setTitle(currentMenu.getTitle()); Drawable navigationIcon = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); Drawable wrappedNavigationIcon = DrawableCompat.wrap(navigationIcon); DrawableCompat.setTint(wrappedNavigationIcon, getResources().getColor(R.color.primary_text)); toolbar.setNavigationIcon(navigationIcon); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainActivity.this.listViewMenuAdapter.onBackPressed(); } }); } }