Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

my changes attached #1

Merged
merged 1 commit into from

2 participants

David Parker Khalid Alharbi
David Parker

No description provided.

Khalid Alharbi kalharbi merged commit d017651 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2012
  1. David Parker
This page is out of date. Refresh to see the latest.
148 res/layout/citydetails.xml
View
@@ -1,74 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
- <ImageView
- android:id="@+id/flickrcity_image"
- android:src="@drawable/flickrcity_launcher_32"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:contentDescription="FlickrCity"/>
-
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/textviewtitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="FlickrCity"
- android:textSize="25dp"/>
- </LinearLayout>
- <TextView
- android:id="@+id/textviewcityname"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="20dp"/>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
-
- <TextView
- android:id="@+id/textviewlat"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Latitude:"
- android:textSize="18dp"/>
- <TextView
- android:id="@+id/textviewlatVal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="18dp"/>
- </LinearLayout>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
-
- <TextView
- android:id="@+id/textviewlng"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Longitude:"
- android:textSize="18dp"/>
- <TextView
- android:id="@+id/textviewlngVal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="18dp"/>
- </LinearLayout>
-
- <Button
- android:id="@+id/view_flickr_pictures"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="view Flickr pictures" />
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <TextView
+ android:id="@+id/corestext"
+ android:layout_width="20dp"
+ android:layout_height="20dp" />
+ <ImageView
+ android:id="@+id/flickrcity_image"
+ android:src="@drawable/flickrcity_launcher_32"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="FlickrCity" />
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/textviewtitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="FlickrCity"
+ android:textSize="25dp" />
+ </LinearLayout>
+ <TextView
+ android:id="@+id/textviewcityname"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="20dp" />
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/textviewlat"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Latitude:"
+ android:textSize="18dp" />
+ <TextView
+ android:id="@+id/textviewlatVal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="18dp" />
+ </LinearLayout>
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/textviewlong"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Longitude:"
+ android:textSize="18dp" />
+ <TextView
+ android:id="@+id/textviewlongVal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="18dp" />
+ </LinearLayout>
+
+ <Button
+ android:id="@+id/view_flickr_pictures"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="view Flickr pictures" />
</LinearLayout>
52 res/layout/main.xml
View
@@ -1,28 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <EditText
- android:id="@+id/locationedittext"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@android:drawable/editbox_background"
- android:hint="@string/location_search"
- android:inputType="textPostalAddress"/>
- </LinearLayout>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
- <com.google.android.maps.MapView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/mapview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:clickable="true"
- android:apiKey="0nPbAvuDMJWq7-mfR2dkquZuR57FTJX3ZCUEFJA"/>
- </LinearLayout>
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <EditText
+ android:id="@+id/locationedittext"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@android:drawable/editbox_background"
+ android:hint="@string/location_search"
+ android:inputType="textPostalAddress" />
+ </LinearLayout>
+
+ <com.google.android.maps.MapView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mapview"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:clickable="true"
+ android:apiKey="0nPbAvuDMJWq7-mfR2dkquZuR57FTJX3ZCUEFJA" />
+</LinearLayout>
33 src/com/FlickrCity/FlickrCityAndroid/City.java
View
@@ -0,0 +1,33 @@
+package com.FlickrCity.FlickrCityAndroid;
+
+public class City {
+
+ private String name;
+ private int latitude;
+ private int longitude;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(int latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(int longitude) {
+ this.longitude = longitude;
+ }
+
+}
58 src/com/FlickrCity/FlickrCityAndroid/CityDetailsView.java
View
@@ -1,32 +1,46 @@
package com.FlickrCity.FlickrCityAndroid;
-import android.app.ListActivity;
+import android.app.Activity;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.TextView;
-
-public class CityDetailsView extends ListActivity {
+public class CityDetailsView extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.citydetails);
-
- // get city info
- Bundle extras = getIntent().getExtras();
- if(extras !=null) {
- String city=extras.getString("city");
- int lat = extras.getInt("lat");
- int lng = extras.getInt("lng");
-
- }
-
- final Button button = (Button) findViewById(R.id.view_flickr_pictures);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Perform action on click
- }
- });
-
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.citydetails);
+
+// // setup concurrency
+// final int numberOfCores = Runtime.getRuntime().availableProcessors();
+// final double blockingCoefficient = 0.9;
+// final int poolSize = (int) (numberOfCores / (1 - blockingCoefficient));
+// TextView cores = (TextView) findViewById(R.id.corestext);
+// cores.setText(String.valueOf(poolSize));
+
+ // get city info
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ String city = extras.getString("NAME");
+ int lat = extras.getInt("LAT");
+ int lng = extras.getInt("LONG");
+ TextView citytext = (TextView) findViewById(R.id.textviewcityname);
+ Log.v("CITY", city);
+ TextView lattext = (TextView) findViewById(R.id.textviewlatVal);
+ TextView longtext = (TextView) findViewById(R.id.textviewlongVal);
+ citytext.setText(city);
+ lattext.setText(String.valueOf(lat));
+ longtext.setText(String.valueOf(lng));
+ }
+
+ final Button button = (Button) findViewById(R.id.view_flickr_pictures);
+ button.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ // Perform action on click
+ }
+ });
+
}
}
260 src/com/FlickrCity/FlickrCityAndroid/MapViewerActivity.java
View
@@ -27,7 +27,6 @@
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
-import com.google.android.maps.OverlayItem;
public class MapViewerActivity extends MapActivity implements LocationListener {
private static final String TAG = "MapViewActivity";
@@ -36,135 +35,131 @@
private String provider;
private MyItemizedOverlay itemizedoverlay;
private List<Overlay> mapOverlays;
- private Geocoder geocoder=null;
- private ProgressDialog progDialog=null;
+ private Geocoder geocoder = null;
+ private ProgressDialog progDialog = null;
List<Address> addressList;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- mapView = (MapView) findViewById(R.id.mapview);
- mapView.setBuiltInZoomControls(true);
-
- mapOverlays = mapView.getOverlays();
- Drawable drawable = this.getResources().getDrawable(R.drawable.mapmarker);
- itemizedoverlay = new MyItemizedOverlay(drawable, this);
-
- provider=LocationManager.GPS_PROVIDER;
- displayCurrentGeoLocation();
-
- geocoder=new Geocoder(this);
-
- final EditText edittext = (EditText) findViewById(R.id.locationedittext);
- edittext.setOnKeyListener(new OnKeyListener() {
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- // If the event is a key-down event on the "enter" button
- if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
- (keyCode == KeyEvent.KEYCODE_ENTER)) {
- // search for the entered location
- progDialog=ProgressDialog.show(MapViewerActivity.this,"Progressing...","Finding location...",
- true,false);
- searchForLocation(edittext.getText().toString());
-
- return true;
- }
- return false;
- }
- });
-
- }
-
- public void displayCurrentGeoLocation(){
- locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
- if(locationmanager.isProviderEnabled(provider))
- {
- Location location = locationmanager.getLastKnownLocation(provider);
- if(location!=null){
- int longitude = (int)(location.getLongitude()*1e6);
- int latitude = (int)(location.getLatitude()*1e6);
- addOverlayItems(latitude, longitude);
- }
- else
- Toast.makeText(this, "Unknown location! ",
- Toast.LENGTH_SHORT).show();
- }
- }
-
- // add marker on the map
- public void addOverlayItems(int latitude, int longitude){
-
- String city="";
- GeoPoint point = new GeoPoint(latitude,longitude);
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mapView = (MapView) findViewById(R.id.mapview);
+ mapView.setBuiltInZoomControls(true);
+
+ mapOverlays = mapView.getOverlays();
+ Drawable drawable = this.getResources().getDrawable(R.drawable.mapmarker);
+ itemizedoverlay = new MyItemizedOverlay(drawable, this);
+
+ provider = LocationManager.GPS_PROVIDER;
+ displayCurrentGeoLocation();
+
+ geocoder = new Geocoder(this);
+
+ final EditText edittext = (EditText) findViewById(R.id.locationedittext);
+ edittext.setOnKeyListener(new OnKeyListener() {
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ // If the event is a key-down event on the "enter" button
+ if ((event.getAction() == KeyEvent.ACTION_DOWN)
+ && (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // search for the entered location
+ progDialog = ProgressDialog.show(MapViewerActivity.this, "Progressing...",
+ "Finding location...", true, false);
+ searchForLocation(edittext.getText().toString());
+
+ return true;
+ }
+ return false;
+ }
+ });
+
+ }
+
+ public void displayCurrentGeoLocation() {
+ locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
+ if (locationmanager.isProviderEnabled(provider)) {
+ Location location = locationmanager.getLastKnownLocation(provider);
+ if (location != null) {
+ int longitude = (int) (location.getLongitude() * 1e6);
+ int latitude = (int) (location.getLatitude() * 1e6);
+ addOverlayItems(latitude, longitude);
+ } else
+ Toast.makeText(this, "Unknown location! ", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ // add marker on the map
+ public void addOverlayItems(int latitude, int longitude) {
+ City city = new City();
+ String name = "";
+ GeoPoint point = new GeoPoint(latitude, longitude);
mapView.getController().setZoom(7);
mapView.getController().animateTo(point);
- try{
+ try {
Geocoder gcd = new Geocoder(MapViewerActivity.this, Locale.getDefault());
- List<Address> addresses = gcd.getFromLocation(latitude/1e6, longitude/1e6, 1);
- if (addresses.size() > 0)
- city=addresses.get(0).getLocality()+"\nlatitude:"+latitude+"\nlongitude: "+longitude;
+ List<Address> addresses = gcd.getFromLocation(latitude / 1e6, longitude / 1e6, 1);
+ if (addresses.size() > 0)
+ name = addresses.get(0).getLocality();
+ city.setName(name);
+ city.setLatitude(latitude);
+ city.setLongitude(longitude);
+ } catch (IOException e) {
+ Log.e(TAG, "Can't connect to Geocoder", e);
}
- catch (IOException e) {
- Log.e(TAG, "Can't connect to Geocoder", e);
- }
-
- OverlayItem overlayitem = new OverlayItem(point, "City",city);
+
+ MyOverlay overlayitem = new MyOverlay(point, "City", name);
+ overlayitem.setCity(city);
+ // overlayitem.
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
- }
-
- /* Search for location */
- public void searchForLocation(final String locName){
- // Run background thread to handle time-consuming search operation.
- Thread th=new Thread(){
- public void run(){
- try{
- // search for location
- addressList=geocoder.getFromLocationName(locName, 5);
- // send message to handler to process results
- uiCallback.sendEmptyMessage(0);
-
- }
-
- catch(IOException e){
- e.printStackTrace();
- }
- }
- };
- th.start();
- }
-
- private Handler uiCallback=new Handler(){
- @Override
- public void handleMessage(Message msg){
- // dismiss the dialog
- progDialog.dismiss();
-
- if(addressList!=null&&addressList.size()>0){
- int lat=(int)(addressList.get(0).getLatitude()*1e6);
- int lng=(int)(addressList.get(0).getLongitude()*1e6);
- //GeoPoint pt=new GeoPoint(lat, lng);
- //mapView.getController().setZoom(7);
- //mapView.getController().setCenter(pt);
- addOverlayItems(lat, lng);
-
- }
- else{
- Dialog foundNothingDlg=new AlertDialog.Builder(MapViewerActivity.this)
- .setIcon(0)
- .setTitle("Failed to find location")
- .setPositiveButton("OK", null)
- .setMessage("Ooops! Location not Found! Go back, friend, go back!")
- .create();
- foundNothingDlg.show();
- }
- }
-
- };
-
-
+ }
+
+ /* Search for location */
+ public void searchForLocation(final String locName) {
+ // Run background thread to handle time-consuming search operation.
+ Thread th = new Thread() {
+ public void run() {
+ try {
+ // search for location
+ addressList = geocoder.getFromLocationName(locName, 5);
+ // send message to handler to process results
+ uiCallback.sendEmptyMessage(0);
+ }
+
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ th.start();
+ }
+
+ private Handler uiCallback = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ // dismiss the dialog
+ progDialog.dismiss();
+
+ if (addressList != null && addressList.size() > 0) {
+ int lat = (int) (addressList.get(0).getLatitude() * 1e6);
+ int lng = (int) (addressList.get(0).getLongitude() * 1e6);
+ // GeoPoint pt=new GeoPoint(lat, lng);
+ // mapView.getController().setZoom(7);
+ // mapView.getController().setCenter(pt);
+ addOverlayItems(lat, lng);
+
+ } else {
+ Dialog foundNothingDlg = new AlertDialog.Builder(MapViewerActivity.this).setIcon(0)
+ .setTitle("Failed to find location").setPositiveButton("OK", null)
+ .setMessage("Ooops! Location not Found! Go back, friend, go back!")
+ .create();
+ foundNothingDlg.show();
+ }
+ }
+
+ };
+
/* Request updates at startup */
@Override
protected void onResume() {
@@ -185,28 +180,27 @@ public void onLocationChanged(Location location) {
int longitude = (int) (location.getLongitude());
addOverlayItems(latitude, longitude);
}
+
@Override
public void onProviderEnabled(String provider) {
- Toast.makeText(this, "Enabled new provider " + provider,
- Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, "Enabled new provider " + provider, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
- Toast.makeText(this, "Disabled provider " + provider,
- Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, "Disabled provider " + provider, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ protected boolean isRouteDisplayed() {
+ return false;
}
-
- @Override
- protected boolean isRouteDisplayed() {
- return false;
- }
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
-
+
}
}
56 src/com/FlickrCity/FlickrCityAndroid/MyItemizedOverlay.java
View
@@ -2,55 +2,61 @@
import java.util.ArrayList;
-import android.app.AlertDialog;
import android.content.Context;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
-public class MyItemizedOverlay extends ItemizedOverlay {
-
+public class MyItemizedOverlay extends ItemizedOverlay<MyOverlay> {
+
private ArrayList<OverlayItem> myOverlays = new ArrayList<OverlayItem>();
private Context myContext;
-
+
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
-
+
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
- super(boundCenterBottom(defaultMarker));
- myContext = context;
- }
-
+ super(boundCenterBottom(defaultMarker));
+ myContext = context;
+ }
+
// Add new OverlayItems to the ArrayLis
public void addOverlay(OverlayItem overlay) {
- myOverlays.add(overlay);
- populate(); // this will call createItem(int) in the ItemizedOverlay to retrieve each OverlayItem
+ myOverlays.add(overlay);
+ populate(); // this will call createItem(int) in the ItemizedOverlay to
+ // retrieve each OverlayItem
}
-
+
// Return the OverlayItem from the position specified by the given integer.
@Override
- protected OverlayItem createItem(int i) {
- return myOverlays.get(i);
+ protected MyOverlay createItem(int i) {
+ return (MyOverlay) myOverlays.get(i);
}
-
+
// Return the current number of items in the ArrayList.
@Override
public int size() {
- return myOverlays.size();
+ return myOverlays.size();
}
-
+
// Handle the event when an item is tapped by the user
@Override
protected boolean onTap(int index) {
- OverlayItem item = myOverlays.get(index);
-
- // TODO: Open up a new activity (CityDetailsView) instead of the AlertDialog.
- AlertDialog.Builder dialog = new AlertDialog.Builder(myContext);
- dialog.setTitle(item.getTitle());
- dialog.setMessage(item.getSnippet());
- dialog.show();
- return true;
+ MyOverlay item = (MyOverlay) myOverlays.get(index);
+ Intent i = new Intent(myContext, CityDetailsView.class);
+ i.putExtra("NAME", item.getCity().getName());
+ i.putExtra("LAT", item.getCity().getLatitude());
+ i.putExtra("LONG", item.getCity().getLongitude());
+ myContext.startActivity(i);
+ // TODO: Open up a new activity (CityDetailsView) instead of the
+ // AlertDialog.
+ // AlertDialog.Builder dialog = new AlertDialog.Builder(myContext);
+ // dialog.setTitle(item.getTitle());
+ // dialog.setMessage(item.getSnippet());
+ // dialog.show();
+ return true;
}
}
21 src/com/FlickrCity/FlickrCityAndroid/MyOverlay.java
View
@@ -0,0 +1,21 @@
+package com.FlickrCity.FlickrCityAndroid;
+
+import com.google.android.maps.GeoPoint;
+
+public class MyOverlay extends com.google.android.maps.OverlayItem {
+
+ private City city;
+
+ public MyOverlay(GeoPoint point, String title, String snippet) {
+ super(point, title, snippet);
+ }
+
+ public void setCity(City model) {
+ this.city = model;
+ }
+
+ public City getCity() {
+ return this.city;
+ }
+
+}
Something went wrong with that request. Please try again.