androidx.core.widget.ImageViewCompat Java Examples

The following examples show how to use androidx.core.widget.ImageViewCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditorActivity.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View view = convertView;
	
	if (view == null) {
		view = LayoutInflater.from(getContext()).inflate(R.layout.problem_overview_list_item, null);
	}
	
	final CompilerProblem problem = getItem(position);
	
	if (view != null && view instanceof LinearLayout && problem != null) {
		LinearLayout container = (LinearLayout) view;
		TextView problemText = container.findViewById(R.id.problem_overview_list_item_problem_text);
		ImageView problemIcon = container.findViewById(R.id.problem_overview_list_item_problem_icon);
		
		problemText.setText(getProblemOverviewDescription(getContext(), problem));
		
		// Color the problem icon red (error) or yellow (warning)
		ImageViewCompat.setImageTintList(problemIcon, ColorStateList.valueOf(ContextCompat.getColor(getContext(), problem.isError() ? R.color.error_back : R.color.warning_back)));
	}
	
	return view;
}
 
Example #2
Source File: LabelListAdapter.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull AbstractMailboxViewHolder abstractHolder, final int position) {
    if (abstractHolder instanceof MailboxHeaderViewHolder) {
        return;
    }
    MailboxViewHolder holder = (MailboxViewHolder) abstractHolder;
    final Context context = holder.binding.getRoot().getContext();
    final Label label = getItem(position);
    holder.binding.setLabel(label);
    holder.binding.item.setOnClickListener(v -> {
        if (onLabelSelected != null) {
            onLabelSelected.onLabelSelected(label, same(label, this.selectedLabel));
        }
    });
    if (same(label, this.selectedLabel)) {
        holder.binding.item.setBackgroundColor(ContextCompat.getColor(context, R.color.primary12));
        ImageViewCompat.setImageTintList(holder.binding.icon, ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorPrimary)));
    } else {
        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        holder.binding.item.setBackgroundResource(outValue.resourceId);
        ImageViewCompat.setImageTintList(holder.binding.icon, ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorSecondaryOnSurface)));
    }
}
 
Example #3
Source File: MainActivity.java    From Intra with Apache License 2.0 6 votes vote down vote up
private void showInfo(InfoPage page) {
  View view = chooseView(R.id.info_page);

  ActionBar actionBar = getSupportActionBar();
  actionBar.setTitle(page.title);

  ImageView image = view.findViewById(R.id.info_image);
  image.setImageResource(page.drawable);
  int color = ContextCompat.getColor(this, page.good ? R.color.accent_good : R.color.accent_bad);
  ImageViewCompat.setImageTintList(image, ColorStateList.valueOf(color));

  TextView headline = view.findViewById(R.id.info_headline);
  headline.setText(page.headline);

  TextView body = view.findViewById(R.id.info_body);
  body.setText(page.body);
}
 
Example #4
Source File: GameCardView.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
private void setupColors() {
    int foreground = card.black() ? Color.WHITE : Color.BLACK;
    int background = card.black() ? Color.BLACK : getWhiteBackground();

    if (card instanceof Card && ((Card) card).isWinner())
        setCardBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
    else
        setCardBackgroundColor(background);

    text.setTextColor(foreground);
    watermark.setTextColor(foreground);
    numPick.setTextColor(foreground);
    numDraw.setTextColor(foreground);
    ImageViewCompat.setImageTintList(unknown, ColorStateList.valueOf(foreground));
    ImageViewCompat.setImageTintList(primaryAction, ColorStateList.valueOf(foreground));
    ImageViewCompat.setImageTintList(secondaryAction, ColorStateList.valueOf(foreground));
}
 
Example #5
Source File: ChatFragment.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
private void updateTabLayoutTabs() {
    mTabLayout.removeAllTabs();
    final int c = mSectionsPagerAdapter.getCount();
    for (int i = 0; i < c; i++) {
        TabLayout.Tab tab = mTabLayout.newTab();
        tab.setText(mSectionsPagerAdapter.getPageTitle(i));
        tab.setTag(mSectionsPagerAdapter.getChannel(i));
        tab.setCustomView(R.layout.chat_tab);
        TextView textView = tab.getCustomView().findViewById(android.R.id.text1);
        textView.setTextColor(mTabLayout.getTabTextColors());
        ImageViewCompat.setImageTintList(tab.getCustomView().findViewById(R.id.notification_icon), mTabLayout.getTabTextColors());
        updateTabLayoutTab(tab);
        mTabLayout.addTab(tab, false);
    }

    final int currentItem = mViewPager.getCurrentItem();
    if (currentItem != mTabLayout.getSelectedTabPosition() && currentItem < mTabLayout.getTabCount())
        mTabLayout.getTabAt(currentItem).select();
}
 
Example #6
Source File: ExpandableColorSetting.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
protected void setPaletteBtnColor(int color) {
    ViewCompat.setBackgroundTintList(mPaletteBtn, ColorStateList.valueOf(color));
    int paletteIconColor = 0xFFFFFFFF;
    if (ColorUtils.calculateLuminance(color) >= 0.6)
        paletteIconColor = 0xFF000000;
    ImageViewCompat.setImageTintList(mPaletteIcon, ColorStateList.valueOf(paletteIconColor));
}
 
Example #7
Source File: MaterialDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Adapts the dialog's icon.
 */
private void adaptIcon() {
    if (iconImageView != null) {
        ImageViewCompat.setImageTintList(iconImageView, iconTintList);
        ImageViewCompat.setImageTintMode(iconImageView, iconTintMode);
        iconImageView.setImageDrawable(icon);
        iconImageView.setVisibility(icon != null ? View.VISIBLE : View.GONE);
    }

    adaptTitleContainerVisibility();
}
 
Example #8
Source File: RatingBar.java    From Kore with Apache License 2.0 5 votes vote down vote up
private FrameLayout createStar(Context context, AttributeSet attrs, int defStyle) {
    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    AppCompatImageView ivStarBackground = new AppCompatImageView(context, attrs, defStyle);
    ivStarBackground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarBackground.setImageResource(iconResourceId);
    ivStarBackground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarBackground, ColorStateList.valueOf(backgroundColor));
    frameLayout.addView(ivStarBackground);

    ClipDrawable clipDrawable = new ClipDrawable(
            ContextCompat.getDrawable(context, iconResourceId),
            Gravity.START,
            ClipDrawable.HORIZONTAL);

    AppCompatImageView ivStarForeground = new AppCompatImageView(context, attrs, defStyle);
    ivStarForeground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarForeground.setImageDrawable(clipDrawable);
    ivStarForeground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarForeground, ColorStateList.valueOf(foregroundColor));
    frameLayout.addView(ivStarForeground);

    clipDrawables.add((ClipDrawable) ivStarForeground.getDrawable());

    return frameLayout;
}
 
Example #9
Source File: DetailsAdapter.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
void onBindView(Index index) {
    Context context = itemView.getContext();

    icon.setImageResource(index.iconId);
    ImageViewCompat.setImageTintList(
            icon,
            ColorStateList.valueOf(themeManager.getTextContentColor(context))
    );

    title.setText(index.title);
    title.setTextColor(themeManager.getTextContentColor(context));

    content.setText(index.content);
    content.setTextColor(themeManager.getTextSubtitleColor(context));
}
 
Example #10
Source File: SavedColorListAdapter.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void bind(int color) {
    super.bind(color);
    if (ColorUtils.calculateLuminance(color) < 0.6)
        ImageViewCompat.setImageTintList(mIcon, ColorStateList.valueOf(0xFFFFFFFF));
    else
        ImageViewCompat.setImageTintList(mIcon, ColorStateList.valueOf(0xFF000000));
}
 
Example #11
Source File: ThemedToolbar.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    super.addView(child, index, params);
    if (child instanceof AppCompatImageButton) {
        mThemeComponent.addColorProperty(R.attr.actionBarTextColorPrimary, (c) ->
                ImageViewCompat.setImageTintList((ImageView) child, ColorStateList.valueOf(c)));
    } else if (child instanceof ActionMenuView) {
        mThemeComponent.addColorProperty(R.attr.actionBarTextColorPrimary, (c) -> {
            ActionMenuView ch = (ActionMenuView) child;
            Drawable d = DrawableCompat.wrap(ch.getOverflowIcon()).mutate();
            DrawableCompat.setTint(d, c);
            ch.setOverflowIcon(d);
        });
    }
}
 
Example #12
Source File: TextFormatBar.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public void updateFormattingAtCursor() {
    if (mEditText == null)
        return;
    Editable text = mEditText.getText();
    int start = mEditText.getSelectionStart();
    int end = mEditText.getSelectionEnd();
    Object[] spans = text.getSpans(start, end, Object.class);

    mBoldButton.setSelected(false);
    mItalicButton.setSelected(false);
    mUnderlineButton.setSelected(false);

    int fgColor = -1;
    int bgColor = -1;

    for (Object span : spans) {
        if (!SpannableStringHelper.checkSpanInclude(text, span, start, end) ||
                (text.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0)
            continue;
        if (span instanceof StyleSpan) {
            int style = ((StyleSpan) span).getStyle();
            if (style == Typeface.BOLD)
                mBoldButton.setSelected(true);
            else if (style == Typeface.ITALIC)
                mItalicButton.setSelected(true);
        } else if (span instanceof UnderlineSpan) {
            mUnderlineButton.setSelected(true);
        } else if (span instanceof ForegroundColorSpan) {
            fgColor = ((ForegroundColorSpan) span).getForegroundColor();
        } else if (span instanceof BackgroundColorSpan) {
            bgColor = ((BackgroundColorSpan) span).getBackgroundColor();
        }
    }

    ImageViewCompat.setImageTintList(mTextColorValue, fgColor != -1
            ? ColorStateList.valueOf(fgColor) : mTextColorValueDefault);
    ImageViewCompat.setImageTintList(mFillColorValue, bgColor != -1
            ? ColorStateList.valueOf(bgColor) : mFillColorValueDefault);
}
 
Example #13
Source File: ImeCandidatesView.java    From mongol-library with MIT License 5 votes vote down vote up
ViewHolder(View itemView) {
    super(itemView);
    imageView = itemView.findViewById(R.id.keyboard_tool_button_image);
    ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(mTextColor));
    itemView.setOnClickListener(this);
    itemView.setOnTouchListener(this);
}
 
Example #14
Source File: BindingAdapters.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
@BindingAdapter("isFlagged")
public static void setIsFlagged(final ImageView imageView, final boolean isFlagged) {
    if (isFlagged) {
        imageView.setImageResource(R.drawable.ic_star_black_no_padding_24dp);
        ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(ContextCompat.getColor(imageView.getContext(), R.color.indicator)));
    } else {
        imageView.setImageResource(R.drawable.ic_star_border_no_padding_black_24dp);
        ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(ContextCompat.getColor(imageView.getContext(), R.color.colorSecondaryOnSurface)));
    }
}
 
Example #15
Source File: Banner.java    From MaterialBanner with Apache License 2.0 4 votes vote down vote up
private void setIconTintColorInternal(@ColorInt int color) {
    ImageViewCompat.setImageTintList(mIconView, ColorStateList.valueOf(color));
}
 
Example #16
Source File: FirstCardHeaderController.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint({"SetTextI18n", "InflateParams"})
public FirstCardHeaderController(@NonNull GeoActivity activity, @NonNull Location location) {
    this.activity = activity;
    this.view = LayoutInflater.from(activity).inflate(R.layout.container_main_first_card_header, null);

    AppCompatImageView timeIcon = view.findViewById(R.id.container_main_first_card_header_timeIcon);
    TextView refreshTime = view.findViewById(R.id.container_main_first_card_header_timeText);
    TextClock localTime = view.findViewById(R.id.container_main_first_card_header_localTimeText);
    TextView alert = view.findViewById(R.id.container_main_first_card_header_alert);
    View line = view.findViewById(R.id.container_main_first_card_header_line);

    ThemeManager themeManager = ThemeManager.getInstance(activity);

    if (location.getWeather() != null) {
        this.weather = location.getWeather();

        view.setOnClickListener(v ->
                IntentHelper.startManageActivityForResult(activity, MainActivity.MANAGE_ACTIVITY));
        view.setEnabled(!MainDisplayUtils.isMultiFragmentEnabled(activity));

        if (weather.getAlertList().size() == 0) {
            timeIcon.setEnabled(false);
            timeIcon.setImageResource(R.drawable.ic_time);
        } else {
            timeIcon.setEnabled(true);
            timeIcon.setImageResource(R.drawable.ic_alert);
        }
        ImageViewCompat.setImageTintList(
                timeIcon,
                ColorStateList.valueOf(themeManager.getTextContentColor(activity))
        );
        timeIcon.setOnClickListener(this);

        refreshTime.setText(
                activity.getString(R.string.refresh_at)
                        + " "
                        + Base.getTime(activity, weather.getBase().getUpdateDate())
        );
        refreshTime.setTextColor(themeManager.getTextContentColor(activity));

        long time = System.currentTimeMillis();
        if (TimeZone.getDefault().getOffset(time) == location.getTimeZone().getOffset(time)) {
            // same time zone.
            localTime.setVisibility(View.GONE);
        } else {
            localTime.setVisibility(View.VISIBLE);
            localTime.setTimeZone(location.getTimeZone().getID());
            localTime.setTextColor(themeManager.getTextSubtitleColor(activity));
            localTime.setFormat12Hour(
                    activity.getString(R.string.date_format_widget_long) + ", h:mm aa"
            );
            localTime.setFormat24Hour(
                    activity.getString(R.string.date_format_widget_long) + ", HH:mm"
            );
        }

        if (weather.getAlertList().size() == 0) {
            alert.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
        } else {
            alert.setVisibility(View.VISIBLE);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < weather.getAlertList().size(); i ++) {
                builder.append(weather.getAlertList().get(i).getDescription())
                        .append(", ")
                        .append(
                                DateFormat.getDateTimeInstance(
                                        DateFormat.LONG,
                                        DateFormat.DEFAULT
                                ).format(weather.getAlertList().get(i).getDate())
                        );
                if (i != weather.getAlertList().size() - 1) {
                    builder.append("\n");
                }
            }
            alert.setText(builder.toString());
            alert.setTextColor(themeManager.getTextSubtitleColor(activity));

            line.setVisibility(View.VISIBLE);
            line.setBackgroundColor(themeManager.getRootColor(activity));
        }
        alert.setOnClickListener(this);
    }
}
 
Example #17
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the back/up icon drawable; does not set other icons
 */
public void setBackIconColor(@ColorInt int color) {
    ImageViewCompat.setImageTintList(backButton, ColorStateList.valueOf(color));
}
 
Example #18
Source File: LocationManageFragment.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setThemeStyle() {
    ThemeManager themeManager = ThemeManager.getInstance(requireActivity());

    ImageViewCompat.setImageTintList(
            searchIcon,
            ColorStateList.valueOf(themeManager.getTextContentColor(requireActivity()))
    );
    ImageViewCompat.setImageTintList(
            currentLocationButton,
            ColorStateList.valueOf(themeManager.getTextContentColor(requireActivity()))
    );
    searchTitle.setTextColor(
            ColorStateList.valueOf(themeManager.getTextSubtitleColor(requireActivity())));

    // background.
    if (colorAnimator != null) {
        colorAnimator.cancel();
        colorAnimator = null;
    }

    int oldColor = Color.TRANSPARENT;
    Drawable background = recyclerView.getBackground();
    if (background instanceof ColorDrawable) {
        oldColor = ((ColorDrawable) background).getColor();
    }
    int newColor = themeManager.getRootColor(requireActivity());

    if (newColor != oldColor) {
        colorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), oldColor, newColor);
        colorAnimator.addUpdateListener(animation -> {
            cardView.setCardBackgroundColor((Integer) animation.getAnimatedValue());
            recyclerView.setBackgroundColor((Integer) animation.getAnimatedValue());
        });
        colorAnimator.setDuration(450);
        colorAnimator.start();
    } else {
        cardView.setCardBackgroundColor(newColor);
        recyclerView.setBackgroundColor(newColor);
    }

    if (decoration != null) {
        recyclerView.removeItemDecoration(decoration);
        decoration = null;
    }
    decoration = new MainListDecoration(requireActivity());
    recyclerView.addItemDecoration(decoration);
}
 
Example #19
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 4 votes vote down vote up
/**
 * Sets icons colors, does not set back/up icon
 */
public void setIconsColor(@ColorInt int color) {
    ImageViewCompat.setImageTintList(clearButton, ColorStateList.valueOf(color));
    ImageViewCompat.setImageTintList(voiceButton, ColorStateList.valueOf(color));
}
 
Example #20
Source File: RandomActivity.java    From NClientV2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Global.initActivity(this);
    setContentView(R.layout.activity_random);
    loader=new RandomLoader(this);


    //init components id
    Toolbar toolbar=findViewById(R.id.toolbar);
    FloatingActionButton shuffle = findViewById(R.id.shuffle);
    ImageButton share = findViewById(R.id.share);
    censor=findViewById(R.id.censor);
    language=findViewById(R.id.language);
    thumbnail=findViewById(R.id.thumbnail);
    favorite=findViewById(R.id.favorite);
    title=findViewById(R.id.title);
    page=findViewById(R.id.pages);

    //init toolbar
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setTitle(R.string.random_manga);


    if(loadedGallery!=null)loadGallery(loadedGallery);

    shuffle.setOnClickListener(v -> loader.requestGallery());

    thumbnail.setOnClickListener(v -> {
        if(loadedGallery!=null) {
            Intent intent = new Intent(RandomActivity.this, GalleryActivity.class);
            intent.putExtra(RandomActivity.this.getPackageName() + ".GALLERY", loadedGallery);
            RandomActivity.this.startActivity(intent);
        }
    });
    share.setOnClickListener(v -> {
        if(loadedGallery!=null)Global.shareGallery(RandomActivity.this,loadedGallery);
    });
    censor.setOnClickListener(v -> censor.setVisibility(View.GONE));

    favorite.setOnClickListener(v -> {
        if(loadedGallery!=null){
            if(isFavorite){
                if(Favorites.removeFavorite(loadedGallery)) isFavorite=false;
            }else if(Favorites.addFavorite(loadedGallery)) isFavorite=true;
        }
        favoriteUpdateButton();
    });

    ColorStateList colorStateList=ColorStateList.valueOf(Global.getTheme()== Global.ThemeScheme.LIGHT? Color.WHITE:Color.BLACK);

    ImageViewCompat.setImageTintList(shuffle,colorStateList);
    ImageViewCompat.setImageTintList(share,colorStateList);
    ImageViewCompat.setImageTintList(favorite,colorStateList);

    Global.setTint(shuffle.getContentBackground());
    Global.setTint(share.getDrawable());
    Global.setTint(favorite.getDrawable());
}