Professional Documents
Culture Documents
B4 ACode Snippets
B4 ACode Snippets
Edit 1.2
Table of content
Documentation
1.1
SQLite
1.2
Regex
2
Code snippets
2.1
Label line spacing
2.2
Launching another application
2.3
Reading mp3 headers
2.4
Writing wave file
2.5
Initialize GPS
2.6
Minimize EditText height
2.7
Changing color of selected text in a Label
2.8
SelectionEnd in an EditText
2.9
Turn off text correction
2.10 SQLite BLOB UPDATE
2.11 Rename a folder
2.12 Webviewscrolling
2.13 Change color of Android ProgressBar
2.14 Change the padding (margins) of an EditText view
2.15 Search on the Internet
2.16 Get the pressure on the screen
2.17 Calculate the Number of Days Between Two Dates
2.18 Display a PDF file
2.19 Select Case with True
2.20 Fill an array with random numbers without repetition
2.21 Change Alpha property of a view
2.22 Getting a views' index
2.23 How Can I Hide the Scrollbar on Scrollview
2.24 How to call the internal calculator
2.25 Get pixel colors
2.26 Get device type
2.27 Generate a Click event
2.28 Pseudo Custom Controls
2.29 Elipsize a Label
2.30 Get the dpi values (dot per inch)
2.31 Android settings indents
2.32 Out of memory problem with orientation change
2.33 Changing character set encoding
2.34 EditText pseudo Tab order
2.35 Get Package name
2.36 Get the current screen orientation in the code
2.37 CreateScaledBitmap
2.38 Scale a View in code like AutoScale
2.39 Get physical screen size
2.40 Check if a device has a built in GPS
2.41 Set Button to Pressed state
2.42 Converting Drawable object to a Bitmap
2.43 Special characters
2.44 Go back from a WebView
2.45 Get Resource drawables
2.46 Change the Disabled Drawable of an EditText view
2.47 Set Left and Right volume level for MediaPlayer
2.48 Get a screenshot
4
4
4
5
5
5
5
6
8
8
8
9
9
9
9
9
10
11
11
11
12
12
12
12
13
13
13
13
14
14
15
16
17
17
18
19
19
19
20
20
20
21
21
21
22
22
22
23
23
23
24
25
Table of content
2.49
Contributors:
Klaus Christl
Forum users
1 Documentation
Documentation
1.1 SQLite
http://www.sqlite.org/lang.html
1.2 Regex
http://regexlib.com/?AspxAutoDetectCookieSupport=1
http://www.regular-expressions.info/
2 Code snippets
Code snippets
2 Code snippets
2 Code snippets
WavHead.NumChannels = 2
WavHead.SampleRate = 44100
WavHead.BitsPerSample = 16
WavHead.ByteRate = WavHead.SampleRate * WavHead.NumChannels * WavHead.Bit
sPerSample / 8
WavHead.BlockAlign = WavHead.NumChannels * WavHead.BitsPerSample / 8
WavHead.Subchunk2Size = NumSamples * WavHead.NumChannels *
WavHead.Bi
tsPerSample / 8
WavHead.ChunkSize = 36 + WavHead.Subchunk2Size
l1 = GenSin(WavData, 0, 32000, 5000, NumSamples, 44100)
Buf2 = bc.ShortsToBytes(WavData)
RAB.WriteBytes(WavHead.ChunkID, 0, 4, 0)
RAB.WriteInt(WavHead.Subchunk1Size, 4)
RAB.WriteBytes(WavHead.Format, 0, 4, 8)
RAB.WriteBytes(WavHead.Subchunk1ID, 0, 4, 12)
RAB.WriteInt(WavHead.Subchunk1Size, 16)
RAB.WriteShort(WavHead.AudioFormat, 20)
RAB.WriteShort(WavHead.NumChannels, 22)
RAB.WriteInt(WavHead.SampleRate, 24)
RAB.WriteInt(WavHead.ByteRate, 28)
RAB.WriteShort(WavHead.BlockAlign, 32)
RAB.WriteShort(WavHead.BitsPerSample, 34)
RAB.WriteBytes(WavHead.Subchunk2ID, 0, 4, 36)
RAB.WriteInt(WavHead.Subchunk2Size, 40)
RAB.WriteBytes(Buf2, 0, 2*l1, 44)
RAF.Initialize2(File.DirDefaultExternal, "data.wav", False, True)
RAF.WriteBytes(buf, 0, 44+2*l1, 0)
...
End Sub
'
'
'
'
'
'
'
2 Code snippets
2 Code snippets
states(0, 0) = sd.State_Pressed
Dim r As Reflector
Dim csl As Object
csl = r.CreateObject2("android.content.res.ColorStateList", _
Array As Object(states, clrs), Array As String("[[I", "[I"))
r.Target = Label1
r.RunMethod4("setTextColor", Array As Object(csl), _
Array As String("android.content.res.ColorStateList"))
End Sub
2.8
SelectionEnd in an EditText
2.12 Webviewscrolling
So, in summary, to scroll a WebView to a particular DOM element, write a JavaScript function to do
the scrolling:
2 Code snippets
10
function scrollToElement(id) {
var elem = document.getElementById(id);
var x = 0;
var y = 0;
while (elem != null) {
x += elem.offsetLeft;
y += elem.offsetTop;
elem = elem.offsetParent;
}
window.scrollTo(x, y);
}
and then from your Android app (Java code), tell your WebView to load a URL:
There are some issues with this approach, such as the scroll will not be nicely animated, but the
general mechanism works.
2 Code snippets
11
Array As Object(r.GetStaticField("android.R$id",
"progress"), clipDrawable), _
Array As String("java.lang.int",
"android.graphics.drawable.Drawable"))
End Sub
2 Code snippets
12
2 Code snippets
13
Dim j, k As Int
j = Rnd(0, i + 1)
k = arr(j)
arr(j) = arr(i)
arr(i) = k
Next
End Sub
2 Code snippets
14
2 Code snippets
15
2 Code snippets
16
Activity:
Sub Process_Globals
End Sub
Sub Globals
Dim m1, m2 As MyView
End Sub
Sub Activity_Create(FirstTime As Boolean)
m1 = c1.CreateMyView("m1", "Button #1", "Label #1")
Activity.AddView(m1.p, 10dip, 10dip, 100dip, 200dip)
m2 = c1.CreateMyView("m2", "Button #2", "Label #2")
Activity.AddView(m2.p, 10dip, 110dip, 100dip, 200dip)
End Sub
Sub m1_Click
c1.ChangeValue(m1, "new value")
End Sub
Sub m2_Click
c1.ChangeValue(m2, "new value2")
End Sub
2 Code snippets
17
Remove Ellipsize:
Sub RemoveEllipsize(TextView As Label)
Dim r As Reflector
r.Target = TextView
r.RunMethod2("setSingleLine", False, "java.lang.boolean")
End Sub
2 Code snippets
18
2 Code snippets
19
=
=
=
=
EditText2
EditText3
EditText4
EditText1
Sub EditText_EnterPressed
Dim currentView, nextView As View
currentView = Sender
nextView = currentView.Tag
nextView.RequestFocus
End Sub
2 Code snippets
20
Tablets
0 = landscape
1 = portrait turn left
2 = landscape upside down
3 = portrait turn right
2.37 CreateScaledBitmap
Requires the Reflection library.
Sub Activity_Create(FirstTime As Boolean)
Dim b As Bitmap
b = LoadBitmap(File.DirAssets, "small_logo.png")
b = CreateScaledBitmap(b, 16, 16, True)
End Sub
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter A
s Boolean) As Bitmap
Dim r As Reflector
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.i
nt", "java.lang.boolean"))
Return b
End Sub
2 Code snippets
21
2 Code snippets
22
2 Code snippets
23
2 Code snippets
24
2 Code snippets
25