diff options
Diffstat (limited to 'vdrmanager/src/de/bjusystems')
28 files changed, 849 insertions, 503 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java b/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java new file mode 100644 index 0000000..23f1845 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java @@ -0,0 +1,151 @@ +package de.bjusystems.vdrmanager; + +import java.util.ArrayList; +import java.util.List; + + +public class StringUtils { + + /** + * An empty immutable <code>String</code> array. + */ + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + + + /** + * Performs the logic for the <code>split</code> and + * <code>splitPreserveAllTokens</code> methods that return a maximum array + * length. + * + * @param str the String to parse, may be <code>null</code> + * @param separatorChars the separate character + * @param max the maximum number of elements to include in the + * array. A zero or negative value implies no limit. + * @param preserveAllTokens if <code>true</code>, adjacent separators are + * treated as empty token separators; if <code>false</code>, adjacent + * separators are treated as one separator. + * @return an array of parsed Strings, <code>null</code> if null String input + */ + private static String[] splitWorker(String str, String separatorChars, int max, boolean preserveAllTokens) { + // Performance tuned for 2.0 (JDK1.4) + // Direct code is quicker than StringTokenizer. + // Also, StringTokenizer uses isSpace() not isWhitespace() + + if (str == null) { + return null; + } + int len = str.length(); + if (len == 0) { + return EMPTY_STRING_ARRAY; + } + List list = new ArrayList(); + int sizePlus1 = 1; + int i = 0, start = 0; + boolean match = false; + boolean lastMatch = false; + if (separatorChars == null) { + // Null separator means use whitespace + while (i < len) { + if (Character.isWhitespace(str.charAt(i))) { + if (match || preserveAllTokens) { + lastMatch = true; + if (sizePlus1++ == max) { + i = len; + lastMatch = false; + } + list.add(str.substring(start, i)); + match = false; + } + start = ++i; + continue; + } + lastMatch = false; + match = true; + i++; + } + } else if (separatorChars.length() == 1) { + // Optimise 1 character case + char sep = separatorChars.charAt(0); + while (i < len) { + if (str.charAt(i) == sep) { + if (match || preserveAllTokens) { + lastMatch = true; + if (sizePlus1++ == max) { + i = len; + lastMatch = false; + } + list.add(str.substring(start, i)); + match = false; + } + start = ++i; + continue; + } + lastMatch = false; + match = true; + i++; + } + } else { + // standard case + while (i < len) { + if (separatorChars.indexOf(str.charAt(i)) >= 0) { + if (match || preserveAllTokens) { + lastMatch = true; + if (sizePlus1++ == max) { + i = len; + lastMatch = false; + } + list.add(str.substring(start, i)); + match = false; + } + start = ++i; + continue; + } + lastMatch = false; + match = true; + i++; + } + } + if (match || (preserveAllTokens && lastMatch)) { + list.add(str.substring(start, i)); + } + return (String[]) list.toArray(new String[list.size()]); + } + + /** + * <p>Splits the provided text into an array, separators specified, + * preserving all tokens, including empty tokens created by adjacent + * separators. This is an alternative to using StringTokenizer.</p> + * + * <p>The separator is not included in the returned String array. + * Adjacent separators are treated as separators for empty tokens. + * For more control over the split use the StrTokenizer class.</p> + * + * <p>A <code>null</code> input String returns <code>null</code>. + * A <code>null</code> separatorChars splits on whitespace.</p> + * + * <pre> + * StringUtils.splitPreserveAllTokens(null, *) = null + * StringUtils.splitPreserveAllTokens("", *) = [] + * StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"] + * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"] + * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"] + * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] + * StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""] + * StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""] + * StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"] + * StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"] + * StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"] + * StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""] + * </pre> + * + * @param str the String to parse, may be <code>null</code> + * @param separatorChars the characters used as the delimiters, + * <code>null</code> splits on whitespace + * @return an array of parsed Strings, <code>null</code> if null String input + * @since 2.1 + */ + public static String[] splitPreserveAllTokens(String str, String separatorChars) { + return splitWorker(str, separatorChars, -1, true); + } + +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/C.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/C.java new file mode 100644 index 0000000..8156f69 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/C.java @@ -0,0 +1,15 @@ +package de.bjusystems.vdrmanager.app; + +/** + * + * Some constants + * @author lado + * + * + */ +public interface C { + + public static final String DATA_SEPARATOR = ":"; + + public static final long ONE_MINUTE_IN_MILLIS = 60 * 1000; +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java index 6f19f36..7029a53 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java @@ -6,9 +6,9 @@ import java.util.List; import android.app.Activity; import android.app.Application; import de.bjusystems.vdrmanager.data.Channel; -import de.bjusystems.vdrmanager.data.Epg; import de.bjusystems.vdrmanager.data.EpgSearchParams; import de.bjusystems.vdrmanager.data.Event; +import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.Timer; public class VdrManagerApp extends Application { @@ -42,8 +42,10 @@ public class VdrManagerApp extends Application { @Override public void onCreate() { super.onCreate(); + Preferences.loadPreferences(this); } + public void clear() { this.currentEvent = null; this.currentTimer = null; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java index eeda768..9cc8396 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java @@ -1,23 +1,37 @@ package de.bjusystems.vdrmanager.data; + +import de.bjusystems.vdrmanager.StringUtils; +import de.bjusystems.vdrmanager.app.C; + import android.os.Parcel; import android.os.Parcelable; public class Channel implements Parcelable { - private final int number; - private final String name; - private final String provider; + String id; + private int number; + private String name; + private String provider; + private String rawAudio; + + public String getRawAudio() { + return rawAudio; + } public Channel(final String channelData) { - String[] words = channelData.split(":"); + String[] words = StringUtils.splitPreserveAllTokens(channelData, C.DATA_SEPARATOR); this.number = Integer.valueOf(words[0].substring(1)); if (words.length > 2) { this.name = words[1]; this.provider = words[2]; + this.id = words[3]; + this.rawAudio = words[4]; } else { this.name = words[1]; + this.id = "-1"; this.provider = "Unknown"; + this.rawAudio = ""; } } @@ -25,12 +39,16 @@ public class Channel implements Parcelable { this.number = 0; this.name = "Unknown"; this.provider = "Unknown"; + this.id = "Uknwon"; + this.rawAudio = ""; } public Channel(Parcel in) { this.number = in.readInt(); this.name = in.readString(); this.provider = in.readString(); + this.id = in.readString(); + this.rawAudio = in.readString(); } public boolean isGroupSeparator() { @@ -68,6 +86,9 @@ public class Channel implements Parcelable { dest.writeInt(number); dest.writeString(name); dest.writeString(provider); + dest.writeString(id); + dest.writeString(rawAudio); + } public static final Parcelable.Creator<Channel> CREATOR = new Parcelable.Creator<Channel>() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java index 079fcf0..f9ca15a 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java @@ -2,6 +2,12 @@ package de.bjusystems.vdrmanager.data; import java.util.Date; + +import de.bjusystems.vdrmanager.StringUtils; +import de.bjusystems.vdrmanager.app.C; + +import static de.bjusystems.vdrmanager.gui.Utils.mapSpecialChars; + /** * Class for EPG events * @author bju @@ -11,14 +17,14 @@ public class Epg extends BaseEvent { private Timer timer; public Epg(final String line) { - final String[] words = line.split(":"); + final String[] words = StringUtils.splitPreserveAllTokens(line, C.DATA_SEPARATOR); channelNumber = words[0].substring(1); channelName = words[1]; start = new Date(Long.parseLong(words[2])*1000); stop = new Date(Long.parseLong(words[3])*1000); - title = words[4]; - description = words.length > 5 ? words[5] : ""; - shortText = words.length > 6 ? words[6] : ""; + title = mapSpecialChars(words[4]); + description = words.length > 5 ? mapSpecialChars(words[5]): ""; + shortText = words.length > 6 ? mapSpecialChars(words[6]) : ""; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java index 2570e67..9f4151f 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java @@ -1,17 +1,23 @@ package de.bjusystems.vdrmanager.data; +import java.util.Locale; + import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.text.TextUtils; import de.bjusystems.vdrmanager.R; /** * Class for all preferences * * @author bju, lado - * + * */ public class Preferences { + public static final String DEFAULT_LANGUAGE_VALUE = "DEFAULT"; + private boolean ssl; /** SVDRP host name or ip */ private String svdrpHost; @@ -81,12 +87,14 @@ public class Preferences { /** * Do not send broadcasts, send directly to the host (router problem) + * * @since 0.2 */ private String wolCustomBroadcast = ""; /** * Whether to show channel numbers in the overviews + * * @since 0.2 */ private boolean showChannelNumbers = false; @@ -95,45 +103,81 @@ public class Preferences { * Use remux ? */ private boolean enableRemux; - + /** * Remux command */ private String remuxCommand; - + /** - * Remux command Parameter + * Remux command Parameter */ private String remuxParameter; - + /** * Quits the app on back button */ - private boolean quiteOnBackButton = true; - - + private boolean quiteOnBackButton = true; + /** - * Show IMDB buttons, where possible (e.g. EPG Details) + * Show IMDB buttons, where possible (e.g. EPG Details) */ private boolean showImdbButton = true; - - + /** * On Which imdb site to search? */ - private String imdbUrl = "imdb.de"; + private String imdbUrl = "akas.imdb.com"; + + + /** + * Connection timeout + */ + private int connectionTimeout; + /** + * Read Timeout + */ + private int readTimeout; + + /** + * Timeout for a whole command run + */ + private int timeout; + + public int getConnectionTimeout() { + return connectionTimeout; + } + + public int getReadTimeout() { + return readTimeout; + } + + public int getTimeout() { + return timeout; + } + + public void setConnectionTimeout(int connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + public void setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + public String getImdbUrl() { return imdbUrl; } - public void setImdbUrl(String imdbUrl) { this.imdbUrl = imdbUrl; } - /** * @return whether to shwo imdb button */ @@ -144,10 +188,9 @@ public class Preferences { /** Properties singleton */ private static Preferences thePrefs; - /** - * Whether to send Packets to the custom broadcast address. - * It is used, if the address ist not empty + * Whether to send Packets to the custom broadcast address. It is used, if + * the address ist not empty * * @return * @since 0.2 @@ -156,7 +199,6 @@ public class Preferences { return wolCustomBroadcast; } - /** * Getter for use24hFormat * @@ -376,7 +418,7 @@ public class Preferences { editor.commit(); // reload - loadPreferences(context); + init(context); } /** @@ -390,48 +432,43 @@ public class Preferences { return context.getString(R.string.app_name); } - - - - /** * Show Channel Numbers in the overviews + * * @since 0.2 * @return */ public boolean isShowChannelNumbers() { return showChannelNumbers; } - - /** - * getter + * getter + * * @return */ public boolean isEnableRemux() { return enableRemux; } - /** * getter + * * @return */ public String getRemuxCommand() { return remuxCommand; } - /** * getter + * * @return */ public String getRemuxParameter() { return remuxParameter; } - /** * getter * @@ -441,7 +478,6 @@ public class Preferences { return quiteOnBackButton; } - /** * Gets the previous loaded preferences * @@ -450,30 +486,23 @@ public class Preferences { public static Preferences getPreferences() { return thePrefs; } - + /** * * Gets the previous loaded preferences, same as getPreferences(); * * @return */ - public static Preferences get(){ + public static Preferences get() { return thePrefs; } - /** - * Loads all preferences - * - * @param context - * Context - * @return Preferences - */ - public static void loadPreferences(final Context context) { + private static void initInternal(final Context context) { final Preferences prefs = new Preferences(); prefs.svdrpHost = getString(context, R.string.vdr_host_key, "0.0.0.0"); - prefs.svdrpPort = getInt(context, R.string.vdr_port_key, 6419); + prefs.svdrpPort = getInt(context, R.string.vdr_port_key, 6420); prefs.password = getString(context, R.string.vdr_password_key, ""); prefs.ssl = getBoolean(context, R.string.vdr_ssl_key, false); prefs.streamPort = getInt(context, R.string.vdr_stream_port, 3000); @@ -515,26 +544,64 @@ public class Preferences { prefs.use24hFormat = getBoolean(context, R.string.gui_enable_24h_format_key, true); - - prefs.wolCustomBroadcast = getString(context, R.string.wakeup_wol_custom_broadcast_key, ""); - prefs.showChannelNumbers = getBoolean(context, R.string.gui_channels_show_channel_numbers_key, false); - - prefs.enableRemux = getBoolean(context, R.string.key_remux_enable, false); - - prefs.remuxCommand =getString(context, R.string.key_remux_command, "EXT"); - - prefs.remuxParameter = getString(context, R.string.key_remux_parameter, ""); - - prefs.quiteOnBackButton = getBoolean(context, R.string.qui_quit_on_back_key, true); - - prefs.showImdbButton = getBoolean(context, R.string.qui_show_imdb_button_key, true); - + prefs.wolCustomBroadcast = getString(context, + R.string.wakeup_wol_custom_broadcast_key, ""); + + prefs.showChannelNumbers = getBoolean(context, + R.string.gui_channels_show_channel_numbers_key, false); + + prefs.enableRemux = getBoolean(context, R.string.key_remux_enable, + false); + + prefs.remuxCommand = getString(context, R.string.key_remux_command, + "EXT"); + + prefs.remuxParameter = getString(context, R.string.key_remux_parameter, + ""); + + prefs.quiteOnBackButton = getBoolean(context, + R.string.qui_quit_on_back_key, true); + + prefs.showImdbButton = getBoolean(context, + R.string.qui_show_imdb_button_key, true); + prefs.imdbUrl = getString(context, R.string.qui_imdb_url_key, "imdb.de"); + prefs.connectionTimeout = getInt(context, R.string.vdr_conntimeout_key, 10); + prefs.readTimeout = getInt(context, R.string.vdr_readtimeout_key, 10); + prefs.timeout = getInt(context, R.string.vdr_timeout_key, 120); + thePrefs = prefs; } + public static void reset(){ + thePrefs = null; + } + + /** + * Loads all preferences + * + * @param context + * Context + * @return Preferences + */ + public static void init(final Context context) { + +// if (thePrefs != null) { +// return; +// } + + synchronized (Preferences.class) { +// if (thePrefs != null) { +// return; +// } + initInternal(context); + setLocale(context); + } + + } + /** * Gets the persistent preferences * @@ -581,7 +648,6 @@ public class Preferences { return sharedPrefs.getBoolean(context.getString(resId), defValue); } - /** * Helper for retrieving string values from preferences * @@ -599,10 +665,30 @@ public class Preferences { return sharedPrefs.getString(context.getString(resId), defValue); } - public String getTimeFormat() { + public String getTimeFormat() { if (isUse24hFormat()) { return "HH:mm"; } return "h:mm a"; } + + /** + * Set locale read from preferences to context. + * + * @param context + * {@link Context} + */ + public static void setLocale(final Context context) { + String lc = getString(context, R.string.gui_custom_locale_key, DEFAULT_LANGUAGE_VALUE); + Locale locale; + if(lc.equals(DEFAULT_LANGUAGE_VALUE) == false){ + locale = new Locale(lc); + } else { + locale = new Locale(""); + } + Locale.setDefault(locale); + final Configuration config = new Configuration(); + config.locale = locale; + context.getResources().updateConfiguration(config, null); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java index 75fe9af..378ec00 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java @@ -3,19 +3,24 @@ package de.bjusystems.vdrmanager.data; import java.util.Date; +import de.bjusystems.vdrmanager.StringUtils; +import de.bjusystems.vdrmanager.app.C; + +import static de.bjusystems.vdrmanager.gui.Utils.mapSpecialChars; + public class Recording extends BaseEvent{ public Recording(String line) { - final String[] words = line.split(":"); + final String[] words = StringUtils.splitPreserveAllTokens(line, C.DATA_SEPARATOR); int idx = 0; index = Integer.valueOf(words[idx++]); start = new Date(Long.parseLong(words[idx++]) * 1000); stop = new Date(Long.parseLong(words[idx++]) * 1000); - channelName = words[idx++]; - title = words[idx++]; - shortText = words[idx++]; - description = words[idx++]; - fileName = words[idx++]; + channelName = mapSpecialChars(words[idx++]); + title = mapSpecialChars(words[idx++]); + shortText = mapSpecialChars(words[idx++]); + description = mapSpecialChars(words[idx++]); + fileName = mapSpecialChars(words[idx++]); fileSize = Integer.valueOf(words[idx++]); } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java index d357d5a..fb79fde 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java @@ -4,10 +4,15 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; + +import de.bjusystems.vdrmanager.StringUtils; +import de.bjusystems.vdrmanager.app.C; +import de.bjusystems.vdrmanager.gui.Utils; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; /** * Class for timer data + * * @author bju */ public class Timer extends BaseEvent { @@ -22,15 +27,18 @@ public class Timer extends BaseEvent { private final int priority; private final int lifetime; - /** * Constructs a timer from SvdrpHelper result line - * @param timerData result line - * @param channels list of channels + * + * @param timerData + * result line + * @param channels + * list of channels */ public Timer(final String timerData) { - final String[] values = timerData.split(":"); + final String[] values = StringUtils.splitPreserveAllTokens(timerData, + C.DATA_SEPARATOR); // number this.number = Integer.valueOf(values[0].substring(1)); @@ -38,7 +46,7 @@ public class Timer extends BaseEvent { // flags, channel number and channel name this.flags = Integer.valueOf(values[1]); this.channelNumber = values[2]; - this.channelName = values[3]; + this.channelName = Utils.mapSpecialChars(values[3]); // get start and stop this.start = new Date(Long.parseLong(values[4]) * 1000); @@ -49,17 +57,19 @@ public class Timer extends BaseEvent { this.lifetime = Integer.valueOf(values[7]); // title and description - this.title = values[8]; - - this.description = values.length > 9 ? values[9] : ""; - - this.shortText = values.length > 10 ? values[10] : ""; - - if(values.length > 11){ - this.description = values[11]; + this.title = Utils.mapSpecialChars(values[8]); + + this.description = values.length > 9 ? values[9] : "";// aux + + // 10 and 11 are optional if there where event with this timer + this.shortText = values.length > 10 ? Utils + .mapSpecialChars(values[10]) : ""; + + if (values.length > 11) { + this.description = values[11]; // if real description, set it } - - + + description = Utils.mapSpecialChars(description); } public Timer(final Event event) { @@ -72,8 +82,10 @@ public class Timer extends BaseEvent { this.priority = prefs.getTimerDefaultPriority(); this.lifetime = prefs.getTimerDefaultLifetime(); - this.start = new Date(event.getStart().getTime() - prefs.getTimerPreMargin() * 60000); - this.stop = new Date(event.getStop().getTime() + prefs.getTimerPostMargin() * 60000); + this.start = new Date(event.getStart().getTime() + - prefs.getTimerPreMargin() * 60000); + this.stop = new Date(event.getStop().getTime() + + prefs.getTimerPostMargin() * 60000); this.title = event.getTitle(); this.description = event.getDescription(); @@ -89,26 +101,25 @@ public class Timer extends BaseEvent { final Calendar cal = new GregorianCalendar(); cal.setTime(start); - line.append(String.format("%04d-%02d-%02d:", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH))); - line.append(String.format("%02d%02d:", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE))); + line.append(String.format("%04d-%02d-%02d:", cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))); + line.append(String.format("%02d%02d:", cal.get(Calendar.HOUR_OF_DAY), + cal.get(Calendar.MINUTE))); cal.setTime(stop); - line.append(String.format("%02d%02d:", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE))); + line.append(String.format("%02d%02d:", cal.get(Calendar.HOUR_OF_DAY), + cal.get(Calendar.MINUTE))); line.append(priority).append(":"); line.append(lifetime).append(":"); - line.append(title).append(":"); - if(op != TimerOperation.DELETE){ - line.append(description); - } - + line.append(Utils.unMapSpecialChars(title)); return line.toString(); } public int getNumber() { return number; } - + public int getPriority() { return priority; } @@ -138,6 +149,7 @@ public class Timer extends BaseEvent { public boolean isVps() { return (flags & VPS) == VPS; } + public boolean isRecording() { return (flags & RECORDING) == RECORDING; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java index 629f2a6..5e2e49c 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java @@ -1,48 +1,70 @@ package de.bjusystems.vdrmanager.gui; -import de.bjusystems.vdrmanager.R; -import de.bjusystems.vdrmanager.app.VdrManagerApp; -import de.bjusystems.vdrmanager.data.Channel; import android.app.Activity; +import android.app.AlertDialog; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; +import android.widget.ListView; +import android.widget.Toast; +import android.widget.ViewFlipper; +import de.bjusystems.vdrmanager.R; +import de.bjusystems.vdrmanager.app.VdrManagerApp; +import de.bjusystems.vdrmanager.data.Channel; +import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; -public abstract class BaseActivity extends Activity implements OnClickListener{ - +public abstract class BaseActivity<T extends ListView> extends Activity + implements OnClickListener { public static final int MENU_GROUP_REFRESH = 99; - + public static final int MENU_REFRESH = 99; + + protected T listView; + protected ViewFlipper flipper; + + protected SvdrpProgressDialog progress; + abstract protected int getMainLayout(); - - protected void switchNoConnection(){ + + public void svdrpException(final SvdrpException exception) { + // Log.w(TAG, exception); + alert(getString(R.string.vdr_error_text, exception.getMessage())); + } + + protected void switchNoConnection() { View view = findViewById(R.id.main_content); - if(view != null){ + if (view != null) { view.setVisibility(View.GONE); } - findViewById(R.id.no_connection_layout).setVisibility(View.VISIBLE); - Button b = (Button) findViewById(R.id.retry_button); + view = findViewById(R.id.no_connection_layout); + if (view != null) { + view.setVisibility(View.VISIBLE); + } + Button b = (Button) findViewById(R.id.retry_button); b.setOnClickListener(this); } public void onClick(View v) { - if(v.getId() == R.id.retry_button){ - findViewById(R.id.no_connection_layout).setVisibility(View.GONE); - View view = findViewById(R.id.main_content); - if(view != null){ + if (v.getId() == R.id.retry_button) { + View view = findViewById(R.id.no_connection_layout); + if (view != null) { + view.setVisibility(View.GONE); + } + view = findViewById(R.id.main_content); + if (view != null) { view.setVisibility(View.VISIBLE); } retry(); } } - + protected void updateWindowTitle(int topic, int subtopic) { String title; - title = getString(topic); + title = getString(topic); if (subtopic != -1) { title += " > " + getString(subtopic); } @@ -57,7 +79,6 @@ public abstract class BaseActivity extends Activity implements OnClickListener{ setTitle(title); } - @Override public boolean onCreateOptionsMenu(final Menu menu) { MenuItem item; @@ -66,40 +87,69 @@ public abstract class BaseActivity extends Activity implements OnClickListener{ item.setAlphabeticShortcut('r'); return true; } - - abstract protected void refresh(); - - abstract protected void retry(); - + + abstract protected void refresh(); + + abstract protected void retry(); + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_REFRESH: + backupViewSelection(); refresh(); return true; - default: return false; } } - protected void setAsCurrent(Channel channel) { getApp().setCurrentChannel(channel); } - - protected VdrManagerApp getApp(){ + protected VdrManagerApp getApp() { final VdrManagerApp app = (VdrManagerApp) getApplication(); return app; } - - //protected Channel getCurrentChannel(){ - //final Channel channel = ((VdrManagerApp) getApplication()) - //.getCurrentChannel(); - //return channel; -// } - - + // protected Channel getCurrentChannel(){ + // final Channel channel = ((VdrManagerApp) getApplication()) + // .getCurrentChannel(); + // return channel; + // } + + protected void say(int res) { + Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); + } + + protected void say(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + protected void alert(String msg) { + new AlertDialog.Builder(this)// + .setMessage(msg)// + .setPositiveButton(android.R.string.ok, null)// + .create()// + .show();// + } + + protected void alert(int resId) { + alert(getString(resId)); + } + + protected void restoreViewSelection() { + listView.setSelectionFromTop(index, top); + } + + protected void backupViewSelection() { + index = listView.getFirstVisiblePosition(); + View v = listView.getChildAt(0); + top = (v == null) ? 0 : v.getTop(); + } + + int index; + int top; + } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java index e8dd66b..7174803 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java @@ -10,6 +10,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; @@ -21,7 +22,6 @@ import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; -import android.widget.Toast; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.app.Intents; import de.bjusystems.vdrmanager.data.Channel; @@ -38,8 +38,10 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; * */ public abstract class BaseEventListActivity<T extends Event> extends - BaseActivity implements OnItemClickListener, SvdrpAsyncListener<T>, - SimpleGestureListener { + BaseActivity<ListView> implements OnItemClickListener, + SvdrpAsyncListener<T>, SimpleGestureListener { + + public static final String TAG = BaseEventListActivity.class.getName(); public static final int MENU_GROUP_SHARE = 90; @@ -51,8 +53,6 @@ public abstract class BaseEventListActivity<T extends Event> extends protected EventAdapter adapter; - protected SvdrpProgressDialog progress; - protected String highlight = null; protected static final Date FUTURE = new Date(Long.MAX_VALUE); @@ -61,8 +61,6 @@ public abstract class BaseEventListActivity<T extends Event> extends protected Channel currentChannel = null; - protected ListView listView; - abstract protected int getWindowTitle(); protected List<Event> results = new ArrayList<Event>(); @@ -82,6 +80,16 @@ public abstract class BaseEventListActivity<T extends Event> extends .getParcelableExtra(Intents.CURRENT_CHANNEL); } + private boolean refreshViewOnResume = false; + + @Override + protected void onResume() { + super.onResume(); + if (refreshViewOnResume) { + adapter.notifyDataSetChanged(); + } + } + /* * (non-Javadoc) * @@ -130,7 +138,7 @@ public abstract class BaseEventListActivity<T extends Event> extends return super.onContextItemSelected(item); } - return true; + return true; } /* @@ -167,7 +175,6 @@ public abstract class BaseEventListActivity<T extends Event> extends @Override public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); // if (v.getId() == R.id.whatson_list) { final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; @@ -175,12 +182,14 @@ public abstract class BaseEventListActivity<T extends Event> extends // set menu title final EventListItem item = adapter.getItem(info.position); + MenuItem mi = menu.findItem(R.id.epg_item_menu_live_tv); if (item.isLive()) { - menu.findItem(R.id.epg_item_menu_live_tv).setVisible(true); + mi.setVisible(true); + } else { + mi.setVisible(false); } - menu.add(MENU_GROUP_SHARE, MENU_SHARE, 0, R.string.share); - // } + super.onCreateContextMenu(menu, v, menuInfo); } @@ -217,40 +226,48 @@ public abstract class BaseEventListActivity<T extends Event> extends @Override protected void onPause() { super.onPause(); - if (epgClient != null) { - epgClient.abort(); - } - if (progress != null) { - progress.dismiss(); - progress = null; - } + refreshViewOnResume = true; + // if (epgClient != null) { + // epgClient.abort(); + // } + // if (progress != null) { + // progress.dismiss(); + // progress = null; + // } } public void svdrpEvent(final SvdrpEvent event, final T result) { - if (progress != null) { - progress.svdrpEvent(event); - } - switch (event) { - case ERROR: - Toast.makeText(this, R.string.epg_client_errors, Toast.LENGTH_SHORT) - .show(); - dismiss(progress); + case ABORTED: + alert(R.string.aborted); break; - case CONNECTING: + case ERROR: + alert(R.string.epg_client_errors); + // say(R.string.epg_client_errors); + // dismiss(progress); break; + // case CONNECTING: + // break; case CONNECTED: results.clear(); break; case CONNECT_ERROR: + say(R.string.progress_connect_error); + switchNoConnection(); + break; case FINISHED_ABNORMALY: + alert(R.string.progress_connect_finished_abnormal); + switchNoConnection(); + break; case LOGIN_ERROR: switchNoConnection(); break; case FINISHED_SUCCESS: if (finishedSuccess() == false) { say(R.string.epg_no_items); + } else { + restoreViewSelection(); } break; case RESULT_RECEIVED: @@ -263,24 +280,23 @@ public abstract class BaseEventListActivity<T extends Event> extends results.add(result); } - // - // @Override - // protected void onRestoreInstanceState(Bundle savedInstanceState) { - // super.onRestoreInstanceState(savedInstanceState); - // int index = savedInstanceState.getInt("INDEX"); - // int top = savedInstanceState.getInt("TOP"); - // listView.setSelectionFromTop(index, top); - // } - // - // @Override - // protected void onSaveInstanceState(Bundle outState) { - // int index = listView.getFirstVisiblePosition(); - // View v = listView.getChildAt(0); - // int top = (v == null) ? 0 : v.getTop(); - // outState.putInt("INDEX", index); - // outState.putInt("TOP", top); - // super.onSaveInstanceState(outState); - // } + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + int index = savedInstanceState.getInt("INDEX"); + int top = savedInstanceState.getInt("TOP"); + listView.setSelectionFromTop(index, top); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + int index = listView.getFirstVisiblePosition(); + View v = listView.getChildAt(0); + int top = (v == null) ? 0 : v.getTop(); + outState.putInt("INDEX", index); + outState.putInt("TOP", top); + super.onSaveInstanceState(outState); + } protected void dismiss(AlertDialog dialog) { if (dialog == null) { @@ -346,17 +362,8 @@ public abstract class BaseEventListActivity<T extends Event> extends } public void svdrpException(final SvdrpException exception) { - if (progress != null) { - progress.svdrpException(exception); - } - } - - protected void say(int res) { - Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); - } - - protected void say(String msg) { - Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + Log.w(TAG, exception); + alert(getString(R.string.vdr_error_text, exception.getMessage())); } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java index c4fc5fd..55cc468 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java @@ -21,7 +21,6 @@ import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; import de.bjusystems.vdrmanager.R; -import de.bjusystems.vdrmanager.data.Epg; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventFormatter; import de.bjusystems.vdrmanager.data.EventListItem; @@ -30,7 +29,6 @@ import de.bjusystems.vdrmanager.tasks.CreateTimerTask; import de.bjusystems.vdrmanager.tasks.DeleteTimerTask; import de.bjusystems.vdrmanager.tasks.ModifyTimerTask; import de.bjusystems.vdrmanager.tasks.ToggleTimerTask; -import de.bjusystems.vdrmanager.utils.date.DateFormatter; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; public abstract class BaseTimerEditActivity<T extends Event> extends @@ -64,24 +62,25 @@ public abstract class BaseTimerEditActivity<T extends Event> extends case CREATE: tView.modifyButton.setVisibility(View.GONE); tView.saveButton.setVisibility(View.VISIBLE); - tView.saveButton.setText(R.string.timer_details_save_title); + tView.saveButton.setText(R.string.timer_details_create_title); break; case MODIFY: tView.saveButton.setVisibility(View.GONE); tView.modifyButton.setVisibility(View.VISIBLE); + tView.saveButton.setText(R.string.timer_details_save_title); + break; } } private void updateDisplay() { - final DateFormatter dateFormatter = new DateFormatter(timer.getStart()); + EventFormatter f = new EventFormatter(timer,true); tView.channel.setText(timer.getChannelNumber() + " " + timer.getChannelName()); - tView.title.setText(timer.getTitle()); - tView.dateField.setText(dateFormatter.getDateString()); - tView.startField.setText(dateFormatter.getTimeString()); - tView.endField.setText(new DateFormatter(timer.getStop()) - .getTimeString()); + tView.title.setText(f.getTitle()); + tView.dateField.setText(f.getDate()); + tView.startField.setText(f.getTime()); + tView.endField.setText(f.getStop()); } protected Timer getTimer(EventListItem item) { @@ -258,38 +257,44 @@ public abstract class BaseTimerEditActivity<T extends Event> extends say(R.string.done); break; } + + default: + super.onClick(view); } } private void modifyTimer(Timer timer) { + backupViewSelection(); final ModifyTimerTask task = new ModifyTimerTask(this, timer) { @Override public void finished() { refresh(); - say(R.string.done); + //say(R.string.done); } }; task.start(); } protected void deleteTimer(final Timer timer) { - + backupViewSelection(); final DeleteTimerTask task = new DeleteTimerTask(this, timer) { @Override public void finished() { refresh(); - say(R.string.done); + restoreViewSelection(); + //say(R.string.done); } }; task.start(); } private void createTimer(Timer timer) { + backupViewSelection(); final CreateTimerTask task = new CreateTimerTask(this, timer) { @Override public void finished() { refresh(); - say(R.string.done); + //say(R.string.done); } }; task.start(); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java index 7c0ff05..fff74a9 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java @@ -2,14 +2,10 @@ package de.bjusystems.vdrmanager.gui; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import android.content.Context; import android.graphics.Color; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.TextUtils; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java index a2249b9..1c2c4ff 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java @@ -3,15 +3,12 @@ package de.bjusystems.vdrmanager.gui; import java.util.ArrayList; import java.util.HashMap; -import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; +import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; @@ -19,15 +16,12 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; -import android.widget.ArrayAdapter; -import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.ExpandableListView.ExpandableListContextMenuInfo; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ExpandableListView.OnGroupClickListener; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.app.Intents; -import de.bjusystems.vdrmanager.app.VdrManagerApp; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; @@ -42,14 +36,16 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; * * @author bju */ -public class ChannelListActivity extends BaseActivity implements +public class ChannelListActivity extends BaseActivity<ExpandableListView> implements OnChildClickListener, OnGroupClickListener, SvdrpAsyncListener<Channel> { + private static final String TAG = ChannelListActivity.class.getName(); ChannelClient channelClient; + ChannelAdapter adapter; + Preferences prefs; - SvdrpProgressDialog progress; - + public static final int MENU_GROUP = 0; public static final int MENU_PROVIDER = 1; public static final int MENU_NAME = 2; @@ -59,7 +55,7 @@ public class ChannelListActivity extends BaseActivity implements final static ArrayList<String> ALL_CHANNELS_GROUP = new ArrayList<String>( 1); - ExpandableListView listView; + //ExpandableListView listView; // @Override // public boolean onKeyLongPress(int keyCode, KeyEvent event) { @@ -79,6 +75,12 @@ public class ChannelListActivity extends BaseActivity implements // return super.onKeyUp(keyCode, event); // } // + + @Override + protected void onResume() { + super.onResume(); + } + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -106,27 +108,12 @@ public class ChannelListActivity extends BaseActivity implements // @Override - protected void onResume() { - super.onResume(); - - } - - @Override protected void onPause() { super.onPause(); - if (channelClient != null) { - channelClient.abort(); - } - if (progress != null) { - progress.dismiss(); - progress = null; - } - if (groupByDialog != null) { - groupByDialog.dismiss(); - } } private void startChannelQuery() { + backupViewSelection(); startChannelQuery(true); } @@ -140,10 +127,11 @@ public class ChannelListActivity extends BaseActivity implements channelClient); // create progress - progress = new SvdrpProgressDialog(this, channelClient); + progress = new SvdrpProgressDialog<Channel>(this, channelClient); // attach listener task.addListener(this); + task.addListener(progress); // start task task.run(); @@ -152,20 +140,24 @@ public class ChannelListActivity extends BaseActivity implements private void fillAdapter() { switch (groupBy) { case MENU_GROUP: - adapter.fill( - channelClient.getChannelGroups(), - channelClient.getGroupChannels(), groupBy); - listView.collapseGroup(0); + ArrayList<String> cgs = channelClient.getChannelGroups(); + adapter.fill(cgs, channelClient.getGroupChannels(), groupBy); + if(cgs.size() == 1){ + listView.expandGroup(0); + } updateWindowTitle( getString(R.string.action_menu_channels), getString(R.string.groupby_window_title_templte, getString(R.string.groupby_group))); break; case MENU_PROVIDER: - adapter.fill(new ArrayList<String>(channelClient - .getProviderChannels().keySet()), channelClient + ArrayList<String> gs = new ArrayList<String>(channelClient + .getProviderChannels().keySet()); + adapter.fill(gs, channelClient .getProviderChannels(), groupBy); - listView.collapseGroup(0); + if(gs.size() == 1){ + listView.expandGroup(0); + } updateWindowTitle( getString(R.string.action_menu_channels), getString(R.string.groupby_window_title_templte, @@ -190,36 +182,47 @@ public class ChannelListActivity extends BaseActivity implements } public void svdrpEvent(final SvdrpEvent event, final Channel result) { - - if (progress != null) { - progress.svdrpEvent(event); - } - switch (event) { + case ABORTED: + say(R.string.aborted); + break; + case ERROR: + say(R.string.epg_client_errors); + break; case CONNECTING: break; case CONNECT_ERROR: + say(R.string.progress_connect_error); + switchNoConnection(); + break; + case FINISHED_ABNORMALY: + say(R.string.progress_connect_finished_abnormal); switchNoConnection(); break; case LOGIN_ERROR: switchNoConnection(); break; - case FINISHED_SUCCESS: case CACHE_HIT: + say(R.string.progress_cache_hit); fillAdapter(); + restoreViewSelection(); break; - case FINISHED_ABNORMALY: - switchNoConnection(); + case FINISHED_SUCCESS: + fillAdapter(); + restoreViewSelection(); break; + } } + public void svdrpException(final SvdrpException exception) { - if (progress != null) { - progress.svdrpException(exception); - } + progress.svdrpException(exception); + Log.w(TAG, exception); + alert(getString(R.string.vdr_error_text, exception.getMessage())); } + public boolean onPrepareOptionsMenu(Menu menu) { return super.onPrepareOptionsMenu(menu); @@ -420,12 +423,13 @@ public class ChannelListActivity extends BaseActivity implements @Override protected void refresh() { + backupViewSelection(); startChannelQuery(false); } @Override protected void retry() { - startChannelQuery(false); + refresh(); } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java index ca492d5..40d54fe 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java @@ -44,7 +44,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; public class EpgDetailsActivity extends Activity implements OnClickListener, SimpleGestureListener { - public static String IMDB_URL = "http://www.%s/find?s=all&q=%s"; + public static String IMDB_URL = "http://%s/find?s=all&q=%s"; private SimpleGestureFilter detector; @@ -61,6 +61,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, super.onCreate(savedInstanceState); Intent i = getIntent(); + highlight = i.getStringExtra(Intents.HIGHLIGHT); // Attach view @@ -84,29 +85,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, counter++; } - new AsyncTask<Void, Void, Void>() { - - protected void onPreExecute() { - // event_left.setEnabled(false); - // event_right.setEnabled(false); - }; - - protected Void doInBackground(Void... params) { - initEPGs(); - return null; - }; - - protected void onPostExecute(Void result) { - // event_left.setEnabled(true); - // event_right.setEnabled(true); - }; - - }.execute((Void) null); - publishEPG(epg); - - // TODO was ist das? - app.clearActivitiesToFinish(); } private void setState(ImageView view, int res) { @@ -280,9 +259,10 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, } - List<Event> epgs = null; + List<Event> epgs = new ArrayList<Event>(); + int counter = 0; - +/* public void initEPGs() { if (epgs != null) { @@ -323,7 +303,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, ; } } - +*/ private void nextEPG() { if (counter < epgs.size() - 1) { counter++; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java index 85aae19..3ff0df2 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java @@ -1,7 +1,6 @@ package de.bjusystems.vdrmanager.gui; import java.util.Calendar; -import java.util.List; import android.app.SearchManager; import android.content.Intent; @@ -16,56 +15,66 @@ import de.bjusystems.vdrmanager.data.Epg; import de.bjusystems.vdrmanager.data.EpgSearchParams; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventListItem; +import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.utils.date.DateFormatter; import de.bjusystems.vdrmanager.utils.svdrp.EpgClient; 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.SvdrpException; /** * This class is used for showing what's current running on all channels * * @author bju */ -public class EpgSearchListActivity extends BaseEventListActivity<Epg> implements +public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements OnItemClickListener, SvdrpAsyncListener<Epg> { - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent intent = getIntent(); + private void initSearch(Intent intent){ if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); if (TextUtils.isEmpty(query) == false) { highlight = query.trim(); } } - adapter = new TimeEventAdapter(this); - adapter.setHideDescription(false); + } + + + @Override + protected void onNewIntent(Intent intent) { + initSearch(intent); + startSearch(); + } + + + private void startSearch(){ startEpgQuery(); + } + @Override + protected void onCreate(final Bundle savedInstanceState) { + + Preferences.init(this); + + super.onCreate(savedInstanceState); + + + Intent intent = getIntent(); + initSearch(intent); + adapter = new TimeEventAdapter(this); + // Create adapter for EPG list + adapter.setHideDescription(false); listView = (ListView) findViewById(R.id.whatson_list); listView.setAdapter(adapter); - listView.setFastScrollEnabled(true); listView.setTextFilterEnabled(true); registerForContextMenu(listView); - // register EPG item click listView.setOnItemClickListener(this); - - } - - @Override - protected void onResume() { - super.onResume(); - // adapter.notifyDataSetChanged(); - + startSearch(); } - public void onNothingSelected(final AdapterView<?> arg0) { // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); } @@ -78,7 +87,7 @@ public class EpgSearchListActivity extends BaseEventListActivity<Epg> implements sp.setTitle(highlight); setTitle(getString(R.string.epg_by_search_param, highlight)); epgClient = new EpgClient(sp); - + epgClient.setResultInfoEnabled(true); // remove old listeners // epgClient.clearSvdrpListener(); @@ -87,8 +96,9 @@ public class EpgSearchListActivity extends BaseEventListActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog(this, epgClient); + progress = new SvdrpProgressDialog<Epg>(this, epgClient); // attach listener + task.addListener(progress); task.addListener(this); // start task @@ -126,13 +136,6 @@ public class EpgSearchListActivity extends BaseEventListActivity<Epg> implements return results.isEmpty() == false; } - - - public void svdrpException(final SvdrpException exception) { - if (progress != null) { - progress.svdrpException(exception); - } - } protected void prepareTimer(final EventListItem item) { final VdrManagerApp app = (VdrManagerApp) getApplication(); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java index 3f7fc4d..96e2e7e 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java @@ -12,7 +12,6 @@ import android.widget.ArrayAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.ImageView; -import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import de.bjusystems.vdrmanager.R; @@ -23,6 +22,8 @@ import de.bjusystems.vdrmanager.data.EventListItem; abstract class EventAdapter extends ArrayAdapter<EventListItem> implements Filterable { + private final int TYPE_ITEM = 0; + private final int TYPE_HEADER = 1; protected final int layout; protected final LayoutInflater inflater; protected final List<EventListItem> items = new ArrayList<EventListItem>(); @@ -39,8 +40,10 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements inflater = LayoutInflater.from(context); } - - + @Override + public int getViewTypeCount() { + return 2; + } @Override public void add(EventListItem object) { @@ -49,78 +52,103 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements } @Override - public View getView(final int position, final View convertView, - final ViewGroup parent) { + public int getItemViewType(int position) { // get item final EventListItem item = getItem(position); if (item.isHeader()) { - return getHeaderView(item, convertView, parent); + return TYPE_HEADER; + } + return TYPE_ITEM; + } + + @Override + public View getView(final int position, View convertView, + final ViewGroup parent) { + + // get item + final EventListItem item = getItem(position); + + Object holder = null; + int type = getItemViewType(position); + if (convertView == null) { + switch (type) { + case TYPE_ITEM: + convertView = inflater.inflate(layout, null); + holder = getEventViewHolder(item, convertView); + break; + case TYPE_HEADER: + convertView = inflater.inflate(R.layout.header_item, null); + holder = getHeaderViewHolder(item, convertView); + break; + } + convertView.setTag(holder); } else { - return getEventView(item, convertView, parent); + holder = convertView.getTag(); } + switch (type) { + case TYPE_ITEM: + convertView = inflater.inflate(layout, null); + holder = getEventViewHolder(item, convertView); + break; + case TYPE_HEADER: + convertView = inflater.inflate(R.layout.header_item, null); + holder = getHeaderViewHolder(item, convertView); + break; + } + + if (type == TYPE_ITEM) { + fillEventViewHolder((EventListItemHolder) holder, item); + } else { + ((EventListItemHeaderHolder) holder).header.setText(item + .getHeader()); + } + return convertView; } - private View getEventView(EventListItem item, View convertView, - ViewGroup parent) { + private EventListItemHolder getEventViewHolder(EventListItem item, View view) { EventListItemHolder itemHolder = new EventListItemHolder(); - // recycle view? - View view = convertView; - if (view == null || view instanceof ListView == false) { - view = inflater.inflate(layout, null); - - itemHolder = new EventListItemHolder(); - - itemHolder.state = (ImageView) view - .findViewById(R.id.timer_item_state); - itemHolder.time = (TextView) view - .findViewById(R.id.timer_item_time); - itemHolder.channel = (TextView) view - .findViewById(R.id.timer_item_channel); - itemHolder.title = (TextView) view - .findViewById(R.id.timer_item_title); - itemHolder.progress = (ProgressBar) view - .findViewById(R.id.timer_progress); - itemHolder.shortText = (TextView) view - .findViewById(R.id.timer_item_shorttext); - itemHolder.duration = (TextView) view - .findViewById(R.id.timer_item_duration); - itemHolder.description = (TextView) view - .findViewById(R.id.event_item_description); - view.setTag(itemHolder); - } else { - itemHolder = (EventListItemHolder) view.getTag(); - } + itemHolder = new EventListItemHolder(); + + itemHolder.state = (ImageView) view.findViewById(R.id.timer_item_state); + itemHolder.time = (TextView) view.findViewById(R.id.timer_item_time); + itemHolder.channel = (TextView) view + .findViewById(R.id.timer_item_channel); + itemHolder.title = (TextView) view.findViewById(R.id.timer_item_title); + itemHolder.progress = (ProgressBar) view + .findViewById(R.id.timer_progress); + itemHolder.shortText = (TextView) view + .findViewById(R.id.timer_item_shorttext); + itemHolder.duration = (TextView) view + .findViewById(R.id.timer_item_duration); + itemHolder.description = (TextView) view + .findViewById(R.id.event_item_description); + return itemHolder; + } + public void fillEventViewHolder(EventListItemHolder itemHolder, + EventListItem item) { -// itemHolder.title.setVisibility(View.VISIBLE); itemHolder.state.setVisibility(View.VISIBLE); - //itemHolder.shortText.setVisibility(View.VISIBLE); - //itemHolder.duration.setVisibility(View.VISIBLE); - // itemHolder.state.setVisibility(View.); switch (item.getTimerState()) { case Active: - //itemHolder.state.setVisibility(View.VISIBLE); itemHolder.state.setImageResource(R.drawable.timer_active); break; case Inactive: - //itemHolder.state.setVisibility(View.VISIBLE); itemHolder.state.setImageResource(R.drawable.timer_inactive); break; case Recording: - //itemHolder.state.setVisibility(View.VISIBLE); itemHolder.state.setImageResource(R.drawable.timer_recording); break; case None: - //itemHolder.state.setVisibility(View.GONE); itemHolder.state.setImageResource(R.drawable.timer_none); break; } - + final EventFormatter formatter = getEventFormatter(item); itemHolder.time.setText(formatter.getTime()); if (hideChannelName) { @@ -147,49 +175,28 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements int p = Utils.getProgress(item); if (p == -1) { itemHolder.progress.setVisibility(View.GONE); - // itemHolder.time.setTypeface(null, Typeface.NORMAL); - // itemHolder.title.setTypeface(null, Typeface.NORMAL); - // itemHolder.shortText.setTypeface(null, Typeface.NORMAL); int dura = Utils.getDuration(item); itemHolder.duration.setText(getContext().getString( R.string.epg_duration_template, dura)); } else { itemHolder.progress.setVisibility(View.VISIBLE); itemHolder.progress.setProgress(p); - // itemHolder.time.setTypeface(null, Typeface.BOLD); - // itemHolder.title.setTypeface(null, Typeface.BOLD); - // itemHolder.shortText.setTypeface(null, Typeface.BOLD); int dura = Utils.getDuration(item); int rest = dura - (dura * p / 100); itemHolder.duration.setText(getContext().getString( R.string.epg_duration_template_live, rest, dura)); } - - return view; } class EventListItemHeaderHolder { public TextView header; } - private View getHeaderView(EventListItem item, View convertView, - ViewGroup parent) { - + private EventListItemHeaderHolder getHeaderViewHolder(EventListItem item, + View view) { EventListItemHeaderHolder itemHolder = new EventListItemHeaderHolder(); - - // recycle view? - View view = convertView; - if (view == null || convertView instanceof TextView == false) { - view = inflater.inflate(R.layout.header_item, null); - - itemHolder = new EventListItemHeaderHolder(); - - itemHolder.header = (TextView) view.findViewById(R.id.header_item); - } else { - itemHolder = (EventListItemHeaderHolder) view.getTag(); - } - itemHolder.header.setText(item.getHeader()); - return view; + itemHolder.header = (TextView) view.findViewById(R.id.header_item); + return itemHolder; } protected EventFormatter getEventFormatter(Event event) { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java index f481244..257eea5 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java @@ -77,7 +77,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements // Create adapter for EPG list listView = (ListView) findViewById(R.id.whatson_list); listView.setAdapter(adapter); - listView.setFastScrollEnabled(true); + //listView.setFastScrollEnabled(true); listView.setTextFilterEnabled(true); registerForContextMenu(listView); @@ -86,12 +86,6 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements } - @Override - protected void onResume() { - super.onResume(); - // adapter.notifyDataSetChanged(); - // startEpgQuery(); - } public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { @@ -171,10 +165,12 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog(this, epgClient); + progress = new SvdrpProgressDialog<Epg>(this, epgClient); // attach listener + task.addListener(progress); task.addListener(this); + // start task task.run(); } @@ -208,7 +204,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements } } cachedChannel = currentChannel; - listView.setSelectionAfterHeaderView(); + //listView.setSelectionAfterHeaderView(); dismiss(progress); return CACHE.isEmpty() == false; } @@ -252,8 +248,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements private void prevEvent() { int pos = channelSpinner.getSelectedItemPosition(); if (pos <= 0) { - Toast.makeText(this, R.string.navigae_at_the_start, - Toast.LENGTH_SHORT).show(); + say(R.string.navigae_at_the_start); return; } channelSpinner.setSelection(pos - 1, true); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java index dfffc0c..d741004 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; +import android.preference.DialogPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; @@ -12,6 +13,9 @@ import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; +import android.text.TextUtils; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.app.VdrManagerApp; import de.bjusystems.vdrmanager.data.Preferences; @@ -134,7 +138,9 @@ public class PreferencesActivity extends PreferenceActivity implements updateChildPreferences(); Preference p = findPreference(key); updateSummary(p); - Preferences.loadPreferences(this); + //Preferences.reset(); + Preferences.init(this); + //Preferences.setLocale(getBaseContext()); } public boolean onPreferenceChange(Preference arg0, Object arg1) { @@ -183,7 +189,22 @@ public class PreferencesActivity extends PreferenceActivity implements if (text == null) { return; } + + if(isPassword(ep.getEditText())){ + text = text.replaceAll(".", "*"); + } + + setSummary(text, ep); + } + private boolean isPassword(EditText et){ + if((et.getInputType() & EditorInfo.TYPE_TEXT_VARIATION_PASSWORD) == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD){ + return true; + } + return false; + } + + private void setSummary(CharSequence text, DialogPreference ep){ CharSequence sm = ep.getSummary(); String sum; if (sm != null) { @@ -193,6 +214,11 @@ public class PreferencesActivity extends PreferenceActivity implements } else { sum = ""; } + + if(TextUtils.isEmpty(text)){ + text = getString(R.string.prefs_current_value_not_set); + } + if (isBlank(sum)) { sum = getString(R.string.prefs_current_value_template, text); } else { @@ -201,30 +227,14 @@ public class PreferencesActivity extends PreferenceActivity implements } ep.setSummary(sum); } - + private void updateSummary(ListPreference ep) { CharSequence text = ep.getEntry(); if (text == null) { return; } - - CharSequence sm = ep.getSummary(); - String sum; - if (sm != null) { - sum = ep.getSummary().toString(); - sum = substringBeforeLast(sum, - getString(R.string.prefs_current_value)).trim(); - } else { - sum = ""; - } - if (isBlank(sum)) { - sum = getString(R.string.prefs_current_value_template, text); - } else { - sum = sum + " " - + getString(R.string.prefs_current_value_template, text); - } - ep.setSummary(sum); + setSummary(text, ep); } /** diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java index b194b22..b13d3ae 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java @@ -40,7 +40,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> adapter = new RecordingAdapter(this); // attach adapter to ListView - final ListView listView = (ListView) findViewById(R.id.recording_list); + listView = (ListView) findViewById(R.id.recording_list); listView.setAdapter(adapter); // set click listener @@ -55,17 +55,8 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> } @Override - protected void onResume() { - super.onResume(); - } - - @Override protected void onPause() { super.onPause(); - if (recordingClient != null) { - recordingClient.abort(); - } - dismiss(progress); } @Override @@ -77,7 +68,6 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> @Override public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); if (v.getId() == R.id.recording_list) { final MenuInflater inflater = getMenuInflater(); @@ -90,6 +80,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> inflater.inflate(R.menu.recording_list_item_menu, menu); } + super.onCreateContextMenu(menu, v, menuInfo); } @Override @@ -101,7 +92,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> Recording rec = event.getRecording(); switch (item.getItemId()) { case R.id.recording_item_menu_delete: { - DeleteRecordingTask drt = new DeleteRecordingTask(this,rec) { + DeleteRecordingTask drt = new DeleteRecordingTask(this, rec) { @Override public void finished() { dismiss(progress); @@ -112,10 +103,10 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> break; } case R.id.recording_item_menu_stream: { - say("Sorry, not yet. It would be. File -> "+ rec.getFileName()); + say("Sorry, not yet. It would be. File -> " + rec.getFileName()); break; } - + default: return super.onContextItemSelected(item); } @@ -132,9 +123,12 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> recordingClient); // create progress dialog + progress = new SvdrpProgressDialog(this, recordingClient); + // attach listener + task.addListener(progress); task.addListener(this); // start task @@ -156,7 +150,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> @Override protected int getWindowTitle() { - return R.string.remux_title; + return R.string.action_menu_recordings; } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java index 8997214..f3468f8 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java @@ -2,22 +2,20 @@ package de.bjusystems.vdrmanager.gui; import android.app.Activity; import android.app.ProgressDialog; -import android.util.Log; -import android.widget.Toast; import de.bjusystems.vdrmanager.R; +import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; -public class SvdrpProgressDialog extends ProgressDialog { - - private static final String TAG = SvdrpProgressDialog.class.getName(); +public class SvdrpProgressDialog<T> extends ProgressDialog implements + SvdrpAsyncListener<T> { ProgressDialog progress; Activity activity; SvdrpClient<? extends Object> client; public SvdrpProgressDialog(final Activity activity, - final SvdrpClient<? extends Object> client) { + final SvdrpClient<T> client) { super(activity); this.activity = activity; this.client = client; @@ -28,24 +26,25 @@ public class SvdrpProgressDialog extends ProgressDialog { svdrpEvent(event, null); } - public void svdrpEvent(final SvdrpEvent event, Throwable error) { - switch (event) { + public void svdrpEvent(final SvdrpEvent sevent, T e) { + switch (sevent) { + case ABORTED: + case CONNECT_ERROR: + case ERROR: + case LOGIN_ERROR: + case FINISHED_ABNORMALY: + case FINISHED_SUCCESS: + case CACHE_HIT: + progress.dismiss(); + break; case CONNECTING: progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); setMessage(R.string.progress_connect); progress.show(); break; - case CONNECT_ERROR: - progress.dismiss(); - showToast(R.string.progress_connect_error); - break; case LOGGED_IN: setMessage(R.string.progress_login); break; - case LOGIN_ERROR: - progress.dismiss(); - showToast(R.string.progress_login_error); - break; case COMMAND_SENT: setMessage(client.getProgressTextId()); break; @@ -56,27 +55,11 @@ public class SvdrpProgressDialog extends ProgressDialog { break; case DISCONNECTED: break; - case FINISHED_ABNORMALY: - progress.dismiss(); - if (error == null) { - showToast(R.string.progress_connect_finished_abnormal); - } else { - showToast(R.string.progress_connect_finished_abnormal_arg, - error.getMessage()); - } - case FINISHED_SUCCESS: - progress.dismiss(); - break; - case CACHE_HIT: - progress.dismiss(); - setMessage(R.string.progress_cache_hit); - break; } } public void svdrpException(final SvdrpException exception) { - Log.w(TAG, String.valueOf(activity), exception); - showToast(R.string.vdr_error_text, exception.getMessage()); + progress.dismiss(); } private void setMessage(final int resId, Object... args) { @@ -86,17 +69,8 @@ public class SvdrpProgressDialog extends ProgressDialog { progress.setMessage(activity.getString(resId, args)); } } - - private void showToast(final int resId, Object... args) { - progress.dismiss(); - final CharSequence text = args.length == 0 ? activity.getString(resId) - : activity.getString(resId, args); - final int duration = Toast.LENGTH_SHORT; - final Toast toast = Toast.makeText(activity, text, duration); - toast.show(); - } - public void dismiss(){ + public void dismiss() { progress.dismiss(); } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java index f237a89..dfa7e6c 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java @@ -77,9 +77,7 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements } - private void addCustom() { - } private void fillTimeSpinnerValues() { final EpgSearchTimeValues values = new EpgSearchTimeValues(this); @@ -89,7 +87,6 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements } } - private int currentPostion = 0; @Override protected void onPause() { @@ -97,10 +94,6 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements } - @Override - protected void onResume() { - super.onResume(); - } public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { @@ -171,8 +164,9 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog(this, epgClient); + progress = new SvdrpProgressDialog<Epg>(this, epgClient); // attach listener + task.addListener(progress); task.addListener(this); // start task diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java index f796fa6..7c3c77b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java @@ -53,10 +53,6 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements startTimerQuery(); } - @Override - protected void onResume() { - super.onResume(); - } @Override protected void onPause() { @@ -87,7 +83,6 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements task.run(); } - @Override protected Timer getTimer(EventListItem item) { return item.getTimer(); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java index 6886e37..fef4108 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java @@ -1,6 +1,8 @@ package de.bjusystems.vdrmanager.gui; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import android.app.Activity; import android.app.AlertDialog; @@ -14,6 +16,7 @@ import android.text.TextUtils; import android.text.style.ForegroundColorSpan; import android.util.Pair; import de.bjusystems.vdrmanager.R; +import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventFormatter; @@ -21,6 +24,7 @@ import de.bjusystems.vdrmanager.data.Preferences; public class Utils { + public static final List EMPTY_LIST = new ArrayList(0); public static final ForegroundColorSpan HIGHLIGHT_TEXT = new ForegroundColorSpan( Color.RED); @@ -84,7 +88,7 @@ public class Utils { } public static boolean isLive(Event event) { - long now = new Date().getTime(); + long now = System.currentTimeMillis(); return now >= event.getStart().getTime() && now < event.getStop().getTime(); } @@ -182,7 +186,7 @@ public class Utils { share.putExtra(android.content.Intent.EXTRA_SUBJECT, sb.toString()); sb = new StringBuilder(); sb.append(title).append("\n\n"); - sb.append(event.getChannelNumber() +" " + event.getChannelName()); + sb.append(event.getChannelNumber() + " " + event.getChannelName()); sb.append("\n\n"); sb.append(ef.getShortText()); sb.append("\n\n"); @@ -192,14 +196,19 @@ public class Utils { activity.startActivity(Intent.createChooser(share, activity.getString(R.string.share_chooser))); } - - public static String mapSpecialChars(String src){ - if(src == null){ + public static String mapSpecialChars(String src) { + if (src == null) { return ""; } - return src.replace("|##", ":").replace("||#", "\n"); + return src.replace("|##", C.DATA_SEPARATOR).replace("||#", "\n"); } + public static String unMapSpecialChars(String src) { + if (src == null) { + return ""; + } + return src.replace(C.DATA_SEPARATOR, "|##").replace("\n", "||#"); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java index 70a56dc..983fb28 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java @@ -23,7 +23,7 @@ public class VdrManagerActivity extends Activity implements OnClickListener { // attach view setContentView(R.layout.vdrmanager); - Preferences.loadPreferences(this); + //Preferences.loadPreferences(this); findViewById(R.id.action_menu_channels).setOnClickListener(this); findViewById(R.id.action_menu_recordings).setOnClickListener(this); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java index 2b80499..daf7d73 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java @@ -9,17 +9,18 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; public abstract class AsyncProgressTask<Result> { - class AsyncProgress extends SvdrpProgressDialog implements SvdrpAsyncListener<Result> { + class AsyncProgress extends SvdrpProgressDialog<Result> implements SvdrpAsyncListener<Result> { public AsyncProgress(final Activity activity, final SvdrpClient<Result> client) { super(activity, client); } - public void svdrpEvent(final SvdrpEvent event, final Object result) { - svdrpEvent(event); + public void svdrpEvent(final SvdrpEvent event, final Result result) { + super.svdrpEvent(event, result); switch (event) { case FINISHED_ABNORMALY: case FINISHED_SUCCESS: + case ABORTED: AsyncProgressTask.this.finished(); break; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java index 7dc0097..fd4c63b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import android.os.AsyncTask; +import android.util.Log; public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>> extends AsyncTask<Void, Object, Void> @@ -34,13 +35,13 @@ public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>> try { client.run(); } catch (final SvdrpException e) { - publishProgress(null, null, e); + publishProgress(e); } return null; } public void svdrpEvent(final SvdrpEvent event, final Result result) { - publishProgress(event, result, null); + publishProgress(event, result); } @SuppressWarnings("unchecked") @@ -48,14 +49,16 @@ public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>> protected void onProgressUpdate(final Object... values) { super.onProgressUpdate(values); - if (values[2] == null) { + if (values.length == 2) { for(final SvdrpAsyncListener<Result> listener : listeners) { listener.svdrpEvent((SvdrpEvent)values[0], (Result)values[1]); } - } else { + } else if(values.length == 1) { for(final SvdrpAsyncListener<Result> listener : listeners) { - listener.svdrpException((SvdrpException)values[2]); + listener.svdrpException((SvdrpException)values[0]); } + } else { + Log.w(toString(), "Unknonw count of argument in onProgressUpdate"); } } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index 5f04578..35016b1 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -4,11 +4,15 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetSocketAddress; import java.net.Socket; import java.util.ArrayList; import java.util.List; +import java.util.Timer; +import java.util.TimerTask; import android.util.Log; +import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.data.Preferences; /** @@ -36,6 +40,8 @@ public abstract class SvdrpClient<Result> { /** should the listener be informed about each received result */ private boolean resultInfoEnabled = false; + private Timer watchDog = new Timer(); + /** * Parse received answer line * @@ -116,12 +122,22 @@ public abstract class SvdrpClient<Result> { */ protected boolean connect() throws IOException { - final Preferences prefs = Preferences.getPreferences(); - + Preferences prefs = Preferences.get(); try { // connect + //TODO prefs informListener(SvdrpEvent.CONNECTING, null); - socket = new Socket(prefs.getSvdrpHost(), prefs.getSvdrpPort()); + socket = new Socket(); + socket.connect(new InetSocketAddress(prefs.getSvdrpHost(), prefs.getSvdrpPort()), 10 * 1000);//8 secs for connect + socket.setSoTimeout(15 * 1000);//15 sec for each read + final long delay = C.ONE_MINUTE_IN_MILLIS * 3; //in 3 minutes we abort the communication + watchDog.schedule(new TimerTask() { + @Override + public void run() { + Log.w(TAG, "Aborted after " + delay + " ms"); + abort = true; + } + }, delay); informListener(SvdrpEvent.CONNECTED, null); } catch (final IOException e) { Log.w(TAG, e); @@ -236,12 +252,12 @@ public abstract class SvdrpClient<Result> { informListener(SvdrpEvent.COMMAND_SENDING, null); writeLine(command); informListener(SvdrpEvent.COMMAND_SENT, null); - Log.i(TAG, SvdrpEvent.COMMAND_SENT +":" + command); - + Log.i(TAG, SvdrpEvent.COMMAND_SENT + ":" + command); + // read first line String line = readLine(); if (!line.startsWith("START")) { - Log.w(TAG,line); + Log.w(TAG, line); throw new IOException("Answer not wellformed: " + line); } @@ -270,7 +286,7 @@ public abstract class SvdrpClient<Result> { Result result = null; try { result = parseAnswer(line); - } catch(Exception ex){ + } catch (Exception ex) { Log.w(TAG, ex); Log.w(TAG, "line: " + line); informListener(SvdrpEvent.ERROR, null); @@ -289,7 +305,11 @@ public abstract class SvdrpClient<Result> { // disconnect disconnect(); - informListener(SvdrpEvent.FINISHED_SUCCESS, null); + if (abort) { + informListener(SvdrpEvent.ABORTED, null); + } else { + informListener(SvdrpEvent.FINISHED_SUCCESS, null); + } } catch (final Exception e) { // throw new SvdrpException(e); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java index bb1ebb8..4384136 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java @@ -14,6 +14,7 @@ public enum SvdrpEvent { DISCONNECTED, FINISHED_ABNORMALY, FINISHED_SUCCESS, + ABORTED, ERROR, CACHE_HIT, } |