diff --git a/app/src/main/java/de/jg_cody/Terraplex/IntroActivity.java b/app/src/main/java/de/jg_cody/Terraplex/IntroActivity.java new file mode 100644 index 0000000..d3435de --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/IntroActivity.java @@ -0,0 +1,48 @@ +package de.jg_cody.Terraplex; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.Menu; +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.navigation.ui.AppBarConfiguration; +import androidx.navigation.ui.NavigationUI; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.navigation.NavigationView; + +import static de.jg_cody.Terraplex.ui.Konsole.KonsoleFragment.command; +import static de.jg_cody.Terraplex.ui.home.HomeFragment.ip; +import static de.jg_cody.Terraplex.ui.home.HomeFragment.password; +import static de.jg_cody.Terraplex.ui.home.HomeFragment.user; + +public class IntroActivity extends AppCompatActivity { + + +private AppBarConfiguration mAppBarConfiguration; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_intro); + final Handler handler = new Handler(Looper.getMainLooper()); + handler.postDelayed(new Runnable() { + @Override + public void run() { + //Do something after 100ms + Intent m = new Intent(getApplicationContext(),MainActivity.class); + startActivity(m); + } + }, 6000); + + } + +} \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Terraplex/SSH_connection.java b/app/src/main/java/de/jg_cody/Terraplex/SSH_connection.java new file mode 100644 index 0000000..7a365b8 --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/SSH_connection.java @@ -0,0 +1,58 @@ +package de.jg_cody.Terraplex; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.Session; + +import java.io.InputStream; + +public class SSH_connection { + + public static void executeRemoteCommand(String ip, String user, String password, String command) throws Exception { + new Thread(() -> { + String command1 = command; + try { + + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); + JSch jsch = new JSch(); + Session session = jsch.getSession(user, ip, 22); + session.setPassword(password); + session.setConfig(config); + session.connect(); + System.out.println("Connected"); + + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command1); + channel.setInputStream(null); + ((ChannelExec) channel).setErrStream(System.err); + + InputStream in = channel.getInputStream(); + channel.connect(); + byte[] tmp = new byte[1024]; + while (true) { + while (in.available() > 0) { + int i = in.read(tmp, 0, 1024); + if (i < 0) break; + System.out.print(new String(tmp, 0, i)); + } + if (channel.isClosed()) { + System.out.println("exit-status: " + channel.getExitStatus()); + break; + } + try { + Thread.sleep(1000); + } catch (Exception ee) { + } + } + channel.disconnect(); + session.disconnect(); + System.out.println("DONE"); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleFragment.java b/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleFragment.java new file mode 100644 index 0000000..73aa87b --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleFragment.java @@ -0,0 +1,61 @@ +package de.jg_cody.Terraplex.ui.Konsole; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import de.jg_cody.Terraplex.R; +import de.jg_cody.Terraplex.SSH_connection; + +import static de.jg_cody.Terraplex.ui.home.HomeFragment.ip; +import static de.jg_cody.Terraplex.ui.home.HomeFragment.password; +import static de.jg_cody.Terraplex.ui.home.HomeFragment.user; + +public class KonsoleFragment extends Fragment { + + public static String command; + + public static EditText befehlInput; + Button SendCommandButton; + + private KonsoleViewModel konsoleViewModel; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + konsoleViewModel = + new ViewModelProvider(this).get(KonsoleViewModel.class); + View root = inflater.inflate(R.layout.fragment_konsole, container, false); + final TextView textView = root.findViewById(R.id.text_konsole); + konsoleViewModel.getText().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(@Nullable String s) { + textView.setText(s); + } + }); + befehlInput = (EditText) root.findViewById(R.id.befehlInput); + SendCommandButton = (Button) root.findViewById(R.id.SendCommandButton); + SendCommandButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + command = befehlInput.getText().toString(); + + Toast.makeText(root.getContext(),command,Toast.LENGTH_SHORT).show(); + SSH_connection.executeRemoteCommand(ip, user, password, command); + } catch (Exception e) { + }} + }); + return root; + } +} \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleViewModel.java b/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleViewModel.java new file mode 100644 index 0000000..a26d4af --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/ui/Konsole/KonsoleViewModel.java @@ -0,0 +1,19 @@ +package de.jg_cody.Terraplex.ui.Konsole; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +public class KonsoleViewModel extends ViewModel { + + private MutableLiveData mText; + + public KonsoleViewModel() { + mText = new MutableLiveData<>(); + mText.setValue("Konsole"); + } + + public LiveData getText() { + return mText; + } +} \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroFragment.java b/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroFragment.java new file mode 100644 index 0000000..a3f0281 --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroFragment.java @@ -0,0 +1,106 @@ +package de.jg_cody.Terraplex.ui.intro; + +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.VideoView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import de.jg_cody.Terraplex.R; + +public class IntroFragment extends Fragment { + + // Create a VideoView variable, a MediaPlayer variable, and an int to hold the current + // video position. + private VideoView videoBG; + MediaPlayer mMediaPlayer; + int mCurrentVideoPosition; + + private IntroViewModel introViewModel; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + introViewModel = + new ViewModelProvider(this).get(IntroViewModel.class); + View root = inflater.inflate(R.layout.fragment_intro, container, false); + + // Hook up the VideoView to our UI. + videoBG = (VideoView) root.findViewById(R.id.videoView); + + // Build your video Uri + Uri uri = Uri.parse("android.resource://" // First start with this, + + getContext().getPackageName() // then retrieve your package name, + + "/" // add a slash, + + R.raw.intro); // and then finally add your video resource. Make sure it is stored + // in the raw folder. + + // Set the new Uri to our VideoView + System.out.println(uri); + videoBG.setVideoURI(uri); + // Start the VideoView + videoBG.start(); + + // Set an OnPreparedListener for our VideoView. For more information about VideoViews, + // check out the Android Docs: https://developer.android.com/reference/android/widget/VideoView.html + videoBG.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(MediaPlayer mediaPlayer) { + float videoRatio = mediaPlayer.getVideoWidth() / (float) mediaPlayer.getVideoHeight(); + float screenRatio = videoBG.getWidth() / (float) + videoBG.getHeight(); + float scaleX = videoRatio / screenRatio; + if (scaleX >= 1f) { + videoBG.setScaleX(scaleX); + } else { + videoBG.setScaleY(1f / scaleX); + } + System.out.println("VIDEOOOOO"); + mMediaPlayer = mediaPlayer; + // We want our video to play over and over so we set looping to true. + mMediaPlayer.setLooping(true); + // We then seek to the current position if it has been set and play the video. + if (mCurrentVideoPosition != 0) { + mMediaPlayer.seekTo(mCurrentVideoPosition); + mMediaPlayer.start(); + } + } + }); + return root; + } + /*================================ Important Section! ================================ + We must override onPause(), onResume(), and onDestroy() to properly handle our + VideoView. + */ + + @Override + public void onPause() { + super.onPause(); + // Capture the current video position and pause the video. + mCurrentVideoPosition = mMediaPlayer.getCurrentPosition(); + videoBG.pause(); + } + + @Override + public void onResume() { + super.onResume(); + // Restart the video when resuming the Activity + videoBG.start(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + // When the Activity is destroyed, release our MediaPlayer and set it to null. + mMediaPlayer.release(); + mMediaPlayer = null; + } +} \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroViewModel.java b/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroViewModel.java new file mode 100644 index 0000000..762681d --- /dev/null +++ b/app/src/main/java/de/jg_cody/Terraplex/ui/intro/IntroViewModel.java @@ -0,0 +1,19 @@ +package de.jg_cody.Terraplex.ui.intro; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +public class IntroViewModel extends ViewModel { + + private MutableLiveData mText; + + public IntroViewModel() { + mText = new MutableLiveData<>(); + mText.setValue("Intro"); + } + + public LiveData getText() { + return mText; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml new file mode 100644 index 0000000..9028384 --- /dev/null +++ b/app/src/main/res/layout/activity_intro.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_intro.xml b/app/src/main/res/layout/fragment_intro.xml new file mode 100644 index 0000000..62e6196 --- /dev/null +++ b/app/src/main/res/layout/fragment_intro.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_konsole.xml b/app/src/main/res/layout/fragment_konsole.xml new file mode 100644 index 0000000..88ebe35 --- /dev/null +++ b/app/src/main/res/layout/fragment_konsole.xml @@ -0,0 +1,61 @@ + + + + + + + + + +