JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
BrowseActivity.java
Go to the documentation of this file.
1 package jarmos.app.activity;
2 
3 import jarmos.app.Const;
6 
7 import java.io.FileOutputStream;
8 import java.io.IOException;
9 
10 import android.app.Activity;
11 import android.content.Context;
12 import android.os.Bundle;
13 import android.util.Log;
14 import android.webkit.WebView;
15 import android.webkit.WebViewClient;
16 import android.widget.Toast;
17 
28 public class BrowseActivity extends Activity {
29  private WebView browser;
30 
34  protected void onCreate(Bundle icicle) {
35  super.onCreate(icicle);
36 
37  browser = new WebView(this);
38  setContentView(browser);
39 
40  // Create model manager instance to use
41  AModelManager m = null;
42  try {
43  m = Const.getModelManager(getApplicationContext(), getIntent());
44  } catch (ModelManagerException e) {
45  Log.e("BrowseActivity", "Creation of ModelManager failed", e);
46  finish();
47  return;
48  }
49 
50  // if info page was not supplied/another error occurs while loading,
51  // redirect user to home site
52  browser.setWebViewClient(new WebViewClient() {
53  public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
54  Toast.makeText(BrowseActivity.this, "Sorry, no informational page was supplied with this problem",
55  Toast.LENGTH_LONG).show();
56  }
57  });
58 
59  // removes white scrollbar from view while keeping scrolling
60  // funcionality
61  browser.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
62 
63  String file = m.getModelXMLTagValue("infohtml");
64  if (file != null) {
65  browser.loadUrl(m.getModelURI() + "/" + file);
66  Log.d("browser", m.getModelURI() + "/" + file);
67  } else {
68  String img = m.getModelXMLTagValue("model.description.image");
69  img = img != null ? "<img src='" + m.getModelURI() + "/" + img + "' alt=''/>" : "";
70  String html = "<html><body bgcolor='Black'><center><font color='white'>Sorry, this model does not have any information page associated with it."
71  + img + "</font></center>" + "</body></html>";
72  try {
73  FileOutputStream f = openFileOutput("noinfo.html", Context.MODE_PRIVATE);
74  f.write(html.getBytes());
75  f.close();
76  } catch (IOException e) {
77  Log.e("BrowseActivity", "Error saving a temporary html file", e);
78  return;
79  }
80  browser.loadUrl("file://" + Const.APP_DATA_DIRECTORY + "/noinfo.html");
81  // browser.loadData(html, "text/html", "utf8");
82  }
83  }
84 
88  public void onBackPressed() {
89  // need to tell parent activity to close all activities
90  getParent().onBackPressed();
91  }
92 
93 }
This class serves as base class for accessing various types of models at different locations...
An activity which displays URLs in a simple browser.
This Exception gets thrown when an error occurs regarding the functionality of the ModelManager...
Class that contains miscellaneous JaRMoS specific constants and static functions. ...
Definition: Const.java:26