The final version for lede-gui (the phone app for device registration)
[iot2.git] / others / lede-gui / src / main / java / com / example / lede2 / RelationActivity.java
index a87b490ce2d59a806d7ad98c3fec5d25ecc759da..201e26ead0394338375de2a1140f3346b1a759e0 100644 (file)
@@ -1,89 +1,89 @@
-package com.example.lede2;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-import android.view.Gravity;
-import android.view.View;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
-import android.widget.EditText;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class RelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener {
-
-    Button addButton;
-    Button deleteButton;
-    EditText databaseInfo;
-    EditText idSource;
-    EditText idDestination;
-    private SSH_MySQL ssh;//Connection object between Android & Host
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_relation);
-
-        addButton = (Button) findViewById(R.id.addButton);
-        deleteButton = (Button) findViewById(R.id.delButton);
-        databaseInfo = (EditText)findViewById(R.id.textInfoComm);
-        idSource = (EditText)findViewById(R.id.id_source);
-        idDestination = (EditText)findViewById(R.id.id_destination);
-
-        addButton.setOnClickListener(this);
-        deleteButton.setOnClickListener(this);
-        databaseInfo.setOnFocusChangeListener(this);
-        idSource.setOnFocusChangeListener(this);
-        idDestination.setOnFocusChangeListener(this);
-        ssh = new SSH_MySQL();
-        // Set config text from file for device
-        try {
-            InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_COMM_FILE);
-            int size = is.available();
-            byte[] buffer = new byte[size];
-            is.read(buffer);
-            is.close();
-            String text = new String(buffer);
-            databaseInfo.setGravity(Gravity.LEFT);
-            databaseInfo.setText(text);
-            Log.d("LOADINGFILE", "Add comm info file is already loaded!");
-        } catch (IOException ex) {
-            Log.d("LOADINGFILE", "Add comm info file is NOT loaded!");
-            ex.printStackTrace();
-        }
-    }
-
-    @Override
-    public void onClick(View v) {
-        if(v == addButton){
-            // 1) Create a new file and insert the configuration
-            // 2) Run iotinstaller code for communication/relation installation
-            // 3) Remove the existing config file
-            ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " +
-                    MainActivity.DEF_MYSQL_CONFIG_FILE + ";" +
-                    MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" +
-                    "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE);
-            finish();
-        }
-        if(v == deleteButton){
-            // Delete a communication/relation entry
-            ssh.execute(MainActivity.DEF_DELETE_RELATION_CMD + " " + idSource.getText().toString()
-                    + " " + idDestination.getText().toString());
-            finish();
-        }
-    }
-
-    @Override
-    public void onFocusChange(View view, boolean hasFocus) {
-        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-        if (hasFocus) {
-            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
-        } else {
-            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
-        }
-    }
-
-}
+package com.example.lede2;\r
+\r
+import android.content.Context;\r
+import android.os.Bundle;\r
+import android.support.v7.app.AppCompatActivity;\r
+import android.util.Log;\r
+import android.view.Gravity;\r
+import android.view.View;\r
+import android.view.inputmethod.InputMethodManager;\r
+import android.widget.Button;\r
+import android.widget.EditText;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+public class RelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener {\r
+\r
+    Button addButton;\r
+    Button deleteButton;\r
+    EditText databaseInfo;\r
+    EditText idSource;\r
+    EditText idDestination;\r
+    private SSH_MySQL ssh;//Connection object between Android & Host\r
+\r
+    @Override\r
+    protected void onCreate(Bundle savedInstanceState) {\r
+        super.onCreate(savedInstanceState);\r
+        setContentView(R.layout.activity_relation);\r
+\r
+        addButton = (Button) findViewById(R.id.addButton);\r
+        deleteButton = (Button) findViewById(R.id.delButton);\r
+        databaseInfo = (EditText)findViewById(R.id.textInfoComm);\r
+        idSource = (EditText)findViewById(R.id.id_source);\r
+        idDestination = (EditText)findViewById(R.id.id_destination);\r
+\r
+        addButton.setOnClickListener(this);\r
+        deleteButton.setOnClickListener(this);\r
+        databaseInfo.setOnFocusChangeListener(this);\r
+        idSource.setOnFocusChangeListener(this);\r
+        idDestination.setOnFocusChangeListener(this);\r
+        ssh = new SSH_MySQL();\r
+        // Set config text from file for device\r
+        try {\r
+            InputStream is = getAssets().open(MainActivity.DEF_INSTALL_ADDRESS_FILE);\r
+            int size = is.available();\r
+            byte[] buffer = new byte[size];\r
+            is.read(buffer);\r
+            is.close();\r
+            String text = new String(buffer);\r
+            databaseInfo.setGravity(Gravity.LEFT);\r
+            databaseInfo.setText(text);\r
+            Log.d("LOADINGFILE", "Add comm info file is already loaded!");\r
+        } catch (IOException ex) {\r
+            Log.d("LOADINGFILE", "Add comm info file is NOT loaded!");\r
+            ex.printStackTrace();\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void onClick(View v) {\r
+        if(v == addButton){\r
+            // 1) Create a new file and insert the configuration\r
+            // 2) Run iotinstaller code for communication/relation installation\r
+            // 3) Remove the existing config file\r
+            ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " +\r
+                    MainActivity.DEF_MYSQL_CONFIG_FILE + ";" +\r
+                    MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" +\r
+                    "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE);\r
+            finish();\r
+        }\r
+        if(v == deleteButton){\r
+            // Delete a communication/relation entry\r
+            ssh.execute(MainActivity.DEF_DELETE_RELATION_CMD + " " + idSource.getText().toString()\r
+                    + " " + idDestination.getText().toString());\r
+            finish();\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void onFocusChange(View view, boolean hasFocus) {\r
+        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
+        if (hasFocus) {\r
+            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);\r
+        } else {\r
+            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);\r
+        }\r
+    }\r
+\r
+}\r