B4ACodeSnippets

19

Click here to load reader

Transcript of B4ACodeSnippets

Page 1: B4ACodeSnippets

Code Snippets

Copyright: © 2012 Anywhere Software Edit 1.0

Page 2: B4ACodeSnippets

2 Code snippets 2 Basic4Android Code Snippets

1 Documentation ........................................................................................................................3

1.1 SQLite .............................................................................................................................3 1.2 Regex ..............................................................................................................................3

2 Code snippets ..........................................................................................................................4 2.1 Label line spacing ............................................................................................................4 2.2 Launching another application .........................................................................................4 2.3 Reading mp3 headers.......................................................................................................4 2.4 Writing wave file .............................................................................................................5 2.5 Initialize GPS ..................................................................................................................7 2.6 Minimize EditText height ................................................................................................7 2.7 Changing color of selected text in a Label........................................................................7 2.8 SelectionEnd in an EditText.............................................................................................8 2.9 Turn off text correction....................................................................................................8 2.10 SQLite BLOB UPDATE..................................................................................................8 2.11 Rename a folder...............................................................................................................8 2.12 Webviewscrolling ............................................................................................................8 2.13 Change color of Android ProgressBar..............................................................................9 2.14 Change the padding (margins) of an EditText view........................................................ 10 2.15 Search on the Internet .................................................................................................... 10 2.16 Get the pressure on the screen........................................................................................ 10 2.17 Calculate the Number of Days Between Two Dates ....................................................... 11 2.18 Display a PDF file ......................................................................................................... 11 2.19 Select Case with True .................................................................................................... 11 2.20 Fill an array with random numbers without repetition .................................................... 11 2.21 Change Alpha property of a view................................................................................... 12 2.22 Getting a views' index.................................................................................................... 12 2.23 How Can I Hide the Scrollbar on Scrollview.................................................................. 12 2.24 How to call the internal calculator.................................................................................. 12 2.25 Get pixel colors.............................................................................................................. 13 2.26 Get device type .............................................................................................................. 13 2.27 Generate a Click event ................................................................................................... 14 2.28 Remove the scrollbar from a ScrollView........................................................................ 14 2.29 Pseudo Custom Controls ................................................................................................ 15 2.30 Elipsize a Label ............................................................................................................. 16 2.31 Get the dpi values (dot per inch) .................................................................................... 16 2.32 Android settings indents................................................................................................. 17

3 Classes .................................................................................................................................. 19 3.1 Draggable view class ..................................................................................................... 19

Contributors: Klaus Christl Forum users

Page 3: B4ACodeSnippets

1 Documentation 3 Basic4Android Beginner's Guide

1 Documentation In this chapter some links that might be interesting.

1.1 SQLite http://www.sqlite.org/lang.html

1.2 Regex http://regexlib.com/?AspxAutoDetectCookieSupport=1 http://www.regular-expressions.info/

Page 4: B4ACodeSnippets

2 Code snippets 4 Basic4Android Code Snippets

2 Code snippets Code snippets gathered from the forum.

2.1 Label line spacing Dim Obj1 As Reflector Obj1.Target = lbl Obj1.RunMethod3("setLineSpacing", 1, "java.lang.float", 2, "java.lang.float")

2.2 Launching another application

Dim in As Intent Dim pm As PackageManager in = pm.GetApplicationIntent("com.google.android.youtube") If in.IsInitialized Then StartActivity(in) StartActivity(in)

2.3 Reading mp3 headers http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm#MPEGTAG Sub Activity_Create(FirstTime As Boolean) LogMp3Tags(File.DirRootExternal, "1.mp3") End Sub Sub LogMp3Tags(Dir As String, FileName As String) Dim raf As RandomAccessFile raf.Initialize2(Dir, FileName, True, True) If raf.Size < 128 Then Log("No TAG found.") Return End If Dim buffer(128) As Byte raf.ReadBytes(buffer, 0, 3, raf.Size - 128) If BytesToString(buffer, 0, 3, "UTF8") <> "TAG" Then Log("No TAG found.") Return End If 'Title raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition) Log("Title=" & ConvertBytesToString(buffer, 30)) 'Artist raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition) Log("Artist=" & ConvertBytesToString(buffer, 30)) 'Album raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition) Log("Album=" & ConvertBytesToString(buffer, 30)) 'Year raf.ReadBytes(buffer, 0, 4, raf.CurrentPosition) Log("Album=" & ConvertBytesToString(buffer, 4)) 'Comment

Page 5: B4ACodeSnippets

2 Code snippets 5 Basic4Android Code Snippets

raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition) Log("Comment=" & ConvertBytesToString(buffer, 30)) 'Genre Dim genre As Int genre = raf.ReadUnsignedByte(raf.CurrentPosition) Log("Genre=" & genre) End Sub Sub ConvertBytesToString(Buffer() As Byte, MaxLength As Int) As String For i = 0 To MaxLength - 1 If Buffer(i) = 0 Then Return BytesToString(Buffer, 0, i, "UTF8") Next Return BytesToString(Buffer, 0, MaxLength, "UTF8") End Sub

2.4 Writing wave file Sub Globals ... Type TWaveHeader _ (ChunkID(4) As Byte, _ ChunkSize As Int, _ Format(4) As Byte, _ Subchunk1ID(4) As Byte, _ Subchunk1Size As Int, _ AudioFormat As Short, _ NumChannels As Short, _ SampleRate As Int, _ ByteRate As Int, _ BlockAlign As Short, _ BitsPerSample As Short, _ Subchunk2ID(4) As Byte, _ Subchunk2Size As Int) Dim WavHead As TWaveHeader Dim NumSamples As Int: NumSamples = 1000 Dim WavData(2*NumSamples) As Short End Sub Sub Activity_Create(FirstTime As Boolean) Dim l1 As Long Dim Buf(44+4*NumSamples), Buf2(4*NumSamples) As Byte Dim bc As ByteConverter Dim RAB, RAF As RandomAccessFile ... WavHead.Initialize bc.LittleEndian = True RAB.Initialize3(Buf, True) WavHead.ChunkID = "RIFF".GetBytes("UTF8") WavHead.Format = "WAVE".GetBytes("UTF8") WavHead.Subchunk1ID = "fmt ".GetBytes("UTF8") WavHead.Subchunk2ID = "data".GetBytes("UTF8") WavHead.Subchunk1Size = 16 WavHead.AudioFormat = 1

Page 6: B4ACodeSnippets

2 Code snippets 6 Basic4Android Code Snippets

WavHead.NumChannels = 2 WavHead.SampleRate = 44100 WavHead.BitsPerSample = 16 WavHead.ByteRate = WavHead.SampleRate * WavHead.NumChannels * WavHead.BitsPerSample / 8 WavHead.BlockAlign = WavHead.NumChannels * WavHead.BitsPerSample / 8 WavHead.Subchunk2Size = NumSamples * WavHead.NumChannels * WavHead.BitsPerSample / 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 ' GenSin = (2 * pi * t * freq) / samplerate [return sample count] ' buf - sample buffer ' ch - channel 0-left, 1-right ' v - volume (magnitude multiplier) ' fr - frequency ' ns - number of samples max ' sr - sample rate [clock time = ( 1.0 / (ns/ sr) )] Sub GenSin(buf() As Short, ch As Int, v As Float, fr As Float, ns As Int, sr As Int) As Int Dim i, j As Int Dim g, h, tp, fsr As Float tp = 2 * cPI fsr = sr For i=0 To ns-1 j = 2 * i + ch g = (i * tp * fr) / fsr h = v * Sin(g) buf(j) = h Next Return(i) End Sub

Page 7: B4ACodeSnippets

2 Code snippets 7 Basic4Android Code Snippets

2.5 Initialize GPS

If GPS1.GPSEnabled = False Then StartActivity (GPS1.LocationSettingsIntent)

2.6 Minimize EditText height Based on Reflection library.

Sub Globals Dim txt1 As EditText End Sub Sub Activity_Create(FirstTime As Boolean) txt1.Initialize("txt1") Dim c As Canvas Dim b As Bitmap b.InitializeMutable(1, 10) c.Initialize2(b) txt1.Text = "Hello" Dim size As Float size = c.MeasureStringHeight(txt1.Text, txt1.Typeface, txt1.TextSize) txt1.Gravity = Bit.Or(Gravity.TOP, Gravity.LEFT) 'Set gravity to top left Activity.AddView(txt1, 10dip, 10dip, 100dip, size + 6dip) txt1.Color = Colors.White 'Removes the view edges Dim r As Reflector r.Target = txt1 'Set padding to minimum r.RunMethod4("setPadding", Array As Object(0, 1dip, 0, 0), _ Array As String("java.lang.int", "java.lang.int", "java.lang.int", "java.lang.int")) End Sub

2.7 Changing color of selected text in a Label

Sub Activity_Create(FirstTime As Boolean) Dim l As Label l.Initialize("l") Activity.AddView(l, 0, 0, 100dip, 100dip) l.Text = "Some text" SetColorList(l, Colors.Yellow, Colors.Blue) End Sub Sub l_Click End Sub Sub SetColorList (Label1 As Label, DefaultColor As Int,PressedColor As Int) Dim sd As StateListDrawable Dim clrs(2) As Int Dim states(2,1) As Int clrs(0) = DefaultColor clrs(1) = PressedColor

Page 8: B4ACodeSnippets

2 Code snippets 8 Basic4Android 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 Based on Reflection library.

Sub GetSelectionEnd(txt As EditText) As Int Dim r As Reflector r.Target = txt Return r.RunMethod("getSelectionEnd") End Sub

2.9 Turn off text correction

EditText1.InputType = 52428

2.10 SQLite BLOB UPDATE SQL1.ExecNonQuery2("INSERT INTO table2 VALUES('smiley', ?)", Array As Object(Buffer))

2.11 Rename a folder Sub Activity_Create(FirstTime As Boolean) RenameFolder(File.DirRootExternal, "test1", "test2") End Sub Sub RenameFolder(Parent As String, CurrentFolder As String, NewFolder) Dim p As Phone Dim args(2) As String args(0) = File.Combine(Parent, CurrentFolder) args(1) = File.Combine(Parent, NewFolder) p.Shell("mv", args, Null, Null) End Sub

2.12 Webviewscrolling

So, in summary, to scroll a WebView to a particular DOM element, write a JavaScript function to do the scrolling:

Page 9: B4ACodeSnippets

2 Code snippets 9 Basic4Android Code Snippets

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:

webView.loadUrl("javascript:scrollToElement('" + elemId + "')");

There are some issues with this approach, such as the scroll will not be nicely animated, but the general mechanism works.

2.13 Change color of Android ProgressBar Based on Reflection library. Sub Globals Dim pb As ProgressBar End Sub Sub Activity_Create(FirstTime As Boolean) pb.Initialize("pb") Dim gd As GradientDrawable gd.Initialize("TOP_BOTTOM", Array As Int(Colors.Blue, Colors.Red)) gd.CornerRadius = 3dip SetProgressDrawable(pb, gd) pb.Progress = 50 Activity.AddView(pb, 10dip, 10dip, 300dip, 50dip) End Sub Sub SetProgressDrawable(p As ProgressBar, drawable As Object) Dim r As Reflector Dim clipDrawable As Object clipDrawable = r.CreateObject2("android.graphics.drawable.ClipDrawable", _ Array As Object(drawable, Gravity.LEFT, 1), _ Array As String("android.graphics.drawable.Drawable", "java.lang.int", "java.lang.int")) r.Target = p r.Target = r.RunMethod("getProgressDrawable") 'Gets the layerDrawable r.RunMethod4("setDrawableByLayerId", _

Page 10: B4ACodeSnippets

2 Code snippets 10 Basic4Android Code Snippets

Array As Object(r.GetStaticField("android.R$id", "progress"), clipDrawable), _ Array As String("java.lang.int", "android.graphics.drawable.Drawable")) End Sub

2.14 Change the padding (margins) of an EditText view Dim refl As Reflector refl.Target=EditFeld refl.RunMethod4("setPadding", Array As Object(Left, Top, Right, Bottom), _ Array As String("java.lang.int", "java.lang.int", _ "java.lang.int","java.lang.int"))

2.15 Search on the Internet Dim SearchWord As String SearchWord = "apples" Dim i As Intent i.Initialize(i.ACTION_VIEW,"http://www.google.com/#q=" & SearchWord)

2.16 Get the pressure on the screen Sub Activity_Create(FirstTime As Boolean) Dim r As Reflector Dim btn As Button btn.Initialize("") Activity.AddView(btn, 10dip, 10dip, 300dip, 300dip) r.Target = btn r.SetOnTouchListener("btn_touch") End Sub Sub btn_touch (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean Dim r As Reflector r.Target = motionevent Dim pressure As Float pressure = r.RunMethod("getPressure") Log(pressure) Return True End Sub

Page 11: B4ACodeSnippets

2 Code snippets 11 Basic4Android Code Snippets

2.17 Calculate the Number of Days Between Two Dates Sub Activity_Create(FirstTime As Boolean) DateTime.SetTimeZone(0) Dim Date1, Date2 As Long DateTime.DateFormat = "M/d/yyyy h:mm:ss a Z" Date1 = DateTime.DateParse("12/29/2011 11:04:17 AM -5") Date2 = DateTime.DateParse("12/27/2011 11:04:17 AM -5") Log(DaysBetweenDates(Date1, Date2)) End Sub Sub DaysBetweenDates(Date1 As Long, Date2 As Long) Return Floor((Date2 - Date1) / DateTime.TicksPerDay) End Sub

2.18 Display a PDF file Sub Btn_Tarif_Click Dim nom_file As String nom_file = "file:///sdcard/_lelong/fiches_tarif/" & nomdoc 'Msgbox(nom_file,"nom fichier") Dim zz As Intent 'Requires a reference to the Phone library zz.Initialize(zz.ACTION_VIEW, nom_file) zz.SetType("application/pdf") 'zz.WrapAsIntentChooser("Choose PDF Viewer") StartActivity(zz) End Sub

2.19 Select Case with True i = 10 Select True Case (i < 9) Log("False") Case (i = 10) Log("True") End Select

2.20 Fill an array with random numbers without repetition Sub Activity_Create (FirstTime As Boolean) Dim numbers(10) As Int 'put numbers 1 - 10 in the array For i = 0 To 9 numbers(i) = i + 1 Next ShuffleArray(numbers) For i = 0 To 9 Log(numbers(i)) 'print the numbers to the log Next End Sub Sub ShuffleArray(arr() As Int) For i = arr.Length - 1 To 0 Step -1

Page 12: B4ACodeSnippets

2 Code snippets 12 Basic4Android Code Snippets

Dim j, k As Int j = Rnd(0, i + 1) k = arr(j) arr(j) = arr(i) arr(i) = k Next End Sub

2.21 Change Alpha property of a view Sub SetAlpha(Control As View, Alpha As Int) Dim r as Reflector r.Target = Control.Background r.RunMethod2("setAlpha", Alpha, "java.lang.int") End Sub

2.22 Getting a views' index Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("1") Log(PanelIndexOf(Panel1, EditText2)) End Sub Sub PanelIndexOf(p As Panel, v As View) As Int For i = 0 To p.NumberOfViews - 1 If p.GetView(i) = v Then Return i Next Return -1 End Sub

2.23 How Can I Hide the Scrollbar on Scrollview Dim r As Reflector r.Target = ScrollView1 r.RunMethod2("setVerticalScrollBarEnabled", False, "java.lang.boolean")

2.24 How to call the internal calculator Sub Calculator Dim i As Intent i.Initialize("", "") i.SetComponent("com.android.calculator2/.Calculator") Try StartActivity(i) Catch ToastMessageShow("Calculator app not found.", True) End Try End Sub

Page 13: B4ACodeSnippets

2 Code snippets 13 Basic4Android Code Snippets

2.25 Get pixel colors Sub Activity_Create(FirstTime As Boolean) Dim argb() As Int argb = GetARGB(Colors.Transparent) Log("A = " & argb(0)) Log("R = " & argb(1)) Log("G = " & argb(2)) Log("B = " & argb(3)) End Sub Sub GetARGB(Color As Int) As Int() Dim res(4) As Int res(0) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24) res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16) res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8) res(3) = Bit.And(Color, 0xff) Return res End Sub

2.26 Get device type Sub Activity_Create(FirstTime As Boolean) If GetDevicePhysicalSize > 6 Then '7'' or 10'' tablet Else 'phone End If End Sub Sub GetDevicePhysicalSize As Float Dim lv As LayoutValues lv = GetDeviceLayoutValues Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2)) End Sub

Page 14: B4ACodeSnippets

2 Code snippets 14 Basic4Android Code Snippets

2.27 Generate a Click event Sub Globals Dim sp As Spinner End Sub Sub Activity_Create(FirstTime As Boolean) sp.Initialize("sp") sp.AddAll(Array As String("a", "b", "c", "d")) Activity.AddView(sp, 10dip, 10dip, 200dip, 50dip) End Sub Sub Activity_Click OpenSpinner(sp) End Sub Sub OpenSpinner(s As Spinner) Dim r As Reflector r.Target = s r.RunMethod("performClick") End Sub

2.28 Remove the scrollbar from a ScrollView The code needs the Reflection library. Dim r As Reflector r.Target = ScrollView1 r.RunMethod2("setVerticalScrollBarEnabled", False, "java.lang.boolean")

Page 15: B4ACodeSnippets

2 Code snippets 15 Basic4Android Code Snippets

2.29 Pseudo Custom Controls Here is a very simplistic implementation: Code module named C1 Sub Process_Globals Type MyView (p As Panel, b1 As Button, l1 As Label) End Sub Sub CreateMyView(ButtonEvent As String, ButtonText As String, LabelText As String) As MyView Dim m As MyView m.Initialize m.p.Initialize("") m.b1.Initialize(ButtonEvent) m.b1.Text = ButtonText m.l1.Initialize("") m.l1.Text = LabelText m.b1.Tag = m 'store the structure in the button's Tags property. m.p.AddView(m.b1, 10dip, 10dip, 100dip, 40dip) m.p.AddView(m.l1, 10dip, 50dip, 100dip, 40dip) Return m End Sub Sub ChangeValue(m As MyView, value As String) m.l1.Text = value End Sub

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

Page 16: B4ACodeSnippets

2 Code snippets 16 Basic4Android Code Snippets

2.30 Elipsize a Label Needs the reflection library. Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout(1) Label1.Text = "this is a very long text." SetEllipsize(Label1, "END") End Sub Sub SetEllipsize(TextView As Label, Mode As String) Dim r As Reflector r.Target = TextView r.RunMethod2("setLines", 1, "java.lang.int") r.RunMethod2("setHorizontallyScrolling", True, "java.lang.boolean") r.RunMethod2("setEllipsize", Mode, "android.text.TextUtils$TruncateAt") End Sub

2.31 Get the dpi values (dot per inch) Needs the reflection library. Dim Xdpi,Ydpi As Float Dim r As Reflector r.Target = r.GetContext r.Target = r.RunMethod("getResources") r.Target = r.RunMethod("getDisplayMetrics") Xdpi = r.GetField("xdpi") Ydpi = r.GetField("ydpi")

Page 17: B4ACodeSnippets

2 Code snippets 17 Basic4Android Code snippets

2.32 Android settings indents Code : Dim DoIntent As Intent DoIntent.Initialize("android.settings.LOCATION_SOURCE_SETTINGS", "") StartActivity(DoIntent) Action Details(Activity action) ACCESSIBILITY_SETTINGS = Show settings for accessibility modules. ADD_ACCOUNT = Show add account screen for creating a new account. AIRPLANE_MODE_SETTINGS = Show settings to allow entering/exiting airplane mode. APN_SETTINGS = Show settings to allow configuration of APNs. APPLICATION_DETAILS_SETTINGS = Show screen of details about a particular application. APPLICATION_DEVELOPMENT_SETTINGS = Show settings to allow configuration of application development-related settings. APPLICATION_SETTINGS = Show settings to allow configuration of application-related settings. BLUETOOTH_SETTINGS = Show settings to allow configuration of Bluetooth. DATA_ROAMING_SETTINGS = Show settings for selection of 2G/3G. DATE_SETTINGS = Show settings to allow configuration of date and time. DEVICE_INFO_SETTINGS = Show general device information settings (serial number, software version, phone number, etc.). DISPLAY_SETTINGS = Show settings to allow configuration of display. INPUT_METHOD_SETTINGS = Show settings to configure input methods, in particular allowing the user to enable input methods. INPUT_METHOD_SUBTYPE_SETTINGS = Show settings to enable/disable input method subtypes. INTERNAL_STORAGE_SETTINGS = Show settings for internal storage. LOCALE_SETTINGS = Show settings to allow configuration of locale. LOCATION_SOURCE_SETTINGS = Show settings to allow configuration of current location sources. MANAGE_ALL_APPLICATIONS_SETTINGS = Show settings to manage all applications. MANAGE_APPLICATIONS_SETTINGS = Show settings to manage installed applications. MEMORY_CARD_SETTINGS = Show settings for memory card storage. NETWORK_OPERATOR_SETTINGS = Show settings for selecting the network operator. NFCSHARING_SETTINGS = Show NFC Sharing settings. NFC_SETTINGS = Show NFC settings. PRIVACY_SETTINGS = Show settings to allow configuration of privacy options. QUICK_LAUNCH_SETTINGS = Show settings to allow configuration of quick launch shortcuts. SEARCH_SETTINGS = Show settings for global search. SECURITY_SETTINGS = Show settings to allow configuration of security and location privacy. SETTINGS = Show system settings. SOUND_SETTINGS = Show settings to allow configuration of sound and volume. SYNC_SETTINGS = Show settings to allow configuration of sync settings. USER_DICTIONARY_SETTINGS = Show settings to manage the user input dictionary. WIFI_IP_SETTINGS = Show settings to allow configuration of a static IP address for Wi-Fi. WIFI_SETTINGS = Show settings to allow configuration of Wi-Fi. WIRELESS_SETTINGS = Show settings to allow configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks. EXTRA_AUTHORITIES = Limit available options in launched activity based on the given authority.

Page 18: B4ACodeSnippets

2 Code snippets 18 Basic4Android Code snippets

2.33 Out of memory proble with orientation change In many cases the error happens when you change the orientation several times. These kinds of memory problems can be resolved by loading the images only once. Sub Process_Globals Dim Image1, Image2 As Bitmap Dim ImageView1 As ImageView End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then Image1 = LoadBitmap(...) Image2 = LoadBitmap(...) End If ImageView1.Bitmap = ' ' End Sub

Page 19: B4ACodeSnippets

3 Classes 19 Basic4Android Code snippets

3 Classes

3.1 Draggable view class Main module: 'Main activity module Sub process_globals End Sub Sub Globals Dim Button1 As Button Dim Button2 As Button Dim EditText1 As EditText End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("1") Dim dv1, dv2, dv3 As DraggableView dv1.Initialize(Activity, Button1) dv2.Initialize(Activity, Button2) dv3.Initialize(Activity, EditText1) End Sub