package org.ntlab.irisclient; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import android.content.Intent; import android.graphics.Bitmap; 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; private DrawingStateViewModel drawingStateViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawing); //Irisから必要な情報を取得 Iris iris = (Iris) this.getApplication(); String rid = iris.getRid(); String nickName = iris.getNickname(); Boolean bMaster = iris.isMaster(); drawingStateViewModel= new ViewModelProvider(this).get(DrawingStateViewModel.class); //viewModelに必用な情報をセット drawingStateViewModel.setRid(rid); drawingStateViewModel.setNickName(nickName); findViewById(R.id.okButtton).setOnClickListener(this);//お絵描き終了ボタン findViewById(R.id.clearButton).setOnClickListener(this);//画面クリアボタン TextView textKeyword =(TextView)findViewById(R.id.textKeyword);//keywordのTextView drawingCanvas = (DrawingCanvas) findViewById(R.id.drawingCanvas); //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(""+dno); } }); //getState drawingStateViewModel.getState().observe(this, new Observer<Integer>() { @Override public void onChanged(Integer state) { Class nextActivity = GameMemberActivity.class; if(bMaster) nextActivity = GameMasterActivity.class;//自分がMasterならMaster用のGame画面へ遷移 //stateが変わったらゲーム画面へ遷移 if(state == 3) { Intent intent = new Intent(DrawingActivity.this, nextActivity); startActivity(intent); } } }); //タイマースタート呼び出し drawingStateViewModel.start(500); } @Override public void onClick(View v){ if(v.getId() == R.id.okButtton) {//okButtonが押されたときの処理 Bitmap bitmap = null; drawingStateViewModel.putDrawing(bitmap); }else if(v.getId() == R.id.clearButton){//clearButtonが押されたときの処理 drawingCanvas.clearCanvas(); } } }