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,667
  • Screenshot_2013-02-22-14-27-47.jpg
    Screenshot_2013-02-22-14-27-47.jpg
    42.8 KB · Views: 1,038
  • screenshot-1361581047960.jpg
    screenshot-1361581047960.jpg
    27.8 KB · Views: 957
  • WorldClock1_1.zip
    95.9 KB · Views: 1,263
Last edited:

walterf25

Expert
Licensed User
Longtime User
Great job buddy, can the widgets be resized?
if so can you share with us how you accomplished this?

I think this will be of great help to many of us, i have been working on a weather widget for months on and off, but i can't figure out how to make the widget re sizable to fit diferent screen resolutions.

Cheers,
Walter
 

barx

Well-Known Member
Licensed User
Longtime User
Looks nice,

Simple but effective UI.

One feature for a future update - Allow to set color of main holding panel.

Screenshot:-

World Clock.jpg
 

corwin42

Expert
Licensed User
Longtime User
Great job buddy, can the widgets be resized?
if so can you share with us how you accomplished this?

Yes, the widget is scalable and resizable.

I will publish the source next week so you can play with it and ask questions about it. The trick for scalable and resizable widgets is to create the whole layout manually using XML layout files.

One feature for a future update - Allow to set color of main holding panel.

Yes, this can be added, too. Currently the background is the standard Android Widget background for ICS/JB. If you use GB/HC you will get another background. See the first post for an image under Gingerbread.

BTW: I updated the apk in the first post. The old version had a serious bug that the widget didn't work on Android < ICS. A simple xml file was missing and it took me a few hours to find the problem. The exception I got was not really helpful. Thats the drawback if you directly use the Android xml stuff.
 

ferya

Member
Licensed User
Longtime User
I can't find AHDateUtils Library

I tried to compile world clock but I can't find AHDateUtils Library
 

ferya

Member
Licensed User
Longtime User
Thank you for your help NJDude
again I have same problem in line 135
B4X:
Dim du As AHDateUtils
 

ferya

Member
Licensed User
Longtime User
Sorry I changed lib to V1.15
now skip that error but there is new error in WidgetConfig line 313:
B4X:
tz.Initzialize2(gTimeZone)
Unknown member: initzialize2
 

corwin42

Expert
Licensed User
Longtime User
Updated the first post with the source to version 1.1 of the widget.

The magic goes even further. This new version has a real time preview in the widget configuration activity. This is done by loading the widget xml layout into a B4A Panel and with a few helper subs (which use Reflection of course) it is possible to manipulate the views in this layout.

Again, this example is for the advanced B4A programmer and is not easy to understand but it shows what is possible with B4A and homescreen widgets.
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi corwin42,
I have this problem,How do I resolved it,Thank you
 
Last edited:

magoandroid

Member
Licensed User
Longtime User
Hi corwin42,
I have this problem,How do I resolved it,Thank you.
 

Attachments

  • B4a-Compile error.png
    B4a-Compile error.png
    35.4 KB · Views: 339

corwin42

Expert
Licensed User
Longtime User
You don't have the android.support.v4.jar installed. Take a look at the first post of the AHViewPager library thread for more info.

sent from my Galaxy Nexus
 

magoandroid

Member
Licensed User
Longtime User
Hi corwin42,
I did not realize that you have copied android-support-v4.jar the wrong folder.:sign0013:
I pull the ears alone at least 100 times.

Thanks to your reply I rechecked and now everything works.

Best regards.
Maurizio
 

Rusty

Well-Known Member
Licensed User
Longtime User
Is there an example widget xml file?
I keep getting an error:
B4X:
res\xml\advancedwidget_info.xml:3: error: No resource identifier found for attribute 'widgetCategory' in package 'android'
Thanks,
Rusty
 
Top