예제 #1
0
  static float[] updateGraph() {
    long timeStep = 1445214540000L;
    float[] results = new float[numData];

    ParseQuery<ParseObject> query = ParseQuery.getQuery("data");
    query.whereEqualTo("flag", 1);
    try {
      ParseObject flagged = query.getFirst();
      timeStep = flagged.getLong("unixTimeStamp");
      flagged.put("flag", 0);
      flagged.saveInBackground();
      Log.d("Find Flag", flagged.getObjectId());
    } catch (ParseException e) {
      Log.d("Find Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByAscending("unixTimeStamp");
    query.whereGreaterThan("unixTimeStamp", timeStep);
    try {
      ParseObject nextFlag = query.getFirst();
      nextFlag.put("flag", 1);
      nextFlag.saveInBackground();
      Log.d("Set Next Flag", nextFlag.getObjectId() + " is " + nextFlag.getInt("flag"));
    } catch (ParseException e) {
      Log.d("Set Next Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByDescending("unixTimeStamp");
    query.whereLessThan("unixTimeStamp", timeStep);
    for (int i = 0; i < numData; i++) {
      try {
        ParseObject data = query.getFirst();
        results[numData - i - 1] = (float) data.getInt("Bg");
        query.whereLessThan("unixTimeStamp", data.getLong("unixTimeStamp"));
      } catch (ParseException e) {
        Log.d("Fill Results Array", "Failed");
      }
    }
    /*query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> data, ParseException e) {
            int i = 0;

            if (e == null) {
                Log.d("Blood Glucose", "Retrieved " + data.size() + " Blood Glucose Data Points");
                for(ParseObject person : data) {
                    results[i] = person.getInt("Bg");
                    i++;
                }
            }
            else {
                Log.d("Blood Glucose", "Error: " + e.getMessage());
            }
        }
    });*/
    return results;
  }
예제 #2
0
  public void getMorePosts(final NewsFeedAdapter adapter) {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
    query.setLimit(2);
    if (mLast != -1 && mPrevious != mLast) {

      query.orderByDescending("createdAt");
      query.whereLessThan("number", mLast);
      mPrevious = mLast;
    } else {
      Toast.makeText(adapter.getContext(), "No more posts", Toast.LENGTH_SHORT).show();
      return;
    }

    final int count = adapter.getCount();
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
              ArrayList<News> news = new ArrayList<News>();
              for (ParseObject item : list) {
                News n = new News();

                n.setTitle(item.getString("title"));
                n.setLocation(item.getString("location"));
                n.setTime(item.getString("time"));
                n.setText(item.getString("text"));
                n.setIndicator((ArrayList<String>) item.get("icons"));
                n.setType(item.getString("type"));
                n.setDate(item.getDate("date"));
                n.setAuthor(item.getString("Author"));
                n.setCreatedAt(item.getCreatedAt());
                news.add(n);
              }

              adapter.addItems(news);
            } else {
              e.printStackTrace();
            }
          }
        });
  }
예제 #3
0
  public static void addUserMeal(
      final Calendar cal,
      final ParseUser user,
      final List<DiaryEntry> entries,
      final String userMeal) {

    // Check if user meal exists
    ParseQuery<ParseObject> query = ParseQuery.getQuery("UserMeal");
    query.whereGreaterThan("date", Utils.getDateBefore(cal));
    query.whereLessThan("date", Utils.getDateAfter(cal));
    query.whereEqualTo("user", user);
    query.whereEqualTo("title", userMeal);

    query.findInBackground(
        new FindCallback<ParseObject>() {

          public void done(List<ParseObject> meals, ParseException e) {

            if (e == null && meals.size() > 0) {

              // Add diary entries to already existing UserMeal
              UserMeal meal = (UserMeal) meals.get(0);
              for (DiaryEntry entry : entries) {
                meal.addDiaryEntry(entry);
              }
              meal.saveInBackground();

            } else {

              // Add new UserMeal to parse
              UserMeal newmeal = new UserMeal();
              newmeal.put("date", cal.getTime());
              newmeal.put("user", user);
              newmeal.put("title", userMeal);
              newmeal.put("entries", entries);
              newmeal.saveInBackground();
            }
          }
        });
  }
  private void RefreshRumours() {
    if (isNetworkAvailable() == false) {
      noInternetAccess();
      return;
    }

    refresh = false;
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(publicchannel);
    Date day = new Date();
    day.setDate(day.getDate() - 1);
    query.whereLessThan("createdAt", day);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> objects, ParseException e) {
            ParseObject myObject;
            Log.v("hiiiiii", publicchannel + " " + refresh + objects.size());

            for (int i = 0; i < objects.size(); ++i) {
              myObject = objects.get(i);
              myObject.deleteInBackground();
            }
          }
        });

    if (Build.VERSION.SDK_INT >= 11) {
      recreate();
    } else {
      Intent intent = getIntent();
      intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
      finish();
      overridePendingTransition(0, 0);

      startActivity(intent);
      overridePendingTransition(0, 0);
    }
  }