use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class MakePhotoActivity method onActivityResult.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Default.CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
String pictureName = "camera" + random.nextInt() + ".jpg";
Bitmap bitmap = (Bitmap) data.getExtras().get(Default.DATA_TAG);
Bitmap bitmapFile = bitmap;
mImage.setImageBitmap(bitmap);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmapFile.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + pictureName);
final String filePath = file.getPath();
try {
file.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(bytes.toByteArray());
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
progressDialog = ProgressDialog.show(MakePhotoActivity.this, "", "Loading", true);
Backendless.Files.Android.upload(bitmap, Bitmap.CompressFormat.JPEG, 100, pictureName, Default.DEFAULT_PATH_ROOT, new AsyncCallback<BackendlessFile>() {
@Override
public void handleResponse(BackendlessFile response) {
String photoCameraUrl = response.getFileURL();
Intent intent = new Intent();
intent.putExtra(Default.PHOTO_CAMERA_URL, photoCameraUrl);
intent.putExtra(Default.FILE_PATH, filePath);
setResult(Default.ADD_NEW_PHOTO_RESULT, intent);
progressDialog.cancel();
finish();
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(MakePhotoActivity.this, fault.toString(), Toast.LENGTH_SHORT).show();
}
});
} else {
mImage = (ImageView) findViewById(R.id.camera_image);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, Default.CAMERA_PIC_REQUEST);
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class PointCommentsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_point_comments);
photoBtn = (Button) findViewById(R.id.photoBtn);
photoBtn.setVisibility(View.INVISIBLE);
final TextView textViewComment = (TextView) findViewById(R.id.textViewComment);
TextView textPointComments = (TextView) findViewById(R.id.textPointComments);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textPointComments.setTypeface(typeface);
textViewComment.setTypeface(typeface);
textViewComment.setVisibility(View.INVISIBLE);
final EditText editComment = (EditText) findViewById(R.id.editComment);
editComment.setVisibility(View.INVISIBLE);
photoBtn.setTypeface(typeface);
Intent intent = getIntent();
geoPointId = intent.getStringExtra(Default.GEO_POINT_ID);
userName = (String) Backendless.UserService.CurrentUser().getProperty("name");
if (userName == null)
userName = Backendless.UserService.CurrentUser().getEmail();
Bitmap bitmap = intent.getParcelableExtra(Default.SEND_BITMAP);
imageView = (ImageView) findViewById(R.id.photoView);
imageView.setImageBitmap(bitmap);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final Button commentsBtn = (Button) findViewById(R.id.commentsBtn);
commentsBtn.setTypeface(typeface);
commentsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageView.setVisibility(View.INVISIBLE);
commentsBtn.setEnabled(false);
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.addProperty("name");
backendlessDataQuery.addProperty("message");
backendlessDataQuery.setWhereClause("geoPointId=" + "'" + geoPointId + "'");
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Backendless.Persistence.of(Comment.class).find(backendlessDataQuery, new AsyncCallback<Collection<Comment>>() {
@Override
public void handleResponse(Collection<Comment> response) {
Collection<Comment> comments = response;
for (int i = 0; i < comments.getCurrentPage().size(); i++) {
Comment comment = comments.getCurrentPage().get(i);
String userName = comment.getName();
commentsPoint.add(userName + " : " + comment.getMessage());
}
lvMain = (ListView) findViewById(R.id.commentList);
lvMain.setVisibility(View.VISIBLE);
adapter = new ArrayAdapter<String>(PointCommentsActivity.this, android.R.layout.simple_list_item_1, commentsPoint);
lvMain.setAdapter(adapter);
progressDialog.cancel();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(PointCommentsActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
});
}
});
addCommentBtn = (Button) findViewById(R.id.addCommentBtn);
addCommentBtn.setTypeface(typeface);
addCommentBtn.setVisibility(View.INVISIBLE);
addCommentBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentName = editComment.getText().toString();
if (TextUtils.isEmpty(commentName)) {
String alertMessage = "Please, fill in empty field!";
Toast.makeText(PointCommentsActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
}
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Comment commentPoint = new Comment(userName, commentName, geoPointId);
Backendless.Persistence.save(commentPoint, new BackendlessCallback<Comment>() {
@Override
public void handleResponse(Comment commentPoint) {
Intent categoryIntent = getIntent();
String name = categoryIntent.getStringExtra(Default.SEARCH_CATEGORY_NAME);
Intent intent = new Intent();
intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
setResult(Default.ADD_NEW_COMMENT, intent);
progressDialog.cancel();
finish();
Toast.makeText(PointCommentsActivity.this, "A new comment was successfully added", Toast.LENGTH_LONG).show();
}
});
}
});
photoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.clear();
lvMain.setAdapter(adapter);
lvMain.setVisibility(View.INVISIBLE);
textViewComment.setVisibility(View.INVISIBLE);
editComment.setVisibility(View.INVISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
photoBtn.setVisibility(View.INVISIBLE);
commentsBtn.setVisibility(View.VISIBLE);
commentsBtn.setEnabled(true);
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class RegistrationActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_registration);
TextView textEmail = (TextView) findViewById(R.id.textEmail);
TextView textPass = (TextView) findViewById(R.id.textPass);
TextView textName = (TextView) findViewById(R.id.textName);
TextView textRegistration = (TextView) findViewById(R.id.textRegistration);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textEmail.setTypeface(typeface);
textPass.setTypeface(typeface);
textName.setTypeface(typeface);
textRegistration.setTypeface(typeface);
Button registrationBtn = (Button) findViewById(R.id.registrationBtn);
registrationBtn.setTypeface(typeface);
registrationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText editEmailText = (EditText) findViewById(R.id.emailEdit);
EditText editPasswordText = (EditText) findViewById(R.id.passwordEdit);
EditText editNameText = (EditText) findViewById(R.id.editUserName);
final String messageMail = editEmailText.getText().toString();
final String messagePassword = editPasswordText.getText().toString();
final String messageName = editNameText.getText().toString();
if (TextUtils.isEmpty(messageMail) || TextUtils.isEmpty(messagePassword) || TextUtils.isEmpty(messageName)) {
String alertMessage = "Please, fill in all fields!";
Toast.makeText(RegistrationActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
}
progressDialog = ProgressDialog.show(RegistrationActivity.this, "", "Loading", true);
BackendlessUser userObj = new BackendlessUser();
userObj.setProperty("name", messageName);
userObj.setEmail(messageMail);
userObj.setPassword(messagePassword);
Backendless.UserService.register(userObj, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser backendlessUser) {
final Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
intent.putExtra(Default.EXTRA_EMAIL, messageMail);
startActivity(intent);
progressDialog.cancel();
finish();
Toast.makeText(RegistrationActivity.this, "Registration was successful", Toast.LENGTH_LONG).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(RegistrationActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
Button cancelBtn = (Button) findViewById(R.id.cancelBtn);
cancelBtn.setTypeface(typeface);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class BrowseActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse);
padding = (int) getResources().getDimension(R.dimen.micro_padding);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int screenWidth = displayMetrics.widthPixels;
itemWidth = (screenWidth - (2 * (int) getResources().getDimension(R.dimen.default_margin))) / 3;
GridView gridView = (GridView) findViewById(R.id.gridView);
imageAdapter = new ImageAdapter(this);
gridView.setAdapter(imageAdapter);
Toast.makeText(BrowseActivity.this, "Downloading images...", Toast.LENGTH_SHORT).show();
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.setQueryOptions(new QueryOptions(100, 0, "uploaded"));
Backendless.Persistence.of(ImageEntity.class).find(backendlessDataQuery, new AsyncCallback<Collection<ImageEntity>>() {
@Override
public void handleResponse(final Collection<ImageEntity> response) {
Toast.makeText(BrowseActivity.this, "Will add " + response.getCurrentPage().size() + " images", Toast.LENGTH_SHORT).show();
new Thread() {
@Override
public void run() {
List<ImageEntity> imageEntities = response.getCurrentPage();
for (ImageEntity imageEntity : imageEntities) {
Message message = new Message();
try {
URL url = new URL(imageEntity.getUrl());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
message.obj = BitmapFactory.decodeStream(input);
} catch (Exception e) {
message.obj = e;
}
imagesHandler.sendMessage(message);
}
}
}.start();
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(BrowseActivity.this, "Make some upload first", Toast.LENGTH_SHORT).show();
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Files method upload.
public void upload(final File file, final String path, boolean overwrite, final UploadCallback uploadCallback, final AsyncCallback<BackendlessFile> responder) {
try {
checkFileAndPath(file, path);
new UploadFileAsyncTask().executeThis(file, path, overwrite, uploadCallback, responder);
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
Aggregations