Android Open Source - AndroidPlaces Place Detail Activity






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 w w.  ja v  a  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.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.tigerpenguin.places.model.Photo;
import com.tigerpenguin.places.model.PlaceDetail;
import com.tigerpenguin.places.model.Review;
import com.tigerpenguin.places.request.InvalidRequestException;
import com.tigerpenguin.places.request.PlaceDetailRequest;
import com.tigerpenguin.places.responsehandler.PlaceDetailResponseHandlerFragment;
import com.tigerpenguin.places.responsehandler.PlacesResponseHandler;
import com.tigerpenguin.places.response.PlaceDetailResponse;

import java.util.List;

import static com.tigerpenguin.demo.places.PlaceThumbnailsFragment.ThumbnailClickListener;
import static com.tigerpenguin.places.responsehandler.PlaceDetailResponseHandlerFragment.PlaceDetailResponseHandler;

public class PlaceDetailActivity extends Activity
        implements PlaceDetailResponseHandler, ThumbnailClickListener {

    public static final String EXTRA_PLACE_NAME = "EXTRA_PLACE_NAME";
    public static final String EXTRA_PLACE_ID = "EXTRA_PLACE_ID";
    private static final String TAG_PLACE_DETAIL_HANDLER = "TAG_PLACE_DETAIL_HANDLER";

    private ImageView placePhoto;
    private TextView attribution;
    private PlaceReviewsFragment placeReviews;
    private PlaceThumbnailsFragment thumbnailsFragment;
    private PlaceDetailResponseHandlerFragment placeDetailHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.place_detail);
        placePhoto = (ImageView) findViewById(R.id.placePhoto);
        attribution = (TextView) findViewById(R.id.attribution);
        attribution.setMovementMethod(LinkMovementMethod.getInstance());

        setupFragments();
        if (savedInstanceState == null) {
            requestPlaceDetail();
        }
    }

    @Override
    public void handleResponse(PlaceDetailResponse placeDetailResponse) {
        PlaceDetail placeDetail = placeDetailResponse.getPlaceDetail();
        List<Review> reviews = placeDetail.getReviews();
        placeReviews.setReviews(reviews);
        if (placeDetail.hasPhotos()) {
            onThumbnailClicked(placeDetail.getPhotos().get(0));
            thumbnailsFragment.addPhotos(placeDetail.getPhotos());
        }
    }

    @Override
    public void onThumbnailClicked(Photo photo) {
        photo.loadImage(this, placePhoto);
        if (photo.hasHtmlAttributions()) {
            attribution.setVisibility(View.VISIBLE);
            attribution.setText(photo.getSpannedHtmlAttribution());
        } else {
            attribution.setVisibility(View.GONE);
        }
    }

    private void setupFragments() {
        FragmentManager fm = getFragmentManager();
        placeReviews = (PlaceReviewsFragment) fm.findFragmentById(R.id.placeReviews);
        thumbnailsFragment = (PlaceThumbnailsFragment) fm.findFragmentById(R.id.placeThumbnails);
        placeDetailHandler = (PlaceDetailResponseHandlerFragment) fm.findFragmentByTag(TAG_PLACE_DETAIL_HANDLER);
        if (placeDetailHandler == null) {
            placeDetailHandler = new PlaceDetailResponseHandlerFragment();
            fm.beginTransaction().add(placeDetailHandler, TAG_PLACE_DETAIL_HANDLER).commit();
        }
    }

    private void requestPlaceDetail() {
        Intent intent = getIntent();
        String placeId = intent.getStringExtra(EXTRA_PLACE_ID);
        getActionBar().setTitle(intent.getStringExtra(EXTRA_PLACE_NAME));
        PlaceDetailRequest placeDetailRequest = new PlaceDetailRequest(this, placeId, placeDetailHandler);
        try {
            placeDetailRequest.execute();
        } catch (InvalidRequestException e) {
            e.printStackTrace();
        }
    }
}




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