+/* CampusApp.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package de.dhbwloe.campusapp;
import android.content.Context;
import android.content.Intent;
+import android.content.res.TypedArray;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import de.dhbwloe.campusapp.nfcreader.NfcCardListener;
public class CampusApp extends FragmentActivity {
-
private boolean bSearchActive = false;
private CampusAppContext AppContext = null;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_campus_app);
+ // Erstelle neuen AppContext, wenn keiner existiert
AppContext = CampusAppContext.getInstance();
if(AppContext == null)
- AppContext = new CampusAppContext(this, R.id.fragment_container);
+ AppContext = new CampusAppContext(this, R.id.fragment_container, R.id.nav_view);
else
AppContext.setMainActivity(this);
+ // Wenn die App aus dem Ruhezustand (oder auch Orientation change) reaktiviert wird soll nicht zuerst der Splashscreen angezeigt werden.
boolean instantRestore = false;
if(savedInstanceState != null) {
long lastrun = savedInstanceState.getLong("lastrun");
if(lastrun < 30) {
instantRestore = true;
+ // restore previous Title
AppContext.setTitle(savedInstanceState.getString("activetitle"));
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
Log.i("CampusApp", "Event: onSaveInstanceState");
+
// Save instance state during "restarts" due to orientation changes.
// We don't want to see the splash screen everytime the orientation changes ;)
savedInstanceState.putLong("lastrun", (new Date()).getTime() / 1000);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
-
- AppContext = null; // simulate GC
}
public void prepareMainUi() {
// Handle navigation view item clicks here.
int id = item.getItemId();
- switch (id) { // Navigation Items from res/menu/activity_campus_app_drawer.xml
- case R.id.nav_dashboard:
- AppContext.getNavigationManager().navigatePage("Dashboard");
- break;
- case R.id.nav_vorlesungsplan:
- AppContext.getNavigationManager().navigatePage("Vorlesungsplan");
- break;
- case R.id.nav_mensa:
- AppContext.getNavigationManager().navigatePage("Mensa");
+ for(CampusAppContext.NavigationItem navitem : AppContext.NAVIGATION_TARGETS) {
+ if(navitem.navItemId == id) {
+ AppContext.getNavigationManager().navigatePage(navitem.navTarget);
break;
- case R.id.nav_news:
- AppContext.getNavigationManager().navigatePage("News");
- break;
- case R.id.nav_settings:
- AppContext.getNavigationManager().navigatePage("Settings");
- break;
- case R.id.nav_wifi:
- AppContext.getNavigationManager().navigatePage("WifiSettings");
- break;
- case R.id.nav_impressum:
- AppContext.getNavigationManager().navigatePage("Impressum");
- break;
- default:
- return false;
+ }
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
EditText edtSearchInput = (EditText) findViewById(R.id.search_input);
TextView txtTitle = (TextView) findViewById(R.id.title);
+ // EventListener für Suchfunktion
btnOpenSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@Override
public void onResume() {
if(AppContext == null)
- AppContext = new CampusAppContext(this, R.id.fragment_container);
+ AppContext = CampusAppContext.getInstance();
+ if(AppContext == null)
+ AppContext = new CampusAppContext(this, R.id.fragment_container, R.id.nav_view);
else
AppContext.setMainActivity(this);