package com.yy.sc;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import com.yyyy.shipin.Video;
import com.yyyy.yuyin.Capture;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;public class SCActivity extends Activity { SurfaceView surfaceView1;
SurfaceView surfaceView2;
TextView textView;
EditText editText;
Button fasong;
Button qidong; ServerSocket serSocket;
Socket client;
InputStream in;
BufferedReader br;
OutputStream out;
BufferedWriter bw; String SERVERHOST = "127.0.0.1"; @Override
protected void onResume() {
/**
 * 设置为横屏
 */
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
} public void fasong() {
try {
String str = editText.getText().toString();
byte[] buf = str.getBytes();
editText.setText(null);
out.write(buf);
System.out.print(out);
textView.setText(textView.getText().toString().trim() + "I say:"
+ str);
textView.setText(textView.getText().toString() + "\n");
} catch (IOException ioe) {
System.out.print(ioe.getMessage());
}
} public void qidong() {
try {
Socket cli = new Socket(SERVERHOST, 6000);
Capture cap = new Capture(cli);
cap.start(); } catch (Exception e) {
} } @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏
setContentView(R.layout.main);
surfaceView1 = (SurfaceView) findViewById(R.id.surfaceView1);
surfaceView2 = (SurfaceView) findViewById(R.id.surfaceView2);
textView = (TextView) findViewById(R.id.textView1);
editText = (EditText) findViewById(R.id.editText1);
fasong = (Button) findViewById(R.id.button1);
qidong = (Button) findViewById(R.id.button2);
        new got().start();
Video video = new Video(surfaceView1);
OnClickListener clickListener = new OnClickListener() { public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
fasong();
break; case R.id.button2:
qidong();
break;
}
}
};
fasong.setOnClickListener(clickListener);
qidong.setOnClickListener(clickListener);

}
class got extends Thread{
public void run(){ try {  Log.i("SCActivity", "o");
Socket client = new Socket(SERVERHOST, 5000);//发现不执行这一行代码,这是什么情况???
try {
sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Log.i("SCActivity", in + "0.3");
textView.setText("Connect to:"
+ client.getInetAddress().getHostName() + "\n\n");
Log.i("SCActivity", in + "o.5");
in = client.getInputStream();
Log.i("SCActivity", in + "1");
br = new BufferedReader(new InputStreamReader(in));
out = client.getOutputStream();
bw = new BufferedWriter(new OutputStreamWriter(out));
} catch (IOException ioe) {
ioe.printStackTrace();
}
// if(in!=null){
while (true) {
try {
byte[] buf = new byte[200];
Log.i("SCActivity", in + "2");
in.read(buf);
Log.i("SCActivity", in + "3");
String str = new String(buf);
textView.setText(textView.getText().toString().trim()
+ "Server say:" + str);
textView.setText(textView.getText().toString() + "\n");
} catch (IOException e) {
System.out.print(e.getMessage());
}
}
}
}
}