Exemple #1
0
  private void retrieveMessages() {
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
    query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> messages, ParseException e) {

            if (mSwipe.isRefreshing()) {
              mSwipe.setRefreshing(false);
            }

            if (e == null) {
              // We found the message
              mMessages = messages;
              String[] usernames = new String[mMessages.size()];
              int i = 0;
              for (ParseObject message : mMessages) {
                usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
                i++;
              }
              if (getListView().getAdapter() == null) {
                MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                setListAdapter(adapter);
              } else {
                // Refill listview
                ((MessageAdapter) getListView().getAdapter()).refill(mMessages);
              }
            }
          }
        });
  }
  private void getCurrentUserId(String phoneNumber) {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("SimpleUser");
    query.whereEqualTo("phone_number", phoneNumber);
    query.getFirstInBackground(
        new GetCallback<ParseObject>() {
          public void done(ParseObject object, ParseException e) {
            if (e == null) {
              String userId = object.getObjectId().toString();
              String currentUserObjId = userId;
              SimpleUser.currentUserObjectId = currentUserObjId;
              // Write the userId in shared pref if the user successfully signed up
              SharedPreferences pref =
                  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
              SharedPreferences.Editor edit = pref.edit();
              edit.putString("userId", userId);
              edit.commit();

              Intent returnIntent = new Intent();
              setResult(RESULT_OK, returnIntent);
              finish();
              overridePendingTransition(R.anim.stay_in_place, R.anim.exit_to_bottom);
            } else {
              Log.d("DEBUG", "Error: " + e.getMessage());
            }
          }
        });
  }
  // open history chat from parse
  private void GetingHistoryChat(final String friend, final String me) {

    ParseQuery<ParseObject> GetMessageTable = ParseQuery.getQuery("Message");
    GetMessageTable.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> object, ParseException e) {
            if (e == null) {
              for (int indx = 0; indx < object.size(); indx++) {
                // if its my message
                if (object.get(indx).getString("Receiver").matches(friend)
                    && object.get(indx).getString("Sender").matches(me)) {
                  abp.add(
                      new ChatMessage(
                          side,
                          object.get(indx).getString("txt")
                              + "\n"
                              + object.get(indx).getString("Time")));
                } else if (object.get(indx).getString("Receiver").matches(me)
                    && object.get(indx).getString("Sender").matches(friend)) {
                  abp.add(
                      new ChatMessage(
                          !side,
                          object.get(indx).getString("txt")
                              + "\n"
                              + object.get(indx).getString("Time")));
                }
              }
            }
          }
        });
  }
Exemple #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_display);
    if (savedInstanceState == null) {
      Bundle extras = getIntent().getExtras();
      if (extras == null) {
        itemId = null;
      } else {
        itemId = extras.getString("itemId");
      }
    } else {
      itemId = (String) savedInstanceState.getSerializable("itemId");
    }

    if (savedInstanceState == null) {
      Bundle extras = getIntent().getExtras();
      if (extras == null) {
        imageNum = 0;
      } else {
        imageNum = extras.getInt("imageNum");
      }
    } else {
      imageNum = (int) savedInstanceState.getSerializable("imageNum");
    }

    if (savedInstanceState == null) {
      Bundle extras = getIntent().getExtras();
      if (extras == null) {
        userId = null;
      } else {
        userId = extras.getString("userId");
      }
    } else {
      userId = (String) savedInstanceState.getSerializable("userId");
    }

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Item");
    query.getInBackground(
        itemId,
        new GetCallback<ParseObject>() {
          public void done(ParseObject object, ParseException e) {
            if (e == null) {

              if (object.has("itemImage0")) {
                ImageView displayImage = (ImageView) findViewById(R.id.imageDisplay);
                ParseFile image = object.getParseFile("itemImage0");
                try {
                  byte[] imageData = image.getData();
                  Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
                  displayImage.setImageBitmap(bitmap);
                } catch (ParseException e1) {
                  e1.printStackTrace();
                }
              }
            } else {
            }
          }
        });
  }
 private void loadSaturdayFromParse() {
   ParseQuery<Saturday> query = Saturday.getQuery();
   query.findInBackground(
       new FindCallback<Saturday>() {
         public void done(List<Saturday> saturdayList, ParseException e) {
           if (e == null) {
             ParseObject.pinAllInBackground(
                 (List<Saturday>) saturdayList,
                 new SaveCallback() {
                   public void done(ParseException e) {
                     if (e == null) {
                       if (!getActivity().isFinishing()) {
                         saturdaySGWListAdapter.loadObjects();
                         saturdayLoyolaListAdapter.loadObjects();
                       }
                     } else {
                       Log.i("MainActivity", "Error pinning saturday: " + e.getMessage());
                     }
                   }
                 });
           } else {
             Log.i(
                 "MainActivity",
                 "loadSaturdayFromParse: Error finding pinned saturday: " + e.getMessage());
           }
         }
       });
 }
  private void activePatientData() {

    ParseQuery<ParseObject> query = ParseQuery.getQuery("PatientDetails");
    query.whereEqualTo("patientId", patientIdRemove);
    try {
      ParseObject object = query.getFirst();
      object.put("status", "Active");
      object.save();
    } catch (ParseException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }

    /*	ParseQuery<ParseObject> query3 = ParseQuery.getQuery("_User");
    query3.whereEqualTo("userId", patientIdRemove);
    try {
    	ParseObject object = query3.getFirst();
    	object.put("status", "Active");
    	object.save();

    	}catch (ParseException e2) {
    	// TODO Auto-generated catch block
    	e2.printStackTrace();
    }*/

    Toast.makeText(SearchPatientByAdmin.this, "Patient Active", Toast.LENGTH_SHORT).show();
  }
  private void updatePostList() {
    // Create query for objects of type "Post"
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");

    // Restrict to cases where the author is the current user.
    // Note that you should pass in a ParseUser and not the
    // String representation of that user
    query.whereEqualTo("author", ParseUser.getCurrentUser());
    // Run the query
    query.findInBackground(
        new FindCallback<ParseObject>() {

          @Override
          public void done(List<ParseObject> postList, ParseException e) {
            if (e == null) {
              // If there are results, update the list of posts
              // and notify the adapter
              posts.clear();
              for (ParseObject post : postList) {
                posts.add(post.getString("textContent"));
              }
              ((ArrayAdapter<String>) getListAdapter()).notifyDataSetChanged();
            } else {
              Log.d("Post retrieval", "Error: " + e.getMessage());
            }
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choosehackathon);

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Hackathon");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(final List<ParseObject> hackathonList, ParseException e) {
            if (e == null) {
              final ArrayList<String> hackathonNames = new ArrayList<String>();
              final ListView listChooseHackathon =
                  (ListView) findViewById(R.id.listChooseHackathon);
              for (ParseObject o : hackathonList) hackathonNames.add(o.getString("name"));
              ArrayAdapter<String> aa =
                  new ArrayAdapter<String>(
                      context, android.R.layout.simple_list_item_1, hackathonNames);
              listChooseHackathon.setAdapter(aa);
              listChooseHackathon.setOnItemClickListener(
                  new AdapterView.OnItemClickListener() {
                    public void onItemClick(
                        AdapterView<?> parentView, View childView, int position, long id) {
                      Intent i = new Intent(context, HackathonInfoActivity.class);
                      Bundle b = new Bundle();
                      b.putString("hackathon_id", hackathonList.get(position).getObjectId());
                      b.putString("user_id", getIntent().getExtras().getString("user_id"));
                      i.putExtras(b);
                      startActivity(i);
                    }
                  });
            } else alertMessage("Error", "Error retrieving hackathons", true);
          }
        });
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /** Called when the activity is first created. */
    setContentView(R.layout.stream);

    ParseUser currentUser = ParseUser.getCurrentUser();
    if (currentUser == null) {
      startActivity(new Intent(this, StartActivity.class));
    }

    ParseQuery query = new ParseQuery("Vow");
    query.whereEqualTo("user", ParseUser.getCurrentUser());
    query.findInBackground(
        new FindCallback() {
          public void done(List<ParseObject> evidence, com.parse.ParseException e) {
            if (e == null) {
              setListAdapter(new EvidenceAdapter(StreamActivity.this, evidence));
            } else {
              Log.d("Dmitrij", "Error: " + e.getMessage());
            }
          }
        });

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
    }
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      menulista = new ArrayList<MenuSetGet>();
      try {
        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("computadoras");
        // Locate the column named "ranknum" in Parse.com and order list
        // by ascending
        query.orderByAscending("orden");
        ob = query.find();
        for (ParseObject country : ob) {
          // Locate images in flag column
          ParseFile image = (ParseFile) country.get("imagen");

          MenuSetGet map = new MenuSetGet();
          map.setNombre((String) country.get("nombre"));
          map.setDetalle((String) country.get("Detalle"));
          map.setPrecio((String) country.get("precio"));
          map.setImagen(image.getUrl());
          menulista.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
  protected void getMarkersFromParse() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Route");
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> routeObjects, com.parse.ParseException e) {
            if (e == null) {

              for (ParseObject object : routeObjects) {
                String id = object.getObjectId().toString();
                double longitude = object.getParseGeoPoint("startingPointGeo").getLongitude();
                double latitude = object.getParseGeoPoint("startingPointGeo").getLatitude();
                String title = object.getString("startingPoint");
                String destination = object.getString("destination");

                Marker marker =
                    mGoogleMap.addMarker(
                        new MarkerOptions()
                            .position(new LatLng(latitude, longitude))
                            .title("#id: " + id)
                            .snippet(
                                title
                                    + " - "
                                    + destination
                                    + "\nStart date: "
                                    + object.getString("date")
                                    + "\nStart time: "
                                    + object.getString("time")));

                mMarkers.add(marker);
              }
            }
          }
        });
  }
Exemple #12
0
 private void startManageContent() {
   // if you're logged
   if (app.logged()) {
     findViewById(R.id.progress).setVisibility(View.VISIBLE);
     manageNotLoggedText.setVisibility(View.GONE);
     ParseQuery<ParseObject> query = ParseQuery.getQuery(Consts.PROTEST);
     query.whereEqualTo(Consts.P_ADMIN, app.getUsername());
     query.orderByDescending("createdAt");
     query.findInBackground(
         new FindCallback<ParseObject>() {
           public void done(List<ParseObject> retrievedProtestList, ParseException e) {
             if (e == null) {
               manageProtestArrList = Protest.convertList(retrievedProtestList);
               manageProtestAdapter =
                   new ProtestsAdapter(con, R.layout.row_protest, manageProtestArrList);
               manageProtestList.setAdapter(manageProtestAdapter);
               showHideNoProtestsMsg(retrievedProtestList);
             } else {
               Log.v(TAG, "Error: " + e.getMessage());
             }
             findViewById(R.id.progress).setVisibility(View.GONE);
           }
         });
   } else {
     notLogged("view protests you manage ", getString(R.string.unregistered_manage));
   }
 }
Exemple #13
0
  private void retrieveMessages() {
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstant.CLASS_MESSAGE);
    query.whereEqualTo(ParseConstant.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addDescendingOrder(ParseConstant.KEY_CREATED_AT);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            getActivity().setProgressBarIndeterminateVisibility(false);
            if (mSwipeRefreshLayout.isRefreshing()) {
              mSwipeRefreshLayout.setRefreshing(false);
            }

            if (e == null) {
              // No found message
              mMessages = list;
              String[] usernames = new String[mMessages.size()];
              int i = 0;
              for (ParseObject message : mMessages) {
                usernames[i] = message.getString(ParseConstant.KEY_SENDER_NAME);
                i++;
              }
              if (getListView().getAdapter() == null) {
                MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                setListAdapter(adapter);
              } else {
                // refill the adapter
                ((MessageAdapter) getListView().getAdapter()).refill(mMessages);
              }
            }
          }
        });
  }
  public static Task<ArrayList<ParseObject>> fetchFirstDataFromParse(
      ArrayList<ParseQuery<ParseObject>> arrayList) {

    final TaskCompletionSource<ArrayList<ParseObject>> successful = new TaskCompletionSource<>();

    ArrayList<Task<List<ParseObject>>> mutu = new ArrayList<>();

    for (ParseQuery<ParseObject> query : arrayList) {

      mutu.add(query.findInBackground());
    }

    Task.whenAllResult(mutu)
        .continueWith(
            new Continuation<List<List<ParseObject>>, Object>() {
              @Override
              public Object then(Task<List<List<ParseObject>>> task) throws Exception {
                return null;
              }
            });
    /*

            Task.whenAllResult(mutu).continueWith(new Continuation<List<List<ParseObject>>, Object>() {
                @Override
                public Object then(Task<List<List<ParseObject>>> task) throws Exception {
                    //successful.setResult(task.getResult());
                    successful.setResult();

                    return task;
                }
            });

    */
    return successful.getTask();
  }
Exemple #15
0
  public void getUsers(final List<ParseObject> list, final int listSize, final int i) {
    size = listSize;
    if (i == listSize) {
      checkList();
    } else {
      if ((list.get(i).getString("toUser") + "").equals(currentUser.getObjectId() + "")) {
        friendid = list.get(i).getString("fromUser");
      } else {
        friendid = list.get(i).getString("toUser");
      }

      ParseQuery<ParseUser> query = ParseUser.getQuery();
      query.getInBackground(
          friendid,
          new GetCallback<ParseUser>() {

            @Override
            public void done(ParseUser arg0, ParseException arg1) {
              // Toast.makeText(Friends.this, arg0.getObjectId()+"", Toast.LENGTH_SHORT).show();
              addUser(arg0);
              getUsers(list, listSize, i + 1);
            }
          });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_status_detail_view);

    mStatus = (TextView) findViewById(R.id.statusDetailView);

    // get intent that status detail
    Intent intent = getIntent();
    status = intent.getStringExtra("objectID");

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");

    query.getInBackground(
        status,
        new GetCallback<ParseObject>() {
          @Override
          public void done(ParseObject parseObject, ParseException e) {
            if (e == null) {
              // success
              String userStatus = parseObject.getString("newStatus");
              mStatus.setText(userStatus);
            } else {
              // there was a problem, advice user

            }
          }
        });
  }
 // load user's profile image from parse - added by alex, edited by Jamie
 public void retrieveImage(String struser) {
   ParseQuery query = ParseUser.getQuery();
   query.whereContains("username", struser);
   query.findInBackground(
       new FindCallback<ParseObject>() {
         public void done(List<ParseObject> objects, ParseException e) {
           if (e == null) {
             // The query was successful.
             // Locate the column named "ImageName" and set
             // the string
             for (ParseObject ob : objects) {
               ParseFile fileObject = (ParseFile) ob.getParseFile("profileImg");
               if (fileObject != null) {
                 profileImg.setParseFile(fileObject);
                 profileImg.loadInBackground(
                     new GetDataCallback() {
                       @Override
                       public void done(byte[] bytes, ParseException e) {
                         // nothing to be done
                       }
                     });
               } else profileImg.setImageResource(R.drawable.no_image);
             }
           } else {
             // Something went wrong. Look at the ParseException to see what's up.
           }
         }
       });
 }
 @Override
 public Object getData(Object... params)
     throws JSONException, SQLException, NullPointerException, RestException, ClassCastException,
         ParseException {
   ParseQuery<ParseObject> query = (ParseQuery<ParseObject>) params[0];
   return query.find();
 }
Exemple #19
0
  // TODO: What to do with strings? leave it of clean it
  public void getNewPosts(final NewsFeedAdapter adapter) {

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
    query.setLimit(2);
    query.orderByDescending("createdAt");
    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());
                Log.d("CREATEDAT", item.getCreatedAt().toString());
                news.add(n);
              }
              mLast = list.get(list.size() - 1).getInt("number");
              adapter.addItems(news);
            } else {
              e.printStackTrace();
            }
          }
        });
  }
    @Override
    protected String doInBackground(String... params) {

      // Notify Parse Analytics that the app has been opened
      ParseAnalytics.trackAppOpenedInBackground(getIntent());

      CardDbHelper cardDbHelper = new CardDbHelper(getBaseContext());

      SQLiteDatabase db = cardDbHelper.getWritableDatabase();
      cardDbHelper.onCreate(db);

      try {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Card");
        query.setLimit(1000);
        query.selectKeys(Arrays.asList(""));
        List<ParseObject> results = query.find();

        Iterator<ParseObject> iterator = results.iterator();

        // Writing values to DB
        ContentValues values = new ContentValues();

        while (iterator.hasNext()) {
          ParseObject next = iterator.next();
          values.put("cardId", next.getObjectId().toString());
          db.insert(CardDbHelper.TABLE_NAME, "null", values);
        }

      } catch (ParseException e) {
        e.printStackTrace();
      }

      return "";
    }
  public void getQuotes(final Context context) {
    row_quotes = new ArrayList<RowQuote>();

    query.whereExists("createdAt");
    query.orderByDescending("createdAt");
    query.setLimit(1000);

    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> quoteList, ParseException e) {
            if (e == null) {
              for (int i = 0; i < quoteList.size(); i++) {
                String quote = quoteList.get(i).getString("Quote");
                String name = quoteList.get(i).getString("Name");
                row_quotes.add(new RowQuote(name, quote));

                //						if (i == quoteList.size()-1) {
                //							last_item_date = quoteList.get(i).getCreatedAt();
                //						}
              }
            } else {
              row_quotes.add(
                  new RowQuote(
                      "Justin",
                      "hm, either you don't have internet connection or my database is down"));
            }

            row_adapter = new RowQuoteAdapter(context, row_quotes);
            list = (ListView) getActivity().findViewById(R.id.list);
            list.setAdapter(row_adapter);
          }
        });
  }
  @Override
  protected void onResume() {
    super.onResume();
    if (!onResumeHasRun) {
      onResumeHasRun = true;
      return;
    }

    movieList = new ArrayList<String>();
    noItemsTV.setVisibility(View.GONE);

    ParseUser currentUser = ParseUser.getCurrentUser();
    if (currentUser != null) {
      ParseQuery<ParseObject> query = ParseQuery.getQuery("itemInfo");
      query.whereEqualTo("user", currentUser);
      query.findInBackground(
          new FindCallback<ParseObject>() {

            @Override
            public void done(List<ParseObject> movObjs, ParseException arg1) {
              // TODO Auto-generated method stub
              if (arg1 == null) {
                for (ParseObject object : movObjs) {
                  movieList.add(object.get("title").toString());
                }
                setAdapter();
              } else {
                Log.d("Error", "Error: " + arg1.getMessage());
              }
            }
          });
    }
  }
Exemple #23
0
  public void moreImageFunction(View view) {

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Item");
    query.getInBackground(
        itemId,
        new GetCallback<ParseObject>() {
          public void done(ParseObject object, ParseException e) {
            if (e == null) {
              imageNum = next(imageNum);
              String item = "itemImage" + imageNum;
              if (object.has(item)) {
                ImageView displayImage = (ImageView) findViewById(R.id.imageDisplay);
                ParseFile image = object.getParseFile(item);
                try {
                  byte[] imageData = image.getData();
                  Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
                  displayImage.setImageBitmap(bitmap);
                } catch (ParseException e1) {
                  e1.printStackTrace();
                }
              }
            } else {
            }
          }
        });
  }
Exemple #24
0
  public void syncWithParse() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseConstants.CLASS_SAVED_WORD);
    query.whereEqualTo(ParseConstants.SAVED_WORD_USER, ParseUser.getCurrentUser());
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> words, ParseException e) {
            if (e == null) {
              // delete current data in Parse
              for (ParseObject word : words) {
                word.deleteInBackground();
              }

              // save data in local database to Parse
              ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseConstants.CLASS_SAVED_WORD);
              query.whereEqualTo(ParseConstants.SAVED_WORD_USER, ParseUser.getCurrentUser());
              query.fromLocalDatastore();
              query.findInBackground(
                  new FindCallback<ParseObject>() {
                    @Override
                    public void done(List<ParseObject> words, ParseException e) {
                      if (e == null) {
                        // save each word to Parse
                        for (ParseObject word : words) {
                          word.saveInBackground();
                        }
                      }
                    }
                  });
            }
          }
        });
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      soaplist = new ArrayList<WorldPopulation>();
      try {
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Product");
        // query.orderByAscending("Product");
        ob = query.find();
        for (ParseObject Product : ob) {
          // Locate images in Picture column
          ParseFile image = (ParseFile) Product.get("Picture");

          WorldPopulation map = new WorldPopulation();
          if (Product.get("Category").equals("soaps and shampoos")) {
            map.setPrice((String) Product.get("Price"));
            map.setProduct((String) Product.get("Product"));
            map.setCategory((String) Product.get("Category"));
            map.setQuantity(Integer.parseInt(Product.get("qty").toString()));
            map.setPicture(image.getUrl());
            soaplist.add(map);
          }
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
  public void saveNote() {
    String titleToSave = titleEditText.getText().toString().trim();
    String contentToSave = contentEditText.getText().toString().trim();

    if (!contentToSave.isEmpty() || !titleToSave.isEmpty()) {
      if (note == null) {
        ParseObject post = new ParseObject("Post");
        post.put("title", titleToSave);
        post.put("content", contentToSave);
        post.put("author", ParseUser.getCurrentUser());
        post.saveInBackground();
        callback.onNoteAdded(titleToSave, contentToSave);
      } else {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
        final String newTitleToSave = titleToSave;
        final String newContentToSave = contentToSave;
        query.getInBackground(
            note.getId(),
            new GetCallback<ParseObject>() {
              @Override
              public void done(ParseObject parseObject, ParseException e) {
                if (e == null) {
                  parseObject.put("title", newTitleToSave);
                  parseObject.put("content", newContentToSave);
                  callback.onNoteChanged(new Note(newTitleToSave, newContentToSave), note);
                  parseObject.saveInBackground();
                }
              }
            });
      }
    }
  }
  private void displayInfo() {
    // get the info that was passed in from EventVoteActivity
    String eventId = getIntent().getExtras().getString("eventId");
    position = getIntent().getExtras().getInt("position");

    // find the Event in Parse to grab info from
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Event");
    query.whereEqualTo("objectId", eventId);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
              // set the text on the page to the information for that restaurant
              // that is stored in Parse
              ParseObject obj = list.get(0);
              restaurantName.setText((String) obj.getList("restaurants").get(position));
              rating.setText((String) obj.getList("ratings").get(position));
              type.setText((String) obj.getList("typeOfFood").get(position));
              address.setText((String) obj.getList("addresses").get(position));
              phone.setText((String) obj.getList("phoneNumbers").get(position));
            }
          }
        });
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Create the array
      photoarraylist = new ArrayList<PhotoList>();
      try {
        // Locate the class table named "ImageUpload" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("ImageUpload");
        // Locate the column named "position" in Parse.com and order list
        // by descending order of created.
        query.orderByDescending("createdAt");
        query.setLimit(15);
        ob = query.find();
        for (ParseObject po : ob) {
          // retrieve objectID and Title
          String stringTitle = (String) po.get("Title");
          String stringObjectID = po.getObjectId();

          // retrieve the image file
          ParseFile image = (ParseFile) po.get("Photo");
          PhotoList map = new PhotoList();
          map.setPhoto(image.getUrl());
          map.setObjectID(stringObjectID);
          map.setTitle(stringTitle);
          photoarraylist.add(map);
        }
      } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
      }
      return null;
    }
  /** This function downloads the Splash Image from the Parse Table 'Splash' */
  public void downloadSplashImage() {
    Log.e("downloadSplashImage", "downloadSplashImage");

    dialog1.setMessage("Downloading Splash Image...");
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Splash");
    query.whereEqualTo("username", Login.USERNAME);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
              ParseFile myFile = objects.get(0).getParseFile("image");
              myFile.getDataInBackground(
                  new GetDataCallback() {
                    public void done(byte[] data, ParseException e) {
                      if (e == null) {
                        // user the function writeFile() to create the file in the Internal Memory
                        // the file name will be like someusername_splash.jpg
                        writeFile(data, Login.USERNAME + "_splash.jpg");
                        // once the splash image is downloaded, we need to download the images for
                        // the listview.
                        downloadImages();
                      } else {
                        Log.e("Something went wrong", "Something went wrong");
                      }
                    }
                  });
            } else {
              Log.e("PARSE", "Error: " + e.getMessage());
            }
          }
        });
  }
Exemple #30
0
  public void show1(View v) {
    String code = tv.getText().toString();
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
    query.whereEqualTo("Image", code);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> parseObjects, ParseException e) {
            ParseFile file = (ParseFile) parseObjects.get(0).get("ImageFile");
            file.getDataInBackground(
                new GetDataCallback() {
                  @Override
                  public void done(byte[] bytes, ParseException e) {
                    Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                    img1.setImageBitmap(bmp);
                  }
                });
          }
        });

    /*DBAdapter1 db = new DBAdapter1(this);
    String name = db.getbook(code);

    Uri muri = Uri.parse(name);
     s = getPath(muri);
        System.out.println("Image Path : " + s);
        img1.setImageURI(muri);*/
  }