Beispiel #1
0
    @Override
    public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
      // try {
      String key = m.getName();

      if (args.length == 0) {
        // built-in
        if ("objectData".equals(key)) return new ParseObjectData(obj);
        if (ParseBase.PARSE_OBJECT.equals(key)) return obj;

        // user define
        final Class<?> returnType = m.getReturnType();
        String typeName = returnType.getName();
        if (typeName.equalsIgnoreCase("float")) {
          return (float) obj.getDouble(key);
        } else {
          Object object = obj.get(key);
          if (returnType.isPrimitive() && object == null) {
            return 0;
          } else if (object != null
              && ParseObject.class.isInstance(object)
              && ParseBase.class.isAssignableFrom(returnType)) {
            return ((ParseFacade<?>) ParseFacade.get(returnType)).wrap((ParseObject) object);
          } else if (object != null
              && !returnType.isInstance(object)
              && !returnType.isPrimitive()) {
            return null;
          } else {
            return object;
          }
        }
      } else { // arg.length == 1
        // set value
        Object object = args[0];
        if (key.equals("objectId")) System.out.println("value " + object);

        if (object instanceof ParseBase) {
          obj.put(key, ((ParseBase) object).parseObject());
        } else {
          obj.put(key, object);
        }

        return null;
      }
      // } catch (InvocationTargetException e) {
      // throw e.getTargetException();
      // } catch (Exception e) {
      // throw e;
      // }
      // return something
    }
 public static Pin createPin(ParseObject object) {
   cache().put(object);
   String title = getStringIfHas(object, "title");
   String description = getStringIfHas(object, "description");
   String image = getStringIfHas(object, "image");
   String linkUrl = getStringIfHas(object, "url");
   double aspectRatio = object.has("aspectratio") ? object.getDouble("aspectratio") : 1;
   ParseObject board = object.has("board") ? object.getParseObject("board") : null;
   return new Pin(
       object.getObjectId(),
       title,
       description,
       image,
       ParseHelper.createBoard(board),
       linkUrl,
       aspectRatio);
 }
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    List<ParseObject> ob;

    try {
      // Locate the class table named "stansbeers" in Parse.com
      ParseQuery<ParseObject> query = new ParseQuery<>("capitolbeers").fromLocalDatastore();
      // Locate the column named "name" in Parse.com and order list
      // by ascending

      query.orderByAscending("name").whereEqualTo("group", "IMPORT_BOTTLES_CANS");

      ob = query.find();

      beerObject = new ArrayList<>();

      for (ParseObject beers : ob) {
        // Locate images in flag column

        //  ParseFile image = (ParseFile) stansbeers.get("image");

        BeerListObject beer = new BeerListObject();
        beer.setBeerName((String) beers.get("name"));
        beer.setBeerWhereFrom((String) beers.get("wherefrom"));
        beer.setBeerAbv(beers.getDouble("abvinteger"));
        beer.setBeerGroup((String) beers.get("group"));
        beer.setBeerAbout((String) beers.get("about"));
        beer.setBeerPrice((String) beers.get("price"));
        beer.setBeerSize((String) beers.get("size"));
        //   beer.setBeerImage(image.getUrl());
        beerObject.add(beer);
      }

    } catch (ParseException e) {
      Log.e("Error", e.getMessage());
      e.printStackTrace();
    }

    adapter = new BeersListViewAdapter(getActivity(), beerObject);
    setListAdapter(adapter);
  }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {

    x = x + 1;

    if (x == 6) {

      x = 0;
    }

    String[] toastSort = new String[8];
    toastSort[0] = "Sorted by name Ascending";
    toastSort[1] = "by name descending";
    toastSort[2] = "by A.B.V ascending";
    toastSort[3] = "by A.B.V descending";
    toastSort[4] = "by where from ascending";
    toastSort[5] = "by where from descending";

    String tm = toastSort[x];

    Toast sort = Toast.makeText(getActivity(), tm, Toast.LENGTH_LONG);
    sort.setGravity(Gravity.CENTER, 0, 0);
    sort.show();

    List<ParseObject> ob;

    try {
      // Locate the class table named "stansbeers" in Parse.com
      ParseQuery<ParseObject> query = new ParseQuery<>("capitolbeers").fromLocalDatastore();
      // Locate the column named "name" in Parse.com and order list
      // by ascending

      query.orderByAscending("name").whereEqualTo("group", "IMPORT_BOTTLES_CANS");

      switch (x) {
        case 0:
          query.orderByAscending("name");
          break;
        case 1:
          query.orderByDescending("name");
          break;
        case 2:
          query.orderByAscending("abvinteger");
          break;
        case 3:
          query.orderByDescending("abvinteger");
          break;
        case 4:
          query.orderByAscending("wherefrom");
          break;
        case 5:
          query.orderByDescending("wherefrom");
          break;
      }

      ob = query.find();

      beerObject = new ArrayList<>();

      for (ParseObject beers : ob) {
        // Locate images in flag column

        //   ParseFile image = (ParseFile) stansbeers.get("image");

        BeerListObject beer = new BeerListObject();
        beer.setBeerName((String) beers.get("name"));
        beer.setBeerWhereFrom((String) beers.get("wherefrom"));
        beer.setBeerAbv(beers.getDouble("abvinteger"));
        beer.setBeerGroup((String) beers.get("group"));
        beer.setBeerAbout((String) beers.get("about"));
        beer.setBeerPrice((String) beers.get("price"));
        beer.setBeerSize((String) beers.get("size"));
        beerObject.add(beer);
      }
    } catch (ParseException e) {
      Log.e("Error", e.getMessage());
      e.printStackTrace();
    }

    adapter = new BeersListViewAdapter(getActivity(), beerObject);
    setListAdapter(adapter);

    adapter.notifyDataSetChanged();
  }