public void sampleFileExport(String fileName, String filePath) { String fileContent = sampleFileGetContent(filePath); byte[] data = fileContent.getBytes(); ParseFile file = new ParseFile(fileName, data); TextView fileSize = (TextView) findViewById(R.id.sampleSize); fileSize.setText("" + fileContent.length()); file.saveInBackground(); ParseObject jobApplication = new ParseObject("SensoramaFile"); jobApplication.put("fileName", fileName); jobApplication.put("sampleFile", file); jobApplication.put("devname", SRCfg.deviceName); jobApplication.saveInBackground(); }
public void getContactInfos(List<String> usernames, final EMValueCallBack<List<EaseUser>> callback) { ParseQuery<ParseObject> pQuery = ParseQuery.getQuery(CONFIG_TABLE_NAME); pQuery.whereContainedIn(CONFIG_USERNAME, usernames); pQuery.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> arg0, ParseException arg1) { if (arg0 != null) { List<EaseUser> mList = new ArrayList<EaseUser>(); for (ParseObject pObject : arg0) { EaseUser user = new EaseUser(pObject.getString(CONFIG_USERNAME)); ParseFile parseFile = pObject.getParseFile(CONFIG_AVATAR); if (parseFile != null) { user.setAvatar(parseFile.getUrl()); } user.setNick(pObject.getString(CONFIG_NICK)); EaseCommonUtils.setUserInitialLetter(user); mList.add(user); } callback.onSuccess(mList); } else { callback.onError(arg1.getCode(), arg1.getMessage()); } } }); }
public static void retreiveprofile(String username , final Context context) { ParseQuery<ParseObject> query= ParseQuery.getQuery("Profile"); query.whereEqualTo("user",username); query.getFirstInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject parseObject, ParseException e) { if(parseObject!=null && e==null) { ParseFile file = (ParseFile) parseObject.get("image"); String url = "http://wwww.webianks.com"; if (file != null) { url = file.getUrl().toString(); } MainActivity.retriveProfileCallback(context, url); }else{ //canntretrivee file } } }); }
public static void retreivetimelineprofile(String username , final Context context) { ParseQuery<ParseObject> query= ParseQuery.getQuery("Profile"); query.whereEqualTo("user",username); query.getFirstInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject parseObject, ParseException e) { if(parseObject!=null && e==null) { ParseFile file = (ParseFile) parseObject.get("image"); String url = "http://wwww.webianks.com"; if (file != null) { url = file.getUrl().toString(); } Profile.retriveTimelineProfileCallback(context, url); }else{ //canntretrivee file } } }); }
private void getUserDetailsFromParse() { parseUser = ParseUser.getCurrentUser(); //Fetch profile photo try { ParseFile parseFile = parseUser.getParseFile("profileThumb"); byte[] data = parseFile.getData(); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); mProfileImage.setImageBitmap(bitmap); } catch (Exception e) { e.printStackTrace(); } mEmailID.setText(parseUser.getEmail()); mUsername.setText(parseUser.getUsername()); Toast.makeText(MainActivity.this, "Welcome back " + mUsername.getText().toString(), Toast.LENGTH_SHORT).show(); }
protected ParseObject createMessage() { ParseObject message = new ParseObject(ParseConstants.CLASS_MESSAGES); message.put(ParseConstants.KEY_SENDER_ID, ParseUser.getCurrentUser().getObjectId()); message.put(ParseConstants.KEY_SENDER_NAME, ParseUser.getCurrentUser().getUsername()); message.put(ParseConstants.KEY_RECIPIENT_IDS, getRecipientIds()); message.put(ParseConstants.KEY_FILE_TYPE, mFileType); byte[] fileBytes = FileHelper.getByteArrayFromFile(this, mMediaUri); if (fileBytes == null) { return null; } else { if (mFileType.equals(ParseConstants.TYPE_IMAGE)) { fileBytes = FileHelper.reduceImageForUpload(fileBytes); } String fileName = FileHelper.getFileName(this, mMediaUri, mFileType); ParseFile file = new ParseFile(fileName, fileBytes); message.put(ParseConstants.KEY_FILE, file); return message; } }
public static Event getEventFromParseObject(@NonNull ParseObject parseObject){ ParseGeoPoint location = parseObject.getParseGeoPoint(Event.LOCATION); ParseFile parseFile = parseObject.getParseFile(Event.IMAGE); return new Event(parseObject.getObjectId(), parseObject.getString(Event.TITLE), parseObject.getString(Event.DESCRIPTION), location != null? location.getLatitude() : Event.INVALID_LOCATION, location != null? location.getLongitude() : Event.INVALID_LOCATION, parseObject.getString(Event.LOCATION_SUMMARY), parseObject.getString(Event.LOCATION_DESCRIPTION), parseFile != null? parseFile.getUrl() : null, parseObject.getDate(Event.INITIAL_DATE), // If end date is null, set it as initial date, so we can use it in our order by parseObject.getDate(Event.END_DATE) != null? parseObject.getDate(Event.END_DATE) : parseObject.getDate(Event.INITIAL_DATE), parseObject.getInt(Event.TYPE), parseObject.getBoolean(Event.ENABLED), (parseObject.getNumber(Event.GOING) != null)? parseObject.getNumber(Event.GOING).longValue() : 0, parseObject.getString(Event.LINK_URL), parseObject.getString(Event.LINK_TEXT), parseObject.getUpdatedAt() ); }
private void fetchInfoFromParse() throws Exception { ParseUser currentUser = ParseUser.getCurrentUser(); if (currentUser != null) { if (currentUser.get(ParseTables.Users.EMAIL) != null) tEmail.setText(currentUser.getString(ParseTables.Users.EMAIL)); if (currentUser.get(ParseTables.Users.INSTITUTE) != null) { eInstitute.setText(currentUser.getString(ParseTables.Users.INSTITUTE)); } if (currentUser.get(ParseTables.Users.NAME) != null) tFullName.setText(currentUser.getString(ParseTables.Users.NAME)); if (currentUser.get(ParseTables.Users.QUALIFICATIONS) != null) eQualificaton.setText(currentUser.getString(USER_QUALIFICATIONS)); } else { //TODO: handle errors if any generated } ParseFile profileFile = null; if (currentUser != null) { profileFile = currentUser.getParseFile(ParseTables.Users.IMAGE); } imageProfile.setParseFile(profileFile); imageProfile.loadInBackground(); }
public Bitmap convertFileToBitmap(ParseFile picFile){ if(picFile == null){ return null; } try { byte[] image = picFile.getData(); if(image!=null){ Bitmap pic = BitmapFactory.decodeByteArray(image, 0, image.length); return pic; } } catch (ParseException e) { e.printStackTrace(); return null; } return null; }
public Bitmap getPic(){ ParseFile picFile=null; if(parseEntry!=null){ if(parseEntry.getParseFile("ProfilePic")!=null){ picFile = parseEntry.getParseFile("ProfilePic"); }; } if(picFile == null){ return null; } try { byte[] image = picFile.getData(); Bitmap pic = BitmapFactory.decodeByteArray(image, 0, image.length); return pic; } catch (ParseException e) { e.printStackTrace(); return null; } }
public Bitmap getPic() { if(triedPostPicFetch){ //If we've already retrieved it before(or got null) //return the same result return postPic; } triedPostPicFetch = true; //fetch the picfile from parse ParseFile picFile = getParseFile("picture"); if (picFile == null) { //there is no pic for this message return null; } else { Bitmap result = ImageOperations.bitmapFromPicFile(picFile, 300, 300); try { this.pin(); } catch (ParseException e) { e.printStackTrace(); } triedPostPicFetch = true; postPic = result; return result; } }
@Override public void onResume() { super.onResume(); ParseFile photoFile = ((NewPhotoActivity) getActivity()).getImageFile(); if (photoFile != null) { Log.i(AnypicApplication.TAG, "The photo WAS taken"); photoPreview.setParseFile(photoFile); photoPreview.loadInBackground(new GetDataCallback() { @Override public void done(byte[] data, ParseException e) { photoPreview.setVisibility(View.VISIBLE); } }); } else{ photoPreview.setVisibility(View.INVISIBLE); } }
/** * Saves a SnackEntry and its photo to Parse and adds the SnackEntry to the SnackList. * * @param entry The SnackEntry to add * @param photo The SnackEntry's photo * @param callback Optional. The callback to invoke after completion. */ public void addSnack(final SnackEntry entry, final ParseFile photo, @Nullable final SaveCallback callback){ if(photo.isDirty()){ notifyUpdateStart(); photo.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { entry.setPhoto(photo); addSnack(entry, callback); } else if(callback != null){ callback.done(e); } } }); } else { entry.setPhoto(photo); addSnack(entry, callback); } }
@Override protected Void doInBackground(Void... voids) { for(ParseObject o : mCatImages) { ParseFile file = o.getParseFile("image"); try { Bitmap bmp = BitmapFactory.decodeByteArray(file.getData(), 0, file.getData().length); CatImage c = new CatImage(); c.bitmap = bmp; c.objectId = o.getObjectId(); mAdapter.addImage(c); } catch (ParseException e) { Log.d("CatChatTag", "Failed to decode bitmap: " + o, e); } } return null; }
@Override public View getItemView(PrsPhoto photo, View v, ViewGroup parent) { if (v == null) { v = View.inflate(getContext(), R.layout.photo_list_adapter, null); } super.getItemView(photo, v, parent); ParseImageView photoImage = (ParseImageView) v.findViewById(R.id.icon); ParseFile photoFile = photo.getParseFile("photo"); if (photoFile != null) { photoImage.setParseFile(photoFile); photoImage.loadInBackground(new GetDataCallback() { @Override public void done(byte[] data, ParseException e) { // nothing to do } }); } return v; }
@Override public View getView(int position, View convertView, ViewGroup parent) { Student student = getItem(position); final ViewHolder viewHolder; if (convertView != null) { viewHolder = (ViewHolder)convertView.getTag(); } else { viewHolder = new ViewHolder(); LayoutInflater inflater = LayoutInflater.from(getContext()); convertView = inflater.inflate(R.layout.student_grid_item, parent, false); viewHolder.imageView = (RoundedParseImageView)convertView.findViewById(R.id.image_view); viewHolder.nameTextView = (TextView)convertView.findViewById(R.id.name_text_view); convertView.setTag(viewHolder); } viewHolder.nameTextView.setText(student.getName()); ParseFile profileImageFile = student.getProfileImage(); if (profileImageFile != null) { viewHolder.imageView.loadParseFileImageInBackground(profileImageFile); } return convertView; }
private User getUser(ParseObject parseUser) throws ParseException, IOException { parseUser.fetchIfNeeded(); String userId = parseUser.getObjectId(); User user = new User(); user.setId(userId); ParseFile profilePicFile; if (parseUser.getString(NAME) == null ){ ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_FACEBOOK_TABLE); query.whereEqualTo(USER, parseUser); List<ParseObject> result = query.find(); if (result.isEmpty()) { return user; } else { ParseObject fbInfo = result.iterator().next(); user.setName(fbInfo.getString(NAME)); profilePicFile = fbInfo.getParseFile(PROFILE_PICTURE_SMALL); } } else { user.setName(parseUser.getString(NAME)); profilePicFile = parseUser.getParseFile(PROFILE_PICTURE_SMALL); } if (profilePicFile != null) { setProfilePicture(userId, user, profilePicFile); } return user; }
@Override public void addFacebookUser(String facebookId, String name, byte[] profilePicture) { try { final ParseObject object = new ParseObject(USER_FACEBOOK_TABLE); //object.setACL(getPublicACL()); object.put(NAME, name); object.put(FACEBOOK_ID, facebookId); object.put(USER, ParseUser.getCurrentUser()); if (profilePicture != null) { ParseFile parseFile = new ParseFile("smallProfile.jpg", profilePicture); parseFile.save(); object.put(PROFILE_PICTURE_SMALL, parseFile); } object.save(); } catch (Exception e) { Log.e(LOG_TAG, "Failed saving user", e); } }
private void savePhotoAndReturn(ParseFile photoFile) { UserPicture userPicture = new UserPicture(); userPicture.setPhotoFile(photoFile); userPicture.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { FragmentManager fm = getActivity().getFragmentManager(); fm.popBackStack("CameraFragment", FragmentManager.POP_BACK_STACK_INCLUSIVE); } else { Toast.makeText(getActivity().getApplicationContext(), "Error saving: " + e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); }
@Override public View getItemView(UserPicture userPicture, View v, ViewGroup parent) { if (v == null) { v = View.inflate(getContext(), R.layout.item_list_photos, null); } super.getItemView(userPicture, v, parent); ParseImageView userImage = (ParseImageView) v.findViewById(R.id.icon); ParseFile photoFile = userPicture.getParseFile("photo"); if (photoFile != null) { userImage.setParseFile(photoFile); userImage.loadInBackground(new GetDataCallback() { @Override public void done(byte[] arg0, ParseException arg1) { // do nothing Log.d(TAG, "photoFile loaded"); } }); } else { Log.d(TAG, "photoFile is null"); } return v; }
public void bitmapToParse(@NonNull Bitmap bitmap){ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream); byte [] byteArray = outputStream.toByteArray(); image = new ParseFile("image.jpg",byteArray); //code for thumbNail BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = byteArray.length/50000; Bitmap thumbBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, options); ByteArrayOutputStream thumbStream = new ByteArrayOutputStream(); thumbBitmap.compress(Bitmap.CompressFormat.JPEG,100,thumbStream); byte [] thumbByteArray = thumbStream.toByteArray(); thumbNail = new ParseFile("thumbNail.jpg",thumbByteArray); }
public void asyncGetUserInfo(final String username,final EMValueCallBack<EaseUser> callback){ ParseQuery<ParseObject> pQuery = ParseQuery.getQuery(CONFIG_TABLE_NAME); pQuery.whereEqualTo(CONFIG_USERNAME, username); pQuery.getFirstInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject pUser, ParseException e) { if(pUser!=null){ String nick = pUser.getString(CONFIG_NICK); ParseFile pFile = pUser.getParseFile(CONFIG_AVATAR); if(callback!=null){ EaseUser user = DemoHelper.getInstance().getContactList().get(username); if(user!=null){ user.setNick(nick); if (pFile != null && pFile.getUrl() != null) { user.setAvatar(pFile.getUrl()); } }else{ user = new EaseUser(username); user.setNick(nick); if (pFile != null && pFile.getUrl() != null) { user.setAvatar(pFile.getUrl()); } } callback.onSuccess(user); } }else{ if(callback!=null){ callback.onError(e.getCode(), e.getMessage()); } } } }); }
@Override public void register(String email, String username, String password, Bitmap profilePicture) { final ParseUser user = new ParseUser(); user.setEmail(email); user.setUsername(username); user.setPassword(password); if (profilePicture != null){ byte[] pfArray = getBytesFromBitmap(profilePicture); final ParseFile file = new ParseFile("abc.png", pfArray); file.saveInBackground(); file.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null){ user.put("photo", file); signUpInBackground(user); } else { EventBus.getDefault().post(new RegisterCallbackEvent(false,e.getMessage())); } } }); } else { signUpInBackground(user); } }
private void saveParseFile(@NonNull String localMessageId, @NonNull File cacheFile) { final ParseObject image = ParseObject.create(ParseUtils.ImagesTable.NAME); try { image.put(ParseUtils.ImagesTable.Fields.IMAGE, new ParseFile(cacheFile)); image.put(ParseUtils.ImagesTable.Fields.LOCAL_MESSAGE_ID, localMessageId); image.save(); Log.d(TAG, "Saved file to Parse cloud"); } catch (ParseException e) { Log.e(TAG, "Unable to save parse object " + image, e); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.item_user_cell, parent, false); } final ParseImageView ivIcon = (ParseImageView) convertView.findViewById(R.id.ivIcon); final TextView tvUsername = (TextView) convertView.findViewById(R.id.tvUsername); final User user = mUsers.get(position); user.fetchIfNeededInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject parseObject, ParseException e) { ParseFile avatar = user.getAvatar(); if (avatar != null) ivIcon.setParseFile(avatar); String username = user.getUsername(); if (username != null) tvUsername.setText(username); ivIcon.loadInBackground(); } }); return convertView; }
private void pushDataToParse() { ParseObject event = new ParseObject("Events"); if (byteArray == null) { Drawable drawable = getResources().getDrawable(R.drawable.listings_placeholder); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 25, stream); byteArray = stream.toByteArray(); } ParseFile file = new ParseFile(ParseTables.Events.EVENT_PNG, byteArray); file.saveInBackground(); event.put(ParseTables.Events.IMAGE, file); event.put(ParseTables.Events.TITLE, events.get(ParseTables.Events.TITLE)); event.put(ParseTables.Events.DESCRIPTION, events.get(ParseTables.Events.DESCRIPTION)); event.put(ParseTables.Events.TYPE, events.get(ParseTables.Events.TYPE)); event.put(ParseTables.Events.LOCATION_DES, events.get(ParseTables.Events.LOCATION)); event.put(ParseTables.Events.DATE, events.get(ParseTables.Events.DATE)); event.put(ParseTables.Events.TIME, events.get(ParseTables.Events.TIME)); event.put(ParseTables.Events.CREATED_BY, events.get(ParseTables.Events.USER)); event.put(ParseTables.Events.URL, events.get(ParseTables.Events.URL)); event.put(ParseTables.Events.CONTACT, events.get(ParseTables.Events.CONTACT)); event.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { progressBarCircular.setVisibility(View.GONE); create.setClickable(true); Toast.makeText(getActivity().getApplicationContext(), getString(R.string.event_created), Toast.LENGTH_SHORT).show(); } }); }
public NotesCustomGridViewAdapter(Context c, ArrayList<String> notesCollegeName, ArrayList<String> notesBranchName, ArrayList<String> notesTopicName, ArrayList<String> notesSubjectName, ArrayList<ArrayList<ParseFile>> notesFirstImage, ArrayList<String> uploadedBy) { mContext = c; this.notesBranchName = notesBranchName; this.notesCollegeName = notesCollegeName; this.notesSubjectName = notesSubjectName; this.notesTopicName = notesTopicName; this.notesFirstImage = notesFirstImage; this.uploadedBy = uploadedBy; gridLayout = R.layout.notes_search_gridview_item; }
public void getNotes() { clear_lists(); ParseQuery<ParseObject> query = new ParseQuery<>( "Notes"); query.orderByDescending("createdAt"); query.setCachePolicy(ParseQuery.CachePolicy.NETWORK_ELSE_CACHE); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> parseObjects, ParseException e) { for (ParseObject notes : parseObjects) { notesBranchName.add((String) notes.get("branchName")); notesSubjectName.add((String) notes.get("subjectName")); notesCollegeName.add((String) notes.get("collegeName")); notesTopicName.add((String) notes.get("topicName")); uploadedBy.add((String) notes.get("userName")); notesFirstImage.add((ArrayList<ParseFile>) notes.get("notesImages")); } notesCustomGridViewAdapter = new NotesCustomGridViewAdapter(getActivity(), notesCollegeName, notesBranchName, notesTopicName, notesSubjectName, notesFirstImage, uploadedBy); mRecyclerView.setAdapter(notesCustomGridViewAdapter); } }); }
public void performSearch(final String s) { if(s.equals("")) { Toast.makeText(getActivity(),"Please Enter Something",Toast.LENGTH_SHORT).show(); return; } ParseQuery<ParseObject> query = new ParseQuery<>( "Notes"); clear_lists(); query.whereContains("topicName",s); query.orderByDescending("createdAt"); query.setCachePolicy(ParseQuery.CachePolicy.NETWORK_ELSE_CACHE); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> parseObjects, ParseException e) { // Log.d("Search notes","result size : "+String.valueOf( parseObjects.size())+" "+s); for (ParseObject notes : parseObjects) { notesBranchName.add((String) notes.get("branchName")); notesSubjectName.add((String) notes.get("subjectName")); notesCollegeName.add((String) notes.get("collegeName")); notesTopicName.add((String) notes.get("topicName")); uploadedBy.add((String) notes.get("userName")); notesFirstImage.add((ArrayList<ParseFile>) notes.get("notesImages")); } notesCustomGridViewAdapter = new NotesCustomGridViewAdapter(getActivity(), notesCollegeName, notesBranchName, notesTopicName, notesSubjectName, notesFirstImage, uploadedBy); mRecyclerView.setAdapter(notesCustomGridViewAdapter); // notesCustomGridViewAdapter.notifyDataSetChanged(); } }); }
public ParseFile convertBitmapToParseFile( Bitmap bitmap){ // Convert it to byte ByteArrayOutputStream stream = new ByteArrayOutputStream(); // Compress image to lower quality scale 1 - 100 bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] image = stream.toByteArray(); // Create the ParseFile ParseFile file = new ParseFile("userPic.png", image); return file; }
public void setPic(Bitmap pic){ // Convert it to byte ByteArrayOutputStream stream = new ByteArrayOutputStream(); // Compress image to lower quality scale 1 - 100 pic.compress(Bitmap.CompressFormat.PNG, 20, stream); byte[] image = stream.toByteArray(); // Create the ParseFile ParseFile file = new ParseFile("userPic.png", image); if(parseEntry!=null){ parseEntry.put("ProfilePic", file); parseEntry.saveInBackground(); } }
public void setPic(Bitmap pic){ // Convert it to byte ByteArrayOutputStream stream = new ByteArrayOutputStream(); // Compress image to lower quality scale 1 - 100 pic.compress(Bitmap.CompressFormat.PNG, 20, stream); byte[] image = stream.toByteArray(); // Create the ParseFile ParseFile file = new ParseFile("comment_pic.png", image); smallPostPic = ImageOperations.bitmapFromPicFile(file, 50, 50); put("picture", file); }
public static Bitmap bitmapFromPicFile(ParseFile picFile, int reqWidth, int reqHeight){ try { byte[] image = picFile.getData(); return compressImage(image, reqWidth,reqHeight); } catch(ParseException e){ e.printStackTrace(); return null; } }