Created
December 2, 2014 15:11
-
-
Save ravenberg/8882d7503ec7cc5977fd to your computer and use it in GitHub Desktop.
Welzorg Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package nl.dtt.welzorgpechhulp; | |
| import com.google.android.gms.common.ConnectionResult; | |
| import com.google.android.gms.common.GooglePlayServicesClient; | |
| import com.google.android.gms.location.LocationClient; | |
| import com.google.android.gms.maps.CameraUpdate; | |
| import com.google.android.gms.maps.CameraUpdateFactory; | |
| import com.google.android.gms.maps.GoogleMap; | |
| import com.google.android.gms.maps.MapView; | |
| import com.google.android.gms.maps.MapsInitializer; | |
| import com.google.android.gms.maps.model.LatLng; | |
| import android.content.Intent; | |
| import android.location.Location; | |
| import android.net.Uri; | |
| import android.os.Bundle; | |
| import android.support.v4.app.FragmentActivity; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.Toast; | |
| public class PechHulpActivity extends FragmentActivity implements GooglePlayServicesClient.ConnectionCallbacks, | |
| GooglePlayServicesClient.OnConnectionFailedListener{ | |
| GoogleMap gMap; | |
| MapView gMapView; | |
| LocationClient gLocationClient; | |
| private static final float DEFAULTZOOM = 17; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| //Transform launcher icon to an up button | |
| getActionBar().setDisplayHomeAsUpEnabled(true); | |
| //Hide app icon | |
| getActionBar().setDisplayShowHomeEnabled(false); | |
| setContentView(R.layout.activity_pech_hulp); | |
| //Lay Out map | |
| gMapView = (MapView) findViewById(R.id.map); | |
| gMapView.onCreate(savedInstanceState); | |
| try { | |
| MapsInitializer.initialize(this); | |
| //Connect to location Client | |
| gLocationClient = new LocationClient(this, this, this); | |
| gLocationClient.connect(); | |
| //Go to location | |
| goToLocation(); | |
| } catch(Exception e){ | |
| } | |
| //call button (with my own phone number) | |
| final Button button = (Button) findViewById(R.id.call_button); | |
| button.setOnClickListener(new View.OnClickListener() { | |
| public void onClick(View v) { | |
| Intent callIntent = new Intent(Intent.ACTION_CALL); | |
| callIntent.setData(Uri.parse("tel:0624553747")); | |
| startActivity(callIntent); | |
| } | |
| }); | |
| } | |
| //Go to location method | |
| private void goToLocation(){ | |
| Location currentLocation = gLocationClient.getLastLocation(); | |
| if (currentLocation == null){ | |
| Toast.makeText(this, "Locatie vaststellen mislukt. Controleer GPS instellingen van telefoon en zorg " + | |
| "dat die aan staan.", Toast.LENGTH_LONG).show(); | |
| } else { | |
| LatLng latLng = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()); | |
| CameraUpdate update = CameraUpdateFactory.newLatLngZoom(latLng, DEFAULTZOOM); | |
| gMap.animateCamera(update); | |
| } | |
| } | |
| @Override | |
| protected void onDestroy() { | |
| super.onDestroy(); | |
| gMapView.onDestroy(); | |
| } | |
| @Override | |
| public void onLowMemory() { | |
| super.onLowMemory(); | |
| gMapView.onLowMemory(); | |
| } | |
| @Override | |
| protected void onPause() { | |
| super.onPause(); | |
| gMapView.onPause(); | |
| } | |
| @Override | |
| protected void onResume() { | |
| super.onResume(); | |
| gMapView.onResume(); | |
| } | |
| @Override | |
| protected void onSaveInstanceState(Bundle outState) { | |
| super.onSaveInstanceState(outState); | |
| gMapView.onSaveInstanceState(outState); | |
| } | |
| @Override | |
| public void onConnectionFailed(ConnectionResult result) { | |
| } | |
| @Override | |
| public void onConnected(Bundle connectionHint) { | |
| //Connected verification | |
| Toast.makeText(this, "Locatie vaststellen..", Toast.LENGTH_SHORT).show(); | |
| } | |
| @Override | |
| public void onDisconnected() { | |
| // TODO Auto-generated method stub | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment