| 1 |
package com.webworxshop.swallowcatcher; |
| 2 |
|
| 3 |
import android.app.Activity; |
| 4 |
import android.os.Bundle; |
| 5 |
import android.content.Intent; |
| 6 |
import android.webkit.WebView; |
| 7 |
import android.util.Log; |
| 8 |
|
| 9 |
import java.sql.SQLException; |
| 10 |
import java.net.URLEncoder; |
| 11 |
import java.io.UnsupportedEncodingException; |
| 12 |
|
| 13 |
import com.j256.ormlite.android.apptools.OpenHelperManager; |
| 14 |
import com.j256.ormlite.dao.Dao; |
| 15 |
|
| 16 |
import com.webworxshop.swallowcatcher.db.Episode; |
| 17 |
import com.webworxshop.swallowcatcher.db.DatabaseHelper; |
| 18 |
|
| 19 |
public class ShowNotesActivity extends Activity |
| 20 |
{ |
| 21 |
/** Called when the activity is first created. */ |
| 22 |
@Override |
| 23 |
public void onCreate(Bundle savedInstanceState) |
| 24 |
{ |
| 25 |
super.onCreate(savedInstanceState); |
| 26 |
setContentView(R.layout.shownotes_view); |
| 27 |
|
| 28 |
Intent i = getIntent(); |
| 29 |
int id = i.getIntExtra("episode", -1); |
| 30 |
|
| 31 |
try |
| 32 |
{ |
| 33 |
DatabaseHelper helper = (DatabaseHelper)OpenHelperManager.getHelper(this); |
| 34 |
Dao<Episode, Object> dao = helper.getEpisodeDao(); |
| 35 |
|
| 36 |
Episode ep = dao.queryForId(id); |
| 37 |
setTitle(ep.toString()); |
| 38 |
|
| 39 |
// the webview needs its content urlencoded, but with spaces as spaces |
| 40 |
// for some reason |
| 41 |
String text = URLEncoder.encode(ep.getDescription(), "utf-8"); |
| 42 |
text = text.replace('+', ' '); |
| 43 |
|
| 44 |
WebView web = (WebView)findViewById(R.id.shownotes); |
| 45 |
web.loadData(text, "text/html", "utf-8"); |
| 46 |
} |
| 47 |
catch(SQLException e) |
| 48 |
{ |
| 49 |
Log.e("SwallowCatcher", "Unable to find episode!", e); |
| 50 |
} |
| 51 |
catch(UnsupportedEncodingException e) |
| 52 |
{ |
| 53 |
Log.e("SwallowCatcher", "Unable to encode content!", e); |
| 54 |
} |
| 55 |
} |
| 56 |
} |