Android Code Snippet Grabbing the Analog Clock at android.widget.AnalogClock

AnalogClock.png


See the attached project....You will need library Reflection (V2.4) to be enabled.

Change the value of the corner radius of the customview (AC) in the designer to a larger value (up to for eg 100) to get closer to a perfect circular border around the clock.
 

Attachments

  • AnalogClock.zip
    12.4 KB · Views: 753
Last edited:

davidt

Member
Licensed User
Longtime User
Thanks for the code snippet Johan. I have implemented with the Analog clock and it works fine.

I was hoping you may be able to help me with a question re using this method to add other widgets to the home screen. I have tried with several other widgets but am having issues working out what the string for the first parameter on the CreateObject2 method should be. I have used the InstalledProviders property in the RSSmartWidgets object to attempt to retrieve the package/class names for the widgets installed on the device, but am having no luck with displaying the widget as I am not sure how I derive the widget class name from the ComponentInfo that is returned in the InstalledProviders list.

Any help you could provide would be much appreciated.

Dave
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thanks for the code snippet Johan. I have implemented with the Analog clock and it works fine.

I was hoping you may be able to help me with a question re using this method to add other widgets to the home screen. I have tried with several other widgets but am having issues working out what the string for the first parameter on the CreateObject2 method should be. I have used the InstalledProviders property in the RSSmartWidgets object to attempt to retrieve the package/class names for the widgets installed on the device, but am having no luck with displaying the widget as I am not sure how I derive the widget class name from the ComponentInfo that is returned in the InstalledProviders list.

Any help you could provide would be much appreciated.

Dave
What widgets are you interested in making use of? I will have to revisit this project as it has been some time since I have done it.
 

davidt

Member
Licensed User
Longtime User
Thanks for your reply Johan. I ended up using the RSSmartwidgets library to enabled widget functionality I no longer have the need to determine the class names.
I appreciate you reply.
Dave
 

davidt

Member
Licensed User
Longtime User
Hi Johan,

Requirements have changed again :(

The widgets I am looking at using are the Garmin widgets in bold below. I am unsure of how I specify the package name for the CreateObject2 method.

So line 1. below is from your code snippet and works fine. Whereas line 2. fails with the error show below.

1. mac=R.CreateObject2("android.widget.AnalogClock",Array As Object(R.GetContext),Array As String("android.content.Context"))
2. mac=R.CreateObject2("com.garmin.garminwidget.WhereToWidgetProvider",Array As Object(R.GetContext),Array As String("android.content.Context"))

Any help would be appreciated and getting the format of the call to the CreateObject2 method correct.

Regards,
Dave


(ArrayList)
[AppWidgetProviderInfo(provider=ComponentInfo{com.garmin.garminwidget/com.garmin.garminwidget.FleetWhereToViewMapWidget}), AppWidgetProviderInfo(provider=ComponentInfo{com.garmin.garminwidget/com.garmin.garminwidget.WhereToWidgetProvider}), AppWidgetProviderInfo(provider=ComponentInfo{com.garmin.garminwidget/com.garmin.garminwidget.NavigationWidgetProvider}), AppWidgetProviderInfo(provider=ComponentInfo{com.garmin.garminwidget/com.garmin.garminwidget.NavigationStopButtonProvider}),]


Error Message:

Error occurred on line: 18 (GarminWidgetClass)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.garmin.garminwidget.WhereToWidgetProvider
at anywheresoftware.b4a.agraham.reflection.Reflection.CreateObject2(Reflection.java:268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at Dashboard.Extreme.main.afterFirstLayout(main.java:102)
at Dashboard.Extreme.main.access$000(main.java:17)
at Dashboard.Extreme.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.garmin.garminwidget.WhereToWidgetProvider
at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:170)
at anywheresoftware.b4a.agraham.reflection.Reflection.CreateObject2(Reflection.java:261)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.garmin.garminwidget.WhereToWidgetProvider
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:167)
... 21 more
Caused by: java.lang.NoClassDefFoundError: com/garmin/garminwidget/WhereToWidgetProvider
... 25 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.garmin.garminwidget.WhereToWidgetProvider" on path: DexPathList[[zip file "/data/app/Dashboard.Extreme-2.apk"],nativeLibraryDirectories=[/data/app-lib/Dashboard.Extreme-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 25 more
** Activity (main) Resume **
 
Top