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





 

Attachments

  • TheJavaCode.zip
    19.9 KB · Views: 388
  • SquareCameraLibFiles.zip
    110.7 KB · Views: 443

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:

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

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" />)





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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…