From d76c4b7b50dbc15975fda4d368e5c10f805048dd Mon Sep 17 00:00:00 2001 From: uykek Date: Sat, 6 Jun 2020 12:51:39 +0200 Subject: [PATCH] Fix bug which causes vector graphics which receive their color from theme attributes to appear invisible when placed on an image button. --- .../ui/view/SudokuSpecialButtonLayout.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuSpecialButtonLayout.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuSpecialButtonLayout.java index 1823c7f..d6c2d79 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuSpecialButtonLayout.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/SudokuSpecialButtonLayout.java @@ -98,6 +98,7 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh public SudokuSpecialButtonLayout(Context context, AttributeSet attrs) { super(context, attrs); setWeightSum(fixedButtonsCount); + this.context = context; } public void setButtonsEnabled(boolean enabled) { @@ -148,6 +149,13 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh fixedButtons[i].setOnClickListener(listener); fixedButtons[i].setBackgroundResource(R.drawable.numpad_highlighted_four); 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++; } @@ -167,12 +175,8 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh break; case NoteToggle: Drawable drawable = ContextCompat.getDrawable(context, fixedButtons[i].getType().getResID()); - 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); + setUpVectorDrawable(drawable); - canvas = new Canvas(bitResult); canvas.rotate(gameController.getNoteStatus() ? 45.0f : 0.0f, bitMap.getWidth()/2, bitMap.getHeight()/2); canvas.drawBitmap(bitMap, 0, 0, null); 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 { LinkedList listeners = new LinkedList<>();