1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public class PAN extends Activity implements OnSeekBarChangeListener
{ private SeekBar bar;
private TextView textProgress, textAction;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pan);
bar = (SeekBar)findViewById(R.id.seekBar1);
bar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
textProgress = (TextView)findViewById(R.id.textView1);
textAction = (TextView)findViewById(R.id.textView3);}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
textProgress.setText("The value is: "+progress);
textAction.setText("changing");}
public void onStartTrackingTouch(SeekBar seekBar) {
textAction.setText("starting to track touch");}
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.setSecondaryProgress(seekBar.getProgress());
textAction.setText("ended tracking touch");}
}
class NETWORK extends Activity
{private int port;
private InetAddress address;
private DatagramSocket UDPSocket;
@Override
public void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pan);
try
{UDPSocket = new DatagramSocket();
address = InetAddress.getByName("192.168.1.254");
port = 5000;}
catch (IOException e)
{Toast.makeText(this, "Network error",Toast.LENGTH_LONG).show();}
ToggleButton btn = (ToggleButton) findViewById(R.id.onOffBtn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (((ToggleButton)v).isChecked()) sendOneByte((byte)1);
else sendOneByte((byte)0);
return;}
});}
public void sendOneByte(byte value) {
try {
byte[] data = {value};
DatagramPacket packet;
packet = new DatagramPacket(data, data.length, address, port);
UDPSocket.send(packet);}
catch (Exception e) {
Toast.makeText(this, "Sending error", Toast.LENGTH_LONG).show();}
} }; |
Partager