forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a simple Animal Quiz app (hacktoberfest17#832)
* added a new text file * added maths operations in java * Delete readme_doc.txt * made a new directory * Delete math_operations.java * A very basic Animal Quiz app
- Loading branch information
1 parent
91459db
commit 10678ba
Showing
55 changed files
with
1,019 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.0" | ||
defaultConfig { | ||
applicationId "com.example.anurag.animalquiz" | ||
minSdkVersion 20 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.1.0' | ||
compile 'com.android.support:design:25.1.0' | ||
compile 'com.android.support:support-v4:25.1.0' | ||
testCompile 'junit:junit:4.12' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Anurag\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
26 changes: 26 additions & 0 deletions
26
...lQuiz/app/src/androidTest/java/com/example/anurag/animalquiz/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.anurag.animalquiz; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.anurag.animalquiz", appContext.getPackageName()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...s/AnimalQuiz/app/src/androidTest/java/com/example/knightcube/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.knightcube; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.anurag.animalquiz", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.knightcube"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name="com.example.knightcube.MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
198 changes: 198 additions & 0 deletions
198
android_apps/AnimalQuiz/app/src/main/java/com/example/anurag/animalquiz/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package com.example.anurag.animalquiz; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.preference.PreferenceManager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Random; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
Button option1, option2, option3, option4, reset; | ||
TextView score; | ||
ImageView animalImage; | ||
private Handler handler; | ||
int copy; | ||
int points = 0; | ||
int animalImages[] = | ||
{ | ||
R.drawable.tame_animals_bird, | ||
R.drawable.tame_animals_cat, | ||
R.drawable.tame_animals_dolphin, | ||
R.drawable.tame_animals_fish, | ||
R.drawable.tame_animals_flappy_bird, | ||
R.drawable.tame_animals_goat, | ||
R.drawable.tame_animals_horse, | ||
R.drawable.tame_animals_peacock, | ||
R.drawable.tame_animals_rabbit, | ||
R.drawable.tame_animals_penguin, | ||
R.drawable.tame_animals_sheep, | ||
R.drawable.wild_animals_bear, | ||
R.drawable.wild_animals_crocodile, | ||
R.drawable.wild_animals_dog, | ||
R.drawable.wild_animals_eagle, | ||
R.drawable.wild_animals_elephant, | ||
R.drawable.wild_animals_fox, | ||
R.drawable.wild_animals_leopard, | ||
R.drawable.wild_animals_lion, | ||
R.drawable.wild_animals_mouse, | ||
R.drawable.wild_animals_pink_panther, | ||
R.drawable.wild_animals_shark, | ||
R.drawable.wild_animals_snake, | ||
R.drawable.wild_animals_tiger | ||
|
||
|
||
}; | ||
|
||
String animalNames[] = new String[] | ||
{ | ||
|
||
"Bird", | ||
"Cat", | ||
"Dolphin", | ||
"Fish", | ||
"Flappy_Bird", | ||
"Goat", | ||
"Horse", | ||
"Peacock", | ||
"Rabbit", | ||
"Penguin", | ||
"Sheep", | ||
"Bear", | ||
"Crocodile", | ||
"Dog", | ||
"Eagle", | ||
"Elephant", | ||
"Fox", | ||
"Leopard", | ||
"Lion", | ||
"Mouse", | ||
"Pink_Panther", | ||
"Shark", | ||
"Snake", | ||
"Tiger" | ||
|
||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
handler = new Handler(); | ||
option1 = (Button) findViewById(R.id.option1); | ||
option2 = (Button) findViewById(R.id.option2); | ||
option3 = (Button) findViewById(R.id.option3); | ||
option4 = (Button) findViewById(R.id.option4); | ||
reset = (Button) findViewById(R.id.reset); | ||
score = (TextView) findViewById(R.id.score); | ||
animalImage = (ImageView) findViewById(R.id.imageView); | ||
generateOptions(); | ||
reset.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
int points = 0; | ||
score.setText(Integer.toString(points)); | ||
generateOptions(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private void generateOptions() { | ||
|
||
int numberOfAnimals = animalImages.length; | ||
Random random = new Random(); | ||
int answer = random.nextInt(numberOfAnimals); | ||
copy = answer; | ||
animalImage.setImageResource(animalImages[answer]); | ||
ArrayList<String> answers = new ArrayList<String>(); | ||
answers.add(animalNames[answer]); | ||
|
||
int x = random.nextInt(numberOfAnimals); | ||
|
||
|
||
while (answers.size() < 4) { | ||
|
||
if (x != answer && !answers.contains(animalNames[x])) { | ||
answers.add(animalNames[x]); | ||
|
||
} | ||
|
||
x = random.nextInt(numberOfAnimals); | ||
} | ||
|
||
//Shuffle the answers | ||
Collections.shuffle(answers); | ||
option1.setText(answers.get(0).toString()); | ||
option2.setText(answers.get(1).toString()); | ||
option3.setText(answers.get(2).toString()); | ||
option4.setText(answers.get(3).toString()); | ||
|
||
answers.clear(); | ||
|
||
option1.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
||
verify(option1.getText().toString()); | ||
|
||
} | ||
}); | ||
|
||
option2.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
||
verify(option2.getText().toString()); | ||
} | ||
}); | ||
|
||
|
||
option3.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
||
verify(option3.getText().toString()); | ||
|
||
} | ||
}); | ||
|
||
|
||
option4.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
||
verify(option4.getText().toString()); | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
private void verify(String s) { | ||
if (s.compareTo(animalNames[copy].toString()) == 0) { | ||
Toast.makeText(getApplicationContext(), "Correct!!", Toast.LENGTH_SHORT).show(); | ||
points += 10; | ||
score.setText("Your Score: " + Integer.toString(points)); | ||
generateOptions(); | ||
} else { | ||
Toast.makeText(getApplicationContext(), "Wrong!!Try Again", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.