private void asyncThread() { new AsyncTask<Void, String, Void>()
{
private ProgressDialog mPdialog ;
@Override
protected void onCancelled() {
// TODO Auto-generated method stub
super.onCancelled();
}
@Override
protected void onPostExecute(Void result) {
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
mPdialog = showDialog(SubPage01Activity.this,false);
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
Log.d("onProUp",values[0]);
int check_slot_A=0;
int check_slot_B=0;
//int check_slot_C=0;
int check_slot_A_tmp=0;
int check_slot_B_tmp=0;
//int check_slot_C_tmp=0;
int[][] a = new int[3][3];//슬롯을 체크할 int형 배열
//String building=null; //안드로이드로 부터 받은 '동'정보를 다시 안드로이드로 보내기 위한 변수
//tv.setText("주차 공간 할당 : " + recive_msg);
//check_slot = Integer.parseInt(recive_msg);
StringTokenizer stk = new StringTokenizer(recive_msg, " ");
String token="";
token=stk.nextToken();
building=token;
//Toast.makeText(SubPage01Activity.this, token, Toast.LENGTH_SHORT).show();
while(stk.hasMoreTokens()){
token=stk.nextToken();
if(token.equals("A")){
token=stk.nextToken();
check_slot_A=Integer.parseInt(token);
//Toast.makeText(SubPage01Activity.this, String.valueOf(check_slot_A), Toast.LENGTH_SHORT).show();
}else if(token.equals("B")){
token=stk.nextToken();
check_slot_B=Integer.parseInt(token);
}else{
}
}
check_slot_A_tmp=check_slot_A;
check_slot_B_tmp=check_slot_B;
//check_slot_C_tmp=check_slot_C;
a[0][0] = check_slot_A/100;//b-1공간 할당
check_slot_A = check_slot_A%100;
a[0][1] = check_slot_A/10;//b-2공간 할당
a[0][2] = check_slot_A%10;//b-3
a[1][0] = check_slot_B/100;//b-1공간 할당
check_slot_B = check_slot_B%100;
a[1][1] = check_slot_B/10;//b-2공간 할당
a[1][2] = check_slot_B%10;//b-3
//주차될 경우 주차 공간을 빨간색으로 변환_A
if (a[0][0] == 1)// a-1 지그비 8번
{
A_1 = (Button) findViewById(R.id.A_1);
A_1.setBackgroundColor(Color.rgb(255, 0, 0));
} else
// 아닌 경우 다시 흰색으로 변환.
A_1.setBackgroundColor(Color.TRANSPARENT);
if (a[0][1] == 1)// a-2 지그비 9번
{
A_2 = (Button) findViewById(R.id.A_1);
A_2.setBackgroundColor(Color.rgb(255, 0, 0));
} else
A_2.setBackgroundColor(Color.TRANSPARENT);
if (a[0][2] == 1)// a-3 지그비 5번
{
A_3 = (Button) findViewById(R.id.A_1);
A_3.setBackgroundColor(Color.rgb(255, 0, 0));
} else
A_3.setBackgroundColor(Color.TRANSPARENT);
//주차될 경우 주차 공간을 빨간색으로 변환_B
if (a[1][0] == 1)// a-1 지그비 8번
{
B_1 = (Button) findViewById(R.id.A_1);
B_1.setBackgroundColor(Color.rgb(255, 0, 0));
} else
// 아닌 경우 다시 흰색으로 변환.
B_1.setBackgroundColor(Color.TRANSPARENT);
if (a[1][1] == 1)// a-2 지그비 9번
{
B_2 = (Button) findViewById(R.id.A_1);
B_2.setBackgroundColor(Color.rgb(255, 0, 0));
} else
B_2.setBackgroundColor(Color.TRANSPARENT);
if (a[1][2] == 1)// a-3 지그비 5번
{
B_3 = (Button) findViewById(R.id.A_1);
B_3.setBackgroundColor(Color.rgb(255, 0, 0));
} else
B_3.setBackgroundColor(Color.TRANSPARENT);
if(building.equals("A")){
if(check_slot_A_tmp==0 || check_slot_A_tmp==10 || check_slot_A_tmp==1 || check_slot_A_tmp==11)
{
tv.setText("" + "A A-1");
A_1.setBackgroundColor(Color.BLACK);
}
else if(check_slot_A_tmp==100 || check_slot_A_tmp==101)
{
tv.setText("" + "A A-2");
A_2.setBackgroundColor(Color.BLACK);
}
else if(check_slot_A_tmp==110)
{
tv.setText("" + "A A-3");
A_3.setBackgroundColor(Color.BLACK);
}
else{
tv.setText("" + "B B-1");
B_1.setBackgroundColor(Color.BLACK);
}
}else if(building.equals("B")){
if(check_slot_B_tmp==0 || check_slot_B_tmp==10 || check_slot_B_tmp==1 || check_slot_B_tmp==11)
{
tv.setText("" + "B B-1");
B_1.setBackgroundColor(Color.BLACK);
}
else if(check_slot_B_tmp==100 || check_slot_B_tmp==101)
{
tv.setText("" + "B B-2");
B_2.setBackgroundColor(Color.BLACK);
}
else if(check_slot_B_tmp==110)
{
tv.setText("" + "B B-3");
B_3.setBackgroundColor(Color.BLACK);
}
else
tv.setText("" + "C C-1");
C_1.setBackgroundColor(Color.BLACK);
}
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
client_join tp = new client_join();
//tp.send_msg("ok!!");
//tp.receive_msg();
String line;
try {
//String line;
while (true) {
line = networkReader.readLine();
recive_msg = line;
// mHandler.post(showUpdate);
}
} catch (Exception e) {
}
return null;
}
}.execute();
}
private class client_join{
private static final String ip = "192.168.0.2";
private static final int serverPort = 10001;
Socket socket;
InetAddress serverAddr;
public client_join()
{
try {
InetAddress serverIP = InetAddress.getByName(ip);
socket = new Socket(serverIP, serverPort);
networkWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
networkReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(networkWriter, true);
} catch (IOException e) {
System.out.println(e);
e.printStackTrace();
}
}
}
}
접속중입니다 프로그레스 바만 뜨네요 계속 화면에서 버튼 색깔을 바꾸어 주어야 하는데 ... 먼가 사용법이 잘못 된건가요