From 0c5e78dfc7956ec00804cf1af8611be84d28f65e Mon Sep 17 00:00:00 2001 From: pip Date: Thu, 20 Apr 2023 11:44:24 -0400 Subject: [PATCH] Added pop up introduction to name game --- .../java/com/example/game2d/NameActivity.java | 39 +++++++++++ .../java/com/example/game2d/mainpopup.java | 5 ++ app/src/main/res/drawable/buttonbg.xml | 6 ++ app/src/main/res/drawable/popupbg.xml | 5 ++ app/src/main/res/layout/activity_name.xml | 1 + app/src/main/res/layout/mainpopup.xml | 65 +++++++++++++++++++ local.properties | 4 +- 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/example/game2d/mainpopup.java create mode 100644 app/src/main/res/drawable/buttonbg.xml create mode 100644 app/src/main/res/drawable/popupbg.xml create mode 100644 app/src/main/res/layout/mainpopup.xml diff --git a/app/src/main/java/com/example/game2d/NameActivity.java b/app/src/main/java/com/example/game2d/NameActivity.java index 7126b93..feef863 100644 --- a/app/src/main/java/com/example/game2d/NameActivity.java +++ b/app/src/main/java/com/example/game2d/NameActivity.java @@ -8,8 +8,13 @@ import android.content.SharedPreferences; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; +import android.widget.PopupWindow; +import android.widget.RelativeLayout; import android.widget.TextView; import android.os.Handler; @@ -26,11 +31,19 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe int currentQuestionIndex = 0; String selectedAnswer = ""; + //for pop up intro + RelativeLayout layout; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_name); + + //for pop up intro + layout = findViewById(R.id.nameActivity); // relative is the id of the layout of the page + CreatepopUpwindow(); + totalQuestionsTextView = findViewById(R.id.total_question); nameTextView = findViewById(R.id.names); yes = findViewById(R.id.yes); @@ -50,6 +63,32 @@ public class NameActivity extends AppCompatActivity implements View.OnClickListe loadNewQuestion(); + } + + //for pop up window + private void CreatepopUpwindow() { + LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + View popUpView=inflater.inflate(R.layout.mainpopup,null); + + int width = ViewGroup.LayoutParams.MATCH_PARENT; + int height= ViewGroup.LayoutParams.MATCH_PARENT; + boolean focusable = true; + PopupWindow popupWindow = new PopupWindow(popUpView, width,height,focusable); + layout.post(new Runnable() { + @Override + public void run() { + popupWindow.showAtLocation(layout, Gravity.BOTTOM,0,0); + } + }); + TextView Continue; + Continue = popUpView.findViewById(R.id.Continue); + Continue.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + popupWindow.dismiss(); + } + }); + } @Override public void onClick(View view) { diff --git a/app/src/main/java/com/example/game2d/mainpopup.java b/app/src/main/java/com/example/game2d/mainpopup.java new file mode 100644 index 0000000..4ca620d --- /dev/null +++ b/app/src/main/java/com/example/game2d/mainpopup.java @@ -0,0 +1,5 @@ +package com.example.game2d; + +public class mainpopup { +} + diff --git a/app/src/main/res/drawable/buttonbg.xml b/app/src/main/res/drawable/buttonbg.xml new file mode 100644 index 0000000..09b3861 --- /dev/null +++ b/app/src/main/res/drawable/buttonbg.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/popupbg.xml b/app/src/main/res/drawable/popupbg.xml new file mode 100644 index 0000000..c604bea --- /dev/null +++ b/app/src/main/res/drawable/popupbg.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_name.xml b/app/src/main/res/layout/activity_name.xml index c937b10..27da7e9 100644 --- a/app/src/main/res/layout/activity_name.xml +++ b/app/src/main/res/layout/activity_name.xml @@ -10,6 +10,7 @@ android:layout_height="match_parent" android:background="@color/white_200" android:padding="24dp" + android:id="@+id/nameActivity" tools:context=".MainActivity"> diff --git a/app/src/main/res/layout/mainpopup.xml b/app/src/main/res/layout/mainpopup.xml new file mode 100644 index 0000000..4ec11b7 --- /dev/null +++ b/app/src/main/res/layout/mainpopup.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/local.properties b/local.properties index fff1b21..fc78f57 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Tue Apr 04 09:53:09 EDT 2023 -sdk.dir=/home/elena/Android/Sdk +#Wed Apr 19 15:38:28 EDT 2023 +sdk.dir=/Users/joharper/Library/Android/sdk -- GitLab