diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingActivity.java b/app/src/main/java/org/ntlab/irisclient/DrawingActivity.java index 6935caf..1410ac5 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingActivity.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingActivity.java @@ -30,6 +30,7 @@ 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に必用な情報をセット @@ -55,9 +56,12 @@ drawingStateViewModel.getState().observe(this, new Observer() { @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, GameMemberActivity.class); + Intent intent = new Intent(DrawingActivity.this, nextActivity); startActivity(intent); } } diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java index 94d43b6..ab43f5a 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java @@ -1,25 +1,20 @@ package org.ntlab.irisclient; -import android.content.Context; import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.media.Image; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; -import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; public class DrawingCardFragment extends Fragment { - + private ImageButton[] imageButtons; + private Drawable[] images; // コンストラクタ public static DrawingCardFragment newInstance(String str){ @@ -32,71 +27,65 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - Resources resources = getResources(); + Resources resources = getResources(); View view = inflater.inflate(R.layout.fragment_card_drawing, container, false); - ImageButton imageButton00 = (ImageButton) view.findViewById(R.id.imageButton00); - imageButton00.setBackground(resources.getDrawable(R.drawable.test02)); + // ImageButton16個の型を使いまわしやすいように配列で使用 + imageButtons = new ImageButton[]{ + (ImageButton) view.findViewById(R.id.imageButton00), + (ImageButton) view.findViewById(R.id.imageButton01), + (ImageButton) view.findViewById(R.id.imageButton02), + (ImageButton) view.findViewById(R.id.imageButton03), + (ImageButton) view.findViewById(R.id.imageButton10), + (ImageButton) view.findViewById(R.id.imageButton11), + (ImageButton) view.findViewById(R.id.imageButton12), + (ImageButton) view.findViewById(R.id.imageButton13), + (ImageButton) view.findViewById(R.id.imageButton20), + (ImageButton) view.findViewById(R.id.imageButton21), + (ImageButton) view.findViewById(R.id.imageButton22), + (ImageButton) view.findViewById(R.id.imageButton23), + (ImageButton) view.findViewById(R.id.imageButton30), + (ImageButton) view.findViewById(R.id.imageButton31), + (ImageButton) view.findViewById(R.id.imageButton32), + (ImageButton) view.findViewById(R.id.imageButton33) + }; - ImageButton imageButton01 = (ImageButton) view.findViewById(R.id.imageButton01); - imageButton01.setBackground(resources.getDrawable(R.drawable.test02)); + // 16枚表示させるImage画像の配列 + images = new Drawable[]{ + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02), + resources.getDrawable(R.drawable.test02) + }; - ImageButton imageButton02 = (ImageButton) view.findViewById(R.id.imageButton02); - imageButton02.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton03 = (ImageButton) view.findViewById(R.id.imageButton03); - imageButton03.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton10 = (ImageButton) view.findViewById(R.id.imageButton10); - imageButton10.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton11 = (ImageButton) view.findViewById(R.id.imageButton11); - imageButton11.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton12 = (ImageButton) view.findViewById(R.id.imageButton12); - imageButton12.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton13 = (ImageButton) view.findViewById(R.id.imageButton13); - imageButton13.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton20 = (ImageButton) view.findViewById(R.id.imageButton20); - imageButton20.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton21 = (ImageButton) view.findViewById(R.id.imageButton21); - imageButton21.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton22 = (ImageButton) view.findViewById(R.id.imageButton22); - imageButton22.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton23 = (ImageButton) view.findViewById(R.id.imageButton23); - imageButton23.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton30 = (ImageButton) view.findViewById(R.id.imageButton30); - imageButton30.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton31 = (ImageButton) view.findViewById(R.id.imageButton31); - imageButton31.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton32 = (ImageButton) view.findViewById(R.id.imageButton32); - imageButton32.setBackground(resources.getDrawable(R.drawable.test02)); - - ImageButton imageButton33 = (ImageButton) view.findViewById(R.id.imageButton33); - imageButton33.setBackground(resources.getDrawable(R.drawable.test02)); + for(int i=0; i< imageButtons.length; i++) { + imageButtons[i].setOnClickListener(this::onClick); + imageButtons[i].setBackground(images[i]); + }; return view; } - @Override - public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + public void onClick(View v) { -// FragmentManager fragmentManager = getChildFragmentManager(); -// FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); -// fragmentTransaction.addToBackStack(null); -// fragmentTransaction.replace(R.id.container, -// DrawingCardFragment.newInstance("Fragment")); -// fragmentTransaction.commit(); + for(int i=0; i< imageButtons.length; i++) { + if(v.getId() == imageButtons[i].getId()) { + System.out.println( "タップされたボタンの配列番号:" + i); + } + } } } diff --git a/app/src/main/java/org/ntlab/irisclient/Iris.java b/app/src/main/java/org/ntlab/irisclient/Iris.java index 05117ed..d482cda 100644 --- a/app/src/main/java/org/ntlab/irisclient/Iris.java +++ b/app/src/main/java/org/ntlab/irisclient/Iris.java @@ -8,6 +8,8 @@ public class Iris extends Application { private String rid; private String nickname; + private String team; + private boolean bMaster; //---------------------------------------------------------- // getter public String getRid() { @@ -18,6 +20,10 @@ return this.nickname; } + public String getTeam() { return this.team; } + + public boolean isMaster() { return this.bMaster; } + //---------------------------------------------------------- // setter public void setRid(String rid) { @@ -28,4 +34,8 @@ this.nickname = nickname; } + public void setTeam(String team) { this.team = team; } + + public void setMaster(boolean master) { bMaster = master; } + }