Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. @Override
  2. public void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. Intent intent = getIntent();
  5. actu_ip = intent.getStringExtra(IPEntry.ACTUALSMARTIP);
  6. setContentView(R.layout.act_ipcontrol);
  7.  
  8. mainListView = (ListView) findViewById( R.id.mainListView );
  9. String[] options = new String[] { "All in to 1", "Spare"};
  10.  
  11. ArrayList<String> optionsList = new ArrayList<String>();
  12. optionsList.addAll( Arrays.asList(options) );
  13. listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, optionsList);
  14. mainListView.setAdapter( listAdapter );
  15.  
  16. try {
  17. Toast.makeText(IPControl.this, "Please wait...Connecting...", Toast.LENGTH_SHORT).show();
  18. new AsyncAction().execute();
  19. } catch(Exception e) {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. private class AsyncAction extends AsyncTask<String, Void, String> {
  25. protected String doInBackground(String... args) {
  26. try {
  27. InetAddress serverAddr = InetAddress.getByName(actu_ip);
  28. socket = new Socket(serverAddr, REDIRECTED_SERVERPORT);
  29. OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
  30. BufferedWriter bw = new BufferedWriter(osw);
  31. out = new PrintWriter(bw, true);
  32. in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  33. while (! in .ready());
  34. readBuffer();
  35. out.println("rootrn");
  36. while (! in .ready());
  37. readBuffer();
  38. out.println("rootrn");
  39. while (! in .ready());
  40. readBuffer();
  41. out.println("[verbose,offrn");
  42. while (! in .ready());
  43. String msg = "";
  44. while ( in .ready()) {
  45. msg = msg + (char) in .read();
  46. }
  47. } catch (UnknownHostException e) {
  48. e.printStackTrace();
  49. } catch (IOException e) {
  50. e.printStackTrace();
  51. }
  52.  
  53. return null;//returns what you want to pass to the onPostExecute()
  54. }
  55.  
  56. protected void onPostExecute(String result) {
  57.  
  58. Toast.makeText(IPControl.this, "Connected", Toast.LENGTH_SHORT).show();
  59.  
  60. //results the data returned from doInbackground
  61.  
  62. IPControl.this.data = result;
  63.  
  64. }
  65. }
  66.  
  67. private String readBuffer() throws IOException {
  68. String msg = "";
  69.  
  70. while(in.ready()) {
  71. msg = msg + (char)in.read();
  72. }
  73. //System.out.print(msg);
  74. if(msg.indexOf("SNX_COM> ") != -1) return msg.substring(0, msg.indexOf("SNX_COM> "));
  75. else if(msg.indexOf("SCX_COM> ") != -1) return msg.substring(0, msg.indexOf("SCX_COM> "));
  76. else return msg;
  77. }
  78. }
  79.  
  80. public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
  81. long arg3) {
  82.  
  83. try {
  84. new AsyncAction1().execute();
  85. } catch(Exception e) {
  86. e.printStackTrace();
  87. }
  88. }
  89.  
  90. private class AsyncAction1 extends AsyncTask<String, Void, String> {
  91. protected String doInBackground(String... args) {
  92. try {
  93. out.println("[c,l#,i1,o*rn");
  94. //System.out.print("rootrn");
  95. while(! in .ready());
  96.  
  97.  
  98. } catch (UnknownHostException e) {
  99. e.printStackTrace();
  100. } catch (IOException e) {
  101. e.printStackTrace();
  102. }
  103.  
  104. return null;//returns what you want to pass to the onPostExecute()
  105. }
  106.  
  107. protected void onPostExecute(String result) {
  108.  
  109. //results the data returned from doInbackground
  110. Toast.makeText(IPControl.this, "Command Sent", Toast.LENGTH_SHORT).show();
  111.  
  112. IPControl.this.data = result;
  113.  
  114. }
  115. }
  116.  
  117. mainListView.setAdapter( listAdapter );
  118. mainListView.setOnItemClickListener(new OnItemClickListener(){
  119. public void onItemClick(AdapterView<?> parent, View view, int position,
  120. long id) {
  121.  
  122. try {
  123. new AsyncAction1().execute();
  124. }catch(Exception e) {
  125. e.printStackTrace();
  126. }
  127. });
  128.  
  129. @Override
  130. public void onCreate(Bundle savedInstanceState) {
  131. super.onCreate(savedInstanceState);
  132. Intent intent = getIntent();
  133. actu_ip = intent.getStringExtra(IPEntry.ACTUALSMARTIP);
  134. setContentView(R.layout.act_ipcontrol);
  135.  
  136. mainListView = (ListView) findViewById( R.id.mainListView );
  137. final String[] options = new String[] { "All in to 1", "Spare"};
  138.  
  139. ArrayList<String> optionsList = new ArrayList<String>();
  140. optionsList.addAll( Arrays.asList(options) );
  141. listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, optionsList);
  142. mainListView.setAdapter( listAdapter );
  143. mainListView.setOnItemClickListener(new OnItemClickListener(){
  144.  
  145. public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
  146. try {
  147. if(pos == 0) {
  148. AsyncAction1 a = new AsyncAction1();
  149. a.setCmd("[c,l#,i1,o*rn");
  150. a.execute();
  151. }
  152. } catch(Exception e) {
  153. e.printStackTrace();
  154. }
  155. }
  156. });
  157.  
  158. private class AsyncAction1 extends AsyncTask<String, Void, String> {
  159. String cmd;
  160.  
  161. public void setCmd(String c) {
  162. cmd = c;
  163. }
  164.  
  165. protected String doInBackground(String... args) {
  166. try {
  167. out.println(cmd);
  168. //System.out.print("rootrn");
  169. while(! in .ready());
  170. } catch (UnknownHostException e) {
  171. e.printStackTrace();
  172. } catch (IOException e) {
  173. e.printStackTrace();
  174. }
  175. return null;//returns what you want to pass to the onPostExecute()
  176. }
  177.  
  178. protected void onPostExecute(String result) {
  179.  
  180. //results the data returned from doInbackground
  181. Toast.makeText(IPControl.this, "Command Sent", Toast.LENGTH_SHORT).show();
  182.  
  183. IPControl.this.data = result;
  184. }
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement