Ejemplo n.º 1
0
  @Override
  public boolean onMenuItemClick(MenuItem item) {
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      Calendar cal = new GregorianCalendar();
      Date date = cal.getTime();

      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateFormat = df.format(date);

      if (location != null) {
        try {
          JSONObject position = new JSONObject();
          position.put("latitude", location.getLatitude());
          position.put("longitude", location.getLongitude());

          boolean isGroup = false;

          Message message =
              new Message("MAP" + position.toString(), dateFormat, true, toID, toID, isGroup);
          messages.add(message);

          sendMessage(message.getText());
          showMap(message);
        } catch (JSONException e) {
          e.printStackTrace();
        }
      } else {
        Toast.makeText(this, getResources().getString(R.string.gps_disabled), Toast.LENGTH_LONG)
            .show();
      }

    } else {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder
          .setMessage(getResources().getString(R.string.gps_off))
          .setCancelable(false)
          .setPositiveButton(
              getResources().getString(R.string.yes),
              new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                  startActivity(
                      new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
              })
          .setNegativeButton(
              "No",
              new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                  dialog.cancel();
                }
              });
      AlertDialog alert = builder.create();
      alert.show();
    }

    return false;
  }
Ejemplo n.º 2
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.chat_send && keyboard.getText().toString().length() != 0) {
      Calendar cal = new GregorianCalendar();
      Date date = cal.getTime();

      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateFormat = df.format(date);

      boolean isGroup = false;

      Message message =
          new Message(keyboard.getText().toString(), dateFormat, true, toID, toID, isGroup);

      messages.add(message);

      sendMessage(message.getText());
      showMessage(message);
    } else {
      popupMenu.show();
    }
  }
Ejemplo n.º 3
0
  public void saveDBMessages() {
    for (int i = 0; i < messages.size(); i++) {
      String text = messages.get(i).getText();
      String date = messages.get(i).getDate();
      int idReceiver = messages.get(i).getReceiver();
      int idFriend = messages.get(i).getIdFriend();
      boolean read = messages.get(i).isRead();

      if (!messages.get(i).getIsGroup()) {
        Actions_DB.insertMessagePrivate(text, date, read, idFriend, idReceiver);
      } else {
        Actions_DB.insertMessageGroup(text, date, read, idReceiver, idFriend);
      }
    }

    messages.clear();
  }