Skip to content

Commit

Permalink
Pequenos refactorings e importação do jar do google play services no
Browse files Browse the repository at this point in the history
projeto para facilitar a importação do projeto.
  • Loading branch information
leandrosilvaferreira committed Mar 23, 2014
1 parent ef75835 commit 00c99f7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Binary file added libs/google-play-services.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-19
target=Google Inc.:Google APIs:19
102 changes: 49 additions & 53 deletions src/com/example/findmesneer/FindMeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,70 @@
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;

public class FindMeActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
public class FindMeActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {

private LocationClient mLocationClient;

private static TextView mEndereco;

private String geoUriString = "geo:15.5555,16.5000?q=(rua a)@15.5555,16.5000";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_find_me);

mEndereco = (TextView) this.findViewById(R.id.textView1);
mEndereco = (TextView) this.findViewById(R.id.textView1);
mLocationClient = new LocationClient(this, this, this);
}

public void abrirMapa(View view) {
atualizaPosicao();

// geoUriString="geo:15.5555,16.5000?q=(rua a)@15.5555,16.5000";
Uri geoUri = Uri.parse(geoUriString);

Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
//startActivity(mapCall);
startActivity(mapCall);
}




private void atualizaPosicao() {

Location mCurrentLocation = mLocationClient.getLastLocation();

AsyncTask<Location, Void, String> execute = (new GetAddressTask(this)).execute(mCurrentLocation);

try {
mEndereco.setText(execute.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

StringBuilder sb = new StringBuilder("geo:");

sb.append(mCurrentLocation.getLatitude())
.append(",")
.append(mCurrentLocation.getLongitude())
.append("?q=(")
.append(mEndereco.getText())
.append(")@")
.append(mCurrentLocation.getLatitude())
.append(",")
.append(mCurrentLocation.getLongitude());

AsyncTask<Location,Void,String> execute = (new GetAddressTask(this)).execute(mCurrentLocation);

try {
mEndereco.setText(execute.get());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

geoUriString = "geo:" + mCurrentLocation.getLatitude() + ","
+ mCurrentLocation.getLongitude() + "?q=("+mEndereco.getText()+")@"
+ mCurrentLocation.getLatitude() + ","
+ mCurrentLocation.getLongitude();


geoUriString = sb.toString();
}

@Override
protected void onStart() {
super.onStart();
// Connect the client.
mLocationClient.connect();

}

@Override
Expand All @@ -102,14 +104,12 @@ public void onConnected(Bundle dataBundle) {
}

/*
* Called by Location Services if the connection to the location client
* drops because of an error.
* Called by Location Services if the connection to the location client drops because of an error.
*/
@Override
public void onDisconnected() {
// Display the connection status
Toast.makeText(this, "Disconnected. Please re-connect.",
Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
}

/*
Expand All @@ -130,48 +130,44 @@ public GetAddressTask(Context context) {
mContext = context;
}


@Override
protected String doInBackground(Location... params) {

Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());

// Get the current location from the input parameter list
Location loc = params[0];

// Create a list to contain the result address
List<Address> addresses = null;
try {
/*
* Return 1 address.
*/
addresses = geocoder.getFromLocation(loc.getLatitude(),
loc.getLongitude(), 1);
addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
} catch (IOException e1) {
Log.e("LocationSampleActivity",
"IO Exception in getFromLocation()");
Log.e("LocationSampleActivity", "IO Exception in getFromLocation()");
e1.printStackTrace();
return ("IO Exception trying to get address");
} catch (IllegalArgumentException e2) {
// Error message to post in the log
String errorString = "Illegal arguments "
+ Double.toString(loc.getLatitude()) + " , "
+ Double.toString(loc.getLongitude())
String errorString = "Illegal arguments " + Double.toString(loc.getLatitude()) + " , " + Double.toString(loc.getLongitude())
+ " passed to address service";
Log.e("LocationSampleActivity", errorString);
e2.printStackTrace();
return errorString;
}

// If the reverse geocode returned an address
if (addresses != null && addresses.size() > 0) {
// Get the first address
Address address = addresses.get(0);
/*
* Format the first line of address (if available), city, and
* country name.
* Format the first line of address (if available), city, and country name.
*/
String addressText = String.format(
"%s, %s, %s",
// If there's a street address, add it
address.getMaxAddressLineIndex() > 0 ? address
.getAddressLine(0) : "",
String addressText = String.format("%s, %s, %s",
// If there's a street address, add it
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
// Locality is usually a city
address.getSubAdminArea(),
// The country of the address
Expand All @@ -182,12 +178,12 @@ protected String doInBackground(Location... params) {
return "No address found";
}
}
protected void onPostExecute(String address) {
// Display the results of the lookup.
if(address!=null && mEndereco !=null)
mEndereco.setText(address);
}

protected void onPostExecute(String address) {
// Display the results of the lookup.
if (address != null && mEndereco != null)
mEndereco.setText(address);
}
}

}

0 comments on commit 00c99f7

Please sign in to comment.