Google App Inventor


Results 1 to 22 of 22

Threaded View

  1. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Google App Inventor

    I have not used BT yet. Used the GPS, compass/accelerometer, write/read to storage... Currently I am working on a database app for an archaeologist that will record position and user entered attributes, with the ability to sync the data once the device is back into cell/wifi range. The learning curve for me was less than App Inventor. I never really made anything useful with App Inventor... But that is me.

    Here is the code for a test app when I started playing with the GPS and the other orientation things.
    The apk is attached if you want to see what it does.
    Code:
    'Activity module
    Sub Process_Globals
        'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim GPS1 As GPS
        Dim Orientation As PhoneOrientation
        'Compass Stuff
        Dim Angle As Float                
        Dim Timer1 As Timer
    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 Button1 As Button
        Dim Button2 As Button
        Dim Button3 As Button
        Dim Button4 As Button
        Dim ScrollView1 As ScrollView
        Dim lblAcu As Label
        Dim lblAlt As Label
        Dim lblLat As Label
        Dim lblLon As Label
        Dim lblSatellites As Label
        Dim lblSpeed As Label
        Dim pnlTest As Panel
        Dim Alt    As    Double
        Dim Rate As Double
        Dim Acu As Double
        Dim Latx As Double
        Dim Lonx As Double
        Dim now As Long
        Dim lblBear As Label
        Dim lblCompass As Label
        'Compass Stuff
        Dim csvCompass, csvNeedle As Canvas
        Dim bmpCompass, bmpNeedle As Bitmap
        Dim imvCompass, imvNeedle As ImageView
        Dim RectCompass, SRectNeedle, DRectNeedle As Rect
        
        
    End Sub
    
    
    Sub Activity_Create(FirstTime As Boolean)
        Activity.LoadLayout("Main")
        ScrollView1.Panel.LoadLayout("scrollviewlayout")
        ScrollView1.Panel.Height = pnlTest.Height
        EditMode
        If FirstTime Then
            GPS1.Initialize("GPS")
        End If
        If File.ExternalWritable = True Then 
            Msgbox("Can write to SD storage card!", "") 
            Return 
        End If
        WriteTextWriter
    End Sub
    
    
    Sub Activity_Resume
        If GPS1.GPSEnabled = False Then
            ToastMessageShow("Please enable the GPS device.", True)
            StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
        Else
            GPS1.Start(0, 0) 'Listen to GPS with no filters.
        End If
        Orientation.StartListening("Orientation")
    End Sub
    
    
    Sub Activity_Pause (UserClosed As Boolean)
        GPS1.Stop
        Orientation.StopListening
    End Sub
    Sub GPS_LocationChanged (Location1 As Location)
        lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
        lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
        Latx = Location1.Latitude
        Lonx = Location1.Longitude
        ' 1 meter per second = 2.23693629 miles per hour
        Rate = Round2(Location1.Speed * 2.23693629,3)
        lblSpeed.Text = "Speed (MPH)= " & Rate
        ' 1 meter = 3.2808399 feet
        Alt = Round2(Location1.Altitude * 3.2808399,3)
        lblAlt.Text = "Altitude (Feet)= " & Alt
        Acu = Round2(Location1.Accuracy * 3.2808399,3)
        lblAcu.Text = "Accuracy (Feet)= " & Acu
        lblBear.Text = "GPS Bearing = " & Location1.Bearing
    End Sub
    
    
    Sub GPS_UserEnabled (Enabled As Boolean)
        ToastMessageShow("GPS device enabled = " & Enabled, True)
    End Sub
    
    
    Sub GPS_GpsStatus (Satellites As List)
        lblSatellites.Text = "Satellites:" & CRLF & _
        "#  SNR Used  Azi  Elev" & CRLF
        For i = 0 To Satellites.Size - 1
            Dim Satellite As GPSSatellite
            Satellite = Satellites.Get(i)
            lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
                "  " & Satellite.Snr & "  " & Satellite.UsedInFix & "  " & Satellite.Azimuth _ 
                & "  " & Satellite.Elevation
        Next
    End Sub
    Sub Button1_Click
          WriteTextWriter
          Msgbox("The date is: " & DateTime.Date(now) & CRLF & _
        "The time is: " & DateTime.Time(now), "") 
    End Sub
    Sub Button2_Click
        ReadStringExample
    End Sub
    
    
    Sub ReadStringExample 
        Msgbox(File.ReadString(File.DirRootExternal, "MAC_GPS.txt"), "") 
    End Sub 
    Sub WriteTextWriter() 
        
        now = DateTime.Now
        Dim TextWriter1 As TextWriter 
        TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal,"MAC_GPS.txt", True)) 
      '  For i = 1 To 10 
      '      TextWriter1.WriteLine("Line" & i) 
      '  Next 
          TextWriter1.WriteLine("Date = " & DateTime.Date(now))
        TextWriter1.WriteLine("Time = " & DateTime.Time(now))
        TextWriter1.WriteLine("Lat = " & Latx)
        TextWriter1.WriteLine("Lon = " & Lonx)
        TextWriter1.WriteLine("Alt = " & Alt)
        TextWriter1.WriteLine(" ")
        TextWriter1.Close 
    End Sub 
    Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
        lblCompass.Text = "Compass = " & Azimuth
        Angle = Azimuth
        Timer1_Tick
    End Sub
    Sub Timer1_Tick
        csvNeedle.DrawRectRotated(DRectNeedle,Colors.Transparent,True,1,0)
        csvNeedle.DrawBitmapRotated(bmpNeedle,SRectNeedle,DRectNeedle,0)
        csvCompass.DrawBitmapRotated(bmpCompass,RectCompass,RectCompass,-Angle)
        imvCompass.Invalidate2(RectCompass)
    End Sub
    Sub EditMode()
        'Compass Stuff
        Dim x, y As Float
    
    
        bmpCompass.Initialize(File.DirAssets,"compass.png")
        bmpNeedle.Initialize(File.DirAssets,"needle.png")
        
        imvCompass.Initialize("")
        imvCompass.Bitmap = bmpCompass
        imvNeedle.Initialize("")
        imvNeedle.Color=Colors.Transparent
        
        x = 30 ' (100%x - bmpCompass.Width)/2
        y = 410 '(100%y - bmpCompass.Height) / 2
        ScrollView1.Panel.AddView(imvCompass, x, y, bmpCompass.Width, bmpCompass.Height)
        ScrollView1.Panel.AddView(imvNeedle, x, y, bmpCompass.Width, bmpCompass.Height)
        csvCompass.Initialize(imvCompass)
        RectCompass.Initialize(0, 0, bmpCompass.Width, bmpCompass.Height)
    
    
        csvNeedle.Initialize(imvNeedle)
        x = (bmpCompass.Width - bmpNeedle.Width)/2
        y = (bmpCompass.Height - bmpNeedle.Height)/2
        SRectNeedle.Initialize(0, 0, bmpNeedle.Width, bmpNeedle.Height)
        DRectNeedle.Initialize(x, y, x + bmpNeedle.Width, y + bmpNeedle.Height)
        
        Timer1.Initialize("Timer1",200)
        Timer1_Tick
        
    End Sub
    Attached Files Attached Files
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts