@Override
  public void onDestroy() {
    super.onDestroy();

    mSocket.disconnect();
    mSocket.off("tag message", onNewMessage);
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_public_user_profile);

    mSocket = SocketManager.getMySocket();
    mSocket.on("RGetAllMyDogs", onRGetAllMyDogs);

    int idUser = getIntent().getIntExtra("USER", -1);
    System.out.println("ID U : " + idUser);
    mSocket.emit("getUserById", idUser);
    mSocket.on("RGetUser", onRGetUser);
    mSocket.emit("getAllMyDogs", idUser);

    // Mise en page formulaire
    tvMail = (TextView) findViewById(R.id.userPublicProfileMail_tv);
    tvPhone = (TextView) findViewById(R.id.userPublicProfilePhoneNumber_tv);
    style();
  }
Exemplo n.º 3
0
  public Model(Socket s) {
    listeners = new ArrayList<>();
    String url = "https://cryptic-brushlands-8704.herokuapp.com";
    // String url = "http://192.168.119.233:5000";
    try {
      s = IO.socket(url);
    } catch (URISyntaxException e) {
      Log.e("Connection Error", "Socket was unable to connect");
      e.printStackTrace();
    }
    // Adds the callback funtions for socket events
    s.on("topic", topic);
    s.on("id", id);

    s.connect();

    this.socket = s;

    topics = new ArrayList<>();
    poll = new HashMap<>();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button connectButton = (Button) findViewById(R.id.connectButton);
    textView1 = (TextView) findViewById(R.id.textView1);

    try {
      WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      WifiInfo info = manager.getConnectionInfo();
      String address = info.getMacAddress();

      String address1 = address.replaceAll(":", "");
      String address2 = address1.toUpperCase();
      finalAddress = "AABBCCDDEEFF" + address2;

      // mSocket = IO.socket("http://chat.socket.io");
      String url = "http://192.168.2.133:3000/?clientId=" + finalAddress;
      mSocket = IO.socket(url);
      // mSocket = IO.socket("http://192.168.2.133:3000/?clientId=AABBCCDDEEFF005C889036BB");

    } catch (URISyntaxException e) {
    }

    connectButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            WifiInfo info = manager.getConnectionInfo();
            String address = info.getMacAddress();

            textView1.setText("mac address--------" + finalAddress);
          }
        });

    mSocket.on("tag message", onNewMessage);
    mSocket.connect();
  }
Exemplo n.º 5
0
        public void call(final Object... args) {
          JSONObject data = (JSONObject) args[0];
          Log.d("JSON", data.toString());
          try {

            socket.emit("recevied", "");
            // Add the new topic to the view
            String title = data.getString("title");
            String description = data.getString("description");
            Boolean interesting = data.getBoolean("interesting");
            Boolean difficulty = data.getBoolean("difficulty");

            Boolean quiz = data.getBoolean("quiz");
            Topic theTopic = new Topic(title, description, interesting, difficulty, quiz);

            if (difficulty) {
              int maxDifficulty = data.getInt("maxDifficulty");
              int minDifficulty = data.getInt("minDifficulty");
              theTopic.maxDifficulty = maxDifficulty;
              theTopic.minDifficulty = minDifficulty;
            }

            if (quiz) {
              theTopic.questionType = data.getJSONObject("question").getString("type");
              theTopic.questionText = data.getJSONObject("question").getString("text");
              JSONArray answersArray = data.getJSONArray("answers");
              for (int i = 0; i < answersArray.length(); i++) {
                JSONObject a = (JSONObject) answersArray.get(i);
                String text = a.getString("text");
                Boolean correct = a.getBoolean("correct");
                Answer answer = new Answer(text, correct);

                theTopic.answers.add(theTopic.answers.size(), answer);
              }
            }

            add(theTopic);

          } catch (Exception e) {
            e.printStackTrace();
          }
        }
Exemplo n.º 6
0
 /** Publishes a message containing name, and text. */
 public void pushMessage(String name, String text) {
   socket.emit("status added", text, name);
 }
Exemplo n.º 7
0
 private DAO() {
   socket.connect();
   socket.on("refresh feed", messageListener);
 } // Prevents other instances