Fix bug which causes vector graphics which receive their color from theme attributes to appear invisible when placed on an image button.

This commit is contained in:
uykek 2020-06-06 12:51:39 +02:00
parent e31add2adf
commit d76c4b7b50

View file

@ -98,6 +98,7 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
public SudokuSpecialButtonLayout(Context context, AttributeSet attrs) { public SudokuSpecialButtonLayout(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setWeightSum(fixedButtonsCount); setWeightSum(fixedButtonsCount);
this.context = context;
} }
public void setButtonsEnabled(boolean enabled) { public void setButtonsEnabled(boolean enabled) {
@ -148,6 +149,13 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
fixedButtons[i].setOnClickListener(listener); fixedButtons[i].setOnClickListener(listener);
fixedButtons[i].setBackgroundResource(R.drawable.numpad_highlighted_four); fixedButtons[i].setBackgroundResource(R.drawable.numpad_highlighted_four);
addView(fixedButtons[i]); addView(fixedButtons[i]);
if(fixedButtons[i].getVisibility() == View.VISIBLE) {
Drawable drawable = ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID());
setUpVectorDrawable(drawable);
drawable.draw(canvas);
fixedButtons[i].setImageBitmap(bitResult);
}
i++; i++;
} }
@ -167,12 +175,8 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
break; break;
case NoteToggle: case NoteToggle:
Drawable drawable = ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID()); Drawable drawable = ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID());
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); setUpVectorDrawable(drawable);
bitMap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
bitResult = Bitmap.createBitmap(bitMap.getWidth(), bitMap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitResult);
canvas.rotate(gameController.getNoteStatus() ? 45.0f : 0.0f, bitMap.getWidth()/2, bitMap.getHeight()/2); canvas.rotate(gameController.getNoteStatus() ? 45.0f : 0.0f, bitMap.getWidth()/2, bitMap.getHeight()/2);
canvas.drawBitmap(bitMap, 0, 0, null); canvas.drawBitmap(bitMap, 0, 0, null);
drawable.draw(canvas); drawable.draw(canvas);
@ -189,6 +193,15 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
} }
} }
private void setUpVectorDrawable(Drawable drawable) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
bitMap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
bitResult = Bitmap.createBitmap(bitMap.getWidth(), bitMap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitResult);
}
public static class HintConfirmationDialog extends DialogFragment { public static class HintConfirmationDialog extends DialogFragment {
LinkedList<IHintDialogFragmentListener> listeners = new LinkedList<>(); LinkedList<IHintDialogFragmentListener> listeners = new LinkedList<>();