Android Open Source - VoxPopuli-Android Home Callback






From Project

Back to project page VoxPopuli-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project VoxPopuli-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.kyriog.android.voxpopuli.socketio;
//  w w  w  .  j  a v  a  2  s  .  c o  m
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import fr.kyriog.android.voxpopuli.entity.Game;

import android.os.Handler;
import android.os.Message;

import io.socket.IOAcknowledge;

public class HomeCallback extends BaseCallback {
  public HomeCallback(Handler handler) {
    super(handler);
  }

  @Override
  public void on(String event, IOAcknowledge ack, Object... args) {
    if("tickList".equals(event)) {
      try {
        JSONObject json = (JSONObject) args[0];
        JSONArray waitingGames = json.getJSONArray("waiting");
        List<Game> games = new ArrayList<Game>();
        for(int i = 0; i < waitingGames.length(); i++) {
          JSONObject jsonGame = waitingGames.getJSONObject(i);
          Game game = new Game(jsonGame.getString("room_id"));
          game.setGamemode(jsonGame.getJSONObject("gamemode").getString("name"));
          game.setNbPlayers(jsonGame.getInt("nbPlayers"));
          game.setNbMinPlayers(jsonGame.getInt("minPlayers"));
          game.setNbMaxPlayers(jsonGame.getInt("maxPlayers"));

          games.add(game);
        }

        Message msg = new Message();
        msg.obj = games;
        handler.sendMessage(msg);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  }
}




Java Source Code List

fr.kyriog.android.voxpopuli.GameActivity.java
fr.kyriog.android.voxpopuli.HomeActivity.java
fr.kyriog.android.voxpopuli.LoginActivity.java
fr.kyriog.android.voxpopuli.adapter.HomeAdapter.java
fr.kyriog.android.voxpopuli.adapter.PlayerAdapter.java
fr.kyriog.android.voxpopuli.adapter.ResultPlayerAdapter.java
fr.kyriog.android.voxpopuli.adapter.VotedPlayerAdapter.java
fr.kyriog.android.voxpopuli.entity.Game.java
fr.kyriog.android.voxpopuli.entity.Player.java
fr.kyriog.android.voxpopuli.entity.Question.java
fr.kyriog.android.voxpopuli.handler.AvatarHandler.java
fr.kyriog.android.voxpopuli.handler.GameHandler.java
fr.kyriog.android.voxpopuli.handler.HomeHandler.java
fr.kyriog.android.voxpopuli.socketio.BaseCallback.java
fr.kyriog.android.voxpopuli.socketio.GameCallback.java
fr.kyriog.android.voxpopuli.socketio.HomeCallback.java
fr.kyriog.android.voxpopuli.thread.AvatarDownloader.java