package org.ntlab.irisclient; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; import org.ntlab.irisclient.viewmodels.DrawingStateViewModel; import java.util.List; public class DrawingActivity extends AppCompatActivity implements View.OnClickListener { private DrawingCanvas drawingCanvas; DrawingStateViewModel drawingStateViewModel = new ViewModelProvider(this).get(DrawingStateViewModel.class); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawing); drawingCanvas = (DrawingCanvas) findViewById(R.id.canvas); //Irisから必要な情報を取得 Iris iris = (Iris) this.getApplication(); String rid = iris.getRid(); String nickName = iris.getNickname(); //viewModelに必用な情報をセット drawingStateViewModel.setRid(rid); drawingStateViewModel.setNickName(nickName); findViewById(R.id.okButtton).setOnClickListener(this);//お絵描き終了ボタン TextView textKeyword =(TextView)findViewById(R.id.textKeyword);//keywordのTextView //getKeywords List<String> keywords = drawingStateViewModel.getKeywords(rid); //getDno drawingStateViewModel.getDno().observe(this, new Observer<Integer>() { @Override public void onChanged(Integer dno) { String keyword = keywords.get(dno); textKeyword.setText(keyword); } }); //getState drawingStateViewModel.getState().observe(this, new Observer<Integer>() { @Override public void onChanged(Integer state) { //stateが変わったらゲーム画面へ遷移 Intent intent = new Intent(DrawingActivity.this, GameMemberActivity.class); startActivity(intent); } }); //タイマースタート呼び出し drawingStateViewModel.start(500); } @Override public void onClick(View v){ if(v.getId() == R.id.okButtton) {//okButtonが押されたときの処理 drawingStateViewModel.putDrawing(); }else if(v.getId() == R.id.clearButton){//clearButtonが押されたときの処理 drawingCanvas.clearCanvas(); } } }