Skip to content

Commit 0be4a55

Browse files
New feature adjustViewBounds 🚀
1 parent 5f2ddff commit 0be4a55

6 files changed

Lines changed: 58 additions & 7 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
android:roundIcon="@mipmap/ic_launcher_round"
1212
android:supportsRtl="true"
1313
android:theme="@style/AppTheme">
14+
<activity android:name=".ExternalUsageActivity" />
1415
<activity android:name=".MainActivity" />
1516
<activity android:name=".Main2Activity" />
1617
<activity android:name=".SpotiActivity">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package egolabsapps.basicodemine.videolayout
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class ExternalUsageActivity : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_external_usage)
10+
}
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
tools:context=".ExternalUsageActivity">
8+
9+
10+
<egolabsapps.basicodemine.videolayout.VideoLayout xmlns:app="http://schemas.android.com/apk/res-auto"
11+
android:id="@+id/videoLayout"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_gravity="center"
15+
app:adjustViewBounds="false"
16+
app:loop="true"
17+
app:path_or_url="lp_chesterr.mp4"
18+
app:video_gravity="centerInside"
19+
tools:context=".MainActivity" />
20+
21+
</LinearLayout>
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
5-
android:layout_width="match_parent"
64
android:id="@+id/frameLayout"
5+
android:layout_width="match_parent"
76
android:layout_height="match_parent"
87
tools:context=".Main2Activity">
98

109

1110
<TextView
1211
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
1313
android:layout_gravity="center"
1414
android:gravity="center"
15-
android:textSize="25dp"
16-
android:textColor="@color/colorPrimaryDark"
1715
android:text="THANK YOU FOR USING LIBRARY"
18-
android:layout_height="match_parent"/>
16+
android:textColor="@color/colorPrimaryDark"
17+
android:textSize="25dp" />
1918

2019
</FrameLayout>

videolayout/src/main/java/egolabsapps/basicodemine/videolayout/VideoLayout.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class VideoLayout extends FrameLayout implements TextureView.SurfaceTextu
3131
private boolean isUrl;
3232
private boolean IS_LOOP;
3333
private boolean SOUND;
34+
private boolean ADJUSTVIEWBOUNDS = false;
3435

3536

3637
// <enum name="start" value="0" />
@@ -82,6 +83,10 @@ public void setSound(boolean sound) {
8283
}
8384
}
8485

86+
public void setAdjustViewBounds(boolean b) {
87+
this.ADJUSTVIEWBOUNDS = b;
88+
}
89+
8590
public VideoLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
8691
super(context, attrs);
8792

@@ -91,6 +96,7 @@ public VideoLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
9196
VIDEO_GRAVITY = a.getInteger(R.styleable.VideoLayout_video_gravity, 2);
9297
IS_LOOP = a.getBoolean(R.styleable.VideoLayout_loop, true);
9398
SOUND = a.getBoolean(R.styleable.VideoLayout_sound, false);
99+
ADJUSTVIEWBOUNDS = a.getBoolean(R.styleable.VideoLayout_adjustViewBounds, false);
94100
} finally {
95101
a.recycle();
96102
}
@@ -178,7 +184,19 @@ private void updateTextureViewSize(int viewWidth, int viewHeight) {
178184
private void surfaceSetup() {
179185
int screenHeight = getResources().getDisplayMetrics().heightPixels;
180186
int screenWidth = getResources().getDisplayMetrics().widthPixels;
181-
updateTextureViewSize(screenWidth, screenHeight);
187+
188+
if (ADJUSTVIEWBOUNDS) {
189+
190+
if (mVideoHeight < screenHeight && mVideoWidth < screenWidth) {
191+
updateTextureViewSize((int) mVideoWidth, (int) mVideoHeight);
192+
} else {
193+
float height = (screenWidth / mVideoWidth) * mVideoHeight;
194+
updateTextureViewSize(screenWidth, (int) height);
195+
}
196+
197+
} else updateTextureViewSize(screenWidth, screenHeight);
198+
199+
182200
}
183201

184202
private void surfaceAvailableWorkers(SurfaceTexture surfaceTexture) {

videolayout/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<attr name="path_or_url" format="string" />
55
<attr name="loop" format="boolean" />
66
<attr name="sound" format="boolean" />
7+
<attr name="adjustViewBounds" format="boolean" />
78
<attr name="video_gravity" format="enum">
89
<enum name="start" value="0" />
910
<enum name="end" value="1" />

0 commit comments

Comments
 (0)