Skip to content

Commit

Permalink
Merge pull request #67 from AAkira/v1.5.0
Browse files Browse the repository at this point in the history
V1.5.0
  • Loading branch information
AAkira committed Apr 7, 2016
2 parents c25cca9 + a93e550 commit 9f379cb
Show file tree
Hide file tree
Showing 35 changed files with 2,226 additions and 179 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ You can include optional contents and use everywhere.
### Example

![ExampleRecyclerView][ExampleRecyclerView] ![ExampleSearch][ExampleSearch]
![ExampleReadMore][ExampleReadMore]

## Usage

### ExpandableRelativeLayout

#### Usage

The expandableRelativeLayout doesn't work if child views change a size.
You should use the ExpandableLinearLayout if there is a possibility.

#### Code

```java
ExpandableRelativeLayout expandLayout
ExpandableRelativeLayout expandableLayout
= (ExpandableRelativeLayout) findViewById(R.id.expandableLayout);

// toggle expand, collapse
Expand Down Expand Up @@ -73,14 +79,37 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
```

### ExpandableLinearLayout

#### Usage

You should use the ExpandableLinearLayout if child views may change a size.
For example, it gets and sets values from a server.

#### Code

```java
ExpandableLinearLayout expandableLayout
= (ExpandableLinearLayout) findViewById(R.id.expandableLayout);

child.setText("Sets text from a server");
expandableLayout.initLayout(true); // Recalculate size of children
```

The `initLayout()` is deprecated in v1.5.0.
The argument of `isMaintain` flag doesn't work.
I'll fix it in [v1.5.1](https://github.com/AAkira/ExpandableLayout/issues/66)

### ExpandableWeightLayout

#### Usage

You should use this layout if you want to use weight attributes at expandable layout.

#### Code

```java
ExpandableWeightLayout expandLayout
ExpandableWeightLayout expandableLayout
= (ExpandableWeightLayout) findViewById(R.id.expandableLayout);

// toggle expand, collapse
Expand Down Expand Up @@ -230,7 +259,7 @@ buildscript {
}
dependencies {
compile 'com.github.aakira:expandable-layout:1.4.3@aar'
compile 'com.github.aakira:expandable-layout:1.5.0@aar'
}
```

Expand Down Expand Up @@ -269,3 +298,4 @@ limitations under the License.
[ExpandableWeightLayout]: /art/ExpandableWeightLayout.gif
[ExampleSearch]: /art/ExampleSearch.gif
[ExampleRecyclerView]: /art/ExampleRecyclerview_v1.1.gif
[ExampleReadMore]: /art/ExampleReadMore.gif
Binary file added art/ExampleReadMore.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=22.0.1
MIN_SDK_VERSION=11
TARGET_SDK_VERSION=23
VERSION_CODE=8
VERSION_NAME=1.4.3
VERSION_CODE=9
VERSION_NAME=1.5.0
SUPPORT_TEST_VERSION=0.4.1
HAMCREST_VERSION=1.3
ESPRESSO_VERSION=2.2.1
KOTLIN_VERSION=1.0.0

SUPPORT_APP_COMPAT_VERSION=23.0.1
SUPPORT_APP_COMPAT_VERSION=23.2.1

GROUP=com.github.aakira
ARTIFACT_ID=expandable-layout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
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 android.widget.TextView
import com.github.aakira.expandablelayout.ExpandableLinearLayout
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 ExpandableLinearLayoutActivityTest : ActivityInstrumentationTestCase2<ExpandableLinearLayoutActivity>
(ExpandableLinearLayoutActivity::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 ExpandableLinearLayout
val child1 = activity.findViewById(R.id.child1) as TextView
val child2 = activity.findViewById(R.id.child2) as TextView
val child3 = activity.findViewById(R.id.child3) as TextView
val marginSmall = getActivity().resources.getDimensionPixelSize(R.dimen.margin_small)

// 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.expandableLayout)).check(matches(equalHeight(
child1,
margin = marginSmall
)))
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(
child1,
child2,
margin = marginSmall
)))
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.expandableLayout)).check(matches(equalHeight(
child1,
margin = marginSmall
)))
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(
child1,
child2,
child3,
margin = marginSmall
)))
Espresso.unregisterIdlingResources(idlingResource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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 android.widget.RelativeLayout
import android.widget.TextView
import com.github.aakira.expandablelayout.ExpandableLinearLayout
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 ExpandableLinearLayoutActivityTest2 : ActivityInstrumentationTestCase2<ExpandableLinearLayoutActivity2>
(ExpandableLinearLayoutActivity2::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 ExpandableLinearLayout
val child1 = activity.findViewById(R.id.child1) as TextView
val child2 = activity.findViewById(R.id.child2) as RelativeLayout
val child3 = activity.findViewById(R.id.child3) as TextView
val child4 = activity.findViewById(R.id.child4) as TextView
val marginSmall = getActivity().resources.getDimensionPixelSize(R.dimen.margin_small)

// 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.expandableLayout)).check(matches(equalHeight(
child1,
margin = marginSmall
)))
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)
onView(withId(R.id.child2)).check(matches(orMoreHeight(1)))
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
child1,
child2,
margin = marginSmall
)))
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.expandableLayout)).check(matches(equalHeight(
child1,
margin = marginSmall
)))
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(
child1,
child2,
child3,
child4,
margin = marginSmall
)))
Espresso.unregisterIdlingResources(idlingResource)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 android.widget.TextView
import com.github.aakira.expandablelayout.ExpandableRelativeLayout
import com.github.aakira.expandablelayout.uitest.utils.ElapsedIdLingResource
import com.github.aakira.expandablelayout.uitest.utils.equalHeight
Expand Down Expand Up @@ -51,6 +52,9 @@ class ExpandableRelativeLayoutActivityTest : ActivityInstrumentationTestCase2<Ex
assertThat(instrumentation, notNullValue())

val expandableLayout = activity.findViewById(R.id.expandableLayout) as ExpandableRelativeLayout
val child1 = activity.findViewById(R.id.child1) as TextView
val child2 = activity.findViewById(R.id.child2) as TextView
val child3 = activity.findViewById(R.id.child3) as TextView

// default close
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(0)))
Expand All @@ -76,11 +80,10 @@ class ExpandableRelativeLayoutActivityTest : ActivityInstrumentationTestCase2<Ex
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)
child1,
child2
)))
Espresso.unregisterIdlingResources(idlingResource)

Expand All @@ -98,9 +101,9 @@ class ExpandableRelativeLayoutActivityTest : ActivityInstrumentationTestCase2<Ex
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)
child1,
child2,
child3
)))
Espresso.unregisterIdlingResources(idlingResource)
}
Expand Down
Loading

0 comments on commit 9f379cb

Please sign in to comment.