Guest User

Untitled

a guest
Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. /**
  2. * Setup
  3. * */
  4. @SuppressWarnings("unchecked")
  5. private void setup() throws IOException {
  6.  
  7. device_array = new ArrayList<Device>();
  8.  
  9. //-----------------ACTIONBAR------------------------------------
  10. //activates the default ActionBar
  11. ActionBar actionBar = getActionBar();
  12. actionBar.show();
  13. // set the app icon as an action to go home
  14. actionBar.setDisplayHomeAsUpEnabled(true);
  15.  
  16. //-------------------INTENT--------------------------------------
  17. //get data from Intent
  18. Intent intent = getIntent();
  19. Name = intent.getStringExtra("Projectname");
  20. IP = intent.getStringExtra("RouterIP");
  21. URL = intent.getStringExtra("URL");
  22. Port = intent.getStringExtra("Port");
  23.  
  24. //-------------------TEXTVIEWS+LISTVIEW---------------------------------------
  25. nameproject = (TextView)findViewById(R.id.nameproject);
  26. nameproject.setText("Projektname: "+Name);
  27. routerip = (TextView)findViewById(R.id.routerip);
  28. routerip.setText("KNX/IP-Router-Adresse: "+IP);
  29. port = (TextView)findViewById(R.id.port);
  30. port.setText(":"+Port);
  31. url = (TextView)findViewById(R.id.url);
  32. url.setText("URL: "+URL);
  33.  
  34. //Fill ListView
  35. display_listview();
  36.  
  37. devices = (ListView)findViewById(R.id.deviceList);
  38. adapter = new DeviceAdapter(this,
  39. R.layout.listviewitem_device, device_array);
  40.  
  41. //add a view which is shown if the ListView is empty
  42. devices.setEmptyView(findViewById(R.id.empty_list_view));
  43.  
  44. //Click on item in listview
  45. devices.setOnItemClickListener(new OnItemClickListener(){
  46. @Override
  47. public void onItemClick(AdapterView<?> parent, View view,
  48. int position, long id) {
  49.  
  50. Intent i = new Intent(ProjectView.this, OnOff.class);
  51. i.putExtra("Uniqid","From_ProjectView_Activity");
  52. i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  53. startActivity(i);
  54. }
  55. });
  56. devices.setAdapter(adapter);
  57.  
  58. //-------------------- READ ARRAYLIST-------------------------------
  59. }
  60.  
  61. /**
  62. * Insert Controls
  63. * */
  64. @SuppressWarnings("unchecked")
  65. private void display_listview() {
  66.  
  67. //------------------ READ ARRAYLIST--------------------------------
  68. //read ArrayList which is saved local
  69. //change path to non-root folder
  70. String filePath = context.getFilesDir().getPath().toString()+"/"+Name;
  71. Log.d("FilestreamfromFolder", "Filepath:"+filePath+ " Projektname:"+Name);
  72. File f = new File(filePath);
  73. try
  74. {
  75. FileInputStream fileIn = new FileInputStream(f);
  76. ObjectInputStream in = new ObjectInputStream(fileIn);
  77. XML = (ArrayList<Datapoint>) in.readObject();
  78. Log.d("XML",XML.toString());
  79. in.close();
  80. fileIn.close();
  81. } catch(IOException ioe)
  82. {
  83. ioe.printStackTrace();
  84. return;
  85. } catch(ClassNotFoundException c)
  86. {
  87. Log.d("FILESTREAM", ".Datapoint class not found.");
  88. c.printStackTrace();
  89. return;
  90. }
  91.  
  92. //------------------ FILL DEVICE ARRAY FROM XML--------------------------------
  93. for (int i=0; i<XML.size(); i++) {
  94. if (XML.get(i).getDptID().contains(ValueTemp)) {
  95. Datapoint d = XML.get(i);
  96. device_array.add(new Device(d.getName().toString(), R.drawable.temperature_5));
  97. Log.d("Temperature", d.getName().toString()+" added");
  98. }
  99. }
  100. for (int i=0; i<XML.size(); i++) {
  101. if (XML.get(i).getDptID().contains(ValueLux)) {
  102. Datapoint d = XML.get(i);
  103. device_array.add(new Device(d.getName().toString(), R.drawable.brightness));
  104. Log.d("Brightness", d.getName().toString()+" added");
  105. }
  106. }
  107. for (int i=0; i<XML.size(); i++) {
  108. if (XML.get(i).getDptID().contains(PercentScaling)) {
  109. Datapoint d = XML.get(i);
  110. device_array.add(new Device(d.getName().toString(), R.drawable.lamp));
  111. Log.d("Dimmer", d.getName().toString()+" added");
  112. }
  113. }
  114. for (int i=0; i<XML.size(); i++) {
  115. //check XML file for datapoint 1.001 which demontrates a on/off switch
  116. if (XML.get(i).getDptID().contains(OnOff)) {
  117. Datapoint d = XML.get(i);
  118. device_array.add(new Device(d.getName().toString(), R.drawable.lamp_switch));
  119. Log.d("OnOFF", d.getName().toString()+" added");
  120. }
  121. }
  122. }
  123.  
  124. package XMLParser;
  125.  
  126. import java.io.Serializable;
  127.  
  128. public class Datapoint implements Serializable{
  129.  
  130. /**
  131. *
  132. */
  133. private static final long serialVersionUID = 4917183601569112207L;
  134.  
  135. private String stateBased;
  136. private String name;
  137. private String priority;
  138. private String mainNumber;
  139. private String groupadress;
  140. private String dptID;
  141.  
  142. public Datapoint(){
  143. }
  144.  
  145. public String getMainNumber() {
  146. return mainNumber;
  147. }
  148.  
  149. public void setMainNumber(String mainNumber) {
  150. this.mainNumber = mainNumber;
  151. }
  152.  
  153. public String getName() {
  154. return name;
  155. }
  156.  
  157. public void setName(String name) {
  158. this.name = name;
  159. }
  160.  
  161. public String getStateBased() {
  162. return stateBased;
  163. }
  164.  
  165. public void setStateBased(String stateBased) {
  166. this.stateBased = stateBased;
  167. }
  168.  
  169. public String getPriority() {
  170. return priority;
  171. }
  172.  
  173. public void setPriority(String priority) {
  174. this.priority = priority;
  175. }
  176.  
  177. public String getGroupadress() {
  178. return groupadress;
  179. }
  180.  
  181. public void setGroupadress(String group) {
  182. this.groupadress = convert_groupadress(group);
  183. }
  184.  
  185. public String getDptID() {
  186. return dptID;
  187. }
  188.  
  189. public void setDptID(String dptID) {
  190. this.dptID = dptID;
  191. }
  192.  
  193. @Override
  194. public String toString() {
  195. return "[[" + this.stateBased + "] ["+ this.name + "] [" + this.mainNumber + "]" + " [" + this.dptID
  196. + "] [" + this.priority + "] [" + this.groupadress + " ]]";
  197. }
  198.  
  199. public String convert_groupadress(String groupadress) {
  200. String groupaddress ="";
  201. int grpadr = Integer.parseInt(groupadress);
  202. int first = grpadr / 2048;
  203. int first_res = grpadr-(first*2048);
  204.  
  205. int second = first_res / 256;
  206. int second_res = first_res-(second*256);
  207.  
  208. int third = second_res / 1;
  209. //int third_res = second_res-(third*32);
  210.  
  211. groupaddress = Integer.toString(first) +"/"+ Integer.toString(second) + "/"+ Integer.toString(third);
  212.  
  213. return groupaddress;
  214. }
  215.  
  216. }
  217.  
  218. @Override
  219. public void onItemClick(AdapterView<?> parent, View view,
  220. int position, long id) {
  221.  
  222. DataPoint point = (DataPoint) parent.getAdapter().getItem(position);
  223. String pointName = point.getName();
  224. // TODO: Launch an activity with that name or something.
  225. }
  226.  
  227. //Click on item in listview
  228. devices.setOnItemClickListener(new OnItemClickListener(){
  229. @Override
  230. public void onItemClick(AdapterView<?> parent, View view,
  231. int position, long id) {
  232.  
  233. if(device_array.get(position).getResImage()==R.drawable.brightness){
  234. Intent i0 = new Intent(ProjectView.this, Brightness.class);
  235. i0.putExtra("Uniqid","From_ProjectView_Activity");
  236. i0.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  237. startActivity(i0);
  238. }
  239.  
  240. if(device_array.get(position).getResImage()==R.drawable.temperature_5){
  241. Intent i0 = new Intent(ProjectView.this, Temperature.class);
  242. i0.putExtra("Uniqid","From_ProjectView_Activity");
  243. i0.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  244. startActivity(i0);
  245. }
  246.  
  247. if(device_array.get(position).getResImage()==R.drawable.lamp){
  248. Intent i0 = new Intent(ProjectView.this, Dimmer.class);
  249. i0.putExtra("Uniqid","From_ProjectView_Activity");
  250. i0.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  251. startActivity(i0);
  252. }
  253.  
  254. if(device_array.get(position).getResImage()==R.drawable.lamp_switch){
  255. Intent i0 = new Intent(ProjectView.this, OnOff.class);
  256. i0.putExtra("Uniqid","From_ProjectView_Activity");
  257. i0.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  258. startActivity(i0);
  259. }
  260. }
  261. });
  262.  
  263. TextView tv = (TextView) v.findViewById(R.id.contacts_name);
  264. String savedname = tv.getText().toString();
  265.  
  266. public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3)
  267. { // do something
  268. }
Add Comment
Please, Sign In to add comment