mirror of
https://github.com/bspeice/itcs4180
synced 2025-04-20 23:01:34 -04:00
Add the behavior for the ResultActivity
This commit is contained in:
parent
9cad32bb14
commit
d7980f9108
@ -52,6 +52,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:onClick="onClick"
|
||||||
android:text="@string/btnTryAgain" />
|
android:text="@string/btnTryAgain" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@ -60,6 +61,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:onClick="onClick"
|
||||||
android:text="@string/btnExit" />
|
android:text="@string/btnExit" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -2,14 +2,35 @@ package com.uncc.hw3;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class ResultActivity extends Activity {
|
public class ResultActivity extends Activity {
|
||||||
|
|
||||||
|
static final int winTime = 50;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_result);
|
setContentView(R.layout.activity_result);
|
||||||
|
|
||||||
|
float elapsedTime = getIntent().getExtras().getFloat("ELAPSED_TIME");
|
||||||
|
|
||||||
|
// We always show the elapsed time, so let's do that now
|
||||||
|
TextView elapsedText = (TextView)findViewById(R.id.txtResultElapsed);
|
||||||
|
elapsedText.setText("Time elapsed : " + elapsedTime);
|
||||||
|
|
||||||
|
// The layout is set for success, so we only need to change it if the
|
||||||
|
// user lost the game...
|
||||||
|
if (elapsedTime > winTime) {
|
||||||
|
TextView resultText = (TextView)findViewById(R.id.txtResultValue);
|
||||||
|
resultText.setText(R.string.txtResultValue_Failure);
|
||||||
|
ImageView imgChest = (ImageView)findViewById(R.id.imgResult);
|
||||||
|
imgChest.setImageDrawable(getResources().getDrawable(R.drawable.lose));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -19,4 +40,12 @@ public class ResultActivity extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
// Figure out if the Try Again or Exit button was clicked
|
||||||
|
if (v.getId() == R.id.btnTryAgain)
|
||||||
|
startActivity(new Intent(this, MainActivity.class));
|
||||||
|
else if (v.getId() == R.id.btnExit)
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user