Page 1 of 1

Android: Test resolution screen

Posted: Mon Sep 18, 2017 6:31 pm
by falsam
If you have a tablet or a smartphone with Android, you can create an apk with this code and tell me if the result is identical to this image.

Image

Each corner of the screen must have a green square.

This code does not work with a computer browser. Only Android.

Thanks.

Greetings

Code: Select all

; Date & Time Version 1
;
; SpiderBasic 2.2 JDK 1.1.8.0 144 (x86)
; Android Only

EnableExplicit

Enumeration 
  #FontH1
  #FontH2
  
  #mf
  #mfDate
  #mfTime
  
  #TL ;Square Top Left
  #TR ;Square Top Right
  #BL ;Square Bottom Left
  #BR ;Square Bottom Right
  
  #Timer
EndEnumeration

Declare Start()
Declare onTimer()
Declare onChangeOrientation()

Start()

Procedure Start()
  Protected BackColor = RGB(105, 105, 105)
  Protected FrontColor = RGB(152, 251, 152)
  Protected Image, Gadget
  
  CloseDebugOutput()
  
  ;No Zoom
  !$('head').append('<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0">');
  
  LoadFont(#FontH1, "", 70)
  LoadFont(#FontH2, "", 50)
  
  OpenWindow(#mf, 0, 0, 0, 0, "Date & Time", #PB_Window_Background)
  SetWindowColor(#mf, BackColor)
  
  TextGadget(#mfDate, 0, 0, 400, 100, "", #PB_Text_Center)   
  SetGadgetFont(#mfDate, FontID(#FontH1))
  SetGadgetColor(#mfDate, #PB_Gadget_FrontColor, FrontColor)
  
  TextGadget(#mfTime, 0, 0, 400, 100, "00:00:00", #PB_Text_Center)   
  SetGadgetFont(#mfTime, FontID(#FontH2))
  SetGadgetColor(#mfTime, #PB_Gadget_FrontColor, FrontColor)
  
  ;Squares
  Image = CreateImage(#PB_Any, 40, 40, 0, FrontColor)
  StartDrawing(ImageOutput(Image))
  Box(0, 0, 40, 40, RGB(0, 0, 0))
  Box(5, 5, 30, 30, FrontColor)
  StopDrawing()
  
  For Gadget = #TL To #BR
    ImageGadget(Gadget, 0, 0, 40, 40, ImageID(Image))
  Next
    
  ;Init
  AddWindowTimer(#mf, #Timer, 1000)
  onTimer()
  onChangeOrientation()
  
  ;Triggers
  BindEvent(#PB_Event_Timer, @onTimer(), #mf, #Timer)
  BindEvent(#PB_Event_SizeWindow, @onChangeOrientation())  
EndProcedure

Procedure onTimer()
  SetGadgetText(#mfDate, FormatDate("%yyyy-%mm-%dd", Date()))
  SetGadgetText(#mfTime, FormatDate("%hh:%ii:%ss", Date())) 
EndProcedure

Procedure onChangeOrientation()
  Protected width, height
  
  !v_width = screen.width * window.devicePixelRatio;
  !v_height = screen.height * window.devicePixelRatio;
    
  !document.body.style.zoom = 1 / window.devicePixelRatio * 100 + "%"
  
  ResizeGadget(#mfDate, (width - GadgetWidth(#mfDate))/2, (height - GadgetHeight(#mfDate))/2, #PB_Ignore, #PB_Ignore)
  ResizeGadget(#mfTime, (width - GadgetWidth(#mfTime))/2, (height - GadgetHeight(#mfTime))/2 + 100, #PB_Ignore, #PB_Ignore)
  
  ResizeGadget(#TL, 0, 0, #PB_Ignore, #PB_Ignore)
  ResizeGadget(#TR, Width - 40, 0, #PB_Ignore, #PB_Ignore)
  ResizeGadget(#BL, 0, height - 40, #PB_Ignore, #PB_Ignore)
  ResizeGadget(#BR, Width - 40, height -40, #PB_Ignore, #PB_Ignore)
  
  ResizeWindow(#mf, #PB_Ignore, #PB_Ignore, width, height)
EndProcedure
If you can not compile for Android, I suggest the APK. DateTime.apk (1.8 Mo)

■ Parameter
- General option: Enabled unknown sources.
- Development options: Enabled USB debugging

Re: Android: Test resolution screen

Posted: Sun Oct 08, 2017 7:33 pm
by mdp
I LOVE that trick to inhibit zoom. I needed that.
Saw your reply minutes ago, still reading the code...

Re: Android: Test resolution screen

Posted: Wed Nov 01, 2017 11:07 am
by Peter
falsam wrote:If you have a tablet or a smartphone with Android, you can create an apk with this code and tell me if the result is identical to this image.
I have just downloaded, installed and started your APK. Works as expected on my Nexus 5X. Thanks!

Greetings ... Peter

Re: Android: Test resolution screen

Posted: Wed Nov 01, 2017 11:20 am
by falsam
Thanks for this test Peter :)