@Override protected void toJSON(UserSettings user, JSONObject object) throws JSONException { String encoded = null; try { if (user.getImage() != null) { encoded = bitmapUtils.encode(user.getImage()); } else if (user.getLocalImagePath() != null) { BitmapFactory.Options bfo = new BitmapFactory.Options(); bfo.inDither = true; bfo.inSampleSize = 4; Bitmap bm = BitmapFactory.decodeFile(user.getLocalImagePath(), bfo); encoded = bitmapUtils.encode(bm); bm.recycle(); user.setLocalImagePath(null); } } catch (Throwable e) { // TODO: Handle OOM errors by changing sample size on profile images e.printStackTrace(); } object.put(FIRST_NAME, user.getFirstName()); object.put(LAST_NAME, user.getLastName()); if (encoded != null) { object.put(IMAGE_DATA, encoded); } object.put(AUTO_POST_FACEBOOK, user.isAutoPostFacebook()); object.put(AUTO_POST_TWITTER, user.isAutoPostTwitter()); object.put(SHARE_LOCATION, user.isLocationEnabled()); object.put(NOTIFICATIONS_ENABLED, user.isNotificationsEnabled()); object.put(SHOW_AUTH, user.isShowAuthDialog()); }