Example usage for java.lang Float MAX_VALUE

List of usage examples for java.lang Float MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Float MAX_VALUE.

Prototype

float MAX_VALUE

To view the source code for java.lang Float MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type float , (2-2-23)·2127.

Usage

From source file:jp.terasoluna.fw.validation.FieldChecks.java

/**
 * ???float??????/*from  w ww. ja va  2  s  .c  om*/
 * ??????
 *
 * <p>???10?100???????????
 * true?????
 *
 * <h5>validation.xml?</h5>
 * <code><pre>
 * &lt;form name=&quot;sample&quot;&gt;
 *  
 *  &lt;field property=&quot;floatField&quot;
 *      depends=&quot;floatRange&quot;&gt;
 *    &lt;arg key=&quot;sample.floatField&quot; position="0"/&gt;
 *    &lt;var&gt;
 *      &lt;var-name&gt;floatRangeMin&lt;/var-name&gt;
 *      &lt;var-value&gt;10&lt;/var-value&gt;
 *    &lt;/var&gt;
 *    &lt;var&gt;
 *      &lt;var-name&gt;floatRangeMax&lt;/var-name&gt;
 *      &lt;var-value&gt;100&lt;/var-value&gt;
 *    &lt;/var&gt;
 *  &lt;/field&gt;
 *  
 * &lt;/form&gt;
 * </pre></code>
 *
 * <h5>validation.xml???&lt;var&gt;?</h5>
 * <table border="1">
 *  <tr>
 *   <td><center><b><code>var-name</code></b></center></td>
 *   <td><center><b><code>var-value</code></b></center></td>
 *   <td><center><b></b></center></td>
 *   <td><center><b>?</b></center></td>
 *  </tr>
 *  <tr>
 *   <td> floatRangeMin </td>
 *   <td>?</td>
 *   <td>false</td>
 *   <td>????????Float???
 *   ?
 *   ????????</td>
 *  </tr>
 *  <tr>
 *   <td> floatRangeMax </td>
 *   <td></td>
 *   <td>false</td>
 *   <td>???????Float??
 *   ?
 *   ????????</td>
 *  </tr>
 * </table>
 *
 * @param bean ?JavaBean
 * @param va ?<code>ValidatorAction</code>
 * @param field ?<code>Field</code>
 * @param errors ?????
 * ??
 * @return ??????<code>true</code>?
 * ????<code>false</code>?
 * @throws ValidatorException validation??????
 * ?
 */
public boolean validateFloatRange(Object bean, ValidatorAction va, Field field, ValidationErrors errors)
        throws ValidatorException {
    // 
    String value = extractValue(bean, field);
    if (StringUtils.isEmpty(value)) {
        return true;
    }

    // float?? --- Float??????
    float floatValue = 0;
    try {
        floatValue = Float.parseFloat(value);
    } catch (NumberFormatException e) {
        rejectValue(errors, field, va, bean);
        return false;
    }

    //  --- ?Float??????
    //                ????
    String strMin = field.getVarValue("floatRangeMin");
    float min = Float.MIN_VALUE;
    if (!GenericValidator.isBlankOrNull(strMin)) {
        try {
            min = Float.parseFloat(strMin);
        } catch (NumberFormatException e) {
            String message = "Mistake on validation definition file. " + "- floatRangeMin is not number. "
                    + "You'll have to check it over. ";
            log.error(message, e);
            throw new ValidatorException(message);
        }
    }
    String strMax = field.getVarValue("floatRangeMax");
    float max = Float.MAX_VALUE;
    if (!GenericValidator.isBlankOrNull(strMax)) {
        try {
            max = Float.parseFloat(strMax);
        } catch (NumberFormatException e) {
            String message = "Mistake on validation definition file. " + "- floatRangeMax is not number. "
                    + "You'll have to check it over. ";
            log.error(message, e);
            throw new ValidatorException(message);
        }
    }

    // 
    if (!GenericValidator.isInRange(floatValue, min, max)) {
        rejectValue(errors, field, va, bean);
        return false;
    }
    return true;
}

From source file:SIFT_Volume_Stitching.java

float[] getAndApplyMinMax(final ArrayList<ImageInformation> imageInformationList, final int dim) {
    float min[] = new float[dim];
    float max[] = new float[dim];
    for (int i = 0; i < min.length; i++) {
        min[i] = Float.MAX_VALUE;
        max[i] = Float.MIN_VALUE;
    }//from  ww  w.j  ava 2s  . c  om

    for (ImageInformation iI : imageInformationList)
        for (int i = 0; i < min.length; i++) {
            if (iI.position[i] < min[i])
                min[i] = iI.position[i];

            if (iI.position[i] + iI.size[i] > max[i])
                max[i] = iI.position[i] + iI.size[i];
        }

    for (ImageInformation iI : imageInformationList)
        for (int i = 0; i < min.length; i++)
            iI.position[i] -= min[i];

    for (int i = 0; i < min.length; i++) {
        max[i] -= min[i];
        min[i] = 0;
    }

    return max;
}

From source file:com.hainva.feedlynavigation.FeedlyViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int height = getHeight();

    final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;//w  ww  .  j av  a  2s .  c o  m
            float offset = oldCurInfo.offset + oldCurInfo.heightFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageHeight(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                Log.d("Hari", "Hari - current - Offset" + offset);
                offset += ii.heightFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageHeight(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.heightFactor + marginOffset;
                Log.d("Hari", "Hari - current - Offset" + offset);
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.heightFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageHeight(pos--) + marginOffset;
        }
        offset -= ii.heightFactor + marginOffset;
        Log.d("Hari", "Hari - prev - Offset" + offset);
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.heightFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageHeight(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.heightFactor - 1;
        }
        Log.d("Hari", "Hari - next - Offset" + offset);
        ii.offset = offset;
        offset += ii.heightFactor + marginOffset;
    }

    //        mNeedCalculatePageOffsets = false;
}

From source file:dev.dworks.libs.widget.VerticalViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int height = getHeight();

    final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;/*from  ww w.j  a va  2 s  . com*/
            float offset = oldCurInfo.offset + oldCurInfo.heightFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageWidth(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.heightFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageWidth(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.heightFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.heightFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageWidth(pos--) + marginOffset;
        }
        offset -= ii.heightFactor + marginOffset;
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.heightFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageWidth(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.heightFactor - 1;
        }
        ii.offset = offset;
        offset += ii.heightFactor + marginOffset;
    }

    //        mNeedCalculatePageOffsets = false;
}

From source file:android.support.custom.view.VerticalViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int height = getHeight();

    final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;//  w  w w. ja  v  a  2s  .c om
            float offset = oldCurInfo.offset + oldCurInfo.heightFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageHeight(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.heightFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageHeight(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.heightFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.heightFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageHeight(pos--) + marginOffset;
        }
        offset -= ii.heightFactor + marginOffset;
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.heightFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageHeight(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.heightFactor - 1;
        }
        ii.offset = offset;
        offset += ii.heightFactor + marginOffset;
    }

    //        mNeedCalculatePageOffsets = false;
}

From source file:android.improving.utils.views.cardsview.OrientedViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int size = getClientSize();
    final float marginOffset = size > 0 ? (float) mPageMargin / size : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;/*from  www  .  j  a v a  2s .  c  o m*/
            float offset = oldCurInfo.offset + oldCurInfo.sizeFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageWidth(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.sizeFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageWidth(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.sizeFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.sizeFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageWidth(pos--) + marginOffset;
        }
        offset -= ii.sizeFactor + marginOffset;
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.sizeFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageWidth(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.sizeFactor - 1;
        }
        ii.offset = offset;
        offset += ii.sizeFactor + marginOffset;
    }

    mNeedCalculatePageOffsets = false;
}

From source file:jp.furplag.util.commons.NumberUtils.java

/**
 * {@link POSITIVE_INFINITY} in BigDecimal.
 *
 * @param type Float or Double.//w  w  w  . j a v a  2 s .c  o m
 * @return POSITIVE_INFINITY in BigDecimal.
 */
private static final BigDecimal toInfinityAndBeyond(Class<? extends Number> type) {
    if (Double.class.equals(type))
        return new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Math.ulp(Double.MAX_VALUE) / 2));
    if (Float.class.equals(type))
        return new BigDecimal(Float.MAX_VALUE).add(new BigDecimal(Math.ulp(Float.MAX_VALUE) / 2));

    throw new IllegalArgumentException("the type \"" + type + "\" are not implements Infinities.");
}

From source file:com.tunebrains.views.InfiniteViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int width = getClientWidth();
    final float marginOffset = width > 0 ? (float) mPageMargin / width : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;/*w  w  w.  java  2 s .  co m*/
            float offset = oldCurInfo.offset + oldCurInfo.widthFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageWidth(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.widthFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageWidth(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.widthFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    //        mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mFirstOffset = -Float.MAX_VALUE;
    mLastOffset = Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageWidth(pos--) + marginOffset;
        }
        offset -= ii.widthFactor + marginOffset;
        ii.offset = offset;
        //            if (ii.position == 0) mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.widthFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageWidth(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            //                mLastOffset = offset + ii.widthFactor - 1;
        }
        ii.offset = offset;
        offset += ii.widthFactor + marginOffset;
    }

    mNeedCalculatePageOffsets = false;
}

From source file:interactive.view.pagereader.ViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int width = getWidth();
    final float marginOffset = width > 0 ? (float) mPageMargin / width : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;//from   ww w.  j  av a 2 s. c om
            float offset = oldCurInfo.offset + oldCurInfo.widthFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageWidth(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.widthFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageWidth(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.widthFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.widthFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageWidth(pos--) + marginOffset;
        }
        offset -= ii.widthFactor + marginOffset;
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.widthFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageWidth(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.widthFactor - 1;
        }
        ii.offset = offset;
        offset += ii.widthFactor + marginOffset;
    }

    //      mNeedCalculatePageOffsets = false;
}

From source file:com.stone.card.VerticalViewPager.java

private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
    final int N = mAdapter.getCount();
    final int height = getHeight();

    final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
    // Fix up offsets for later layout.
    if (oldCurInfo != null) {
        final int oldCurPosition = oldCurInfo.position;
        // Base offsets off of oldCurInfo.
        if (oldCurPosition < curItem.position) {
            int itemIndex = 0;
            ItemInfo ii = null;/* ww  w. ja  v  a  2 s .c om*/
            float offset = oldCurInfo.offset + oldCurInfo.heightFactor + marginOffset;
            for (int pos = oldCurPosition + 1; pos <= curItem.position && itemIndex < mItems.size(); pos++) {
                ii = mItems.get(itemIndex);
                while (pos > ii.position && itemIndex < mItems.size() - 1) {
                    itemIndex++;
                    ii = mItems.get(itemIndex);
                }
                while (pos < ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset += mAdapter.getPageHeight(pos) + marginOffset;
                    pos++;
                }
                ii.offset = offset;
                offset += ii.heightFactor + marginOffset;
            }
        } else if (oldCurPosition > curItem.position) {
            int itemIndex = mItems.size() - 1;
            ItemInfo ii = null;
            float offset = oldCurInfo.offset;
            for (int pos = oldCurPosition - 1; pos >= curItem.position && itemIndex >= 0; pos--) {
                ii = mItems.get(itemIndex);
                while (pos < ii.position && itemIndex > 0) {
                    itemIndex--;
                    ii = mItems.get(itemIndex);
                }
                while (pos > ii.position) {
                    // We don't have an item populated for this,
                    // ask the adapter for an offset.
                    offset -= mAdapter.getPageHeight(pos) + marginOffset;
                    pos--;
                }
                offset -= ii.heightFactor + marginOffset;
                ii.offset = offset;
            }
        }
    }

    // Base all offsets off of curItem.
    final int itemCount = mItems.size();
    float offset = curItem.offset;
    int pos = curItem.position - 1;
    mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
    mLastOffset = curItem.position == N - 1 ? curItem.offset + curItem.heightFactor - 1 : Float.MAX_VALUE;
    // Previous pages
    for (int i = curIndex - 1; i >= 0; i--, pos--) {
        final ItemInfo ii = mItems.get(i);
        while (pos > ii.position) {
            offset -= mAdapter.getPageHeight(pos--) + marginOffset;
        }
        offset -= ii.heightFactor + marginOffset;
        ii.offset = offset;
        if (ii.position == 0)
            mFirstOffset = offset;
    }
    offset = curItem.offset + curItem.heightFactor + marginOffset;
    pos = curItem.position + 1;
    // Next pages
    for (int i = curIndex + 1; i < itemCount; i++, pos++) {
        final ItemInfo ii = mItems.get(i);
        while (pos < ii.position) {
            offset += mAdapter.getPageHeight(pos++) + marginOffset;
        }
        if (ii.position == N - 1) {
            mLastOffset = offset + ii.heightFactor - 1;
        }
        ii.offset = offset;
        offset += ii.heightFactor + marginOffset;
    }

    // mNeedCalculatePageOffsets = false;
}