Many styling things and from Highscores now access to game

This commit is contained in:
Ruben 2016-08-22 21:39:19 +01:00
parent 07f3320a47
commit d3cf4fa73b
19 changed files with 421 additions and 32 deletions

View File

@ -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'
}

View File

@ -28,17 +28,27 @@
</activity>
<activity
android:name=".IntroActivity"
android:theme="@style/FullscreenTheme"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MenuActivity"
android:theme="@style/FullscreenTheme"
android:label="@string/app_name"></activity>
<activity
android:name=".MenuActivity"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" />
<activity
android:name=".HighscoreActivity"
android:label="@string/title_activity_highscore"
android:parentActivityName=".MenuActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.rubenvandeven.emotionhero.MenuActivity" />
</activity>
</application>
</manifest>

View File

@ -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);

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
});

View File

@ -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);
}
}

View File

@ -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<Integer> SCENARIOS = new ArrayList<Integer>() {{
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;
}
}

View File

@ -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<Scenario.Target> targets = new ArrayList<>();

View File

@ -10,6 +10,13 @@ import java.util.Comparator;
public class ScoreList extends ArrayList<Score>{
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

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.rubenvandeven.emotionhero.HighscoreActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/colorPrimary" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_media_play"
app:backgroundTint="@color/colorScenarioLine" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -27,7 +27,7 @@
android:id="@+id/startButton"
android:fontFamily="sans-serif" />
<Button
android:text="@string/continue"
android:text="@string/continueBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/continueButton"

View File

@ -0,0 +1,25 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.rubenvandeven.emotionhero.HighscoreActivity$HighscoreFragment">
<!--<TextView-->
<!--android:id="@+id/section_label"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
<LinearLayout
android:id="@+id/topscoreList"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"></LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.rubenvandeven.emotionhero.HighscoreActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>

View File

@ -0,0 +1,22 @@
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorScenarioLine</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:windowBackground">?attr/colorPrimary</item>
<item name="android:textColorSecondary">@color/colorPrimaryDark</item>
<item name="android:colorBackground">@color/colorPrimary</item>
<item name="android:navigationBarColor">@android:color/background_dark</item>
<item name="android:statusBarColor">?android:attr/colorPrimaryDark</item>
</style>
</resources>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#0000ff</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorScenarioLine">#FF0000</color>
<color name="colorPrimaryDark">#000099</color>
<color name="colorAccent">#ff4081</color>
<color name="colorScenarioLine">#ff0000</color>
<color name="black_overlay">#66000000</color>
<color name="highscore">#ffff00</color>

View File

@ -2,4 +2,7 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
<dimen name="highscore_textsize">15sp</dimen>
</resources>

View File

@ -7,6 +7,9 @@
<string name="restart">Restart</string>
<string name="nextLvl">Next Level!</string>
<string name="start">Start</string>
<string name="continue">Continue</string>
<string name="continueBtn">Continue</string>
<string name="highscores">Highscores</string>
<string name="title_activity_highscore">HighscoreActivity</string>
<string name="action_settings">Settings</string>
<string name="section_format">Hello World from section: %1$d</string>
</resources>

View File

@ -1,11 +1,15 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccent">@color/colorScenarioLine</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:windowBackground">?attr/colorPrimary</item>
<item name="android:textColorSecondary">@color/colorPrimaryDark</item>
<item name="android:colorBackground">@color/colorPrimary</item>
</style>
<style name="FullscreenTheme" parent="AppTheme">
@ -20,4 +24,24 @@
<item name="android:background">@color/black_overlay</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="highscoreItem" parent="@android:style/Widget.TextView">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">50sp</item>
<item name="android:color">@color/highscore</item>
</style>
</resources>