Java Code Examples for androidx.cardview.widget.CardView#setCardBackgroundColor()

The following examples show how to use androidx.cardview.widget.CardView#setCardBackgroundColor() . 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: ServerStatusPreference.java    From FCM-for-Mojo with GNU General Public License v3.0 6 votes vote down vote up
private void updateStatus(CharSequence text, @AttrRes int attr, Drawable icon) {
    if (mViewHolder != null) {
        CardView statusCard = (CardView) ((ViewGroup) mViewHolder.itemView).getChildAt(0);
        TextView status = statusCard.findViewById(android.R.id.text1);

        if (icon != null) {
            icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
            status.setCompoundDrawablesRelative(icon, null, null, null);
        } else {
            status.setCompoundDrawablesRelative(null, null, null, null);
        }
        status.setText(text);

        int[] attrs = {attr};
        TypedArray a = getContext().obtainStyledAttributes(attrs);
        int color = a.getColor(0, 0);
        a.recycle();

        statusCard.setCardBackgroundColor(color);
    }
}
 
Example 2
Source File: ListHeadingCardItemView.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
public void build(@NonNull ListHeadingCard card) {
    super.build(card);

    Version1TextView leftText = (Version1TextView) findViewById(R.id.left_text);
    Version1TextView rightText = (Version1TextView) findViewById(R.id.right_text);

    if (card.getLeftText() == null) {
        leftText.setVisibility(GONE);
    } else {
        leftText.setText(card.getLeftText());
        leftText.setVisibility(VISIBLE);
    }

    if (card.getRightText() == null) {
        rightText.setVisibility(GONE);
    } else {
        rightText.setText(card.getRightText());
        rightText.setVisibility(VISIBLE);
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(getResources().getColor(R.color.overlay_white_with_20));
    }
}
 
Example 3
Source File: StatusCardItemView.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void build(@NonNull StatusCard card) {
    super.build(card);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(getContext().getResources().getColor(R.color.overlay_white_with_10));
    }

    ImageView image = (ImageView) findViewById(R.id.image);
    Version1TextView title = (Version1TextView) findViewById(R.id.title);
    Version1TextView description = (Version1TextView) findViewById(R.id.description);

    image.setImageResource(card.getImageResource());
    title.setText(card.getTitle());
    description.setText(card.getDescription());

    if (card.isDividerShown()) {
        showDivider();
    }
}
 
Example 4
Source File: BinarySwitchCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void build(@NonNull BinarySwitchCard card) {
    super.build(card);
    clickListener = card.getClickListener();

    TextView title = (TextView)this.findViewById(R.id.title);
    title.setText(card.getTitle());
    if(card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView)this.findViewById(R.id.description);
    description.setText(card.getDescription());
    if(card.getTitleColor() != -1) {
        description.setTextColor(card.getTitleColor());
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    ToggleButton button = (ToggleButton) this.findViewById(R.id.toggle);
    if (button != null) {
        button.setOnClickListener(this);
        button.setChecked(card.getToggleChecked());
    }
}
 
Example 5
Source File: HorizontalAlbumAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setColors(int color, ViewHolder holder) {
    if (holder.itemView != null) {
        CardView card=(CardView)holder.itemView;
        card.setCardBackgroundColor(color);
        if (holder.title != null) {
                holder.title.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)));
        }
        if (holder.text != null) {
                holder.text.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color)));
        }
    }
}
 
Example 6
Source File: DNSRelaysAdapter.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
DNSRelaysViewHolder(@NonNull View itemView) {
    super(itemView);

    CardView cardDNSRelay = itemView.findViewById(R.id.cardDNSRelay);
    cardDNSRelay.setCardBackgroundColor(context.getResources().getColor(R.color.colorFirst));
    cardDNSRelay.setFocusable(true);
    cardDNSRelay.setOnClickListener(this);
    cardDNSRelay.setOnFocusChangeListener(this);

    tvDNSRelayName = itemView.findViewById(R.id.tvDNSRelayName);
    tvDNSRelayDescription = itemView.findViewById(R.id.tvDNSRelayDescription);
    chbDNSRelay = itemView.findViewById(R.id.chbDNSRelay);
    chbDNSRelay.setOnCheckedChangeListener(this);
}
 
Example 7
Source File: OverviewRecyclerBaseFragment.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
ComicViewHolder(View itemView) {
    super(itemView);
    cv = (CardView) itemView;
    if (themePrefs.amoledThemeEnabled()) {
        cv.setCardBackgroundColor(Color.BLACK);
    } else if (themePrefs.nightThemeEnabled()) {
        cv.setCardBackgroundColor(ContextCompat.getColor(getActivity(), R.color.background_material_dark));
    }
    comicTitle = itemView.findViewById(R.id.comic_title);
    comicInfo = itemView.findViewById(R.id.comic_info);
    thumbnail = itemView.findViewById(R.id.thumbnail);
}
 
Example 8
Source File: CareTopCardBehaviorView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void build(@NonNull CareStatusCard card) {
    super.build(card);

    mDashedCircleView = (DashedCircleView) findViewById(R.id.dashed_circle);

    mCenterTopTextView = (Version1TextView) findViewById(R.id.center_top_text);
    mCenterBottomTextView = (Version1TextView) findViewById(R.id.center_bottom_text);

    mTopIconView = (ImageView) findViewById(R.id.top_icon);
    mTopLineView = findViewById(R.id.top_line);
    mLeftAlarmIcon = (ImageView) findViewById(R.id.left_alarm_icon);
    mCenterAlarmText = (Version1TextView) findViewById(R.id.center_alarm_text);
    mRightAlarmIcon = (ImageView) findViewById(R.id.right_alarm_icon);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    // Configure the card view based on the alarmstate
    handleAlarmState(card);
}
 
Example 9
Source File: WhatIfOverviewFragment.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
ComicViewHolder(View itemView) {
    super(itemView);
    cv = (CardView) itemView.findViewById(R.id.cv);
    if (themePrefs.amoledThemeEnabled()) {
        cv.setCardBackgroundColor(Color.BLACK);
    } else if (themePrefs.nightThemeEnabled()) {
        cv.setCardBackgroundColor(ContextCompat.getColor(context, R.color.background_material_dark));
    }
    articleTitle = (TextView) itemView.findViewById(R.id.article_title);
    articleNumber = (TextView) itemView.findViewById(R.id.article_info);
    thumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
    if (themePrefs.invertColors(false) || themePrefs.amoledThemeEnabled())
        thumbnail.setColorFilter(themePrefs.getNegativeColorFilter());
}
 
Example 10
Source File: DeviceCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
protected void showCardFirmwareUpdating(@NonNull final DeviceCard card) {
    CardView cardView = findViewById(R.id.cardView);
    if (cardView == null) {
        return;
    }

    cardView.setCardBackgroundColor(getContext().getResources().getColor(R.color.black_with_20));
    if (card.isDividerShown()) {
        showDivider(true);
    }

    View firmwareUpdateContainer = findViewById(R.id.camera_controls_firmware_container);
    View onlineContainer = findViewById(R.id.camera_controls_container);
    View noPreviewImage = findViewById(R.id.preview_image_unavailable);

    firmwareUpdateContainer.setVisibility(VISIBLE);
    onlineContainer.setVisibility(GONE);
    noPreviewImage.setVisibility(VISIBLE);

    TextView offlineName = findViewById(R.id.device_name_firmware);
    offlineName.setText(card.getTitle());

    previewImage = findViewById(R.id.preview_image);
    if (previewImage != null) {
        previewImage.setImageBitmap(null);
        previewImage.setOnClickListener(null);
    }
}
 
Example 11
Source File: CaptionBackgroundPainter.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public void addColorBackgroundToCaption(CardView captionView, String captionColor) {
  if (captionColor != null && !captionColor.isEmpty()) {
    try {
      captionView.setCardBackgroundColor(Color.parseColor(captionColor));
    } catch (IllegalArgumentException e) {
      setDefaultBackgroundColor(captionView);
    }
  } else {
    setDefaultBackgroundColor(captionView);
  }
}
 
Example 12
Source File: DeviceCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
protected void showCardUnavailable(@NonNull final DeviceCard card) {
    CardView cardView = findViewById(R.id.cardView);
    if (cardView == null) {
        return;
    }

    if (card.isDividerShown()) {
        showDivider(true);
    }

    View unavailableContainer = findViewById(R.id.camera_controls_unavailable_container);
    View onlineContainer = findViewById(R.id.camera_controls_container);
    View noPreviewImage = findViewById(R.id.preview_image_unavailable);

    unavailableContainer.setVisibility(VISIBLE);
    onlineContainer.setVisibility(GONE);
    noPreviewImage.setVisibility(VISIBLE);

    TextView offlineName = findViewById(R.id.device_name_unavailable);
    offlineName.setText(card.getTitle());

    previewImage = findViewById(R.id.preview_image);
    if (card.getCacheFile() != null) {
        previewImage.setImageBitmap(null);
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }
    else {
        cardView.setCardBackgroundColor(getContext().getResources().getColor(R.color.black_with_20));
    }
}
 
Example 13
Source File: BaseClimateScheduleCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void build(@NonNull BaseClimateScheduleCard card) {
    super.build(card);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    TextView leftText = (TextView) findViewById(R.id.climate_schedule_left_text);
    TextView rightText = (TextView) findViewById(R.id.climate_schedule_right_text);
    ImageView weatherIcon = (ImageView) findViewById(R.id.climate_schedule_weather_icon);

    ScheduledSetPoint point = card.getScheduledSetPoint();
    if(point !=null) {
        leftText.setText(DateUtils.format(point.getTimeOfDay(), true));
        switch (point.getTimeOfDay().getDayTime()) {
            case DAYTIME:
                weatherIcon.setImageResource(R.drawable.icon_day);
                break;
            case NIGHTTIME:
                weatherIcon.setImageResource(R.drawable.icon_night);
                break;
            case SUNRISE:
                weatherIcon.setImageResource(R.drawable.icon_sunrise);
                break;
            case SUNSET:
                weatherIcon.setImageResource(R.drawable.icon_sunset);
                break;
            default:
                weatherIcon.setImageResource(R.drawable.icon_day);
                break;
        }
        listener.updateRightText(rightText, point);
    }
}
 
Example 14
Source File: IrrigationModeSelectionCardItemView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void build(@NonNull IrrigationModeSelectionCard card) {
    super.build(card);

    TextView title = (TextView) this.findViewById(R.id.title);

    mRadioButton = (ImageView) this.findViewById((R.id.rad_button));

    title.setText(card.getTitle());
    if (card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView) this.findViewById(R.id.description);
    if (card.getDescription() != null) {
        description.setVisibility(VISIBLE);
        description.setText(card.getDescription());
        if (card.getDescriptionColor() != -1) {
            description.setTextColor(card.getDescriptionColor());
        }
    } else {
        description.setVisibility(GONE);
    }

    TextView rightText = (TextView) this.findViewById(R.id.right_text);
    if (card.getRightText() == null) {
        rightText.setVisibility(GONE);
    } else {
        rightText.setText(card.getRightText());
    }

    imageView = (ImageView) this.findViewById(R.id.image);
    imageView.setVisibility(VISIBLE);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isChevronShown()) {
        showChevron();
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    checkRadioButton(card);

    if(card.getShowScheduleIcon()) {
        findViewById(R.id.sched_icon).setVisibility(View.VISIBLE);
    }

}
 
Example 15
Source File: CareAlarmCardItemView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void build(@NonNull CareAlarmCard card) {
    super.build(card);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(getContext().getResources().getColor(R.color.overlay_white_with_10));
    }

    String mode = card.getMode();
    if (mode != null && !mode.equals("")) {
        ImageView stateIcon = (ImageView) findViewById(R.id.state_icon);
        switch (mode) {
            case AlarmStatus.MODE_OFF:
                stateIcon.setImageResource(R.drawable.button_off);
                break;
            case AlarmStatus.MODE_ON:
                stateIcon.setImageResource(R.drawable.button_on);
                break;
            case AlarmStatus.MODE_PARTIAL:
                stateIcon.setImageResource(R.drawable.button_partial);
                break;
            default:
                break;
        }
    }

    String state = card.getState();
    if (state != null && !state.equals("")) {
        Version1TextView title = (Version1TextView) findViewById(R.id.state_title);
        title.setText("Alarm " + state);
    }

    if (card.getDate() != null) {
        Version1TextView subtitle = (Version1TextView) findViewById(R.id.state_subtitle);
        long difference = StringUtils.howManyDaysBetween(Calendar.getInstance().getTime(), card.getDate());
        if(difference >0){
            String days = difference ==1 ? "day" : "days";
            subtitle.setText("since " + difference + " " + days);
        }else{
            SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
            subtitle.setText("Set at " + formatter.format(card.getDate()));
        }

    }

    if (card.isDividerShown()) {
        showDivider();
    }
}
 
Example 16
Source File: LeftScheduleTextCardItemView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void build(@NonNull LeftScheduleTextCard card) {
    super.build(card);

    TextView title = (TextView) this.findViewById(R.id.title);

    mRadioButton = (ImageView) this.findViewById((R.id.rad_button));
    mImageViewSched = (ImageView) this.findViewById((R.id.sched_icon));

    title.setText(card.getTitle());
    if (card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView) this.findViewById(R.id.description);
    if (card.getDescription() != null) {
        description.setVisibility(VISIBLE);
        description.setText(card.getDescription());
        if (card.getDescriptionColor() != -1) {
            description.setTextColor(card.getDescriptionColor());
        }
    } else {
        description.setVisibility(GONE);
    }

    TextView rightText = (TextView) this.findViewById(R.id.right_text);
    if (card.getRightText() == null) {
        rightText.setVisibility(GONE);
    } else {
        rightText.setVisibility(VISIBLE);
        rightText.setText(card.getRightText());
    }

    imageView = (ImageView) this.findViewById(R.id.image);
    imageView.setVisibility(VISIBLE);
    switch (card.getImageDisplayType()) {
        case RESOURCE:
            setResourceImageToView(card);
            break;
        case DEVICE:
            setDeviceImageToView(card);
            break;
        case PERSON:
            setPersonImageToView(card);
            break;
        case PLACE:
            setPlaceImageToView(card);
            break;

        default:
            hideImageView();
            break;
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isChevronShown()) {
        showChevron();
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    showScheduleIcon(card);
    checkRadioButton(card);
}
 
Example 17
Source File: PopupCardItemView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void build(@NonNull PopupCard card) {
    super.build(card);

    TextView title = (TextView)this.findViewById(R.id.title);
    title.setText(card.getTitle());
    if(card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }
    else if (card.isDarkColorScheme()) {
        title.setTextColor(Color.BLACK);
    }

    TextView description = (TextView)this.findViewById(R.id.description);
    if (card.getDescription() != null) {
        description.setText(card.getDescription());
        if (card.getTitleColor() != -1) {
            description.setTextColor(card.getTitleColor());
        }
        else if (card.isDarkColorScheme()) {
            description.setTextColor(Color.BLACK);
        }
    }
    else {
        description.setVisibility(GONE);
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
        cardView.setOnClickListener(this);
    }
    listener = card.getClickListener();

    TextView rightText = (TextView) this.findViewById(R.id.right_text);
    if (card.getRightText() != null) {
        rightText.setVisibility(VISIBLE);
        rightText.setText(card.getRightText());
        if (card.isDarkColorScheme()) {
            rightText.setTextColor(Color.BLACK);
        }
    }
    else {
        rightText.setVisibility(GONE);
    }

    if (card.isDividerShown()) {
        showDivider(card.isDarkColorScheme());
    }

    showChevron(card.isDarkColorScheme());
}
 
Example 18
Source File: DeviceControlCardItemPetView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void build(@NonNull PetControlCard card) {
    super.build(card);

    CardView cardView = (CardView) findViewById(R.id.cardView);
    View divider = findViewById(R.id.divider);
    if (cardView != null) {
        if (card.isOffline()) {
            cardView.setCardBackgroundColor(getContext().getResources().getColor(R.color.overlay_white_with_10));
            divider.setBackgroundColor(getContext().getResources().getColor(R.color.black_with_10));
        } else {
            cardView.setCardBackgroundColor(Color.TRANSPARENT);
            divider.setBackgroundColor(getContext().getResources().getColor(R.color.overlay_white_with_10));
        }
    }

    Version1TextView titleText = (Version1TextView) findViewById(R.id.card_device_control_title_text);
    Version1TextView modeButton = (Version1TextView) findViewById(R.id.mode_button);
    Version1TextView descText = (Version1TextView) findViewById(R.id.card_device_control_description_text);
    RelativeLayout modeButtonRegion = (RelativeLayout) findViewById(R.id.mode_button_clickable_region);

    ImageView chevronButton = (ImageView) findViewById(R.id.card_device_control_chevron);
    GlowableImageView topButton = (GlowableImageView) findViewById(R.id.card_device_control_device_image);

    if(card.getDeviceId() !=null){
        final DeviceModel model = SessionModelManager.instance().getDeviceWithId(card.getDeviceId(), false);
        if(model!=null) {
            topButton.setVisibility(VISIBLE);
            ImageManager.with(getContext())
                    .putSmallDeviceImage(model)
                    .withTransformForStockImages(new BlackWhiteInvertTransformation(Invert.BLACK_TO_WHITE))
                    .withPlaceholder(R.drawable.device_list_placeholder)
                    .withError(R.drawable.device_list_placeholder)
                    .noUserGeneratedImagery()
                    .into(topButton)
                    .execute();
            if(card.getGlowMode() !=null){
                topButton.setGlowMode(card.getGlowMode());
                topButton.setGlowing(card.shouldGlow());
            }
        }else{
            topButton.setVisibility(VISIBLE);
            topButton.setImageResource(R.drawable.device_list_placeholder);
        }
    }else{
        if(card.getTopImageResource() == 0){
            topButton.setVisibility(INVISIBLE);
        }else{
            topButton.setVisibility(VISIBLE);
            topButton.setImageResource(card.getTopImageResource());

        }
    }

    topButton.setEnabled(card.isTopButtonEnabled());
    topButton.setAlpha(card.isTopButtonEnabled() ? BUTTON_ENABLED_ALPHA : BUTTON_DISABLED_ALPHA);

    titleText.setText(card.getTitle());
    descText.setText(card.getDescription());

    modeButton.setText(card.getPetDoorStatus());

    mListener = card.getCallbackListener();

    cardView.setOnClickListener(this);
    modeButton.setOnClickListener(this);
    chevronButton.setOnClickListener(this);
    topButton.setOnClickListener(this);
    modeButtonRegion.setOnClickListener(this);

    if (card.isDividerShown()) {
        showDivider();
    }
}
 
Example 19
Source File: LeftTextCardItemView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void build(@NonNull LeftTextCard card) {
    super.build(card);

    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(card.getTitle());
    if (card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView) this.findViewById(R.id.description);
    if (card.getDescription() != null) {
        description.setVisibility(VISIBLE);
        description.setText(card.getDescription());
        if (card.getDescriptionColor() != -1) {
            description.setTextColor(card.getDescriptionColor());
        }
    }
    else {
        description.setVisibility(GONE);
    }

    TextView rightText = (TextView) this.findViewById(R.id.right_text);
    if (card.getRightText() == null) {
        rightText.setVisibility(GONE);
    }
    else {
        rightText.setText(card.getRightText());
    }

    imageView = (ImageView) this.findViewById(R.id.image);
    imageView.setVisibility(VISIBLE);
    switch (card.getImageDisplayType()) {
        case RESOURCE:
            setResourceImageToView(card);
            break;
        case DEVICE:
            setDeviceImageToView(card);
            break;
        case PERSON:
            setPersonImageToView(card);
            break;
        case PLACE:
            setPlaceImageToView(card);
            break;

        default:
            hideImageView();
            break;
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isChevronShown()) {
        showChevron();
    }

    if (card.isDividerShown()) {
        showDivider();
    }
}
 
Example 20
Source File: ProfilesActivity.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
private void setCardviewColor(CardView newProjectCardView, String color) {
    int backgroundColor = ColorUtilities.toColor(color);
    newProjectCardView.setCardBackgroundColor(backgroundColor);
}