Java tutorial
/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.phl.mosaqua; import java.util.List; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.maps.Overlay; import android.content.Intent; import android.graphics.drawable.Drawable; 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.ImageButton; /** * This shows how to create a simple activity with a raw MapView and add a marker to it. This * requires forwarding all the important lifecycle methods onto MapView. */ public class Locator extends FragmentActivity { final static String TAG = "Activity Locator"; private Button btnLocatie; List<Overlay> mapOverlays; Drawable drawable; private MapView mMapView; private GoogleMap mMap; ImageButton btn_zwembad, btn_info, btn_facebook, btn_locator; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.locator); //Menu - Begin overridePendingTransition(R.anim.none, R.anim.none); // Change default animation btn_zwembad = (ImageButton) findViewById(R.id.btn_footer_zwembad); btn_info = (ImageButton) findViewById(R.id.btn_footer_openingsuren); btn_facebook = (ImageButton) findViewById(R.id.btn_footer_facebook); btn_locator = (ImageButton) findViewById(R.id.btn_footer_locator); btn_zwembad.setOnClickListener(handleButtons); btn_info.setOnClickListener(handleButtons); btn_facebook.setOnClickListener(handleButtons); btn_locator.setOnClickListener(handleButtons); mMapView = (MapView) findViewById(R.id.map); mMapView.onCreate(savedInstanceState); btn_locator.setImageResource(R.drawable.ic_menu_footer_locator_active); //Menu - End // Button Locatie linken met de layout. btnLocatie = (Button) findViewById(R.id.btnLocatie); // ClickListener voor btnLocatie btnLocatie.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Opent de applicatie Maps en toont de routebeschrijving naar // Mosaqua. String uri = "http://maps.google.com/maps?f=d&daddr=Mosaqua+Landsraderweg+11+6271+NT+Gulpen,+Nederland"; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent); } }); setUpMapIfNeeded(); } @Override protected void onResume() { super.onResume(); mMapView.onResume(); setUpMapIfNeeded(); } private void setUpMapIfNeeded() { if (mMap == null) { mMap = ((MapView) findViewById(R.id.map)).getMap(); if (mMap != null) { setUpMap(); } } } private void setUpMap() { // Coordinaten zwembad Mosaqua String coordinates[] = { "50.810214", "5.889098" }; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)).title("Mosaqua") .snippet("Landsraderweg 11, 6271 NT Gulpen, Nederland")); } @Override protected void onPause() { mMapView.onPause(); super.onPause(); } @Override protected void onDestroy() { mMapView.onDestroy(); super.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); mMapView.onLowMemory(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } View.OnClickListener handleButtons = new View.OnClickListener() { @Override public void onClick(View v) { if (btn_zwembad.getId() == ((ImageButton) v).getId()) { // Zwembad startActivity(new Intent(v.getContext(), Home.class)); finish(); // exit this activity } else if (btn_info.getId() == ((ImageButton) v).getId()) { // Openingsuren startActivity(new Intent(v.getContext(), Info.class)); finish(); // exit this activity } else if (btn_facebook.getId() == ((ImageButton) v).getId()) { // Facebook startActivity(new Intent(v.getContext(), Facebook.class)); finish(); // exit this activity } else if (btn_locator.getId() == ((ImageButton) v).getId()) { // Locator startActivity(new Intent(v.getContext(), Locator.class)); finish(); // exit this activity } } }; }