Skip to content

Commit

Permalink
New feature adjustViewBounds 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
AsynctaskCoffee committed Dec 11, 2020
1 parent 5f2ddff commit 0be4a55
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ExternalUsageActivity" />
<activity android:name=".MainActivity" />
<activity android:name=".Main2Activity" />
<activity android:name=".SpotiActivity">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package egolabsapps.basicodemine.videolayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class ExternalUsageActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_external_usage)
}
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_external_usage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ExternalUsageActivity">


<egolabsapps.basicodemine.videolayout.VideoLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/videoLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:adjustViewBounds="false"
app:loop="true"
app:path_or_url="lp_chesterr.mp4"
app:video_gravity="centerInside"
tools:context=".MainActivity" />

</LinearLayout>
11 changes: 5 additions & 6 deletions app/src/main/res/layout/activity_main2.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="25dp"
android:textColor="@color/colorPrimaryDark"
android:text="THANK YOU FOR USING LIBRARY"
android:layout_height="match_parent"/>
android:textColor="@color/colorPrimaryDark"
android:textSize="25dp" />

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class VideoLayout extends FrameLayout implements TextureView.SurfaceTextu
private boolean isUrl;
private boolean IS_LOOP;
private boolean SOUND;
private boolean ADJUSTVIEWBOUNDS = false;


// <enum name="start" value="0" />
Expand Down Expand Up @@ -82,6 +83,10 @@ public void setSound(boolean sound) {
}
}

public void setAdjustViewBounds(boolean b) {
this.ADJUSTVIEWBOUNDS = b;
}

public VideoLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);

Expand All @@ -91,6 +96,7 @@ public VideoLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
VIDEO_GRAVITY = a.getInteger(R.styleable.VideoLayout_video_gravity, 2);
IS_LOOP = a.getBoolean(R.styleable.VideoLayout_loop, true);
SOUND = a.getBoolean(R.styleable.VideoLayout_sound, false);
ADJUSTVIEWBOUNDS = a.getBoolean(R.styleable.VideoLayout_adjustViewBounds, false);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -178,7 +184,19 @@ private void updateTextureViewSize(int viewWidth, int viewHeight) {
private void surfaceSetup() {
int screenHeight = getResources().getDisplayMetrics().heightPixels;
int screenWidth = getResources().getDisplayMetrics().widthPixels;
updateTextureViewSize(screenWidth, screenHeight);

if (ADJUSTVIEWBOUNDS) {

if (mVideoHeight < screenHeight && mVideoWidth < screenWidth) {
updateTextureViewSize((int) mVideoWidth, (int) mVideoHeight);
} else {
float height = (screenWidth / mVideoWidth) * mVideoHeight;
updateTextureViewSize(screenWidth, (int) height);
}

} else updateTextureViewSize(screenWidth, screenHeight);


}

private void surfaceAvailableWorkers(SurfaceTexture surfaceTexture) {
Expand Down
1 change: 1 addition & 0 deletions videolayout/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<attr name="path_or_url" format="string" />
<attr name="loop" format="boolean" />
<attr name="sound" format="boolean" />
<attr name="adjustViewBounds" format="boolean" />
<attr name="video_gravity" format="enum">
<enum name="start" value="0" />
<enum name="end" value="1" />
Expand Down

0 comments on commit 0be4a55

Please sign in to comment.