Mini2440Activity.java
[java]
package sg131971.mini2440;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import Android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
public class Mini2440Activity extends Activity {
private static int Connect_flag = 0;
private static int AutoRefresh_flag = 0;
private static int LED_flag[] = new int[4];
private Bitmap m_Bitmap;
private ImageView myImageView;
private Handler m_Handler = new Handler();
private String Board_IP;
private EditText myEditText;
private Button myButtonConnect;
private Button myButton0;
private Button myButton1;
private Button myButton2;
private Button myButton3;
private Button myButtonStatus;
private Button autoButton;
private Button manualButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myEditText = (EditText) findViewById(R.id.editText);
myButtonConnect = (Button) findViewById(R.id.myButtonConnect);
myButtonConnect.setOnClickListener(new ConnectListener());
myImageView = (ImageView) findViewById(R.id.imageView);
autoButton = (Button) findViewById(R.id.autoButton);
manualButton = (Button) findViewById(R.id.manualButton);
myButton0 = (Button) findViewById(R.id.myButton0);
myButton1 = (Button) findViewById(R.id.myButton1);
myButton2 = (Button) findViewById(R.id.myButton2);
myButton3 = (Button) findViewById(R.id.myButton3);
myButtonStatus = (Button) findViewById(R.id.myButtonStatus);
StopService();
}
public boolean onKeyDown(int keyCode, KeyEvent msg) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
finish();
System.exit(0);
}
return false;
}
private void StartService() {
// TODO Auto-generated method stub
m_Handler.postDelayed(m_RefreshImage, 0);
myButton0.setOnClickListener(new LED0Listener());
myButton1.setOnClickListener(new LED1Listener());
myButton2.setOnClickListener(new LED2Listener());
myButton3.setOnClickListener(new LED3Listener());
myButtonStatus.setOnClickListener(new StatusListener());
autoButton.setOnClickListener(new AutoRefresh());
manualButton.setOnClickListener(new ManualRefresh());
}
private void StopService() {
// TODO Auto-generated method stub
m_Handler.removeCallbacks(m_RefreshImage);
myImageView.setImageResource(R.drawable.first);
myButton0.setOnClickListener(new DefaultListener());
myButton1.setOnClickListener(new DefaultListener());
myButton2.setOnClickListener(new DefaultListener());
myButton3.setOnClickListener(new DefaultListener());
myButtonStatus.setOnClickListener(new DefaultListener());
autoButton.setOnClickListener(new DefaultListener());
manualButton.setOnClickListener(new DefaultListener());
}
public class ConnectListener implements OnClickListener {
public void onClick(View v) {
// TODO Auto-generated method stub
Board_IP = myEditText.getText().toString();
if (Connect_flag == 0) {
Connect_flag = 1;
StartService();
myButtonConnect.setText("Disconnect");
showMessage("已连接:" + Board_IP);
} else {
Connect_flag = 0;
AutoRefresh_flag = 0;
StopService();
-
myButtonConnect.setText("Connect");