Skip to content

Commit

Permalink
update with comments
Browse files Browse the repository at this point in the history
added readme
  • Loading branch information
Vaek committed Apr 14, 2016
1 parent 6bc8394 commit 5b51f2b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ExamCodes
Example codes


## Unit

[Download APK here](https://github.com/Vaek/ExamCodes/blob/master/Unit/app-debug.apk)
Binary file added Unit/app-debug.apk
Binary file not shown.
58 changes: 53 additions & 5 deletions Unit/app/src/main/java/cz/vaek/unit/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package cz.vaek.unit;

import android.os.AsyncTask;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
* Exam code.
* <h1>Storyous exam code</h1>
*
* Find mistake :-D
* <p>Find mistake(s) :-D</p>
* <p>Checkout on Github:
* <a href="https://github.com/Vaek/ExamCodes/tree/master/Unit">here</a></p>
* <p>or Download app:
* <a href="https://github.com/Vaek/ExamCodes/raw/master/Unit/app-debug.apk">here</a></p>
*/
public class MainActivity extends AppCompatActivity {

Expand All @@ -27,19 +33,61 @@ public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
repaintCubeValue();
}

/**
* Call when click on button in layout.
* @param view Button in layout.
*/
public void cubeThrow(View view) {
mLastCubeValue += (int) (Math.random() * 6.1);
repaintCubeValue();
new CubeValueGenerator().execute();
}

/**
* Enable button to throw.
* @param enabled {@link Boolean#TRUE} if button is enabled, {@link Boolean#FALSE} otherwise.
*/
private void enableButton(boolean enabled) {
Button button = (Button) findViewById(R.id.button);
button.setEnabled(enabled);
}

/**
* Repaint value of cube in {@link TextView} with id {@link cz.vaek.unit.R.id#text}.
* @param mLastCubeValue Last value of cube.
*/
private void repaintCubeValue() {
TextView textView = (TextView) findViewById(R.id.text);
textView.setText(CUBE_VALUES[mLastCubeValue]);
}

private class CubeValueGenerator extends AsyncTask<Object, Object, Integer> {
@Override
protected void onPreExecute() {
super.onPreExecute();
enableButton(false);
}

@Override
protected Integer doInBackground(Object... params) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 6.1);
}

@Override
protected void onPostExecute(Integer cubeValue) {
super.onPostExecute(cubeValue);
mLastCubeValue += cubeValue;
repaintCubeValue();
enableButton(true);
}
}

}
4 changes: 3 additions & 1 deletion Unit/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true

com.android.build.gradle.overridePathCheck=true

0 comments on commit 5b51f2b

Please sign in to comment.