This commit is contained in:
JG-Cody 2021-07-18 19:36:30 +02:00
parent 737c2fe722
commit c5e1b8b986
5 changed files with 66 additions and 35 deletions

View File

@ -1,5 +1,7 @@
package de.jg_cody.Teraplex.ui.Terminal; package de.jg_cody.Teraplex.ui.Terminal;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -8,6 +10,7 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -23,6 +26,7 @@ public class TerminalFragment extends Fragment {
TextView terminal_textView; TextView terminal_textView;
Terminal terminal; Terminal terminal;
ScrollView scrollView; ScrollView scrollView;
public static String user, password, ip;
private TerminalViewModel terminalViewModel; private TerminalViewModel terminalViewModel;
@ -31,51 +35,76 @@ public class TerminalFragment extends Fragment {
terminalViewModel = terminalViewModel =
new ViewModelProvider(this).get(TerminalViewModel.class); new ViewModelProvider(this).get(TerminalViewModel.class);
View root = inflater.inflate(R.layout.fragment_terminal, container, false); View root = inflater.inflate(R.layout.fragment_terminal, container, false);
scrollView = (ScrollView) root.findViewById((R.id.scrollView)); SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
terminal_edit_text = (EditText) root.findViewById(R.id.terminal_edit_text); user = prefs.getString("user", null);
terminal_edit_text.setOnKeyListener(new View.OnKeyListener() { password = prefs.getString("password", null);
@Override ip = prefs.getString("ip", null);
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (user == null || ip == null) {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show();
terminal.sendTerminalCommand(terminal_edit_text.getText().toString());
}
else {
Toast.makeText(getContext(), ("test"), Toast.LENGTH_SHORT).show();
scrollView = (ScrollView) root.findViewById((R.id.scrollView));
terminal_edit_text = (EditText) root.findViewById(R.id.terminal_edit_text);
terminal_edit_text.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
terminal.sendTerminalCommand(terminal_edit_text.getText().toString());
} } else {
return false; terminal_textView = (TextView) root.findViewById(R.id.terminal_textView);
} new Thread() {
});
terminal_textView = (TextView) root.findViewById(R.id.terminal_textView);
new Thread() {
public void run() {
terminal = new Terminal();
while (true) {
try {
requireActivity().runOnUiThread(new Runnable() {
@Override
public void run() { public void run() {
boolean atBottom = scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY()); terminal = new Terminal();
terminal_textView.setText(terminal.getTerminalOutput()); boolean isFragmentActive = true;
System.out.println(atBottom); while (isFragmentActive == true) {
Fragment myFragment = (Fragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_terminal);
if (myFragment == null) {
terminal_textView.invalidate(); isFragmentActive = false;
scrollView.invalidate(); }
scrollView.fullScroll(View.FOCUS_DOWN); else if (myFragment.isVisible())
{
isFragmentActive = false;
}
try {
requireActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
boolean atBottom = scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY());
terminal_textView.setText(terminal.getTerminalOutput());
System.out.println(atBottom);
terminal_textView.invalidate();
scrollView.invalidate();
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
}); }.start();
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
} }
return false;
} }
} });
}.start(); }
return root; return root;
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();

View File

@ -54,7 +54,7 @@ public class IntroFragment extends Fragment {
setDimension(); setDimension();
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(false); mMediaPlayer.setLooping(true);
// 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);

View File

@ -91,12 +91,13 @@
android:id="@+id/text_home" android:id="@+id/text_home"
android:layout_width="200dp" android:layout_width="200dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="100dp" android:layout_marginBottom="50dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:text="@string/Welcome_to_your_HOMEAUTOMATION_APP" android:text="@string/Welcome_to_your_HOMEAUTOMATION_APP"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/mtrl_btn_text_color_selector" android:textColor="@color/mtrl_btn_text_color_selector"
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/reboot"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/background" android:background="#000000"
tools:context=".ui.intro.IntroFragment"> tools:context=".ui.intro.IntroFragment">
<VideoView <VideoView

View File

@ -5,6 +5,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:clickable="true" android:clickable="true"
android:id="@+id/fragment_terminal"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.Terminal.TerminalFragment"> tools:context=".ui.Terminal.TerminalFragment">