cordova-plugin-flashlight

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

cordova-plugin-flashlight

Post by falsam »

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 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: cordova-plugin-flashlight

Post by plouf »

Great !!
tested works nexus 5 !
Christos
Post Reply