time calculation in jumble
This commit is contained in:
parent
d5971cf24a
commit
9cbaf5148e
|
@ -4,9 +4,7 @@
|
|||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<compositeConfiguration>
|
||||
<compositeBuild compositeDefinitionSource="SCRIPT" />
|
||||
</compositeConfiguration>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
|
@ -16,7 +14,6 @@
|
|||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Chronometer;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.Inflater.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/*******
|
||||
Created on: 21/01/2020
|
||||
|
@ -25,7 +23,7 @@ import java.util.zip.Inflater.*;
|
|||
********/
|
||||
|
||||
|
||||
public class JumbleActivity extends AppCompatActivity implements View.OnClickListener{
|
||||
public class JumbleActivity extends AppCompatActivity {
|
||||
|
||||
private TextView wordTv;
|
||||
private EditText wordEnteredTv;
|
||||
|
@ -33,6 +31,14 @@ public class JumbleActivity extends AppCompatActivity implements View.OnClickLis
|
|||
private String wordToFind;
|
||||
private int score = 0;
|
||||
private TextView score_dis;
|
||||
private TextView timer;
|
||||
private Chronometer chronometer;
|
||||
private long pauseOffset;
|
||||
private boolean running;
|
||||
private Button pauser;
|
||||
private Button resumer;
|
||||
private long elapsedMillis;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -40,21 +46,22 @@ public class JumbleActivity extends AppCompatActivity implements View.OnClickLis
|
|||
|
||||
|
||||
|
||||
score_dis = (TextView) findViewById(R.id.score);
|
||||
wordTv = (TextView) findViewById(R.id.wordTv);
|
||||
wordEnteredTv = (EditText) findViewById(R.id.wordEnteredTv);
|
||||
validate = (Button) findViewById(R.id.validate);
|
||||
validate.setOnClickListener(this);
|
||||
newGame = (Button) findViewById(R.id.newGame);
|
||||
pauser = findViewById(R.id.pause);
|
||||
resumer = findViewById(R.id.resume);
|
||||
timer = findViewById(R.id.time);
|
||||
score_dis = findViewById(R.id.score);
|
||||
wordTv = findViewById(R.id.wordTv);
|
||||
wordEnteredTv =findViewById(R.id.wordEnteredTv);
|
||||
validate = findViewById(R.id.validate);
|
||||
newGame = findViewById(R.id.newGame);
|
||||
newGame.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
reset();
|
||||
score_dis.setText("Score : " + score);
|
||||
newGame();
|
||||
}
|
||||
});
|
||||
|
||||
newGame();
|
||||
|
||||
|
||||
Button back = (Button) findViewById(R.id.back);
|
||||
|
||||
|
@ -65,22 +72,52 @@ public class JumbleActivity extends AppCompatActivity implements View.OnClickLis
|
|||
}
|
||||
});
|
||||
|
||||
validate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
validate();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == validate) {
|
||||
|
||||
validate();
|
||||
} else if (view == newGame) {
|
||||
score = 0;
|
||||
newGame();
|
||||
chronometer = findViewById(R.id.chronometer);
|
||||
chronometer.setFormat("Time: %s");
|
||||
chronometer.setBase(SystemClock.elapsedRealtime());
|
||||
newGame();
|
||||
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
|
||||
@Override
|
||||
public void onChronometerTick(Chronometer chronometer) {
|
||||
if (score == 15) {
|
||||
elapsedMillis = SystemClock.elapsedRealtime() - chronometer.getBase();
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(elapsedMillis);
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(elapsedMillis);
|
||||
timer.setText("time : " + minutes + ":" + seconds);
|
||||
|
||||
Intent intent = new Intent(JumbleActivity.this,QuickPlayMenu.class);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pauser.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pauseChronometer();
|
||||
}
|
||||
});
|
||||
|
||||
resumer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startChronometer();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void validate() {
|
||||
String w = wordEnteredTv.getText().toString();
|
||||
|
||||
|
@ -102,7 +139,7 @@ public class JumbleActivity extends AppCompatActivity implements View.OnClickLis
|
|||
String wordShuffled = Jumble.shuffleWord(wordToFind);
|
||||
wordTv.setText(wordShuffled);
|
||||
wordEnteredTv.setText("");
|
||||
|
||||
startChronometer();
|
||||
|
||||
|
||||
}
|
||||
|
@ -110,13 +147,39 @@ public class JumbleActivity extends AppCompatActivity implements View.OnClickLis
|
|||
|
||||
score = 0;
|
||||
newGame();
|
||||
resetChronometer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Chronometer;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/*******
|
||||
Created on: 21/01/2020
|
||||
|
@ -21,6 +23,10 @@ public class QuickPlayMenu extends AppCompatActivity {
|
|||
private Button tilematch;
|
||||
private Button game3;
|
||||
private Button game4;
|
||||
private Chronometer chronometer;
|
||||
private long pauseOffset;
|
||||
private boolean running;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -59,5 +65,12 @@ public class QuickPlayMenu extends AppCompatActivity {
|
|||
|
||||
|
||||
|
||||
}
|
||||
public void startChronometer(View v) {
|
||||
if (!running) {
|
||||
chronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
|
||||
chronometer.start();
|
||||
running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,14 +14,11 @@ import android.widget.RadioButton;
|
|||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -131,10 +128,8 @@ public class registration extends AppCompatActivity {
|
|||
});
|
||||
|
||||
|
||||
// get selected radio button from radioGroup
|
||||
int selectedId = radioSexGroup.getCheckedRadioButtonId();
|
||||
|
||||
//find the radiobutton by returned id
|
||||
int selectedId = radioSexGroup.getCheckedRadioButtonId();
|
||||
radioSexButton = findViewById(selectedId);
|
||||
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -1,12 +1,15 @@
|
|||
<RelativeLayout 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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_gradient2"
|
||||
tools:context=".MainActivity" >
|
||||
tools:context=".MainActivity"
|
||||
|
||||
>
|
||||
|
||||
<include layout="@layout/backbutton" />
|
||||
|
||||
<include layout="@layout/backbutton"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/wordTv"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -44,7 +47,8 @@
|
|||
android:layout_below="@id/validate"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="25dp"
|
||||
android:text="New Game" />
|
||||
android:text="New Game"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/score"
|
||||
|
@ -53,6 +57,43 @@
|
|||
android:layout_below="@+id/newGame"
|
||||
|
||||
android:textSize="50dp" />
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/score"
|
||||
android:textSize="50dp"
|
||||
/>
|
||||
|
||||
<Chronometer
|
||||
android:id="@+id/chronometer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginLeft="290dp"
|
||||
android:layout_marginTop="500dp"
|
||||
android:textSize="30sp"
|
||||
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/chronometer"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="-59dp"
|
||||
android:text = "pause"
|
||||
android:id="@+id/pause"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/resume"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/pause"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="-60dp"
|
||||
android:text="resume" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
|
@ -67,7 +67,9 @@
|
|||
android:visibility="visible"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
tools:visibility="visible" />
|
||||
tools:visibility="visible"
|
||||
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/game3"
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
tools:visibility="visible" />
|
||||
|
||||
|
||||
<include layout="@layout/backbutton"
|
||||
/>
|
||||
|
||||
<include layout="@layout/backbutton" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
|
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath 'com.android.tools.build:gradle:3.6.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Fri Jan 17 15:08:17 IST 2020
|
||||
#Sat Mar 21 17:07:16 IST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||
|
|
Loading…
Reference in New Issue