Newer
Older
RxSprout / app / src / main / java / com / example / sprout / battles / ResultActivity.java
package com.example.sprout.battles;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.sprout.R;
import com.example.sprout.R.id;
import com.example.sprout.R.layout;
import com.example.sprout.Sprout;
import com.example.sprout.rooms.Member;
import com.example.sprout.rooms.Room;
import com.example.sprout.rooms.RoomMainActivity;
import com.example.sprout.rooms.RoomsConnection;

import net.arnx.jsonic.JSON;

import framework.network.CallBack;

public class ResultActivity extends Activity {
    private RoomsConnection connection;
    private Sprout sprout;
    private boolean result;
    private Member member[] = new Member[4];
    private String name[] = new String[4];
    private TextView memberName[] = new TextView[4];
    private TextView roomname[] = new TextView[4];
    ;
    private int finish, finish2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_result);
        sprout = (Sprout) getApplication();
        connection = sprout.getRoomsConnection();
        result = sprout.getResult();
        //勝敗
        if (result == true) {
            TextView textView = (TextView) findViewById(id.result_textView1);
            textView.setText("勝ち");
        } else if (result == false) {
            TextView textView2 = (TextView) findViewById(id.result_textView1);
            textView2.setText("負け");
        }
        back_button();
        input_data_myteam();
        input_data_enemyteam();
    }

    //ルームに戻るボタン
    public void back_button() {
        Button backButton = (Button) findViewById(id.result_button1);
        backButton.setOnClickListener(new View.OnClickListener() {
            //押したらルーム画面へ戻る
            public void onClick(View v) {
                Intent intent = new Intent(ResultActivity.this, RoomMainActivity.class);
                startActivity(intent);
            }
        });
    }

    //情報入力(自分のチーム)
    public void input_data_myteam() {
        connection = sprout.getRoomsConnection();
        connection.setCallBack(new CallBack() {
            @Override
            public void onResponse(String response) {
                Room room = JSON.decode(response, Room.class);
                roomname[0] = (TextView) findViewById(id.result_team1);
                roomname[0].setText(room.roomName);
                memberName[0] = (TextView) findViewById(id.result_name1);
                memberName[1] = (TextView) findViewById(id.result_name2);
                memberName[2] = (TextView) findViewById(id.result_name3);
                memberName[3] = (TextView) findViewById(id.result_name4);
                for (int i = 0; i < room.getMemberCount(); i++) {
                    memberName[i].setText(room.getMemberByIndex(i).getUserName());
                    finish = i;
                }
                while (finish != 3) {
                    memberName[finish + 1].setText("");
                    finish++;
                }
            }
        });
        connection.addPathParam(String.valueOf(sprout.getMyTeamId()));
        connection.doGet();
    }

    //情報入力(敵のチーム)
    public void input_data_enemyteam() {
        connection = sprout.getRoomsConnection();
        connection.setCallBack(new CallBack() {
            @Override
            public void onResponse(String response2) {
                Room room2 = JSON.decode(response2, Room.class);
                roomname[1] = (TextView) findViewById(id.result_team2);
                roomname[1].setText(room2.roomName);
                memberName[4] = (TextView) findViewById(id.result_name5);
                memberName[5] = (TextView) findViewById(id.result_name6);
                memberName[6] = (TextView) findViewById(id.result_name7);
                memberName[7] = (TextView) findViewById(id.result_name8);
                for (int i = 0; i < room2.getMemberCount(); i++) {
                    member[i + 4] = room2.getMenmber(i);//i番目の人
                    name[i + 4] = member[i + 4].getUserName(); //i番目の人の名前
                    memberName[i + 4].setText(name[i + 4]);
                    finish = i;
                }
                while (finish != 3) {
                    memberName[finish + 4 + 1].setText("");
                    finish++;
                }
            }
        });
        connection.addPathParam(String.valueOf(sprout.getEnemyTeamId()));
        connection.doGet();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.result, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}