public ParseProxyObject(ParseObject object) {

    // Loop the keys in the ParseObject
    for (String key : object.keySet()) {
      @SuppressWarnings("rawtypes")
      Class classType = object.get(key).getClass();
      if (classType == byte[].class
          || classType == String.class
          || classType == Integer.class
          || classType == Boolean.class
          || classType == Double.class
          || classType == Date.class) {
        values.put(key, object.get(key));
      } else if (classType == ParseUser.class) {
        ParseProxyObject parseUserObject = new ParseProxyObject((ParseObject) object.get(key));
        values.put(key, parseUserObject);
      } else {
        // You might want to add more conditions here, for embedded ParseObject, ParseFile, etc.
      }
    }
    values.put("ObjectId", object.getObjectId());
  }
Ejemplo n.º 2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout ll = null;
    LinearLayout columnLayout = null;
    LinearLayout valueLayout = null;
    TextView noResultsTextView = null;
    TextView tv = null;
    TextView col = null;

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // if user scrolls, reuse view without re-inflating
    if (convertView == null) {
      ll = (LinearLayout) inflater.inflate(R.layout.partial_parseobjectadapter_row, null);
    } else {
      ll = (LinearLayout) convertView;
    }

    valueLayout = (LinearLayout) ll.findViewById(R.id.ParseObjectAdapterValueLayout);
    columnLayout = (LinearLayout) ll.findViewById(R.id.ParseObjectAdapterColumnLayout);
    noResultsTextView = (TextView) ll.findViewById(R.id.ParseObjectAdapterNoResults);

    // set up the displays of our xml controls
    if (position == 0) {
      // if we're setting up the columns, ensure the columnlayout is visible
      columnLayout.setVisibility(View.VISIBLE);
    } else {
      columnLayout.setVisibility(View.INVISIBLE);
    }
    noResultsTextView.setVisibility(View.INVISIBLE);

    if (objects != null && !objects.isEmpty()) {
      ParseObject object = (ParseObject) objects.get(position);
      if (object != null) {
        int i = 0;
        // get the total columns and make a textview for each
        // check if we've passed some columns
        Set<String> collection = object.keySet();
        if (columns != null) {
          collection = columns;
        }
        // now loop through the columns
        for (String key : collection) {
          if (position == 0) {
            // set up columns
            col =
                (TextView)
                    inflater.inflate(R.layout.partial_parseobjectadapter_row_cell_header, null);
            col.setWidth(columnWidth);

            int col_id =
                context
                    .getResources()
                    .getIdentifier(
                        "parse_attributes_quest_" + key.toLowerCase(),
                        "string",
                        context.getPackageName());
            if (col_id != 0) {
              col.setText(context.getResources().getString(col_id));
            } else {
              String column_text = "";
              String words[] = key.split("_");
              for (String word : words) {
                column_text = column_text + WordUtils.capitalize(word) + " ";
              }
              column_text = column_text.trim();
              col.setText(column_text);
            }
            columnLayout.addView(col);
          }

          tv = (TextView) inflater.inflate(R.layout.partial_parseobjectadapter_row_cell, null);
          tv.setWidth(columnWidth);

          // depending on our type of parse object, get the string correctly
          Object value = object.get(key);
          if (value instanceof ParseGeoPoint) {
            value =
                String.valueOf(((ParseGeoPoint) value).getLatitude())
                    + ", "
                    + String.valueOf(((ParseGeoPoint) value).getLongitude());
          }

          tv.setText(value.toString());
          valueLayout.addView(tv);
          i++;
        }
      }
    } else {
      columnLayout.setVisibility(View.INVISIBLE);
      valueLayout.setVisibility(View.INVISIBLE);

      noResultsTextView.setVisibility(View.VISIBLE);
      noResultsTextView.setText(R.string.parse_no_results);
    }

    return ll;
  }