summaryrefslogtreecommitdiff
path: root/vdrmanager/src/de/bjusystems
diff options
context:
space:
mode:
authorherrlado <herrlado@gmail.com>2011-09-23 11:56:19 +0200
committerherrlado <herrlado@gmail.com>2011-09-23 11:56:19 +0200
commit1bbe62e96bbc7564202790d4e6bec1af135dfb14 (patch)
tree42488fd3d23ebe234eec184e8bb9b24165cd47af /vdrmanager/src/de/bjusystems
parent033e4bd7c7c197fcce396f4f4610e8857453e9ae (diff)
downloadvdr-manager-1bbe62e96bbc7564202790d4e6bec1af135dfb14.tar.gz
vdr-manager-1bbe62e96bbc7564202790d4e6bec1af135dfb14.tar.bz2
"wol and wakup state message suppot.'
Diffstat (limited to 'vdrmanager/src/de/bjusystems')
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/WakeupClient.java51
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java69
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupProgress.java28
3 files changed, 73 insertions, 75 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/WakeupClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/WakeupClient.java
deleted file mode 100644
index 072861c..0000000
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/WakeupClient.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package de.bjusystems.vdrmanager.utils.svdrp;
-
-import de.bjusystems.vdrmanager.data.WakeupState;
-
-/**
- * Class for retrieving informations about the running program
- * @author bju
- *
- */
-public class WakeupClient extends SvdrpClient<WakeupState> {
-
- private WakeupState state;
-
- /**
- * Constructor
- */
- public WakeupClient() {
- super();
- }
-
- /**
- * Starts the wakeup request
- */
- @Override
- public void run() throws SvdrpException {
- runCommand("wake");
- }
-
- @Override
- public WakeupState parseAnswer(final String line) {
-
- if (line.startsWith("200")) {
- state = WakeupState.OK;
- } else if (line.startsWith("400")) {
- state = WakeupState.FAILED;
- } else {
- state = WakeupState.ERROR;
- }
- return state;
- }
-
- @Override
- public int getProgressTextId() {
- return 0;
- }
-
- public WakeupState getState() {
- return state;
- }
-
-} \ No newline at end of file
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
index 2586b5c..997dc41 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java
@@ -2,7 +2,9 @@ package de.bjusystems.vdrmanager.utils.wakeup;
import android.app.ProgressDialog;
import android.content.Context;
+import android.graphics.Canvas.VertexMode;
import android.os.AsyncTask;
+import android.util.Log;
import android.widget.Toast;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Preferences;
@@ -10,6 +12,7 @@ import de.bjusystems.vdrmanager.utils.http.HttpHelper;
public class AsyncWakeupTask extends AsyncTask<Object, WakeupProgress, Void> {
+ private static final String TAG = "AsyncWakeupTask";
/** Context */
private final Context context;
/** Progress dialog */
@@ -19,34 +22,54 @@ public class AsyncWakeupTask extends AsyncTask<Object, WakeupProgress, Void> {
this.context = context;
}
+ Wakeuper getWakeuper() {
+ // Preferences
+ final Preferences prefs = Preferences.getPreferences();
+
+ if (Preferences.getPreferences().getWakeupMethod().equals("url")) {
+ return new Wakeuper() {
+ public void wakeup(Context context) {
+ // wakeup by http request
+ final HttpHelper httpHelper = new HttpHelper();
+ httpHelper.performGet(prefs.getWakeupUrl(),
+ prefs.getWakeupUser(), prefs.getWakeupPassword(),
+ null);
+ // request sent
+
+ }
+ };
+ } else {
+ return new Wakeuper() {
+ public void wakeup(Context context) throws Exception {
+ WakeOnLanClient.wake(prefs.getVdrMac());
+ }
+ };
+ }
+ }
+
@Override
protected Void doInBackground(final Object... params) {
// open progress dialog
- publishProgress(WakeupProgress.WAKEUP_STARTED);
-
- // Preferences
- final Preferences prefs = Preferences.getPreferences();
+ publishProgress(new WakeupProgress(WakeupProgressType.WAKEUP_STARTED));
boolean ok = false;
+ String msg = null;
try {
-
- // wakeup by http request
- final HttpHelper httpHelper = new HttpHelper();
- httpHelper.performGet(prefs.getWakeupUrl(), prefs.getWakeupUser(), prefs.getWakeupPassword(), null);
- // request sent
+ getWakeuper().wakeup(context);
ok = true;
-
} catch (final Exception e) {
+ Log.w(TAG, e);
+ msg = e.getMessage();
}
// close progress
- publishProgress(WakeupProgress.WAKEUP_FINISHED);
-
+ publishProgress(new WakeupProgress(WakeupProgressType.WAKEUP_FINISHED));
if (ok) {
- publishProgress(WakeupProgress.WAKEUP_OK);
+ publishProgress(new WakeupProgress(WakeupProgressType.WAKEUP_OK));
} else {
- publishProgress(WakeupProgress.WAKEUP_ERROR);
+ publishProgress(new WakeupProgress(WakeupProgressType.WAKEUP_ERROR,
+ msg));
}
return null;
@@ -56,9 +79,12 @@ public class AsyncWakeupTask extends AsyncTask<Object, WakeupProgress, Void> {
protected void onProgressUpdate(final WakeupProgress... values) {
super.onProgressUpdate(values);
- switch (values[0]) {
+ WakeupProgress t = values[0];
+
+ switch (t.getState()) {
case WAKEUP_STARTED:
- final CharSequence message = context.getText(R.string.progress_wakeup_sending);
+ final CharSequence message = context
+ .getText(R.string.progress_wakeup_sending);
progressDialog = ProgressDialog.show(context, "", message);
break;
case WAKEUP_FINISHED:
@@ -68,14 +94,19 @@ public class AsyncWakeupTask extends AsyncTask<Object, WakeupProgress, Void> {
showToast(R.string.progress_wakeup_sent);
break;
case WAKEUP_ERROR:
- showToast(R.string.progress_wakeup_error);
+ showToast(R.string.progress_wakeup_error, t.getInfo());
break;
}
}
- private void showToast(final int textId) {
+ private void showToast(final int textId, Object... args) {
- final CharSequence text = context.getText(textId);
+ final CharSequence text;
+ if (args.length > 1) {
+ text = context.getString(textId);
+ } else {
+ text = context.getString(textId, args);
+ }
final int duration = Toast.LENGTH_SHORT;
final Toast toast = Toast.makeText(context, text, duration);
toast.show();
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupProgress.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupProgress.java
index 46838dc..f86608a 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupProgress.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupProgress.java
@@ -1,8 +1,26 @@
package de.bjusystems.vdrmanager.utils.wakeup;
-public enum WakeupProgress {
- WAKEUP_STARTED,
- WAKEUP_OK,
- WAKEUP_ERROR,
- WAKEUP_FINISHED
+public class WakeupProgress {
+
+ public WakeupProgress(WakeupProgressType state) {
+ this(state, null);
+ }
+
+ public WakeupProgress(WakeupProgressType state, String info) {
+ this.state = state;
+ this.info = info;
+ }
+
+ private WakeupProgressType state;
+
+ private String info;
+
+ public WakeupProgressType getState() {
+ return state;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
}