package com.Android.CamMonitor;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import android.util.Log;
public class Activity02 extends Activity {
private static String LOG_TAG = "socket";
private EditText LEditText;
private TextView LTextView;
private Button UpButton;
private Button LeftButton;
private Button DownButton;
private Button RightButton;
private Button Btn_Open;
private Socket socket = null;
// private BufferedWriter writer;
// private BufferedReader reader;
private OutputStream writer;
private InputStream reader;
private ImageView myImageView;
byte[] buf = {'O', 'K', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private final int HDRLEN = 50;
private final int SZOFS = 29;
private boolean m_stop = false;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //parent class
setContentView(R.layout.main1); //child class
UpButton = (Button)findViewById(R.id.UpButton);
DownButton = (Button)findViewById(R.id.DownButton);
LeftButton = (Button)findViewById(R.id.LeftButton);
RightButton = (Button)findViewById(R.id.RightButton);
Btn_Open = (Button)findViewById(R.id.btn_Open);
// TextView LTextView=(TextView)findViewById(R.id.TextView01);
// EditText LEditText=(EditText)findViewById(R.id.EditText01);
try {
socket = new Socket("192.168.7.205",7070); //连接服务器
} catch (IOException e3) {
e3.printStackTrace();
}
try {
//reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
reader = socket.getInputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
try
{
//writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer = socket.getOutputStream();
}
catch (IOException e1)
{
e1.printStackTrace();
}
UpButton.setOnClickListener(new Button.OnClickListener()
{
Button U = (Button)findViewById(R.id.UpButton);
public void onClick(View v)
{
//char[] buf = {'O', 'K', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
try
{
buf[13] = 1;
System.out.println("turn up");
writer.write(buf);
writer.flush();
}
catch (IOException e)
{
Log.e(LOG_TAG,e.toString());
}
}
});
DownButton.setOnClickListener(new Button.OnClickListener()
{
Button D = (Button)findViewById(R.id.DownButton);
public void onClick(View v)
{
// char[] buf = {'O', 'K', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2};
try
{
buf[13] = 2;
System.out.println("turn down");
writer.write(buf);
writer.flush();
}
catch (IOException e)
{
Log.e(LOG_TAG,e.toString());
}
}
});
LeftButton.setOnClickListener(new Button.OnClickListener()
{
Button L = (Button)findViewById(R.id.LeftButton);
public void onClick(View v)
{
//String msg=LEditText.getText().toString()+"\r\n";
// char[] buf = {'O', 'K', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3};
try
{
buf[13] = 3;
System.out.println("turn left");
writer.write(buf);
writer.flush();
}
catch (IOException e)
{
Log.e(LOG_TAG,e.toString());
}
}
});
RightButton.setOnClickListener(new Button.OnClickListener()
{
Button Ri = (Button)findViewById(R.id.RightButton);
public void onClick(View v)
{
// char[] buf = {'O', 'K', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4};
try
{
buf[13] = 4;
System.out.println("turn over");
writer.write(buf);
writer.flush();
}
catch (IOException e)
{
Log.e(LOG_TAG,e.toString());
}
}
});
Button fanhui = (Button)findViewById(R.id.fanhui);
fanhui.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Intent intent=new Intent();
intent.setClass(Activity02.this,Activity01.class);
startActivity(intent);
Activity02.this.finish();
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
Btn_Open.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
//while(true)
{
byte[] bb = {'O','K',0,0, 0,0,0,0,0,0,0,0,0};
try {
writer.write(bb);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
writer.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
getImage();
}
}
});
}
public void getImage()
{
myImageView = (ImageView)findViewById(R.id.myImageView);
byte[] buffer = new byte[512*1024];
int siz = 0;
int n = 0;
//BufferedWriter
m_stop = false;
while(!m_stop)
{
try {
n = reader.read(buffer, 0, HDRLEN);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int ssz = SZOFS;
//siz += unsignedByteToInt(buffer[ssz+3]) << 24;
//siz += unsignedByteToInt(buffer[ssz+2]) << 16;
//siz += unsignedByteToInt(buffer[ssz+1]) << 8;
siz += unsignedByteToInt(buffer[ssz]) ;
n = HDRLEN;
if (buffer[0]!='S' || buffer[1]!='P' || buffer[2]!='C' || buffer[3]!='A')
{
System.out.println("*Header missing 'SPCA'");
continue;
}
else if (siz<=0 || siz>(512*1024))
{
siz = 0;
try {
reader.read(buffer, n, buffer.length);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android平台下的摄像头程序CamMonitor.rar (33个子文件)
CamMonitor
.project 846B
default.properties 364B
bin
com
Android
CamMonitor
R$string.class 566B
Activity02$2.class 2KB
R$layout.class 435B
MyService$ServerThread.class 2KB
R$drawable.class 412B
Activity02$3.class 2KB
Activity02$5.class 2KB
Activity01$1.class 1KB
Activity02$6.class 1KB
Activity01.class 961B
R.class 559B
MyService$LocalBinder.class 628B
Activity02$1.class 2KB
Activity02$4.class 2KB
R$attr.class 352B
Activity02.class 4KB
MyService.class 3KB
R$id.class 1KB
CamMonitor.apk 15KB
resources.ap_ 7KB
classes.dex 12KB
AndroidManifest.xml 904B
src
com
Android
CamMonitor
Activity01.java 1KB
Activity02.java 9KB
MyService.java 5KB
res
values
strings.xml 357B
layout
main1.xml 4KB
main.xml 2KB
drawable
icon.png 3KB
.classpath 280B
gen
com
Android
CamMonitor
R.java 2KB
assets
共 33 条
- 1
资源评论
- zt97882011-11-11只适用于2.3以上系统
- 路飞llb2012-11-08没有导入成功啊!
- whl2072012002012-02-212.3的系统才能用!
- syiml2014-08-11我以为是源码,我承认是我自己下错了。
- 迷若烟雨2012-10-23无法使用,打开就崩溃
yujianrong
- 粉丝: 6
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功