Back to project page VoxPopuli-Android.
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.
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(); } } } }