package org.ntlab.irisclient; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import org.ntlab.irisclient.models.Member; import org.ntlab.irisclient.resources.GameRest; import org.ntlab.irisclient.resources.RoomsRest; import java.util.List; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class TestDrawingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_activity_draw); //サーバーとの通信を初期化 Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") .addConverterFactory(JacksonConverterFactory.create()) .build(); final RoomsRest roomsRest = retrofit.create(RoomsRest.class); //上の表示を削除 ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.hide(); } //ownerとして参加 Button ownerButton = findViewById(R.id.ownerdraw); ownerButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("drawtest"); ((Iris) getApplication()).setNickname("owner"); ((Iris) getApplication()).setTeam("r"); ((Iris) getApplication()).setMaster(true); Call<List<Member>> call = roomsRest.getRoomMember("drawtest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功:createDrawTest"); ((Iris) getApplication()).setMemberList(response.body()); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗:createDrawTest"); System.out.println(t); } }); Intent intent = new Intent(TestDrawingActivity.this,DrawingActivity.class); startActivity(intent); } }); //memberとして参加 Button memButton = findViewById(R.id.member); memButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("drawtest"); ((Iris) getApplication()).setNickname("member"); ((Iris) getApplication()).setTeam("b"); ((Iris) getApplication()).setMaster(true); Call<List<Member>> call = roomsRest.getRoomMember("drawtest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功:createDrawTest"); ((Iris) getApplication()).setMemberList(response.body()); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗:createDrawTest"); System.out.println(t); } }); Intent intent = new Intent(TestDrawingActivity.this,DrawingActivity.class); startActivity(intent); } }); //backボタン Button backButton = findViewById(R.id.fromdraw); backButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(TestDrawingActivity.this,TestEnterActivity.class); startActivity(intent); } }); } }