diff options
author | lado <herrlado@gmail.com> | 2012-01-22 03:39:17 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2012-01-22 03:39:17 +0100 |
commit | 36a8723b654faea542da9b6ea7a4a3fe9c22da04 (patch) | |
tree | b3739819727205dc14f2d75d220d662989965f48 /vdrmanager/src/de | |
parent | bdd461526fcfaecfd42cec03b77ab0f6db109c3c (diff) | |
download | vdr-manager-36a8723b654faea542da9b6ea7a4a3fe9c22da04.tar.gz vdr-manager-36a8723b654faea542da9b6ea7a4a3fe9c22da04.tar.bz2 |
Diffstat (limited to 'vdrmanager/src/de')
7 files changed, 56 insertions, 206 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java index 652fd31..ea3cfa2 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java @@ -34,9 +34,15 @@ public class Preferences { } public static void setCurrentVdr(Context context, Vdr vdr) { - setCurrentInternal(context, vdr); + final SharedPreferences sharedPrefs = getSharedPreferences(context); + current = vdr; + sharedPrefs + .edit() + .putInt(context.getString(R.string.current_vdr_id_key), + current.getId()).commit(); } + public Vdr getCurrentVdr() { return current; } @@ -190,9 +196,7 @@ public class Preferences { * @return true, if remote wakeup is enabled */ public boolean isWakeupEnabled() { - return true; - // TODO - // return getCurrentVdr().isWakeupEnabled(); + return getCurrentVdr().isWakeupEnabled(); } /** @@ -447,7 +451,8 @@ public class Preferences { public static void reset() { thePrefs = null; } - + + /** * Loads all preferences * @@ -471,9 +476,9 @@ public class Preferences { setLocale(context); } - // if (current != null) { - // return; - // } + // if (current != null) { + // return; + // } final SharedPreferences sharedPrefs = getSharedPreferences(context); int id = sharedPrefs.getInt( @@ -485,14 +490,14 @@ public class Preferences { } if (vdr != null) { - setCurrentInternal(context, vdr); + setCurrentVdr(context, vdr); return; } List<Vdr> list = db.getVdrDAO().queryForAll(); if (list != null && list.isEmpty() == false) { vdr = list.get(0); - setCurrentInternal(context, vdr); + setCurrentVdr(context, vdr); return; } if (initFromOldVersion(context) == false) { @@ -505,31 +510,15 @@ public class Preferences { } - private static void setCurrentInternal(Context context, Vdr vdr) { - final SharedPreferences sharedPrefs = getSharedPreferences(context); - current = vdr; - sharedPrefs - .edit() - .putInt(context.getString(R.string.current_vdr_id_key), - current.getId()).commit(); - } - private static boolean initFromOldVersion(Context context) { - int version = -1; - try { - version = context.getPackageManager().getPackageInfo( - context.getPackageName(), 0).versionCode; - } catch (Exception ex) { - return false; - } - - if (version != 40) { - return false; - } Vdr vdr = new Vdr(); - vdr.setHost(getString(context, R.string.vdr_host_key, "0.0.0.0")); + String host = getString(context, R.string.vdr_host_key, null); + if(host == null){ + return false; + } + vdr.setHost(host); vdr.setName("Default"); vdr.setPort(getInt(context, R.string.vdr_port_key, 6420)); vdr.setPassword(getString(context, R.string.vdr_password_key, "")); @@ -592,7 +581,7 @@ public class Preferences { return false; } - setCurrentInternal(context, vdr); + setCurrentVdr(context, vdr); return true; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java index fd75033..6b8c6dd 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java @@ -16,7 +16,7 @@ public class Vdr { private Integer id; @DatabaseField(columnName = "name") - private String name; + private String name = "-"; /** * Use secure channel @@ -439,6 +439,10 @@ public class Vdr { } private static <T> T get(Map<String, Object> map, String key) { + return get(map, key, null); + } + + private static <T> T get(Map<String, Object> map, String key, Object def) { return (T) map.get(key); } @@ -506,8 +510,8 @@ public class Vdr { } public void init(Map<String, Object> map) { - name = get(map, "vdr_name"); - host = get(map, "vdr_host"); + name = get(map, "vdr_name", name); + host = get(map, "vdr_host" ); port = getInteger(map, "vdr_port"); password = get(map, "vdr_password"); secure = getBoolean(map, "vdr_secure"); @@ -516,12 +520,12 @@ public class Vdr { channelFilter = get(map, "last_channel"); wakeupEnabled = getBoolean(map, "key_wakeup_enabled"); - wakeupUrl = get(map, "key_wakeup_url"); - wakeupUser = get(map, "key_wakeup_user"); - wakeupPassword = get(map, "key_wakeup_password"); - wakeupMethod = get(map, "key_wakeup_method"); - wolCustomBroadcast = get(map, "key_wol_custom_broadcast"); - mac = get(map, "key_wakeup_wol_mac"); + wakeupUrl = get(map, "key_wakeup_url", "0.0.0.0"); + wakeupUser = get(map, "key_wakeup_user",""); + wakeupPassword = get(map, "key_wakeup_password",""); + wakeupMethod = get(map, "key_wakeup_method","wol"); + wolCustomBroadcast = get(map, "key_wol_custom_broadcast",""); + mac = get(map, "key_wakeup_wol_mac",""); connectionTimeout = getInteger(map, "key_conntimeout_key"); readTimeout = getInteger(map, "key_vdr_readtimeout"); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java index bbaa74e..86103bf 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java @@ -15,6 +15,8 @@ public class VdrSharedPreferences implements SharedPreferences { private static final String EMPTY_STRING = ""; + public int commits = 0; + public RuntimeExceptionDao<Vdr, Integer> dao; public Vdr instance; @@ -108,6 +110,8 @@ public class VdrSharedPreferences implements SharedPreferences { if(status == false) return false; + ++commits; + // and update any listeners for (OnSharedPreferenceChangeListener listener : listeners) { listener.onSharedPreferenceChanged( diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java index 2d892e9..c88ba8c 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java @@ -1,25 +1,16 @@ package de.bjusystems.vdrmanager.gui; -import android.app.ActionBar; -import android.app.ActionBar.OnNavigationListener; -import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; -import android.app.SearchManager; -import android.content.Context; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; -import android.widget.SearchView; -import android.widget.SpinnerAdapter; import android.widget.Toast; import android.widget.ViewFlipper; import de.bjusystems.vdrmanager.R; @@ -31,7 +22,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; -public abstract class BaseActivity<Result, T extends ListView> extends Activity +public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseActivity implements OnClickListener, SvdrpAsyncListener<Result>, Cache { public static final String TAG = BaseActivity.class.getName(); @@ -124,36 +115,6 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity // setTitle(title); // } - public void initActionBar() { - int api = Build.VERSION.SDK_INT; - if (api < 11) { - return; - } - - ActionBar actionBar = getActionBar(); - actionBar.setHomeButtonEnabled(true); - // actionBar.setDisplayShowHomeEnabled(false); - // actionBar.setDisplayShowTitleEnabled(false); - // View actionBarView = - // getLayoutInflater().inflate(R.layout.action_bar_custom_view, null); - // actionBar.setCustomView(actionBarView); - // actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); - - // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - // ArrayAdapter<String> mSpinnerAdapter = new ArrayAdapter<String>(this, - // android.R.layout.simple_spinner_dropdown_item); - // mSpinnerAdapter.add("A"); - // actionBar.setListNavigationCallbacks(mSpinnerAdapter, new - // OnNavigationListener() { - - // public boolean onNavigationItemSelected(int itemPosition, long - // itemId) { - // // TODO Auto-generated method stub - // return false; - // } - // }); - - } @Override protected void onCreate(Bundle savedInstanceState) { @@ -161,6 +122,7 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity Preferences.setLocale(this); progress = new ProgressDialog(this); getApp().addActivityToFinish(this); + initActionBar(); // your logic for click listner diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java index e1b3723..7a0f1e8 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java @@ -205,7 +205,7 @@ public abstract class BaseEventListActivity<T extends Event> extends super.onCreateContextMenu(menu, v, menuInfo); } - + /** * @param parent * @param view @@ -225,8 +225,7 @@ public abstract class BaseEventListActivity<T extends Event> extends prepareDetailsViewData(item); // show details - final Intent intent = new Intent(); - intent.setClass(this, EpgDetailsActivity.class); + final Intent intent = new Intent(this, EpgDetailsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); if (highlight != null) { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java index 28d989d..7843844 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java @@ -4,15 +4,12 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; -import android.app.ActionBar; -import android.app.Activity; import android.app.AlertDialog; import android.app.SearchManager; import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; @@ -53,12 +50,14 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; * * @author bju */ -public class EpgDetailsActivity extends Activity implements OnClickListener, +public class EpgDetailsActivity extends ICSBaseActivity implements OnClickListener, OnPageChangeListener { public static final String TAG = "EpgDetailsActivity"; public static String IMDB_URL = "http://%s/find?s=all&q=%s"; + + private static final String IMDB_URL_ENCODING = "ISO-8859-1"; private String highlight = null; @@ -119,37 +118,6 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, } } - public void initActionBar() { - int api = Build.VERSION.SDK_INT; - if (api < 11) { - return; - } - - ActionBar actionBar = getActionBar(); - actionBar.setHomeButtonEnabled(true); - // actionBar.setDisplayShowHomeEnabled(false); - // actionBar.setDisplayShowTitleEnabled(false); - // View actionBarView = - // getLayoutInflater().inflate(R.layout.action_bar_custom_view, null); - // actionBar.setCustomView(actionBarView); - // actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); - - // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - // ArrayAdapter<String> mSpinnerAdapter = new ArrayAdapter<String>(this, - // android.R.layout.simple_spinner_dropdown_item); - // mSpinnerAdapter.add("A"); - // actionBar.setListNavigationCallbacks(mSpinnerAdapter, new - // OnNavigationListener() { - - // public boolean onNavigationItemSelected(int itemPosition, long - // itemId) { - // // TODO Auto-generated method stub - // return false; - // } - // }); - - } - @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -343,8 +311,8 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, final TextView title = (TextView) view .findViewById(R.id.epg_detail_title); String url = String.format(IMDB_URL, Preferences.get() - .getImdbUrl(), String.valueOf(title.getText())); - url = encode(url, "utf-8"); + .getImdbUrl(), encode(String.valueOf(title.getText()), IMDB_URL_ENCODING)); + //url = encode(url, "utf-8"); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); i.addCategory(Intent.CATEGORY_BROWSABLE); @@ -435,7 +403,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, break; case R.id.epg_event_create_timer: final ArrayAdapter<Wrapper> ada = new ArrayAdapter<Wrapper>(this, - R.layout.timer_operation_list_item); + android.R.layout.simple_dropdown_item_1line); final Timer timer = getTimer(cEvent); // remove unneeded menu items if (timer != null) { @@ -534,71 +502,9 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, task.start(); } - // EditTimerViewHolder tView = null; - - // public void onSwipe(int direction) { - // switch (direction) { - // case SimpleGestureFilter.SWIPE_RIGHT: - // // prevEPG(); - // break; - // case SimpleGestureFilter.SWIPE_LEFT: - // nextEPG(); - // break; - // } - // } - - // private void prevEPG() { - // if(counter == -1){ - // return; - // } - // Event epg; - // if (counter == 0) { - // say(R.string.navigae_at_the_start); - // return; - // } - // epg = epgs.get(--counter); - // publishEPG(epg); - // } - - List<Event> epgs = new ArrayList<Event>(); - - // /int counter = 0; - - /* - * public void initEPGs() { - * - * if (epgs != null) { return; } epgs = new ArrayList<Event>(); - * - * final VdrManagerApp app = (VdrManagerApp) getApplication(); final Event - * event = app.getCurrentEvent(); EpgClient c = new EpgClient(new Channel() - * { - * - * @Override public String getName() { return event.getChannelName(); } - * - * @Override public int getNumber() { return - * Integer.valueOf(event.getChannelNumber()); } }); - * - * try { c.run(); } catch (SvdrpException e) { // TODO Auto-generated catch - * block e.printStackTrace(); } - * - * List<Epg> e = c.getResults(); if (e == null || e.isEmpty()) { return; } - * - * epgs.addAll(e); Event fe = epgs.get(0); if - * (event.getStart().equals(fe.getStart()) == false) { epgs.set(0, event); ; - * } } - */ - // private void nextEPG() { - // if (counter == -1) { - // return; - // } - // if (counter < epgs.size() - 1) { - // counter++; - // Event epg = epgs.get(counter); - // // publishEPG(epg); - // } else { - // say(R.string.navigae_at_the_end); - // } - // } + + private List<Event> epgs = new ArrayList<Event>(); + protected void say(int res) { Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); @@ -608,15 +514,6 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); } - // public void onDoubleTap() { - // - // } - - // @Override - // public boolean dispatchTouchEvent(MotionEvent me) { - // // this.detector.onTouchEvent(me); - // return super.dispatchTouchEvent(me); - // } @Override public final boolean onCreateOptionsMenu(final Menu menu) { @@ -652,15 +549,6 @@ public class EpgDetailsActivity extends Activity implements OnClickListener, return super.onOptionsItemSelected(item); } - // protected void modifyTimer(Timer timer) { - // final ModifyTimerTask task = new ModifyTimerTask(this, timer) { - // @Override - // public void finished(SvdrpEvent event) { - // modifed = true; - // } - // }; - // task.start(); - // } protected void deleteTimer(final Timer timer) { final DeleteTimerTask task = new DeleteTimerTask(this, timer) { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java index 7451043..0015492 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/PreferencesActivity.java @@ -74,13 +74,17 @@ public class PreferencesActivity extends BasePreferencesActivity implements @Override public void onBackPressed() { + + + //Preferences.getSharedPreferences(this) + //.registerOnSharedPreferenceChangeListener(this); // finish this activity final VdrManagerApp app = (VdrManagerApp) getApplication(); app.addActivityToFinish(this); app.finishActivities(); - Preferences.init(this); + //Preferences.init(this); // restart main activity because // the buttons needs refreshing final Intent intent = new Intent(); |