@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    Intent i;

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }
    if (id == R.id.action_maps) {
      i = new Intent(FavoriteDetailsActivity.this, MapsActivity.class);
      i.putExtra("FromMenu", true);
      startActivity(i);
    }
    if (id == R.id.action_profile) {
      i = new Intent(FavoriteDetailsActivity.this, ProfileSetupActivity.class);
      startActivity(i);
    }
    if (id == R.id.action_search) {
      i = new Intent(FavoriteDetailsActivity.this, SearchActivity.class);
      startActivity(i);
    }
    if (id == R.id.action_favorite) {
      i = new Intent(FavoriteDetailsActivity.this, FavoriteActivity.class);
      startActivity(i);
    }
    if (id == R.id.action_user) {
      i = new Intent(FavoriteDetailsActivity.this, UserConfiguration.class);
      startActivity(i);
    }
    if (id == R.id.action_logout) {
      if (settings.getBoolean(Constants.getSession(), false)) {
        settings.edit().putBoolean(Constants.getSession(), false).commit();
        Toast.makeText(FavoriteDetailsActivity.this, "Usuário desconectou", Toast.LENGTH_SHORT)
            .show();
      } else {
        Toast.makeText(
                FavoriteDetailsActivity.this,
                "Nenhum usuário conectado para fazer logoff",
                Toast.LENGTH_SHORT)
            .show();
      }
      i = new Intent(FavoriteDetailsActivity.this, SearchActivity.class);
      startActivity(i);
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_favorite_details);
    settings = getSharedPreferences(Constants.getMyPreferenceFile(), 0);

    toTextView = (TextView) findViewById(R.id.toFavTextView);
    fromTextView = (TextView) findViewById(R.id.fromFavTextView);
    reDoRoute = (Button) findViewById(R.id.reDoRouteButton);

    Gson gson = new Gson();
    String offline = settings.getString(Constants.getFavoriteDetails(), "");
    final Favorite favorite = gson.fromJson(offline, Favorite.class);
    displayListView(favorite.getPreferencias());
    toTextView.setText("Para: " + favorite.getFinish().getNome());
    fromTextView.setText("De: " + favorite.getStart().toString());

    reDoRoute.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Gson gson = new Gson();
            Estabelecimentos e = favorite.getFinish();
            String searchPoint = gson.toJson(e);
            settings.edit().putString(Constants.getSerachPoint(), searchPoint).commit();

            String offlineData = gson.toJson(favorite.getPreferencias());
            settings.edit().putString(Constants.getUserDataPreferenceReDO(), offlineData).commit();

            Intent i = new Intent(FavoriteDetailsActivity.this, MapsActivity.class);
            i.putExtra("FromMenu", false);
            i.putExtra("FromFavorite", true);
            startActivity(i);
          }
        });
  }