Skip to content

Commit

Permalink
Merge branch 'dev' into feature_maintenance-animateaddition
Browse files Browse the repository at this point in the history
Conflicts:
	lib-manipulation/src/main/java/com/nhaarman/listviewanimations/itemmanipulation/animateaddition/AnimateAdditionAdapter.java
  • Loading branch information
nhaarman committed Jun 15, 2014
2 parents e589b53 + 9e5e2f8 commit 1c85619
Show file tree
Hide file tree
Showing 65 changed files with 1,971 additions and 729 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ ListViewAnimations provides the following features:

Setup
-----
* In Eclipse, just import the library as an Android library project.
* Project > Clean to generate the binaries you need, like R.java, etc.
* Then, just add ListViewAnimations as a dependency to your existing project and you're good to go!

**Or**:

* [Download the .jar file][4]
* [Download the latest NineOldAndroids .jar file][17]
Expand All @@ -40,7 +35,7 @@ Add the following to your `build.gradle`:
mavenCentral()
}

dependencies{
dependencies {
compile 'com.nhaarman.listviewanimations:library:2.6.0'
}

Expand Down
3 changes: 3 additions & 0 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ apply plugin: 'android'

dependencies {
compile 'com.android.support:appcompat-v7:19.1.+'
compile 'se.emilsjolander:stickylistheaders:2.4.0'

compile project(':lib-core')
compile project(':lib-core-slh')
compile project(':lib-manipulation')
}

Expand Down
62 changes: 18 additions & 44 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@
</dependency>

<!-- Library -->
<dependency>
<groupId>com.nhaarman.listviewanimations</groupId>
<artifactId>lib-core</artifactId>
<version>${project.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.nhaarman.listviewanimations</groupId>
<artifactId>lib-manipulation</artifactId>
<version>${project.version}</version>
<type>apklib</type>
</dependency>

<!-- StickyListHeaders -->
<dependency>
<groupId>com.nhaarman.listviewanimations</groupId>
<artifactId>lib-core</artifactId>
<version>${project.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.nhaarman.listviewanimations</groupId>
<artifactId>lib-manipulation</artifactId>
<version>${project.version}</version>
<type>apklib</type>
<groupId>se.emilsjolander</groupId>
<artifactId>library</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>

Expand All @@ -59,43 +66,10 @@
<configuration>
<androidManifestFile>${project.basedir}/src/main/AndroidManifest.xml</androidManifestFile>
<resourceDirectory>${project.basedir}/src/main/res</resourceDirectory>
<aidlSourceDirectory>${project.basedir}/src/main/aidl</aidlSourceDirectory>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>initialize</phase>
<configuration>
<target>
<copy todir="src/main/java">
<fileset dir="src/main/aidl">
<include name="**/*.aidl" />
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<phase>install</phase>
<configuration>
<target>
<delete dir="src/main/java/com/android" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<activity
android:name="com.haarman.listviewanimations.itemmanipulationexamples.ExpandableListItemActivity"
android:label="@string/expandablelistitemadapter" />
<activity android:name=".StickyListHeadersActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -15,145 +15,143 @@
*/
package com.haarman.listviewanimations;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.nhaarman.listviewanimations.ArrayAdapter;
import com.nhaarman.listviewanimations.itemmanipulation.OnDismissCallback;
import com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.SwipeDismissAdapter;
import com.nhaarman.listviewanimations.swinginadapters.prepared.SwingBottomInAnimationAdapter;
import com.nhaarman.listviewanimations.swinginadapters.simple.SwingBottomInAnimationAdapter;

import android.support.annotation.NonNull;
import java.util.ArrayList;

public class GoogleCardsActivity extends BaseActivity implements OnDismissCallback {

private GoogleCardsAdapter mGoogleCardsAdapter;

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

ListView listView = (ListView) findViewById(R.id.activity_googlecards_listview);

mGoogleCardsAdapter = new GoogleCardsAdapter(this);
SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(new SwipeDismissAdapter(mGoogleCardsAdapter, this));
swingBottomInAnimationAdapter.setInitialDelayMillis(300);
swingBottomInAnimationAdapter.setAbsListView(listView);

listView.setAdapter(swingBottomInAnimationAdapter);

mGoogleCardsAdapter.addAll(getItems());
}

private ArrayList<Integer> getItems() {
ArrayList<Integer> items = new ArrayList<Integer>();
for (int i = 0; i < 100; i++) {
items.add(i);
}
return items;
}

@Override
public void onDismiss(@NonNull final AbsListView listView, @NonNull final int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mGoogleCardsAdapter.remove(position);
}
}

private static class GoogleCardsAdapter extends ArrayAdapter<Integer> {

private final Context mContext;
private final LruCache<Integer, Bitmap> mMemoryCache;

public GoogleCardsAdapter(final Context context) {
mContext = context;

final int cacheSize = (int) (Runtime.getRuntime().maxMemory() / 1024);
mMemoryCache = new LruCache<Integer, Bitmap>(cacheSize) {
@Override
protected int sizeOf(final Integer key, final Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
}
};
}

@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
ViewHolder viewHolder;
View view = convertView;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.activity_googlecards_card, parent, false);

viewHolder = new ViewHolder();
viewHolder.textView = (TextView) view.findViewById(R.id.activity_googlecards_card_textview);
view.setTag(viewHolder);

viewHolder.imageView = (ImageView) view.findViewById(R.id.activity_googlecards_card_imageview);
} else {
viewHolder = (ViewHolder) view.getTag();
}

viewHolder.textView.setText("This is card " + (getItem(position) + 1));
setImageView(viewHolder, position);

return view;
}

private void setImageView(final ViewHolder viewHolder, final int position) {
int imageResId;
switch (getItem(position) % 5) {
case 0:
imageResId = R.drawable.img_nature1;
break;
case 1:
imageResId = R.drawable.img_nature2;
break;
case 2:
imageResId = R.drawable.img_nature3;
break;
case 3:
imageResId = R.drawable.img_nature4;
break;
default:
imageResId = R.drawable.img_nature5;
}

Bitmap bitmap = getBitmapFromMemCache(imageResId);
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(mContext.getResources(), imageResId);
addBitmapToMemoryCache(imageResId, bitmap);
}
viewHolder.imageView.setImageBitmap(bitmap);
}

private void addBitmapToMemoryCache(final int key, final Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}

private Bitmap getBitmapFromMemCache(final int key) {
return mMemoryCache.get(key);
}

private static class ViewHolder {
TextView textView;
ImageView imageView;
}
}
public class GoogleCardsActivity extends BaseActivity implements OnDismissCallback<ListView> {

private GoogleCardsAdapter mGoogleCardsAdapter;

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

ListView listView = (ListView) findViewById(R.id.activity_googlecards_listview);

mGoogleCardsAdapter = new GoogleCardsAdapter(this);
SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(new SwipeDismissAdapter(mGoogleCardsAdapter, this));
swingBottomInAnimationAdapter.setAbsListView(listView);
swingBottomInAnimationAdapter.getViewAnimator().setInitialDelayMillis(300);

listView.setAdapter(swingBottomInAnimationAdapter);

mGoogleCardsAdapter.addAll(getItems());
}

private ArrayList<Integer> getItems() {
ArrayList<Integer> items = new ArrayList<Integer>();
for (int i = 0; i < 100; i++) {
items.add(i);
}
return items;
}

@Override
public void onDismiss(@NonNull final ListView listView, @NonNull final int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mGoogleCardsAdapter.remove(position);
}
}

private static class GoogleCardsAdapter extends ArrayAdapter<Integer> {

private final Context mContext;
private final LruCache<Integer, Bitmap> mMemoryCache;

public GoogleCardsAdapter(final Context context) {
mContext = context;

final int cacheSize = (int) (Runtime.getRuntime().maxMemory() / 1024);
mMemoryCache = new LruCache<Integer, Bitmap>(cacheSize) {
@Override
protected int sizeOf(final Integer key, final Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
}
};
}

@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
ViewHolder viewHolder;
View view = convertView;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.activity_googlecards_card, parent, false);

viewHolder = new ViewHolder();
viewHolder.textView = (TextView) view.findViewById(R.id.activity_googlecards_card_textview);
view.setTag(viewHolder);

viewHolder.imageView = (ImageView) view.findViewById(R.id.activity_googlecards_card_imageview);
} else {
viewHolder = (ViewHolder) view.getTag();
}

viewHolder.textView.setText("This is card " + (getItem(position) + 1));
setImageView(viewHolder, position);

return view;
}

private void setImageView(final ViewHolder viewHolder, final int position) {
int imageResId;
switch (getItem(position) % 5) {
case 0:
imageResId = R.drawable.img_nature1;
break;
case 1:
imageResId = R.drawable.img_nature2;
break;
case 2:
imageResId = R.drawable.img_nature3;
break;
case 3:
imageResId = R.drawable.img_nature4;
break;
default:
imageResId = R.drawable.img_nature5;
}

Bitmap bitmap = getBitmapFromMemCache(imageResId);
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(mContext.getResources(), imageResId);
addBitmapToMemoryCache(imageResId, bitmap);
}
viewHolder.imageView.setImageBitmap(bitmap);
}

private void addBitmapToMemoryCache(final int key, final Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}

private Bitmap getBitmapFromMemCache(final int key) {
return mMemoryCache.get(key);
}

private static class ViewHolder {
TextView textView;
ImageView imageView;
}
}
}
Loading

0 comments on commit 1c85619

Please sign in to comment.