package com.example.android.sunshine.app;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends ActionBarActivity {

    private final String LOG_TAG = MainActivity.class.getSimpleName();

    // String to store the current location
    private String mLocation;

    // Fragment tag for the forecast fragment
    private static final String DETAILFRAGMENT_TAG = "DFTAG";

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

        Log.v(LOG_TAG, "############## onCreate() called ####################");

        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new ForecastFragment(), FORECASTFRAGMENT_TAG)
                    .commit();
        }

        // Initialize mLocation to store the current location from preferences
        mLocation = Utility.getPreferredLocation(this);

        // Get Support ActionBar
        ActionBar actionBar = getSupportActionBar();

        // Set home button to display app icon in ActionBar
        ///////////****************DOESN'T WORK*******************//////////////////
        if(actionBar != null) {
            actionBar.setLogo(R.drawable.ic_launcher);
            actionBar.setDisplayUseLogoEnabled(true);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();

        Log.v(LOG_TAG, "############## onStart() called ####################");

    }

    @Override
    protected void onResume() {
        // If location was changed by the user, get the ForecastFragment and
        // call onLocationChanged, then set the new location to mLocation
        String userLocation = Utility.getPreferredLocation(this);

        if(userLocation != null && !userLocation.equals(mLocation)) {
            ForecastFragment ff = (ForecastFragment) getSupportFragmentManager().
                    findFragmentById(R.id.fragment_forecast);
            if(ff != null)
                ff.onLocationChanged();

            // Set mLocation to store the new location
            mLocation = userLocation;
        }

        super.onResume();

        Log.v(LOG_TAG, "############## onResume() called ####################");

    }

    @Override
    protected void onPause() {
        super.onPause();

        Log.v(LOG_TAG, "############## onPause() called ####################");
    }

    @Override
    protected void onStop() {
        super.onStop();

        Log.v(LOG_TAG, "############## onStop() called ####################");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.v(LOG_TAG, "############## onDestroy() called ####################");
    }
}

@@ -489,16 +489,112 @@
 FTAG%22;%0A%0A
+    // To figure out whether or not to display the two-pane mode%0A    private boolean mTwoPane;%0A%0A
     @Ove
@@ -713,130 +713,671 @@
     
-Log.v(LOG_TAG, %22############## onCreate() called ####################%22);%0A%0A        setContentView(R.layout.activity_main);%0A
+// Initialize mLocation to store the current location from preferences%0A        mLocation = Utility.getPreferredLocation(this);%0A%0A        setContentView(R.layout.activity_main);%0A        if (findViewById(R.id.container_content_detail) != null) %7B%0A            // The detail container view will be present only in the large-screen layouts%0A            // (res/layout-sw600dp). If this view is present, then the activity should be%0A            // in two-pane mode.%0A            mTwoPane = true;%0A            // In two-pane mode, show the detail view in this activity by%0A            // adding or replacing the detail fragment using a%0A            // fragment transaction.%0A    
     
@@ -1406,32 +1406,36 @@
 tate == null) %7B%0A
+    
             getS
@@ -1501,18 +1501,41 @@
     
-.add(R.id.
+    .replace(R.id.weather_detail_
 cont
@@ -1545,24 +1545,30 @@
 er, new 
-Forecast
+DetailActivity
 Fragment
@@ -1575,16 +1575,14 @@
 (), 
-FORECAST
+DETAIL
 FRAG
@@ -1591,16 +1591,20 @@
 NT_TAG)%0A
+    
         
@@ -1638,145 +1638,70 @@
     
-%7D%0A%0A
     
+%7D%0A
     
-// Initialize mLocation to store the current location from preferences%0A        mLocation = Utility.getPreferredLocation(this);
+    %7D else %7B%0A            mTwoPane = false;%0A        %7D
 %0A%0A  

Check whether device is in two-pane mode