-
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.
- Loading branch information
0 parents
commit 66ef3a7
Showing
31 changed files
with
1,061 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,16 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
|
||
# IntelliJ Idea project files | ||
.idea | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.war | ||
*.jar |
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.macbook.androidapp" | ||
minSdkVersion 21 | ||
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.3.1' | ||
compile 'com.github.billthefarmer:mididriver:v1.14' | ||
compile 'com.android.support:design:25.3.1' | ||
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 /Users/macbook/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
app/src/androidTest/java/com/example/macbook/androidapp/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.macbook.androidapp; | ||
|
||
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.macbook.androidapp", 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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.macbook.androidapp"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".TaskSelectActivity"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
169 changes: 169 additions & 0 deletions
169
app/src/main/java/com/example/macbook/androidapp/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,169 @@ | ||
package com.example.macbook.androidapp; | ||
|
||
import android.graphics.drawable.AnimationDrawable; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { | ||
|
||
private MidiSupport midiSupport; | ||
private StatisticsStorage statisticsStorage; | ||
private Drawable buttonDefaultBackground; | ||
private boolean isStarted = false; | ||
private HashMap<String, Button> noteButtons; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
Spinner spinner = (Spinner) findViewById(R.id.spinner); | ||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, | ||
R.array.task_list, android.R.layout.simple_spinner_item); | ||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
spinner.setAdapter(adapter); | ||
noteButtons = buildNoteButtonsMap(); | ||
Button button = (Button) findViewById(R.id.buttonC); | ||
buttonDefaultBackground = button.getBackground().getCurrent(); | ||
spinner.setOnItemSelectedListener(this); | ||
} | ||
|
||
private HashMap<String, Button> buildNoteButtonsMap() { | ||
HashMap<String, Button> noteButtons = new HashMap<>(); | ||
noteButtons.put("C", (Button) findViewById(R.id.buttonC)); | ||
noteButtons.put("D", (Button) findViewById(R.id.buttonD)); | ||
noteButtons.put("E", (Button) findViewById(R.id.buttonE)); | ||
noteButtons.put("F", (Button) findViewById(R.id.buttonF)); | ||
noteButtons.put("G", (Button) findViewById(R.id.buttonG)); | ||
noteButtons.put("A", (Button) findViewById(R.id.buttonA)); | ||
noteButtons.put("B", (Button) findViewById(R.id.buttonB)); | ||
noteButtons.put("C2", (Button) findViewById(R.id.buttonC2)); | ||
return noteButtons; | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
getMidiSupport().start(); | ||
Log.i("MainActivity", "!!!!!!!!!!!!! Resume"); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
Log.i("MainActivity", "!!!!!!!!!!!!! Start"); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
getMidiSupport().stopPlayingAsync(); | ||
getMidiSupport().stop(); | ||
Log.i("MainActivity", "!!!!!!!!!!!!! Pause"); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
Log.i("MainActivity", "!!!!!!!!!!!!! Stop"); | ||
} | ||
|
||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { | ||
Spinner spinner = (Spinner) findViewById(R.id.spinner); | ||
String taskText = spinner.getSelectedItem().toString(); | ||
for(String note : noteButtons.keySet()) { | ||
noteButtons.get(note).setEnabled(false); | ||
} | ||
for (String note : taskText.split(" ")) { | ||
noteButtons.get(note).setEnabled(true); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> parent) { | ||
} | ||
|
||
public void onStartClick(View view) { | ||
Button button = (Button) findViewById(R.id.buttonStart); | ||
if (isStarted) { | ||
getMidiSupport().stopPlayingAsync(); | ||
isStarted = false; | ||
button.setText("Start"); | ||
return; | ||
} | ||
isStarted = true; | ||
button.setText("Stop"); | ||
Spinner spinner = (Spinner) findViewById(R.id.spinner); | ||
String taskText = spinner.getSelectedItem().toString(); | ||
List<NotesEnum> melody = new ArrayList<>(); | ||
for (String note : taskText.split(" ")) { | ||
melody.add(NotesEnum.valueOf(note)); | ||
} | ||
statisticsStorage = new StatisticsStorage(); | ||
getMidiSupport().playNotesInRandomOrder(melody); | ||
} | ||
|
||
public void onNoteClick(View view) { | ||
Button button = (Button) view; | ||
String text = button.getText().toString(); | ||
TextView textView = (TextView) findViewById(R.id.answerResult); | ||
if (getMidiSupport().getCurrentNote() == null) { | ||
return; | ||
} | ||
int color; | ||
if (text.equals(getMidiSupport().getCurrentNote().getName())) { | ||
color = ContextCompat.getColor(this, R.color.green); | ||
} else { | ||
color = ContextCompat.getColor(this, R.color.red); | ||
} | ||
statisticsStorage.submitAnswer( | ||
getMidiSupport().getCurrentNoteNumber(), | ||
getMidiSupport().getCurrentNote(), | ||
NotesEnum.valueOf(text)); | ||
textView.setText("Correct " + statisticsStorage.getCorrectCount() + | ||
" Wrong " + statisticsStorage.getWrongCount() + | ||
" Missed " + statisticsStorage.getMissedCount()); | ||
AnimationDrawable drawable = buildAnimationDrawable(color); | ||
button.setBackground(drawable); | ||
drawable.start(); | ||
Log.i(Integer.toString(getMidiSupport().getCurrentNoteNumber()), "Pressed"); | ||
} | ||
|
||
public void onMissedAnswer(int noteNumber) { | ||
statisticsStorage.submitAnswer( | ||
noteNumber, | ||
getMidiSupport().getCurrentNote(), | ||
null); | ||
TextView textView = (TextView) findViewById(R.id.answerResult); | ||
textView.setText("Correct " + statisticsStorage.getCorrectCount() + | ||
" Wrong " + statisticsStorage.getWrongCount() + | ||
" Missed " + statisticsStorage.getMissedCount()); | ||
Log.i(Integer.toString(getMidiSupport().getCurrentNoteNumber()), "Missed"); | ||
} | ||
|
||
private AnimationDrawable buildAnimationDrawable(int color) { | ||
AnimationDrawable drawable = new AnimationDrawable(); | ||
drawable.addFrame(new ColorDrawable(color), 150); | ||
drawable.addFrame(buttonDefaultBackground, 150); | ||
drawable.setOneShot(true); | ||
return drawable; | ||
} | ||
|
||
private MidiSupport getMidiSupport() { | ||
if (midiSupport == null) { | ||
midiSupport = new MidiSupport(this); | ||
} | ||
return midiSupport; | ||
} | ||
} |
Oops, something went wrong.