diff options
author | lado <herrlado@gmail.com> | 2011-10-26 15:12:15 +0200 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2011-10-26 15:12:15 +0200 |
commit | bbecdc68f5612e07f15824dc1ee125ff6b9ecc95 (patch) | |
tree | e56312130642fd1f3f3fd1b9bf4160adc2f5402d /vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java | |
parent | 31ca19ed67874146b3ac0061b3c917d26beafab7 (diff) | |
download | vdr-manager-bbecdc68f5612e07f15824dc1ee125ff6b9ecc95.tar.gz vdr-manager-bbecdc68f5612e07f15824dc1ee125ff6b9ecc95.tar.bz2 |
handling von messages, refactoring
Diffstat (limited to 'vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java')
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java | 120 |
1 files changed, 85 insertions, 35 deletions
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; + } |