Ver código fonte

Socket 통신 추가

june9152 5 anos atrás
pai
commit
72a2436ef1

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

@@ -2,6 +2,7 @@
2 2
   <dictionary name="parkyj">
3 3
     <words>
4 4
       <w>bluecell</w>
5
+      <w>infor</w>
5 6
       <w>listview</w>
6 7
     </words>
7 8
   </dictionary>

+ 5 - 0
app/src/main/AndroidManifest.xml

@@ -2,6 +2,11 @@
2 2
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 3
     package="com.example.repeater">
4 4
 
5
+    <uses-permission android:name="android.permission.INTERNET" />
6
+    <uses-permission android:name="android.permission.BLUETOOTH" />
7
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
8
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
9
+
5 10
     <application
6 11
         android:allowBackup="true"
7 12
         android:icon="@mipmap/ic_launcher"

+ 2 - 1
app/src/main/java/com/example/repeater/ListViewAdapter.java

@@ -2,6 +2,7 @@ package com.example.repeater;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.graphics.drawable.Drawable;
5
+import android.support.annotation.ColorInt;
5 6
 import android.view.LayoutInflater;
6 7
 import android.view.View;
7 8
 import android.view.ViewGroup;
@@ -48,7 +49,7 @@ public class ListViewAdapter extends BaseAdapter {
48 49
         // 아이템 내 각 위젯에 데이터 반영
49 50
         descTextView.setText(listViewItem.getDesc());
50 51
         valTextView.setText(listViewItem.getVal());
51
-
52
+//        descTextView.setBackgroundColor();
52 53
         return convertView;
53 54
     }
54 55
 

+ 9 - 1
app/src/main/java/com/example/repeater/ListViewItem.java

@@ -7,7 +7,7 @@ import android.os.Bundle;
7 7
 public class ListViewItem {
8 8
     private String descStr ;
9 9
     private String valStr ;
10
-
10
+    private String colorStr;
11 11
     public void setDesc(String desc) {
12 12
         descStr = desc ;
13 13
     }
@@ -20,4 +20,12 @@ public class ListViewItem {
20 20
     public String getVal() {
21 21
         return this.valStr ;
22 22
     }
23
+
24
+    public String getColorStr() {
25
+        return colorStr;
26
+    }
27
+
28
+    public void setColorStr(String colorStr) {
29
+        this.colorStr = colorStr;
30
+    }
23 31
 }

+ 137 - 22
app/src/main/java/com/example/repeater/MainActivity.java

@@ -1,14 +1,23 @@
1 1
 package com.example.repeater;
2 2
 
3
-import android.support.v4.content.ContextCompat;
4 3
 import android.support.v7.app.AppCompatActivity;
5 4
 import android.os.Bundle;
5
+import android.util.Log;
6 6
 import android.view.View;
7
-import android.widget.ArrayAdapter;
8 7
 import android.widget.ImageButton;
9 8
 import android.widget.ListView;
10
-import android.widget.SimpleAdapter;
11
-
9
+import android.widget.TextView;
10
+import android.widget.ToggleButton;
11
+
12
+import java.io.BufferedReader;
13
+import java.io.BufferedWriter;
14
+import java.io.IOException;
15
+import java.io.InputStreamReader;
16
+import java.io.OutputStreamWriter;
17
+import java.io.PrintWriter;
18
+import java.net.InetSocketAddress;
19
+import java.net.Socket;
20
+import java.net.SocketAddress;
12 21
 import java.util.ArrayList;
13 22
 import java.util.HashMap;
14 23
 
@@ -27,10 +36,17 @@ public class MainActivity extends AppCompatActivity {
27 36
     private HashMap<String,String> InputData11 = new HashMap<>();
28 37
     private HashMap<String,String> InputData12 = new HashMap<>();
29 38
     private ListView listview_info;
30
-    private ListView listview_info01;
39
+    private ListView listview_rf;
31 40
     static final String[] LIST_MENU = {"LIST1", "LIST2", "LIST3"} ;
32
-
33
-
41
+    /*** WIFI Start***/
42
+    BufferedReader in;      //서버로부터 온 데이터를 읽는다.
43
+    PrintWriter out;        //서버에 데이터를 전송한다.
44
+    TextView input;
45
+    TextView output;
46
+    String data;
47
+    ToggleButton button;
48
+    private Socket socket;  //소켓생성
49
+    /*** WIFI END***/
34 50
     private ArrayList<ListViewItem> listViewItemList = new ArrayList<ListViewItem>() ;
35 51
 
36 52
 
@@ -46,25 +62,53 @@ public class MainActivity extends AppCompatActivity {
46 62
         imageButton01 = findViewById(R.id.imageButton01);
47 63
         imageButton02 = findViewById(R.id.imageButton02);
48 64
         listview_info = findViewById(R.id.listview_info);
49
-        listview_info01 = findViewById(R.id.listview_info01);
65
+        listview_rf = findViewById(R.id.listview_rf);
50 66
         imageButton02 = findViewById(R.id.imageButton02);
51 67
 
68
+        input = findViewById(R.id.input);
69
+        output = findViewById(R.id.output);
70
+        button = findViewById(R.id.button);
71
+
52 72
         ListView listview ;
53
-        ListViewAdapter adapter;
73
+        ListViewAdapter adapter_infor;
74
+        ListViewAdapter adapter_rf;
54 75
 
55
-        // Adapter 생성
56
-        adapter = new ListViewAdapter() ;
57 76
 
77
+        // Adapter 생성
78
+        adapter_infor = new ListViewAdapter() ;
79
+        adapter_rf = new ListViewAdapter();
58 80
         // 리스트뷰 참조 및 Adapter달기
59 81
         listview = (ListView) findViewById(R.id.listview_info);
60
-        listview.setAdapter(adapter);
61
-
62
-        // 첫 번째 아이템 추가.
63
-        adapter.addItem("firm info.","0.1Ver") ;
64
-        // 두 번째 아이템 추가.
65
-        adapter.addItem("FPGA Ver.","0.2Ver") ;
66
-        // 세 번째 아이템 추가.
67
-        adapter.addItem("F/W Ver.","0.3Ver") ;
82
+        listview.setAdapter(adapter_infor);
83
+
84
+
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");
97
+
98
+        listview = (ListView) findViewById(R.id.listview_rf);
99
+        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");
68 112
 /*
69 113
 
70 114
 
@@ -102,17 +146,88 @@ public class MainActivity extends AppCompatActivity {
102 146
 //        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2, LIST_MENU) ;
103 147
 //        listview_info.setAdapter(adapter);
104 148
 */
105
-    }
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()에서 실행.
106 208
 
209
+
210
+
211
+
212
+    }
213
+    @Override
214
+    protected void onStop() {  //앱 종료시
215
+        super.onStop();
216
+        try {
217
+            socket.close(); //소켓을 닫는다.
218
+        } catch (IOException e) {
219
+            e.printStackTrace();
220
+        }
221
+    }
107 222
     public void onClick(View view) {
108 223
         switch(view.getId()) {
109 224
             case R.id.imageButton01:
110 225
                 listview_info.setVisibility(view.VISIBLE);
111
-                listview_info01.setVisibility(view.INVISIBLE);
226
+                listview_rf.setVisibility(view.INVISIBLE);
112 227
                 break;
113 228
             case R.id.imageButton02:
114 229
                 listview_info.setVisibility(view.INVISIBLE);
115
-                listview_info01.setVisibility(view.VISIBLE);
230
+                listview_rf.setVisibility(view.VISIBLE);
116 231
                 break;
117 232
         }
118 233
     }

+ 3 - 3
app/src/main/res/layout/activity_intro.xml

@@ -10,9 +10,9 @@
10 10
     <ImageView
11 11
         android:id="@+id/imageView6"
12 12
         android:layout_width="360dp"
13
-        android:layout_height="80dp"
13
+        android:layout_height="92dp"
14 14
         android:layout_marginStart="40dp"
15
+        android:layout_marginLeft="40dp"
15 16
         android:layout_marginTop="250dp"
16
-        app:srcCompat="@drawable/bluecell_logo"
17
-        android:layout_marginLeft="40dp" />
17
+        app:srcCompat="@drawable/bluecell_logo" />
18 18
 </LinearLayout>

+ 1 - 1
app/src/main/res/layout/activity_list_view_item.xml

@@ -17,7 +17,7 @@
17 17
                     android:gravity="center_vertical"
18 18
                     android:text="New Text"
19 19
                     android:textColor="#000000"
20
-                    android:textSize="24dp" />
20
+                    android:textSize="24sp" />
21 21
 
22 22
                 <TextView
23 23
                     android:id="@+id/textView14"

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

@@ -0,0 +1,9 @@
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>

+ 28 - 10
app/src/main/res/layout/activity_main.xml

@@ -97,20 +97,39 @@
97 97
         android:layout_height="wrap_content"
98 98
         android:orientation="horizontal">
99 99
 
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
+
100 118
         <ImageButton
101 119
             android:id="@+id/imageButton01"
102 120
             android:layout_width="wrap_content"
103 121
             android:layout_height="wrap_content"
104
-            android:layout_weight="1"
122
+            android:scaleType="fitStart"
123
+            android:background="@android:color/transparent"
105 124
             android:onClick="onClick"
106
-            app:srcCompat="@android:drawable/dialog_holo_dark_frame" />
125
+            app:srcCompat="@android:drawable/zoom_plate" />
107 126
         <ImageButton
108 127
             android:id="@+id/imageButton02"
109 128
             android:layout_width="wrap_content"
110 129
             android:layout_height="wrap_content"
111
-            android:layout_weight="1"
130
+            android:background="@android:color/transparent"
112 131
             android:onClick="onClick"
113
-            app:srcCompat="@android:drawable/dialog_holo_dark_frame" />
132
+            app:srcCompat="@android:drawable/zoom_plate" />
114 133
     </LinearLayout>
115 134
 
116 135
     <FrameLayout
@@ -119,16 +138,15 @@
119 138
 
120 139
         <ListView
121 140
             android:id="@+id/listview_info"
122
-            android:layout_width="wrap_content"
141
+            android:layout_width="match_parent"
123 142
             android:layout_height="wrap_content"
124
-            android:visibility="invisible"
143
+            android:visibility="visible"
125 144
             />
126 145
         <ListView
127
-            android:id="@+id/listview_info01"
128
-            android:layout_width="wrap_content"
146
+            android:id="@+id/listview_rf"
147
+            android:layout_width="match_parent"
129 148
             android:layout_height="wrap_content"
130
-            android:visibility="visible"
149
+            android:visibility="invisible"
131 150
             />
132 151
     </FrameLayout>
133
-     
134 152
 </LinearLayout>

+ 1 - 1
build.gradle

@@ -7,7 +7,7 @@ buildscript {
7 7
         
8 8
     }
9 9
     dependencies {
10
-        classpath 'com.android.tools.build:gradle:3.4.1'
10
+        classpath 'com.android.tools.build:gradle:3.4.2'
11 11
         
12 12
         // NOTE: Do not place your application dependencies here; they belong
13 13
         // in the individual module build.gradle files