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.models.Member; import org.ntlab.irisclient.viewmodels.DrawingStateViewModel; import java.io.ByteArrayOutputStream; import java.util.List; public class DrawingActivity extends AppCompatActivity implements View.OnClickListener { private DrawingCanvas drawingCanvas; private DrawingStateViewModel drawingStateViewModel; private List<String> keywordList; private Integer drawingNum; private Integer drawingNow = 1; @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(); List<Member> memberList = iris.getMemberList(); 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);//画面クリアボタン findViewById(R.id.eraserButton).setOnClickListener(this);//消しゴムボタン TextView textKeyword =(TextView)findViewById(R.id.textKeyword);//keywordのTextView TextView textMemberNum = (TextView)findViewById(R.id.drawingNowText);//残りのイラスト枚数のTextView drawingCanvas = (DrawingCanvas) findViewById(R.id.drawingCanvas); //残りのイラスト枚数の表示 // if(memberList.size() != 0) { // drawingNum = 16 / memberList.size(); // 一人あたりが描く枚数 // if (16 % memberList.size() != 0) drawingNum++; // 余りが出た場合プラス1枚 // textMemberNum.setText("" + drawingNow + "/" + drawingNum); // } //getKeywords drawingStateViewModel.getKeywords().observe(this, new Observer<List<String>>(){ @Override public void onChanged(List<String> keywords) { keywordList = keywords; } }); //getDno drawingStateViewModel.getDno().observe(this, new Observer<Integer>() { @Override public void onChanged(Integer dno) { String keyword = keywordList.get(dno); textKeyword.setText("Dno: " + dno + ", Keyword: " + keyword); // drawingNow++; // textMemberNum.setText(""+drawingNow+"/"+drawingNum); } }); //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); } } }); //getKeywordの呼び出し drawingStateViewModel.init(); //タイマースタート呼び出し drawingStateViewModel.start(500,(Iris)getApplication()); } @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(); }else if(v.getId() == R.id.eraserButton){//eraserButtonが押されたときの処理 drawingCanvas.eraserPaint(); } } }