Created
September 26, 2014 19:16
-
-
Save talobin/1601ce348faa400b5c94 to your computer and use it in GitHub Desktop.
This file contains 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 edu.southern.cs.circ.devoted; | |
import android.app.Activity; | |
import android.app.FragmentManager; | |
import android.content.SharedPreferences; | |
import android.os.Bundle; | |
import android.preference.PreferenceManager; | |
import android.view.Menu; | |
import android.view.MenuInflater; | |
import java.util.Date; | |
import edu.southern.cs.circ.devoted.Resources.DevotedHelper; | |
public class HomeActivity extends Activity implements FragmentManager.OnBackStackChangedListener { | |
SharedPreferences _prefs; | |
DevotedHelper _devoted; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_home); | |
_devoted = new DevotedHelper(); | |
if (savedInstanceState == null) { | |
getFragmentManager().beginTransaction() | |
.add(R.id.fragment_container, new TodayFragment()) | |
.commit(); | |
} | |
// Handles the Back button | |
getFragmentManager().addOnBackStackChangedListener(this); | |
shouldDisplayHomeUp(); | |
} | |
@Override | |
public void onBackStackChanged() { | |
shouldDisplayHomeUp(); | |
} | |
public void shouldDisplayHomeUp(){ | |
//Enable Up button only if there are entries in the back stack | |
boolean canBack = getFragmentManager().getBackStackEntryCount()>0; | |
getActionBar().setDisplayHomeAsUpEnabled(canBack); | |
} | |
@Override | |
public boolean onNavigateUp() { | |
//This method is called when the up button is pressed. Just the pop back stack. | |
getFragmentManager().popBackStack(); | |
return true; | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
// Save todays date in the desired format and time zone | |
_prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
SharedPreferences.Editor editor = _prefs.edit(); | |
Long dateMST = _devoted.getDateForTimeZoneAsLong(new Date(),"MST"); | |
editor.putLong(getResources().getString(R.string.current_date), dateMST); | |
editor.commit(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu items for use in the action bar | |
MenuInflater inflater = getMenuInflater(); | |
inflater.inflate(R.menu.main, menu); | |
return super.onCreateOptionsMenu(menu); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment