Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mathias Stanger
yasc
Commits
efab36cc
Commit
efab36cc
authored
Apr 13, 2016
by
Mathias Stanger
Browse files
OTTO entfern, wir fahren nicht mehr mit dem Bus.
parent
a8eb612a
Changes
6
Show whitespace changes
Inline
Side-by-side
app/build.gradle
View file @
efab36cc
...
...
@@ -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'
}
app/src/main/AndroidManifest.xml
View file @
efab36cc
...
...
@@ -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>
app/src/main/java/de/matsta/yasc/BusApplication.java
deleted
100644 → 0
View file @
a8eb612a
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
;
}
}
app/src/main/java/de/matsta/yasc/ChronosBusSupportActivity.java
deleted
100644 → 0
View file @
a8eb612a
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
();
}
}
app/src/main/java/de/matsta/yasc/MainActivity.java
deleted
100644 → 0
View file @
a8eb612a
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
();
}
}
app/src/main/java/de/matsta/yasc/SshOperation.java
View file @
efab36cc
...
...
@@ -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
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment