B4A Library SquareCamera

A shortcut wrap for this Github project. You will need B4A V6.00 to run this project (I presume). Posting the following:

1. The Java code - do with it as you like. You will need to create a folder called libs on the same folder level as the src folder and copy android-support-v4.jar and android-support-v7-appcompat.jar into this libs folder in order to compile the Java code.
2. A link to my complete B4A project (too big to post here) - https://www.dropbox.com/s/axmou469kmvwcok/b4aSquareCamera.zip?dl=0
3. The B4A library files and the AppCompat library files - copy them all (including the .aar) to your additional library folder.

From the Github posting:
Android module that takes a square photo using the native Android Camera APIs.

  • Tap to focus
  • Two fingers zooming
  • Front & Back camera
  • Flash mode (Saved when the user exits)
  • Supports both portrait & landscape
  • Runtime permission is supported for saving/viewing photos

Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: SquareCamera
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\SquareCameraLibRes
#AdditionalRes: ..\SquareCameraDemoRes

#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.
   
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
    Dim squarecamera As SquareCamera
   
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")
    squarecamera.Initialize("squarecamera")
    Label1.Visible = True
    Label1.Text = "Wrapped by Johan Schoeman"
   

End Sub

Sub Activity_Resume
   
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
   
  squarecamera.GotoSquareCamera
 
End Sub

1.png


2.png


3.png
 

Attachments

  • TheJavaCode.zip
    19.9 KB · Views: 394
  • SquareCameraLibFiles.zip
    110.7 KB · Views: 456

scsjc

Well-Known Member
Licensed User
Longtime User
Hello, can i select target save the image? have a event to get return picture?

Thanks
 
Last edited:

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello Johan,

I tried your code, but after several experiments and searching in the forum I didn't get a solution for a working example.
This is the error-message:
Logger verbunden mit: Xiaomi Redmi Note 8 Pro
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_globals (java line: 385)
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
at JHS.SquareCamera.main._globals(main.java:385)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at JHS.SquareCamera.main.initializeGlobals(main.java:327)
at JHS.SquareCamera.main.afterFirstLayout(main.java:102)
at JHS.SquareCamera.main.access$000(main.java:17)
at JHS.SquareCamera.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
Caused by: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatActivity
... 14 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at java.lang.Class.forName(Class.java:379)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:624)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:611)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:366)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at JHS.SquareCamera.main.initializeGlobals(main.java:327)
at JHS.SquareCamera.main.afterFirstLayout(main.java:102)
at JHS.SquareCamera.main.access$000(main.java:17)
at JHS.SquareCamera.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
Caused by: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatActivity
... 20 more
** Activity (main) Resume **

I've read, that there are somme problems in the newer rules from google with AppCompat.
Maybe this is the reason for the error?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hello Johan,

I tried your code, but after several experiments and searching in the forum I didn't get a solution for a working example.
This is the error-message:


I've read, that there are somme problems in the newer rules from google with AppCompat.
Maybe this is the reason for the error?

It works with B4A V10.7 and Java 11 (add RuntimePermissions in you B4A code and then you can change the targetSdkVersion to 26+:

B4A Manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<activity
            android:name="com.desmond.squarecamera.MainActivity"
            android:label="@string/app_name" >

        </activity>

        <activity android:name="com.desmond.squarecamera.CameraActivity" />)
        
AddApplicationText(<activity
            android:name="com.desmond.squarecamera.RuntimePermissionActivity"
            android:theme="@style/squarecamera__CameraFullScreenTheme.NoUI" >
        </activity>)       

SetActivityAttribute(Main, android:screenOrientation, "portrait")   
AddManifestText(<uses-feature android:name="android.hardware.camera2" />)


1616839439349.png



B4A Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: SquareCamera
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\SquareCameraLibRes
#AdditionalRes: ..\SquareCameraDemoRes

#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.
    
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
    Dim squarecamera As SquareCamera
    
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")
    squarecamera.Initialize("squarecamera")
    Label1.Visible = True
    Label1.Text = "Wrapped by Johan Schoeman"
    

End Sub

Sub Activity_Resume
    
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    
  squarecamera.GotoSquareCamera
 
End Sub
 
Top