@Override protected void setUp(View view) { mRatingMessageView.setVisibility(View.GONE); mPlayStoreRatingView.setVisibility(View.GONE); LayerDrawable stars = (LayerDrawable) mRatingBar.getProgressDrawable(); stars.getDrawable(2) .setColorFilter(ContextCompat.getColor(getContext(), R.color.yellow), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(0) .setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(1) .setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow), PorterDuff.Mode.SRC_ATOP); mSubmitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPresenter.onRatingSubmitted(mRatingBar.getRating(), mMessage.getText().toString()); } }); }
@Override public View getItemView(int section, int position, View convertView, ViewGroup parent) { LinearLayout layout; if (convertView == null) { LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); layout = (LinearLayout) inflator.inflate(R.layout.item_survey, null); } else { layout = (LinearLayout) convertView; } ((TextView) layout.findViewById(R.id.questionSurvey)).setText(surveyBeans.get(section).get(position).getQuestion()); RatingBar ratingBar = ((RatingBar) layout.findViewById(R.id.ratingBar)); ratingBar.setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate())); if (ratingBar.getRating() == 2f) { //change color of two stars } else if (ratingBar.getRating() == 3f) { //change color of three stars } LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP); stars.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); ((TextView) layout.findViewById(R.id.commentSurvey)).setText(surveyBeans.get(section).get(position).getComment()); return layout; }
@Override protected void setUp(View view) { mRatingMessageView.setVisibility(View.GONE); mPlayStoreRatingView.setVisibility(View.GONE); LayerDrawable stars = (LayerDrawable) mRatingBar.getProgressDrawable(); stars.getDrawable(2) .setColorFilter(ContextCompat.getColor(getContext(), R.color.yellow), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(0) .setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow), PorterDuff.Mode.SRC_ATOP); stars.getDrawable(1) .setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow), PorterDuff.Mode.SRC_ATOP); mSubmitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPresenter.onRatingSubmitted(mRatingBar.getRating(), mMessage.getText().toString()); } }); }
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); stars.getDrawable(1).setColorFilter(starColor, PorterDuff.Mode.SRC_ATOP); stars.getDrawable(2).setColorFilter(starColor, PorterDuff.Mode.SRC_ATOP);
@NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater layoutInflater = MainContext.INSTANCE.getLayoutInflater(); view = layoutInflater.inflate(R.layout.channel_rating_details, parent, false); } WiFiChannel wiFiChannel = getItem(position); if (wiFiChannel == null) { return view; } view.<TextView>findViewById(R.id.channelNumber) .setText(String.format(Locale.ENGLISH, "%d", wiFiChannel.getChannel())); view.<TextView>findViewById(R.id.accessPointCount) .setText(String.format(Locale.ENGLISH, "%d", channelRating.getCount(wiFiChannel))); Strength strength = Strength.reverse(channelRating.getStrength(wiFiChannel)); RatingBar ratingBar = view.findViewById(R.id.channelRating); int size = Strength.values().length; ratingBar.setMax(size); ratingBar.setNumStars(size); ratingBar.setRating(strength.ordinal() + 1); int color = ContextCompat.getColor(getContext(), strength.colorResource()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { setRatingBarColor(ratingBar.getProgressDrawable(), color); } else { ratingBar.setProgressTintList(ColorStateList.valueOf(color)); } return view; }
private void updatePaletteColorViews(Palette palette) { if (palette.getDarkVibrantSwatch() != null) { mRelativeLayout.setBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); mCircularProgressBar.setBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); colorView.setBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); collapsingToolbarLayout.setBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); collapsingToolbarLayout.setStatusBarScrimColor(palette.getDarkVibrantSwatch().getRgb()); collapsingToolbarLayout.setContentScrimColor(palette.getDarkVibrantSwatch().getRgb()); } else if (palette.getMutedSwatch() != null) { mRelativeLayout.setBackgroundColor(palette.getMutedSwatch().getRgb()); mCircularProgressBar.setBackgroundColor(palette.getMutedSwatch().getRgb()); colorView.setBackgroundColor(palette.getMutedSwatch().getRgb()); collapsingToolbarLayout.setBackgroundColor(palette.getMutedSwatch().getRgb()); collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedSwatch().getRgb()); collapsingToolbarLayout.setContentScrimColor(palette.getMutedSwatch().getRgb()); } LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); if (palette.getLightVibrantSwatch() != null) { mCircularProgressBar.setColor(palette.getLightVibrantSwatch().getRgb()); stars.getDrawable(2).setColorFilter(palette.getLightVibrantSwatch().getRgb(), PorterDuff.Mode.SRC_ATOP); } else if (palette.getLightMutedSwatch() != null) { mCircularProgressBar.setColor(palette.getLightMutedSwatch().getRgb()); stars.getDrawable(2).setColorFilter(palette.getLightMutedSwatch().getRgb(), PorterDuff.Mode.SRC_ATOP); } } }