Android Question Timer Picker

Nitin Joshi

Active Member
Licensed User
I already tried this. APP throws below error as soon as it opens...

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main$ResumableSub_Activity_Createresume (java line: 464)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at Test.V6.main$ResumableSub_Activity_Create.resume(main.java:464)
at Test.V6.main._activity_create(main.java:440)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at Test.V6.main.afterFirstLayout(main.java:105)
at Test.V6.main.access$000(main.java:17)
at Test.V6.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 15 more
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
I already tried this. APP throws below error as soon as it opens...

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
......

Interesting. The provided sample also crashed the first time I installed it.
Then I modified the stkTarget version to 29 and it also threw an error - but continued to run and log the date/times I selected.
Then I cleaned the project, deleted the app from my device, rebuilt/installed and it works perfectly.

So it seems the Library can be made to work with a little 'playing around'.
B4X:
Logger connected to:  samsung SM-G988B
--------- beginning of main
Not starting debugger since process cannot load the jdwp agent.
setConscryptValidator
setConscryptValidator - put
Returning zygote-cached class loader: /system/framework/android.test.base.jar
No Network Security Config specified, using platform default
No Network Security Config specified, using platform default
makeCurrent EglSurface : 0x0 -> 0x0
Class anywheresoftware.b4a.BA failed lock verification and will run slower.
Common causes for lock verification issues are non-optimized dex code
and incorrect proguard optimizations.
common created.
Starting remote logger. Port: 34116
TcpOptimizer-ON
[INFO] isPopOver=false, config=true
updateCaptionType >> DecorView@7123d28[], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
setCaptionType = 0, this = DecorView@7123d28[]
Input channel constructed: 'b8964f1', fd=69
setView = com.android.internal.policy.DecorView@7123d28 TM=true
Relayout returned: old=(0,0,1440,3200) new=(0,0,1440,3200) req=(1440,3200)0 dur=4 res=0x7 s={true 524520199056} ch=true fn=-1
ReliableSurface(0x790fd2f4a0) created from window(0x7a1fd713a0)
new_window_surface() [1440x3200] return: 0x3000
eglCreateWindowSurface : 0x790fd35b90 from window:0x7a1fd713a0
[DP] dp(1) 1 android.view.ViewRootImpl.reportNextDraw:10658 android.view.ViewRootImpl.performTraversals:3718 android.view.ViewRootImpl.doTraversal:2504
[DP] pd() Asnyc report
makeCurrent EglSurface : 0x0 -> 0x790fd35b90
mapper 4.x is not supported
mapper 3.x is not supported
Arm Module v1.0
[DP] pdf(0) 1 android.view.ViewRootImpl.lambda$performDraw$1$ViewRootImpl:4539 android.view.-$$Lambda$ViewRootImpl$DJd0VUYJgsebcnSohO6h8zc_ONI.run:6 android.os.Handler.handleCallback:938
[DP] rdf()
Compat change id reported: 147798919; UID 10531; state: DISABLED
*** Debugger waiting for connection (0) ***
show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1 isDexDualMode=false
show: isActivityContext = false
Text: Xait in android.widget.ToastPresenter@237872a
Input channel constructed: '158716a', fd=80
setView = android.widget.LinearLayout@f1eebf6 TM=true
MSG_WINDOW_FOCUS_CHANGED 1 1
prepareNavigationBarInfo() DecorView@7123d28[main]
getNavigationBarColor() -16711423
prepareNavigationBarInfo() DecorView@7123d28[main]
getNavigationBarColor() -16711423
Starting input: tba=JHS.SingleDateAndTimePicker ic=null mNaviBarColor -16711423 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
startInputInner - Id : 0
startInputInner - mService.startInputOrWindowGainedFocus
Input channel constructed: 'ClientS', fd=86
Relayout returned: old=(0,99,1440,3032) new=(160,2590,1280,2808) req=(1120,218)0 dur=3 res=0x7 s={true 524520443216} ch=true fn=-1
[DP] dp(1) 0 android.view.ViewRootImpl.reportNextDraw:10658 android.view.ViewRootImpl.performTraversals:3718 android.view.ViewRootImpl.doTraversal:2504
[DP] pd() Asnyc report
ReliableSurface(0x790fd3ed40) created from window(0x7a1fdacd60)
new_window_surface() [1120x218] return: 0x3000
eglCreateWindowSurface : 0x790fd3f6d0 from window:0x7a1fdacd60
makeCurrent EglSurface : 0x790fd35b90 -> 0x790fd3f6d0
[DP] pdf(0) 0 android.view.ViewRootImpl.lambda$performDraw$1$ViewRootImpl:4539 android.view.-$$Lambda$ViewRootImpl$DJd0VUYJgsebcnSohO6h8zc_ONI.run:6 android.os.Handler.handleCallback:938
[DP] rdf()
prepareNavigationBarInfo() DecorView@7123d28[main]
getNavigationBarColor() -16711423
Starting input: tba=JHS.SingleDateAndTimePicker ic=null mNaviBarColor -16711423 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
startInputInner - Id : 0
hide : Surface(name=Surface(name=3be5150 InputMethod)/@0x45a656f - animation-leash)/@0xcb6c0c9
nativeSetFlags Done : Surface(name=Surface(name=3be5150 InputMethod)/@0x45a656f - animation-leash)/@0xcb6c0c9
release : Surface(name=Surface(name=9d60f83 NavigationBar0)/@0xf6d9ab - animation-leash)/@0xd0383ce
nativeRelease nativeObject s[519687845152]
nativeRelease nativeObject e[519687845152]
release : Surface(name=Surface(name=bff19c7 StatusBar)/@0x520961c - animation-leash)/@0xbfc12ef
nativeRelease nativeObject s[519687819952]
nativeRelease nativeObject e[519687819952]
After accept
*** Debugger waiting for connection (1) ***
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
release : Surface(name=JHS.SingleDateAndTimePicker/JHS.SingleDateAndTimePicker.main$_17443)/@0xf891abc
nativeRelease nativeObject s[519687839328]
nativeRelease nativeObject e[519687839328]
release : Surface(name=Surface(name=3be5150 InputMethod)/@0x45a656f - animation-leash)/@0xcb6c0c9
nativeRelease nativeObject s[519687845264]
nativeRelease nativeObject e[519687845264]
release : Surface(name=Surface(name=9d60f83 NavigationBar0)/@0xf6d9ab - animation-leash)/@0xcedda45
nativeRelease nativeObject s[519687847392]
nativeRelease nativeObject e[519687847392]
release : Surface(name=Surface(name=bff19c7 StatusBar)/@0x520961c - animation-leash)/@0x25259a
nativeRelease nativeObject s[519687848176]
nativeRelease nativeObject e[519687848176]
Relayout returned: old=(0,0,1440,3200) new=(0,0,1440,3200) req=(1440,3200)0 dur=7 res=0x1 s={true 524520199056} ch=false fn=3
makeCurrent EglSurface : 0x790fd3f6d0 -> 0x790fd35b90
ReliableSurface(0x790fd3ed40) destroyed
destroyEglSurface : 0x790fd3f6d0
eglDestroySurface() in
delete_surface() [1120x218] return
eglDestroySurface() out
EGLNativeWindowType 0x7a1fdacd60 disconnect failed
dispatchDetachedFromWindow: reset blurmask
dispatchDetachedFromWindow
release : Surface(name=Toast$_17443)/@0x99acdf2
nativeRelease nativeObject s[519687879312]
nativeRelease nativeObject e[519687879312]
Input channel destroyed: '158716a', fd=80
Thread[6,tid=18877,WaitingInMainSignalCatcherLoop,Thread*=0x7a0fd0bdd0,peer=0x13bc0dc8,"Signal Catcher"]: reacting to signal 28
SIGSAVEPRF profile save
ViewPostIme pointer 0
ViewPostIme pointer 1
YEAR = 2020
MONTH = Dec
DAY OF MONTH = 27
DAY OF WEEK = Sunday
HOUR = 9
MINUTE = 15
STRING DATE AND TIME = Sun Dec 27 09:15:00 GMT 2020
ViewPostIme pointer 0
ViewPostIme pointer 1
2020
Dec
27
Sunday
9
15
Sun Dec 27 09:15:00 GMT 2020
ViewPostIme pointer 0
ViewPostIme pointer 1
YEAR = 2020
MONTH = Dec
DAY OF MONTH = 29
DAY OF WEEK = Tuesday
HOUR = 9
MINUTE = 15
STRING DATE AND TIME = Tue Dec 29 09:15:00 GMT 2020
 
Upvote 0

Albert Kallal

Active Member
Licensed User
Can anyone suggest simple and good timer picker?

Yes, I can! - the least trouble - just works?
Use this:


The other concept? I Always store my time "things" as date + time.

This will result in the ability to do time spans, and never worry about crossing the day boundary.

So, the time picker from above looks like this:

12 hour mode:



24 hour mode:



Now, as noted, I do adopt the concept of a date time.

Thus, with this code:

B4X:
Sub Button1_Click
  

    Dim dtTodayWithTime As Long = DateTime.Now
    Dim dtToday As Long = GetTodayT
  
    Dim PopTime As TimeDialog
    PopTime.TimeTicks = dtTodayWithTime

    If PopTime.Show("","Start Time","Ok","Cancel","",Null) = DialogResponse.POSITIVE Then

        Dim pt As Period
        pt.Initialize
        pt.Hours = PopTime.Hour
        pt.Minutes = PopTime.Minute
      
        ' save today date with time part

        Dim MyResultDateTime As Long = DateUtils.AddPeriod(dtToday,pt)

        ' now for display
        ' 12 hour time
        EditText1.Text = TicksToDate(MyResultDateTime,fTime)
      
        ' Date 24 hour time
        EditText2.Text = TicksToDate(MyResultDateTime,fTime24)

        ' Date full text
        EditText3.Text = TicksToDate(MyResultDateTime,fDateFull)

        ' Date full text with time
        EditText4.Text = TicksToDate(MyResultDateTime,fDateFullT)

        ' Just the date
        EditText5.Text = TicksToDate(MyResultDateTime,fDate)

      
    End If
  
End Sub

Then I get this:



So from that one "time thing", I can extract the date or what ever i wish.

The code I have for TicksToTime is based on me define a set of "date formats".
If I am to to do anything with time, then I put these constants into my app - right from the get go:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
  
  
    Public fDate As String = "MM/dd/yyyy"
    Public fTime As String = "hh:mm:a"    ' 12 hour AM/PM
    Public fTime24 As String = "kk:mm"      ' 24 hour
  
    Public fDateTime As String = "yyyy-MM-dd HH:mm:ss"
    Public fDateTimeSYS As String = "yyyy-MM-dd HH:mm:ss.000"
  
    Public fDateFull As String = "EEEE, MMMM dd, yyyy"
  
    Public fDateFullT As String = "EEEE, MMMM dd, yyyy " & fTime

End Sub

I VERY much had considered to store the ticks value. But sqLite, and even data I pull from SQL server etc. (as date time)? Well, they follow that standard format.
Thus, if I going to use that date/time value to interact with other systems - then best to stick to the android time format.

However, while dateutils is your friend?

I have two more routines - they let me convert from "ticks" to any of my above standard time formats.

Thus to same messy code - I have these 3 helper routines (that I used above in the sample code:

B4X:
Sub DateToTicks(sDate As String, sFormat As String) As Long

   ' play nice - don't break anyones global format
   Dim sOLD As String = DateTime.DateFormat
 
   DateTime.DateFormat = sFormat
    Try
        Dim MyTicks As Long = DateTime.DateParse(sDate)
    Catch
        Log(LastException)
        MyTicks = 0
    End Try
 
   DateTime.DateFormat = sOLD
 
   Return MyTicks
 
  
End Sub

Sub TicksToDate(ticks As Long,sFormat As String) As String

    ' play nice - don't break anyones global format
    Dim sOld As String = DateTime.DateFormat
  
    DateTime.DateFormat = sFormat
    Try
        Dim sResult As String = DateTime.Date(ticks)
    Catch
        Log(LastException)
    End Try
  
    DateTime.DateFormat = sOld
  
    Return sResult
  
End Sub


Public Sub GetTodayT As Long
   ' get today WITHOUT time portion
    Dim tDay As Long = DateTime.Now
  
    Return DateUtils.SetDate(DateTime.GetYear(tDay),DateTime.GetMonth(tDay),DateTime.GetDayOfMonth(tDay))
  
End Sub


So, with above routines - you are now ready to start coding, playing and having fun with date and time formats.

As noted, having and adopting Date + time formats WHEN dealing with time is nice, since then if you span midnight - or even MORE time, you do NOT care, and thus I have a screen like this based on above routines:

Note the FULL text date format in the upper right. And note the use of 12 hour formats - but STILL I cross midnight without issue.




So, having spent time on this?
Those built in dialogs - they work well, are quite easy to use, and you don't have to download or add anything more to B4A

Between dateutils, a few nice defined constants, and the DateToTicks, and TicksToDate? You quite much have a good ready to go framework in which to deal with time, dates and that of a nice time picker. The date picker in Dialogs2 is ALSO very nice - looks to be the standard Android picker, and again this helps for user learning curves and any user familiar having used Android.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…