Hi to everyone.
It has been a while since my last post.
I am having what appears to be an unusual problem with "setCornerRadii"
The following code is an extract from the Sudoku program I have been working on, (on and off) for years.
I use "setCornerRadii" to change the shape of cells which can be swapped.
What I have just discovered is that if you try to run "setCornerRadii" on Cell(80), the program will crash but, if you comment out line 118 in the following code, the program runs perfectly.
I have been trying to figure out what the devil is happening for two days, with no success and no idea.
Any help greatly appreciated.
I hope I have posted the code correctly or, should I have included the code as an attached .zip file.
Thank you
Gavin.
PS
I originally used the following code to set the Cell Background.
The result is the same regardless of the way "SmallColor" is dimensioned.
It has been a while since my last post.
I am having what appears to be an unusual problem with "setCornerRadii"
The following code is an extract from the Sudoku program I have been working on, (on and off) for years.
I use "setCornerRadii" to change the shape of cells which can be swapped.
What I have just discovered is that if you try to run "setCornerRadii" on Cell(80), the program will crash but, if you comment out line 118 in the following code, the program runs perfectly.
I have been trying to figure out what the devil is happening for two days, with no success and no idea.
Any help greatly appreciated.
I hope I have posted the code correctly or, should I have included the code as an attached .zip file.
setCornerRadii Example:
#Region Project Attributes
#ApplicationLabel: Set Corner Radii
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type CellData (Security As String, RCC As String, Row As Int, Column As Int, Group As Int, LastEntry As String, _
Klicked As Int, HighLighted As Boolean, Following As String, Swapable As Boolean, SwapWith As String, _
SwapShape As String, ReadyToSwap As Boolean)
Dim CellInfo(81) As CellData
Type CellPanel_Data(FirstCell As Int, Completed As Boolean, HighLighted As Boolean, Correct As Boolean)
Dim CellPanel_Info(9) As CellPanel_Data
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lblCell(81) As Label
Dim GridPanel(9) As Panel
Dim su As StringUtils
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim TextSizeBasedOnWidth As Int
Dim CalculatedTextSize As Int
Dim RowHeight As Int = 10%x
Dim pnlDisplayPanel As Panel
'==================================================================
'Add the Display Panel to Activity
'==================================================================
pnlDisplayPanel.Initialize("DisplayPanel")
pnlDisplayPanel.Color = Colors.Black
Activity.AddView(pnlDisplayPanel, 0, 0, 100%x, 100%y)
'==================================================================
'Add the Nine Grid Panels to the Display Panel
'==================================================================
For Qty = 0 To 8
GridPanel(Qty).Initialize("GridPanel"&Qty)
GridPanel(Qty).Color = Colors.Black 'ColorInfo.Cell_Panel_Background
Next
Dim TitleBarHeight As Int
TitleBarHeight = 20%x
pnlDisplayPanel.AddView(GridPanel(0), 3.5%x, TitleBarHeight+1.0%x+ 00%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(3), 3.5%x, TitleBarHeight+1.0%x+ 31%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(6), 3.5%x, TitleBarHeight+1.0%x+ 62%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(1), 34.5%x, TitleBarHeight+1.0%x+ 00%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(4), 34.5%x, TitleBarHeight+1.0%x+ 31%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(7), 34.5%x, TitleBarHeight+1.0%x+ 62%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(2), 65.5%x, TitleBarHeight+1.0%x+ 00%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(5), 65.5%x, TitleBarHeight+1.0%x+ 31%x, 31%x, 31%x)
pnlDisplayPanel.AddView(GridPanel(8), 65.5%x, TitleBarHeight+1.0%x+ 62%x, 31%x, 31%x)
'==================================================================
'Add a Corner Radius to the Eighty One Cells, if desired
'==================================================================
Dim SmallColor(81) As ColorDrawable
Dim CornerRadius As Int
CornerRadius = 2 'radius goes here
For Qty = 80 To 0 Step -1
SmallColor(Qty).Initialize(Colors.RGB(255, 140, 0), CornerRadius) '(ColorInfo.Cell_Unprotected, CornerRadius)
Next
'==================================================================
'Add the Eighty One Cells, Nine each the Nine Grid Panels
'==================================================================
For Qty = 80 To 0 Step -1
lblCell(Qty).Initialize("Cells")
Dim JO As JavaObject = lblCell(Qty)
JO.RunMethod("setPadding",Array As Object(0,0,0,0))
lblCell(Qty).Background = SmallColor(Qty)
lblCell(Qty).Tag = Qty
lblCell(Qty).Gravity = Bit.Or(Gravity.Center_Vertical, Gravity.Center_Horizontal)
Next
For Amount = 0 To 2
For Kount = 0 To 2
For Count = 0 To 2
For Qty = 0 To 2
GridPanel(Amount*3+Kount).AddView(lblCell(Amount*27+Kount*9+Count*3+Qty), Qty*10%x+1%X, Count*RowHeight+1%x, 9%x, 9%x)
CellPanel_Info(Amount*3+Kount).FirstCell = Amount*27+Kount*9
CellInfo(Amount*27+Kount*9+Count*3+Qty).Column = Kount*3+Qty
CellInfo(Amount*27+Kount*9+Count*3+Qty).Row = Amount*3+Count
CellInfo(Amount*27+Kount*9+Count*3+Qty).Group = Amount*3+Kount
Next
Next
Next
Next
TextSizeBasedOnWidth = Width_Of_Text("9", lblCell(80))
CalculatedTextSize = Height_Of_Text(lblCell(80), "9", TextSizeBasedOnWidth, "S")
lblCell(80).TextSize = CalculatedTextSize
'If you leave the following instruction uncommented, the application will crash.
'If you comment out the following instruction, the application will run but Cell(80) will remain Square.
'I have no idea why. PLEASE HELP.
SER(lblCell(80))
For Qty = 79 To 0 Step -1
lblCell(Qty).TextSize = CalculatedTextSize
SER(lblCell(Qty))
Next
End Sub
Sub SER(V As View)
SCR(V,4.5%x,4.5%x,4.5%x,4.5%x,4.5%x,4.5%x,4.5%x,4.5%x)
End Sub
Sub SCR(v As View, Rx_TopLeft As Float, Ry_TopLeft As Float, Rx_TopRight As Float, Ry_TopRight As Float, Rx_BottomRight As Float, Ry_BottomRight As Float, Rx_BottomLeft As Float, Ry_BottomLeft As Float)
Dim jo As JavaObject = v.Background
If v.Background Is ColorDrawable Or v.Background Is GradientDrawable Then
jo.RunMethod("setCornerRadii", Array As Object(Array As Float(Rx_TopLeft, Ry_TopLeft, Rx_TopRight, Ry_TopRight, Rx_BottomRight, Ry_BottomRight, Rx_BottomLeft, Ry_BottomLeft)))
End If
End Sub
Sub Width_Of_Text(Text_to_Size As String, TestLabel As Label) As Int
Dim TextSizeBasedOnWidth As Int
Dim CVS As Canvas
CVS.Initialize(TestLabel)
For Qty = 60 To 0 Step -1
TextSizeBasedOnWidth = CVS.MeasureStringWidth(Text_to_Size, TestLabel.Typeface, Qty)
If TextSizeBasedOnWidth < TestLabel.Width Then
Exit
End If
Next
Return(Qty)
End Sub
Sub Height_Of_Text( TestLabel As Label, Text_to_Size As String, TextSizeBasedOnWidth As Int, SorM As String) As Int
Dim CalculatedTextHeight As Int
For Qty = 60 To 5 Step -1
TestLabel.TextSize = Qty
CalculatedTextHeight = su.MeasureMultilineTextHeight(TestLabel, Text_to_Size)
If SorM = "S" Then
If CalculatedTextHeight < TestLabel.Height Then
If TextSizeBasedOnWidth < Qty Then
Qty = TextSizeBasedOnWidth
End If
Exit
End If
Else If SorM = "M" Then
If CalculatedTextHeight < TestLabel.Height Then
Exit
End If
End If
Next
Return(Qty)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Thank you
Gavin.
PS
I originally used the following code to set the Cell Background.
B4X:
Dim SmallColor As ColorDrawable
Dim CornerRadius As Int
CornerRadius = 2 'radius goes here
'==================================================================
'Add the Eighty One Cells, Nine each the Nine Grid Panels
'==================================================================
For Qty = 80 To 0 Step -1
lblCell(Qty).Initialize("Cells")
Dim JO As JavaObject = lblCell(Qty)
JO.RunMethod("setPadding",Array As Object(0,0,0,0))
lblCell(Qty).Background = SmallColor
lblCell(Qty).Tag = Qty
lblCell(Qty).Gravity = Bit.Or(Gravity.Center_Vertical, Gravity.Center_Horizontal)
Next
The result is the same regardless of the way "SmallColor" is dimensioned.