I have this code from RatingBar android - custom draw runtime
It worked before which I used to change the color of a graphic on my rating control:
vthf.rating.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//--
float touchPositionX = event.getX();
float width = vthf.rating.getWidth();
float starsf = (touchPositionX / width);
starsf = starsf * param_final__data.score_max;
int starsint = (int) Math.round(starsf);
byte starsbyte = (byte) starsint;
param_final__data.score_cur = starsbyte;
starsf = starsint;
vthf.rating.setRating(starsf);
//--
int color = Color.BLACK;
switch (starsbyte % 4) {
case 0: color = Color.BLUE; break; // 4 stars
case 3: color = Color.GREEN; break;
case 2: color = Color.YELLOW; break;
case 1: color = Color.RED; break;
}
final LayerDrawable layerDrawable = (LayerDrawable) vthf.rating.getProgressDrawable();
Drawable myWrap = layerDrawable.getDrawable(2);
//--
//
//--
myWrap = DrawableCompat.wrap(myWrap);
//myWrap = myWrap.mutate();
//--
// myWrapMutate.setColorFilter(color, PorterDuff.Mode.SRC_IN);
// DrawableCompat.setTintList(myWrap, ColorStateList.valueOf(color));
//--
DrawableCompat.setTint(myWrap, color);
//--
vthf.rating.invalidate();
}
else
if (event.getAction() == MotionEvent.ACTION_DOWN) {
param_final__view.setPressed(true);
}
else
if (event.getAction() == MotionEvent.ACTION_CANCEL) {
param_final__view.setPressed(false);
}
return true;
}
});
I believe it stopped working after I upgraded from Android Studio 1.5.1 and all support libraries (not sure what version) - I am not 100% sure though since I am no sure I dsicovered the problem immediate or if it had been here longer.
I am tesing on Huawei P6 Android 4.4.2
My gradle is looking like his:
compileSdkVersion 23
buildToolsVersion '23'
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:+'
}
My manifest has this
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17"
/>
This is my best lead on why the code is no longer working - but I am open to all kinds of suggestions if I am missing something obvious that could cause this unrelated to API versions.
---Note---
This code appears to tint the graphic slightly darker:
final LayerDrawable layerDrawable = (LayerDrawable) vthf.rating.getProgressDrawable();
Drawable myWrap = layerDrawable.getDrawable(2);
myWrap = DrawableCompat.wrap(myWrap);
DrawableCompat.setTint(myWrap, color);
This code has no effect:
final LayerDrawable layerDrawable = (LayerDrawable) vthf.rating.getProgressDrawable();
Drawable myWrap = layerDrawable.getDrawable(2);
DrawableCompat.setTint(myWrap, color);
Not sure what to make of the above. Maybe the problem is caused by something else that I do not understand. If the graphic is darkened, one would think it is kinda working... But it is the exact same darkening no matter he color - a least as far as my eye can tell.