@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       return tabManager.onAndroidHome(item);
     case R.id.menu_login:
       Intent intent = new Intent(this, ConnectionAssistantActivity.class);
       lastTab = tabManager.getCurrentTab();
       //				tabManager.switchToTab(RallyeTabManager.TAB_WAIT_FOR_MODEL);
       startActivityForResult(intent, ConnectionAssistantActivity.REQUEST_CODE);
       break;
     case R.id.menu_logout:
       new AlertDialog.Builder(this)
           .setTitle(R.string.logout)
           .setMessage(R.string.are_you_sure)
           .setCancelable(true)
           .setNegativeButton(android.R.string.cancel, null)
           .setPositiveButton(
               android.R.string.ok,
               new DialogInterface.OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int which) {
                   server.logout();
                 }
               })
           .create()
           .show();
       server.tryLogout();
       break;
     case R.id.menu_upload_overview:
       intent = new Intent(this, UploadOverviewActivity.class);
       startActivity(intent);
       break;
     case R.id.menu_share_barcode:
       IntentIntegrator zx = new IntentIntegrator(this);
       ObjectMapper mapper = Serialization.getJsonInstance();
       try {
         zx.shareText(mapper.writeValueAsString(server.exportLogin()));
       } catch (JsonProcessingException e) {
         Log.e(THIS, "Could not serialize exported Login", e);
         Toast.makeText(this, R.string.export_barcode_error, Toast.LENGTH_SHORT).show();
       }
       break;
       //			case R.id.menu_reconnect: //there is no more temporary offline, we cannot know if push
       // messages will reach us
       //				model.reconnect();
       //				break;
     case R.id.menu_settings:
       intent = new Intent(this, SettingsActivity.class);
       startActivity(intent);
       break;
     default:
       return false;
   }
   return true;
 }
  /**
   * git status
   *
   * <p>Passed-Through to Model (if not kept for ConfigurationChange) and GCMRegistrar
   */
  @Override
  protected void onDestroy() {
    Log.i(THIS, "Destroying...");

    server = null;
    Server.removeListener(this);

    Storage.releaseStorage(this);
    pref.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //		android.support.v4.app.FragmentManager.enableDebugLogging(true);

    // Layout, Title, ProgressCircle etc.
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setTitle(R.string.app_name);
    setContentView(R.layout.main);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    logo = (TransitionDrawable) getResources().getDrawable(R.drawable.transition_logo);
    actionBar.setIcon(logo);

    // Check if Google Play Services is working
    int errorCode;
    if ((errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this))
        != ConnectionResult.SUCCESS) {
      GooglePlayServicesUtil.getErrorDialog(errorCode, this, 0).show();
      finish();
    }

    // Google Cloud Messaging Init
    // PushInit.ensureRegistration(this);
    GcmHelper.ensureRegistration(getApplicationContext());

    Storage.aquireStorage(getApplicationContext(), this);
    pref = Storage.getAppPreferences();
    pref.registerOnSharedPreferenceChangeListener(this);
    pref_autoUpload = pref.getBoolean("auto_upload", true);
    pictureManager = Storage.getPictureManager();

    // Initialize Model
    Server.addListener(this);
    server = Server.getCurrentServer();

    // Manages all fragments that will be displayed as Tabs in this activity
    tabManager = new RallyeTabManager(this, server, drawerLayout);

    tabManager.setArguments(
        RallyeTabManager.TAB_MAP,
        getDefaultMapOptions(
            null)); // this map is currently not used anyway, so for the time being we always do
                    // lateInitialization
    // Recover Last State
    tabManager.restoreState(savedInstanceState);

    //		forceOverflowMenu(); // Force devices with hardware menu key to display the modern overflow
    // menu

    // Initialize NFC ability
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      initNFC();
    }
  }
 private boolean isLoggedIn() {
   return server != null && server.hasUserAuth();
 }