package com.example.android.sunshine.app;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }

        if (id == R.id.action_map) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            String locationDefault = getString(R.string.pref_location_default);
            String locationKey = getString(R.string.pref_location_key);
            String location = prefs.getString(locationKey, locationDefault);
            Uri locationUri = Uri.parse("geo:0,0?q=" + location);
            showMap(locationUri);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void showMap(Uri locationUri) {
        Intent mapIntent = new Intent(Intent.ACTION_VIEW, locationUri);
        if (mapIntent.resolveActivity(getPackageManager()) != null) {
            startActivity(mapIntent);
        }

    }

}

@@ -1305,32 +1305,172 @@
 tion_map) %7B%0A    
+        showMap();%0A            return true;%0A        %7D%0A%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A%0A    public void showMap() %7B%0A
         SharedPr
@@ -1540,36 +1540,32 @@
 (this);%0A        
-   
- 
 String locationD
@@ -1608,36 +1608,32 @@
 ation_default);%0A
-    
         String l
@@ -1688,28 +1688,24 @@
 y);%0A        
-    
 String locat
@@ -1765,20 +1765,16 @@
         
- 
-   
 Uri loca
@@ -1823,178 +1823,8 @@
 n);%0A
-            showMap(locationUri);%0A            return true;%0A        %7D%0A%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A%0A    public void showMap(Uri locationUri) %7B%0A
     

Refactor showMap