示例#1
0
 public void shareClicked(View view) {
   try {
     shareAction();
   } catch (Exception e) {
     e.printStackTrace();
     Utilities.messageDialog(this, e.getLocalizedMessage(), null);
   }
 }
示例#2
0
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    selectedItemName = (String) getListAdapter().getItem(position);
    int childCount = l.getChildCount();
    for (int i = 0; i < childCount; i++) {
      View childAt = l.getChildAt(i);
      if (childAt instanceof TextView) {
        TextView textView = (TextView) childAt;
        textView.setTypeface(null, Typeface.NORMAL);
      }
    }
    if (v instanceof TextView) {
      TextView textView = (TextView) v;
      textView.setTypeface(null, Typeface.BOLD_ITALIC);
      // textView.setTextColor(v.getResources().getColor(R.color.formcolorselected));
    }

    JSONObject sectionObject = activity.getSectionObject();
    FragmentDetail oldFragment =
        (FragmentDetail) getFragmentManager().findFragmentById(R.id.detailFragment);
    if (oldFragment != null) { // && oldFragment.isInLayout()) {
      try {
        oldFragment.storeFormItems(false);
      } catch (Exception e) {
        e.printStackTrace();
        Utilities.messageDialog(activity, R.string.error_while_storing_form_data, null);
      }
      // FragmentActivity activity2 = oldFragment.getActivity();
      // int id2 = oldFragment.getId();

      FragmentDetail newFragment = new FragmentDetail();
      newFragment.setForm(selectedItemName, sectionObject);
      FragmentTransaction transaction = getFragmentManager().beginTransaction();
      transaction.remove(oldFragment);
      transaction.add(R.id.detailFragment, newFragment);
      // transaction.replace(R.id.detailFragment, newFragment);
      // transaction.addToBackStack(null); // Ads FirstFragment to the back-stack
      transaction.commit();
    } else {
      // String sectionName = activity.getSectionName();
      Intent intent =
          new Intent(getActivity().getApplicationContext(), FragmentDetailActivity.class);
      intent.putExtra(FormUtilities.ATTR_FORMNAME, selectedItemName);
      intent.putExtra(FormUtilities.ATTR_SECTIONOBJECTSTR, sectionObject.toString());
      intent.putExtra(LibraryConstants.LONGITUDE, activity.getLongitude());
      intent.putExtra(LibraryConstants.LATITUDE, activity.getLatitude());
      startActivityForResult(intent, RETURNCODE_DETAILACTIVITY);
    }
  }
示例#3
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (GPLog.LOG_ABSURD) GPLog.addLogEntry(this, "Activity returned"); // $NON-NLS-1$
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
      case (MapsActivity.FORMUPDATE_RETURN_CODE):
        {
          if (resultCode == Activity.RESULT_OK) {
            String[] formArray = data.getStringArrayExtra(LibraryConstants.PREFS_KEY_FORM);
            if (formArray != null) {
              try {
                double lon = Double.parseDouble(formArray[0]);
                double lat = Double.parseDouble(formArray[1]);
                String textStr = formArray[4];
                String jsonStr = formArray[6];

                float n = (float) (lat + 0.00001f);
                float s = (float) (lat - 0.00001f);
                float w = (float) (lon - 0.00001f);
                float e = (float) (lon + 0.00001f);

                List<Note> notesInWorldBounds = DaoNotes.getNotesInWorldBounds(n, s, w, e);
                if (notesInWorldBounds.size() > 0) {
                  Note note = notesInWorldBounds.get(0);
                  long id = note.getId();
                  DaoNotes.updateForm(id, textStr, jsonStr);
                }

              } catch (Exception e) {
                e.printStackTrace();
                Utilities.messageDialog(this, eu.geopaparazzi.library.R.string.notenonsaved, null);
              }
            }
          }
          break;
        }
    }
  }
示例#4
0
 private void shareAction() throws Exception {
   String form = sectionObject.toString();
   float lat = (float) latitude;
   float lon = (float) longitude;
   String osmUrl = Utilities.osmUrlFromLatLong(lat, lon, true, false);
   // double altim = note.getAltim();
   List<String> imagePaths = FormUtilities.getImages(form);
   File imageFile = null;
   if (imagePaths.size() > 0) {
     String imagePath = imagePaths.get(0);
     imageFile = new File(imagePath);
     if (!imageFile.exists()) {
       imageFile = null;
     }
   }
   String formText = FormUtilities.formToPlainText(form, false);
   formText = formText + "\n" + osmUrl;
   String shareNoteMsg = getResources().getString(R.string.share_note_with);
   if (imageFile != null) {
     ShareUtilities.shareTextAndImage(this, shareNoteMsg, formText, imageFile);
   } else {
     ShareUtilities.shareText(this, shareNoteMsg, formText);
   }
 }
示例#5
0
  private void saveAction() throws Exception {
    // if in landscape mode store last inserted info, since that fragment has not been stored
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
      FragmentDetail detailFragment =
          (FragmentDetail) getSupportFragmentManager().findFragmentById(R.id.detailFragment);
      if (detailFragment != null) {
        detailFragment.storeFormItems(false);
      }
    }

    // extract and check constraints
    List<String> availableFormNames = TagsManager.getFormNames4Section(sectionObject);
    String label = null;
    for (String formName : availableFormNames) {
      JSONObject formObject = TagsManager.getForm4Name(formName, sectionObject);

      JSONArray formItemsArray = TagsManager.getFormItems(formObject);

      int length = formItemsArray.length();
      String value = null;
      for (int i = 0; i < length; i++) {
        JSONObject jsonObject = formItemsArray.getJSONObject(i);

        String key = "-";
        if (jsonObject.has(TAG_KEY)) key = jsonObject.getString(TAG_KEY).trim();

        if (jsonObject.has(TAG_VALUE)) {
          value = jsonObject.getString(TAG_VALUE).trim();
        }
        if (jsonObject.has(TAG_ISLABEL)) {
          String isLabelStr = jsonObject.getString(TAG_ISLABEL).trim();
          boolean isLabel = Boolean.parseBoolean(isLabelStr);
          if (isLabel) label = value;
        }

        // inject latitude
        if (key.equals(LibraryConstants.LATITUDE)) {
          String latitudeString = String.valueOf(latitude);
          value = latitudeString;
          jsonObject.put(TAG_VALUE, latitudeString);
        }
        // inject longitude
        if (key.equals(LibraryConstants.LONGITUDE)) {
          String longitudeString = String.valueOf(longitude);
          value = longitudeString;
          jsonObject.put(TAG_VALUE, longitudeString);
        }

        Constraints constraints = FormUtilities.handleConstraints(jsonObject, null);
        if (value == null || !constraints.isValid(value)) {
          String constraintDescription = constraints.getDescription();
          String validfieldMsg = getString(R.string.form_field_check);
          String msg = Utilities.format(validfieldMsg, key, formName, constraintDescription);
          Utilities.messageDialog(this, msg, null);
          return;
        }
      }
    }

    // finally store data
    String sectionObjectString = sectionObject.toString();
    Date sqlDate = new Date(System.currentTimeMillis());
    String timestamp = LibraryConstants.TIME_FORMATTER_SQLITE.format(sqlDate);

    if (label == null) {
      label = sectionName;
    }
    String[] formDataArray = { //
      String.valueOf(longitude), //
      String.valueOf(latitude), //
      String.valueOf(elevation), //
      timestamp, //
      label, //
      "POI", //
      sectionObjectString
    };
    Intent intent = getIntent();
    intent.putExtra(LibraryConstants.PREFS_KEY_FORM, formDataArray);
    setResult(Activity.RESULT_OK, intent);
    finish();
  }