From 3723a15b00ada1a57e4e29fd5fed0940c5d86f3c Mon Sep 17 00:00:00 2001 From: Zsombor Erdody-Nagy Date: Tue, 22 May 2012 15:42:43 +0200 Subject: [PATCH] Comment updates. --- .DS_Store | Bin 0 -> 6148 bytes .../com/scythe/bucket/BucketListAdapter.java | 51 +++++++++++++----- BucketListAdapterDemo/res/layout/footer.xml | 13 +++++ BucketListAdapterDemo/res/layout/header.xml | 13 +++++ BucketListAdapterDemo/res/layout/main.xml | 4 +- BucketListAdapterDemo/res/values/strings.xml | 2 + .../BucketedListAdapterDemoActivity.java | 13 +++-- .../adapter/MyBucketAdapter.java | 4 +- 8 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 .DS_Store create mode 100644 BucketListAdapterDemo/res/layout/footer.xml create mode 100644 BucketListAdapterDemo/res/layout/header.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 extends BaseAdapter { protected Activity ctx; protected Integer bucketSize; - public BucketListAdapter(Activity ctx, ArrayList 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 elements) { this(ctx, elements, 1); } - public BucketListAdapter(Activity ctx, ArrayList 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 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 @@ -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++) { @@ -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(); diff --git a/BucketListAdapterDemo/res/layout/footer.xml b/BucketListAdapterDemo/res/layout/footer.xml new file mode 100644 index 0000000..ac96a7d --- /dev/null +++ b/BucketListAdapterDemo/res/layout/footer.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/BucketListAdapterDemo/res/layout/header.xml b/BucketListAdapterDemo/res/layout/header.xml new file mode 100644 index 0000000..25d01ba --- /dev/null +++ b/BucketListAdapterDemo/res/layout/header.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/BucketListAdapterDemo/res/layout/main.xml b/BucketListAdapterDemo/res/layout/main.xml index 85fef42..339e527 100644 --- a/BucketListAdapterDemo/res/layout/main.xml +++ b/BucketListAdapterDemo/res/layout/main.xml @@ -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" /> BucketListAdapter demo BucketedListAdapterDemo + Hey, I\'m a footer! + Hey, I\'m a header! \ No newline at end of file diff --git a/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/BucketedListAdapterDemoActivity.java b/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/BucketedListAdapterDemoActivity.java index 496ae4f..325f6e0 100644 --- a/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/BucketedListAdapterDemoActivity.java +++ b/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/BucketedListAdapterDemoActivity.java @@ -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 @@ -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); } diff --git a/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/adapter/MyBucketAdapter.java b/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/adapter/MyBucketAdapter.java index dd93fcf..029431f 100644 --- a/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/adapter/MyBucketAdapter.java +++ b/BucketListAdapterDemo/src/com/scythe/bucketlistdemo/adapter/MyBucketAdapter.java @@ -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; @@ -12,7 +12,7 @@ public class MyBucketAdapter extends BucketListAdapter { - public MyBucketAdapter(Activity ctx, ArrayList elements, + public MyBucketAdapter(Activity ctx, List elements, Integer bucketSize) { super(ctx, elements, bucketSize); }