Share your advanced knowledge/code with the community.
falsam
 
Posts: 275
Joined: Mon May 05, 2014 9:49 pm
Location: France

cordova-plugin-flashlight

by falsam Tue Feb 27, 2018 12:25 pm

Practice with Cordova : Create your flashlight without advertising.

Platform
   Android
   iOS

■ Documentation : https://www.npmjs.com/package/cordova-plugin-flashlight

Code: Select all
Enumeration
  #mf
  #mfSwitch
EndEnumeration

Declare PluginInit(onSuccess, onError)
Declare Start()
Declare OnClick()
Declare OnError()

;No debug
CloseDebugOutput()

;Import Cordova Plugin
Import "cordova plugin add cordova-plugin-flashlight"
EndImport

;Init plugin
PluginInit(@Start(), @OnError())

Procedure PluginInit(onSuccess, onError)
  !window.plugins.flashlight.available(function(isAvailable) {
  ! if (isAvailable) {
  !     v_onsuccess();     
  ! } else {
  !     v_onerror();
  ! }
  !})
EndProcedure

Procedure Start()
  Protected Font = LoadFont(-1, "Arial", 20)
 
  OpenWindow(#mf, 0, 0, 0, 0, "Flash Light", #PB_Window_Background)
  SetWindowColor(#mf, RGB(105, 105, 105))
  ButtonGadget(#mfSwitch, 20, 50, WindowWidth(0)-40, 200, "Light On")
  SetGadgetFont(#mfSwitch, FontID(Font))
 
  ;Trigger
  BindGadgetEvent(#mfSwitch, @OnClick()) 
EndProcedure

Procedure OnClick()
  Static Status
 
  If Status
    Status = #False
    SetGadgetText(#mfSwitch, "Light On")
    ! window.plugins.flashlight.switchOff() 
  Else
    Status = #True
    SetGadgetText(#mfSwitch, "Light Off")
    !  window.plugins.flashlight.switchOn()
  EndIf 
EndProcedure

Procedure OnError()
  !alert("Flashlight not available on this device")
EndProcedure
Last edited by falsam on Sun May 13, 2018 12:31 pm, edited 1 time in total.

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
plouf
 
Posts: 38
Joined: Tue Feb 25, 2014 6:01 pm

Re: cordova-plugin-flashlight

by plouf Tue Feb 27, 2018 6:37 pm

Great !!
tested works nexus 5 !
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 1 guest