Android Open Source - RateBeer-Mobile Place View






From Project

Back to project page RateBeer-Mobile.

License

The source code is released under:

GNU General Public License

If you think the Android project RateBeer-Mobile 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 2010, Jesper Fussing Mrk//  w ww  .  j a v  a2s  . co m
 *
 * This file is part of Ratebeer Mobile for Android.
 *
 * Ratebeer Mobile is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ratebeer Mobile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ratebeer Mobile.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.moerks.ratebeermobile;

import java.util.List;

import android.content.Intent;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import dk.moerks.ratebeermobile.overlays.PinOverlayItem;
import dk.moerks.ratebeermobile.util.StringUtils;

public class PlaceView extends MapActivity {
  //private String placeId = null;
  private String placeName = null;
  private String placeType = null;
  private String placeAddress = null;
  private String placeCity = null;
  //private String placeStateId = null;
  //private String placeCountryId = null;
  //private String placePostalCode = null;
  private String placePhoneNumber = null;
  private String placeAvgRating = null;
  private String placePhoneAC = null;
  private String placeLatitude = null;
  private String placeLongitude = null;
  //private String placeDistance = null;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.place_view);

        Bundle extras = getIntent().getExtras();
        if(extras !=null) {
          //placeId = extras.getString("PLACEID");
          placeName = extras.getString("PLACENAME");
          placeType = extras.getString("PLACETYPE");
          placeAddress = extras.getString("PLACEADDRESS");
          placeCity = extras.getString("PLACECITY");
          //placeStateId = extras.getString("PLACESTATEID");
          //placeCountryId = extras.getString("PLACECOUNTRYID");
          placePhoneNumber = extras.getString("PLACEPHONENUMBER");
          placeAvgRating = extras.getString("PLACEAVGRATING");
          placePhoneAC = extras.getString("PLACEPHONEAC");
          placeLatitude = extras.getString("PLACELAT");
          placeLongitude = extras.getString("PLACELNG");
          //placeDistance = extras.getString("PLACEDISTANCE");
        } else {
          //placeId = "Not Set!";
          placeName = "Not Set!";
          placeType = "Not Set!";
          placeAddress = "Not Set!";
          placeCity = "Not Set!";
          //placeStateId = "Not Set!";
          //placeCountryId = "Not Set!";
          placePhoneNumber = "Not Set!";
          placeAvgRating = "Not Set!";
          placePhoneAC = "Not Set!";
          placeLatitude = "Not Set!";
          placeLongitude = "Not Set!";
          //placeDistance = "Not Set!";
        }

        TextView placeNameText = (TextView) findViewById(R.id.place_view_name);
        placeNameText.setText(placeName);

        TextView placeTypeText = (TextView) findViewById(R.id.place_view_type);
        placeTypeText.setText(placeTypeToString(placeType));

        TextView placeRatingText = (TextView) findViewById(R.id.place_view_rating);
        if(!placeAvgRating.equalsIgnoreCase("null")){
          placeRatingText.setText(getText(R.string.place_avgrating) + " " + StringUtils.roundNumberString(placeAvgRating));
        } else {
          placeRatingText.setText(getText(R.string.place_avgrating) + " N/A - Not enough ratings!");
        }
        TextView placeAddressText = (TextView) findViewById(R.id.place_view_address);
        placeAddressText.setText(placeAddress);

        TextView placeCityText = (TextView) findViewById(R.id.place_view_city);
        placeCityText.setText(placeCity);

      RelativeLayout placeAddress = (RelativeLayout) findViewById(R.id.place_address);
      placeAddress.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        startRouteIntent();
      }
    });

        TextView placePhoneText = (TextView) findViewById(R.id.place_view_phone);
      placePhoneText.setText(getFormattedPhoneNumber());

      RelativeLayout placePhone = (RelativeLayout) findViewById(R.id.place_phone);
      placePhone.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        startCallIntent();
      }
    });

        MapView map = (MapView) findViewById(R.id.place_view_map);
        MapController mc = map.getController();

        //Add this place to the map
        List<Overlay> listOfOverlays = map.getOverlays();

        double lat = Double.parseDouble(placeLatitude);
        double lng = Double.parseDouble(placeLongitude);
        
        Drawable pin = this.getResources().getDrawable(R.drawable.redpushpin);
        Rect pinRect = new Rect(0, 0, 48, 48);
        pinRect.offset(0, -48);
        pin.setBounds(pinRect);
        PinOverlayItem pinOverlays = new PinOverlayItem(pin);
        GeoPoint point = new GeoPoint((int)(lat * 1E6),(int)(lng * 1E6));
        OverlayItem overlayitem = new OverlayItem(point, placeName, placeName);
        pinOverlays.addItem(overlayitem);
        listOfOverlays.add(pinOverlays); 

        mc.animateTo(point);
        mc.setZoom(15);
  }
  
  private String getFormattedPhoneNumber() {
        String number = placePhoneNumber;
        if(placePhoneAC != null && !placePhoneAC.equalsIgnoreCase("Not Set!") && !placePhoneAC.equalsIgnoreCase("null")){
          number = "(" + placePhoneAC + ") " + placePhoneNumber;
        }
        return number;
  }
  
  /**
   * Starts an intent to call this 'place' (assuming it indeed has a phone number)
   */
  private void startCallIntent() {
    if (getFormattedPhoneNumber() != null && !getFormattedPhoneNumber().equals("")) {
      final Uri callUri = Uri.parse("tel:" + getFormattedPhoneNumber());
      startActivity(new Intent(Intent.ACTION_VIEW, callUri));
    }
  }
  
  /**
   * Starts and intent to plan a route to this 'place'
   */
  private void startRouteIntent() {
    if (placeLatitude != null && !placeLatitude.equals("")) {
      // We cannot actually start a route, but we can ask the Google Maps app to show this place's location
      final Uri geoUri = Uri.parse("geo:" + placeLatitude + "," + placeLongitude + "?q=" + placeName);
      startActivity(new Intent(Intent.ACTION_VIEW, geoUri));
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuItem call = menu.add(0, 0, 0, R.string.menu_item_call);
    call.setIcon(android.R.drawable.ic_menu_call);
    MenuItem route = menu.add(1, 1, 1, R.string.menu_item_route);
    route.setIcon(android.R.drawable.ic_menu_mapmode);
    
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case 0:
      startCallIntent();
      return true;
    case 1:
      startRouteIntent();
      return true;
    }
    
    return false;
  }
  
  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }

  //Private Methods
  private String placeTypeToString(String placeType){
    if(placeType.equalsIgnoreCase("1")){
      return "Brewpub";
    } else if(placeType.equalsIgnoreCase("2")){
      return "Bar";
    } else if(placeType.equalsIgnoreCase("3")){
      return "Beer Store";
    } else if(placeType.equalsIgnoreCase("4")){
      return "Restaurant";
    } else if(placeType.equalsIgnoreCase("5")){
      return "Brewery";
    } else if(placeType.equalsIgnoreCase("6")){
      return "Homebrew Shop";
    } else {
      return "Unknown!";
    }
  }
}




Java Source Code List

com.github.droidfu.DroidFuApplication.java
com.github.droidfu.DroidFu.java
com.github.droidfu.activities.BetterActivityHelper.java
com.github.droidfu.activities.BetterActivity.java
com.github.droidfu.activities.BetterDefaultActivity.java
com.github.droidfu.activities.BetterListActivity.java
com.github.droidfu.adapters.ListAdapterWithProgress.java
com.github.droidfu.concurrent.BetterAsyncTaskCallable.java
com.github.droidfu.concurrent.BetterAsyncTask.java
com.github.droidfu.services.BetterService.java
dk.moerks.ratebeermobile.BeerMail.java
dk.moerks.ratebeermobile.BeerView.java
dk.moerks.ratebeermobile.Home.java
dk.moerks.ratebeermobile.MailAction.java
dk.moerks.ratebeermobile.MailView.java
dk.moerks.ratebeermobile.PlaceView.java
dk.moerks.ratebeermobile.Places.java
dk.moerks.ratebeermobile.RateBeer.java
dk.moerks.ratebeermobile.Rate.java
dk.moerks.ratebeermobile.Rating.java
dk.moerks.ratebeermobile.Search.java
dk.moerks.ratebeermobile.Settings.java
dk.moerks.ratebeermobile.activity.BetterRBActivity.java
dk.moerks.ratebeermobile.activity.BetterRBDefaultActivity.java
dk.moerks.ratebeermobile.activity.BetterRBListActivity.java
dk.moerks.ratebeermobile.activity.RBActivity.java
dk.moerks.ratebeermobile.adapters.FeedAdapter.java
dk.moerks.ratebeermobile.adapters.MessageAdapter.java
dk.moerks.ratebeermobile.adapters.PlacesAdapter.java
dk.moerks.ratebeermobile.adapters.ReviewAdapter.java
dk.moerks.ratebeermobile.adapters.SearchAdapter.java
dk.moerks.ratebeermobile.exceptions.LocationException.java
dk.moerks.ratebeermobile.exceptions.LoginException.java
dk.moerks.ratebeermobile.exceptions.NetworkException.java
dk.moerks.ratebeermobile.exceptions.RBException.java
dk.moerks.ratebeermobile.exceptions.RBParserException.java
dk.moerks.ratebeermobile.io.NetBroker.java
dk.moerks.ratebeermobile.io.TwitterPoster.java
dk.moerks.ratebeermobile.overlays.PinOverlayItem.java
dk.moerks.ratebeermobile.receivers.BeerMailServiceReceiver.java
dk.moerks.ratebeermobile.receivers.BootReceiver.java
dk.moerks.ratebeermobile.services.BeerMailService.java
dk.moerks.ratebeermobile.services.BeerSearchHistoryProvider.java
dk.moerks.ratebeermobile.task.BarcodeLookupTask.java
dk.moerks.ratebeermobile.task.BetterRBTask.java
dk.moerks.ratebeermobile.task.DeleteBeermailTask.java
dk.moerks.ratebeermobile.task.PostTwitterStatusTask.java
dk.moerks.ratebeermobile.task.RefreshFriendFeedTask.java
dk.moerks.ratebeermobile.task.RetrieveBeerImageTask.java
dk.moerks.ratebeermobile.task.RetrieveBeerInfoTask.java
dk.moerks.ratebeermobile.task.RetrieveBeerReviewsTask.java
dk.moerks.ratebeermobile.task.RetrieveBeermailTask.java
dk.moerks.ratebeermobile.task.RetrieveBeermailsTask.java
dk.moerks.ratebeermobile.task.RetrievePlacesTask.java
dk.moerks.ratebeermobile.task.RetrieveRatingTask.java
dk.moerks.ratebeermobile.task.RetrieveUserIdTask.java
dk.moerks.ratebeermobile.task.SaveRatingTask.java
dk.moerks.ratebeermobile.task.SearchTask.java
dk.moerks.ratebeermobile.task.SendBeermailTask.java
dk.moerks.ratebeermobile.task.SetDrinkingBeerIdTask.java
dk.moerks.ratebeermobile.task.SetDrinkingStatusTask.java
dk.moerks.ratebeermobile.util.BCPParser.java
dk.moerks.ratebeermobile.util.RBJSONParser.java
dk.moerks.ratebeermobile.util.RBParser.java
dk.moerks.ratebeermobile.util.StringUtils.java
dk.moerks.ratebeermobile.vo.BeerInfo.java
dk.moerks.ratebeermobile.vo.Feed.java
dk.moerks.ratebeermobile.vo.MessageHeader.java
dk.moerks.ratebeermobile.vo.Message.java
dk.moerks.ratebeermobile.vo.PlacesInfo.java
dk.moerks.ratebeermobile.vo.RatingData.java
dk.moerks.ratebeermobile.vo.Review.java
dk.moerks.ratebeermobile.vo.SearchResult.java