@Override public void onResume() { super.onResume(); EventBus.getDefault().register(this); if (mfrag.getPrefs() != null) { pager.setKeepScreenOn(mfrag.getPrefs().getBoolean(PREF_KEEP_SCREEN_ON, false)); } }
@Override public void onPause() { EventBus.getDefault().unregister(this); if (mfrag.getPrefs() != null) { int position = pager.getCurrentItem(); mfrag.getPrefs().edit().putInt(PREF_LAST_POSITION, position).apply(); } super.onPause(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupStrictMode(); setContentView(R.layout.main); pager = (ViewPager) findViewById(R.id.pager); mfrag = (ModelFragment) getFragmentManager().findFragmentByTag(MODEL); if (mfrag == null) { mfrag = new ModelFragment(); getFragmentManager().beginTransaction().add(mfrag, MODEL).commit(); } else if (mfrag.getBook() != null) { setupPager(mfrag.getBook()); } getActionBar().setHomeButtonEnabled(true); UpdateReceiver.scheduleAlarm(this); }
private void setupPager(BookContents contents) { adapter = new ContentsAdapter(this, contents); pager.setAdapter(adapter); findViewById(R.id.progressBar1).setVisibility(View.GONE); findViewById(R.id.pager).setVisibility(View.VISIBLE); SharedPreferences prefs = mfrag.getPrefs(); if (prefs != null) { if (prefs.getBoolean(PREF_SAVE_LAST_POSITION, false)) { pager.setCurrentItem(prefs.getInt(PREF_LAST_POSITION, 0)); } pager.setKeepScreenOn(prefs.getBoolean(PREF_KEEP_SCREEN_ON, false)); } }