Android Open Source - AndroidPlaces Places Demo






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 .j a  v a  2  s. c  o 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.demo.places;

import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.tigerpenguin.places.model.PlaceType;
import com.tigerpenguin.places.request.InvalidRequestException;
import com.tigerpenguin.places.request.NearbySearchRequest;
import com.tigerpenguin.places.response.NearbySearchResponse;
import com.tigerpenguin.places.responsehandler.NearbySearchHandlerFragment;

import java.util.ArrayList;
import java.util.List;

import static com.tigerpenguin.places.responsehandler.NearbySearchHandlerFragment.NearbySearchResponseHandler;

public class PlacesDemo extends Activity
        implements NearbySearchResponseHandler {

    private static final String TAG_NEARBY_SEARCH_HANDLER = "TAG_NEARBY_SEARCH_HANDLER";

    private Spinner demoLocationSpinner;
    private Spinner placeTypeSpinner;
    private View searchButton;
    private PlaceResultsFragment placeResultsFragment;
    private NearbySearchHandlerFragment nearbySearchHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.places_demo);

        demoLocationSpinner = (Spinner) findViewById(R.id.spinnerLocation);
        placeTypeSpinner = (Spinner) findViewById(R.id.spinnerTypes);
        searchButton = findViewById(R.id.btnSearch);

        setupSpinners();
        setupFragments();
    }

    public void onSearch(View view) {
        searchButton.setEnabled(false);
        int radius = 5000;

        DemoLocation selectedLocation = (DemoLocation) demoLocationSpinner.getSelectedItem();
        placeResultsFragment.setOrigin(selectedLocation.getLatitude(), selectedLocation.getLongitude());

        NearbySearchRequest nearbySearchRequest = new NearbySearchRequest(this, nearbySearchHandler,
                selectedLocation.getLatitude(), selectedLocation.getLongitude(), radius);
        nearbySearchRequest.setTypes((PlaceType) placeTypeSpinner.getSelectedItem());
        try {
            nearbySearchRequest.execute();
        } catch (InvalidRequestException e) {
            e.printStackTrace();
            searchButton.setEnabled(true);
        }
    }

    @Override
    public void handleResponse(NearbySearchResponse response) {
        searchButton.setEnabled(true);
        placeResultsFragment.clear();
        placeResultsFragment.handleResponse(response);
    }

    private void setupSpinners() {
        ArrayAdapter<DemoLocation> demoLocationAdapter = new ArrayAdapter<DemoLocation>(this,
                android.R.layout.simple_spinner_item, getDemoLocations());
        demoLocationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        demoLocationSpinner.setAdapter(demoLocationAdapter);

        ArrayAdapter<PlaceType> placeTypeAdapter = new ArrayAdapter<PlaceType>(this,
                android.R.layout.simple_spinner_item, getTypes());
        placeTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        placeTypeSpinner.setAdapter(placeTypeAdapter);
    }

    private void setupFragments() {
        FragmentManager fm = getFragmentManager();
        placeResultsFragment = (PlaceResultsFragment) fm.findFragmentById(R.id.placeResults);

        nearbySearchHandler = (NearbySearchHandlerFragment) fm.findFragmentByTag(TAG_NEARBY_SEARCH_HANDLER);
        if (nearbySearchHandler == null) {
            nearbySearchHandler = new NearbySearchHandlerFragment();
            fm.beginTransaction().add(nearbySearchHandler, TAG_NEARBY_SEARCH_HANDLER).commit();
        }
    }

    private List<PlaceType> getTypes() {
        ArrayList<PlaceType> types = new ArrayList<PlaceType>();
        types.add(PlaceType.AMUSEMENT_PARK);
        types.add(PlaceType.AQUARIUM);
        types.add(PlaceType.ART_GALLERY);
        types.add(PlaceType.MUSEUM);
        types.add(PlaceType.NIGHT_CLUB);
        types.add(PlaceType.RESTAURANT);
        types.add(PlaceType.SHOPPING_MALL);
        return types;
    }

    private List<DemoLocation> getDemoLocations() {
        ArrayList<DemoLocation> locations = new ArrayList<DemoLocation>();
        locations.add(new DemoLocation("Las Vegas", 36.10896, -115.17825));
        locations.add(new DemoLocation("Chicago", 41.8783, -87.63));
        locations.add(new DemoLocation("New York", 40.7614, -73.9826));
        return locations;
    }

    private static class DemoLocation {
        private final String name;
        private final double latitude;
        private final double longitude;

        DemoLocation(String name, double latitude, double longitude) {
            this.name = name;
            this.latitude = latitude;
            this.longitude = longitude;
        }

        @Override
        public String toString() {
            return name;
        }

        public double getLatitude() {
            return latitude;
        }

        public double getLongitude() {
            return longitude;
        }
    }
}




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