Sfoglia il codice sorgente

WIFI Socket Connect,Receive,Send Class Create / Control ,Set 메소드 추가

june9152 5 anni fa
parent
commit
eca2d44998

+ 1 - 0
.idea/dictionaries/parkyj.xml

@@ -4,6 +4,7 @@
4 4
       <w>bluecell</w>
5 5
       <w>infor</w>
6 6
       <w>listview</w>
7
+      <w>portbutton</w>
7 8
     </words>
8 9
   </dictionary>
9 10
 </component>

+ 54 - 4
app/src/main/java/com/example/repeater/ListViewAdapter.java

@@ -7,6 +7,8 @@ import android.view.LayoutInflater;
7 7
 import android.view.View;
8 8
 import android.view.ViewGroup;
9 9
 import android.widget.BaseAdapter;
10
+import android.widget.Button;
11
+import android.widget.EditText;
10 12
 import android.widget.ImageView;
11 13
 import android.widget.TextView;
12 14
 
@@ -41,14 +43,61 @@ public class ListViewAdapter extends BaseAdapter {
41 43
 
42 44
         // 화면에 표시될 View(Layout이 inflate된)으로부터 위젯에 대한 참조 획득
43 45
         TextView descTextView = (TextView) convertView.findViewById(R.id.textView13) ;
44
-        TextView valTextView = (TextView) convertView.findViewById(R.id.textView14) ;
46
+        TextView valTextView  = (TextView) convertView.findViewById(R.id.textView14) ;
47
+        EditText valeditText  = (EditText) convertView.findViewById(R.id.editText) ;
48
+        EditText valeditText1  = (EditText) convertView.findViewById(R.id.editText1) ;
49
+        EditText valeditText2  = (EditText) convertView.findViewById(R.id.editText2) ;
50
+        Button valbutton      = (Button) convertView.findViewById(R.id.button) ;
45 51
 
46 52
         // Data Set(listViewItemList)에서 position에 위치한 데이터 참조 획득
47 53
         ListViewItem listViewItem = listViewItemList.get(position);
48
-
54
+        valTextView.setVisibility(View.VISIBLE);
55
+        valeditText.setVisibility(View.VISIBLE);
56
+        valbutton.setVisibility(View.VISIBLE);
57
+        valeditText1.setVisibility(View.VISIBLE);
58
+        valeditText2.setVisibility(View.VISIBLE);
49 59
         // 아이템 내 각 위젯에 데이터 반영
50 60
         descTextView.setText(listViewItem.getDesc());
51
-        valTextView.setText(listViewItem.getVal());
61
+        if(listViewItem.getMode() == "READ") {
62
+            valTextView.setText(listViewItem.getVal());
63
+            valeditText.setVisibility(View.INVISIBLE);
64
+            valeditText1.setVisibility(View.INVISIBLE);
65
+            valeditText2.setVisibility(View.INVISIBLE);
66
+            valbutton.setVisibility(View.INVISIBLE);
67
+
68
+        }
69
+        else if(listViewItem.getMode() == "EDIT") {
70
+            valTextView.setVisibility(View.INVISIBLE);
71
+            valeditText.setText(listViewItem.getVal());
72
+            valeditText1.setVisibility(View.INVISIBLE);
73
+            valeditText2.setVisibility(View.INVISIBLE);
74
+            valbutton.setVisibility(View.INVISIBLE);
75
+        }
76
+        else if(listViewItem.getMode() == "EDIT2") {
77
+            valTextView.setVisibility(View.INVISIBLE);
78
+            valeditText1.setVisibility(View.VISIBLE);
79
+            valeditText2.setVisibility(View.VISIBLE);
80
+            valeditText.setVisibility(View.INVISIBLE);
81
+            valbutton.setVisibility(View.INVISIBLE);
82
+            valeditText1.setText(listViewItem.getVal());
83
+            valeditText2.setText(listViewItem.getVal());
84
+        }
85
+        else if(listViewItem.getMode() == "BUTTON") {
86
+            valTextView.setVisibility(View.INVISIBLE);
87
+            valeditText.setVisibility(View.INVISIBLE);
88
+            valeditText1.setVisibility(View.INVISIBLE);
89
+            valeditText2.setVisibility(View.INVISIBLE);
90
+            valbutton.setVisibility(View.VISIBLE);
91
+            valbutton.setText(listViewItem.getVal());
92
+        }else{
93
+            valeditText1.setVisibility(View.INVISIBLE);
94
+            valeditText2.setVisibility(View.INVISIBLE);
95
+            valTextView.setVisibility(View.INVISIBLE);
96
+            valeditText.setVisibility(View.INVISIBLE);
97
+            valbutton.setVisibility(View.VISIBLE);
98
+            //   valbutton.setText(listViewItem.getVal());
99
+        }
100
+
52 101
 //        descTextView.setBackgroundColor();
53 102
         return convertView;
54 103
     }
@@ -66,10 +115,11 @@ public class ListViewAdapter extends BaseAdapter {
66 115
     }
67 116
 
68 117
     // 아이템 데이터 추가를 위한 함수. 개발자가 원하는대로 작성 가능.
69
-    public void addItem(String desc,String val) {
118
+    public void addItem(String desc,String val,String mode) {
70 119
         ListViewItem item = new ListViewItem();
71 120
 
72 121
         item.setDesc(desc);
122
+        item.setMode(mode);
73 123
         item.setVal(val);
74 124
 
75 125
         listViewItemList.add(item);

+ 11 - 0
app/src/main/java/com/example/repeater/ListViewItem.java

@@ -4,10 +4,21 @@ import android.graphics.drawable.Drawable;
4 4
 import android.support.v7.app.AppCompatActivity;
5 5
 import android.os.Bundle;
6 6
 
7
+
7 8
 public class ListViewItem {
8 9
     private String descStr ;
9 10
     private String valStr ;
10 11
     private String colorStr;
12
+    private String mode;
13
+
14
+    public String getMode() {
15
+        return mode;
16
+    }
17
+
18
+    public void setMode(String mode) {
19
+        this.mode = mode;
20
+    }
21
+
11 22
     public void setDesc(String desc) {
12 23
         descStr = desc ;
13 24
     }

+ 165 - 158
app/src/main/java/com/example/repeater/MainActivity.java

@@ -4,6 +4,9 @@ import android.support.v7.app.AppCompatActivity;
4 4
 import android.os.Bundle;
5 5
 import android.util.Log;
6 6
 import android.view.View;
7
+import android.view.ViewGroup;
8
+import android.widget.BaseAdapter;
9
+import android.widget.Button;
7 10
 import android.widget.ImageButton;
8 11
 import android.widget.ListView;
9 12
 import android.widget.TextView;
@@ -21,33 +24,19 @@ import java.net.SocketAddress;
21 24
 import java.util.ArrayList;
22 25
 import java.util.HashMap;
23 26
 
24
-public class MainActivity extends AppCompatActivity {
25
-    private ArrayList<HashMap<String,String>> Data = new ArrayList<HashMap<String, String>>();
26
-    private HashMap<String,String> InputData1 = new HashMap<>();
27
-    private HashMap<String,String> InputData2 = new HashMap<>();
28
-    private HashMap<String,String> InputData3 = new HashMap<>();
29
-    private HashMap<String,String> InputData4 = new HashMap<>();
30
-    private HashMap<String,String> InputData5 = new HashMap<>();
31
-    private HashMap<String,String> InputData6 = new HashMap<>();
32
-    private HashMap<String,String> InputData7 = new HashMap<>();
33
-    private HashMap<String,String> InputData8 = new HashMap<>();
34
-    private HashMap<String,String> InputData9 = new HashMap<>();
35
-    private HashMap<String,String> InputData10 = new HashMap<>();
36
-    private HashMap<String,String> InputData11 = new HashMap<>();
37
-    private HashMap<String,String> InputData12 = new HashMap<>();
27
+public class MainActivity extends AppCompatActivity implements Runnable {
38 28
     private ListView listview_info;
39 29
     private ListView listview_rf;
40
-    static final String[] LIST_MENU = {"LIST1", "LIST2", "LIST3"} ;
30
+    private ListView listview_info_set;
31
+    private ListView listview_rf_set;
41 32
     /*** WIFI Start***/
42 33
     BufferedReader in;      //서버로부터 온 데이터를 읽는다.
43 34
     PrintWriter out;        //서버에 데이터를 전송한다.
44
-    TextView input;
45
-    TextView output;
35
+    TextView textView_status;
46 36
     String data;
47
-    ToggleButton button;
37
+    Button button_port,button_control;
48 38
     private Socket socket;  //소켓생성
49 39
     /*** WIFI END***/
50
-    private ArrayList<ListViewItem> listViewItemList = new ArrayList<ListViewItem>() ;
51 40
 
52 41
 
53 42
     ImageButton imageButton01;
@@ -61,174 +50,192 @@ public class MainActivity extends AppCompatActivity {
61 50
 
62 51
         imageButton01 = findViewById(R.id.imageButton01);
63 52
         imageButton02 = findViewById(R.id.imageButton02);
53
+
64 54
         listview_info = findViewById(R.id.listview_info);
65 55
         listview_rf = findViewById(R.id.listview_rf);
66
-        imageButton02 = findViewById(R.id.imageButton02);
56
+        listview_info_set = findViewById(R.id.listview_info_set);
57
+        listview_rf_set = findViewById(R.id.listview_rf_set);
58
+
67 59
 
68
-        input = findViewById(R.id.input);
69
-        output = findViewById(R.id.output);
70
-        button = findViewById(R.id.button);
60
+        imageButton02 = findViewById(R.id.imageButton02);
71 61
 
62
+        button_port = findViewById(R.id.button_port);
63
+        button_control = findViewById(R.id.button_control);
64
+        textView_status = findViewById(R.id.textView_status);
72 65
         ListView listview ;
73 66
         ListViewAdapter adapter_infor;
74 67
         ListViewAdapter adapter_rf;
75
-
68
+        ListViewAdapter adapter_info_set;
69
+        ListViewAdapter adapter_rf_set;
76 70
 
77 71
         // Adapter 생성
78 72
         adapter_infor = new ListViewAdapter() ;
79 73
         adapter_rf = new ListViewAdapter();
74
+        adapter_info_set = new ListViewAdapter() ;
75
+        adapter_rf_set = new ListViewAdapter();
76
+
80 77
         // 리스트뷰 참조 및 Adapter달기
81 78
         listview = (ListView) findViewById(R.id.listview_info);
82 79
         listview.setAdapter(adapter_infor);
83 80
 
84 81
 
85
-        adapter_infor.addItem("firm info.","0.1Ver");
86
-        adapter_infor.addItem("FPGA Ver.","0.2Ver");
87
-        adapter_infor.addItem("F/W Ver.","0.3Ver");
88
-        adapter_infor.addItem("Config No.","0.4Ver");
89
-        adapter_infor.addItem("Sub Frame No.","0.5Ver");
90
-        adapter_infor.addItem("CH1 TTG","0.6Ver");
91
-        adapter_infor.addItem("CH1 RTG","0.7Ver");
92
-        adapter_infor.addItem("CH2 TTG","0.8Ver");
93
-        adapter_infor.addItem("CH2 RTG","0.9Ver");
94
-        adapter_infor.addItem("CH2 Polarity","1.1Ver");
95
-        adapter_infor.addItem("CH2 Default","1.2Ver");
96
-        adapter_infor.addItem("Auto Config","1.3Ver");
82
+        adapter_infor.addItem("firm info.","0.1Ver","READ");
83
+        adapter_infor.addItem("FPGA Ver.","0.2Ver","READ");
84
+        adapter_infor.addItem("F/W Ver.","0.3Ver","READ");
85
+        adapter_infor.addItem("Config No.","0.4Ver","READ");
86
+        adapter_infor.addItem("Sub Frame No.","0.5Ver","READ");
87
+        adapter_infor.addItem("CH1 TTG","0.6Ver","READ");
88
+        adapter_infor.addItem("CH1 RTG","0.7Ver","READ");
89
+        adapter_infor.addItem("CH2 TTG","0.8Ver","READ");
90
+        adapter_infor.addItem("CH2 RTG","0.9Ver","READ");
91
+        adapter_infor.addItem("CH1 Polarity","1.1Ver","READ");
92
+        adapter_infor.addItem("CH1 Default","1.2Ver","READ");
93
+        adapter_infor.addItem("CH2 Polarity","1.1Ver","READ");
94
+        adapter_infor.addItem("CH2 Default","1.2Ver","READ");
95
+        adapter_infor.addItem("Auto Config","1.3Ver","READ");
96
+
97
+        listview = (ListView) findViewById(R.id.listview_info_set);
98
+        listview.setAdapter(adapter_info_set);
99
+        adapter_info_set.addItem("firm info.","0.1Ver","READ");
100
+        adapter_info_set.addItem("FPGA Ver.","0.2Ver","READ");
101
+        adapter_info_set.addItem("F/W Ver.","0.3Ver","READ");
102
+        adapter_info_set.addItem("Config No.","0.4Ver","EDIT");
103
+        adapter_info_set.addItem("Sub Frame No.","0.5Ver","EDIT");
104
+        adapter_info_set.addItem("CH1 TTG","0.6Ver","EDIT");
105
+        adapter_info_set.addItem("CH1 RTG","0.7Ver","EDIT");
106
+        adapter_info_set.addItem("CH2 TTG","0.8Ver","EDIT");
107
+        adapter_info_set.addItem("CH2 RTG","0.9Ver","EDIT");
108
+        adapter_info_set.addItem("CH1 Polarity","1.1Ver","BUTTON");
109
+        adapter_info_set.addItem("CH1 Default","1.2Ver","BUTTON");
110
+        adapter_info_set.addItem("CH2 Polarity","1.1Ver","BUTTON");
111
+        adapter_info_set.addItem("CH2 Default","1.2Ver","BUTTON");
112
+        adapter_info_set.addItem("Auto Config","1.3Ver","BUTTON");
97 113
 
98 114
         listview = (ListView) findViewById(R.id.listview_rf);
99 115
         listview.setAdapter(adapter_rf);
100
-        adapter_rf.addItem("input ATT","0.1Ver");
101
-        adapter_rf.addItem("Output ATT","0.2Ver");
102
-        adapter_rf.addItem("Input Offset ATT","0.3Ver");
103
-        adapter_rf.addItem("Output Offset ATT","0.4Ver");
104
-        adapter_rf.addItem("Gain(dB)","0.5Ver");
105
-        adapter_rf.addItem("ALC Level","0.6Ver");
106
-        adapter_rf.addItem("PA Enable","0.7Ver");
107
-        adapter_rf.addItem("EX PA Enable","0.8Ver");
108
-        adapter_rf.addItem("RF PLL Freq","0.9Ver");
109
-        adapter_rf.addItem("AGD Level","1.1Ver");
110
-        adapter_rf.addItem("ISO Level","1.2Ver");
111
-        adapter_rf.addItem("Temperature","1.3Ver");
112
-/*
113
-
114
-
115
-        listview_info =(ListView)findViewById(R.id.listview_info);
116
-
117
-        //데이터 초기화
118
-        InputData1.put("fw_info","firm info.");
119
-        Data.add(InputData1);
120
-        InputData2.put("fw_info","FPGA Ver.");
121
-        Data.add(InputData2);
122
-        InputData3.put("fw_info","F/W Ver.");
123
-        Data.add(InputData3);
124
-        InputData4.put("fw_info","Config No.");
125
-        Data.add(InputData4);
126
-        InputData5.put("fw_info","Sub Frame No.");
127
-        Data.add(InputData5);
128
-        InputData6.put("fw_info","CH1 TTG");
129
-        Data.add(InputData6);
130
-        InputData7.put("fw_info","CH1 RTG");
131
-        Data.add(InputData7);
132
-        InputData8.put("fw_info","CH2 TTG");
133
-        Data.add(InputData8);
134
-        InputData9.put("fw_info","CH2 RTG");
135
-        Data.add(InputData9);
136
-        InputData10.put("fw_info","CH2 Polarity");
137
-        Data.add(InputData10);
138
-        InputData11.put("fw_info","CH2 Default");
139
-        Data.add(InputData11);
140
-        InputData12.put("fw_info","Auto Config");
141
-        Data.add(InputData12);
142
-
143
-        //simpleAdapter 생성
144
-        SimpleAdapter simpleAdapter = new SimpleAdapter(this,Data,android.R.layout.simple_list_item_2,new String[]{"fw_info"},new int[]{android.R.id.text1});
145
-        listview_info.setAdapter(simpleAdapter);
146
-//        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2, LIST_MENU) ;
147
-//        listview_info.setAdapter(adapter);
148
-*/
149
-// 버튼을 누르는 이벤트 발생, 이벤트 제어문이기 때문에 이벤트 발생 때마다 발동된다. 시스템이 처리하는 부분이 무한루프문에
150
-//있더라도 이벤트가 발생하면 자동으로 실행된다.
151
-        button.setOnClickListener(new View.OnClickListener() {
152
-            public void onClick(View v) {
153
-                new Thread() {
154
-                    public void run() {
155
-                        String data = input.getText().toString(); //글자입력칸에 있는 글자를 String 형태로 받아서 data에 저장
156
-                        Log.w("NETWORK", " " + data);
157
-                        if (data != null) { //만약 데이타가 아무것도 입력된 것이 아니라면
158
-                            out.println(data); //data를 stream 형태로 변형하여 전송. 변환내용은 쓰레드에 담겨 있다.
159
-
160
-                        }
161
-                    }
162
-                }.start();
163
-
164
-            }
165
-        });
166
-
167
-        Thread worker = new Thread() {    //worker 를 Thread 로 생성
168
-            public void run() { //스레드 실행구문
169
-                try {
170
-//소켓을 생성하고 입출력 스트립을 소켓에 연결한다.
171
-                    SocketAddress remoteAddr=new InetSocketAddress("192.168.10.4",4000);
172
-                    Socket socket=new Socket();
173
-                    socket.connect(remoteAddr); //remoteAddr
174
-//                    br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
175
-//                    out=new BufferedOutputStream(socket.getOutputStream()); //output stream
176
-                    in=new BufferedReader(new InputStreamReader(socket.getInputStream(),"EUC_KR")); //input stream
177
-//                    socket = new Socket("192.168.2.38", 9999); //소켓생성
178
-                    out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"EUC_KR")),true);
179
-
180
-
181
-
182
-
183
-//                    out = new PrintWriter(socket.getOutputStream(), true); //데이터를 전송시 stream 형태로 변환하여                                                                                                                       //전송한다.
184
-//                    in = new BufferedReader(new InputStreamReader(
185
-//                            socket.getInputStream())); //데이터 수신시 stream을 받아들인다.
186
-                    Log.w("NETWORK4", "set Complete " + data);
187
-                } catch (IOException e) {
188
-                    e.printStackTrace();
189
-                }
190
-
191
-//소켓에서 데이터를 읽어서 화면에 표시한다.
192
-                try {
193
-                    while (true) {
194
-                        data = in.readLine(); // in으로 받은 데이타를 String 형태로 읽어 data 에 저장
195
-                        output.post(new Runnable() {
196
-                            public void run() {
197
-                                Log.w("NETWORK2", " " + data);
198
-                                output.setText(data); //글자출력칸에 서버가 보낸 메시지를 받는다.
199
-                            }
200
-                        });
201
-                    }
202
-                } catch (Exception e) {
203
-                    Log.w("NETWORK3", "Error Occur!! " + data);
204
-                }
205
-            }
206
-        };
207
-        worker.start();  //onResume()에서 실행.
208
-
209
-
116
+        adapter_rf.addItem("input ATT","0.1Ver","READ");
117
+        adapter_rf.addItem("Output ATT","0.2Ver","READ");
118
+        adapter_rf.addItem("Input Offset ATT","0.3Ver","READ");
119
+        adapter_rf.addItem("Output Offset ATT","0.4Ver","READ");
120
+        adapter_rf.addItem("Gain(dB)","0.5Ver","READ");
121
+        adapter_rf.addItem("ALC Level","0.6Ver","READ");
122
+        adapter_rf.addItem("PA Enable","0.7Ver","READ");
123
+        adapter_rf.addItem("EX PA Enable","0.8Ver","READ");
124
+        adapter_rf.addItem("RF PLL Freq","0.9Ver","READ");
125
+        adapter_rf.addItem("AGD Level","1.1Ver","READ");
126
+        adapter_rf.addItem("ISO Level","1.2Ver","READ");
127
+        adapter_rf.addItem("Temperature","1.3Ver","READ");
128
+
129
+        listview = (ListView) findViewById(R.id.listview_rf_set);
130
+        listview.setAdapter(adapter_rf_set);
131
+        adapter_rf_set.addItem("input ATT","","EDIT2");
132
+        adapter_rf_set.addItem("Output ATT","","EDIT2");
133
+        adapter_rf_set.addItem("Input Offset ATT","","EDIT2");
134
+        adapter_rf_set.addItem("Output Offset ATT","","EDIT2");
135
+        adapter_rf_set.addItem("Gain(dB)","","EDIT2");
136
+        adapter_rf_set.addItem("ALC Level","","EDIT2");
137
+        adapter_rf_set.addItem("PA Enable","0.7Ver","BUTTON");
138
+        adapter_rf_set.addItem("EX PA Enable","0.8Ver","BUTTON");
139
+        adapter_rf_set.addItem("RF PLL Freq","","EDIT");
140
+        adapter_rf_set.addItem("AGD Level","","EDIT");
141
+        adapter_rf_set.addItem("ISO Level","1.2Ver","READ");
142
+        adapter_rf_set.addItem("Temperature","1.3Ver","READ");
210 143
 
211 144
 
212
-    }
213
-    @Override
214
-    protected void onStop() {  //앱 종료시
215
-        super.onStop();
216
-        try {
217
-            socket.close(); //소켓을 닫는다.
218
-        } catch (IOException e) {
219
-            e.printStackTrace();
145
+// 버튼을 누르는 이벤트 발생, 이벤트 제어문이기 때문에 이벤트 발생 때마다 발동된다. 시스템이 처리하는 부분이 무한루프문에
146
+//있더라도 이벤트가 발생하면 자동으로 실행된다.
147
+        try{
148
+            Runnable start = new MainActivity();
149
+            Thread T = new Thread(start);
150
+            T.start();
151
+            Log.d("MainActivity / 쓰레드 실행","성공");
152
+        }catch (Exception e){
153
+            Log.e("MainActivity / 쓰레드 실행","실패");
220 154
         }
155
+
221 156
     }
222 157
     public void onClick(View view) {
223 158
         switch(view.getId()) {
159
+            case R.id.button_port:
160
+                if(button_port.getText() == "Port Close")
161
+                    button_port.setText("Port Open");
162
+                else
163
+                    button_port.setText("Port Close");
164
+                break;
165
+            case R.id.button_control:
166
+                if(button_control.getText() == "Status") {
167
+                    button_control.setText("Control");
168
+                    textView_status.setText("Status");
169
+                    if(listview_info_set.getVisibility() == view.VISIBLE) {
170
+                        listview_info.setVisibility(view.VISIBLE);
171
+                        listview_info_set.setVisibility(view.INVISIBLE);
172
+                        listview_rf.setVisibility(view.INVISIBLE);
173
+                        listview_rf_set.setVisibility(view.INVISIBLE);
174
+                    }else{
175
+                        listview_rf.setVisibility(view.VISIBLE);
176
+                        listview_rf_set.setVisibility(view.INVISIBLE);
177
+                        listview_info.setVisibility(view.INVISIBLE);
178
+                        listview_info_set.setVisibility(view.INVISIBLE);
179
+                    }
180
+                }
181
+                else {
182
+                    button_control.setText("Status");
183
+                    textView_status.setText("Control");
184
+                    if(listview_info.getVisibility() == view.VISIBLE) {
185
+                        listview_info.setVisibility(view.INVISIBLE);
186
+                        listview_info_set.setVisibility(view.VISIBLE);
187
+                        listview_rf.setVisibility(view.INVISIBLE);
188
+                        listview_rf_set.setVisibility(view.INVISIBLE);
189
+                    }else{
190
+                        listview_rf.setVisibility(view.INVISIBLE);
191
+                        listview_rf_set.setVisibility(view.VISIBLE);
192
+                        listview_info.setVisibility(view.INVISIBLE);
193
+                        listview_info_set.setVisibility(view.INVISIBLE);
194
+                    }
195
+                }
196
+                break;
224 197
             case R.id.imageButton01:
225
-                listview_info.setVisibility(view.VISIBLE);
226
-                listview_rf.setVisibility(view.INVISIBLE);
198
+                if(textView_status.getText() != "Control") {
199
+                    listview_info.setVisibility(view.VISIBLE);
200
+                    listview_rf.setVisibility(view.INVISIBLE);
201
+                    listview_info_set.setVisibility(view.INVISIBLE);
202
+
203
+                    listview_rf_set.setVisibility(view.INVISIBLE);
204
+                }else{
205
+                    listview_info.setVisibility(view.INVISIBLE);
206
+                    listview_rf.setVisibility(view.INVISIBLE);
207
+                    listview_rf_set.setVisibility(view.INVISIBLE);
208
+
209
+                    listview_info_set.setVisibility(view.VISIBLE);
210
+                }
227 211
                 break;
228 212
             case R.id.imageButton02:
229
-                listview_info.setVisibility(view.INVISIBLE);
230
-                listview_rf.setVisibility(view.VISIBLE);
213
+                if(textView_status.getText() != "Control") {
214
+                    listview_info.setVisibility(view.INVISIBLE);
215
+                    listview_info_set.setVisibility(view.INVISIBLE);
216
+                    listview_rf_set.setVisibility(view.INVISIBLE);
217
+
218
+                    listview_rf.setVisibility(view.VISIBLE);
219
+                }else{
220
+                    listview_info.setVisibility(view.INVISIBLE);
221
+                    listview_info_set.setVisibility(view.INVISIBLE);
222
+                    listview_rf_set.setVisibility(view.VISIBLE);
223
+
224
+                    listview_rf.setVisibility(view.INVISIBLE);
225
+                }
231 226
                 break;
232 227
         }
233 228
     }
229
+
230
+    @Override
231
+    public void run() {
232
+        connect con = new connect();
233
+        con.run();
234
+        try {
235
+            Log.d("MainActivity / Run 함수 실행", "성공");
236
+        }catch(Exception e){
237
+            Log.e("MainActivity / Run 함수 실행", "실패");
238
+        }
239
+
240
+    }
234 241
 }

+ 33 - 0
app/src/main/java/com/example/repeater/connect.java

@@ -0,0 +1,33 @@
1
+package com.example.repeater;
2
+
3
+import android.util.Log;
4
+
5
+import java.net.Socket;
6
+import java.util.Timer;
7
+
8
+public class connect implements Runnable  {
9
+    private int port = 4000;
10
+    private String ip = "192.168.10.4";
11
+    private Socket socket;
12
+    private Timer timer = null;
13
+
14
+    public connect() {
15
+        try {
16
+            socket = new Socket(ip, port);    //서버에 연결
17
+            timer = new Timer();
18
+            Log.d("connect.class / 소켓 연결", "성공");
19
+        }
20
+        catch(Exception e) {
21
+            Log.e("connect.class / 소켓 연결", "실패");
22
+        }
23
+    }
24
+    @Override
25
+    public void run() {
26
+        // TODO Auto-generated method stub
27
+        send s = new send(socket);    //서버에 연결된 socket을 생성자를 통해 넘긴다
28
+        receive r = new receive(socket);  //서버에 연결된 socket을 생성자를 통해 넘긴다
29
+        timer.scheduleAtFixedRate(s, 1000, 7000);
30
+        r.run();        //스레드 실행
31
+    }
32
+}
33
+

+ 61 - 0
app/src/main/java/com/example/repeater/receive.java

@@ -0,0 +1,61 @@
1
+package com.example.repeater;
2
+
3
+import android.util.Log;
4
+
5
+import java.io.BufferedReader;
6
+import java.io.DataOutputStream;
7
+import java.io.InputStream;
8
+import java.io.InputStreamReader;
9
+import java.io.ObjectInputStream;
10
+import java.io.OutputStream;
11
+import java.io.PrintWriter;
12
+import java.net.Socket;
13
+
14
+public class receive implements Runnable{
15
+
16
+    private InputStreamReader in = null;
17
+    private BufferedReader buffRead = null;
18
+    private StringBuilder myCompleteMessage = null;
19
+    private int numberOfBytesRead = 0;
20
+    private char buff[] = new char[1024];
21
+    private Socket m_socket = null;
22
+
23
+    public receive(Socket socket) {         //생성자를 통하여 소켓을 받아온다
24
+        try {
25
+            m_socket = socket;          //서버에 접속된 소켓 파일 디스크립터 저장
26
+            in = new InputStreamReader(m_socket.getInputStream());  //전송 객체 초기화
27
+            buffRead = new BufferedReader(in);
28
+
29
+            Log.d("receive.class / 데이터 수신 객체 초기화", "성공");
30
+        } catch(Exception e) {
31
+            Log.e("receive.class / 데이터 수신 객체 초기화", "실패");
32
+        }
33
+    }
34
+
35
+    @Override
36
+    public void run() {
37
+        // TODO Auto-generated method stub
38
+        try {
39
+            while(true) {
40
+
41
+
42
+                myCompleteMessage = new StringBuilder();    //StringBuilder 객체 초기화
43
+                buffRead = new BufferedReader(new InputStreamReader(m_socket.getInputStream()));
44
+                numberOfBytesRead = buffRead.read(buff, 0, buff.length);//char 배열 buff에 받아들이고
45
+                myCompleteMessage.append(buff, 0, numberOfBytesRead); //buff의 데이터를 StringBuilder객체로 이동
46
+                Log.d("receive.class / 데이터 수신", "성공 : " + myCompleteMessage.toString() +"byte : " +numberOfBytesRead);//toString메소드를 통해
47
+                /*
48
+                myCompleteMessage = new StringBuilder();    //StringBuilder 객체 초기화
49
+                Log.d("receive1.class / 데이터 수신", "성공 : " + myCompleteMessage.toString());//toString메소드를 통해
50
+                numberOfBytesRead = buffRead.read(buff, 0, buff.length);//char 배열 buff에 받아들이고
51
+                Log.d("receive2.class / 데이터 수신", "성공 : " + myCompleteMessage.toString());//toString메소드를 통해
52
+                //받아들인 byte수를 반환
53
+                myCompleteMessage.append(buff, 2, numberOfBytesRead-2); //buff의 데이터를 StringBuilder객체로 이동
54
+                Log.d("receive.class / 데이터 수신", "성공 : " + myCompleteMessage.toString());//toString메소드를 통해
55
+                //String으로 변환*/
56
+            }
57
+        } catch(Exception e) {
58
+            Log.e("receive.class / 데이터 수신", "실패" + numberOfBytesRead);
59
+        }
60
+    }
61
+}

+ 37 - 0
app/src/main/java/com/example/repeater/send.java

@@ -0,0 +1,37 @@
1
+package com.example.repeater;
2
+
3
+        import android.util.Log;
4
+
5
+        import java.io.DataOutputStream;
6
+        import java.io.OutputStream;
7
+        import java.net.Socket;
8
+        import java.util.Timer;
9
+        import java.util.TimerTask;
10
+
11
+public class send extends TimerTask {
12
+    private OutputStream out = null;
13
+    private DataOutputStream dos = null;
14
+    private Socket m_socket = null;
15
+    private String message = "hello!";
16
+    private byte[] b = {'d','a','t','a','1','2','\r','\n'};
17
+    public send(Socket socket){
18
+        try{
19
+            m_socket = socket;
20
+            out = socket.getOutputStream();
21
+            dos = new DataOutputStream(out);
22
+            Log.d("send.class / 전송 객체 초기화","성공");
23
+        }catch(Exception e){
24
+            Log.e("send.class / 전송 객체 초기화","실패");
25
+        }
26
+    }
27
+    @Override
28
+    public void run() {
29
+        try {
30
+            dos.writeBytes(" data12\r\n");
31
+            //dos.write(b, 0, b.length);
32
+            Log.d("send.class / 메시지 전송", "성공");
33
+        }catch(Exception e){
34
+            Log.e("send.class / 전송 객체 초기화","실패");
35
+        }
36
+    }
37
+}

+ 53 - 7
app/src/main/res/layout/activity_list_view_item.xml

@@ -19,13 +19,59 @@
19 19
                     android:textColor="#000000"
20 20
                     android:textSize="24sp" />
21 21
 
22
-                <TextView
23
-                    android:id="@+id/textView14"
24
-                    android:layout_marginLeft="20dp"
25
-                    android:layout_width="match_parent"
26
-                    android:layout_height="match_parent"
27
-                    android:layout_weight="2"
28
-                    android:text="TextView" />
22
+
23
+
24
+                        <FrameLayout
25
+                            android:layout_width="wrap_content"
26
+                            android:layout_height="match_parent">
27
+                                <TextView
28
+                                    android:id="@+id/textView14"
29
+                                    android:layout_marginLeft="20dp"
30
+                                    android:layout_width="match_parent"
31
+                                    android:layout_height="match_parent"
32
+                                    android:layout_weight="2"
33
+                                    android:text="TextView" />
34
+                                <EditText
35
+                                    android:id="@+id/editText"
36
+                                    android:layout_width="match_parent"
37
+                                    android:layout_height="match_parent"
38
+                                    android:layout_weight="2"
39
+                                    android:ems="10"
40
+                                    android:inputType="textPersonName"
41
+                                    android:text="Name" />
42
+                                <Button
43
+                                    android:id="@+id/button"
44
+                                    android:layout_width="match_parent"
45
+                                    android:layout_height="match_parent"
46
+                                    android:layout_weight="2"
47
+                                    android:text="Button" />
48
+                                <LinearLayout
49
+                                    android:layout_width="wrap_content"
50
+                                    android:layout_height="match_parent"
51
+                                    android:layout_weight="1"
52
+                                    android:orientation="horizontal">
53
+
54
+                                        <EditText
55
+                                            android:id="@+id/editText1"
56
+                                            android:layout_width="111dp"
57
+                                            android:layout_height="match_parent"
58
+                                            android:layout_weight="1"
59
+                                            android:ems="10"
60
+                                            android:inputType="textPersonName"
61
+                                            android:text="Name" />
62
+
63
+                                        <EditText
64
+                                            android:id="@+id/editText2"
65
+                                            android:layout_width="112dp"
66
+                                            android:layout_height="match_parent"
67
+                                            android:layout_weight="1"
68
+                                            android:ems="10"
69
+                                            android:inputType="textPersonName"
70
+                                            android:text="Name" />
71
+                                </LinearLayout>
72
+
73
+                        </FrameLayout>
74
+
29 75
         </LinearLayout>
30 76
 
31 77
 </LinearLayout>

+ 0 - 9
app/src/main/res/layout/activity_list_view_rf.xml

@@ -1,9 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-    xmlns:app="http://schemas.android.com/apk/res-auto"
4
-    xmlns:tools="http://schemas.android.com/tools"
5
-    android:layout_width="match_parent"
6
-    android:layout_height="match_parent"
7
-    tools:context=".ListViewRFActivity">
8
-
9
-</android.support.constraint.ConstraintLayout>

+ 22 - 33
app/src/main/res/layout/activity_main.xml

@@ -20,30 +20,28 @@
20 20
             android:background="@color/colorPrimary"
21 21
             android:text="Repeater" />
22 22
 
23
-        <ToggleButton
24
-            android:id="@+id/button"
23
+        <Button
24
+            android:id="@+id/button_port"
25 25
             android:layout_width="match_parent"
26 26
             android:layout_height="wrap_content"
27
-            android:text="Port Open" />
28
-
27
+            android:text="Port Open"
28
+            android:onClick="onClick" />
29 29
     </LinearLayout>
30 30
 
31 31
     <LinearLayout
32 32
         android:layout_width="match_parent"
33 33
         android:layout_height="wrap_content"
34 34
         android:orientation="horizontal">
35
-
36 35
         <Button
37
-        android:id="@+id/button2"
36
+        android:id="@+id/button_control"
38 37
         android:layout_width="100dp"
39 38
         android:layout_height="100dp"
40 39
         android:layout_marginLeft="10dp"
41 40
         android:layout_marginBottom="10dp"
42
-        android:text="Control" />
43
-
44
-
41
+        android:text="Control"
42
+        android:onClick="onClick" />
45 43
         <TextView
46
-            android:id="@+id/textView3"
44
+            android:id="@+id/textView_status"
47 45
             android:layout_width="match_parent"
48 46
             android:layout_height="wrap_content"
49 47
             android:layout_marginLeft="30dp"
@@ -52,7 +50,7 @@
52 50
             android:textSize="46sp" />
53 51
     </LinearLayout>
54 52
     <TextView
55
-        android:id="@+id/textView4"
53
+        android:id="@+id/textView"
56 54
         android:layout_width="match_parent"
57 55
         android:layout_height="wrap_content"
58 56
         android:background="@color/colorPrimary"
@@ -65,9 +63,8 @@
65 63
             android:id="@+id/textView5"
66 64
             android:layout_width="wrap_content"
67 65
             android:layout_height="wrap_content"
68
-            android:text="Lock"
66
+            android:text="LOCK"
69 67
             tools:ignore="HardcodedText" />
70
-
71 68
         <ImageView
72 69
             android:id="@+id/imageView2"
73 70
             android:layout_width="wrap_content"
@@ -76,7 +73,6 @@
76 73
             app:srcCompat="@android:drawable/presence_invisible"
77 74
             android:contentDescription="TODO"
78 75
             tools:ignore="ContentDescription,HardcodedText" />
79
-
80 76
         <TextView
81 77
             android:id="@+id/textView6"
82 78
             android:layout_width="wrap_content"
@@ -97,24 +93,6 @@
97 93
         android:layout_height="wrap_content"
98 94
         android:orientation="horizontal">
99 95
 
100
-        <TextView
101
-            android:id="@+id/input"
102
-            android:layout_width="wrap_content"
103
-            android:layout_height="wrap_content"
104
-            android:text="I RECV Data"
105
-            tools:ignore="HardcodedText" />
106
-        <TextView
107
-            android:id="@+id/output"
108
-            android:layout_width="wrap_content"
109
-            android:layout_height="wrap_content"
110
-            android:text="I Send Data"
111
-            tools:ignore="HardcodedText" />
112
-    </LinearLayout>
113
-    <LinearLayout
114
-        android:layout_width="match_parent"
115
-        android:layout_height="wrap_content"
116
-        android:orientation="horizontal">
117
-
118 96
         <ImageButton
119 97
             android:id="@+id/imageButton01"
120 98
             android:layout_width="wrap_content"
@@ -135,7 +113,6 @@
135 113
     <FrameLayout
136 114
         android:layout_width="match_parent"
137 115
         android:layout_height="match_parent">
138
-
139 116
         <ListView
140 117
             android:id="@+id/listview_info"
141 118
             android:layout_width="match_parent"
@@ -148,5 +125,17 @@
148 125
             android:layout_height="wrap_content"
149 126
             android:visibility="invisible"
150 127
             />
128
+        <ListView
129
+            android:id="@+id/listview_info_set"
130
+            android:layout_width="match_parent"
131
+            android:layout_height="wrap_content"
132
+            android:visibility="invisible"
133
+            />
134
+        <ListView
135
+            android:id="@+id/listview_rf_set"
136
+            android:layout_width="match_parent"
137
+            android:layout_height="wrap_content"
138
+            android:visibility="invisible"
139
+            />
151 140
     </FrameLayout>
152 141
 </LinearLayout>