Abdulmalik AlOlofi
Member
hi Erel
this is my code with connect to MSSQL directly I hope to help my to avoid hanging app while connect to server with slow internet some time :
cod:
Sub Process_Globals
Private xui As XUI
Dim sql1 As MSSQL
Dim res As MSSQLResultSet
End Sub
Sub Globals
Private CLV1 As CustomListView
Private ImageView1 As B4XView
Private lblTitle As Label
Private lblContent As Label
Private lblAction1 As Label
Private lblAction2 As Label
Public dlg As JSSimpleArcDialog
Private btmPanel As B4XView
Private Button1 As Button
Private Label1 As Label
Private couter As Int
Dim ThreadTest As Thread
ThreadTest.Initialise("TT")
ThreadTest.Start(Null,"TestThread",Null)
'Private ProgressBar1 As ProgressBar
End Sub
Sub TestThread
Try
Dim config As JSArcConfiguration
config.Initialize
config.LoaderStyle = config.STYLE_COMPLETE_ARC
'config.LoaderStyle =config.TypeFace
config.Colors = Array As Int(0xFFE91E63, 0xFF3F51B5, 0xFF9C27B0, 0xFFFFC107, 0xFFF44336, 0xFF4CAF50, 0xFF03A9F4)
config.Text = "تحميل المزيد , الرجاء الانتظار ..."
config.TextSize=12
dlg.Initialize("dlg")
dlg.Show2(config, True)
Catch
Log(LastException)
End Try
End Sub
Dim ThreadTest2 As Thread
ThreadTest2.Initialise("TT")
ThreadTest2.Start(Null,"Threaddb",Null)
Sub Threaddb
Try
sql1.Initialize("connect")
sql1.OpenConnection("jdbc:jtds:sqlserver://208.118.63.49/DB_A0B1FA_rfyemen;user=*******;password=******;")
res = sql1.ExecuteQuery("SELECT top 15 username,pass,'http://rfyemen.org/head_img/'+[i_images] as xx FROM users2 order by num DESC")
Catch
Log(LastException)
End Try
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("card_list")
Dim n As Long = DateTime.Now
TestThread
Threaddb
Try
'ListView1.Clear
Dim rownumber As Int = 0
Do While res.MoveNext
Dim bitmaps As List = Array(res.GetString2("xx"))
Dim content As String =res.GetString2("pass")
Dim t As String =res.GetString2("username")
CLV1.Add(CreateItem(CLV1.AsView.Width, t, bitmaps, content), "")
' Sleep(0)
rownumber=rownumber+1
'Sleep(100)
Loop
'Next
dlg.Dismiss
Log("Loading cards took: " & (DateTime.Now - n) & "ms")
Catch
Log(LastException)
'ToastMessageShow("Error: فشل الاتصال بالانترنت", True)
'ExitApplication
End Try
End Sub
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String) As Panel
Try
Dim p As B4XView = xui.CreatePanel("")
Dim height As Int = 280dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("cardlist_panel")
lblTitle.Text = Title
lblContent.Text = Content
'lblTitle.Gravity =Gravity.RIGHT
SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
'ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
'Picasso1.LoadUrl(res.GetString2("xx")).IntoImageView(ImageView1)
Dim Picasso1 As Picasso
Picasso1.Initialize
Picasso1.LoadUrl(res.GetString2("xx")).IntoImageView(ImageView1)
Return p
Catch
Log(LastException)
ToastMessageShow("Error: فشل الاتصال بالانترنت", True)
'ExitApplication
End Try
End Sub
this is my code with connect to MSSQL directly I hope to help my to avoid hanging app while connect to server with slow internet some time :
cod:
Sub Process_Globals
Private xui As XUI
Dim sql1 As MSSQL
Dim res As MSSQLResultSet
End Sub
Sub Globals
Private CLV1 As CustomListView
Private ImageView1 As B4XView
Private lblTitle As Label
Private lblContent As Label
Private lblAction1 As Label
Private lblAction2 As Label
Public dlg As JSSimpleArcDialog
Private btmPanel As B4XView
Private Button1 As Button
Private Label1 As Label
Private couter As Int
Dim ThreadTest As Thread
ThreadTest.Initialise("TT")
ThreadTest.Start(Null,"TestThread",Null)
'Private ProgressBar1 As ProgressBar
End Sub
Sub TestThread
Try
Dim config As JSArcConfiguration
config.Initialize
config.LoaderStyle = config.STYLE_COMPLETE_ARC
'config.LoaderStyle =config.TypeFace
config.Colors = Array As Int(0xFFE91E63, 0xFF3F51B5, 0xFF9C27B0, 0xFFFFC107, 0xFFF44336, 0xFF4CAF50, 0xFF03A9F4)
config.Text = "تحميل المزيد , الرجاء الانتظار ..."
config.TextSize=12
dlg.Initialize("dlg")
dlg.Show2(config, True)
Catch
Log(LastException)
End Try
End Sub
Dim ThreadTest2 As Thread
ThreadTest2.Initialise("TT")
ThreadTest2.Start(Null,"Threaddb",Null)
Sub Threaddb
Try
sql1.Initialize("connect")
sql1.OpenConnection("jdbc:jtds:sqlserver://208.118.63.49/DB_A0B1FA_rfyemen;user=*******;password=******;")
res = sql1.ExecuteQuery("SELECT top 15 username,pass,'http://rfyemen.org/head_img/'+[i_images] as xx FROM users2 order by num DESC")
Catch
Log(LastException)
End Try
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("card_list")
Dim n As Long = DateTime.Now
TestThread
Threaddb
Try
'ListView1.Clear
Dim rownumber As Int = 0
Do While res.MoveNext
Dim bitmaps As List = Array(res.GetString2("xx"))
Dim content As String =res.GetString2("pass")
Dim t As String =res.GetString2("username")
CLV1.Add(CreateItem(CLV1.AsView.Width, t, bitmaps, content), "")
' Sleep(0)
rownumber=rownumber+1
'Sleep(100)
Loop
'Next
dlg.Dismiss
Log("Loading cards took: " & (DateTime.Now - n) & "ms")
Catch
Log(LastException)
'ToastMessageShow("Error: فشل الاتصال بالانترنت", True)
'ExitApplication
End Try
End Sub
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String) As Panel
Try
Dim p As B4XView = xui.CreatePanel("")
Dim height As Int = 280dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("cardlist_panel")
lblTitle.Text = Title
lblContent.Text = Content
'lblTitle.Gravity =Gravity.RIGHT
SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
'ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
'Picasso1.LoadUrl(res.GetString2("xx")).IntoImageView(ImageView1)
Dim Picasso1 As Picasso
Picasso1.Initialize
Picasso1.LoadUrl(res.GetString2("xx")).IntoImageView(ImageView1)
Return p
Catch
Log(LastException)
ToastMessageShow("Error: فشل الاتصال بالانترنت", True)
'ExitApplication
End Try
End Sub