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.os.Bundle;
- import android.os.Vibrator;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.RotateAnimation;
- 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 MainActivity5 extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
- int spinner_selected = 0;
- private ImageView boca;
- private Random r = new Random();
- private int lastDir;
- private boolean vrti;
- Spinner spinner3;
- 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 otvoriMainActivity3(){
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- v.vibrate(1);
- Intent intent = new Intent(this, MainActivity3.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_main5);
- boca = findViewById(R.id.boca);
- spinner3 = findViewById(R.id.spinner3);
- ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.menu_MainActivity5, R.layout.dropdown_button);
- adapter3.setDropDownViewResource(R.layout.dropdown_item);
- spinner3.setAdapter(adapter3);
- spinner3.setOnItemSelectedListener(this);
- }
- public void spinBottle(View v) {
- if (!vrti) {
- int newDir = r.nextInt(1800);
- float pivotX = boca.getWidth() / 2;
- float pivotY = boca.getHeight() / 2;
- Animation rotate = new RotateAnimation(lastDir, newDir, pivotX, pivotY);
- rotate.setDuration(2500);
- rotate.setFillAfter(true);
- rotate.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- vrti = true;
- }
- @Override
- public void onAnimationEnd(Animation animation) {
- SingleToast.show(getApplicationContext(), "Animacija je gotova!", Toast.LENGTH_SHORT);
- vrti = false;
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- });
- lastDir = newDir;
- boca.startAnimation(rotate);
- }
- else {
- SingleToast.show(getApplicationContext(), "Animacija nije gotova!", 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 "\uD83C\uDFB2":
- otvoriMainActivity3();
- 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