package com.example.nemophila; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.ViewModelProvider; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.Spinner; import com.example.nemophila.viewmodels.AccountViewModel; import com.example.nemophila.viewmodels.FriendViewModel; import com.example.nemophila.viewmodels.PostsViewModel; import com.example.nemophila.viewmodels.ShopsViewModel; import java.util.Base64; public class TestActivity extends AppCompatActivity { int position; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); Nemophila nemophila = (Nemophila) this.getApplication(); //テスト用ViewModel(ViewModelが増えた場合はここで準備。spinnerItemに名前も追加すること) //ViewModelへのアクセス ShopsViewModel shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class); AccountViewModel accountViewModel = new ViewModelProvider(this).get(AccountViewModel.class); PostsViewModel postsViewModel = new ViewModelProvider(this).get(PostsViewModel.class); FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class); //テスト用のspinner Spinner spinner = findViewById(R.id.testspinner); String[] spinnerItems = {"ShopsViewModel", "AccountViewModel", "PostsViewModel", "FriendsViewModel"}; //ここに名前を追加 ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, spinnerItems); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { position = i; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // setViewModelのテスト用 Button setViewModelButton = (Button)findViewById(R.id.setViewModel); setViewModelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (position){ //ここにテストしたい処理を追加する( 0はShopsViewModel、1はAccountViewModel、2はPostsViewModel) case 0: shopsViewModel.setViewArea(20.0, 40.0, 10.0, 30.0); // shopsViewModel.start(500, nemophila); break; case 1: //accountViewModel.getAccountPosts("1111"); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); String s = "Y29udGVudDovL2NvbS5hbmRyb2lkLnByb3ZpZGVycy5tZWRpYS5kb2N1bWVudHMvZG9jdW1lbnQvaW1hZ2UlM0EzNA=="; s = new String(Base64.getDecoder().decode(s)); Uri uri = Uri.parse(s); ImageView imageView = findViewById(R.id.imageView4); imageView.setImageURI(uri); break; case 2: postsViewModel.createPost("1114", "dbfd3740-8dcc-4b9c-b3b0-42c908da1c65", "151347fa-2c90-44d7-ba48-f23f475b910d", 1, "和食", "辛いね", "", "", ""); break; case 3: // friendViewModel.putRequesting("1111", "1112", "a95d68cc-4efb-49e2-8f55-799f768a5c09"); } } }); } }