Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.Kalkulator;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.os.Vibrator;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.Spinner;
- import android.widget.Toast;
- import java.util.Random;
- public class MainActivity3 extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
- int spinner_selected = 0;
- ImageView kocka;
- Spinner spinner3;
- Random random = new Random();
- void baciKocku(){
- int i = random.nextInt(6) + 1; // Ide od 0 - 5 bez + 1 na kraju, zato treba ici +1.
- Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
- kocka.startAnimation(animation);
- switch(i){
- case 1:
- kocka.setImageResource(R.drawable.one);
- SingleToast.show(getApplicationContext(), "1", Toast.LENGTH_SHORT);
- break;
- case 2:
- kocka.setImageResource(R.drawable.two);
- SingleToast.show(getApplicationContext(), "2", Toast.LENGTH_SHORT);
- break;
- case 3:
- kocka.setImageResource(R.drawable.three);
- SingleToast.show(getApplicationContext(), "3", Toast.LENGTH_SHORT);
- break;
- case 4:
- kocka.setImageResource(R.drawable.four);
- SingleToast.show(getApplicationContext(), "4", Toast.LENGTH_SHORT);
- break;
- case 5:
- kocka.setImageResource(R.drawable.five);
- SingleToast.show(getApplicationContext(), "5", Toast.LENGTH_SHORT);
- break;
- case 6:
- kocka.setImageResource(R.drawable.six);
- SingleToast.show(getApplicationContext(), "6", Toast.LENGTH_SHORT);
- break;
- }
- }
- public void otvoriMainActivity(){
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- v.vibrate(1);
- Intent intent = new Intent(this, MainActivity.class);
- startActivity(intent);
- }
- public void otvoriMainActivity2(){
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- v.vibrate(1);
- Intent intent = new Intent(this, MainActivity2.class);
- startActivity(intent);
- }
- public void otvoriMainActivity4(){
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- v.vibrate(1);
- Intent intent = new Intent(this, MainActivity4.class);
- startActivity(intent);
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main3);
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- final MediaPlayer bacanje_kocke = MediaPlayer.create(this, R.raw.shake_dice);
- kocka = findViewById(R.id.kocka);
- spinner3 = findViewById(R.id.spinner3);
- ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.menu_MainActivity3, R.layout.dropdown_button);
- adapter3.setDropDownViewResource(R.layout.dropdown_item);
- spinner3.setAdapter(adapter3);
- spinner3.setOnItemSelectedListener(this);
- kocka.setOnClickListener(view -> {
- if(!bacanje_kocke.isPlaying()) {
- v.vibrate(1);
- bacanje_kocke.start();
- baciKocku();
- }
- else{
- SingleToast.show(getApplicationContext(), "Kocka se još baca!", Toast.LENGTH_SHORT);
- }
- });
- }
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- String text = parent.getItemAtPosition(position).toString();
- if (spinner_selected > 0) {
- switch (text) {
- case "\uD83E\uDDEE":
- otvoriMainActivity();
- SingleToast.show(getApplicationContext(), text, Toast.LENGTH_SHORT);
- break;
- case "\uD83D\uDCCF":
- otvoriMainActivity2();
- SingleToast.show(getApplicationContext(), text, Toast.LENGTH_SHORT);
- break;
- case "\uD83E\uDE99":
- otvoriMainActivity4();
- SingleToast.show(getApplicationContext(), text, Toast.LENGTH_SHORT);
- break;
- }
- }
- spinner_selected++;
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement