shutdown- and restart-button moved to homefragment

removed consolefragment
added working terminal
This commit is contained in:
JG-Cody 2021-07-15 21:11:19 +02:00
parent 746c2db5f8
commit c6037412e7
13 changed files with 430 additions and 364 deletions

View File

@ -7,7 +7,7 @@ android {
defaultConfig { defaultConfig {
applicationId "de.jg_cody.Teraplex" applicationId "de.jg_cody.Teraplex"
minSdkVersion 19 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -33,7 +33,7 @@ android {
dependencies { dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02' implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02'
implementation 'androidx.navigation:navigation-fragment:2.3.5' implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5' implementation 'androidx.navigation:navigation-ui:2.3.5'
@ -42,8 +42,8 @@ dependencies {
implementation 'com.jcraft:jsch:0.1.55' implementation 'com.jcraft:jsch:0.1.55'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.github.martin-stone:hsv-alpha-color-picker-android:3.0.1' implementation 'com.github.martin-stone:hsv-alpha-color-picker-android:3.0.1'
} }

View File

@ -37,7 +37,6 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Switch; import android.widget.Switch;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
@ -142,7 +141,7 @@ public class MainActivity extends AppCompatActivity {
// Passing each menu ID as a set of Ids because each // Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations. // menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder( mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_einstellungen, R.id.nav_zeitsteuerung, R.id.nav_tabs, R.id.nav_über, R.id.nav_konsole) R.id.nav_home, R.id.nav_einstellungen, R.id.nav_zeitsteuerung, R.id.nav_tabs, R.id.nav_über, R.id.nav_terminal)
.setOpenableLayout(drawer) .setOpenableLayout(drawer)
.build(); .build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);

View File

@ -1,183 +0,0 @@
package de.jg_cody.Teraplex.ui.Konsole;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection;
import static de.jg_cody.Teraplex.ui.home.HomeFragment.ip;
import static de.jg_cody.Teraplex.ui.home.HomeFragment.password;
import static de.jg_cody.Teraplex.ui.home.HomeFragment.user;
public class KonsoleFragment extends Fragment {
public static String command;
public static EditText befehlInput;
Button SendCommandButton;
Button shutdown_Button;
Button reboot_Button;
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);
SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null);
if (Background != null) {
ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
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) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
try {
if (befehlInput.getText().toString().trim().length() == 0) {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.invalid))
.setMessage(getString(R.string.inputfields_cant_be_empty))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
} else {
command = befehlInput.getText().toString();
Toast.makeText(getContext(), "Kommando gesendet...", Toast.LENGTH_SHORT).show();
Toast.makeText(root.getContext(), command, Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, command);
}
} catch (Exception ignored) {
}
}
});
reboot_Button = (Button) root.findViewById(R.id.reboot);
reboot_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.restart_server))
.setMessage(getString(R.string.are_you_sure))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();
Toast.makeText(getContext(), "Reboot wird ausgeführt...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "reboot");
} catch (Exception ignored) {
}
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
});
shutdown_Button = (Button) root.findViewById(R.id.shutdown);
shutdown_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.shutdown_server))
.setMessage(getString(R.string.are_you_sure))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();
Toast.makeText(getContext(), "Server wird heruntergefahren...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "shutdown now");
} catch (Exception ignored) {
}
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
});
return root;
}
}

View File

@ -1,8 +0,0 @@
package de.jg_cody.Teraplex.ui.Konsole;
import androidx.lifecycle.ViewModel;
public class KonsoleViewModel extends ViewModel {
}

View File

@ -0,0 +1,115 @@
package de.jg_cody.Teraplex.ui.Terminal;
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/**
* This program enables you to connect to sshd server and get the shell prompt.
* $ CLASSPATH=.:../build javac Shell.java
* $ CLASSPATH=.:../build java Shell
* You will be asked username, hostname and passwd.
* If everything works fine, you will get the shell prompt. Output may
* be ugly because of lacks of terminal-emulation, but you can issue commands.
*/
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import de.jg_cody.Teraplex.ui.home.HomeFragment;
public class Terminal {
private Session session;
private JSch jsch;
private ByteArrayOutputStream Output;
private PipedOutputStream Input;
public Terminal() {
try {
JSch jsch = new JSch();
Session session = jsch.getSession(HomeFragment.user, HomeFragment.ip, 22);
session.setPassword(HomeFragment.password);
session.setUserInfo(new MyUserInfo() {
@Override
public String getPassword() {
return super.getPassword();
}
});
session.setConfig("StrictHostKeyChecking", "no");
session.connect(30000);
Channel channel = session.openChannel("shell");
Input = new PipedOutputStream();
channel.setInputStream(new PipedInputStream(Input));
Output = new ByteArrayOutputStream();
channel.setOutputStream(Output);
channel.connect(3 * 1000);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getTerminalOutput(){
return new String(Output.toByteArray());
}
public void sendTerminalCommand(String terminalcommand){
try {
Input.write((terminalcommand+"\n").getBytes());
Input.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public static abstract class MyUserInfo
implements UserInfo, UIKeyboardInteractive {
public String getPassword() {
return null;
}
public boolean promptYesNo(String str) {
return false;
}
public String getPassphrase() {
return null;
}
public boolean promptPassphrase(String message) {
return false;
}
public boolean promptPassword(String message) {
return false;
}
public void showMessage(String message) {
}
public String[] promptKeyboardInteractive(String destination,
String name,
String instruction,
String[] prompt,
boolean[] echo) {
return null;
}
}
}

View File

@ -0,0 +1,83 @@
package de.jg_cody.Teraplex.ui.Terminal;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import de.jg_cody.Teraplex.R;
public class TerminalFragment extends Fragment {
public static String command;
EditText terminal_edit_text;
TextView terminal_textView;
Terminal terminal;
ScrollView scrollView;
private TerminalViewModel terminalViewModel;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
terminalViewModel =
new ViewModelProvider(this).get(TerminalViewModel.class);
View root = inflater.inflate(R.layout.fragment_terminal, container, false);
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());
}
return true;
}
});
terminal_textView = (TextView) root.findViewById(R.id.terminal_textView);
new Thread() {
public void run() {
terminal = new Terminal();
while (true) {
try {
getActivity().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();
return root;
}
@Override
public void onDestroy() {
super.onDestroy();
}
}

View File

@ -0,0 +1,8 @@
package de.jg_cody.Teraplex.ui.Terminal;
import androidx.lifecycle.ViewModel;
public class TerminalViewModel extends ViewModel {
}

View File

@ -3,6 +3,7 @@ package de.jg_cody.Teraplex.ui.home;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
@ -27,6 +28,7 @@ import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection;
public class HomeFragment extends Fragment { public class HomeFragment extends Fragment {
@ -35,6 +37,8 @@ public class HomeFragment extends Fragment {
public static EditText ipInput; public static EditText ipInput;
public static EditText userInput; public static EditText userInput;
public static EditText passwordInput; public static EditText passwordInput;
Button reboot_Button;
Button shutdown_Button;
Button loginButton; Button loginButton;
Button logoutButton; Button logoutButton;
Button wlan_aus_Button; Button wlan_aus_Button;
@ -74,14 +78,20 @@ public class HomeFragment extends Fragment {
passwordInput = (EditText) root.findViewById(R.id.loginpasswordInput); passwordInput = (EditText) root.findViewById(R.id.loginpasswordInput);
ipInput = (EditText) root.findViewById(R.id.ipInput); ipInput = (EditText) root.findViewById(R.id.ipInput);
loginButton = (Button) root.findViewById(R.id.loginButton); loginButton = (Button) root.findViewById(R.id.loginButton);
reboot_Button = (Button) root.findViewById(R.id.reboot);
shutdown_Button = (Button) root.findViewById(R.id.shutdown);
SharedPreferences t = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences t = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
if (user == null || ip == null) { if (user == null || ip == null) {
loginButton.setVisibility(View.VISIBLE); loginButton.setVisibility(View.VISIBLE);
reboot_Button.setVisibility(View.GONE);
shutdown_Button.setVisibility(View.GONE);
} else { } else {
loginButton.setVisibility(View.INVISIBLE); loginButton.setVisibility(View.INVISIBLE);
ipInput.setVisibility(View.GONE); ipInput.setVisibility(View.GONE);
userInput.setVisibility(View.GONE); userInput.setVisibility(View.GONE);
passwordInput.setVisibility(View.GONE); passwordInput.setVisibility(View.GONE);
reboot_Button.setVisibility(View.VISIBLE);
shutdown_Button.setVisibility(View.VISIBLE);
} }
loginButton.setOnClickListener(new View.OnClickListener() { loginButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -112,6 +122,8 @@ public class HomeFragment extends Fragment {
Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show();
if (user == null || ip == null) { if (user == null || ip == null) {
login_data.setText(""); login_data.setText("");
reboot_Button.setVisibility(View.GONE);
shutdown_Button.setVisibility(View.GONE);
} else { } else {
login_data.setText(getString(R.string.sie_sind_als_angemeldet).replace("{IP}", ip).replace("{USERNAME}", user)); login_data.setText(getString(R.string.sie_sind_als_angemeldet).replace("{IP}", ip).replace("{USERNAME}", user));
logoutButton.setVisibility(View.VISIBLE); logoutButton.setVisibility(View.VISIBLE);
@ -119,6 +131,8 @@ public class HomeFragment extends Fragment {
ipInput.setVisibility(View.GONE); ipInput.setVisibility(View.GONE);
userInput.setVisibility(View.GONE); userInput.setVisibility(View.GONE);
passwordInput.setVisibility(View.GONE); passwordInput.setVisibility(View.GONE);
reboot_Button.setVisibility(View.VISIBLE);
shutdown_Button.setVisibility(View.VISIBLE);
} }
} }
} }
@ -129,8 +143,12 @@ public class HomeFragment extends Fragment {
ipInput.setVisibility(View.VISIBLE); ipInput.setVisibility(View.VISIBLE);
userInput.setVisibility(View.VISIBLE); userInput.setVisibility(View.VISIBLE);
passwordInput.setVisibility(View.VISIBLE); passwordInput.setVisibility(View.VISIBLE);
reboot_Button.setVisibility(View.GONE);
shutdown_Button.setVisibility(View.GONE);
} else { } else {
logoutButton.setVisibility(View.VISIBLE); logoutButton.setVisibility(View.VISIBLE);
reboot_Button.setVisibility(View.VISIBLE);
shutdown_Button.setVisibility(View.VISIBLE);
} }
logoutButton.setOnClickListener(new View.OnClickListener() { logoutButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -143,7 +161,91 @@ public class HomeFragment extends Fragment {
requireActivity().finish(); requireActivity().finish();
} }
}); });
reboot_Button = (Button) root.findViewById(R.id.reboot);
reboot_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.restart_server))
.setMessage(getString(R.string.are_you_sure))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();
Toast.makeText(getContext(), "Reboot wird ausgeführt...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "reboot");
} catch (Exception ignored) {
}
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
});
shutdown_Button = (Button) root.findViewById(R.id.shutdown);
shutdown_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.shutdown_server))
.setMessage(getString(R.string.are_you_sure))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
try {
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_down);
mp.start();
Toast.makeText(getContext(), "Server wird heruntergefahren...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "shutdown now");
} catch (Exception ignored) {
}
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
});
return root; return root;
} }
} }

View File

@ -9,6 +9,35 @@
android:hapticFeedbackEnabled="true" android:hapticFeedbackEnabled="true"
tools:context=".ui.home.HomeFragment"> tools:context=".ui.home.HomeFragment">
<Button
android:id="@+id/shutdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/button_round"
android:hapticFeedbackEnabled="true"
android:text="@string/shutdown"
app:backgroundTint="@null"
app:icon="@drawable/power_settings_new_24px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/reboot" />
<Button
android:id="@+id/reboot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_round"
android:hapticFeedbackEnabled="true"
android:text="@string/reboot"
app:backgroundTint="@null"
app:icon="@drawable/restart_alt_24px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ipInput" />
<ImageView <ImageView
android:id="@+id/Background" android:id="@+id/Background"
android:layout_width="0dp" android:layout_width="0dp"
@ -29,23 +58,40 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginStart="-25dp" android:layout_marginStart="-25dp"
android:layout_marginLeft="-25dp"
android:layout_marginTop="-25dp" android:layout_marginTop="-25dp"
android:layout_marginEnd="-25dp" android:layout_marginEnd="-25dp"
android:layout_marginRight="-25dp"
android:layout_marginBottom="-25dp" android:layout_marginBottom="-25dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:src="@drawable/backgroundoverlay" android:src="@drawable/backgroundoverlay"
app:layout_constraintBottom_toBottomOf="@+id/logoutButton" app:layout_constraintBottom_toBottomOf="@+id/logoutButton"
app:layout_constraintEnd_toEndOf="@+id/text_home" app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/text_home" app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toTopOf="@+id/text_home" /> app:layout_constraintTop_toTopOf="@+id/text_home"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/backgroundoverlay"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="-25dp"
android:layout_marginTop="-25dp"
android:layout_marginEnd="-25dp"
android:layout_marginBottom="-25dp"
android:scaleType="centerCrop"
android:src="@drawable/backgroundoverlay"
app:layout_constraintBottom_toBottomOf="@+id/shutdown"
app:layout_constraintEnd_toEndOf="@+id/shutdown"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/shutdown"
app:layout_constraintTop_toTopOf="@+id/reboot"
app:layout_constraintVertical_bias="0.0" />
<TextView <TextView
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="200dp" android:layout_marginTop="100dp"
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"

View File

@ -1,159 +0,0 @@
<?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:clickable="true"
android:layout_height="match_parent"
tools:context=".ui.Konsole.KonsoleFragment">
<ImageView
android:id="@+id/Background"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="@drawable/fog_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@drawable/backgroundoverlay"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="-25dp"
android:layout_marginLeft="-25dp"
android:layout_marginTop="-25dp"
android:layout_marginEnd="-25dp"
android:layout_marginRight="-25dp"
android:layout_marginBottom="-25dp"
android:scaleType="centerCrop"
android:src="@drawable/backgroundoverlay"
app:layout_constraintBottom_toBottomOf="@+id/shutdown"
app:layout_constraintEnd_toEndOf="@+id/Serverbefehle"
app:layout_constraintStart_toStartOf="@+id/Serverbefehle"
app:layout_constraintTop_toTopOf="@+id/textView6" />
<Button
android:id="@+id/shutdown"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/button_right"
android:hapticFeedbackEnabled="true"
android:text="@string/shutdown"
app:backgroundTint="@null"
app:icon="@drawable/power_settings_new_24px"
app:layout_constraintEnd_toEndOf="@+id/Serverbefehle"
app:layout_constraintStart_toEndOf="@+id/reboot"
app:layout_constraintTop_toBottomOf="@+id/Serverbefehle" />
<Button
android:id="@+id/reboot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/button_left"
android:hapticFeedbackEnabled="true"
android:text="@string/reboot"
app:backgroundTint="@null"
app:icon="@drawable/restart_alt_24px"
app:layout_constraintEnd_toStartOf="@+id/shutdown"
app:layout_constraintStart_toStartOf="@+id/Serverbefehle"
app:layout_constraintTop_toBottomOf="@+id/Serverbefehle" />
<EditText
android:id="@+id/befehlInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/mtrl_btn_text_color_selector"
android:ems="10"
android:hint="COMMAND"
android:inputType="text"
android:textColor="@color/mtrl_btn_text_color_selector"
android:textColorHint="@color/mtrl_btn_text_color_selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
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="@string/console"
android:textAlignment="center"
android:textColor="@color/mtrl_btn_text_color_selector"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/befehlInput"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/Serverbefehle"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center_horizontal"
android:text="@string/servercommands"
android:textAlignment="center"
android:textColor="@color/mtrl_btn_text_color_selector"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider8" />
<Button
android:id="@+id/SendCommandButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/button_round"
android:hapticFeedbackEnabled="true"
android:text="@string/button_send_command"
app:backgroundTint="@null"
app:icon="@drawable/send_24px"
app:layout_constraintEnd_toEndOf="@+id/befehlInput"
app:layout_constraintStart_toStartOf="@+id/befehlInput"
app:layout_constraintTop_toBottomOf="@+id/befehlInput" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_marginStart="-50dp"
android:layout_marginLeft="-50dp"
android:layout_marginEnd="-50dp"
android:layout_marginRight="-50dp"
android:layout_marginBottom="-125dp"
android:src="@drawable/teraplex_sidebar"
app:tint="@color/mtrl_btn_text_color_selector"
app:layout_constraintBottom_toTopOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:id="@+id/divider8"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/background_full"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/SendCommandButton" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,63 @@
<?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:clickable="true"
android:layout_height="match_parent"
tools:context=".ui.Terminal.TerminalFragment">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toTopOf="@+id/divider2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/terminal_textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView"
android:textColor="#FFFFFF" />
</LinearLayout>
</ScrollView>
<View
android:id="@+id/divider2"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/background_full"
app:layout_constraintBottom_toTopOf="@+id/terminal_edit_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/terminal_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="type commands"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -14,7 +14,7 @@
android:icon="@drawable/home_black_24dp" android:icon="@drawable/home_black_24dp"
android:title="@string/menu_home" /> android:title="@string/menu_home" />
<item <item
android:id="@+id/nav_konsole" 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_konsole" />
<item <item

View File

@ -13,10 +13,10 @@
tools:layout="@layout/fragment_home" /> tools:layout="@layout/fragment_home" />
<fragment <fragment
android:id="@+id/nav_konsole" android:id="@+id/nav_terminal"
android:name="de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment" android:name="de.jg_cody.Teraplex.ui.Terminal.TerminalFragment"
android:label="@string/menu_konsole" android:label="@string/menu_konsole"
tools:layout="@layout/fragment_konsole" /> tools:layout="@layout/fragment_terminal" />
<fragment <fragment
android:id="@+id/nav_einstellungen" android:id="@+id/nav_einstellungen"