/**********************************************************************************
 * Bismillahir Rahmanir Rahim, ALLAHU AKBAR                                       *
 * The MIT License (MIT)                                                          *
 *                                                                                *
 * Copyright (c) 2014 Mohammed Sazid-Al-Rashid                                    *
 *                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy   *
 * of this software and associated documentation files (the "Software"), to deal  *
 * in the Software without restriction, including without limitation the rights   *
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      *
 * copies of the Software, and to permit persons to whom the Software is          *
 * furnished to do so, subject to the following conditions:                       *
 *                                                                                *
 * The above copyright notice and this permission notice shall be included in all *
 * copies or substantial portions of the Software.                                *
 *                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    *
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         *
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  *
 * SOFTWARE.                                                                      *
 **********************************************************************************/

package com.mohammedsazidalrashid.android.sunshine;

import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {

    public static String LOG_TAG = MainActivity.class.getSimpleName();

    public static Bundle bundleForFragments = new Bundle();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new ForecastFragment())
                    .commit();
        }

        getFragmentManager().addOnBackStackChangedListener(
                new FragmentManager.OnBackStackChangedListener() {
                    @Override
                    public void onBackStackChanged() {
                        shouldDisplayHomeUp();
                    }
                }
        );

    }

    @Override
    public void onBackPressed() {
//        Log.v(LOG_TAG, String.valueOf(getFragmentManager().getBackStackEntryCount()));
        if (getFragmentManager().getBackStackEntryCount() < 1) {
            super.onBackPressed();
        }

        getFragmentManager().popBackStack();
    }


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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            getFragmentManager().beginTransaction()
                    .addToBackStack(null)
                    .setCustomAnimations(
                            R.animator.enter_anim,
                            R.animator.exit_anim,
                            R.animator.enter_anim_reverse,
                            R.animator.exit_anim_reverse)
                    .replace(R.id.container, new SettingsFragment())
                    .commit();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void shouldDisplayHomeUp() {
        boolean canGoBack = getFragmentManager().getBackStackEntryCount() > 0;
        try {
            getActionBar().setDisplayHomeAsUpEnabled(canGoBack);
        } catch (NullPointerException e) {
            Log.e(LOG_TAG, e.getMessage().toString(), e);
            e.printStackTrace();
        }
    }

    @Override
    public boolean onNavigateUp() {
        // This method is called when the Up button is pressed.
//        getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        getFragmentManager().popBackStack();
        return true;
    }

}

@@ -2068,37 +2068,8 @@
 e;%0A%0A
-import android.app.Activity;%0A
 impo
@@ -2126,16 +2126,65 @@
 Bundle;%0A
+import android.support.v7.app.ActionBarActivity;%0A
 import a
@@ -2292,16 +2292,25 @@
 extends 
+ActionBar
 Activity
@@ -4069,462 +4069,8 @@
 ) %7B%0A
-            getFragmentManager().beginTransaction()%0A                    .addToBackStack(null)%0A                    .setCustomAnimations(%0A                            R.animator.enter_anim,%0A                            R.animator.exit_anim,%0A                            R.animator.enter_anim_reverse,%0A                            R.animator.exit_anim_reverse)%0A                    .replace(R.id.container, new SettingsFragment())%0A                    .commit();%0A
     
@@ -4086,24 +4086,24 @@
 eturn true;%0A
+
         %7D%0A%0A 
@@ -4307,16 +4307,23 @@
      get
+Support
 ActionBa
@@ -4521,32 +4521,32 @@
 %0A%0A    @Override%0A
-
     public boole
@@ -4550,16 +4550,23 @@
 olean on
+Support
 Navigate

Make action bar visible again