Commit 20893dd3 authored by Krish Shah's avatar Krish Shah
Browse files

Updated frontend, completed Preliminary Issue: Repeated Event

parent 0f9f99c9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".PopUpWindow"
            android:configChanges="orientation"
            android:screenOrientation="portrait">
        </activity>
    </application>

</manifest>
 No newline at end of file
+91 −3
Original line number Diff line number Diff line
package com.example.a8_bitinvader;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Button;
import android.content.Context;
import android.media.AudioManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Handler;

public class MainActivity extends AppCompatActivity {

    Animation animation;
    boolean play;

    /**
     * Displays the menu and checks for user input to click play
     * @param savedInstanceState The cached state of the game
@@ -25,19 +36,86 @@ public class MainActivity extends AppCompatActivity {
            getSupportActionBar().hide();
        }


        // initalizes 8-bit Invaders Logo

        ImageView myImageView = (ImageView) findViewById(R.id.image_logo);
        myImageView.setImageResource(R.drawable.logobit);
        ImageView logo = (ImageView) findViewById(R.id.image_logo);
        logo.setImageResource(R.drawable.logobit);

        // Creates new Intent and starts GameActivity if 'play' is pressed on MainActivity screen.
        findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_animation);
                // logo.startAnimation(animation);
                startActivity(new Intent(MainActivity.this, GameActivity.class));
                play = true;
            }
        });

        // Creates new Intent and Mutes Device Audio if mute button is pressed on MainActivity screen
        // Reference: https://www.youtube.com/watch?v=_Klq62-me8s&ab_channel=AppleCoders
        // Reference: https://developer.android.com/reference/android/media/MediaPlayer
        findViewById(R.id.mute_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Declare an audio manager
                AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
                // ADJUST_MUTE => mutes the device
                // FLAG_SHOW_UI => Show changes made to the volume bar
                audioManager.adjustVolume (AudioManager.ADJUST_MUTE, AudioManager.FLAG_SHOW_UI);

            }

        });


        // Creates new Intent and stars LeaderboardView if the leaderboard button is pressed on the MainActivity Screen
        // As of 4/14 12:51 AM, this is not implemented with LeaderboardView -- Krish Shah

        findViewById(R.id.leaderboard_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openPopUpWindow();
            }
        });


        //Code to show the toast every 5 seconds. For Preliminary Issue: Repeated event
        Timer timer = new Timer();
        Context context = getApplicationContext();
        CharSequence text = "Hello toast!";
        int duration = 5000;

        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        final Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
                        toast.show();
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                toast.cancel();
                            }
                        }, duration);

                    }
                });
            }
        }, 0, duration);
        }

    private void openPopUpWindow() {
        Intent popupwindow = new Intent(MainActivity.this, PopUpWindow.class);
        startActivity(popupwindow);
    }

    /**
     * Start the game
@@ -86,4 +164,14 @@ public class MainActivity extends AppCompatActivity {
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    public void onBackPressed() {

        // Call super.onBackPressed() to perform default back button behavior
        super.onBackPressed();

    }


}
 No newline at end of file
+38 −0
Original line number Diff line number Diff line
package com.example.a8_bitinvader;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Button;
import android.content.Context;
import android.media.AudioManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.util.DisplayMetrics;
public class PopUpWindow extends AppCompatActivity{

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.popup_window);

      DisplayMetrics dm = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics (dm);

      int width = dm.widthPixels;
      int height = dm.heightPixels;

      getWindow().setLayout((int)(width*.7), (int)(height*.5));

      WindowManager.LayoutParams params = getWindow().getAttributes();
      params.gravity = Gravity.CENTER;
      params.x = 0;
      params.y = -20;

      getWindow().setAttributes(params);
   }

}
+10 −0
Original line number Diff line number Diff line
package com.example.a8_bitinvader;

import android.view.animation.Interpolator;

public class ReverseInterpolator implements Interpolator {
   @Override
   public float getInterpolation(float paramFloat) {
      return Math.abs(paramFloat -1f);
   }
}
+9 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="500"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>
Loading