-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from AAkira/v1.4.3
V1.4.3
- Loading branch information
Showing
30 changed files
with
1,009 additions
and
55 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
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
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
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
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,36 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion COMPILE_SDK_VERSION as int | ||
buildToolsVersion BUILD_TOOLS_VERSION | ||
|
||
defaultConfig { | ||
minSdkVersion MIN_SDK_VERSION as int | ||
targetSdkVersion TARGET_SDK_VERSION as int | ||
versionCode VERSION_CODE as int | ||
versionName VERSION_NAME | ||
|
||
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':library') | ||
|
||
compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION" | ||
compile "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" | ||
androidTestCompile "com.android.support:support-annotations:$SUPPORT_APP_COMPAT_VERSION" | ||
androidTestCompile "com.android.support.test:runner:$SUPPORT_TEST_VERSION" | ||
androidTestCompile "com.android.support.test:rules:$SUPPORT_TEST_VERSION" | ||
androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION" | ||
} |
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 /Applications/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 *; | ||
#} |
107 changes: 107 additions & 0 deletions
107
...st/java/com/github/aakira/expandablelayout/uitest/ExpandableRelativeLayoutActivityTest.kt
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,107 @@ | ||
package com.github.aakira.expandablelayout.uitest | ||
|
||
import android.app.Activity | ||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.espresso.Espresso | ||
import android.support.test.espresso.Espresso.onView | ||
import android.support.test.espresso.assertion.ViewAssertions.matches | ||
import android.support.test.espresso.matcher.ViewMatchers.withId | ||
import android.support.test.runner.AndroidJUnit4 | ||
import android.test.ActivityInstrumentationTestCase2 | ||
import com.github.aakira.expandablelayout.ExpandableRelativeLayout | ||
import com.github.aakira.expandablelayout.uitest.utils.ElapsedIdLingResource | ||
import com.github.aakira.expandablelayout.uitest.utils.equalHeight | ||
import com.github.aakira.expandablelayout.uitest.utils.orMoreHeight | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.core.IsNull.notNullValue | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.hamcrest.CoreMatchers.`is` as _is | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ExpandableRelativeLayoutActivityTest : ActivityInstrumentationTestCase2<ExpandableRelativeLayoutActivity> | ||
(ExpandableRelativeLayoutActivity::class.java) { | ||
|
||
companion object { | ||
val DURATION = 500L | ||
} | ||
|
||
@Before | ||
@Throws(Exception::class) | ||
public override fun setUp() { | ||
super.setUp() | ||
injectInstrumentation(InstrumentationRegistry.getInstrumentation()) | ||
} | ||
|
||
@After | ||
@Throws(Exception::class) | ||
public override fun tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
@Test | ||
fun testExpandableRelativeLayout() { | ||
val activity = activity | ||
val instrumentation = instrumentation | ||
|
||
// check activity | ||
assertThat<Activity>(activity, notNullValue()) | ||
assertThat(instrumentation, notNullValue()) | ||
|
||
val expandableLayout = activity.findViewById(R.id.expandableLayout) as ExpandableRelativeLayout | ||
|
||
// default close | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(0))) | ||
|
||
// open toggle | ||
instrumentation.runOnMainSync { expandableLayout.toggle() } | ||
var idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
onView(withId(R.id.expandableLayout)).check(matches(orMoreHeight(1))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// move to first layout | ||
instrumentation.runOnMainSync { expandableLayout.moveChild(0) } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
onView(withId(R.id.child1)).check(matches(equalHeight(expandableLayout))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// set close height | ||
instrumentation.runOnMainSync { expandableLayout.closePosition = expandableLayout.currentPosition; } | ||
|
||
// move to second layout | ||
instrumentation.runOnMainSync { expandableLayout.moveChild(1) } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
// second.height != 0 && first.height + second.height == expandableLayout.height | ||
onView(withId(R.id.child2)).check(matches(orMoreHeight(1))) | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight( | ||
activity.findViewById(R.id.child1), | ||
activity.findViewById(R.id.child2) | ||
))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// check toggle (close to first) | ||
instrumentation.runOnMainSync { expandableLayout.toggle() } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
// move to first position | ||
onView(withId(R.id.child1)).check(matches(equalHeight(expandableLayout))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// check toggle open (full) | ||
instrumentation.runOnMainSync { expandableLayout.toggle() } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
// move to first position | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight( | ||
activity.findViewById(R.id.child1), | ||
activity.findViewById(R.id.child2), | ||
activity.findViewById(R.id.child3) | ||
))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...t/java/com/github/aakira/expandablelayout/uitest/ExpandableRelativeLayoutActivityTest2.kt
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,96 @@ | ||
package com.github.aakira.expandablelayout.uitest | ||
|
||
import android.app.Activity | ||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.espresso.Espresso | ||
import android.support.test.espresso.Espresso.onView | ||
import android.support.test.espresso.assertion.ViewAssertions.matches | ||
import android.support.test.espresso.matcher.ViewMatchers.withId | ||
import android.support.test.runner.AndroidJUnit4 | ||
import android.test.ActivityInstrumentationTestCase2 | ||
import com.github.aakira.expandablelayout.ExpandableRelativeLayout | ||
import com.github.aakira.expandablelayout.uitest.utils.ElapsedIdLingResource | ||
import com.github.aakira.expandablelayout.uitest.utils.equalHeight | ||
import com.github.aakira.expandablelayout.uitest.utils.equalWidth | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.core.IsNull.notNullValue | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.hamcrest.CoreMatchers.`is` as _is | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ExpandableRelativeLayoutActivityTest2 : ActivityInstrumentationTestCase2<ExpandableRelativeLayoutActivity2> | ||
(ExpandableRelativeLayoutActivity2::class.java) { | ||
|
||
companion object { | ||
val DURATION = 350L | ||
} | ||
|
||
@Before | ||
@Throws(Exception::class) | ||
public override fun setUp() { | ||
super.setUp() | ||
injectInstrumentation(InstrumentationRegistry.getInstrumentation()) | ||
} | ||
|
||
@After | ||
@Throws(Exception::class) | ||
public override fun tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
@Test | ||
fun testExpandableRelativeLayout2() { | ||
val activity = activity | ||
val instrumentation = instrumentation | ||
val resources = activity.resources | ||
|
||
// check activity | ||
assertThat<Activity>(activity, notNullValue()) | ||
assertThat(instrumentation, notNullValue()) | ||
|
||
val expandableLayout = activity.findViewById(R.id.expandableLayout) as ExpandableRelativeLayout | ||
val expandableLayoutPadding = resources.getDimensionPixelSize(R.dimen.margin_large) | ||
|
||
// default close | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(0))) | ||
// width | ||
onView(withId(R.id.child1)).check(matches( | ||
equalWidth(resources.getDimensionPixelSize(R.dimen.relative_layout_2_child_1_width)))) | ||
onView(withId(R.id.child2)).check(matches( | ||
equalWidth(resources.getDimensionPixelSize(R.dimen.relative_layout_2_child_2_width)))) | ||
|
||
// open toggle | ||
instrumentation.runOnMainSync { expandableLayout.toggle() } | ||
var idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight( | ||
activity.findViewById(R.id.child1), | ||
activity.findViewById(R.id.child3), | ||
margin = expandableLayoutPadding | ||
))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// move to first layout | ||
instrumentation.runOnMainSync { expandableLayout.moveChild(0) } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight( | ||
activity.findViewById(R.id.child1), | ||
margin = expandableLayoutPadding | ||
))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
|
||
// move to second layout | ||
instrumentation.runOnMainSync { expandableLayout.moveChild(1) } | ||
idlingResource = ElapsedIdLingResource(DURATION) | ||
Espresso.registerIdlingResources(idlingResource) | ||
onView(withId(R.id.expandableLayout)).check(matches(equalHeight( | ||
activity.findViewById(R.id.child2), | ||
margin = expandableLayoutPadding | ||
))) | ||
Espresso.unregisterIdlingResources(idlingResource) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...i-test/src/androidTest/java/com/github/aakira/expandablelayout/uitest/utils/ContextExt.kt
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,11 @@ | ||
package com.github.aakira.expandablelayout.uitest.utils | ||
|
||
import android.content.Context | ||
import android.util.DisplayMetrics | ||
import android.view.WindowManager | ||
|
||
fun Context.getDisplayMetrics(): DisplayMetrics { | ||
val metrics = DisplayMetrics() | ||
(getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(metrics) | ||
return metrics | ||
} |
38 changes: 38 additions & 0 deletions
38
...droidTest/java/com/github/aakira/expandablelayout/uitest/utils/ElapsedIdLingResource.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,38 @@ | ||
package com.github.aakira.expandablelayout.uitest.utils; | ||
|
||
import android.support.test.espresso.IdlingResource; | ||
|
||
/** | ||
* Referenced from stack over flow. | ||
* http://stackoverflow.com/questions/30155227/espresso-how-to-wait-for-some-time1-hour | ||
*/ | ||
public class ElapsedIdLingResource implements IdlingResource { | ||
private final long startTime; | ||
private final long waitingTime; | ||
private ResourceCallback resourceCallback; | ||
|
||
public ElapsedIdLingResource(long waitingTime) { | ||
this.startTime = System.currentTimeMillis(); | ||
this.waitingTime = waitingTime; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return ElapsedIdLingResource.class.getName() + ":" + waitingTime; | ||
} | ||
|
||
@Override | ||
public boolean isIdleNow() { | ||
long elapsed = System.currentTimeMillis() - startTime; | ||
boolean idle = (elapsed >= waitingTime); | ||
if (idle) { | ||
resourceCallback.onTransitionToIdle(); | ||
} | ||
return idle; | ||
} | ||
|
||
@Override | ||
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { | ||
this.resourceCallback = resourceCallback; | ||
} | ||
} |
Oops, something went wrong.