Commit efab36cc authored by Mathias Stanger's avatar Mathias Stanger

OTTO entfern, wir fahren nicht mehr mit dem Bus.

parent a8eb612a
......@@ -26,5 +26,4 @@ dependencies {
compile 'com.jcraft:jsch:0.1.53'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.redmadrobot:chronos:1.0.5'
compile 'com.squareup:otto:1.3.8'
}
......@@ -12,7 +12,6 @@
android:icon="@mipmap/ic_launcher_sphinx"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".BusApplication"
android:theme="@style/AppTheme">
<activity android:name=".FragmentContainerActivity">
<intent-filter>
......@@ -20,7 +19,5 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package de.matsta.yasc;
import android.app.Application;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
public class BusApplication extends Application {
/* Bitte einsteigen, Otto fährt gleich weiter. */
public static Bus bus = new Bus(ThreadEnforcer.ANY);
public static Bus getBus() {
return bus;
}
}
package de.matsta.yasc;
import com.redmadrobot.chronos.gui.activity.ChronosActivity;
public class ChronosBusSupportActivity extends ChronosActivity {
@Override
protected void onResume() {
super.onResume();
// Alle Events der Activity registrieren
BusApplication.getBus().register(this);
}
@Override
protected void onPause() {
// Alle Events abklemmen, damit wir nicht darauf reagieren während die Activity nicht sichtbar ist.
BusApplication.getBus().unregister(this);
super.onPause();
}
}
package de.matsta.yasc;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.redmadrobot.chronos.gui.activity.ChronosSupportActivity;
import com.squareup.otto.Subscribe;
import java.net.URISyntaxException;
import butterknife.Bind;
import butterknife.ButterKnife;
public class MainActivity extends ChronosSupportActivity {
private static final int FILE_SELECT_CODE = 0;
@Bind(R.id.btnExecute)
Button mBtnExecute;
@Bind(R.id.edtUsername)
EditText mEdtUsername;
@Bind(R.id.edtKeyPass)
EditText mEdtKeyPass;
@Bind(R.id.btnSelectKey)
Button mBtnSelectKey;
//@Bind(R.id.btnBuzz)
//Button mBtnBuzz;
@Bind(R.id.btnOpen)
Button mBtnOpen;
@Bind(R.id.btnClose)
Button mBtnClose;
@Bind(R.id.btnStatus)
Button mBtnStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mBtnExecute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save();
executeRemote("who");
}
});
mBtnStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save();
executeRemote("status");
}
});
/*mBtnBuzz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save();
executeRemote("buzz");
}
});*/
mBtnOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save();
executeRemote("open");
}
});
mBtnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save();
executeRemote("close");
}
});
mBtnSelectKey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFileChooser();
}
});
SharedPrefsTools sharedPrefs = new SharedPrefsTools(getApplicationContext());
// Daten aus SharedPreferences laden
mEdtUsername.setText(sharedPrefs.getUsername());
mEdtKeyPass.setText(sharedPrefs.getKeyPwd());
}
public void onOperationFinished(final SshOperation.Result result) {
// Wird das hier eigentlich jemals aufgerufen?
if (result.isSuccessful()) {
Toast.makeText(this, "onOperationFinished: " + result.getOutput(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "onOperationFinished: " + result.getErrorMessage(), Toast.LENGTH_LONG).show();
Log.d(this.getClass().getSimpleName(), result.getErrorMessage());
}
}
private void executeRemote(String command) {
SharedPrefsTools sharedPrefsTools = new SharedPrefsTools(getApplicationContext());
runOperation(new SshOperation(
// TODO Die Serveradresse sollte konfigurierbar sein.
sharedPrefsTools.getHost(), sharedPrefsTools.getUsername(), sharedPrefsTools.getKey(), sharedPrefsTools.getKeyPwd(), 22, command
));
}
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, getString(R.string.selectPrivateKey)),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, R.string.installFilebrowser,
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Wir erhalten eine URI um auf die Datei zuzugreifen
Uri uri = data.getData();
// Wir wollen aber keine Uri sondern den Pfad
try {
String path = Utils.getPath(this, uri);
if (path == null) {
throw new Exception(getString(R.string.exceptionPathNotParseable));
}
new SharedPrefsTools(this).setKey(path);
} catch (Exception e) {
Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage());
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private void save() {
// Wir speichern die Eingaben in den SharedPreferences
SharedPrefsTools sharedPrefsTools = new SharedPrefsTools(getApplicationContext());
sharedPrefsTools.setUsername(mEdtUsername.getText().toString());
// TODO Schlüssel im Keystore / Authenticator speichern.
sharedPrefsTools.setKeyPwd(mEdtKeyPass.getText().toString());
}
@Subscribe
public void onShellMessage(ShellMessageEvent event) {
// Wir bekommen die gesamte Ausgabe, also ganzen Text mit allen Befehlen und deren Rückgaben. Hier könnte man vielleicht noch etwas filtern oder besser darauf reagieren.
Toast.makeText(this, event.getMessage(), Toast.LENGTH_LONG).show();
}
}
......@@ -69,9 +69,6 @@ public class SshOperation extends ChronosOperation<String> {
System.out.println("Error while reading channel output: " + e);
}
// Nachricht auf den Bus werfen
BusApplication.getBus().post(
new ShellMessageEvent(sb.toString()));
return sb.toString();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment