Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #2

Merged
merged 23 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ce30eaf
codebase for prototype with simple example
oleg-vasiliev Feb 8, 2017
5f456ff
Update README.md
oleg-vasiliev Feb 8, 2017
22a0e32
thinking about code design and possibility of changing slider vertica…
oleg-vasiliev Feb 23, 2017
e303948
code redesign
oleg-vasiliev Mar 6, 2017
af4ae16
redesign finished
oleg-vasiliev Mar 6, 2017
8d69bd5
build tools and gradle version updated
oleg-vasiliev Mar 6, 2017
0304a9c
Merge branch 'development' into fragmentation_to_parts
oleg-vasiliev Mar 6, 2017
53fcd1a
trying to insert listview to card body
oleg-vasiliev Mar 13, 2017
daae27c
listview card implemented
oleg-vasiliev Mar 16, 2017
bf3631e
working on example
oleg-vasiliev Mar 17, 2017
9dcacb3
implemented background image caching
oleg-vasiliev Mar 27, 2017
70e1362
code clean. example implemented.
oleg-vasiliev Mar 31, 2017
3daf1f7
Working on simple example & documentation.
oleg-vasiliev Apr 4, 2017
3ac830d
Fixed bug with nullable resource id in library. Removed bitmap drawab…
oleg-vasiliev Apr 5, 2017
195dffd
Examples updated.
oleg-vasiliev Apr 5, 2017
5d639ff
Minor API changes. Readme added.
oleg-vasiliev Apr 7, 2017
53cfd98
Readme adjustments. Module versions updated.
oleg-vasiliev Apr 7, 2017
990c9a8
Update README.md
RamotionRussell Apr 7, 2017
cbbc89d
Some javadoc explanations added to classes.
oleg-vasiliev Apr 10, 2017
329b388
More javadocs added.
oleg-vasiliev Apr 11, 2017
73a311e
Add files via upload
Juriv Apr 14, 2017
a631d7c
Update README.md
Juriv Apr 14, 2017
9e7a049
Update README.md
Juriv Apr 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor API changes. Readme added.
  • Loading branch information
oleg-vasiliev committed Apr 7, 2017
commit 5d639ff4ec7c847add00274afe2fc1cb15580433
220 changes: 215 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,223 @@
# ExpandingCollection for Android

## Licence
Expanding Collection is released under the MIT license.
See [LICENSE](./LICENSE.md) for details.
## About
The project maintained by [app development agency](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell-android) [Ramotion Inc.](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell-android)
See our other [open-source projects](https://github.com/ramotion) or [hire](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell-android) us to design, develop, and grow your product.
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=https://github.com/ramotion/foolding-cell-android)
[![Twitter Follow](https://img.shields.io/twitter/follow/ramotion.svg?style=social)](https://twitter.com/ramotion)

## Requirements
- Android 4.0 IceCreamSandwich (API lvl 14) or greater
- Your favorite IDE

## Installation
Just download the package from [here](http://central.maven.org/maven2/com/ramotion/foldingcell/folding-cell/1.1.0/folding-cell-1.1.0.aar) and add it to your project classpath, or just use the maven repo:

Gradle:
```groovy
'com.ramotion.expandingcollection:expanding-collection:0.9.0'
```
SBT:
```scala
libraryDependencies += "com.ramotion.expandingcollection" % "expanding-collection" % "0.9.0"
```
Maven:
```xml
<dependency>
<groupId>com.ramotion.expandingcollection</groupId>
<artifactId>expanding-collection</artifactId>
<version>0.9.0</version>
</dependency>
```

## Basic usage
1. Add background switcher `ECBackgroundSwitcherView` and main pager `ECPagerView` to your layout. `ECPagerView` always should have `match_parent` width and `wrap_content` height. Vertical position you can adjust by yourself using **alignment/gravity** or **top margin**. `ECBackgroundSwitcherView` it's just dynamic background switcher, so you probably want it to be as big as his parent.

```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.ramotion.expandingcollection.ECBackgroundSwitcherView
android:id="@+id/ec_bg_switcher_element"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.ramotion.expandingcollection.ECPagerView
android:id="@+id/ec_pager_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>

</RelativeLayout>
```

2. Tune `ECPagerView`: setup size of card in collapsed state and height of header in expanded state.

```xml
<com.ramotion.expandingcollection.ECPagerView xmlns:ec="http://schemas.android.com/apk/res-auto"
android:id="@+id/ec_pager_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ec:cardHeaderHeightExpanded="150dp"
ec:cardHeight="200dp"
ec:cardWidth="250dp" />
```

3. Expanded card contains two parts : header part with background(initially visible when card is collapsed) and a ListView element as content(visible only when card is expanded), so you need a xml layout for list items.

```xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_text"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@color/colorPrimary"
android:textAlignment="center" />

</FrameLayout>
```

4. Also you need to implement a custom list adapter for list items by extending parametrized `com.ramotion.expandingcollection.ECCardContentListItemAdapter.java` class, where `T` is type of datasource object for list items inside card, in example bellow `T` is just a string object. It's pretty straightforward implementation with common view holder pattern.

```java
public class CardListItemAdapter extends ECCardContentListItemAdapter<String> {

public CardListItemAdapter(@NonNull Context context, @NonNull List<String> objects) {
super(context, R.layout.list_item, objects);
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
ViewHolder viewHolder;
View rowView = convertView;

if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
rowView = inflater.inflate(R.layout.list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemText = (TextView) rowView.findViewById(R.id.list_item_text);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) rowView.getTag();
}

String item = getItem(position);
if (item != null) {
viewHolder.itemText.setText(item);
}
return rowView;
}

static class ViewHolder {
TextView itemText;
}

}
```
5. Your data class must implement `com.ramotion.expandingcollection.ECCardData.java` interface where `T` is type of datasource object for list items inside card.

```java
public class CardDataImpl implements ECCardData<String> {

private String cardTitle;
private Integer mainBackgroundResource;
private Integer headBackgroundResource;
private List<String> listItems;

@Override
public Integer getMainBackgroundResource() {
return mainBackgroundResource;
}

@Override
public Integer getHeadBackgroundResource() {
return headBackgroundResource;
}

@Override
public List<String> getListItems() {
return listItems;
}
}
```

6. Almost done! Last thing we need is provide our dataset to pager element through a pager adapter. It's just a implementation of abstract class `com.ramotion.expandingcollection.ECPagerViewAdapter.java` with one abstract method, so it can be easily implemented inside your activity.

```java
public class MainActivity extends Activity {

private ECPagerView ecPagerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Get pager from layout
ecPagerView = (ECPagerView) findViewById(R.id.ec_pager_element);

// Generate example dataset
List<ECCardData> dataset = CardDataImpl.generateExampleData();

// Implement and pager adapter and set it to pager view
ecPagerView.setPagerViewAdapter(new ECPagerViewAdapter(getApplicationContext(), dataset) {
@Override
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ListView list, ECCardData data) {
// Data object for current card
CardDataImpl cardData = (CardDataImpl) data;

// Set adapter and items to current card content list
list.setAdapter(new CardListItemAdapter(getApplicationContext(), cardData.getListItems()));
// Also some visual tuning can be done here
list.setBackgroundColor(Color.WHITE);

// Here we can create elements for head view or inflate layout from xml using inflater service
TextView cardTitle = new TextView(getApplicationContext());
cardTitle.setText(cardData.getCardTitle());
cardTitle.setTextSize(COMPLEX_UNIT_DIP, 20);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
head.addView(cardTitle, layoutParams);

// Card toggling by click on head element view
head.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
ecPagerView.toggle();
}
});
}
});

// Add background switcher to pager view
ecPagerView.setBackgroundSwitcherView((ECBackgroundSwitcherView) findViewById(R.id.ec_bg_switcher_element));

}

// Card collapse on back pressed
@Override
public void onBackPressed() {
if (!ecPagerView.collapse())
super.onBackPressed();
}

}
```

You can find this and other, more complex, examples in this repository ​

## Licence
Expanding Collection is released under the MIT license.
See [LICENSE](./LICENSE.md) for details.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.ramotion.expandingcollection.ECBackgroundSwitcherView;
import com.ramotion.expandingcollection.ECCardData;
import com.ramotion.expandingcollection.ECPagerCardContentList;
import com.ramotion.expandingcollection.ECPagerCardHead;
import com.ramotion.expandingcollection.ECPagerView;
import com.ramotion.expandingcollection.ECPagerViewAdapter;
import com.ramotion.expandingcollection.examples.full.pojo.CardData;
Expand All @@ -36,12 +36,12 @@ protected void onCreate(Bundle savedInstanceState) {
// Create adapter for pager
ECPagerViewAdapter adapter = new ECPagerViewAdapter(this, new ExampleDataset().getDataset()) {
@Override
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ECPagerCardContentList list, final ECCardData data) {
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ListView list, final ECCardData data) {
final CardData cardData = (CardData) data;

// Create adapter for list inside a card and set adapter to card content
CommentArrayAdapter commentArrayAdapter = new CommentArrayAdapter(getApplicationContext(), cardData.getListItems());
list.setEcArrayAdapter(commentArrayAdapter);
list.setAdapter(commentArrayAdapter);
list.setDivider(getResources().getDrawable(R.drawable.list_divider));
list.setDividerHeight((int) pxFromDp(getApplicationContext(), 0.5f));
list.setSelector(R.color.transparent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String getCardTitle() {
public static List<ECCardData> generateExampleData() {
List<ECCardData> list = new ArrayList<>();
list.add(new CardDataImpl("Card 1", R.drawable.attractions, R.drawable.attractions_head, createItemsList("Card 1")));
list.add(new CardDataImpl("Card 2", null, R.drawable.city_scape_head, createItemsList("Card 2")));
list.add(new CardDataImpl("Card 2", R.drawable.city_scape, R.drawable.city_scape_head, createItemsList("Card 2")));
list.add(new CardDataImpl("Card 3", R.drawable.nature, R.drawable.nature_head, createItemsList("Card 3")));
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ramotion.expandingcollection.ECBackgroundSwitcherView;
Expand All @@ -27,29 +28,35 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Get pager from layout
ecPagerView = (ECPagerView) findViewById(R.id.ec_pager_element);


// Generate example dataset
List<ECCardData> dataset = CardDataImpl.generateExampleData();

// Implement and pager adapter and set it to pager view
ecPagerView.setPagerViewAdapter(new ECPagerViewAdapter(getApplicationContext(), dataset) {
@Override
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ECPagerCardContentList list, ECCardData data) {
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ListView list, ECCardData data) {
// Data object for current card
CardDataImpl cardData = (CardDataImpl) data;

list.setEcArrayAdapter(new CardListItemAdapter(getApplicationContext(), cardData.getListItems()));
// Set adapter and items to current card content list
list.setAdapter(new CardListItemAdapter(getApplicationContext(), cardData.getListItems()));
// Also some visual tuning can be done here
list.setBackgroundColor(Color.WHITE);

// Here we can create elements for head view or inflate layout from xml using inflater service
TextView cardTitle = new TextView(getApplicationContext());
cardTitle.setText(cardData.getCardTitle());
cardTitle.setTextSize(COMPLEX_UNIT_DIP, 20);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
cardTitle.setText(cardData.getCardTitle());
head.addView(cardTitle, layoutParams);

// Card toggling by click on head element view
head.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Expand All @@ -59,10 +66,12 @@ public void onClick(final View v) {
}
});

// Add background switcher to pager view
ecPagerView.setBackgroundSwitcherView((ECBackgroundSwitcherView) findViewById(R.id.ec_bg_switcher_element));

}

// Card collapse on back pressed
@Override
public void onBackPressed() {
if (!ecPagerView.collapse())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ec="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,9 +8,9 @@
<com.ramotion.expandingcollection.ECBackgroundSwitcherView
android:id="@+id/ec_bg_switcher_element"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />

<com.ramotion.expandingcollection.ECPagerView
<com.ramotion.expandingcollection.ECPagerView xmlns:ec="http://schemas.android.com/apk/res-auto"
android:id="@+id/ec_pager_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Loading