From 30e8c495ec552b0241f4c1dd460ad0d4a41dc9eb Mon Sep 17 00:00:00 2001 From: lado Date: Wed, 2 May 2012 01:01:25 +0200 Subject: switch channel --- .../vdrmanager/gui/ChannelListActivity.java | 27 +++++++++++ .../utils/svdrp/SwitchChannelClient.java | 55 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java (limited to 'vdrmanager/src/de') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java index 08a1956..f185932 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java @@ -14,6 +14,7 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; +import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; @@ -33,9 +34,12 @@ import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.tasks.VoidAsyncTask; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; +import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncTask; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; +import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; +import de.bjusystems.vdrmanager.utils.svdrp.SwitchChannelClient; /** * This class is used for showing what's current running on all channels @@ -365,7 +369,30 @@ public class ChannelListActivity extends case R.id.channel_item_menu_hide_permanent: // TODO http://projects.vdr-developer.org/issues/722 break; + + case R.id.channel_item_menu_switch: + final String name = channel.getName(); + final SwitchChannelClient scc = new SwitchChannelClient(channel.getId()); + SvdrpAsyncTask task = new SvdrpAsyncTask(scc); + task.addListener(new SvdrpAsyncListener() { + public void svdrpEvent(SvdrpEvent event, String result) { + if(event == SvdrpEvent.FINISHED_SUCCESS){ + say(getString(R.string.switching_success, name)); + } else if(event == SvdrpEvent.CONNECT_ERROR || event == SvdrpEvent.FINISHED_ABNORMALY || event == SvdrpEvent.ABORTED || event == SvdrpEvent.ERROR || event == SvdrpEvent.CACHE_HIT){ + say(getString(R.string.switching_failed, name, event.name())); + } + + } + + public void svdrpException(SvdrpException e) { + Log.w(TAG, e.getMessage(), e); + say(e.getMessage()); + } + }); + task.run(); } + + return true; } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java new file mode 100644 index 0000000..d9fd77a --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java @@ -0,0 +1,55 @@ +package de.bjusystems.vdrmanager.utils.svdrp; + +import de.bjusystems.vdrmanager.R; + + +/** + * Class for switching a channel by SETCHANNEL + * + * @author lado + * + */ +public class SwitchChannelClient extends SvdrpClient { + + private Integer nr; + + private String chid; + + public SwitchChannelClient(Integer nr){ + this.nr = nr; + } + + public SwitchChannelClient(String chid){ + this.chid = chid; + } + + /** + * Constructor + */ + public SwitchChannelClient() { + super(); + } + + /** + * Starts the wakeup request + */ + @Override + public void run() throws SvdrpException { + if(nr != null){ + runCommand("SETCHANNEL " + String.valueOf(nr)); + } else { + runCommand("SETCHANNEL " + chid); + } + } + + @Override + public String parseAnswer(final String line) { + return line; + } + + @Override + public int getProgressTextId() { + return R.string.progress_switching; + } + +} \ No newline at end of file -- cgit v1.2.3