Share My Creation WorldClock widget

This is a very simple WorldClock widget.

I wanted to find out what is possible with B4A and widgets and so I started to create this project.

I think the result is quite amazing. At the beginning of this project I haven't thought that this all is possible but thanks to the great Reflection library I got all working as expected.

Be aware that it is only a widget and not a complete app, so just add it to your homescreen and configure it. To change the settings for a widget click on it.

The widget has the following features:
- Resizable layout (works with most custom launcher and stock launcher since Android 3+)
- Different instances of the same widget. All with their own settings.
- Search for any location in the world and set its timezone automatically. This uses the standard Android search feature, geolocation and a web service.
- Widget configuration screen.
- Different layouts for portrait and landscape
- Selectable layout from widget configuration screen
- Adjustable widget transparency (Android 2.1 and up)
- Correct widget size for Android 4+
- Uses different background on different Android Versions
- Detects changes in system settings (Manually setting time and timezone)
- Uses correct Time and Date format according to Device settings
- NEW: Real time preview of the exact widget

The project uses the following libraries:
- AHLocale - For TimeZone selection and formatting dates and times.
- AHViewPager - For selecting different widget layouts.
- Geocoder - For searching for locations
- HTTP - For requesting timezone data
- ICOSImageView - For displaying the widget layout preview images (Needs special scale type)
- IME - For closing the keyboard after searching for location
- Phone - Detecting Android version
- Reflection - For many magic things. :)
- XmlSax - For parsing Webservice result (Timezone)
- HTTPUtils2 - For requesting TimeZone data from webservice
- Statemanager - For saving widget settings and saving Activity state
- Dialogs - For the color dialog (setting text color)

V1.1:
- Show the real widget in the preview
- Added colordialog for selecting text color
 

Attachments

  • Screenshot1.jpg
    Screenshot1.jpg
    59.5 KB · Views: 12,719
  • Screenshot_2013-02-22-14-27-47.jpg
    Screenshot_2013-02-22-14-27-47.jpg
    42.8 KB · Views: 1,052
  • screenshot-1361581047960.jpg
    screenshot-1361581047960.jpg
    27.8 KB · Views: 969
  • WorldClock1_1.zip
    95.9 KB · Views: 1,280
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
My android device can't handle working widgets examples at all, so I would like to try yours one.
At compiling there is an error:
Sub GeoCoder_GeocodeDone(Address1() As Address, Tag As Object) -> Error description: Unknown type: address
Can you help me, what is missing from the zip file posted at first post?
thanks in advance
Steven
 

sifdin17

New Member
My android device can't handle working widgets examples at all, so I would like to try yours one.
At compiling there is an error:
Sub GeoCoder_GeocodeDone(Address1() As Address, Tag As Object) -> Error description: Unknown type: address
Can you help me, what is missing from the zip file posted at first post?
thanks in advance
Steven

Hi.

do you remember how did you fix that issue? i am trying to run the project but i always get the same error !!!
Sub GeoCoder_GeocodeDone(Address1() As Address, Tag As Object) Error description: Unknown type: address

B4X:
Sub GeoCoder_GeocodeDone(Address1() As Address, Tag As Object)
    Dim loca As myLocation

    'Sometimes the geocoder does not return a result (timeouts?). In this case we try to geocode the search string up to 5 times.
    If Address1.Length = 0 And Tag < 5 Then
        Dim geo As Geocoder
        geo.Initialize("GeoCoder")
        geo.GetFromLocationName(gSearchString, 5, (Tag + 1))
        Return
    End If

    'Get some information from the resulting location.
    If Address1.Length > 0 Then
        For i = 0 To Address1.Length - 1
            If Address1(i).HasLatitude And Address1(i).HasLongitude Then
                Dim loca As myLocation
                loca.Initialize
                
                loca.Latitude = Address1(i).Latitude
                loca.Longitude = Address1(i).Longitude
                If Address1(i).Locality <> Null Then
                    loca.Name = Address1(i).Locality
                Else
                    If Address1(i).FeatureName <> Null Then
                        loca.Name = Address1(i).FeatureName
                    Else
                        If Address1(i).AddressLines <> Null And Address1(i).AddressLines.Size > 0 Then
                            loca.Name = Address1(i).AddressLines.Get(0)
                        End If
                    End If
                End If
                            
                If Address1(i).CountryName <> Null Then
                    loca.Name = loca.Name & " (" & Address1(i).CountryName & ")"
                End If
                Exit
            End If
        Next
    End If
    
    'If a location is found then Request timezone data from this location
    If loca.IsInitialized Then
        RequestTimeZone(loca)
    Else
        ProgressDialogHide
        ToastMessageShow("Unable to find location!", True)
    End If
End Sub
 
Top