#Region Project Attributes
#ApplicationLabel: AndroidVisionMaster
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#AdditionalRes: ..\resource
#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design
#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama
#Extends: android.support.v7.app.AppCompatActivity
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim nativeMe As JavaObject
Dim HasAnyActivityPaused As Boolean = False
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private Label1 As Label
Private Label2 As Label
Private Label4 As Label
Private Label3 As Label
Dim settings(2) As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Label1.Text = ""
Label2.Text = ""
Label3.Text = "Flash Disabled"
Label4.Text = "Auto Focus Enabled"
nativeMe.InitializeContext
Log("ID of Front Facing Camera = " & nativeMe.RunMethod("getFrontFacingCamera", Null))
Log("ID of Back Facing Camera = " & nativeMe.RunMethod("getBackFacingCamera", Null))
Log("Device has a flash = " & nativeMe.RunMethod("hasFlash", Null))
If nativeMe.RunMethod("hasFlash", Null) = False Then
Label3.Visible = False 'hide the label to select the flash with
End If
settings(0) = False 'do not switch on the Torch when the scanner starts
settings(1) = True 'use Auto Focus once the scanner started
End Sub
Sub Activity_Resume
HasAnyActivityPaused = False
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
CallSubDelayed2(Main_Scanner, "StartScan", settings)
End Sub
Sub GetResult(retval() As String) 'This is called by activity Main_Scanner (with the result of the scan)
HasAnyActivityPaused = False
Log("back in main : format = " & retval(0))
Log("back in main : data = " & retval(1))
Label1.Text = "Barcode Format : " & retval(0)
Label2.Text = "Barcode Data : " & retval(1)
End Sub
Sub Label3_Click
If Label3.Text = "Flash Disabled" Then
Label3.Text = "Flash Enabled"
Label3.Color = Colors.Red
settings(0) = True
Else
Label3.Color = 0xff008000
Label3.Text = "Flash Disabled"
settings(0) = False
End If
End Sub
Sub Label4_Click
If Label4.Text = "Auto Focus Disabled" Then
Label4.Text = "Auto Focus Enabled"
Label4.Color = Colors.Red
settings(1) = True
Else
Label4.Color = 0xff008000
Label4.Text = "Auto Focus Disabled"
settings(1) = False
End If
End Sub
#If Java
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.CameraInfo;
import android.content.pm.PackageManager;
import android.content.Context;
public int CAMERA_FRONT = -1;
public int CAMERA_BACK = -1;
private boolean hasflash = false;
public int getFrontFacingCamera() {
int cameraId = -1;
// Search for the front facing camera
// get the number of cameras
int numberOfCameras = Camera.getNumberOfCameras();
// for every camera check
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
cameraId = i;
break;
}
}
CAMERA_FRONT = cameraId;
return cameraId;
}
/**
* Get the ID of the back facing camera
* If the device has a front and back camera then the ID = 0
* If the device has a back facing camera only then the ID = 0
* It will return the ID as -1 if there is no back facing camera
*/
public int getBackFacingCamera() {
int cameraId = -1;
// Search for the back facing camera
// get the number of cameras
int numberOfCameras = Camera.getNumberOfCameras();
// for every camera check
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
cameraId = i;
break;
}
}
CAMERA_BACK = cameraId;
return cameraId;
}
public boolean hasFlash() {
/*
* First check if device is supporting a flashlight or not
*/
hasflash = BA.applicationContext.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
return hasflash;
}
#End If