Skip to content

Commit

Permalink
Simplified activity transitions between gameplay and results, added i…
Browse files Browse the repository at this point in the history
…mage button for game play and results
  • Loading branch information
chrisjluc committed Feb 28, 2015
1 parent c3944da commit 6132b70
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 99 deletions.
14 changes: 7 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="chrisjluc.onesearch.ui.gameplay.WordSearchActivity"
android:label="@string/app_name"></activity>
android:name=".ui.gameplay.WordSearchActivity"
android:label="@string/app_name" />
<activity
android:name="chrisjluc.onesearch.ui.SplashActivity"
android:label="@string/app_name"></activity>
android:name=".ui.SplashActivity"
android:label="@string/app_name" />
<activity
android:name="chrisjluc.onesearch.ui.ResultsActivity"
android:label="@string/title_activity_results"></activity>
android:name=".ui.ResultsActivity"
android:label="@string/title_activity_results" />
<activity
android:name="chrisjluc.onesearch.ui.MenuActivity"
android:name=".ui.MenuActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/chrisjluc/onesearch/OnesearchApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public void onCreate() {
// Enabling Advertising Features in Google Analytics allows you to take advantage of
// Remarketing, Demographics & Interests reports, and more.
Tracker t = getTracker(TrackerName.APP_TRACKER);
// GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
t.enableAdvertisingIdCollection(true);

if(BuildConfig.DEBUG) {
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
GoogleAnalytics.getInstance(this).setDryRun(true);
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/chrisjluc/onesearch/models/GameState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package chrisjluc.onesearch.models;

public class GameState {
public static final String START = "s", PLAY = "p", PAUSE = "a", FINISHED = "f";
}
4 changes: 3 additions & 1 deletion app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class MenuActivity extends BaseGooglePlayServicesActivity implements View
private final static String MENU_PREF_NAME = "menu_prefs";
private final static String FIRST_TIME = "first_time";

private final static long ROUND_TIME_IN_MS = 60000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -74,7 +76,7 @@ public void onClick(View view) {
}
analyticsTrackEvent(ga_button_id);
WordSearchManager wsm = WordSearchManager.getInstance();
wsm.Initialize(new GameMode(GameType.Timed, gd, 60000), getApplicationContext());
wsm.Initialize(new GameMode(GameType.Timed, gd, ROUND_TIME_IN_MS), getApplicationContext());
wsm.buildWordSearches();
Intent i = new Intent(getApplicationContext(), WordSearchActivity.class);
startActivity(i);
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package chrisjluc.onesearch.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
Expand All @@ -21,9 +20,6 @@

public class ResultsActivity extends BaseGooglePlayServicesActivity implements View.OnClickListener {

public final static int RESULT_REPLAY_GAME = 0;
public final static int RESULT_EXIT_TO_MENU = 1;
public final static String ACTION_IDENTIFIER = "action_identifier";
public final static int REQUEST_LEADERBOARD = 2;
public final static int REQUEST_ACHIEVEMENTS = 3;

Expand Down Expand Up @@ -169,18 +165,16 @@ public void onClick(View view) {
return;

}
Intent resultIntent = new Intent(getApplicationContext(), WordSearchActivity.class);
switch (view.getId()) {
case R.id.bReplay:
analyticsTrackEvent(R.string.ga_click_replay);
resultIntent.putExtra(ACTION_IDENTIFIER, RESULT_REPLAY_GAME);
Intent intent = new Intent(getApplicationContext(), WordSearchActivity.class);
startActivity(intent);
break;
case R.id.bReturnMenu:
analyticsTrackEvent(R.string.ga_click_return_to_menu);
resultIntent.putExtra(ACTION_IDENTIFIER, RESULT_EXIT_TO_MENU);
break;
}
setResult(Activity.RESULT_OK, resultIntent);
finish();
}

Expand All @@ -199,9 +193,6 @@ protected void onResume() {

@Override
public void onBackPressed() {
Intent resultIntent = new Intent(getApplicationContext(), WordSearchActivity.class);
resultIntent.putExtra(ACTION_IDENTIFIER, RESULT_EXIT_TO_MENU);
setResult(Activity.RESULT_OK, resultIntent);
finish();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package chrisjluc.onesearch.ui.gameplay;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import chrisjluc.onesearch.R;
import chrisjluc.onesearch.adapters.WordSearchPagerAdapter;
import chrisjluc.onesearch.base.BaseActivity;
import chrisjluc.onesearch.framework.WordSearchManager;
import chrisjluc.onesearch.models.GameState;
import chrisjluc.onesearch.ui.ResultsActivity;

public class WordSearchActivity extends BaseActivity implements WordSearchGridView.WordFoundListener, PauseDialogFragment.PauseDialogListener, View.OnClickListener {
Expand Down Expand Up @@ -50,10 +50,8 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.wordsearch_activity);
mGameState = GameState.START;
Button skipButton = (Button) findViewById(R.id.bSkip);
Button pauseButton = (Button) findViewById(R.id.bPause);
skipButton.setOnClickListener(this);
pauseButton.setOnClickListener(this);
findViewById(R.id.bSkip).setOnClickListener(this);
findViewById(R.id.bPause).setOnClickListener(this);
mTimerTextView = (TextView) findViewById(R.id.tvTimer);
mScoreTextView = (TextView) findViewById(R.id.tvScore);
mScoreTextView.setText("0");
Expand Down Expand Up @@ -174,24 +172,6 @@ protected void onPause() {
stopCountDownTimer();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
System.out.println("Result not okay");
return;
}
switch (requestCode) {
case 0:
int action = data.getIntExtra(ResultsActivity.ACTION_IDENTIFIER, -1);
if (action == ResultsActivity.RESULT_REPLAY_GAME)
restart();
else if (action == ResultsActivity.RESULT_EXIT_TO_MENU)
finish();
break;
}
}

@Override
public void onBackPressed() {
pauseGameplay();
Expand All @@ -200,17 +180,36 @@ public void onBackPressed() {
private void setupCountDownTimer(final long timeinMS) {
mCountDownTimer = new CountDownTimer(timeinMS, TIMER_GRANULARITY_IN_MS) {


public void onTick(long millisUntilFinished) {
mTimerTextView.setText(Long.toString(millisUntilFinished / 1000 + 1));
mTimeRemaining = millisUntilFinished;
long secondsRemaining = mTimeRemaining / 1000 + 1;
mTimerTextView.setText(Long.toString(secondsRemaining));
if (secondsRemaining <= 10) {
mTimerTextView.setTextColor(getResources().getColor(R.color.red));
} else {
mTimerTextView.setTextColor(Color.BLACK);

}
}

public void onFinish() {
mGameState = GameState.FINISHED;
Intent i = new Intent(getApplicationContext(), ResultsActivity.class);
i.putExtra("score", mScore);
i.putExtra("skipped", mSkipped);
startActivityForResult(i, 0);
mTimerTextView.setText("0");
((WordSearchFragment) mWordSearchPagerAdapter.getFragmentFromCurrentItem(currentItem)).highlightWord();
(new CountDownTimer(ON_SKIP_HIGHLIGHT_WORD_DELAY_IN_MS, TIMER_GRANULARITY_IN_MS) {

public void onTick(long millisUntilFinished) {
}

public void onFinish() {
Intent i = new Intent(getApplicationContext(), ResultsActivity.class);
i.putExtra("score", mScore);
i.putExtra("skipped", mSkipped);
startActivity(i);
finish();
}
}).start();
}
};
}
Expand All @@ -233,7 +232,4 @@ public int getScore() {
return mScore;
}

private static class GameState {
public static final String START = "s", PLAY = "pl", PAUSE = "pa", FINISHED = "fi";
}
}
Binary file added app/src/main/res/drawable/achievement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/leaderboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/pause_button.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/skip_button.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions app/src/main/res/layout/activity_results.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,26 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<chrisjluc.onesearch.ui.components.GameButton
<ImageButton
android:layout_centerHorizontal="true"
android:layout_below="@id/llScoreResult"
android:id="@+id/bShowLeaderBoards"
android:text="Leaderboards"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:src="@drawable/leaderboard"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:layout_width="@dimen/results_image_button_size"
android:layout_height="@dimen/results_image_button_size" />

<chrisjluc.onesearch.ui.components.GameButton
<ImageButton
android:layout_marginTop="@dimen/element_margin_separation"
android:layout_centerHorizontal="true"
android:layout_below="@id/bShowLeaderBoards"
android:id="@+id/bShowAchievements"
android:text="Achievements"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:src="@drawable/achievement"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:layout_width="@dimen/results_image_button_size"
android:layout_height="@dimen/results_image_button_size" />

<LinearLayout
android:layout_alignParentBottom="true"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_gameplay_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
android:layout_margin="@dimen/activity_vertical_margin" >
<chrisjluc.onesearch.ui.components.GameTextView
android:text="Time"
android:textSize="18sp"
android:textSize="@dimen/wordsearchactivity_indicator_text_title_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<chrisjluc.onesearch.ui.components.GameTextView
<chrisjluc.onesearch.ui.components.GameBoldTextView
android:id="@+id/tvTimePause"
android:text="@string/app_name"
android:gravity="center"
android:textSize="28sp"
android:textSize="@dimen/wordsearchactivity_indicator_text_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Expand All @@ -51,15 +51,15 @@
android:layout_margin="@dimen/activity_vertical_margin" >
<chrisjluc.onesearch.ui.components.GameTextView
android:text="Score"
android:textSize="18sp"
android:textSize="@dimen/wordsearchactivity_indicator_text_title_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<chrisjluc.onesearch.ui.components.GameTextView
<chrisjluc.onesearch.ui.components.GameBoldTextView
android:id="@+id/tvScorePause"
android:text="@string/app_name"
android:gravity="center"
android:textSize="28sp"
android:textSize="@dimen/wordsearchactivity_indicator_text_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Expand Down
46 changes: 32 additions & 14 deletions app/src/main/res/layout/wordsearch_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".WordSearchActivity">

<LinearLayout
Expand Down Expand Up @@ -82,21 +83,38 @@
android:layout_centerHorizontal="true"
android:weightSum="1">

<chrisjluc.onesearch.ui.components.GameButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/element_margin_separation"
android:text="Pause"
android:id="@+id/bPause"
android:layout_weight="0.50" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="@dimen/wordsearchactivity_image_button_size"
android:layout_weight="0.50">

<ImageButton
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:layout_height="@dimen/wordsearchactivity_image_button_size"
android:layout_width="@dimen/wordsearchactivity_image_button_size"
android:background="@android:color/transparent"
android:layout_margin="@dimen/element_margin_separation"
android:src="@drawable/pause_button"
android:id="@+id/bPause" />
</RelativeLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="@dimen/wordsearchactivity_image_button_size"
android:layout_weight="0.50">

<ImageButton
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:layout_height="@dimen/wordsearchactivity_image_button_size"
android:layout_width="@dimen/wordsearchactivity_image_button_size"
android:background="@android:color/transparent"
android:layout_margin="@dimen/element_margin_separation"
android:src="@drawable/skip_button"
android:id="@+id/bSkip" />
</RelativeLayout>

<chrisjluc.onesearch.ui.components.GameButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/element_margin_separation"
android:text="Skip"
android:layout_weight="0.50"
android:id="@+id/bSkip" />
</LinearLayout>

</RelativeLayout>
23 changes: 14 additions & 9 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="grid_horizontal_margin">4dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="element_margin_separation">4dp</dimen>
<dimen name="results_title_padding">0dp</dimen>
<dimen name="results_title_size">24sp</dimen>

<dimen name="splash_header_text">36sp</dimen>
<dimen name="splash_center_text">28sp</dimen>
<dimen name="splash_bottom_text">28sp</dimen>
<dimen name="top_bar">80dp</dimen>
<dimen name="bottom_bar">40dp</dimen>

<!--Gameplay-->
<dimen name="grid_horizontal_margin">4dp</dimen>
<dimen name="wordsearchactivity_indicator_text_padding_left">8dp</dimen>
<dimen name="wordsearchactivity_indicator_text_title_size">18sp</dimen>
<dimen name="wordsearchactivity_indicator_text_size">28sp</dimen>
<dimen name="wordsearchactivity_image_button_size">80dp</dimen>
<dimen name="wordsearchfragment_word_size">36sp</dimen>

<dimen name="top_bar">80dp</dimen>
<dimen name="bottom_bar">40dp</dimen>
<!--Results-->
<dimen name="results_title_padding">0dp</dimen>
<dimen name="results_title_size">24sp</dimen>
<dimen name="results_image_button_size">60dp</dimen>

<!--Splash screen-->
<dimen name="splash_header_text">36sp</dimen>
<dimen name="splash_center_text">28sp</dimen>
<dimen name="splash_bottom_text">28sp</dimen>
</resources>
Loading

0 comments on commit 6132b70

Please sign in to comment.