diff options
Diffstat (limited to 'vdrmanager/src/de')
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/EpgCache.java | 2 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/FetchEditTextPreference.java (renamed from vdrmanager/src/de/bjusystems/vdrmanager/data/MacFetchEditTextPreference.java) | 10 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java | 23 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java | 10 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java | 6 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrPreferencesActivity.java | 134 |
6 files changed, 139 insertions, 46 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/EpgCache.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/EpgCache.java index a66b499..fd1a895 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/EpgCache.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/EpgCache.java @@ -9,6 +9,4 @@ public class EpgCache { public static WeakHashMap<String, ArrayList<Epg>> CACHE = new WeakHashMap<String, ArrayList<Epg>>(); public static WeakHashMap<String, Date> NEXT_REFRESH = new WeakHashMap<String, Date>(); - - } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/MacFetchEditTextPreference.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/FetchEditTextPreference.java index 3b5ab4f..5e4022e 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/MacFetchEditTextPreference.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/FetchEditTextPreference.java @@ -10,7 +10,7 @@ import android.widget.ImageButton; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.VdrSharedPreferences.Editor; -public class MacFetchEditTextPreference extends DialogPreference { +public class FetchEditTextPreference extends DialogPreference{ private EditText mEditText; @@ -38,15 +38,15 @@ public class MacFetchEditTextPreference extends DialogPreference { //private CharSequence mCompoundButtonText; private View.OnClickListener mCompoundButtonCallback; - public MacFetchEditTextPreference(Context context, AttributeSet attrs, + public FetchEditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - setDialogLayoutResource(R.layout.mac_fetch_preference); + setDialogLayoutResource(R.layout.fetch_preference); } - public MacFetchEditTextPreference(Context context, AttributeSet attrs) { + public FetchEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); - setDialogLayoutResource(R.layout.mac_fetch_preference); + setDialogLayoutResource(R.layout.fetch_preference); } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java index a55e821..8839fa0 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java @@ -39,9 +39,9 @@ public class VdrSharedPreferences implements SharedPreferences { } -// public VdrSharedPreferences(Vdr vdr) { + // public VdrSharedPreferences(Vdr vdr) { -// } + // } public boolean contains(String key) { return map.containsKey(key); @@ -64,11 +64,21 @@ public class VdrSharedPreferences implements SharedPreferences { } public int getInt(String key, int defValue) { - return get(key, defValue); + String val = get(key, String.valueOf(defValue)); + try { + return Integer.valueOf(val); + } catch (Exception ex) { + return defValue; + } } public long getLong(String key, long defValue) { - return get(key, defValue); + String val = get(key, String.valueOf(defValue)); + try { + return Long.valueOf(val); + } catch (Exception ex) { + return defValue; + } } public <T> T get(String key, T defValue) { @@ -118,9 +128,7 @@ public class VdrSharedPreferences implements SharedPreferences { public boolean commit() { - - - if(instance == null){ + if (instance == null) { map.putAll(modified); return true; } @@ -136,7 +144,6 @@ public class VdrSharedPreferences implements SharedPreferences { map.putAll(modified); - ++commits; // and update any listeners diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java index 168eef3..50e9bb7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java @@ -1,6 +1,5 @@ package de.bjusystems.vdrmanager.gui; -import android.preference.DialogPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; @@ -9,7 +8,7 @@ import android.text.TextUtils; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import de.bjusystems.vdrmanager.R; -import de.bjusystems.vdrmanager.data.MacFetchEditTextPreference; +import de.bjusystems.vdrmanager.data.FetchEditTextPreference; /** * @@ -24,8 +23,8 @@ public abstract class BasePreferencesActivity extends PreferenceActivity { updateSummary((EditTextPreference) ep); } else if (ep instanceof ListPreference) { updateSummary((ListPreference) ep); - } else if(ep instanceof MacFetchEditTextPreference){ - updateSummary((MacFetchEditTextPreference)ep); + } else if(ep instanceof FetchEditTextPreference){ + updateSummary((FetchEditTextPreference)ep); } } @@ -34,12 +33,11 @@ public abstract class BasePreferencesActivity extends PreferenceActivity { * * @param ep */ - protected void updateSummary(MacFetchEditTextPreference ep) { + protected void updateSummary(FetchEditTextPreference ep) { String text = ep.getText(); if (text == null) { text = ""; } - setSummary(text, ep); } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java index 2b30fc6..06e2522 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java @@ -410,6 +410,12 @@ public class Utils { t.show(); } + public static void say(Context ctx, int msg) { + Toast t = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); + t.setGravity(Gravity.CENTER, 0, 0); + t.show(); + } + /** * Formats the date and time based on user's phone date/time preferences. * diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrPreferencesActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrPreferencesActivity.java index c166333..35798d2 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrPreferencesActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrPreferencesActivity.java @@ -6,13 +6,20 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +import org.fueri.reeldroid.network.DeviceManager; import android.app.Activity; +import android.app.AlertDialog; import android.app.ProgressDialog; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.os.AsyncTask; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; @@ -20,7 +27,7 @@ import android.view.View; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.ZonePicker; import de.bjusystems.vdrmanager.app.Intents; -import de.bjusystems.vdrmanager.data.MacFetchEditTextPreference; +import de.bjusystems.vdrmanager.data.FetchEditTextPreference; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.Vdr; import de.bjusystems.vdrmanager.data.VdrSharedPreferences; @@ -30,7 +37,7 @@ import de.bjusystems.vdrmanager.tasks.VoidAsyncTask; public class VdrPreferencesActivity extends BasePreferencesActivity implements OnSharedPreferenceChangeListener, OnPreferenceClickListener { - public static final int REQUEST_CODE_PICK_A_TIME_ZONE = 1; + public static final int REQUEST_CODE_PICK_A_TIME_ZONE = 1; Vdr vdr; @@ -48,10 +55,9 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements return super.findPreference(key); } - @Override protected void updateSummary(Preference ep) { - if(ep.getKey().equals("key_timezone")) { + if (ep.getKey().equals("key_timezone")) { String text = vdr.getServerTimeZone(); if (text == null) { return; @@ -61,6 +67,7 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements } super.updateSummary(ep); } + private void initVDRInstance() { id = getIntent().getIntExtra(Intents.VDR_ID, -1); if (id == -1) {// new vdr @@ -124,16 +131,15 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements return null; } - private String getIp() throws Exception { - final Preferences prefs = Preferences.get(); - String host = prefs.getSvdrpHost(); - return InetAddress.getByName(host).getHostAddress(); - } +// private String getIp() throws Exception { +// final Preferences prefs = Preferences.get(); +// String host = prefs.getSvdrpHost(); +// return InetAddress.getByName(host).getHostAddress(); +// } - private void ping(String ip) throws Exception { - final Preferences prefs = Preferences.get(); + private void ping(String ip, int port) throws Exception { Socket socket = new Socket(); - socket.connect(new InetSocketAddress(ip, prefs.getSvdrpPort()), + socket.connect(new InetSocketAddress(ip, port), 5 * 1000); socket.setSoTimeout(5 * 1000); } @@ -155,8 +161,6 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements pref.registerOnSharedPreferenceChangeListener(this); - - String recstream = pref.getString("key_recstream_method", "vdr-live"); if (recstream.equals("vdr-live") == false) { @@ -167,20 +171,22 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements // cat.removePreference(p); } - final String host = pref.getString(getString(R.string.vdr_host_key), - null); + // create background task // start task - final MacFetchEditTextPreference macedit = (MacFetchEditTextPreference) findPreference(getString(R.string.wakeup_wol_mac_key)); + final FetchEditTextPreference macedit = (FetchEditTextPreference) findPreference(getString(R.string.wakeup_wol_mac_key)); String mac = vdr.getMac(); + if(mac == null){ + mac = ""; + } macedit.setText(mac); macedit.setCompoundButtonListener(new View.OnClickListener() { @Override public void onClick(View v) { - + final String host = vdr.getHost(); if (host == null) { Utils.say(VdrPreferencesActivity.this, getString(R.string.vdr_host_not_defined)); @@ -213,8 +219,8 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements @Override protected Void doInBackground(Void... params) { try { - String ip = getIp(); - ping(ip); + String ip = InetAddress.getByName(host).getHostAddress(); + ping(ip, vdr.getPort()); mac = getMacFromArpCache(ip); } catch (Exception ex) { message = ex.getLocalizedMessage(); @@ -226,9 +232,87 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements } }); + final FetchEditTextPreference ipEdit = (FetchEditTextPreference) findPreference(getString(R.string.vdr_host_key)); + String ip = vdr.getHost(); + ipEdit.setText(ip); + ipEdit.setCompoundButtonListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + new AsyncTask<Void, String, List<String>>() { + + ProgressDialog pd; + + String message; + + protected void onPreExecute() { + pd = new ProgressDialog(VdrPreferencesActivity.this); + pd.setMessage(getString(R.string.processing)); + pd.show(); + }; + + protected void onPostExecute(final List<String> ips) { + pd.dismiss(); + if (message != null) { + Utils.say(VdrPreferencesActivity.this, message); + return; + } + + if(ips.isEmpty()){ + Utils.say(VdrPreferencesActivity.this, R.string.no_results); + return; + } + if (ips.size() == 1) { + ipEdit.setEditText(ips.get(0).toString()); + } else { + new AlertDialog.Builder(VdrPreferencesActivity.this).setItems( + ips.toArray(new CharSequence[] {}), + new DialogInterface.OnClickListener() { + @Override + public void onClick( + DialogInterface dialog, + int which) { + String ip = ips.get(which); + ipEdit.setEditText(ip); + } + }).show(); + } + + } + + protected void onProgressUpdate(String... values) { + pd.setMessage(getString(R.string.probing, values[0])); + }; + + @Override + protected List<String> doInBackground(Void... params) { + try { + + final int port = vdr.getPort(); + return DeviceManager.findVDRHosts( + VdrPreferencesActivity.this, port, + new DeviceManager.ProgressListener() { + + @Override + public void publish(String currentIP) { + publishProgress(currentIP); + } + }); + + } catch (Exception ex) { + message = ex.getLocalizedMessage(); + } + return new ArrayList<String>(0); + } + }.execute(); + + } + }); + updateChildPreferences(); - findPreference(getString(R.string.timezone_key)).setOnPreferenceClickListener(this); + findPreference(getString(R.string.timezone_key)) + .setOnPreferenceClickListener(this); } @@ -374,19 +458,19 @@ public class VdrPreferencesActivity extends BasePreferencesActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if(resultCode != Activity.RESULT_OK){ + if (resultCode != Activity.RESULT_OK) { super.onActivityResult(requestCode, resultCode, data); return; } - if(requestCode == REQUEST_CODE_PICK_A_TIME_ZONE){ + if (requestCode == REQUEST_CODE_PICK_A_TIME_ZONE) { String ntz = data.getStringExtra("new_tz"); - if(ntz != null){ + if (ntz != null) { vdr.setServerTimeZone(ntz); Editor editor = findPreference("key_timezone").getEditor(); editor.putString("key_timezone", ntz); editor.commit(); - //setSummary(ntz, ); + // setSummary(ntz, ); } } } |