Android Open Source - CoHomeAndroid View Ad






From Project

Back to project page CoHomeAndroid.

License

The source code is released under:

Apache License

If you think the Android project CoHomeAndroid 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

package com.cohome.android;
/*from ww  w.ja  va 2 s. c  o m*/

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.androidspike.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class ViewAd extends Activity {
    private static final String LOG_TAG = "CoHomeAndroid";
    private GoogleMap mMap;
   
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.activity_view_ad);
    JSONObject j;
    Intent intent = getIntent();
    String response = intent.getStringExtra(SearchAd.EXTRA_MESSAGE);
    //System.out.println(message);
    try {
      j = new JSONObject(response);
    
      mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
      CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(new LatLng(Double.parseDouble(j.getJSONObject("coordinate").getString("lat")),Double.parseDouble(j.getJSONObject("coordinate").getString("lng"))))  // Sets the center of the map to Mountain View
        .zoom(13)                   // Sets the zoom
        .build();                   // Creates a CameraPosition from the builder
      mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

      JSONArray a = j.getJSONArray("annunci");
      for(int index=0; index<a.length()-1;index++)
        addMarker((JSONObject)a.get(index));  
    } catch (JSONException e) {
      e.printStackTrace();
    }
   }
  public void addMarker(JSONObject j){
    try {
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    mMap.addMarker(new MarkerOptions()
              .position(new LatLng(Double.parseDouble(j.getString("lat")),Double.parseDouble(j.getString("lng"))))
              .title(j.getString("titolo")) );
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.view_ad, menu);
    return true;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      return true;
    }
    return super.onOptionsItemSelected(item);
  }
  
}




Java Source Code List

com.cohome.android.ActivityGPS.java
com.cohome.android.MainActivity.java
com.cohome.android.SearchAd.java
com.cohome.android.ViewAd.java
com.cohome.util.PlacesAutoCompleteAdapter.java