Android Question getDefaultSize

MarcoRome

Expert
Licensed User
Longtime User
I should translate this into B4A. I stopped on "getDefaultSize (mVideoWidth, widthMeasureSpec);"
The code is:
Code:
2     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
4         int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
5         int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
6         if (mVideoWidth > 0 && mVideoHeight > 0) {
7             if ( mVideoWidth * height  > width * mVideoHeight ) {
8                 //Log.i("@@@", "image too tall, correcting");
9                 height = width * mVideoHeight / mVideoWidth;
10             } else if ( mVideoWidth * height  < width * mVideoHeight ) {
11                //Log.i("@@@", "image too wide, correcting");
12                 width = height * mVideoWidth / mVideoHeight;
13             } else {
14                 //Log.i("@@@", "aspect ratio is correct: " +
15                         //width+"/"+height+"="+
16                         //mVideoWidth+"/"+mVideoHeight);
17             }
18         }
19         //Log.i("@@@@@@@@@@", "setting size: " + width + 'x' + height);
20         setMeasuredDimension(width, height);
21     }

Any idea ?
Thank you
 
We have in B4A this utility o equivalent ?
getDefaultSize
Added in API level 1
int getDefaultSize (int size,
int measureSpec)
Utility to return a default size. Uses the supplied size if the MeasureSpec imposed no constraints. Will get larger if allowed by the MeasureSpec.
Parameters
sizeint: Default size for this view
measureSpecint: Constraints imposed by the parent
Returns
intThe size this view should be.

Thank you
Marco
 
Upvote 0
I tried this code:

Code:
  Dim bo As JavaObject
  bo.InitializeStatic("android.widget.VideoView")
  Dim vedi As Int = bo.RunMethod("getDefaultSize", Array As Object(480, 1280 ))
Log("getDefaultSize: " & vedi )

Return ever first number that i put: "480"
if i write:
Code:
....
Dim vedi As Int = bo.RunMethod("getDefaultSize", Array As Object(600, 1280 ))
....
Return 600

Where i wrong ?
 
Upvote 0
Erel sorry for the question.. but if i write 480, 1280 why i need android.view.view if i already insert value

Code:
 Dim vedi As Int = bo.RunMethod("getDefaultSize", Array As Object(480, 1280 ))
 
Upvote 0
This is source the getDefaultSize:

Code:
public static int getDefaultSize(int size, int measureSpec) {
        int result = size;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);

        switch (specMode) {
        case MeasureSpec.UNSPECIFIED:
            result = size;
            break;
        case MeasureSpec.AT_MOST:
        case MeasureSpec.EXACTLY:
            result = specSize;
            break;
        }
        return result;
    }

Now if i already write value "size" and "measureSpec" ( 480, 1280 ) why the result is ever result = size.
 
Upvote 0
Yes Erel you are right.
This code is to zoom in (also using the Ratio to prevent the Video is not proportionate, type too elongated, pressed, etc).
So I found this code over the network and wanted to exchange this for B4A so that could work.
To explain in my case I have the video from 480 (width) and 280 (height).
If I want to fill the device screen with the movie (especially in portrait mode) I get a very elongated image and obviously not proportional.
In any case, I settled with the following code that I share in the event that will be useful to a colleague:

Code:
.....
Dim width As Int = Activity.Width
Dim height As Int = Activity.Height
If height > width Then
         width = ((Activity.Height * 480 ) / 270 )
    Else
        height = (( Activity.Width * 270 ) / 450 )
End If

w = width
h = height
.....
 
Upvote 0
Back
Top