8a478ab4def6347225ea6df0967ad4865ff17803
[debian/openrocket] / android / src / net / sf / openrocket / android / simulation / SimulationViewActivity.java
1 /**\r
2  * Copyright (C) 2009, 2010 SC 4ViewSoft SRL\r
3  *  \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *  \r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *  \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package net.sf.openrocket.android.simulation;\r
17 \r
18 import net.sf.openrocket.R;\r
19 import net.sf.openrocket.android.ActivityHelpers;\r
20 import net.sf.openrocket.android.Application;\r
21 import net.sf.openrocket.document.OpenRocketDocument;\r
22 import net.sf.openrocket.document.Simulation;\r
23 import android.os.Bundle;\r
24 import android.support.v4.app.Fragment;\r
25 import android.support.v4.app.FragmentActivity;\r
26 import android.support.v4.app.FragmentTransaction;\r
27 import android.view.Menu;\r
28 import android.view.MenuItem;\r
29 \r
30 /**\r
31  * An activity that encapsulates a graphical view of the chart.\r
32  */\r
33 public class SimulationViewActivity extends FragmentActivity {\r
34 \r
35         @Override\r
36         protected void onCreate(Bundle savedInstanceState) {\r
37                 super.onCreate(savedInstanceState);\r
38                 //setContentView(R.layout.simulation_graph_activity);\r
39                 int simulationNumber = getIntent().getIntExtra("Simulation", 0);\r
40 \r
41                 final OpenRocketDocument rocketDocument = ((Application)getApplication()).getRocketDocument();\r
42 \r
43                 Simulation sim = rocketDocument.getSimulation(simulationNumber);\r
44 \r
45                 SimulationChart chart = new SimulationChart( simulationNumber);\r
46                 chart.setSeries1(sim.getSimulatedData().getBranch(0).getTypes()[1]);\r
47                 chart.setSeries2(sim.getSimulatedData().getBranch(0).getTypes()[2]);\r
48 \r
49                 Fragment graph = SimulationFragment.newInstance(chart);\r
50 \r
51                 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\r
52                 ft.replace(android.R.id.content, graph);\r
53                 ft.commit();\r
54         }\r
55 \r
56         @Override\r
57         public boolean onMenuItemSelected(int featureId, MenuItem item) {\r
58                 switch (item.getItemId()) {\r
59                 case R.id.preference_menu_option:\r
60                         ActivityHelpers.startPreferences(this);\r
61                         return true;\r
62                 }\r
63                 return super.onMenuItemSelected(featureId, item);\r
64         }\r
65 \r
66         @Override\r
67         public boolean onCreateOptionsMenu(Menu menu) {\r
68                 MenuItem prefItem = menu.add(Menu.NONE, R.id.preference_menu_option, Menu.CATEGORY_SYSTEM, R.string.Preferences);\r
69                 prefItem.setIcon(R.drawable.ic_menu_preferences);\r
70                 return true;\r
71         }\r
72 \r
73 }