SSH was working :(
SSH is connected to InputFields
This commit is contained in:
parent
4bc3832218
commit
c36368eee8
48
app/src/main/java/de/jg_cody/Terraplex/IntroActivity.java
Normal file
48
app/src/main/java/de/jg_cody/Terraplex/IntroActivity.java
Normal file
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
app/src/main/java/de/jg_cody/Terraplex/SSH_connection.java
Normal file
58
app/src/main/java/de/jg_cody/Terraplex/SSH_connection.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<String>() {
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
@ -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<String> mText;
|
||||||
|
|
||||||
|
public KonsoleViewModel() {
|
||||||
|
mText = new MutableLiveData<>();
|
||||||
|
mText.setValue("Konsole");
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<String> getText() {
|
||||||
|
return mText;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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<String> mText;
|
||||||
|
|
||||||
|
public IntroViewModel() {
|
||||||
|
mText = new MutableLiveData<>();
|
||||||
|
mText.setValue("Intro");
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<String> getText() {
|
||||||
|
return mText;
|
||||||
|
}
|
||||||
|
}
|
17
app/src/main/res/layout/activity_intro.xml
Normal file
17
app/src/main/res/layout/activity_intro.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
tools:openDrawer="start">
|
||||||
|
|
||||||
|
<androidx.fragment.app.FragmentContainerView
|
||||||
|
android:id="@+id/fragment2"
|
||||||
|
android:name="de.jg_cody.Terraplex.ui.intro.IntroFragment"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
|
|
20
app/src/main/res/layout/fragment_intro.xml
Normal file
20
app/src/main/res/layout/fragment_intro.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/background"
|
||||||
|
tools:context=".ui.intro.IntroFragment">
|
||||||
|
|
||||||
|
<VideoView
|
||||||
|
android:id="@+id/videoView"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.0" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
61
app/src/main/res/layout/fragment_konsole.xml
Normal file
61
app/src/main/res/layout/fragment_konsole.xml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.Konsole.KonsoleFragment"
|
||||||
|
android:background="@drawable/background">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/befehlInput"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:backgroundTint="#FFFFFF"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="text"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textColorHint="#FFFFFF"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/text_konsole"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.497"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView6"
|
||||||
|
android:layout_width="253dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="KONSOLE"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/befehlInput"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_konsole"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/SendCommandButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="SEND COMMAND"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/befehlInput" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
BIN
app/src/main/res/raw/intro.mp4
Normal file
BIN
app/src/main/res/raw/intro.mp4
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user