Advertisement
Guest User

android main class

a guest
Jan 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. package com.bootje.stijn.bootje;
  2.  
  3. import android.content.Context;
  4. import android.content.pm.ActivityInfo;
  5. import android.net.wifi.WifiConfiguration;
  6. import android.net.wifi.WifiManager;
  7. import android.os.Looper;
  8. import android.os.Message;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.view.View.*;
  14. import android.view.*;
  15. import android.widget.Toast;
  16.  
  17. public class Bootje extends AppCompatActivity {
  18.  
  19. public static Bootje main;
  20. boolean disconnected = false;
  21.  
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_bootje);
  26. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
  27. registerListeners();
  28. main = this;
  29. }
  30.  
  31. void registerListeners() {
  32. Button button = (Button) findViewById(R.id.links);
  33. Button button2 = (Button) findViewById(R.id.rechts);
  34. Button status = (Button) findViewById(R.id.check);
  35. //check
  36. status.setOnClickListener(new OnClickListener() {
  37. @Override
  38. public void onClick(View v) {
  39. setStatus("Verbinding testen...");
  40. new sendTCP().execute("check");
  41. }
  42. });
  43. //links
  44. button.setOnTouchListener(new OnTouchListener() {
  45. @Override
  46. public boolean onTouch(View v, MotionEvent event) {
  47. if (event.getAction() == MotionEvent.ACTION_UP ||
  48. event.getAction() == MotionEvent.ACTION_CANCEL) {
  49. new sendTCP().execute("leftoff");
  50. } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
  51. new sendTCP().execute("lefton");
  52. }
  53. return false;
  54. }
  55. });
  56. //rechts
  57. button2.setOnTouchListener(new OnTouchListener() {
  58. @Override
  59. public boolean onTouch(View v, MotionEvent event) {
  60. if (event.getAction() == MotionEvent.ACTION_UP ||
  61. event.getAction() == MotionEvent.ACTION_CANCEL) {
  62. new sendTCP().execute("rightoff");
  63. } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
  64. new sendTCP().execute("righton");
  65. }
  66. return false;
  67. }
  68. });
  69. }
  70.  
  71. public void setStatus(final String message) {
  72. Context context = Bootje.main.getApplicationContext();
  73. Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement