List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint
public static void setTint(Drawable drawable, int i)
From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomNavigationTextView.java
private void applyColorFilters() { if (isSelected()) { DrawableCompat.setTint(mTopDrawable, mTextActiveColorFilter); setTextColor(mTextActiveColorFilter); } else {//from ww w .j ava2s . c o m DrawableCompat.setTintList(mTopDrawable, ColorStateList.valueOf(mInactiveTextColor)); if (!mShiftingMode) { setTextColor(mInactiveTextColor); } } }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static void drawWordmarkFromStaticImage(@NonNull Context context, @NonNull Canvas canvas, boolean isArticleRTL) { // scaling it a bit down from original 317x54px size final int width = 130; final int height = 22; final int bottom = HEIGHT - BOTTOM_PADDING; final int top = bottom - height; Drawable d = ContextCompat.getDrawable(context, R.drawable.wp_wordmark); DrawableCompat.setTint(d, Color.LTGRAY); int left = WIDTH - HORIZONTAL_PADDING - width; if (isArticleRTL) { left = HORIZONTAL_PADDING;/*from w ww .ja v a 2s. c o m*/ } int right = left + width; d.setBounds(left, top, right, bottom); d.draw(canvas); }
From source file:info.bartowski.easteregg.LLand.java
private void reset() { L("reset");/*from ww w .ja v a 2 s. c o m*/ final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]); sky.setDither(true); setBackground(sky); mFlipped = frand() > 0.5f; setScaleX(mFlipped ? -1 : 1); setScore(0); int i = getChildCount(); while (i-- > 0) { final View v = getChildAt(i); if (v instanceof GameView) { removeViewAt(i); } } mObstaclesInPlay.clear(); mWidth = getWidth(); mHeight = getHeight(); boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25; if (showingSun) { final Star sun = new Star(getContext()); sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun)); final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size); sun.setTranslationX(frand(w, mWidth - w)); if (mTimeOfDay == DAY) { sun.setTranslationY(frand(w, (mHeight * 0.66f))); DrawableCompat.setTint(sun.getBackground(), 0); } else { sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w)); DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP); DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000); } addView(sun, new LayoutParams(w, w)); } if (!showingSun) { final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT; final float ff = frand(); if ((dark && ff < 0.75f) || ff < 0.5f) { final Star moon = new Star(getContext()); moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon)); moon.getBackground().setAlpha(dark ? 255 : 128); moon.setScaleX(frand() > 0.5 ? -1 : 1); moon.setRotation(moon.getScaleX() * frand(5, 30)); final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size); moon.setTranslationX(frand(w, mWidth - w)); moon.setTranslationY(frand(w, mHeight - w)); addView(moon, new LayoutParams(w, w)); } } final int mh = mHeight / 6; final boolean cloudless = frand() < 0.25; final int N = 20; for (i = 0; i < N; i++) { final float r1 = frand(); final Scenery s; if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) { s = new Star(getContext()); } else if (r1 < 0.6 && !cloudless) { s = new Cloud(getContext()); } else { s = new Building(getContext()); s.z = (float) i / N; ViewCompat.setTranslationZ(s, PARAMS.SCENERY_Z * (1 + s.z)); s.v = 0.85f * s.z; // buildings move proportional to their distance hsv[0] = 175; hsv[1] = 0.25f; hsv[2] = 1 * s.z; s.setBackgroundColor(Color.HSVToColor(hsv)); s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh); } final LayoutParams lp = new LayoutParams(s.w, s.h); if (s instanceof Building) { lp.gravity = Gravity.BOTTOM; } else { lp.gravity = Gravity.TOP; final float r = frand(); if (s instanceof Star) { lp.topMargin = (int) (r * r * mHeight); } else { lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2; } } addView(s, lp); s.setTranslationX(frand(-lp.width, mWidth + lp.width)); } mDroid = new Player(getContext()); mDroid.setX(mWidth / 2); mDroid.setY(mHeight / 2); addView(mDroid, new LayoutParams(PARAMS.PLAYER_SIZE, PARAMS.PLAYER_SIZE)); mAnim = new TimeAnimator(); mAnim.setTimeListener(new TimeAnimator.TimeListener() { @Override public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) { step(t, dt); } }); }
From source file:com.finchuk.clock2.timepickers.Utils.java
/** * Returns a tinted drawable from the given drawable resource and color resource. *//*from www . j av a 2s . c o m*/ public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes int drawableRes, @ColorInt int colorInt) { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes).mutate()); DrawableCompat.setTint(d, colorInt); return d; }
From source file:com.google.android.apps.forscience.whistlepunk.EditNoteDialog.java
@Override public AlertDialog onCreateDialog(Bundle savedInstanceState) { mLabel = getArguments().getParcelable(KEY_SAVED_LABEL); String timeText = getArguments().getString(KEY_SAVED_TIME_TEXT, ""); String timeTextContentDescription = getArguments().getString(KEY_SAVED_TIME_TEXT_DESCRIPTION); mTimestamp = getArguments().getLong(KEY_SAVED_TIMESTAMP); try {/*w ww . ja v a 2 s . c om*/ mSelectedValue = GoosciLabelValue.LabelValue.parseFrom(getArguments().getByteArray(KEY_SELECTED_VALUE)); } catch (InvalidProtocolBufferNanoException ex) { Log.wtf(TAG, "Couldn't parse label value"); } AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); LinearLayout rootView = (LinearLayout) LayoutInflater.from(getActivity()) .inflate(R.layout.run_review_label_edit, null); alertDialog.setView(rootView); ImageView imageView = (ImageView) rootView.findViewById(R.id.picture_note_preview_image); final EditText editText = (EditText) rootView.findViewById(R.id.edit_note_text); TextView autoTextView = (TextView) rootView.findViewById(R.id.auto_note_text); // Use mSelectedValue to load content, because the user may have changed the value since // it was stored in the label. Note that picture labels can't be edited at this time, // but in the future this will apply to picture labels as well. if (mLabel instanceof PictureLabel) { imageView.setVisibility(View.VISIBLE); autoTextView.setVisibility(View.GONE); editText.setText(PictureLabel.getCaption(mSelectedValue)); editText.setHint(R.string.picture_note_caption_hint); Glide.with(getActivity()).load(PictureLabel.getFilePath(mSelectedValue)).into(imageView); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PictureUtils.launchExternalViewer(getActivity(), (PictureLabel.getFilePath(mSelectedValue))); } }); } else if (mLabel instanceof TextLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.GONE); editText.setText(TextLabel.getText(mSelectedValue)); } else if (mLabel instanceof SensorTriggerLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.VISIBLE); editText.setText(SensorTriggerLabel.getCustomText(mSelectedValue)); String autoText = SensorTriggerLabel.getAutogenText(mSelectedValue); TriggerHelper.populateAutoTextViews(autoTextView, autoText, R.drawable.ic_label_black_24dp, getResources()); } alertDialog.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mLabel.setTimestamp(mTimestamp); if (mLabel instanceof TextLabel) { ((TextLabel) mLabel).setText(editText.getText().toString()); } else if (mLabel instanceof PictureLabel) { ((PictureLabel) mLabel).setCaption(editText.getText().toString()); } else if (mLabel instanceof SensorTriggerLabel) { ((SensorTriggerLabel) mLabel).setCustomText(editText.getText().toString()); } getDataController().editLabel(mLabel, ((EditNoteDialogListener) getParentFragment()).onLabelEdit(mLabel)); } }); alertDialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.setCancelable(true); TextView timeTextView = (TextView) rootView.findViewById(R.id.edit_note_time); timeTextView.setText(timeText); timeTextView.setContentDescription(timeTextContentDescription); if (labelBelongsToRun() && mLabel.canEditTimestamp()) { timeTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GoosciLabelValue.LabelValue value = new GoosciLabelValue.LabelValue(); if (mLabel instanceof PictureLabel) { // Captions can be edited, but the picture path cannot be edited at this // time. PictureLabel.populateStorageValue(value, ((PictureLabel) mLabel).getFilePath(), editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } else if (mLabel instanceof TextLabel) { TextLabel.populateStorageValue(value, editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } } }); } else if (labelBelongsToRun()) { Drawable lockDrawable = getResources().getDrawable(R.drawable.ic_lock_black_18dp); DrawableCompat.setTint(lockDrawable, getResources().getColor(R.color.text_color_light_grey)); // There is already a start drawable. Use it again. Drawable[] drawables = timeTextView.getCompoundDrawablesRelative(); timeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], null, lockDrawable, null); } AlertDialog dialog = alertDialog.create(); if (mLabel instanceof TextLabel || mLabel instanceof SensorTriggerLabel) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } return dialog; }
From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java
private Drawable initArrowDrawable(int drawableTint) { Drawable drawable = ContextCompat.getDrawable(getContext(), arrowDrawableResId); if (drawable != null) { drawable = DrawableCompat.wrap(drawable); if (drawableTint != Integer.MAX_VALUE && drawableTint != 0) { DrawableCompat.setTint(drawable, drawableTint); }//from w ww . j av a 2s. c o m } return drawable; }
From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java
public void setTint(int tint) { if (mDelegateDrawable != null) { DrawableCompat.setTint(mDelegateDrawable, tint); return;/* w ww . ja va 2 s . c om*/ } mAnimatedVectorState.mVectorDrawable.setTint(tint); }
From source file:org.gateshipone.malp.application.fragments.serverfragments.AlbumsFragment.java
/** * Initialize the options menu./*from w ww.j a va 2s. co m*/ * Be sure to call {@link #setHasOptionsMenu} before. * * @param menu The container for the custom options menu. * @param menuInflater The inflater to instantiate the layout. */ @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { // Inflate the menu; this adds items to the action bar if it is present. if (null != mArtist && !mArtist.getArtistName().equals("")) { menuInflater.inflate(R.menu.fragment_menu_albums, menu); // get tint color int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent); Drawable drawable = menu.findItem(R.id.action_add_artist).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, tintColor); menu.findItem(R.id.action_add_artist).setIcon(drawable); menu.findItem(R.id.action_reset_artwork).setVisible(true); } super.onCreateOptionsMenu(menu, menuInflater); }
From source file:com.appyvet.materialrangebar.PinView.java
@Override public void draw(Canvas canvas) { //Draw the circle boundary only if mCircleBoundaryPaint was initialized if (mCircleBoundaryPaint != null) canvas.drawCircle(mX, mY, mCircleRadiusPx, mCircleBoundaryPaint); canvas.drawCircle(mX, mY, mCircleRadiusPx, mCirclePaint); //Draw pin if pressed if (mPinRadiusPx > 0 && (mHasBeenPressed || !mPinsAreTemporary)) { mBounds.set((int) mX - mPinRadiusPx, (int) mY - (mPinRadiusPx * 2) - (int) mPinPadding, (int) mX + mPinRadiusPx, (int) mY - (int) mPinPadding); mPin.setBounds(mBounds);// www . j a va2s .co m String text = mValue; if (this.formatter != null) { text = formatter.format(text); } calibrateTextSize(mTextPaint, text, mBounds.width()); mTextPaint.getTextBounds(text, 0, text.length(), mBounds); mTextPaint.setTextAlign(Paint.Align.CENTER); DrawableCompat.setTint(mPin, pinColor); mPin.draw(canvas); canvas.drawText(text, mX, mY - mPinRadiusPx - mPinPadding + mTextYPadding, mTextPaint); } super.draw(canvas); }
From source file:org.floens.chan.ui.controller.AlbumDownloadController.java
@SuppressWarnings("deprecation") private void setItemChecked(AlbumDownloadCell cell, boolean checked, boolean animated) { float scale = checked ? 0.75f : 1f; if (animated) { cell.thumbnailView.animate().scaleX(scale).scaleY(scale).setInterpolator(new DecelerateInterpolator(3f)) .setDuration(500).start(); } else {// w w w.ja v a 2 s . c o m cell.thumbnailView.setScaleX(scale); cell.thumbnailView.setScaleY(scale); } Drawable drawable = context.getResources().getDrawable( checked ? R.drawable.ic_check_circle_white_24dp : R.drawable.ic_radio_button_unchecked_white_24dp); if (checked) { Drawable wrapped = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrapped, ThemeHelper.PrimaryColor.BLUE.color); cell.checkbox.setImageDrawable(wrapped); } else { cell.checkbox.setImageDrawable(drawable); } }