Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Add sort order option to NumericWheelAdapter #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
40 changes: 38 additions & 2 deletions wheel/src/kankan/wheel/widget/adapters/NumericWheelAdapter.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public class NumericWheelAdapter extends AbstractWheelTextAdapter {
/** The default max value */
private static final int DEFAULT_MIN_VALUE = 0;

/** Sort order */
public enum SortOrder {
SMALLEST_AT_BOTTOM,
SMALLEST_AT_TOP
}

// Values
private int minValue;
private int maxValue;
private SortOrder sortOrder = SortOrder.SMALLEST_AT_TOP;

// format
private String format;
Expand All @@ -51,7 +58,18 @@ public NumericWheelAdapter(Context context) {
* @param maxValue the wheel max value
*/
public NumericWheelAdapter(Context context, int minValue, int maxValue) {
this(context, minValue, maxValue, null);
this(context, minValue, maxValue, null, SortOrder.SMALLEST_AT_TOP);
}

/**
* Constructor
* @param context the current context
* @param minValue the wheel min value
* @param maxValue the wheel max value
* @param sortOrder the sort order
*/
public NumericWheelAdapter(Context context, int minValue, int maxValue, SortOrder sortOrder) {
this(context, minValue, maxValue, null, sortOrder);
}

/**
Expand All @@ -62,17 +80,35 @@ public NumericWheelAdapter(Context context, int minValue, int maxValue) {
* @param format the format string
*/
public NumericWheelAdapter(Context context, int minValue, int maxValue, String format) {
this(context, minValue, maxValue, format, SortOrder.SMALLEST_AT_TOP);
}

/**
* Constructor
* @param context the current context
* @param minValue the wheel min value
* @param maxValue the wheel max value
* @param format the format string
* @param sortOrder the sort order
*/
public NumericWheelAdapter(Context context, int minValue, int maxValue, String format, SortOrder sortOrder) {
super(context);

this.minValue = minValue;
this.maxValue = maxValue;
this.format = format;
this.sortOrder = sortOrder;
}

@Override
public CharSequence getItemText(int index) {
if (index >= 0 && index < getItemsCount()) {
int value = minValue + index;
int value;
if (sortOrder == SortOrder.SMALLEST_AT_TOP){
value = minValue + index;
} else {
value = maxValue - index;
}
return format != null ? String.format(format, value) : Integer.toString(value);
}
return null;
Expand Down