/*
 * $URL$
 * $Revision$
 * $LastChangedBy$
 * $LastChangedDate$
 *
 * Copyright (c) 2005 syseca AG, Switzerland
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of syseca AG. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you
 * entered into with syseca AG.
 */
package ch.spherIC.components;

import android.content.Context;
import android.util.AttributeSet;


/**
 * Shutter speed spinner.
 */
public class ShutterSpeedSpinner extends XSpinner {

    /**
     * Creates a new ShutterSpeedSpinner object.
     *
     * @param  context {@link Context}
     */
    public ShutterSpeedSpinner(Context context) {
        super(context);
    }

    /**
     * Creates a new ShutterSpeedSpinner object.
     *
     * @param  context {@link Context}
     * @param  attrs {@link AttributeSet}
     */
    public ShutterSpeedSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Creates a new ShutterSpeedSpinner object.
     *
     * @param  context {@link Context}
     * @param  attrs {@link AttributeSet}
     * @param  defStyle  int
     */
    public ShutterSpeedSpinner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    /**
     * Retrieves floating value of the selected shutter speed item.
     *
     * @return  Selected shutter speed as {@link Double}
     */
    public double getSelectedShutterSpeed() {

        double resVal;
        String valStr = getSelectedItem().toString();

        if (valStr.contains("1/")) {
            resVal = 1 / new Double(valStr.substring(2)).doubleValue();
        } else {
            resVal = new Double(valStr).doubleValue();
        }

        return resVal;
    }

    /**
     * Retrieves floating value of the selected shutter speed item.
     *
     * @return  Selected shutter speed as {@link Double}
     */
    public double getShutterSpeedAt(int position) {

        double resVal;
        String valStr = getItemAtPosition(position).toString();

        if (valStr.contains("1/")) {
            resVal = 1 / new Double(valStr.substring(2)).doubleValue();
        } else {
            resVal = new Double(valStr).doubleValue();
        }

        return resVal;
    }
}
