package com.hanry;
import java.io.BufferedInputStream;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.hanry.Constant;
import com.hanry.R;
import com.hanry.WifiCarSettings;
import com.hanry.Constant.CommandArray;
public class Main extends Activity implements SeekBar.OnSeekBarChangeListener
{
private final int MSG_ID_ERR_CONN = 1001;
//private final int MSG_ID_ERR_SEND = 1002;
private final int MSG_ID_ERR_RECEIVE = 1003;
private final int MSG_ID_CON_READ = 1004;
private final int MSG_ID_CON_SUCCESS = 1005;
private final int MSG_ID_START_CHECK = 1006;
private final int MSG_ID_ERR_INIT_READ = 1007;
private final int MSG_ID_CLEAR_QUIT_FLAG = 1008;
private final int MSG_ID_LOOP_START = 1010;
private final int MSG_ID_HEART_BREAK_RECEIVE = 1011;
private final int MSG_ID_HEART_BREAK_SEND = 1012;
private final int MSG_ID_LOOP_END = 1013;
private final int STATUS_INIT = 0x2001;
//private final int STATUS_CONNECTING = 0x2002;
private final int STATUS_CONNECTED = 0x2003;
private final int WARNING_ICON_OFF_DURATION_MSEC = 600;
private final int WARNING_ICON_ON_DURATION_MSEC = 800;
private final int WIFI_STATE_UNKNOW = 0x3000;
private final int WIFI_STATE_DISABLED = 0x3001;
private final int WIFI_STATE_NOT_CONNECTED = 0x3002;
private final int WIFI_STATE_CONNECTED = 0x3003;
private final int MIN_GEAR_STEP = 5;
private final int MAX_GEAR_VALUE = 180;
private final int INIT_GEAR_VALUE = 50;
private final byte COMMAND_PERFIX = -1;
private final int HEART_BREAK_CHECK_INTERVAL = 8000;//ms
private final int QUIT_BUTTON_PRESS_INTERVAL = 2500;//ms
private final int HEART_BREAK_SEND_INTERVAL = 2500;//ms
private boolean m4test = false;
private String CAMERA_VIDEO_URL = "http://192.168.2.1:8080/?action=stream";
private String CAMERA_VIDEO_URL_TEST = "";
private String ROUTER_CONTROL_URL = "192.168.2.1";
private String ROUTER_CONTROL_URL_TEST = "192.168.1.1";
private int ROUTER_CONTROL_PORT = 2001;
private int ROUTER_CONTROL_PORT_TEST = 2001;
private final String WIFI_SSID_PERFIX = "robot";
private ImageButton ForWard;
private ImageButton BackWard;
private ImageButton TurnLeft;
private ImageButton TurnRight;
private ImageButton TakePicture;
private ImageView mAnimIndicator;
private boolean bAnimationEnabled = true;
private Drawable mWarningIcon;
private boolean bReaddyToSendCmd = false;
private TextView mLogText;
private Drawable ForWardon;
private Drawable ForWardoff;
private Drawable BackWardon;
private Drawable BackWardoff;
private Drawable TurnLefton;
private Drawable TurnLeftoff;
private Drawable TurnRighton;
private Drawable TurnRightoff;
private Drawable buttonLenon;
private Drawable buttonLenoff;
private SeekBar mSeekBar;
private int mSeekBarValue = -1;
private ImageButton buttonCus1;
private ImageButton buttonLen;
private boolean bLenon = false;
private int mWifiStatus = STATUS_INIT;
private Thread mThreadClient = null;
private boolean mThreadFlag = false;
private boolean mQuitFlag = false;
private boolean bHeartBreakFlag = false;
private int mHeartBreakCounter = 0;
private int mLastCounter = 0;
private Context mContext;
SocketClient mtcpSocket;
MjpegView backgroundView = null;
private byte[] COMM_FORWARD = {(byte) 0xFF, (byte)0x00, (byte)0x01, (byte)0x00, (byte) 0xFF};
private byte[] COMM_BACKWARD = {(byte) 0xFF, 0x00, 0x02, 0x00, (byte) 0xFF};
private byte[] COMM_STOP = {(byte) 0xFF, 0x00, 0x00, 0x00, (byte) 0xFF};
private byte[] COMM_LEFT = {(byte) 0xFF, 0x00, 0x03, 0x00, (byte) 0xFF};
private byte[] COMM_RIGHT = {(byte) 0xFF, 0x00, 0x04, 0x00, (byte) 0xFF};
private byte[] COMM_LEN_ON = {(byte) 0xFF, 0x04, 0x03, 0x00, (byte) 0xFF};
private byte[] COMM_LEN_OFF = {(byte) 0xFF, 0x04, 0x02, 0x00, (byte) 0xFF};
private byte[] COMM_GEAR_CONTROL = {(byte) 0xFF, 0x01, 0x01, 0x00, (byte) 0xFF};
private byte[] COMM_SELF_CHECK = {(byte) 0xFF, (byte)0xEE, (byte)0xEE, 0x00, (byte) 0xFF};
private byte[] COMM_SELF_CHECK_ALL = {(byte) 0xFF, (byte)0xEE, (byte)0xE0, 0x00, (byte) 0xFF};
private byte[] COMM_HEART_BREAK = {(byte) 0xFF, (byte)0xEE, (byte)0xE1, 0x00, (byte) 0xFF};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
initSettings();
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//隐去标题(应用的名字必须要写在setContentView之前,否则会有异常)
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
ForWard= (ImageButton)findViewById(R.id.btnForward);
TurnLeft= (ImageButton)findViewById(R.id.btnLeft);
TurnRight=(ImageButton)findViewById(R.id.btnRight);
BackWard= (ImageButton)findViewById(R.id.btnBack);
buttonCus1= (ImageButton)findViewById(R.id.ButtonCus1);
buttonCus1.setOnClickListener(buttonCus1ClickListener);
buttonCus1.setOnLongClickListener(buttonCus1ClickListener2);
buttonLen= (ImageButton)findViewById(R.id.btnLen);
buttonLen.setOnClickListener(buttonLenClickListener);
buttonLen.setLongClickable(true);
TakePicture = (ImageButton)findViewById(R.id.ButtonTakePic);
TakePicture.setOnClickListener(buttonTakePicClickListener);
mAnimIndicator = (ImageView)findViewById(R.id.btnIndicator);
mWarningIcon = getResources().getDrawable(R.drawable.sym_indicator1);
ForWardon = getResources().getDrawable(R.drawable.sym_forward_1);
ForWardoff = getResources().getDrawable(R.drawable.sym_forward);
TurnLefton = getResources().getDrawable(R.drawable.sym_left_1);
TurnLeftoff = getResources().getDrawable(R.drawable.sym_left);
TurnRighton = getResources().getDrawable(R.drawable.sym_right_1);
TurnRightoff = getResources().getDrawable(R.drawable.sym_right);
BackWardon = getResources().getDrawable(R.drawable.sym_backward_1);
BackWardoff = getResources().getDrawable(R.drawable.sym_backward);
buttonLenon = getResources().getDrawable(R.drawable.sym_light);
buttonLenoff = getResources().getDrawable(R.drawable.sym_light_off);
backgroundView = (MjpegView)findViewById(R.id.mySurfaceView1);
mLogText = (TextView)findViewById(R.id.logTextView);
if (null != mLogText) {
mLogText.setBackgroundColor(Color.argb(0, 0, 255, 0));//0~255透明度值
mLogText.setTextColor(Color.argb(90, 0, 255, 0));
}
mSeekBar = (SeekBar)findViewById(R.id.ge
- 1
- 2
- 3
前往页