diff --git a/app/build.gradle b/app/build.gradle
index f76f3f4..ac34997 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -27,6 +27,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.affectiva.android:affdexsdk:3.1'
- testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.4'
+ compile 'com.android.support:design:23.4.0'
+ testCompile 'junit:junit:4.12'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4ab3f1d..0934b86 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -28,17 +28,27 @@
+ android:label="@string/app_name"
+ android:theme="@style/FullscreenTheme">
-
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java
index f3a40df..cdf7940 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java
@@ -73,7 +73,9 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getSupportActionBar().hide();
+ if(getSupportActionBar() != null) {
+ getSupportActionBar().hide();
+ }
setContentView(R.layout.activity_gaming);
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/HighscoreActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/HighscoreActivity.java
new file mode 100644
index 0000000..461779e
--- /dev/null
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/HighscoreActivity.java
@@ -0,0 +1,194 @@
+package com.rubenvandeven.emotionhero;
+
+import android.content.Intent;
+import android.graphics.Typeface;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.Snackbar;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutCompat;
+import android.support.v7.widget.Toolbar;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class HighscoreActivity extends AppCompatActivity {
+
+ /**
+ * The {@link android.support.v4.view.PagerAdapter} that will provide
+ * fragments for each of the sections. We use a
+ * {@link FragmentPagerAdapter} derivative, which will keep every
+ * loaded fragment in memory. If this becomes too memory intensive, it
+ * may be best to switch to a
+ * {@link android.support.v4.app.FragmentStatePagerAdapter}.
+ */
+ private SectionsPagerAdapter mSectionsPagerAdapter;
+
+ /**
+ * The {@link ViewPager} that will host the section contents.
+ */
+ private ViewPager mViewPager;
+
+ Player player;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setContentView(R.layout.activity_highscore);
+
+ player = Player.getInstance(getApplicationContext());
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setTitle("Highscores");
+ // Create the adapter that will return a fragment for each of the three
+ // primary sections of the activity.
+ mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+
+ // Set up the ViewPager with the sections adapter.
+ mViewPager = (ViewPager) findViewById(R.id.container);
+ mViewPager.setAdapter(mSectionsPagerAdapter);
+
+
+ // start the current level when pressing the big red button
+ // ... but only if having access.
+ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int lvl_id = mSectionsPagerAdapter.getLevelIdForPosition(mViewPager.getCurrentItem());
+ if(!player.getPlayerInfo().hasAccessToLevel(lvl_id)) {
+ Snackbar.make(view, "No access to this level yet... complete the other levels first" , Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ } else {
+ Intent intent = new Intent(HighscoreActivity.this, GamingActivity.class);
+ intent.putExtra(GamingActivity.INTENT_EXTRA_SCENARIO, lvl_id);
+ finish();
+ startActivity(intent);
+ }
+ }
+ });
+
+ }
+
+ /**
+ * A placeholder fragment containing a simple view.
+ */
+ public static class HighscoreFragment extends Fragment {
+ /**
+ * The fragment argument representing the section number for this
+ * fragment.
+ */
+ private static final String ARG_LVL_ID = "LVL_ID";
+
+ public HighscoreFragment() {
+ }
+
+ /**
+ * Returns a new instance of this fragment for the given section
+ * number.
+ */
+ public static HighscoreFragment newInstance(int lvl_id) {
+ HighscoreFragment fragment = new HighscoreFragment();
+ Bundle args = new Bundle();
+ args.putInt(ARG_LVL_ID, lvl_id);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_highscore, container, false);
+// TextView textView = (TextView) rootView.findViewById(R.id.section_label);
+ Player player = Player.getInstance(getContext());
+ ScoreList scores = player.getPlayerInfo().getScoresForLevel(getArguments().getInt(ARG_LVL_ID));
+
+// String highscoreText = "";
+
+ ScoreList topscores = scores.getTopN(8); // TODO: only highscores for current lEVEL!!!!!!!
+
+ LinearLayout topscoreList = (LinearLayout) rootView.findViewById(R.id.topscoreList);
+
+ if(topscores.size() == 0) {
+// TextView noScoreItemText = new TextView(getContext(), null, R.style.AppTheme);
+ TextView noScoreItemText = new TextView(getContext());
+ noScoreItemText.setText("No Scores");
+ noScoreItemText.setTextColor(ContextCompat.getColor(getContext(), R.color.highscore));
+ noScoreItemText.setTextSize(getResources().getDimension(R.dimen.highscore_textsize));
+ noScoreItemText.setTypeface(Typeface.DEFAULT_BOLD);
+ topscoreList.addView(noScoreItemText);
+ }
+
+ int i = 0;
+ for(Score topscore: topscores) {
+ i++;
+ String highscoreText = String.format("%1$d. %2$.2f\n", i, topscore.score); //make line by line elements
+ TextView scoreItem = new TextView(getContext());
+ scoreItem.setText(highscoreText);
+ scoreItem.setTextColor(ContextCompat.getColor(getContext(), R.color.highscore));
+ scoreItem.setTextSize(getResources().getDimension(R.dimen.highscore_textsize));
+ scoreItem.setTypeface(Typeface.DEFAULT_BOLD);
+ topscoreList.addView(scoreItem);
+ }
+// textView.setText(highscoreText);
+// textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_LVL_ID)));
+ return rootView;
+ }
+ }
+
+ /**
+ * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
+ * one of the sections/tabs/pages.
+ */
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ // getItem is called to instantiate the fragment for the given page.
+ // Return a HighscoreFragment (defined as a static inner class below).
+ // position is the used to get lvl_id.
+ return HighscoreFragment.newInstance(getLevelIdForPosition(position));
+ }
+
+ public int getLevelIdForPosition(int position) {
+ return Scenario.SCENARIOS.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ // Show 3 total pages.
+ return Scenario.SCENARIOS.size();
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return "SECTION 1";
+ case 1:
+ return "SECTION 2";
+ case 2:
+ return "SECTION 3";
+ }
+ return null;
+ }
+ }
+}
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/IntroActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/IntroActivity.java
index 261018f..242c591 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/IntroActivity.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/IntroActivity.java
@@ -15,11 +15,22 @@ public class IntroActivity extends AppCompatActivity {
protected Player player;
+ protected Handler continueHandler;
+
+ protected Runnable continueRunnable = new Runnable() {
+ @Override
+ public void run() {
+ continueToMenu();
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getSupportActionBar().hide();
+ if(getSupportActionBar() != null) {
+ getSupportActionBar().hide();
+ }
setContentView(R.layout.activity_intro);
player = Player.getInstance(getApplicationContext());
@@ -31,6 +42,17 @@ public class IntroActivity extends AppCompatActivity {
extraLogoDelay = 0;
}
+ View introView = findViewById(R.id.activity_intro);
+
+ if(!player.isNew()) {
+ introView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ continueToMenu();
+ }
+ });
+ }
+
final ImageView logoV2 = (ImageView) findViewById(R.id.logoV2);
final ImageView logoArquivo = (ImageView) findViewById(R.id.logoArquivo);
final ImageView logoAffectiva = (ImageView) findViewById(R.id.logoAffectiva);
@@ -61,17 +83,16 @@ public class IntroActivity extends AppCompatActivity {
animatorSet.start();
- final Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(IntroActivity.this, MenuActivity.class);
- finish();
- startActivity(intent);
- //disable distracting transition when going to menu
- IntroActivity.this.overridePendingTransition(0, 0);
+ continueHandler = new Handler();
+ continueHandler.postDelayed(continueRunnable, 7000 + (3*extraLogoDelay));
+ }
- }
- }, 7000 + (3*extraLogoDelay));
+ public void continueToMenu() {
+ continueHandler.removeCallbacks(continueRunnable);
+ Intent intent = new Intent(this, MenuActivity.class);
+ finish();
+ startActivity(intent);
+ //disable distracting transition when going to menu
+ IntroActivity.this.overridePendingTransition(0, 0);
}
}
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/MenuActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/MenuActivity.java
index 5c48ff7..3d458a2 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/MenuActivity.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/MenuActivity.java
@@ -21,7 +21,9 @@ public class MenuActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getSupportActionBar().hide();
+ if(getSupportActionBar() != null) {
+ getSupportActionBar().hide();
+ }
setContentView(R.layout.activity_menu);
player = Player.getInstance(getApplicationContext());
@@ -90,8 +92,9 @@ public class MenuActivity extends AppCompatActivity {
highscoreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Toast toast = Toast.makeText(getApplicationContext(), "Not implemented yet", Toast.LENGTH_LONG);
- toast.show();
+ Intent intent = new Intent(MenuActivity.this, HighscoreActivity.class);
+// intent.putExtra(HighscoreActivity.INTENT_EXTRA_LEVEL, player.getPlayerInfo().reachedLevelId);
+ startActivity(intent);
}
});
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/PlayerInfo.java b/app/src/main/java/com/rubenvandeven/emotionhero/PlayerInfo.java
index 42f5020..62038c1 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/PlayerInfo.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/PlayerInfo.java
@@ -67,4 +67,13 @@ public class PlayerInfo {
return false;
}
+
+ public boolean hasAccessToLevel(int lvl_id) {
+ if(lvl_id == reachedLevelId) {
+ return true;
+ }
+
+ return Scenario.isHigherLevel(reachedLevelId, lvl_id);
+ }
+
}
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/Scenario.java b/app/src/main/java/com/rubenvandeven/emotionhero/Scenario.java
index 697f0d3..749074c 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/Scenario.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/Scenario.java
@@ -25,12 +25,14 @@ public class Scenario {
public static final int LVL_ANGER = 1;
public static final int LVL_JOY = 2;
public static final int LVL_SURPRISE = 3;
+ public static final int LVL_SADDNESS= 4;
// the levels in the right order.
public static final ArrayList SCENARIOS = new ArrayList() {{
add(LVL_ANGER);
add(LVL_JOY);
add(LVL_SURPRISE);
+ add(LVL_SADDNESS);
}};
static int DESIRED_FPS = 25;
@@ -318,6 +320,12 @@ public class Scenario {
setTarget(Emotion.SURPRISE, 80, 3);
setTarget(Emotion.SURPRISE, 100, 4);
break;
+ case LVL_SADDNESS:
+ setTarget(Emotion.SADNESS, 20, 1);
+ setTarget(Emotion.SADNESS, 50, 2);
+ setTarget(Emotion.SADNESS, 80, 3);
+ setTarget(Emotion.SADNESS, 100, 4);
+ break;
}
}
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/Score.java b/app/src/main/java/com/rubenvandeven/emotionhero/Score.java
index d37f3c0..c3c486b 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/Score.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/Score.java
@@ -8,9 +8,10 @@ import java.util.Date;
*/
public class Score {
- int lvl_id;
- float score;
- Date time;
+ public int id;
+ public int lvl_id;
+ public float score;
+ public Date time;
ArrayList targets = new ArrayList<>();
diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/ScoreList.java b/app/src/main/java/com/rubenvandeven/emotionhero/ScoreList.java
index bd59e4e..27262d3 100644
--- a/app/src/main/java/com/rubenvandeven/emotionhero/ScoreList.java
+++ b/app/src/main/java/com/rubenvandeven/emotionhero/ScoreList.java
@@ -10,6 +10,13 @@ import java.util.Comparator;
public class ScoreList extends ArrayList{
+ public boolean add(Score score) {
+ boolean ret = super.add(score);
+ int id = super.indexOf(score);
+ score.id = id;
+ return ret;
+ }
+
/**
* Check if given highscore is highest hit in this set.
* @param score
diff --git a/app/src/main/res/layout/activity_highscore.xml b/app/src/main/res/layout/activity_highscore.xml
new file mode 100644
index 0000000..d9042a1
--- /dev/null
+++ b/app/src/main/res/layout/activity_highscore.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_menu.xml b/app/src/main/res/layout/activity_menu.xml
index 6a7c4f8..07ccea8 100644
--- a/app/src/main/res/layout/activity_menu.xml
+++ b/app/src/main/res/layout/activity_menu.xml
@@ -27,7 +27,7 @@
android:id="@+id/startButton"
android:fontFamily="sans-serif" />