passing tile time to DB
This commit is contained in:
parent
7a2ef373b1
commit
a36bfccb24
|
@ -12,6 +12,7 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<activity android:name=".QuickQuizStart"></activity>
|
<activity android:name=".QuickQuizStart"></activity>
|
||||||
|
<activity android:name=".QuizQuestionPage" />
|
||||||
<activity android:name=".UserAreaActivity" />
|
<activity android:name=".UserAreaActivity" />
|
||||||
<activity android:name=".QuickPlayMenu" />
|
<activity android:name=".QuickPlayMenu" />
|
||||||
<activity android:name=".TileMatchingActivity" />
|
<activity android:name=".TileMatchingActivity" />
|
||||||
|
@ -19,8 +20,6 @@
|
||||||
<activity android:name=".JumbleActivity" />
|
<activity android:name=".JumbleActivity" />
|
||||||
<activity android:name=".login" />
|
<activity android:name=".login" />
|
||||||
<activity android:name=".registration" />
|
<activity android:name=".registration" />
|
||||||
<activity android:name=".QuizQuestionPage" />
|
|
||||||
|
|
||||||
<activity android:name=".MainActivity">
|
<activity android:name=".MainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
|
@ -32,7 +32,8 @@ public class QuickPlayMenu extends AppCompatActivity {
|
||||||
private Button game4;
|
private Button game4;
|
||||||
private long jumble_elapsed_millis = 0;
|
private long jumble_elapsed_millis = 0;
|
||||||
private String username;
|
private String username;
|
||||||
private TextView username_text;
|
private TextView game_times;
|
||||||
|
private long tile_elapsed_millis = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,8 +49,8 @@ public class QuickPlayMenu extends AppCompatActivity {
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
username = intent.getStringExtra(login.EXTRA_TEXT);
|
username = intent.getStringExtra(login.EXTRA_TEXT);
|
||||||
//username_text = findViewById(R.id.username);
|
game_times = findViewById(R.id.game_times);
|
||||||
//username_text.setText("username : "+ username);
|
game_times.setText("username : "+ username);
|
||||||
|
|
||||||
jumble.setOnClickListener(new View.OnClickListener() {
|
jumble.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +66,8 @@ public class QuickPlayMenu extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(QuickPlayMenu.this,TileMatchingActivity.class);
|
Intent intent = new Intent(QuickPlayMenu.this,TileMatchingActivity.class);
|
||||||
startActivity(intent);
|
intent.putExtra("tile_elapsed_millis", tile_elapsed_millis);
|
||||||
|
startActivityForResult(intent, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -89,6 +91,21 @@ public class QuickPlayMenu extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
if (requestCode == 1) {
|
||||||
|
if (resultCode == RESULT_OK) {
|
||||||
|
jumble_elapsed_millis = data.getLongExtra("jumble_elapsed_millis", 0);
|
||||||
|
game_times.setText("username : "+ username+ " " + jumble_elapsed_millis);
|
||||||
if(jumble_elapsed_millis != 0) {
|
if(jumble_elapsed_millis != 0) {
|
||||||
|
|
||||||
Response.Listener<String> responseListener = new Response.Listener<String>() {
|
Response.Listener<String> responseListener = new Response.Listener<String>() {
|
||||||
|
@ -112,22 +129,54 @@ public class QuickPlayMenu extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JumbleSender jumble_sender = new JumbleSender(username, jumble_elapsed_millis, responseListener);
|
JumbleSender jumble_sender = new JumbleSender(username, jumble_elapsed_millis, responseListener);
|
||||||
RequestQueue queue = Volley.newRequestQueue(QuickPlayMenu.this);
|
RequestQueue queue = Volley.newRequestQueue(QuickPlayMenu.this);
|
||||||
queue.add(jumble_sender);
|
queue.add(jumble_sender);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
if (resultCode == RESULT_CANCELED) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
if (requestCode == 1) {
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (requestCode == 2) {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
jumble_elapsed_millis = data.getLongExtra("jumble_elapsed_millis", 0);
|
tile_elapsed_millis = data.getLongExtra("tile_elapsed_millis", 0);
|
||||||
|
game_times.setText("username : "+ username+ " " + tile_elapsed_millis);
|
||||||
|
|
||||||
|
if(tile_elapsed_millis!= 0) {
|
||||||
|
|
||||||
|
Response.Listener<String> responseListener = new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
try {
|
||||||
|
JSONObject jsonResponse = new JSONObject(response);
|
||||||
|
boolean success = jsonResponse.getBoolean("success");
|
||||||
|
if (success) {
|
||||||
|
Intent intent = new Intent(QuickPlayMenu.this, UserAreaActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(QuickPlayMenu.this);
|
||||||
|
builder.setMessage("Register Failed")
|
||||||
|
.setNegativeButton("Retry", null)
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TileSender tile_sender = new TileSender(username, tile_elapsed_millis, responseListener);
|
||||||
|
RequestQueue queue = Volley.newRequestQueue(QuickPlayMenu.this);
|
||||||
|
queue.add(tile_sender);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class QuizQuestionPage extends AppCompatActivity {
|
public class QuizQuestionPage extends AppCompatActivity {
|
||||||
|
|
||||||
private TextView textViewQuestion;
|
private TextView textViewQuestion;
|
||||||
|
@ -55,7 +55,9 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
questionCountTotal = questionList.size();
|
questionCountTotal = questionList.size();
|
||||||
Collections.shuffle(questionList);
|
Collections.shuffle(questionList);
|
||||||
|
|
||||||
showNextQuestion();
|
//showNextQuestion();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
package com.example.alzapp;
|
package com.example.alzapp;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Chronometer;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.example.alzapp.R;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
/*******
|
/*******
|
||||||
Created on: 21/01/2020
|
Created on: 21/01/2020
|
||||||
|
|
||||||
|
@ -31,6 +32,12 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
ImageView i21,i22,i23,i24;
|
ImageView i21,i22,i23,i24;
|
||||||
ImageView i31,i32,i33,i34;
|
ImageView i31,i32,i33,i34;
|
||||||
ImageView i41,i42,i43,i44;
|
ImageView i41,i42,i43,i44;
|
||||||
|
private Chronometer chronometer;
|
||||||
|
private long pauseOffset;
|
||||||
|
private boolean running;
|
||||||
|
private Button pauser;
|
||||||
|
private Button resumer;
|
||||||
|
private long elapsedMillis;
|
||||||
|
|
||||||
Integer[] cardsArray={101,102,103,104,105,106,107,108,201,202,203,204,205,206,207,208};
|
Integer[] cardsArray={101,102,103,104,105,106,107,108,201,202,203,204,205,206,207,208};
|
||||||
|
|
||||||
|
@ -46,6 +53,7 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
setContentView(R.layout.activity_tile_matching);
|
setContentView(R.layout.activity_tile_matching);
|
||||||
counter=(TextView) findViewById(R.id.counter1);
|
counter=(TextView) findViewById(R.id.counter1);
|
||||||
|
|
||||||
|
|
||||||
i11=(ImageView) findViewById(R.id.i11);
|
i11=(ImageView) findViewById(R.id.i11);
|
||||||
i12=(ImageView) findViewById(R.id.i12);
|
i12=(ImageView) findViewById(R.id.i12);
|
||||||
i13=(ImageView) findViewById(R.id.i13);
|
i13=(ImageView) findViewById(R.id.i13);
|
||||||
|
@ -88,6 +96,13 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
|
|
||||||
frontCards();
|
frontCards();
|
||||||
|
|
||||||
|
chronometer = findViewById(R.id.tile_time);
|
||||||
|
chronometer.setFormat("Time: %s");
|
||||||
|
chronometer.setBase(SystemClock.elapsedRealtime());
|
||||||
|
startChronometer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Collections.shuffle(Arrays.asList(cardsArray));
|
Collections.shuffle(Arrays.asList(cardsArray));
|
||||||
|
|
||||||
i11.setOnClickListener(new View.OnClickListener() {
|
i11.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -233,6 +248,26 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
|
||||||
|
@Override
|
||||||
|
public void onChronometerTick(Chronometer chronometer) {
|
||||||
|
if (checkEnd()) {
|
||||||
|
elapsedMillis = SystemClock.elapsedRealtime() - chronometer.getBase();
|
||||||
|
//long minutes = TimeUnit.MILLISECONDS.toMinutes(elapsedMillis);
|
||||||
|
//long seconds = TimeUnit.MILLISECONDS.toSeconds(elapsedMillis);
|
||||||
|
|
||||||
|
|
||||||
|
Intent resultIntent = new Intent();
|
||||||
|
resultIntent.putExtra("tile_elapsed_millis", elapsedMillis);
|
||||||
|
setResult(RESULT_OK, resultIntent);
|
||||||
|
finish();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,7 +511,7 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
checkEnd();
|
checkEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEnd(){
|
private boolean checkEnd(){
|
||||||
if(i11.getVisibility()==View.INVISIBLE &&
|
if(i11.getVisibility()==View.INVISIBLE &&
|
||||||
i12.getVisibility()==View.INVISIBLE &&
|
i12.getVisibility()==View.INVISIBLE &&
|
||||||
i13.getVisibility()==View.INVISIBLE &&
|
i13.getVisibility()==View.INVISIBLE &&
|
||||||
|
@ -503,6 +538,11 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,4 +565,25 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
img207=R.drawable.chicken;
|
img207=R.drawable.chicken;
|
||||||
img208=R.drawable.cow;
|
img208=R.drawable.cow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startChronometer() {
|
||||||
|
if (!running) {
|
||||||
|
chronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
|
||||||
|
chronometer.start();
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pauseChronometer() {
|
||||||
|
if (running) {
|
||||||
|
chronometer.stop();
|
||||||
|
pauseOffset = SystemClock.elapsedRealtime() - chronometer.getBase();
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetChronometer() {
|
||||||
|
chronometer.setBase(SystemClock.elapsedRealtime());
|
||||||
|
pauseOffset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.example.alzapp;
|
||||||
|
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TileSender extends StringRequest {
|
||||||
|
private static final String REQUEST_URL = "https://eclectic-sweeps.000webhostapp.com/tile_sender.php";
|
||||||
|
private Map<String, String> params;
|
||||||
|
|
||||||
|
TileSender(String username,long times , Response.Listener<String> listener) {
|
||||||
|
super(Method.POST, REQUEST_URL, listener, null);
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("username", username);
|
||||||
|
params.put("tile",times+"");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -89,6 +89,14 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/jumble"
|
app:layout_constraintTop_toBottomOf="@+id/jumble"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/game_times"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
|
||||||
|
|
||||||
|
android:textSize="50dp" />
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/username"
|
android:id="@+id/username"
|
||||||
|
|
|
@ -43,6 +43,17 @@
|
||||||
android:text="MOVES= 0"
|
android:text="MOVES= 0"
|
||||||
android:textSize="20sp"/>
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
|
<Chronometer
|
||||||
|
android:id="@+id/tile_time"
|
||||||
|
android:layout_width="132dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginLeft="24dp"
|
||||||
|
android:layout_marginEnd="263dp"
|
||||||
|
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue