FileDocCategorySizeDatePackage
Criteria.javaAPI DocAndroid 5.1 API13672Thu Mar 12 22:22:30 GMT 2015android.location

Criteria

public class Criteria extends Object implements android.os.Parcelable
A class indicating the application criteria for selecting a location provider. Providers maybe ordered according to accuracy, power usage, ability to report altitude, speed, and bearing, and monetary cost.

Fields Summary
public static final int
NO_REQUIREMENT
A constant indicating that the application does not choose to place requirement on a particular feature.
public static final int
POWER_LOW
A constant indicating a low power requirement.
public static final int
POWER_MEDIUM
A constant indicating a medium power requirement.
public static final int
POWER_HIGH
A constant indicating a high power requirement.
public static final int
ACCURACY_FINE
A constant indicating a finer location accuracy requirement
public static final int
ACCURACY_COARSE
A constant indicating an approximate accuracy requirement
public static final int
ACCURACY_LOW
A constant indicating a low location accuracy requirement - may be used for horizontal, altitude, speed or bearing accuracy. For horizontal and vertical position this corresponds roughly to an accuracy of greater than 500 meters.
public static final int
ACCURACY_MEDIUM
A constant indicating a medium accuracy requirement - currently used only for horizontal accuracy. For horizontal position this corresponds roughly to to an accuracy of between 100 and 500 meters.
public static final int
ACCURACY_HIGH
a constant indicating a high accuracy requirement - may be used for horizontal, altitude, speed or bearing accuracy. For horizontal and vertical position this corresponds roughly to an accuracy of less than 100 meters.
private int
mHorizontalAccuracy
private int
mVerticalAccuracy
private int
mSpeedAccuracy
private int
mBearingAccuracy
private int
mPowerRequirement
private boolean
mAltitudeRequired
private boolean
mBearingRequired
private boolean
mSpeedRequired
private boolean
mCostAllowed
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Criteria()
Constructs a new Criteria object. The new object will have no requirements on accuracy, power, or response time; will not require altitude, speed, or bearing; and will not allow monetary cost.


                                         
      
public Criteria(Criteria criteria)
Constructs a new Criteria object that is a copy of the given criteria.

        mHorizontalAccuracy = criteria.mHorizontalAccuracy;
        mVerticalAccuracy = criteria.mVerticalAccuracy;
        mSpeedAccuracy = criteria.mSpeedAccuracy;
        mBearingAccuracy = criteria.mBearingAccuracy;
        mPowerRequirement = criteria.mPowerRequirement;
        mAltitudeRequired = criteria.mAltitudeRequired;
        mBearingRequired = criteria.mBearingRequired;
        mSpeedRequired = criteria.mSpeedRequired;
        mCostAllowed = criteria.mCostAllowed;
    
Methods Summary
private static java.lang.StringaccuracyToString(int accuracy)

        switch (accuracy) {
            case NO_REQUIREMENT:
                return "---";
            case ACCURACY_HIGH:
                return "HIGH";
            case ACCURACY_MEDIUM:
                return "MEDIUM";
            case ACCURACY_LOW:
                return "LOW";
            default:
                return "???";
        }
    
public intdescribeContents()


    
       
        return 0;
    
public intgetAccuracy()
Returns a constant indicating desired accuracy of location Accuracy may be {@link #ACCURACY_FINE} if desired location is fine, else it can be {@link #ACCURACY_COARSE}.

        if (mHorizontalAccuracy >= ACCURACY_HIGH) {
            return ACCURACY_FINE;
        } else {
            return ACCURACY_COARSE;
        }
    
public intgetBearingAccuracy()
Returns a constant indicating the desired bearing accuracy. Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_HIGH}, or {@link #NO_REQUIREMENT}.

        return mBearingAccuracy;
    
public intgetHorizontalAccuracy()
Returns a constant indicating the desired horizontal accuracy (latitude and longitude). Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_MEDIUM}, {@link #ACCURACY_HIGH} or {@link #NO_REQUIREMENT}.

        return mHorizontalAccuracy;
    
public intgetPowerRequirement()
Returns a constant indicating the desired power requirement. The returned

        return mPowerRequirement;
    
public intgetSpeedAccuracy()
Returns a constant indicating the desired speed accuracy Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_HIGH}, or {@link #NO_REQUIREMENT}.

        return mSpeedAccuracy;
    
public intgetVerticalAccuracy()
Returns a constant indicating the desired vertical accuracy (altitude). Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_HIGH}, or {@link #NO_REQUIREMENT}.

        return mVerticalAccuracy;
    
public booleanisAltitudeRequired()
Returns whether the provider must provide altitude information. Not all fixes are guaranteed to contain such information.

        return mAltitudeRequired;
    
public booleanisBearingRequired()
Returns whether the provider must provide bearing information. Not all fixes are guaranteed to contain such information.

        return mBearingRequired;
    
public booleanisCostAllowed()
Returns whether the provider is allowed to incur monetary cost.

        return mCostAllowed;
    
public booleanisSpeedRequired()
Returns whether the provider must provide speed information. Not all fixes are guaranteed to contain such information.

        return mSpeedRequired;
    
private static java.lang.StringpowerToString(int power)

        switch (power) {
            case NO_REQUIREMENT:
                return "NO_REQ";
            case POWER_LOW:
                return "LOW";
            case POWER_MEDIUM:
                return "MEDIUM";
            case POWER_HIGH:
                return "HIGH";
            default:
                return "???";
        }
    
public voidsetAccuracy(int accuracy)
Indicates the desired accuracy for latitude and longitude. Accuracy may be {@link #ACCURACY_FINE} if desired location is fine, else it can be {@link #ACCURACY_COARSE}. More accurate location may consume more power and may take longer.

throws
IllegalArgumentException if accuracy is not one of the supported constants

        if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_COARSE) {
            throw new IllegalArgumentException("accuracy=" + accuracy);
        }
        if (accuracy == ACCURACY_FINE) {
            mHorizontalAccuracy = ACCURACY_HIGH;
        } else {
            mHorizontalAccuracy = ACCURACY_LOW;
        }
    
public voidsetAltitudeRequired(boolean altitudeRequired)
Indicates whether the provider must provide altitude information. Not all fixes are guaranteed to contain such information.

        mAltitudeRequired = altitudeRequired;
    
public voidsetBearingAccuracy(int accuracy)
Indicates the desired bearing accuracy. Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_HIGH}, or {@link #NO_REQUIREMENT}. More accurate location may consume more power and may take longer.

throws
IllegalArgumentException if accuracy is not one of the supported constants

        if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_HIGH) {
            throw new IllegalArgumentException("accuracy=" + accuracy);
        }
        mBearingAccuracy = accuracy;
    
public voidsetBearingRequired(boolean bearingRequired)
Indicates whether the provider must provide bearing information. Not all fixes are guaranteed to contain such information.

        mBearingRequired = bearingRequired;
    
public voidsetCostAllowed(boolean costAllowed)
Indicates whether the provider is allowed to incur monetary cost.

        mCostAllowed = costAllowed;
    
public voidsetHorizontalAccuracy(int accuracy)
Indicates the desired horizontal accuracy (latitude and longitude). Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_MEDIUM}, {@link #ACCURACY_HIGH} or {@link #NO_REQUIREMENT}. More accurate location may consume more power and may take longer.

throws
IllegalArgumentException if accuracy is not one of the supported constants

        if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_HIGH) {
            throw new IllegalArgumentException("accuracy=" + accuracy);
        }
        mHorizontalAccuracy = accuracy;
    
public voidsetPowerRequirement(int level)
Indicates the desired maximum power level. The level parameter must be one of NO_REQUIREMENT, POWER_LOW, POWER_MEDIUM, or POWER_HIGH.

        if (level < NO_REQUIREMENT || level > POWER_HIGH) {
            throw new IllegalArgumentException("level=" + level);
        }
        mPowerRequirement = level;
    
public voidsetSpeedAccuracy(int accuracy)
Indicates the desired speed accuracy. Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_HIGH}, or {@link #NO_REQUIREMENT}. More accurate location may consume more power and may take longer.

throws
IllegalArgumentException if accuracy is not one of the supported constants

        if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_HIGH) {
            throw new IllegalArgumentException("accuracy=" + accuracy);
        }
        mSpeedAccuracy = accuracy;
    
public voidsetSpeedRequired(boolean speedRequired)
Indicates whether the provider must provide speed information. Not all fixes are guaranteed to contain such information.

        mSpeedRequired = speedRequired;
    
public voidsetVerticalAccuracy(int accuracy)
Indicates the desired vertical accuracy (altitude). Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_MEDIUM}, {@link #ACCURACY_HIGH} or {@link #NO_REQUIREMENT}. More accurate location may consume more power and may take longer.

throws
IllegalArgumentException if accuracy is not one of the supported constants

        if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_HIGH) {
            throw new IllegalArgumentException("accuracy=" + accuracy);
        }
        mVerticalAccuracy = accuracy;
    
public java.lang.StringtoString()

        StringBuilder s = new StringBuilder();
        s.append("Criteria[power=").append(powerToString(mPowerRequirement));
        s.append(" acc=").append(accuracyToString(mHorizontalAccuracy));
        s.append(']");
        return s.toString();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        parcel.writeInt(mHorizontalAccuracy);
        parcel.writeInt(mVerticalAccuracy);
        parcel.writeInt(mSpeedAccuracy);
        parcel.writeInt(mBearingAccuracy);
        parcel.writeInt(mPowerRequirement);
        parcel.writeInt(mAltitudeRequired ? 1 : 0);
        parcel.writeInt(mBearingRequired ? 1 : 0);
        parcel.writeInt(mSpeedRequired ? 1 : 0);
        parcel.writeInt(mCostAllowed ? 1 : 0);