Newer
Older
IrisClient / app / src / main / java / org / ntlab / irisclient / TestDrawingActivity.java
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.resources.GameRest;
import org.ntlab.irisclient.resources.RoomsRest;

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) {
                //(ownerのみ)drawtestを更新 : は動かない
/*
                Call<Void> call = roomsRest.putTestRoom();
                call.enqueue(new Callback<Void>() {
                    @Override
                    public void onResponse(Call<Void> call, Response<Void> response) {
                        if (response.isSuccessful()){
                            System.out.println("通信成功:createDrawTest");
                        }
                    }
                    @Override
                    public void onFailure(Call<Void> call, Throwable t) {
                        System.out.println("通信失敗:createDrawTest");
                        System.out.println(t);
                    }
                });
*/
                ((Iris) getApplication()).setRid("drawtest");
                ((Iris) getApplication()).setNickname("owner");
                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");
                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);
            }
        });

    }
}