Browse files

Merging intents

  • Loading branch information...
1 parent 12cb526 commit 1907f79cddd9bc824091ab379cdd6465933d910c @atoji committed Oct 30, 2011
View
2 AndroidManifest.xml
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.beyondweb.pong"
android:versionCode="1"
- android:versionName="1.0" >
+ android:versionName="1.0.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
View
56 src/com/beyondweb/pong/activities/GameOverActivity.java
@@ -1,56 +0,0 @@
-package com.beyondweb.pong.activities;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.content.Intent;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.widget.Button;
-import android.widget.TextView;
-
-import com.beyondweb.pong.R;
-
-public class GameOverActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- setContentView(R.layout.main);
-
- ((TextView) findViewById(R.id.title)).setTypeface(Typeface.createFromAsset(getAssets(), "font/atari.ttf"));
- ((Button) findViewById(R.id.player)).setTypeface(Typeface.createFromAsset(getAssets(), "font/atari.ttf"));
- ((Button) findViewById(R.id.easy)).setTypeface(Typeface.createFromAsset(getAssets(), "font/atari.ttf"));
- ((Button) findViewById(R.id.medium)).setTypeface(Typeface.createFromAsset(getAssets(), "font/atari.ttf"));
- ((Button) findViewById(R.id.hard)).setTypeface(Typeface.createFromAsset(getAssets(), "font/atari.ttf"));
-
- final boolean isNPC = getIntent().getExtras().getBoolean("isNPC");
- final int dificulty = getIntent().getExtras().getInt("dificulty");
- final int winner = getIntent().getExtras().getInt("winner");
-
- Builder builder = new AlertDialog.Builder(GameOverActivity.this);
- builder.setTitle(String.format(getString(R.string.player_wins), winner))
- .setMessage(R.string.play_again)
- .setPositiveButton(R.string.yes, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(GameOverActivity.this, PongActivity.class);
- intent.putExtra("isNPC", isNPC);
- intent.putExtra("dificulty", dificulty);
- GameOverActivity.this.startActivity(intent);
- GameOverActivity.this.finish();
- }
- })
- .setNegativeButton(R.string.no, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- GameOverActivity.this.finish();
- }
- })
- .show();
-
- super.onCreate(savedInstanceState);
- }
-}
View
33 src/com/beyondweb/pong/activities/StartActivity.java
@@ -1,5 +1,10 @@
package com.beyondweb.pong.activities;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.DialogInterface.OnClickListener;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.Button;
@@ -30,4 +35,32 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+
+ if (resultCode == RESULT_OK && requestCode == 15) {
+ int winner = data.getIntExtra("winner", 1);
+ final boolean isNPC = data.getBooleanExtra("isNPC", true);
+ final int dificulty = data.getIntExtra("dificulty", 16);
+
+ Builder builder = new AlertDialog.Builder(StartActivity.this);
+ builder.setTitle(String.format(getString(R.string.player_wins), winner))
+ .setMessage(R.string.play_again)
+ .setPositiveButton(R.string.yes, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(StartActivity.this, PongActivity.class);
+ intent.putExtra("isNPC", isNPC);
+ intent.putExtra("dificulty", dificulty);
+ StartActivity.this.startActivityForResult(intent, 15);
+ }
+ })
+ .setNegativeButton(R.string.no, null)
+ .show();
+
+ }
+
+ super.onActivityResult(requestCode, resultCode, data);
+ }
}
View
2 src/com/beyondweb/pong/listeners/StartGameListener.java
@@ -24,7 +24,7 @@ public void onClick(View v) {
Intent intent = new Intent(activity, PongActivity.class);
intent.putExtra("isNPC", isNPC);
intent.putExtra("dificulty", dificulty);
- activity.startActivity(intent);
+ activity.startActivityForResult(intent, 15);
}
}
View
10 src/com/beyondweb/pong/model/ScoreBoard.java
@@ -5,10 +5,10 @@
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.opengl.font.Font;
+import android.app.Activity;
import android.content.Intent;
import android.view.Display;
-import com.beyondweb.pong.activities.GameOverActivity;
import com.beyondweb.pong.activities.PongActivity;
@@ -66,11 +66,11 @@ private void gameOver(int winner) {
player1ScoreText.setText("" + player1.getScore());
player2ScoreText.setText("" + player2.getScore());
- Intent intent = new Intent(activity, GameOverActivity.class);
- intent.putExtra("isNPC", activity.getIntent().getExtras().getBoolean("isNPC"));
- intent.putExtra("dificulty", activity.getIntent().getExtras().getInt("dificulty"));
+ Intent intent = new Intent();
+ intent.putExtra("isNPC", activity.getIntent().getBooleanExtra("isNPC", true));
+ intent.putExtra("dificulty", activity.getIntent().getIntExtra("dificulty", 16));
intent.putExtra("winner", winner);
- activity.startActivity(intent);
+ activity.setResult(Activity.RESULT_OK, intent);
activity.finish();
}
}

0 comments on commit 1907f79

Please sign in to comment.