package org.smarthome;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import org.smarthome.R;
import org.smarthome.ImageThread;
import org.util.FileTools;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;
public class CameraActivity extends Activity{
/* (non-Javadoc)
* @see android.app.Activity#onTouchEvent(android.view.MotionEvent)
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("进入触笔事件");
int iAction = event.getAction();
if(iAction == MotionEvent.ACTION_CANCEL ||
// iAction == MotionEvent.ACTION_DOWN ||
iAction == MotionEvent.ACTION_MOVE)
{
return false;
}
//得到触笔点的位置
int x = (int)event.getX();
int y = (int)event.getY();
System.out.println(x);
System.out.println(y);
// if((x > 20) && (x < 280) && (y > 30) && (y < 220)){
if(this.b != null){
System.out.println("开始存数文件");
File file = new FileTools().StorePicture(b);
System.out.println("存数文件完毕");
Toast toast = Toast.makeText(CameraActivity.this,
"存储文件名为"+file.getName(), Toast.LENGTH_SHORT);
toast.show();
}else{
Toast toast = Toast.makeText(CameraActivity.this,
"存储失败", Toast.LENGTH_SHORT);
toast.show();
}
// }
return super.onTouchEvent(event);
}
public static final int REFRESH = 0x000001;
public Object synch = new Object();
private Spinner mSpinner = null;
private Spinner mSpinner01 = null;
// private Button mButton01 = null;
// private Button mButton02 = null;
private Button mButton03 = null;
private Button mButton04 = null;
private Button mButton05 = null;
private Button mButton06 = null;
private Button mButton07 = null;
private Button mButton08 = null;
private Button mButton09 = null;
// private Button mButton10 = null;
// private Button mButton11 = null;
private Button mButton12 = null;
private Button mButton17 = null;
private SurfaceView mSurfaceView01 = null;
private SurfaceHolder mSurfaceHolder = null;
// private Thread imgThread;
private ImageThread mImageThread;
private DrawImage mDrawImage;
private Canvas c = null;
boolean flag = false;
int pictureWidth = 0, prePictureWidth = 0;
byte flip = 0, flip01 = 0;
String IPstr,port;
String domain="http://yaokainan.eicp.net";
InetAddress address = null;
Bitmap b = null;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
// mButton01 = (Button)findViewById(R.id.mButton01);
// mButton02 = (Button)findViewById(R.id.mButton02);
mButton03 = (Button)findViewById(R.id.mButton03);
mButton04 = (Button)findViewById(R.id.mButton04);
mButton05 = (Button)findViewById(R.id.mButton05);
mButton06 = (Button)findViewById(R.id.mButton06);
mButton07 = (Button)findViewById(R.id.mButton07);
mButton08 = (Button)findViewById(R.id.mButton08);
mButton09 = (Button)findViewById(R.id.mButton09);
// mButton10 = (Button)findViewById(R.id.mButton10);
// mButton11 = (Button)findViewById(R.id.mButton11);
mButton17 = (Button)findViewById(R.id.mButton17);
mButton12 = (Button)findViewById(R.id.mButton12);
mSpinner = (Spinner)findViewById(R.id.mSpinner);
mSpinner01 = (Spinner) findViewById(R.id.mSpinner01);
getIp();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.xiangsu_array,
android.R.layout.simple_spinner_item);
System.out.println(adapter);
System.out.println(mSpinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
mSpinner.setPrompt("选择像素");
ArrayAdapter<CharSequence> adapter01 = ArrayAdapter.createFromResource(
this, R.array.liangdu_array,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner01.setAdapter(adapter01);
mSpinner01.setPrompt("选择亮度");
mSurfaceView01 = (SurfaceView) findViewById(R.id.mSurfaceView01);
mSurfaceHolder = mSurfaceView01.getHolder();
mSurfaceHolder.addCallback(new CameraView());
// mButton01.setOnClickListener(new ClickButton());
// mButton02.setOnClickListener(new ClickButton());
mButton03.setOnClickListener(new ClickButton());
mButton04.setOnClickListener(new ClickButton());
mButton05.setOnClickListener(new ClickButton());
mButton06.setOnClickListener(new ClickButton());
mButton07.setOnClickListener(new ClickButton());
mButton08.setOnClickListener(new ClickButton());
mButton09.setOnClickListener(new ClickButton());
// mButton10.setOnClickListener(new ClickButton());
// mButton11.setOnClickListener(new ClickButton());
mButton12.setOnClickListener(new ClickButton());
mButton17.setOnClickListener(new ClickButton());
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
if(mImageThread != null){
switch (arg2) {
case 0:
mImageThread.SendCmd("camera_control.cgi?param=0&value=2");
break;
case 1:
mImageThread.SendCmd("camera_control.cgi?param=0&value=8");
break;
case 2:
mImageThread.SendCmd("camera_control.cgi?param=0&value=32");
break;
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
// 什么也不做
}
});
mSpinner01.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
if(mImageThread != null){
switch (arg2) {
// case 0:
// mImageThread.SendCmd("camera_control.cgi?param=1&value=16");
// break;
// case 1:
// mImageThread.SendCmd("camera_control.cgi?param=1&value=32");
// break;
case 2:
mImageThread.SendCmd("camera_control.cgi?param=1&value=48");
break;
case 3:
mImageThread.SendCmd("camera_control.cgi?param=1&value=64");
break;
case 4:
mImageThread.SendCmd("camera_control.cgi?param=1&value=80");
break;
case 5:
mImageThread.SendCmd("camera_control.cgi?param=1&value=96");
break;
case 6:
mImageThread
.SendCmd("camera_control.cgi?param=1&value=112");
break;
case 7:
mImageThread
.SendCmd("camera_control.cgi?param=1&value=128");
break;
case 8:
mImageThread
.SendCmd("camera_control.cgi?param=1&value=144");
break;
case 9:
mImageThread
.SendCmd("camera_control.cgi?param=1&value=160");
break;
// case 10:
// mImageThread
// .SendCmd("camera_control.cgi?param=1&value=176");
// break;
// case 11:
// mImageThread
// .SendCmd("camera_control.
评论0