diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2996d53..9bba60d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,14 +1,20 @@ + diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 29855f7..e5ccd03 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 419509c..e1f72b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,20 +6,18 @@ - - - - + android:theme="@style/AppTheme" + android:usesCleartextTraffic="true"> + + @@ -27,10 +25,10 @@ - + - diff --git a/app/src/main/java/com/example/aorora/ARScreen.java b/app/src/main/java/com/example/aorora/ARScreen.java new file mode 100644 index 0000000..f21b5ec --- /dev/null +++ b/app/src/main/java/com/example/aorora/ARScreen.java @@ -0,0 +1,116 @@ +package com.example.aorora; + +import android.content.Context; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.GestureDetector; +import android.view.View; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.Toast; + +import com.example.aorora.network.GetDataService; +import com.example.aorora.network.NetworkCalls; +import com.example.aorora.network.RetrofitClientInstance; + +public class ARScreen extends AppCompatActivity implements View.OnClickListener { + //User account info + Integer userPollen; + Integer userId; + + //Retrofit network object + GetDataService service; + + Context arScreen; + ImageButton home_button_bottombar; + ImageButton profile_button_bottombar; + ImageButton community_button_bottombar; + ImageButton quest_button_bottombar; + Button spendPollenBtn; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //User account info + userPollen = MainActivity.user_info.getUser_pollen(); + userId = MainActivity.user_info.getUser_id(); + + //Retrofit objects + //Init our backend service + service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class); + + setContentView(R.layout.activity_ar_screen); + arScreen = this; + home_button_bottombar = (ImageButton) findViewById(R.id.home_button_bottom_bar); + profile_button_bottombar = (ImageButton) findViewById(R.id.profile_button_bottom_bar); + community_button_bottombar = (ImageButton) findViewById(R.id.community_button_bottom_bar); + quest_button_bottombar = (ImageButton) findViewById(R.id.quest_button_bottom_bar); + spendPollenBtn = (Button) findViewById(R.id.spend_pollen_btn); + + + //Onclicklisteners for this class. + home_button_bottombar.setOnClickListener(this); + profile_button_bottombar.setOnClickListener(this); + community_button_bottombar.setOnClickListener(this); + quest_button_bottombar.setOnClickListener(this); + + + + spendPollenBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(!hasEnoughPollen()){ + Toast.makeText(ARScreen.this, "Sorry! Not enough pollen! Complete some quests!", Toast.LENGTH_SHORT).show(); + return; + } + //Otherwise, we have enough pollen, decrement it and update the backend. + userPollen -= 10; + Toast.makeText(ARScreen.this, "Spending pollen to access AR butterflies for one day.", Toast.LENGTH_SHORT).show(); + //TODO: Add one day activation of butterfly activity, perhaps in MainActivity or UserInfo? + //Finally do the PUT request with the new pollen value. May need to refresh the UI. + //This is not updating the backend, need to use a network call. + MainActivity.user_info.setUser_pollen(userPollen); + //This will update the backend and set the current pollen to our decremented value. + NetworkCalls.updateUserCurrentPoints(userId, userPollen,ARScreen.this); + } + }); + + } + + public boolean hasEnoughPollen() { + return userPollen >= 10; + } + + @Override + public void onClick(View v) { + int view_id = v.getId(); + Intent to_navigate; + + if(view_id == profile_button_bottombar.getId()) + { + to_navigate = new Intent(arScreen, ProfilePage.class); + startActivity(to_navigate); + } + else if(view_id == community_button_bottombar.getId()) + { + to_navigate = new Intent(arScreen, CommunityPage.class); + startActivity(to_navigate); + } + else if(view_id == quest_button_bottombar.getId()) + { + to_navigate = new Intent(arScreen, MindfullnessSelection.class); + startActivity(to_navigate); + + } + else if(view_id == home_button_bottombar.getId()) + { + to_navigate = new Intent(arScreen, HomeScreen.class); + startActivity(to_navigate); + } + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/aorora/HomeScreen.java b/app/src/main/java/com/example/aorora/HomeScreen.java index 58a0f96..503b757 100644 --- a/app/src/main/java/com/example/aorora/HomeScreen.java +++ b/app/src/main/java/com/example/aorora/HomeScreen.java @@ -1,38 +1,37 @@ package com.example.aorora; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.media.Image; import android.media.MediaPlayer; -import android.os.Build; -import android.os.CountDownTimer; -import android.os.VibrationEffect; import android.os.Vibrator; -import android.support.annotation.DrawableRes; import android.support.constraint.ConstraintLayout; -import android.support.constraint.ConstraintSet; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -import java.util.Random; +import com.example.aorora.network.NetworkCalls; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; public class HomeScreen extends AppCompatActivity implements GestureDetector.OnGestureListener, View.OnClickListener { + //User account info + String userName; + String userNamePower; + Integer userPollen; + + //UI and Activity Elements Context homeScreen; GestureDetector gestureDetector; ImageButton home_button_bottombar; @@ -45,9 +44,14 @@ public class HomeScreen extends AppCompatActivity implements GestureDetector.OnG TextView notification_tv; TextView label_ar_game_button; TextView label_quest_button; + TextView userPollenTv; + TextView quickAccessUName; + TextView quickAccessPollen; + String userPollenDisplay; Boolean isButtonsPoppedUp; Animation notification_anim; Vibrator myVibrate; + LinearLayout ar_layout; public LayoutInflater layoutInflater; public View speck1; ConstraintLayout speck_holder_cl; @@ -63,7 +67,14 @@ public class HomeScreen extends AppCompatActivity implements GestureDetector.OnG @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); + //Testing a refresh of userData here instead of in M1-M3 + //NetworkCalls.getUserInfo(MainActivity.user_info.getUser_id(), HomeScreen.this); setContentView(R.layout.activity_home_screen); + //Fetch userdata from the local user_info instance in MainActivity. + userPollen = MainActivity.user_info.getUser_pollen(); + Log.d("OnCreate Pollen", "onCreate: Displayed userPollen: " + userPollen); + userName = MainActivity.user_info.getUser_name(); + userNamePower = MainActivity.user_info.getUser_name_of_strength(); homeScreen = this; isButtonsPoppedUp = false; @@ -72,6 +83,7 @@ protected void onCreate(Bundle savedInstanceState){ profile_button_bottombar = (ImageButton) findViewById(R.id.profile_button_bottom_bar); community_button_bottombar = (ImageButton) findViewById(R.id.community_button_bottom_bar); quest_button_bottombar = (ImageButton) findViewById(R.id.quest_button_bottom_bar); + ar_layout = (LinearLayout) findViewById(R.id.ar_game_button_ll); ar_game_button = (ImageButton) findViewById(R.id.ar_game_button); quest_button = (ImageButton) findViewById(R.id.quest_button); pop_up_twobuttons_button = findViewById(R.id.pop_up_buttons_button); @@ -79,21 +91,36 @@ protected void onCreate(Bundle savedInstanceState){ label_ar_game_button = (TextView) findViewById(R.id.label_ar_button); label_quest_button = (TextView) findViewById(R.id.label_quest_button); popup_quick_access = (LinearLayout) findViewById(R.id.popup_quick_access); + + //User pollen value that will be displayed on the homepage, accessed from included layout. + userPollenTv = (TextView) popup_quick_access.findViewById(R.id.pollen_score_layout_tv); + userPollenDisplay = Integer.toString(userPollen); + userPollenTv.setText(userPollenDisplay); + //Update the popup menu for pollen to reflect user account values. + quick_menu = (LinearLayout) findViewById(R.id.include_quick_access_menu); + quickAccessUName = (TextView) quick_menu.findViewById(R.id.quick_access_user_id_tv); + quickAccessPollen = (TextView) quick_menu.findViewById(R.id.quickaccesspollen); + quickAccessUName.setText(userName); + quickAccessPollen.setText(userPollenDisplay); + + speck_holder_cl = (ConstraintLayout) findViewById(R.id.speck_holder_cl); - quick_menu = (LinearLayout) findViewById(R.id.include_popup_quick_access_menu); + + is_menu_inflated = false; //buttonClick = MediaPlayer.create(getBaseContext(), R.raw.button1); + Log.d("TESTNAV", "Calling onCreate!"); + quick_menu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(HomeScreen.this, "Pollen Shop is underdevelopment", Toast.LENGTH_SHORT).show(); - /* ---------------- Not working, underdevelopment -------------- Intent to_navigate = new Intent(homeScreen, PollenStoreDailyQuestPage.class); to_navigate.putExtra("NavigatedFrom", 1); - startActivity(to_navigate);*/ + startActivity(to_navigate); } }); popup_quick_access.setOnClickListener(new View.OnClickListener() { @@ -148,6 +175,7 @@ public void onClick(View v) { } }); + //This does not invoke the network calls, it simply accesses the user_info object values. switch (MainActivity.user_info.getUser_current_butterfly()){ case 0: profile_butterfly.setImageResource(R.drawable.orange_butterfly_image); @@ -183,9 +211,10 @@ public void onClick(View v) { community_button_bottombar.setOnClickListener(this); quest_button_bottombar.setOnClickListener(this); quest_button.setOnClickListener(this); + ar_game_button.setOnClickListener(this); notification_tv.setOnClickListener(this); speck1.setOnClickListener(this); - notification_tv.setVisibility(View.INVISIBLE); + // notification_tv.setVisibility(View.VISIBLE); ring = MediaPlayer.create(homeScreen,R.raw.notify_2); spec_alert = MediaPlayer.create(homeScreen,R.raw.notify_wav); @@ -233,15 +262,13 @@ public void onAnimationRepeat(Animation animation) { } }); + //Central white button to show and hide AR and Quest buttons. pop_up_twobuttons_button.setOnClickListener(new ImageButton.OnClickListener() { public void onClick(View v) { - - if(!isButtonsPoppedUp) { pop_up_twobuttons_button.setImageDrawable(getResources().getDrawable(R.drawable.menu_button_unfilled)); + ar_layout.setVisibility(View.VISIBLE); quest_button.setVisibility(View.VISIBLE); - ar_game_button.setVisibility(View.VISIBLE); - label_ar_game_button.setVisibility(View.VISIBLE); label_quest_button.setVisibility(View.VISIBLE); isButtonsPoppedUp = true; ar_game_button.setClickable(TRUE); @@ -249,9 +276,8 @@ public void onClick(View v) { } else{ pop_up_twobuttons_button.setImageDrawable(getResources().getDrawable(R.drawable.menu_button_filled)); + ar_layout.setVisibility(View.INVISIBLE); quest_button.setVisibility(View.INVISIBLE); - ar_game_button.setVisibility(View.INVISIBLE); - label_ar_game_button.setVisibility(View.INVISIBLE); label_quest_button.setVisibility(View.INVISIBLE); isButtonsPoppedUp = false; ar_game_button.setClickable(FALSE); @@ -283,18 +309,23 @@ public void onFinish() { } }.start(); */ - } + + + //Built in overriden onFLing method for swiping control between Activities + //Implements from the GestureDetector interface. @Override public boolean onFling (MotionEvent motionEvent1, MotionEvent motionEvent2, float X, float Y) { page_left = true; + //This checks if we swiped left on the homepage if (motionEvent1.getX() - motionEvent2.getX() > 150) { Intent profilePage = new Intent(homeScreen, MindfullnessSelection.class); startActivity(profilePage); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); return true; } + //This checks if we swiped right on the homepage if (motionEvent2.getX() - motionEvent1.getX() > 150) { Intent mindfullness = new Intent(homeScreen, ProfilePage.class); startActivity(mindfullness); @@ -304,39 +335,6 @@ public boolean onFling (MotionEvent motionEvent1, MotionEvent motionEvent2, floa return true; } } - - @Override - public boolean onTouchEvent(MotionEvent motionEvent) { - return gestureDetector.onTouchEvent(motionEvent); - } - - // We don't need to implement those unless otherwise told. They just need to be there - // because we are implementing the GestureDetector class - @Override - public boolean onDown(MotionEvent e) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return false; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - - } - @Override public void onClick(View v) { int view_id = v.getId(); @@ -362,7 +360,6 @@ else if(view_id == community_button_bottombar.getId()) } else if(view_id == quest_button_bottombar.getId() || view_id == quest_button.getId()) { - to_navigate = new Intent(homeScreen, MindfullnessSelection.class); startActivity(to_navigate); @@ -379,17 +376,55 @@ else if (view_id == speck1.getId()) } else if(view_id == notification_tv.getId()) { - to_navigate = new Intent(homeScreen, MindfullnessBreathing.class); startActivity(to_navigate); } else if(view_id == ar_game_button.getId()) { - to_navigate = new Intent(homeScreen, DailyQuestPage.class); + to_navigate = new Intent(homeScreen, ARScreen.class); startActivity(to_navigate); + Log.d("ARBUTTON", "Launching arpack, which is where?????"); //Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.NAUVRLab.ARProduct"); //startActivity(launchIntent); } } + + @Override + public boolean onTouchEvent(MotionEvent motionEvent) { + return gestureDetector.onTouchEvent(motionEvent); + } + + // We don't need to implement those unless otherwise told. They just need to be there + // because we are implementing the GestureDetector class + @Override + public boolean onDown(MotionEvent e) { + return false; + } + + @Override + public void onShowPress(MotionEvent e) { + + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + return false; + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + return false; + } + + @Override + public void onLongPress(MotionEvent e) { + + } + + @Override + protected void onResume() { + super.onResume(); + //TODO: Refresh pollen values from backend. Userinfo call should do it. + } } diff --git a/app/src/main/java/com/example/aorora/MainActivity.java b/app/src/main/java/com/example/aorora/MainActivity.java index 773f80c..28bba0b 100644 --- a/app/src/main/java/com/example/aorora/MainActivity.java +++ b/app/src/main/java/com/example/aorora/MainActivity.java @@ -37,8 +37,10 @@ public class MainActivity extends AppCompatActivity { Context context; EditText username_et; EditText password_et; + //Determined if a user has logged in before. To be used in autopopulating login form. boolean is_first_time_username_et; boolean is_first_time_password_et; + //This service is our backend connection that will respond to http requests we made in GetDataService.java GetDataService service; @Override @@ -50,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) { password_et = findViewById(R.id.login_password_et); is_first_time_password_et = true; is_first_time_username_et = true; + //Init our backend service service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class); context = this; @@ -99,8 +102,12 @@ private void login(String username, String password) public void onResponse(Call call, Response response) { if(response.isSuccess()) { + //This UserAuth object is initialized using the very first login object, UserAuth, + //that is generated from this login form. It gives us a userId, which we need. UserAuth user = (UserAuth) response.body(); - NetworkCalls.getDailyTaskOfUser(user.getUser_id(),MainActivity.this); + //NetworkCalls.getDailyTaskOfUser(user.getUser_id(),MainActivity.this); + //This will build and assign a UserInfo instance to the user_info variable above + //for package-wide use. NetworkCalls.getUserInfo(user.getUser_id(), MainActivity.this); surveyPage = new Intent(context, SurveyPage.class); startActivity(surveyPage); diff --git a/app/src/main/java/com/example/aorora/MindfullnessBreathing.java b/app/src/main/java/com/example/aorora/MindfullnessBreathing.java index b3495ab..e8e578b 100644 --- a/app/src/main/java/com/example/aorora/MindfullnessBreathing.java +++ b/app/src/main/java/com/example/aorora/MindfullnessBreathing.java @@ -141,8 +141,8 @@ public void selectTimeMiddleItem() if(isInMiddle) { - //TODO Fix this, it is currently hardcoded - timerCount = 10; //viewHolder.getAdapterPosition(); + //TODO Fix this, it is currently hardcoded, setting to 1 for the 1 breath option. + timerCount = 1; //viewHolder.getAdapterPosition(); text_view.setTextColor(getResources().getColor(R.color.colorWhite)); } } diff --git a/app/src/main/java/com/example/aorora/MindfullnessBreathingGame.java b/app/src/main/java/com/example/aorora/MindfullnessBreathingGame.java index 63655c6..6a870fb 100644 --- a/app/src/main/java/com/example/aorora/MindfullnessBreathingGame.java +++ b/app/src/main/java/com/example/aorora/MindfullnessBreathingGame.java @@ -62,6 +62,7 @@ public class MindfullnessBreathingGame extends AppCompatActivity { ImageButton pollen_button; int points_to_collect; int initial_score; + int tempBreathCount; View pollen_layout; View emitter; int possible_points; @@ -85,6 +86,7 @@ protected void onCreate(Bundle savedInstanceState) { possible_points = 100; is_button_still_clicked = false; performed_click = false; + tempBreathCount = 2; LottieAnimationView animationView = findViewById(R.id.animation_view); animationView.setSpeed(1f); @@ -113,16 +115,16 @@ protected void onCreate(Bundle savedInstanceState) { { //Changing default value from 1 to 2 int text = getIntent().getIntExtra("TimerValue", 2); - /* - Disabling 5 breath option for testing purposes + + //Disabling 5 breath option for testing purposes, possible_points is the amount of breaths remaining. if(text == 1) { initial_game_count = text; - possible_points = 5; - text = 5; + possible_points = tempBreathCount; + text = tempBreathCount; } - */ - if( text == 2) + + else if( text == 2) { initial_game_count = text; possible_points = 10; @@ -144,11 +146,13 @@ protected void onCreate(Bundle savedInstanceState) { shrink = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.butterfly_closing); final Handler handler = new Handler(); + //This runs in a Runnable thread final Runnable mLongPressed = new Runnable() { public void run() { Log.d("VERBOSE", "run: INSIDE RUN "); butterfly_image.startAnimation(shrink); isRun = true; + //Causes the phone to vibrate using the vibrate function of the myVibrate object. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { myVibrate.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else { @@ -232,7 +236,7 @@ public void onAnimationEnd(Animation animation) { handler.postDelayed(mLongPressed, 3000); myTimer.start(); } - + //The game is over when count reaches 0, navigate to the reciept page. if(count == 0) { //DialogFragment newFragment = new BreathDialog(); @@ -241,15 +245,19 @@ public void onAnimationEnd(Animation animation) { { breathing_music.stop(); } - int user_points = MainActivity.user_info.getUser_pollen(); - Log.e("USER POINTS ", user_points + " "); - user_points += possible_points; - NetworkCalls.updateUserCurrentPoints(MainActivity.user_info.getUser_id(), user_points, MindfullnessBreathingGame.this); - NetworkCalls.getUserInfo(MainActivity.user_info.getUser_id(), MindfullnessBreathingGame.this); + //TODO: Why are the network calls here instead of recieptpage? KISS and add a consistent number of points when we reach that page. + int new_user_points = MainActivity.user_info.getUser_pollen() + 10; + Log.e("NEW USER POINTS ", new_user_points + " "); + NetworkCalls.updateUserCurrentPoints(MainActivity.user_info.getUser_id(), new_user_points, MindfullnessBreathingGame.this); + //Now update our local pollen value + MainActivity.user_info.setUser_pollen(new_user_points); + //This old GET request was causing race conditions with the PATCH above, and wasnt necessary. + //NetworkCalls.getUserInfo(MainActivity.user_info.getUser_id(), MindfullnessBreathingGame.this); + //Set the pollen value locally Intent to_navigate = new Intent(mindfullness_breathing_game, ReceiptPage.class); to_navigate.putExtra("NavigatedFrom", 1); - NetworkCalls.updateDailyTaskM1(user_info.getUser_id(), 1, mindfullness_breathing_game); - NetworkCalls.createQuestReport(1, user_info.getUser_id(),mindfullness_breathing_game); + //NetworkCalls.updateDailyTaskM1(user_info.getUser_id(), 1, mindfullness_breathing_game); + //NetworkCalls.createQuestReport(1, user_info.getUser_id(),mindfullness_breathing_game); to_navigate.putExtra("GAME", initial_game_count); startActivity(to_navigate); @@ -269,7 +277,7 @@ public void onAnimationRepeat(Animation animation) { } }); - + //User clicks the x button to end the game early exit_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/com/example/aorora/MindfullnessMeditation.java b/app/src/main/java/com/example/aorora/MindfullnessMeditation.java index f9983b9..1418456 100644 --- a/app/src/main/java/com/example/aorora/MindfullnessMeditation.java +++ b/app/src/main/java/com/example/aorora/MindfullnessMeditation.java @@ -227,6 +227,7 @@ else if(view_id == play_button.getId()) duration_string = String.valueOf(text_view.getText()); if(duration_string.equals("3 minutes")) { + //Desired duration to be sent to the game in ms. duration_int = 180000; } else if(duration_string.equals("5 minutes")) diff --git a/app/src/main/java/com/example/aorora/MindfullnessWalking.java b/app/src/main/java/com/example/aorora/MindfullnessWalking.java index bb05b87..3563bca 100644 --- a/app/src/main/java/com/example/aorora/MindfullnessWalking.java +++ b/app/src/main/java/com/example/aorora/MindfullnessWalking.java @@ -21,6 +21,7 @@ import com.example.aorora.adapter.HorizontalMountainAdapter; import com.example.aorora.interfaces.OnItemClickListener; +//Represents the MindfullnessWalking Selection Page, continues into MindfullnessWalkingGame if selected. public class MindfullnessWalking extends AppCompatActivity implements View.OnClickListener { Animation infinite_blink; diff --git a/app/src/main/java/com/example/aorora/MindfullnessWalkingGame.java b/app/src/main/java/com/example/aorora/MindfullnessWalkingGame.java index 15256e3..e2c3b9e 100644 --- a/app/src/main/java/com/example/aorora/MindfullnessWalkingGame.java +++ b/app/src/main/java/com/example/aorora/MindfullnessWalkingGame.java @@ -8,6 +8,7 @@ import android.content.IntentFilter; import android.media.MediaPlayer; import android.os.CountDownTimer; +import android.os.Handler; import android.support.constraint.ConstraintLayout; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AppCompatActivity; @@ -35,7 +36,11 @@ public class MindfullnessWalkingGame extends AppCompatActivity { - + //Adding a finish button and handler for integration. Handler shows the button after x seconds. + Button finishButton; + //Testing variable to make the finish button pop up after this amount of milliseconds. + Integer timeUntilFinished; + Handler handler; BroadcastReceiver broadcastReceiver; ImageButton exit; ParticleSystem myParticle; @@ -59,7 +64,9 @@ public class MindfullnessWalkingGame extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mindfullness_walking_game); - + //Display the finishButton after x seconds + finishButton = (Button) findViewById(R.id.finish_walk_btn); + timeUntilFinished = 6000; exit = (ImageButton) findViewById(R.id.mindfullness_walking_exit_button); emitter = (View) findViewById(R.id.emiter_top); walking_game_layout = findViewById(R.id.walking_game_background); @@ -78,6 +85,15 @@ protected void onCreate(Bundle savedInstanceState) { walking_music.start(); } + //Display a finish button for testing. + handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + finishButton.setVisibility(View.VISIBLE); + } + },timeUntilFinished); + Toast.makeText(MindfullnessWalkingGame.this, "Listen to the prompt as you walk slowly in a safe place\n" + "\n.", Toast.LENGTH_SHORT).show(); @@ -134,6 +150,26 @@ public void onReceive(Context context, Intent intent) { }; startTracking(); + finishButton.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + if(walking_music.isPlaying()){ + walking_music.stop(); + } + Intent to_navigate = new Intent(mindfulness_walking, ReceiptPage.class); + to_navigate.putExtra("NavigatedFrom", 3); + to_navigate.putExtra("Game Theme", game_theme); + stopTracking(); + startActivity(to_navigate); + int user_points = MainActivity.user_info.getUser_pollen(); + user_points += 25; + NetworkCalls.updateUserCurrentPoints(MainActivity.user_info.getUser_id(), user_points, MindfullnessWalkingGame.this); + MainActivity.user_info.setUser_pollen(user_points); + //NetworkCalls.updateDailyTaskM3(user_info.getUser_id(), 1, walking); + //NetworkCalls.createQuestReport(3, user_info.getUser_id(),mindfulness_walking); + } + }); + /*walking_loading.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/com/example/aorora/MindfulnessMeditationGame_R.java b/app/src/main/java/com/example/aorora/MindfulnessMeditationGame_R.java index dbf895c..583082c 100644 --- a/app/src/main/java/com/example/aorora/MindfulnessMeditationGame_R.java +++ b/app/src/main/java/com/example/aorora/MindfulnessMeditationGame_R.java @@ -29,7 +29,7 @@ import static com.example.aorora.MainActivity.user_info; public class MindfulnessMeditationGame_R extends AppCompatActivity implements View.OnClickListener { - + //Class Member variable declaration int gameDuration; ImageView outer_most_ring; @@ -75,8 +75,6 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_mindfulness_meditation_game__r); tutorialPopUp(); - - is_first_cycle = false; is_second_cycle = false; is_third_cycle = false; @@ -384,12 +382,18 @@ public void onFinish() { Intent to_navigate = new Intent(MindfulnessMeditationGame_R.this, ReceiptPage.class); to_navigate.putExtra("NavigatedFrom", 2); to_navigate.putExtra("Game Theme", game_theme); - int user_points = user_info.getUser_pollen(); - NetworkCalls.updateUserCurrentPoints(user_info.getUser_id(), user_points + 5 , MindfulnessMeditationGame_R.this); - NetworkCalls.updateDailyTaskM2(user_info.getUser_id(), 1, MindfulnessMeditationGame_R.this); - NetworkCalls.createQuestReport(2, user_info.getUser_id(),MindfulnessMeditationGame_R.this); - startActivity(to_navigate); + int new_user_pollen = user_info.getUser_pollen() + 10; + //First update our local userInfo instance + MainActivity.user_info.setUser_pollen(new_user_pollen); + Log.d("EndGame pollen", "onFinish current userpollen: " + new_user_pollen); + //Next communicate it to the backend via the appropriate NetworkCall function. + NetworkCalls.updateUserCurrentPoints(user_info.getUser_id(), new_user_pollen, MindfulnessMeditationGame_R.this); + //Comment out these incorrect/unimplemented calls as the server simply errors. + // NetworkCalls.updateDailyTaskM2(user_info.getUser_id(), 1, MindfulnessMeditationGame_R.this); + //NetworkCalls.createQuestReport(2, user_info.getUser_id(),MindfulnessMeditationGame_R.this); Log.e("ON FINISH", "" + " FINISH"); + startActivity(to_navigate); + } /* public long onPause() diff --git a/app/src/main/java/com/example/aorora/PollenStoreDailyQuestPage.java b/app/src/main/java/com/example/aorora/PollenStoreDailyQuestPage.java index b8b6488..1906246 100644 --- a/app/src/main/java/com/example/aorora/PollenStoreDailyQuestPage.java +++ b/app/src/main/java/com/example/aorora/PollenStoreDailyQuestPage.java @@ -10,6 +10,8 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; import android.widget.Toast; import com.example.aorora.model.RetroPhoto; @@ -28,9 +30,11 @@ public class PollenStoreDailyQuestPage extends AppCompatActivity implements View ImageButton quest_button_bottombar; Context pollenStoreDailyQuestPage; RecyclerView pollen_recycler; + RelativeLayout currentPollenLayout; private com.example.aorora.adapter.QuestAdapter questAdapter; private com.example.aorora.adapter.PollenShopAdapter shopAdapter; - + int userPollen; + TextView userPollenTv; Button daily_quest_button; Button pollen_shop_button; ImageView daily_quest_underline; @@ -43,6 +47,9 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pollen_store_daily_quest_page); + //Fetch user account details + userPollen = MainActivity.user_info.getUser_pollen(); + pollenStoreDailyQuestPage = this; pollen_recycler = (RecyclerView) findViewById(R.id.pollenRecyclerView); @@ -60,6 +67,9 @@ protected void onCreate(Bundle savedInstanceState) { pollen_shop_button = (Button) findViewById(R.id.pollen_shop_tabs_button); daily_quest_underline = (ImageView) findViewById(R.id.underline_daily_quests); pollen_shop_underline = (ImageView) findViewById(R.id.underline_pollen_shop); + currentPollenLayout = (RelativeLayout) findViewById(R.id.pollen_count_layout); + userPollenTv = (TextView) currentPollenLayout.findViewById(R.id.current_pollentv); + userPollenTv.setText(Integer.toString(userPollen) + " Pollen" ); currentIntent = this.getIntent(); diff --git a/app/src/main/java/com/example/aorora/ProfilePage.java b/app/src/main/java/com/example/aorora/ProfilePage.java index 4d0798f..5b09dd9 100644 --- a/app/src/main/java/com/example/aorora/ProfilePage.java +++ b/app/src/main/java/com/example/aorora/ProfilePage.java @@ -30,6 +30,10 @@ import retrofit2.Response; public class ProfilePage extends AppCompatActivity implements View.OnClickListener, GestureDetector.OnGestureListener { + //User account info + String userName; + String userNamePower; + int userPollen; GestureDetector gestureDetector; ImageButton home_button_bottombar; @@ -51,6 +55,11 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile_page); + //Init user account info + userName = MainActivity.user_info.getUser_name(); + userNamePower = MainActivity.user_info.getUser_name_of_strength(); + userPollen = MainActivity.user_info.getUser_pollen(); + home_button_bottombar = (ImageButton) findViewById(R.id.home_button_bottom_bar); profile_button_bottombar = (ImageButton) findViewById(R.id.profile_button_bottom_bar); profile_button_bottombar.setImageResource(R.drawable.profile_filled_button); @@ -66,7 +75,9 @@ protected void onCreate(Bundle savedInstanceState) { butterfly_description_tv = (TextView) findViewById(R.id.profile_page_bf_desc_tv); profilePage = this; - user_score_tv.setText("" + MainActivity.user_info.getUser_pollen()); + //User tv at the top of the page. Pollen is accessed from the backend User Table. + user_name_tv.setText(userName); + user_score_tv.setText(Integer.toString(userPollen)); home_button_bottombar.setOnClickListener(this); profile_button_bottombar.setOnClickListener(this); community_button_bottombar.setOnClickListener(this); @@ -132,6 +143,8 @@ else if(view_id == home_button_bottombar.getId()) } else if(view_id == settings_button.getId()) { + /* This toast was added to show that settings is under development and the settings + * button is unresponsive. */ Toast.makeText(ProfilePage.this , "Settings is under development.", Toast.LENGTH_SHORT).show(); //to_navigate = new Intent(profilePage, MindfulnessMeditationGame_R.class); //startActivity(to_navigate); @@ -140,21 +153,19 @@ else if(view_id == settings_button.getId()) //to_navigate = new Intent(profilePage, EndOfMindfulnessGamePage.class); //startActivity(to_navigate); - /* This toast was added to show that settings is under development and the settings - * button is unresponsive. */ - Toast.makeText(ProfilePage.this, "Settings is under development", Toast.LENGTH_SHORT).show(); + } else if(view_id == pollen_button.getId()) { - // to_navigate = new Intent(profilePage, PollenStoreDailyQuestPage.class); - // to_navigate.putExtra("NavigatedFrom", 2); - //startActivity(to_navigate); + to_navigate = new Intent(profilePage, PollenStoreDailyQuestPage.class); + to_navigate.putExtra("NavigatedFrom", 2); + startActivity(to_navigate); /* This toast was added to show that navigation has been blocked to the pollen page. * Navigation to this page has been blocked because of errors with the display in the * pollen page. */ - Toast.makeText(ProfilePage.this, "Pollen page is under development", Toast.LENGTH_SHORT).show(); - Toast.makeText(ProfilePage.this, "Settings is under maintenance", Toast.LENGTH_SHORT).show(); + //Toast.makeText(ProfilePage.this, "Pollen page is under development", Toast.LENGTH_SHORT).show(); + //Toast.makeText(ProfilePage.this, "Settings is under maintenance", Toast.LENGTH_SHORT).show(); } else if(view_id == pollen_button.getId()) { diff --git a/app/src/main/java/com/example/aorora/SurveyPage.java b/app/src/main/java/com/example/aorora/SurveyPage.java index f1d38e3..c3ef172 100644 --- a/app/src/main/java/com/example/aorora/SurveyPage.java +++ b/app/src/main/java/com/example/aorora/SurveyPage.java @@ -79,7 +79,8 @@ protected void onCreate (Bundle savedInstanceState) { navigatedFrom = getIntent(); if(navigatedFrom.hasExtra("NavigatedFrom")) { - from = navigatedFrom.getIntExtra("NavigatedFrom", 0); + from = navigatedFrom.getIntExtra("NAVIGATEDFROM", 0); + Log.d("IntExtraSurvey", "value: " + from); if(from == -1 || from == -2 || from == -3) { exitButton.setVisibility(View.VISIBLE); @@ -302,6 +303,7 @@ else if(mindfullness == 3) startActivity(to_navigate); } } + //This is the case that is called when no extras are passed, which is when we first complete the survey. else{ to_navigate = new Intent(surveyPage, HomeScreen.class); startActivity(to_navigate); diff --git a/app/src/main/java/com/example/aorora/model/DailyTask.java b/app/src/main/java/com/example/aorora/model/DailyTask.java index 3536f8f..851052b 100644 --- a/app/src/main/java/com/example/aorora/model/DailyTask.java +++ b/app/src/main/java/com/example/aorora/model/DailyTask.java @@ -1,7 +1,8 @@ package com.example.aorora.model; import com.google.gson.annotations.SerializedName; - +//This class serves to embody an entire daily task and uses SerializedName to access the Django +//backend fields via JSON format? public class DailyTask { /* "daily_task_id": 3, diff --git a/app/src/main/java/com/example/aorora/model/QuesrtReportCreateReturn.java b/app/src/main/java/com/example/aorora/model/QuestReportCreateReturn.java similarity index 82% rename from app/src/main/java/com/example/aorora/model/QuesrtReportCreateReturn.java rename to app/src/main/java/com/example/aorora/model/QuestReportCreateReturn.java index d997e96..6edf6db 100644 --- a/app/src/main/java/com/example/aorora/model/QuesrtReportCreateReturn.java +++ b/app/src/main/java/com/example/aorora/model/QuestReportCreateReturn.java @@ -3,12 +3,12 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class QuesrtReportCreateReturn { +public class QuestReportCreateReturn { @SerializedName("quest_report_id") @Expose private Integer quest_report_id; - public QuesrtReportCreateReturn(Integer quest_report_id) { + public QuestReportCreateReturn(Integer quest_report_id) { this.quest_report_id = quest_report_id; } diff --git a/app/src/main/java/com/example/aorora/network/GetDataService.java b/app/src/main/java/com/example/aorora/network/GetDataService.java index ef333e6..d65f5f1 100644 --- a/app/src/main/java/com/example/aorora/network/GetDataService.java +++ b/app/src/main/java/com/example/aorora/network/GetDataService.java @@ -2,12 +2,11 @@ import com.example.aorora.model.Butterfly; import com.example.aorora.model.ButterflyLike; -import com.example.aorora.model.ButterflyLikeCreateReturn; import com.example.aorora.model.DailyTask; import com.example.aorora.model.DailyTaskReturn; import com.example.aorora.model.MoodReportIdReturn; import com.example.aorora.model.NotificationCreateReturn; -import com.example.aorora.model.QuesrtReportCreateReturn; +import com.example.aorora.model.QuestReportCreateReturn; import com.example.aorora.model.Quest; import com.example.aorora.model.QuestReport; import com.example.aorora.model.RetroPhoto; @@ -16,21 +15,26 @@ import com.example.aorora.model.UserInfo; import com.example.aorora.model.UserInteraction; import com.example.aorora.model.Notification; -import com.example.aorora.model.UserInteractionCreateReturn; import java.util.List; import retrofit2.Call; import retrofit2.http.Body; -import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; +import retrofit2.http.PATCH; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; -import retrofit2.http.Query; + +/* +This interface defines all of the HTTP requests necessary to access, update, and view contents of +the Django2 backend database. These are to be called as functions within your code elsewhere, these +interfaces are populated with code via Retrofit automatically when used with Gson and Retrofit +functions. See the ARORA-Server repo readme for more information. + */ public interface GetDataService { @GET("/photos") @@ -110,12 +114,13 @@ Call userInteract(@Field("initiator_user_id") Integer sender, @GET("/userinfo/{user_id}") Call getUserInfo(@Path("user_id") Integer user_id); + //Possible refactor into PATCH?? @PUT("/userinfo/{user_id}") @FormUrlEncoded Call updateUserCurrentButterfly(@Path("user_id") Integer user_id, @Field("user_current_butterfly") Integer user_current_butterfly); - - @PUT("/userinfo/{user_id}") + //This needed to be a PATCH, not a PUT! + @PATCH("/userinfo/{user_id}") @FormUrlEncoded Call updateUserPollen(@Path("user_id") Integer user_id, @Field("user_pollen") Integer user_pollen); @@ -144,6 +149,6 @@ Call updateDailyTaskM3(@Path("user_id") Integer user_id, @Field("daily_task_m3_achieved") Integer daily_task_m3_achieved); @POST("/questreport") @FormUrlEncoded - Call createQuestReport(@Field("quest_id") Integer quest_id, - @Field("user_id") Integer user_id); + Call createQuestReport(@Field("quest_id") Integer quest_id, + @Field("user_id") Integer user_id); } \ No newline at end of file diff --git a/app/src/main/java/com/example/aorora/network/NetworkCalls.java b/app/src/main/java/com/example/aorora/network/NetworkCalls.java index 4566a7b..bf042bc 100644 --- a/app/src/main/java/com/example/aorora/network/NetworkCalls.java +++ b/app/src/main/java/com/example/aorora/network/NetworkCalls.java @@ -1,34 +1,22 @@ package com.example.aorora.network; import android.content.Context; -import android.content.Intent; import android.util.Log; -import android.widget.ListAdapter; import android.widget.Toast; -import com.example.aorora.CommunityPage; import com.example.aorora.MainActivity; -import com.example.aorora.ProfilePage; -import com.example.aorora.SurveyPage; -import com.example.aorora.model.Butterfly; -import com.example.aorora.model.ButterflyLike; -import com.example.aorora.model.ButterflyLikeCreateReturn; import com.example.aorora.model.DailyTask; import com.example.aorora.model.DailyTaskReturn; import com.example.aorora.model.MoodReportIdReturn; import com.example.aorora.model.NotificationCreateReturn; -import com.example.aorora.model.QuesrtReportCreateReturn; +import com.example.aorora.model.QuestReportCreateReturn; import com.example.aorora.model.UserInfo; -import com.example.aorora.model.UserInteractionCreateReturn; - -import java.util.List; +import com.google.gson.GsonBuilder; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import static com.example.aorora.MainActivity.user_info; - public class NetworkCalls { public static GetDataService service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class); @@ -65,14 +53,13 @@ public static void updateUserCurrentPoints(int user_id, int user_pollen, final C @Override public void onResponse(Call call, Response response) { if(response.isSuccess()) - //response.body().getUsername() { - //Toast.makeText(context, " POLLEN UPDATED Updated Successfuly", Toast.LENGTH_SHORT).show(); + Toast.makeText(context, " POLLEN UPDATED Updated Successfuly", Toast.LENGTH_SHORT).show(); } else { - //Toast.makeText(context, "Something went wrong", Toast.LENGTH_SHORT).show(); + Toast.makeText(context, "Something went wrong", Toast.LENGTH_SHORT).show(); } } @@ -85,6 +72,7 @@ public void onFailure(Call call, Throwable t) { public static void getUserInfo(int user_id, final Context context) { + //Find these services in the interface GetDataService. Create a UserInfo object Call call = service.getUserInfo(user_id); call.enqueue(new Callback() { @Override @@ -92,7 +80,10 @@ public void onResponse(Call call, Response response) { if(response.isSuccess()) //response.body().getUsername() { - user_info = response.body(); + //PACKAGE GLOBAL USED WITHOUT DOCUMENTATION. BAD! Specify that user_info is from + //MainActivity! + MainActivity.user_info = response.body(); + Log.d("RESPONSESTR", new GsonBuilder().setPrettyPrinting().create().toJson(response.body())); //Toast.makeText(context, "User Info Gathered", Toast.LENGTH_SHORT).show(); } else @@ -201,14 +192,14 @@ public void onFailure(Call call, Throwable t) { public static void createQuestReport(int quest_id, int user_id, final Context context) { - Call call = service.createQuestReport(quest_id,user_id); - call.enqueue(new Callback() { + Call call = service.createQuestReport(quest_id,user_id); + call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { //Toast.makeText(context, "Quest Report Created ID: " + response.body(), Toast.LENGTH_SHORT).show(); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { Toast.makeText(context, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); } }); diff --git a/app/src/main/res/drawable-v24/pleasant.png b/app/src/main/res/drawable-v24/pleasant.png new file mode 100644 index 0000000..707a1c9 Binary files /dev/null and b/app/src/main/res/drawable-v24/pleasant.png differ diff --git a/app/src/main/res/drawable-v24/yellow_butterflu_button.png b/app/src/main/res/drawable-v24/yellow_butterfly_button.png similarity index 100% rename from app/src/main/res/drawable-v24/yellow_butterflu_button.png rename to app/src/main/res/drawable-v24/yellow_butterfly_button.png diff --git a/app/src/main/res/layout/activity_ar_screen.xml b/app/src/main/res/layout/activity_ar_screen.xml new file mode 100644 index 0000000..e132b58 --- /dev/null +++ b/app/src/main/res/layout/activity_ar_screen.xml @@ -0,0 +1,48 @@ + + + + +