Android Open Source - AndroidPlaces Place Search Request






From Project

Back to project page AndroidPlaces.

License

The source code is released under:

Apache License

If you think the Android project AndroidPlaces listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Brian Lee//from w  ww  .  ja v a 2s.co m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tigerpenguin.places.request;

import android.content.Context;
import com.tigerpenguin.places.model.Language;
import com.tigerpenguin.places.model.PlaceType;
import com.tigerpenguin.places.model.PriceLevel;
import com.tigerpenguin.places.response.PlaceSearchResponse;
import com.tigerpenguin.places.responsehandler.PlacesResponseHandler;

public abstract class PlaceSearchRequest<SearchRequestT extends PlaceSearchRequest,
        SearchResponseT extends PlaceSearchResponse> extends PlacesRequest<SearchRequestT, SearchResponseT> {

    protected static final String PARAM_LOCATION = "location";
    protected static final String PARAM_RADIUS = "radius";
    protected static final String PARAM_NAME = "name";
    protected static final String PARAM_TYPES = "types";
    protected static final String PARAM_KEYWORD = "keyword";
    protected static final String PARAM_LANGUAGE = "language";
    protected static final String PARAM_MIN_PRICE = "minprice";
    protected static final String PARAM_MAX_PRICE = "maxprice";
    protected static final String PARAM_OPEN_NOW = "opennow";
    protected static final String PARAM_PAGE_TOKEN = "pagetoken";

    private static final double MAX_LATITUDE = 90.0;
    private static final double MIN_LATITUDE = -90.0;
    private static final double MAX_LONGITUDE = 180.0;
    private static final double MIN_LONGITUDE = -180.0;
    private static final int MAX_RADIUS = 50000;

    private final boolean isNextPageSearch;

    protected PlaceSearchRequest(Context context, PlacesResponseHandler<SearchResponseT> placesResponseHandler) {
        super(context, placesResponseHandler);
        isNextPageSearch = false;
    }

    protected PlaceSearchRequest(Context context, String nextPageToken,
                                 PlacesResponseHandler<SearchResponseT> placesResponseHandler) {
        super(context, placesResponseHandler);
        setParameter(PARAM_PAGE_TOKEN, nextPageToken);
        isNextPageSearch = true;
    }

    public final SearchRequestT setMinPrice(PriceLevel minPrice) {
        setParameter(PARAM_MIN_PRICE, String.valueOf(minPrice.getJsonValue()));
        return getThis();
    }

    public final SearchRequestT setMaxPrice(PriceLevel maxPrice) {
        setParameter(PARAM_MAX_PRICE, String.valueOf(maxPrice.getJsonValue()));
        return getThis();
    }

    public final SearchRequestT setOpenNow(boolean openNow) {
        setParameter(PARAM_OPEN_NOW, String.valueOf(openNow));
        return getThis();
    }

    public final SearchRequestT setLanguage(Language language) {
        setParameter(PARAM_LANGUAGE, language.getCode());
        return getThis();
    }

    protected static final void checkLatLong(double latitude, double longitude) {
        if (latitude < MIN_LATITUDE || latitude > MAX_LATITUDE
                || longitude < MIN_LONGITUDE || longitude > MAX_LONGITUDE) {
            throw new IllegalArgumentException("Latitude and longitude must be valid");
        }
    }

    protected static final void checkRadius(int radius) {
        if (radius < 0 || radius > MAX_RADIUS) {
            throw new IllegalArgumentException("Radius can not be greater than " + MAX_RADIUS);
        }
    }

    protected static final String typesToParameter(PlaceType[] placeTypes) {
        StringBuilder sb = new StringBuilder();
        if (placeTypes != null) {
            boolean firstItem = true;
            for (PlaceType placeType : placeTypes) {
                if (firstItem) {
                    firstItem = false;
                } else {
                    sb.append("|");
                }
                sb.append(placeType.getJsonValue());
            }
        }
        return sb.toString();
    }

    protected final boolean isNextPageSearch() {
        return isNextPageSearch;
    }

    @Override
    protected void validate() throws InvalidRequestException {
        super.validate();
        if (isNextPageSearch) {
            checkParameterDefined(PARAM_PAGE_TOKEN, "Page token must be defined for next page search");
        }
    }
}




Java Source Code List

com.tigerpenguin.demo.places.PlaceDetailActivity.java
com.tigerpenguin.demo.places.PlaceResultAdapter.java
com.tigerpenguin.demo.places.PlaceResultsFragment.java
com.tigerpenguin.demo.places.PlaceReviewAdapter.java
com.tigerpenguin.demo.places.PlaceReviewsFragment.java
com.tigerpenguin.demo.places.PlaceThumbnailAdapter.java
com.tigerpenguin.demo.places.PlaceThumbnailsFragment.java
com.tigerpenguin.demo.places.PlacesDemo.java
com.tigerpenguin.places.PlacesTest.java
com.tigerpenguin.places.deserializer.HtmlStringDeserializer.java
com.tigerpenguin.places.deserializer.PlaceTypeDeserializer.java
com.tigerpenguin.places.model.AddressComponent.java
com.tigerpenguin.places.model.AspectRating.java
com.tigerpenguin.places.model.AspectType.java
com.tigerpenguin.places.model.DayOfWeek.java
com.tigerpenguin.places.model.DayTime.java
com.tigerpenguin.places.model.Geometry.java
com.tigerpenguin.places.model.JsonModel.java
com.tigerpenguin.places.model.Language.java
com.tigerpenguin.places.model.OpeningHours.java
com.tigerpenguin.places.model.Period.java
com.tigerpenguin.places.model.Photo.java
com.tigerpenguin.places.model.PlaceDetail.java
com.tigerpenguin.places.model.PlaceLocation.java
com.tigerpenguin.places.model.PlaceType.java
com.tigerpenguin.places.model.Place.java
com.tigerpenguin.places.model.PriceLevel.java
com.tigerpenguin.places.model.RankBy.java
com.tigerpenguin.places.model.Review.java
com.tigerpenguin.places.model.StatusCode.java
com.tigerpenguin.places.request.InvalidRequestException.java
com.tigerpenguin.places.request.NearbySearchRequestTest.java
com.tigerpenguin.places.request.NearbySearchRequest.java
com.tigerpenguin.places.request.PlaceDetailRequestTest.java
com.tigerpenguin.places.request.PlaceDetailRequest.java
com.tigerpenguin.places.request.PlaceSearchRequestTest.java
com.tigerpenguin.places.request.PlaceSearchRequest.java
com.tigerpenguin.places.request.PlacesRequestTest.java
com.tigerpenguin.places.request.PlacesRequest.java
com.tigerpenguin.places.request.RequestTest.java
com.tigerpenguin.places.response.NearbySearchResponseFactory.java
com.tigerpenguin.places.response.NearbySearchResponse.java
com.tigerpenguin.places.response.PlaceDetailResponseFactory.java
com.tigerpenguin.places.response.PlaceDetailResponse.java
com.tigerpenguin.places.response.PlaceSearchResponse.java
com.tigerpenguin.places.response.PlacesResponseFactory.java
com.tigerpenguin.places.response.PlacesResponse.java
com.tigerpenguin.places.responsehandler.NearbySearchHandlerFragment.java
com.tigerpenguin.places.responsehandler.PlaceDetailResponseHandlerFragment.java
com.tigerpenguin.places.responsehandler.PlacesResponseHandler.java
com.tigerpenguin.widget.simpleratingbar.MockAttributes.java
com.tigerpenguin.widget.simpleratingbar.SimpleRatingBarAttributes.java
com.tigerpenguin.widget.simpleratingbar.SimpleRatingBarTest.java
com.tigerpenguin.widget.simpleratingbar.SimpleRatingBar.java