Android Question How to make image based on high unix char look disabled

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using various ways to add images to an overflow menu. These overflow menu items always have text and and sometimes an image in front of the text.
The images can be provided by: an image file, FontAwesome or MaterialIcons icons, or by a high unicode icon character. This is the code covering the last
3 options:

B4X:
            If arrMenuButtons(i).iIconChar > 0 Then
                Select Case arrMenuButtons(i).iIconFont
                    Case 0
                        btn.Typeface = Typeface.DEFAULT
                        btn.Text = UnicodeToString(arrMenuButtons(i).iIconChar, "UTF32") & " " & arrMenuButtons(i).strTitle1
                        btn.TextColor = arrMenuButtons(i).iTextColour
                    Case 1
                        Dim oCS As CSBuilder
                        oCS.Initialize.Typeface(Typeface.FONTAWESOME).Color(arrMenuButtons(i).iIconColour)
                        oCS.Append(Chr(arrMenuButtons(i).iIconChar)).PopAll
                        oCS.Typeface(Typeface.DEFAULT).Color(arrMenuButtons(i).iTextColour).Append(" " & arrMenuButtons(i).strTitle1).PopAll
                        btn.text = oCS
                    Case 2
                        Dim oCS As CSBuilder
                        oCS.Initialize.Typeface(Typeface.MATERIALICONS).Color(arrMenuButtons(i).iIconColour)
                        oCS.Append(Chr(arrMenuButtons(i).iIconChar)).PopAll
                        oCS.Typeface(Typeface.DEFAULT).Color(arrMenuButtons(i).iTextColour).Append(" " & arrMenuButtons(i).strTitle1).PopAll
                        btn.text = oCS
                End Select

Now these overflow icons may need to look disabled and that is easy with all, except the ones with images based on the unix icon characters (Case 0 above).
Is it possible to make these unix icon images disabled, so change the various colours to the same tint of gray?
Can't see an easy was to do this.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You can recolor images with BitmapCreatorEffects.
Yes, I am using that with bitmaps based on an image file and that works all fine.
I can't though get a good bitmap (showing an accurate image) from the unix char icon.

Tried with this code:

B4X:
Sub TextToBitmap(strText As String, FontSize As Float, lFontColour As Int, _
                 iWidth As Int, iHeight As Int, _
                 TF As Typeface, strAlignment As String, _
                iVerticalAdjust As Int, iHorizontalAdjust As Int) As Bitmap
 
    Dim bmp As Bitmap
    Dim cvs As Canvas
     
    bmp.InitializeMutable(iWidth * 100dip / 100, iHeight * 100dip / 100)
    cvs.Initialize2(bmp)
    Dim h As Double = cvs.MeasureStringHeight(strText, TF, FontSize)
    cvs.DrawText(strText, bmp.Width / 2 + iHorizontalAdjust, bmp.Height / 2 + h / 2 + iVerticalAdjust, _
                 TF, FontSize, lFontColour, strAlignment)
                 
    Return bmp
 
End Sub

I am using this code to get bitmaps from file based images, so I can change the colour, and that is all working fine.

It does show an image in grey that has some resemblance to the unix char icon, but not good enough.
For now I am experimenting with character 127757, showing it in an imageview.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Yes, I am using that with bitmaps based on an image file and that works all fine.
I can't though get a good bitmap (showing an accurate image) from the unix char icon.

Tried with this code:

B4X:
Sub TextToBitmap(strText As String, FontSize As Float, lFontColour As Int, _
                 iWidth As Int, iHeight As Int, _
                 TF As Typeface, strAlignment As String, _
                iVerticalAdjust As Int, iHorizontalAdjust As Int) As Bitmap
 
    Dim bmp As Bitmap
    Dim cvs As Canvas
    
    bmp.InitializeMutable(iWidth * 100dip / 100, iHeight * 100dip / 100)
    cvs.Initialize2(bmp)
    Dim h As Double = cvs.MeasureStringHeight(strText, TF, FontSize)
    cvs.DrawText(strText, bmp.Width / 2 + iHorizontalAdjust, bmp.Height / 2 + h / 2 + iVerticalAdjust, _
                 TF, FontSize, lFontColour, strAlignment)
                
    Return bmp
 
End Sub

I am using this code to get bitmaps from file based images, so I can change the colour, and that is all working fine.

It does show an image in grey that has some resemblance to the unix char icon, but not good enough.
For now I am experimenting with character 127757, showing it in an imageview.

RBS
I think it is too much trouble (premature optimization one could say) to have the same unix char icon image in grey and just done it simply like this for now:

B4X:
                            If iButtonAction = 1 Then
                                'enabled overflow item
                                v.TextColor = arrMenuButtons(iTag).iTextColour
                                v.Text = UnicodeToString(arrMenuButtons(iTag).iIconChar, "UTF32") & " " & arrMenuButtons(iTag).strTitle1
                            Else
                                'disabled overflow item
                                v.TextColor = Colors.RGB(160, 160, 160)
                                '11044, 1758, 9899, 9938, 10807, 8855, 10683
                                v.Text = UnicodeToString(10683, "UTF32") & " " & arrMenuButtons(iTag).strTitle1
                            End If

RBS
 
Upvote 0
Top