package org.fox.ttrss; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; public class MainActivity extends Activity { private SharedPreferences m_prefs; private String m_themeName = ""; private String m_sessionId; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { setTheme(R.style.DarkTheme); } else { setTheme(R.style.LightTheme); } m_themeName = m_prefs.getString("theme", "THEME_DARK"); Bundle extras = getIntent().getExtras(); if (extras != null) { m_sessionId = extras.getString("sessionId"); } else if (savedInstanceState != null) { m_sessionId = savedInstanceState.getString("sessionId"); } setContentView(R.layout.main); } @Override public void onSaveInstanceState (Bundle out) { super.onSaveInstanceState(out); out.putString("sessionId", m_sessionId); } @Override public void onResume() { super.onResume(); if (!m_prefs.getString("theme", "THEME_DARK").equals(m_themeName)) { Intent refresh = new Intent(this, LoginActivity.class); startActivity(refresh); finish(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.preferences: Intent intent = new Intent(this, PreferencesActivity.class); startActivityForResult(intent, 0); return true; case R.id.logout: intent = new Intent(this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivityForResult(intent, 0); finish(); return true; default: return super.onOptionsItemSelected(item); } } }