JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
SimulationActivity.java
Go to the documentation of this file.
1 package jarmos.app.activity.kermor;
2 
3 import jarmos.app.Const;
6 import jarmos.app.R;
10 import kermor.ReducedModel;
11 import android.app.Activity;
12 import android.app.ProgressDialog;
13 import android.content.DialogInterface;
14 import android.content.DialogInterface.OnCancelListener;
15 import android.os.Bundle;
16 import android.os.Handler;
17 import android.os.Message;
18 import android.util.Log;
19 import android.view.View;
20 import android.widget.Button;
21 import android.widget.TableLayout;
22 import android.widget.Toast;
23 
31 public class SimulationActivity extends Activity {
32 
33  public static ReducedModel rm;
34 
38  private ProgressDialog pd;
39 
40  private AModelManager mng = null;
41  private ParamBars pb = null;
42 
43  @Override
44  protected void onCreate(Bundle savedInstanceState) {
45  super.onCreate(savedInstanceState);
46  setContentView(R.layout.kermor_main);
47 
48  // Create model manager instance to use
49  try {
50  mng = Const.getModelManager(getApplicationContext(), getIntent());
51  } catch (ModelManagerException e) {
52  Log.e("SimulationActivity", "Creation of ModelManager failed", e);
53  finish();
54  return;
55  }
56 
57  pd = ProgressDialog.show(SimulationActivity.this, "Loading model data", "", true, true, new OnCancelListener() {
58  @Override
59  public void onCancel(DialogInterface dialog) {
60  // delete_downloaded_files();
61  setResult(0);
62  finish();
63  }
64  });
65 
66  final Handler sh = new Handler() {
67  @Override
68  public void handleMessage(Message msg) {
69  pd.dismiss();
70 
71  Toast.makeText(SimulationActivity.this, "Model successfully simulated!", Toast.LENGTH_LONG).show();
72  }
73  };
74 
75  // Add listener to the Solve button
76  Button solveButton = (Button) findViewById(R.id.solveButton);
77  solveButton.setOnClickListener(new View.OnClickListener() {
78  public void onClick(View view) {
79  pd = ProgressDialog.show(SimulationActivity.this, "", "Solving...");
80  new Thread() {
81  public void run() {
82  try {
83  rm.simulate(rm.params.getCurrent(), rm.system.currentInput());
84  sh.sendEmptyMessage(0);
85  } catch (KerMorException e) {
86  Log.e("SimulationActivity", "Error simulating", e);
87  }
88  }
89  }.start();
90  }
91 
92  });
93 
94  final ModelManagerProgressHandler progressHandler = new ModelManagerProgressHandler() {
95  public void handleMessage(Message msg) {
96  pd.setMessage(msg.getData().getString("file") + "...");
97  }
98  };
99  mng.addMessageHandler(progressHandler);
100 
101  final Handler h = new Handler() {
102  @Override
103  public void handleMessage(Message msg) {
104 
105  pb = new ParamBars(SimulationActivity.this, rm.params);
106  pb.createBars((TableLayout) findViewById(R.id.paramLayout));
107 
108  pd.dismiss();
109  mng.removeMessageHandler(progressHandler);
110 
111  Toast.makeText(SimulationActivity.this, "Model successfully loaded!", Toast.LENGTH_LONG).show();
112 
113  // RealMatrix res = null;
114  // try {
115  // res = rm.simulate(null);
116  // } catch (KerMorException e) {
117  // Log.e("SimulationActivity","Error simulating.",e);
118  // //finish();
119  // }
120  // Log.d("SimulationActivity", res.toString());
121  // Display stuff!
122  }
123  };
124 
125  (new Thread() {
126 
127  @Override
128  public void run() {
129  try {
130  rm = new ReducedModel();
131  rm.loadOfflineData(mng);
132  } catch (Exception e) {
133  Log.e("SimulationActivity", "Error loading reduced model.", e);
134  }
135  h.sendEmptyMessage(0);
136  }
137 
138  }).start();
139 
140  }
141 
142 }
A helper class for a collection of UI elements regarding model parameter display. ...
Definition: ParamBars.java:37
Main reduced model class.
This class serves as base class for accessing various types of models at different locations...
Custom exception for JKerMor related errors.
The JKerMor model simulation activity.
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
ReducedSystem system
A progress notification handler implementation for android platforms.