Back to project page AndroidPlaces.
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.
/* * Copyright (C) 2014 Brian Lee/*w w w.j ava 2s .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.ListFragment; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import com.tigerpenguin.places.model.Place; import com.tigerpenguin.places.request.InvalidRequestException; import com.tigerpenguin.places.response.NearbySearchResponse; import com.tigerpenguin.places.responsehandler.PlacesResponseHandler; public class PlaceResultsFragment extends ListFragment implements PlacesResponseHandler<NearbySearchResponse>, View.OnClickListener { private PlaceResultAdapter placeResultAdapter; private TextView attributions; private Button loadMore; private NearbySearchResponse lastSearchResponse; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.places_results, container, false); placeResultAdapter = new PlaceResultAdapter(getActivity()); attributions = (TextView) root.findViewById(R.id.attributions); loadMore = (Button) root.findViewById(R.id.loadMore); loadMore.setOnClickListener(this); setListAdapter(placeResultAdapter); return root; } public void setOrigin(double latitude, double longitude) { placeResultAdapter.setOrigin(latitude, longitude); } @Override public void handleResponse(NearbySearchResponse response) { lastSearchResponse = response; placeResultAdapter.addAll(response.getResults()); if (lastSearchResponse.hasHtmlAttributions()) { attributions.setVisibility(View.VISIBLE); attributions.setText(lastSearchResponse.getSpannedHtmlAttribution()); } else { attributions.setVisibility(View.GONE); } loadMore.setEnabled(lastSearchResponse.hasMoreResults()); } public void clear() { placeResultAdapter.clear(); lastSearchResponse = null; } @Override public void onClick(View view) { loadMore.setEnabled(false); if (lastSearchResponse != null && lastSearchResponse.hasMoreResults()) { try { lastSearchResponse.getMoreResults(getActivity(), this); } catch (InvalidRequestException ire) { loadMore.setEnabled(true); } } } @Override public void onListItemClick(ListView listView, View view, int position, long id) { Place selectedPlace = placeResultAdapter.getItem(position); Intent intent = new Intent(getActivity(), PlaceDetailActivity.class); intent.putExtra(PlaceDetailActivity.EXTRA_PLACE_NAME, selectedPlace.getName()); intent.putExtra(PlaceDetailActivity.EXTRA_PLACE_ID, selectedPlace.getPlaceId()); startActivity(intent); } }