package org.ntlab.irisclient; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import android.os.Bundle; import android.view.View; import org.ntlab.irisclient.viewmodels.DrawingStateViewModel; public class DrawingActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawing); DrawingStateViewModel drawingStateViewModel = new ViewModelProvider(this).get(DrawingStateViewModel.class); //Irisから必要な情報を取得 Iris iris = (Iris) this.getApplication(); String rid = iris.getRid(); String nickName = iris.getNickname(); //viewModelに必用な情報をセット drawingStateViewModel.setRid(rid); drawingStateViewModel.setNickName(nickName); //タイマースタート呼び出し //drawingStateViewModel.start(100ms); findViewById(R.id.okButtton).setOnClickListener(this);//お絵描き終了ボタン drawingStateViewModel.getDno().observe(this, new Observer<Integer>() { private Integer dno; @Override public void onChanged(Integer dno) { this.dno = dno; } }); drawingStateViewModel.getState().observe(this, new Observer<Integer>() { private Integer state; @Override public void onChanged(Integer state) { this.state = state; } }); } @Override public void onClick(View v){ DrawingStateViewModel drawingStateViewModel = new ViewModelProvider(this).get(DrawingStateViewModel.class); if(v.getId() == R.id.okButtton) { //okButtonが押された処理 drawingStateViewModel.putDrawing(); } } }