Android Code Snippet View Utils

Subject: Set and get the 'padding' of a view.

Sub: setPadding
Description: Sets the padding'of a view.
B4X:
'Sets the padding of a view
'v = view
'Left, Top, Right, Bottom padding values in pixels
Sub setPadding(v As View, Left As Int, Top As Int, Right As Int, Bottom As Int)
    Dim jo = v As JavaObject
    jo.RunMethod("setPadding", Array As Object(Left, Top, Right, Bottom))
End Sub

Sub: getPaddingLeft
Description: Gets the left 'padding' of a view.
B4X:
'Gets the Left padding of the given view
Sub getPaddingLeft(v As View) As Int
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPaddingLeft", Null)
End Sub

Sub: getPaddingTop
Description: Gets the top 'padding' of a view.
B4X:
'Gets the Top padding of the given view
Sub getPaddingTop(v As View) As Int
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPaddingTop", Null)
End Sub

Sub: getPaddingRight
Description: Gets the right 'padding' of a view.
B4X:
'Gets the Right padding of the given view
Sub getPaddingRight(v As View) As Int
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPaddingRight", Null)
End Sub

Sub: getPaddingBottom
Description: Gets the bottom 'padding' of a view.
B4X:
'Gets the Bottom padding of the given view
Sub getPaddingBottom(v As View) As Int
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPaddingBottom", Null)
End Sub

Tags: View, Padding, getPadding, setPadding
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Subject: Get the root or parent view of a given view, check if a view is an Activity.

Sub: getRootView

Description: Gets the root view of the given view.
This routine is not really useful, it doesn't return the Activiy but the Activitys parent.
B4X:
'Returns the root view of the given view, it's mainly the Activity
Sub getRootView(v As View) As View
    Dim jo = v As JavaObject
    Return jo.RunMethod("getRootView", Null)
End Sub


Sub: getParent
Description: Gets the parent view of the given view. Activity or Panel.
B4X:
'Returns the parent view of the given view
Sub getParent(v As View) As View
    Dim jo = v As JavaObject
    Return jo.RunMethod("getParent", Null)
End Sub

Sub: IsActivity
Description: Returns True if the given view is an Activity, otherwise returns False.
B4X:
' Checks if a view is an Activity
Sub IsActivity(v As View) As Boolean
    Try
        v.Left = 10dip
        Return False
    Catch
        Return True
    End Try
End Sub

Tags: View, parent, parent view, getParent, getRootView, root view, activity
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Subject: View rotations

Valid since API level 11

Sub: setRotation
Description: Sets the rotation angle of the given view around the Z axis.
B4X:
'Sets the rotation angle of the given view
'v = view
'Angle = rotation angle in degrees
Sub setRotation(v As View, Angle As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))
End Sub

Sub: setRotationX
Description: Sets the rotation angle around the X axis of the given view.
B4X:
'Sets the rotation angle around the X axis of the given view
'v = view
'Angle = rotation angle in degrees
Sub setRotationX(v As View, Angle As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setRotationX", Array As Object(Angle))
End Sub

Sub: setRotationY
Description: Sets the rotation angle around the Y axis of the given view.
B4X:
'Sets the rotation angle around the Y axis of the given view
'v = view
'Angle = rotation angle in degrees
Sub setRotationY(v As View, Angle As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setRotationY", Array As Object(Angle))
End Sub

Sub: setPivotX
Description: Sets the X pivot for the given view.
B4X:
'Sets the X pivot point of the given view
'v = view
'X = X coordinate of the pivot in pixels
'reference upper left corner, default pivot middle of the view
Sub setPivotX(v As View, X As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setPivotX", Array As Object(X))
End Sub

Sub: setPivotY
Description: Sets the Y pivot for the given view.
B4X:
'Sets the Y pivot point of the given view
'v = view
'Y = Y coordinate of the pivot in pixels
'reference upper left corner, default pivot middle of the view
Sub setPivotY(v As View, Y As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setPivotY", Array As Object(Y))
End Sub

Sub: getPivotX
Description: Gets the X pivot for the given view.
B4X:
'Gets the X pivot point of the given view
Sub getPivotX(v As View) As Float
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPivotX", Null)
End Sub

Sub: getPivotY
Description: Gets the Y pivot for the given view.
B4X:
'Gets the Y pivot point of the given view
Sub getPivotY(v As View) As Float
    Dim jo = v As JavaObject
    Return jo.RunMethod("getPivotY", Null)
End Sub

Dependencies: JavaObject library.

Tags: View, rotate, pivot, setRotation, setPivot

Attached a small test project showing the principle.
 

Attachments

  • ViewRotation.png
    ViewRotation.png
    40.9 KB · Views: 1,503
  • ViewRotation.zip
    7.4 KB · Views: 1,250
Last edited:

Kevin L. Johnson

Member
Licensed User
Longtime User
Does anyone know if this pivot-point x, y, and z along with the rotation about x, y, or z capability (using B4A code) exists somehow under B4J? If not, how might it be done under B4J?

I would like to rotate photos taken of data traces (graphs) displayed on a data collection screen at various x, y, and z angles, such that the pictures of the graphs could then be cropped, rotated and or pivoted such that the graphs could then be digitized and data values extracted.

This would allow for (in my case) remote data analysis of any ad-hoc disparate non-standard data collection systems to work together without the need of defining a formal interface between them. All the onsite technician needs to do is snap a picture of the screen (which may not always be directly in front of them) and transfer the picture to the remote off-site. Then software could rotate the pic, digitize the trace so that the analysis could take place. The technician could then be advised as to the quantifiable effect of the previous adjustment then also advised of the next adjustment.

Thanks
Kevin
 
Last edited:

Kevin L. Johnson

Member
Licensed User
Longtime User
You can use the jXUI library, which is included in B4J.
The B4XView object has a Rotation property.
It has only one pivot point in the middle.
This is explained in the B4X IDE Booklet in the FirstExample project.

Thanks Klaus, I had looked into that. My recollection was that while I could get by with the one pivot point, I could not rotate about the X, Y and Z axis but only rotate the image clockwise or counterclockwise. If the computer screen containing the graph in the image was trapezoidal (for instance) then any clockwise or counter-clockwise rotation of the image would still be trapezoidal and rotated. My goal would be to get a trapezoidal shaped screen to be rectangular.

I will again, look at your reference to the B4X IDE Booklet in the FirstExample project.
Thanks
Kevin
 

klaus

Expert
Licensed User
Longtime User
I will again, look at your reference to the B4X IDE Booklet in the FirstExample project.
The explanation concerns only the z rotation with the rotation point in the middle.

Maybe this thread could help: B4J Question 3D rotation
 
Top