introvideo scaleproblems fixed
This commit is contained in:
parent
c6037412e7
commit
737c2fe722
@ -41,7 +41,7 @@ public class TerminalFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
terminal_textView = (TextView) root.findViewById(R.id.terminal_textView);
|
terminal_textView = (TextView) root.findViewById(R.id.terminal_textView);
|
||||||
@ -50,7 +50,7 @@ public class TerminalFragment extends Fragment {
|
|||||||
terminal = new Terminal();
|
terminal = new Terminal();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
requireActivity().runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -51,18 +51,10 @@ public class IntroFragment extends Fragment {
|
|||||||
videoBG.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
videoBG.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared(MediaPlayer mediaPlayer) {
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
||||||
float videoRatio = mediaPlayer.getVideoWidth() / (float) mediaPlayer.getVideoHeight();
|
setDimension();
|
||||||
float screenRatio = videoBG.getWidth() / (float)
|
|
||||||
videoBG.getHeight();
|
|
||||||
float scaleX = videoRatio / screenRatio;
|
|
||||||
if (scaleX >= 1f) {
|
|
||||||
videoBG.setScaleX(scaleX);
|
|
||||||
} else {
|
|
||||||
videoBG.setScaleY(1f / scaleX);
|
|
||||||
}
|
|
||||||
mMediaPlayer = mediaPlayer;
|
mMediaPlayer = mediaPlayer;
|
||||||
// We want our video to play over and over so we set looping to true.
|
// We want our video to play over and over so we set looping to true.
|
||||||
mMediaPlayer.setLooping(true);
|
mMediaPlayer.setLooping(false);
|
||||||
// We then seek to the current position if it has been set and play the video.
|
// We then seek to the current position if it has been set and play the video.
|
||||||
if (mCurrentVideoPosition != 0) {
|
if (mCurrentVideoPosition != 0) {
|
||||||
mMediaPlayer.seekTo(mCurrentVideoPosition);
|
mMediaPlayer.seekTo(mCurrentVideoPosition);
|
||||||
@ -99,4 +91,30 @@ public class IntroFragment extends Fragment {
|
|||||||
mMediaPlayer.release();
|
mMediaPlayer.release();
|
||||||
mMediaPlayer = null;
|
mMediaPlayer = null;
|
||||||
}
|
}
|
||||||
|
private void setDimension() {
|
||||||
|
// Adjust the size of the video
|
||||||
|
// so it fits on the screen
|
||||||
|
float videoProportion = getVideoProportion();
|
||||||
|
int screenWidth = getResources().getDisplayMetrics().widthPixels;
|
||||||
|
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
||||||
|
float screenProportion = (float) screenHeight / (float) screenWidth;
|
||||||
|
android.view.ViewGroup.LayoutParams lp = videoBG.getLayoutParams();
|
||||||
|
|
||||||
|
if (videoProportion < screenProportion) {
|
||||||
|
lp.height= screenHeight;
|
||||||
|
lp.width = (int) ((float) screenHeight / videoProportion);
|
||||||
|
} else {
|
||||||
|
lp.width = screenWidth;
|
||||||
|
lp.height = (int) ((float) screenWidth * videoProportion);
|
||||||
|
}
|
||||||
|
videoBG.setLayoutParams(lp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method gets the proportion of the video that you want to display.
|
||||||
|
// I already know this ratio since my video is hardcoded, you can get the
|
||||||
|
// height and width of your video and appropriately generate the proportion
|
||||||
|
// as :height/width
|
||||||
|
private float getVideoProportion(){
|
||||||
|
return 2.22f;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,9 +12,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
app:layout_constraintVertical_bias="0.0" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -16,7 +16,7 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/nav_terminal"
|
android:id="@+id/nav_terminal"
|
||||||
android:icon="@drawable/code_black_24dp"
|
android:icon="@drawable/code_black_24dp"
|
||||||
android:title="@string/menu_konsole" />
|
android:title="@string/menu_terminal" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_zeitsteuerung"
|
android:id="@+id/nav_zeitsteuerung"
|
||||||
android:icon="@drawable/schedule_black_24dp"
|
android:icon="@drawable/schedule_black_24dp"
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_terminal"
|
android:id="@+id/nav_terminal"
|
||||||
android:name="de.jg_cody.Teraplex.ui.Terminal.TerminalFragment"
|
android:name="de.jg_cody.Teraplex.ui.Terminal.TerminalFragment"
|
||||||
android:label="@string/menu_konsole"
|
android:label="@string/menu_terminal"
|
||||||
tools:layout="@layout/fragment_terminal" />
|
tools:layout="@layout/fragment_terminal" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<string name="login_username">BENUTZERNAME</string>
|
<string name="login_username">BENUTZERNAME</string>
|
||||||
<string name="login_password">PASSWORT</string>
|
<string name="login_password">PASSWORT</string>
|
||||||
<string name="menu_home">HOME</string>
|
<string name="menu_home">HOME</string>
|
||||||
<string name="menu_konsole">KONSOLE</string>
|
<string name="menu_terminal">TERMINAL</string>
|
||||||
<string name="menu_kueche">KÜCHE</string>
|
<string name="menu_kueche">KÜCHE</string>
|
||||||
<string name="menu_zeitsteuerung">ZEITSTEUERUNG</string>
|
<string name="menu_zeitsteuerung">ZEITSTEUERUNG</string>
|
||||||
<string name="menu_schlafzimmer">SCHLAFZIMMER</string>
|
<string name="menu_schlafzimmer">SCHLAFZIMMER</string>
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
<string name="cooperation">IN COOPERATION WITH</string>
|
<string name="cooperation">IN COOPERATION WITH</string>
|
||||||
|
|
||||||
<string name="menu_home">HOME</string>
|
<string name="menu_home">HOME</string>
|
||||||
<string name="menu_konsole">CONSOLE</string>
|
<string name="menu_terminal">TERMINAL</string>
|
||||||
<string name="menu_kueche">KITCHEN</string>
|
<string name="menu_kueche">KITCHEN</string>
|
||||||
<string name="menu_zeitsteuerung">TIME-CONTROL</string>
|
<string name="menu_zeitsteuerung">TIME-CONTROL</string>
|
||||||
<string name="menu_schlafzimmer">BEDROOM</string>
|
<string name="menu_schlafzimmer">BEDROOM</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user