Skip to content
This repository has been archived by the owner on Jan 4, 2018. It is now read-only.

Commit

Permalink
Comment updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsombor Erdody-Nagy committed May 22, 2012
1 parent 4d684ad commit 3723a15
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 18 deletions.
Binary file added .DS_Store
Binary file not shown.
51 changes: 39 additions & 12 deletions BucketListAdapter/src/com/scythe/bucket/BucketListAdapter.java
@@ -1,6 +1,5 @@
package com.scythe.bucket;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
Expand All @@ -25,25 +24,52 @@ public abstract class BucketListAdapter<T> extends BaseAdapter {
protected Activity ctx;
protected Integer bucketSize;

public BucketListAdapter(Activity ctx, ArrayList<T> elements) {
/**
* Basic constructor, takes an Activity context and the list of elements.
* Assumes a 1 column view by default.
*
* @param ctx
* The Activity context.
* @param elements
* The list of elements to present.
*/
public BucketListAdapter(Activity ctx, List<T> elements) {
this(ctx, elements, 1);
}

public BucketListAdapter(Activity ctx, ArrayList<T> elements,
Integer bucketSize) {
/**
* Extended constructor, takes an Activity context, the list of elements and
* the exact number of columns.
*
* @param ctx
* The Activity context.
* @param elements
* The list of elements to present.
* @param bucketSize
* The exact number of columns.
*
*/
public BucketListAdapter(Activity ctx, List<T> elements, Integer bucketSize) {
this.elements = elements;
this.ctx = ctx;
this.bucketSize = bucketSize;
}

public void enableAutoMeasure(float minBucketElementWidthDip){

/**
* Calculates the required number of columns based on the actual screen
* width (in DIP) and the given minimum element width (in DIP).
*
* @param minBucketElementWidthDip
* The minimum width in DIP of an element.
*/
public void enableAutoMeasure(float minBucketElementWidthDip) {
float screenWidth = getScreenWidthInDip();
if(minBucketElementWidthDip >= screenWidth){

if (minBucketElementWidthDip >= screenWidth) {
bucketSize = 1;
} else {
bucketSize = (int)(screenWidth / minBucketElementWidthDip);
}
bucketSize = (int) (screenWidth / minBucketElementWidthDip);
}
}

@Override
Expand All @@ -63,7 +89,7 @@ public long getItemId(int position) {

@Override
public View getView(int bucketPosition, View convertView, ViewGroup parent) {

ViewGroup bucket = (ViewGroup) View.inflate(ctx, R.layout.bucket, null);

for (int i = (bucketPosition * bucketSize); i < ((bucketPosition * bucketSize) + bucketSize); i++) {
Expand Down Expand Up @@ -93,7 +119,8 @@ public View getView(int bucketPosition, View convertView, ViewGroup parent) {
* The current element for which the View should be constructed
* @return The View that should be presented in the corresponding bucket.
*/
protected abstract View getBucketElement(int position, T currentElement);
protected abstract View getBucketElement(final int position,
T currentElement);

protected float getScreenWidthInDip() {
WindowManager wm = ctx.getWindowManager();
Expand Down
13 changes: 13 additions & 0 deletions BucketListAdapterDemo/res/layout/footer.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/footer" />

</FrameLayout>
13 changes: 13 additions & 0 deletions BucketListAdapterDemo/res/layout/header.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/header" />

</FrameLayout>
4 changes: 3 additions & 1 deletion BucketListAdapterDemo/res/layout/main.xml
Expand Up @@ -9,7 +9,9 @@
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:gravity="center_horizontal"
android:text="@string/title" />
android:text="@string/title"
android:textSize="26dip"
android:textStyle="bold" />

<ListView android:id="@+id/BucketList"
android:layout_width="fill_parent"
Expand Down
2 changes: 2 additions & 0 deletions BucketListAdapterDemo/res/values/strings.xml
Expand Up @@ -3,5 +3,7 @@

<string name="title">BucketListAdapter demo</string>
<string name="app_name">BucketedListAdapterDemo</string>
<string name="footer">Hey, I\'m a footer!</string>
<string name="header">Hey, I\'m a header!</string>

</resources>
Expand Up @@ -2,12 +2,13 @@

import java.util.ArrayList;

import com.scythe.bucketlistdemo.adapter.MyBucketAdapter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.scythe.bucketlistdemo.adapter.MyBucketAdapter;

public class BucketedListAdapterDemoActivity extends Activity {

@Override
Expand All @@ -22,9 +23,15 @@ public void onCreate(Bundle savedInstanceState) {
list.add(i);
}

MyBucketAdapter adap = new MyBucketAdapter(this, list, 3);
MyBucketAdapter adap = new MyBucketAdapter(this, list, 100);
adap.enableAutoMeasure(100);

View header = View.inflate(this, R.layout.header, null);
View footer = View.inflate(this, R.layout.footer, null);

bucketList.addHeaderView(header);
bucketList.addFooterView(footer);

bucketList.setAdapter(adap);
}

Expand Down
@@ -1,6 +1,6 @@
package com.scythe.bucketlistdemo.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.View;
Expand All @@ -12,7 +12,7 @@

public class MyBucketAdapter extends BucketListAdapter<Integer> {

public MyBucketAdapter(Activity ctx, ArrayList<Integer> elements,
public MyBucketAdapter(Activity ctx, List<Integer> elements,
Integer bucketSize) {
super(ctx, elements, bucketSize);
}
Expand Down

0 comments on commit 3723a15

Please sign in to comment.