public void SetItems() {
    itemsView = (ListView) findViewById(R.id.myItemsListView);

    if (NetworkUtil.getConnectivityStatus(this) == 1) {
      usersItems = user.getMyItems();
      itemsList = new String[usersItems.size()];
      itemsList = usersItems.toArray(itemsList);
      ItemController.getItemsByIDElasticSearch(itemsList);
      usersItemsArrayList = ItemController.getItemList().getItemList();
      for (Item item : usersItemsArrayList) {
        if (item.getAvailability()) {
          usersItemsArrayList.remove(item);
        }
      }
      if (usersItemsArrayList.isEmpty()) {
        Toast.makeText(
                ViewBorrowingOutActivity.this,
                "None of your items are being borrowed.",
                Toast.LENGTH_SHORT)
            .show();
      }
      // TODO: can stop converting the items list into String[] once that's it's actual type
      adapter = new CustomSearchResultsAdapter(this, usersItemsArrayList);
      itemsView.setAdapter(adapter);
      adapter.notifyDataSetChanged();
    } else {
      Toast.makeText(this, "You are not connected to the internet.", Toast.LENGTH_SHORT).show();
    }
  }
  private void cadastrarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cadastrarActionPerformed
    Date datamanutencao;
    if (checkfields()) {
      if (this.cadastrar.getText().equals("Cadastrar")) {
        Item itemx = null;
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        try {
          datamanutencao = (Date) dateFormat.parse(this.datamanutencao.getText());
          if (this.freezer.isSelected()) {
            itemx = new Item(this.item.getText(), this.localizacao.getText(), 1, datamanutencao);
          } else if (this.sala.isSelected()) {
            itemx = new Item(this.item.getText(), this.localizacao.getText(), 2, datamanutencao);
          } else {
            itemx = new Item(this.item.getText(), this.localizacao.getText(), 3, datamanutencao);
          }
        } catch (ParseException ex) {
          Logger.getLogger(ManutencaoSalaEquipamentoInterface.class.getName())
              .log(Level.SEVERE, null, ex);
        }
        if (ItemController.CadastrarItem(itemx)) {
          JOptionPane.showMessageDialog(null, "Item cadastrado!");
          this.dispose();
        }

      } else if (this.cadastrar.getText().equals("Salvar")) {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        try {
          datamanutencao = (Date) dateFormat.parse(this.datamanutencao.getText());
          if (this.freezer.isSelected()) {
            Item atualizado =
                new Item(this.item.getText(), this.localizacao.getText(), 1, datamanutencao);
            if (ItemController.UpdateItem(atualizado)) {
              JOptionPane.showMessageDialog(null, "Item atualizado com sucesso!");
            }
          } else if (this.sala.isSelected()) {
            Item atualizado =
                new Item(this.item.getText(), this.localizacao.getText(), 2, datamanutencao);
            if (ItemController.UpdateItem(atualizado)) {
              JOptionPane.showMessageDialog(null, "Item atualizado com sucesso!");
            }
          } else if (this.equipamento.isSelected()) {
            Item atualizado =
                new Item(this.item.getText(), this.localizacao.getText(), 3, datamanutencao);
            if (ItemController.UpdateItem(atualizado)) {
              JOptionPane.showMessageDialog(null, "Item atualizado com sucesso!");
            }
          }
        } catch (ParseException ex) {
          Logger.getLogger(ManutencaoSalaEquipamentoInterface.class.getName())
              .log(Level.SEVERE, null, ex);
        }
      }
    } else {
      JOptionPane.showMessageDialog(null, "Campos obbrigatorios em branco!");
    }
  } // GEN-LAST:event_cadastrarActionPerformed
  public static boolean addItem(RouterCutter routerCutter)
      throws ClassNotFoundException, SQLException {
    Connection connection = DBConnection.getDBConnection().getConnection();
    String sql = DBQueryGenerator.insertQuery(RouterCutter.class.getSimpleName(), 2);

    try {
      connection.setAutoCommit(false);

      Object[] ob = new Object[] {routerCutter.getCode(), routerCutter.getSize()};
      boolean itemDetailAdded = ItemController.addItem(routerCutter);
      if (itemDetailAdded) {
        boolean routerCutterAdded = DBHandler.setData(connection, sql, ob) > 0 ? true : false;
        if (routerCutterAdded) {
          connection.commit();
          return true;
        } else {
          connection.rollback();
          return false;
        }

      } else {
        connection.rollback();
        return false;
      }

    } catch (Exception e) {
      connection.rollback();
      throw e;
    } finally {
      connection.setAutoCommit(true);
    }
  }
 public void recalculatePlayerStats(Player player) {
   player.resetStatsToBaseTraits();
   player.recalculateLevelExperience();
   controllers.itemController.applyInventoryEffects(player);
   controllers.skillController.applySkillEffects(player);
   applyEffectsFromCurrentConditions(player);
   ItemController.recalculateHitEffectsFromWornItems(player);
   capActorHealthAtMax(player);
   capActorAPAtMax(player);
 }
public class GetLocationActivity extends FragmentActivity
    implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener {

  Item item = ItemController.getItem();

  private static final int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;

  private GoogleMap mMap;
  private GoogleApiClient mGoogleApiClient;
  private LocationRequest locationRequest;
  private Location location;
  public static final String TAG = GetLocationActivity.class.getSimpleName();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_location);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    locationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000) // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds
  }

  @Override
  protected void onResume() {
    super.onResume();
    // setUpMapIfNeeded();
    mGoogleApiClient.connect();
  }

  @Override
  protected void onPause() {
    super.onPause();
    if (mGoogleApiClient.isConnected()) {
      LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
      mGoogleApiClient.disconnect();
    }
  }

  @Override
  public void onConnected(Bundle bundle) {
    Log.i(TAG, "Location services connected.");
    location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (location == null) {
      LocationServices.FusedLocationApi.requestLocationUpdates(
          mGoogleApiClient, locationRequest, this);
    } else {
      handleNewLocation(location);
    }
  }

  private void handleNewLocation(Location location) {
    Log.d(TAG, location.toString());
    double currentLatitude = location.getLatitude();
    double currentLongitude = location.getLongitude();
    LatLng latLng = new LatLng(currentLatitude, currentLongitude);

    MarkerOptions options = new MarkerOptions().position(latLng);
    mMap.addMarker(options);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
  }

  @Override
  public void onConnectionSuspended(int i) {
    Log.i(TAG, "Location services suspended. Please reconnect.");
  }

  @Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
      try {
        // Start an Activity that tries to resolve the error
        connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);
      } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
      }
    } else {
      Log.i(
          TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
    }
  }

  /**
   * Manipulates the map once available. This callback is triggered when the map is ready to be
   * used. This is where we can add markers or lines, add listeners or move the camera. If Google
   * Play services is not installed on the device, the user will be prompted to install it inside
   * the SupportMapFragment. This method will only be triggered once the user has installed Google
   * Play services and returned to the app.
   */
  @Override
  public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
  }

  @Override
  public void onLocationChanged(Location location) {
    handleNewLocation(location);
  }

  public void saveLocation(View view) {
    if (location != null) {
      Intent passBack = new Intent();
      Double latitude = location.getLatitude();
      Double longitude = location.getLongitude();
      passBack.putExtra("location", location);
      passBack.putExtra("latitude", latitude);
      passBack.putExtra("longitude", longitude);
      setResult(RESULT_OK, passBack);
    }
    finish();
  }

  public void cancelOut(View view) {
    finish();
  }
}
Exemple #6
0
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public SheetViewModelCollection getSheets(@Context HttpServletRequest req) {
    if (!Authenticate.authenticateHeader(req)) {
      return null;
    }

    SheetController sheetController = new SheetController();
    sheetvector sheets =
        sheetController.GetSheetsByUsername(Authenticate.getAuthRequest(req).getUsername());

    ContentPlaceholderController cphController = new ContentPlaceholderController();
    FeedController feedc = new FeedController();
    ItemController itemc = new ItemController();

    List<SheetViewModel> models = new ArrayList<SheetViewModel>();

    int sheetLen = (int) sheets.size();
    for (int i = 0; i < sheetLen; i++) {
      boolean column1 = false;
      boolean column2 = false;

      List<newsfeeder.lib.model.ContentPlaceholder> contentPlaceholders =
          new ArrayList<newsfeeder.lib.model.ContentPlaceholder>();

      Sheet s = sheets.get(i);
      cphvector cphs = cphController.GetContentPlaceholdersBySheetId(s.getId());

      int cphLen = (int) cphs.size();
      for (int x = 0; x < cphLen; x++) {
        nfdb.ContentPlaceholder cph = cphs.get(x);

        NewsContentPlaceholder newsCPH =
            new NewsContentPlaceholder(cph.getColumn(), cph.getOrder());
        contentPlaceholders.add(newsCPH);

        if (cph.getColumn() == 0) {
          column1 = true;
        }

        if (cph.getColumn() == 1) {
          column2 = true;
        }

        feedvector feeds = feedc.GetFeedsByCphId(cph.getId());
        int feedLen = (int) feeds.size();

        for (int y = 0; y < feedLen; y++) {
          Feed f = feeds.get(y);

          itemvector items = itemc.GetItemsByFeedId(f.getId());
          int itemLen = (int) items.size();
          for (int z = 0; z < itemLen; z++) {
            nfdb.Item dbItem = items.get(z);

            NewsItem item =
                new NewsItem(dbItem.getId(), dbItem.getContent(), dbItem.getTitle(), "");
            newsCPH.addItem(item);
          }
        }
      }

      SheetLayout layout = get2ColLayout();

      if (column1 && column2) {
        layout = get2ColLayout();
      } else if (column1) {
        layout = get1ColLayout(0);
      } else if (column2) {
        layout = get1ColLayout(1);
      }

      SheetViewModel model =
          new SheetViewModel(s.getId(), s.getName(), layout, contentPlaceholders);
      models.add(model);
    }

    SheetViewModelCollection collection = new SheetViewModelCollection();
    collection.Sheets = (ArrayList<SheetViewModel>) models;

    return collection;
  }