use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.
the class EditProfileActivity method onActivityResult.
/**
* When a photo is selected, return to the activity setting the photo
* for the current user
*
* @param requestCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
try {
final Uri imageUri = data.getData();
final InputStream imageStream = this.getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
File file = new File(imageUri.getPath());
// taken from https://stackoverflow.com/questions/2407565/bitmap-byte-size-after-decoding
// 2018-04-03
maxSize = 65536;
Log.i("ACTUAL SIZE", String.valueOf(selectedImage.getByteCount()));
Integer width = 1200;
Integer height = 1200;
Bitmap resizedImage;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
selectedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
while (stream.size() > maxSize) {
width = width - 200;
height = height - 200;
stream = new ByteArrayOutputStream();
resizedImage = Bitmap.createScaledBitmap(selectedImage, width, height, false);
resizedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
}
byte[] byteImage;
byteImage = stream.toByteArray();
String image = Base64.encodeToString(byteImage, Base64.DEFAULT);
user.setPhoto(new Photo(image));
profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
Log.i("test", user.getPhoto().toString());
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "You haven't picked a photo", Toast.LENGTH_LONG).show();
}
}
use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.
the class ProfileActivity method setValues.
/**
* retrieves id from previous activity and get the user from elastic search
* setting up the views on the profile activity
*/
public void setValues() {
userID = getIntent().getStringExtra("user id");
this.profileController = new ProfileController(this.findViewById(android.R.id.content), this);
profileController.setUserID(userID);
profileController.getUserRequest();
user = profileController.getUser();
name = user.getName();
try {
email = user.getEmail().toString();
phone = user.getPhone().toString();
} catch (Exception e) {
email = "No Email";
phone = "No Number";
}
numRequests = profileController.getNumberOfRequests(user.getUsername());
numTasksDone = profileController.getNumberOfTasksDone(user.getUsername());
nameField.setText(name);
emailField.setText(email);
phoneField.setText(phone);
numRequestsField.setText(numRequests);
numTasksDoneField.setText(numTasksDone);
providerRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getProviderRating()));
requesterRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getRequesterRating()));
try {
profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
} catch (Exception e) {
Photo defaultPhoto = new Photo("");
profilePicture.setImageBitmap(defaultPhoto.StringToBitmap());
}
}
use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.
the class ViewTaskActivity method onCreate.
/**
*onCreate
* Retrieve the task using the task id that was sent using
* intent into the activity updating the information on the
* activity_ViewTaskActivity while checking if the task has
* a provider, what the status is and if the user viewing
* is the owner of the task
*
* @param savedInstanceState
* @author Micheal-Nguyen, myapplestory
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_task);
appColors = AppColors.getInstance();
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
findViews();
// starts the activity at the very top
scrollView.setFocusableInTouchMode(true);
scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
// gets the task id
this.viewTaskController = new ViewTaskController(this.findViewById(android.R.id.content), this);
taskID = getIntent().getStringExtra("TaskId");
setValues();
setRequesterField();
setProviderField();
photos = task.getPhotos();
NoLocation = findViewById(R.id.NoLocationText);
NoLocation.setVisibility(View.INVISIBLE);
if (task.getLocation() == null) {
NoLocation.setVisibility(View.VISIBLE);
// mapFragment.s
}
linearLayout = findViewById(R.id.Photos);
recyclerPhotosView = findViewById(R.id.listOfPhotos);
layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerPhotosView.setLayoutManager(layoutManager);
recyclerPhotosViewAdapter = new RecyclerViewAdapter(getApplicationContext(), photos, new CustomOnItemClick() {
@Override
public void onColumnClicked(int position) {
Intent intent = new Intent(getApplicationContext(), ZoomImageActivity.class);
intent.putExtra("Photo", photos.get(position).toString());
startActivity(intent);
}
});
recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
setVisibility();
setUpBidsList();
}
use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.
the class NewTaskController method addTask.
/**
* Error checks the task name and description to enforce character limits.
* Then the task is added to Elastic Search
* @param name Task name
* @param user User that is making the task
* @param description Description of the task
*/
public void addTask(String name, User user, String description, LatLng taskLocation, ArrayList<Photo> photos) {
// Check field lengths and give error
EditText taskName = view.findViewById(R.id.TaskName);
EditText taskDescription = view.findViewById(R.id.Description);
if (TextUtils.getTrimmedLength(taskName.getText()) <= 55 && TextUtils.getTrimmedLength(taskName.getText()) > 0 && TextUtils.getTrimmedLength(taskDescription.getText()) <= 500 && TextUtils.getTrimmedLength(taskDescription.getText()) > 0) {
Task task = new Task(name, user, description, taskLocation, photos);
AddTaskRequest request = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(ctx, request);
request.getResult();
taskId = task.getId();
Intent intent = new Intent();
intent.putExtra("result", taskId);
view.setResult(RESULT_OK, intent);
// Toast.makeText(view, "New task created, refresh page to see updated list", Toast.LENGTH_SHORT).show();
view.finish();
} else {
if (TextUtils.getTrimmedLength(taskName.getText()) > 55) {
taskName.setError("Name can not exceed 55 characters");
}
if (TextUtils.getTrimmedLength(taskName.getText()) == 0) {
taskName.setError("Name can not empty");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) > 500) {
taskDescription.setError("Description can not exceed 500 characters");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) == 0) {
taskDescription.setError("Description can not be empty");
}
}
}
use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.
the class ProfileFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("does this work", String.valueOf(requestCode));
if (requestCode == 1) {
// code to add to ESC
if (resultCode == RESULT_OK) {
String newName = data.getStringExtra("Name");
String newEmail = data.getStringExtra("Email");
String newPhone = data.getStringExtra("Phone");
String newPhoto = data.getStringExtra("Photo");
user.setName(newName);
user.setEmail(new EmailAddress(newEmail));
user.setPhone(new PhoneNumber(newPhone));
user.setPhoto(new Photo(newPhoto));
AddUserRequest request = new AddUserRequest(user);
RequestManager.getInstance().invokeRequest(getContext(), request);
nameField.setText(newName);
emailField.setText(newEmail);
phoneField.setText(newPhone);
profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
}
}
}
Aggregations