Reflector-Function:
Sub HasFeature(feature As String) As Boolean
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getPackageManager")
Return r.RunMethod2("hasSystemFeature", feature, "java.lang.String")
End Sub
Sub GetDeviceId As String
Dim R As Reflector
Dim Api As Int
Api = R.GetStaticField("android.os.Build$VERSION", "SDK_INT")
If Api < 9 Then
'Old device
If File.Exists(File.DirInternal, "__id") Then
'Log(File.ReadString(File.DirInternal, "__id"))
Return File.ReadString(File.DirInternal, "__id")
Else
Dim id As Int
id = Rnd(0x10000000, 0x7FFFFFFF)
File.WriteString(File.DirInternal, "__id", id)
Return id
End If
Else
'New device
Return R.GetStaticField("android.os.Build", "SERIAL")
End If
End Sub
Sub ExactSize As Double
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
Dim xdpi As Double = r.GetField("xdpi")
Dim ydpi As Double = r.GetField("ydpi")
'Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Dim size As Double = Sqrt(Power(lv.Width / xdpi, 2) + Power(lv.Height / ydpi, 2))
'Log("ExactSize=" & size)
Return size
End Sub
Sub SetNinePatchDrawable(Control As View, ImageName As String)
Dim r As Reflector
Dim package As String
Dim id As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
id = r.GetStaticField(package & ".R$drawable", ImageName)
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub
Sub SetNinePatchButton(Btn As Button, DefaultImage As String, PressedImage As String)
Dim r As Reflector
Dim package As String
Dim idDefault, idPressed As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
idDefault = r.GetStaticField(package & ".R$drawable", DefaultImage)
idPressed = r.GetStaticField(package & ".R$drawable", PressedImage)
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
Dim sd As StateListDrawable
sd.Initialize
sd.AddState(sd.State_Pressed, r.RunMethod2("getDrawable", idPressed, "java.lang.int"))
sd.AddCatchAllState( r.RunMethod2("getDrawable", idDefault, "java.lang.int"))
Btn.Background = sd
End Sub
Sub SetAirplaneMode(On As Boolean)
Dim p As Phone
If On = GetAirplaneMode Then Return 'already in the correct state
Dim R As Reflector
Dim contentResolver As Object
R.Target = R.GetContext
contentResolver = R.RunMethod("getContentResolver")
Dim state As Int
If On Then state = 1 Else state = 0
R.RunStaticMethod("android.provider.Settings$System", "putInt", _
Array As Object(contentResolver, "airplane_mode_on", state), _
Array As String("android.content.ContentResolver", "java.lang.String", "java.lang.int"))
Dim i As Intent
i.Initialize("android.intent.action.AIRPLANE_MODE", "")
i.PutExtra("state", "" & On)
p.SendBroadcastIntent(i)
End Sub
Private Sub GetDefaultLanguage As String
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.Locale", "getDefault", Null, Null)
Return r.RunMethod("getLanguage")
End Sub
###########################################################################
JavaObject-Function:
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
Dim jo = TextView As JavaObject
jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub
Private Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Private Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub
Sub Rotate(view As View, Degree As Float, Duration As Long)
Dim jo As JavaObject = view
jo.RunMethodJO("animate", Null).RunMethodJO("rotationBy", Array(Degree)).RunMethodJO("setDuration", Array(Duration)).RunMethodJO("start", Null)
End Sub