Skip to content

Commit

Permalink
Merge release 1.4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgomezrico committed Aug 8, 2017
2 parents 5de6e71 + 62977ec commit 2a37142
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 96 deletions.
24 changes: 11 additions & 13 deletions app/build.gradle
Expand Up @@ -7,8 +7,8 @@ apply plugin: 'spoon'
apply from: '../jacoco.gradle'

def appId = "com.makingiants.android.banjotuner"
def appVersionName = "1.4.8"
def appVersionCode = 107
def appVersionName = "1.4.9"
def appVersionCode = 108

android {
compileSdkVersion setup.targetSdk
Expand All @@ -21,12 +21,12 @@ android {
versionCode appVersionCode
versionName appVersionName

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

// Enable just English configs for dependencies, allowing to shrink apk size more
resConfigs "en", "pt"

resValue "string", "ads_unit_id_banner", "$BANJEN_ADS_UNIT_ID_BANNER"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -44,11 +44,9 @@ android {

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

aaptOptions {
// All images are already optimized so we can avoid this
cruncherEnabled = false
packagingOptions {
exclude 'META-INF/services/org.xmlpull.v1.XmlPullParserFactory'
}
}
}

Expand All @@ -68,12 +66,12 @@ dependencies {
testCompile "org.jetbrains.kotlin:kotlin-stdlib:$deps.kotlin"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$deps.kotlin"

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', excludeAnnotations)
androidTestCompile('com.android.support.test:runner:0.5', excludeAnnotations)
androidTestCompile('com.android.support.test:rules:0.5', excludeAnnotations)
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0', excludeAnnotations
androidTestCompile 'com.android.support.test:runner:1.0.0', excludeAnnotations
androidTestCompile 'com.android.support.test:rules:1.0.0', excludeAnnotations

androidTestCompile 'com.squareup.spoon:spoon-client:1.7.1'
androidTestCompile('com.jraska:falcon-spoon-compat:1.0.4') {
androidTestCompile 'com.jraska:falcon-spoon-compat:1.0.4', {
exclude group: 'com.squareup.spoon', module: 'spoon-client'
}
}
Expand Down
@@ -1,37 +1,33 @@
package com.makingiants.android.banjotuner

import android.support.test.filters.MediumTest
import android.support.test.filters.LargeTest
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@MediumTest
@LargeTest
@RunWith(AndroidJUnit4::class)
class EarActivityTest {

@Rule @JvmField
var mActivityRule: ActivityTestRule<EarActivity> = ActivityTestRule(EarActivity::class.java)
var activityRule: ActivityTestRule<EarActivity> = ActivityTestRule(EarActivity::class.java)

fun test_isPlaying(index: Int) {
withEarRobot(mActivityRule.activity) {
click(index)
}.isPlaying()
}
fun test_isPlaying(index: Int) = withEarRobot(activityRule.activity) {
click(index)
}.checkIsPlaying()

fun test_stopsPlaying(index: Int) {
withEarRobot(mActivityRule.activity) {
click(index)
click(index)
}.isNotPlaying()
}
fun test_stopsPlaying(index: Int) = withEarRobot(activityRule.activity) {
click(index)
click(index)
}.checkIsNotPlaying()

@Test
fun test_onClick_ifUnselected_playSound() = (1..4).forEach {
test_isPlaying(it)
}

@Test
fun test_onClick_ifSelected_stopSound() = (1..4).forEach {
test_stopsPlaying(it)
Expand Down
Expand Up @@ -14,21 +14,26 @@ import org.junit.Assert.assertTrue

class EarRobot(val activity: Activity) {

val audioService = activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val audioService by lazy { activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager }

init {
// animations that repeat forever break espresso
(activity as EarActivity).clickAnimation.repeatCount = 0
}

fun click(buttonIndex: Int) {
FalconSpoon.screenshot(activity, "before-click-$buttonIndex")
onView(withText(Matchers.startsWith("$buttonIndex"))).perform(ViewActions.click())
FalconSpoon.screenshot(activity, "after-click-$buttonIndex")
}

fun isPlaying() {
fun checkIsPlaying() {
FalconSpoon.screenshot(activity, "isPLaying")
assertTrue(audioService.isMusicActive)
}

fun isNotPlaying() {
FalconSpoon.screenshot(activity, "isNotPlaying")
fun checkIsNotPlaying() {
FalconSpoon.screenshot(activity, "checkIsNotPlaying")
assertFalse(audioService.isMusicActive)
}

Expand Down
72 changes: 51 additions & 21 deletions app/src/main/java/com/makingiants/android/banjotuner/EarActivity.kt
@@ -1,9 +1,14 @@
package com.makingiants.android.banjotuner

import android.os.Bundle
import android.support.annotation.VisibleForTesting
import android.support.v4.view.ViewCompat
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Button
import android.widget.ToggleButton
import com.crashlytics.android.Crashlytics
import com.google.android.gms.ads.AdRequest
Expand All @@ -13,16 +18,39 @@ import kotlinx.android.synthetic.main.activity_ear_ads.*
import java.io.IOException

class EarActivity : AppCompatActivity(), View.OnClickListener {

private val player by lazy { SoundPlayer(this) }
private val firebaseAnalytics by lazy { FirebaseAnalytics.getInstance(this) }
private val elevationPixels by lazy {
resources.getDimensionPixelSize(R.dimen.spacing_4dp).toFloat()
}

@VisibleForTesting
internal val clickAnimation: Animation by lazy {
AnimationUtils.loadAnimation(this, R.anim.shake_animation)
}

//<editor-fold desc="Activity Overrides">
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Fabric.with(this, Crashlytics())
firebaseAnalytics.logEvent("screenview", Bundle().apply { putString("name", "ear") })
setContentView(R.layout.activity_ear_ads)

soundsRadioGroup.setOnCheckedChangeListener { radioGroup, i ->
(0 until radioGroup.childCount)
.map { radioGroup.getChildAt(it) as ToggleButton }
.forEach {
val shouldCheck = it.id == i

it.isChecked = shouldCheck
handleAnimation(it, shouldCheck)
}
}

arrayOf(ear1Button, ear2Button, ear3Button, ear4Button).forEach {
it.setOnClickListener(this)
}

val adRequest: AdRequest
if (BuildConfig.DEBUG) {
adRequest = AdRequest.Builder()
Expand All @@ -33,16 +61,6 @@ class EarActivity : AppCompatActivity(), View.OnClickListener {
adRequest = AdRequest.Builder().build()
}
adsView.loadAd(adRequest)

soundsRadioGroup.setOnCheckedChangeListener { radioGroup, i ->
(0 until radioGroup.childCount)
.map { radioGroup.getChildAt(it) as ToggleButton }
.forEach { it.isChecked = it.id == i }
}

arrayOf(ear1Button, ear2Button, ear3Button, ear4Button).forEach {
it.setOnClickListener(this)
}
}

override fun onPause() {
Expand All @@ -52,19 +70,31 @@ class EarActivity : AppCompatActivity(), View.OnClickListener {
}

override fun onClick(view: View?) {
val button = view as ToggleButton
soundsRadioGroup.check(button.id)
firebaseAnalytics.logEvent("click", Bundle().apply { putString("id", "$button.id") })
(view as? ToggleButton)?.let { button ->
firebaseAnalytics.logEvent("click", Bundle().apply { putString("id", "$button.id") })
soundsRadioGroup.check(button.id)
handleAnimation(button, button.isChecked)

if (button.isChecked) {
val buttonTag = Integer.parseInt(button.tag.toString())
try {
player.playWithLoop(buttonTag)
} catch (e: IOException) {
Log.e("EarActivity", "Playing sound", e)
if (button.isChecked) {
val buttonTag = Integer.parseInt(button.tag.toString())
try {
player.playWithLoop(buttonTag)
} catch (e: IOException) {
Log.e("EarActivity", "Playing sound", e)
}
} else {
player.stop()
}
}
}

fun handleAnimation(button: Button, shouldShow: Boolean = false) {
if (shouldShow) {
ViewCompat.setElevation(button, elevationPixels)
button.startAnimation(clickAnimation)
} else {
player.stop()
ViewCompat.setElevation(button, 0f)
button.clearAnimation()
}
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/anim/shake_animation.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromDegrees="-3"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="3" />
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/button.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/banjen_accent" android:state_checked="true" />
<item android:drawable="@color/banjen_background" android:state_checked="false" />

</selector>
27 changes: 13 additions & 14 deletions app/src/main/res/layout/activity_ear_ads.xml
Expand Up @@ -10,56 +10,55 @@
android:id="@+id/soundsRadioGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:orientation="vertical">

<ToggleButton
android:id="@+id/ear4Button"
style="@style/EarButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="3"
android:textOff="@string/ear_button_4_text"
android:textOn="@string/ear_button_4_text" />
android:textOn="@string/ear_button_4_text"
style="@style/EarButton" />

<ToggleButton
android:id="@+id/ear3Button"
style="@style/EarButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="2"
android:textOff="@string/ear_button_3_text"
android:textOn="@string/ear_button_3_text" />
android:textOn="@string/ear_button_3_text"
style="@style/EarButton" />

<ToggleButton
android:id="@+id/ear2Button"
style="@style/EarButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="1"
android:textOff="@string/ear_button_2_text"
android:textOn="@string/ear_button_2_text" />
android:textOn="@string/ear_button_2_text"
style="@style/EarButton" />

<ToggleButton
android:id="@+id/ear1Button"
style="@style/EarButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="0"
android:textOff="@string/ear_button_1_text"
android:textOn="@string/ear_button_1_text" />
android:textOn="@string/ear_button_1_text"
style="@style/EarButton" />

</RadioGroup>

<com.google.android.gms.ads.AdView
android:id="@+id/adsView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="top"
ads:adSize="BANNER"
ads:adUnitId="@string/ads_unit_id_banner" />

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/layout/empty_relative_layout.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/values/colors.xml
Expand Up @@ -2,6 +2,7 @@
<resources>
<color name="banjen_primary">@color/primary_material_dark</color>
<color name="banjen_primary_dark">@color/primary_dark_material_dark</color>
<color name="banjen_accent">#ffa38251</color>
<color name="banjen_accent">#6d94a1</color>
<color name="banjen_background">@color/banjen_primary</color>
<color name="banjen_gray">#666666</color>
</resources>
5 changes: 1 addition & 4 deletions app/src/main/res/values/dimens.xml
@@ -1,8 +1,5 @@
<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="ear_horizontal_margin">16dp</dimen>
<dimen name="ear_vertical_margin">8dp</dimen>
<dimen name="ear_button_height">90dp</dimen>
<dimen name="spacing_4dp">4dp</dimen>

</resources>

0 comments on commit 2a37142

Please sign in to comment.