Search in sources :

Example 11 with Photo

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) Photo(com.cmput301w18t05.taskzilla.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) File(java.io.File)

Example 12 with Photo

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());
    }
}
Also used : ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) Photo(com.cmput301w18t05.taskzilla.Photo)

Example 13 with Photo

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();
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ColorDrawable(android.graphics.drawable.ColorDrawable) Intent(android.content.Intent) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) ActionBar(android.support.v7.app.ActionBar) ViewTaskController(com.cmput301w18t05.taskzilla.controller.ViewTaskController)

Example 14 with Photo

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");
        }
    }
}
Also used : EditText(android.widget.EditText) Task(com.cmput301w18t05.taskzilla.Task) Intent(android.content.Intent) AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)

Example 15 with Photo

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());
        }
    }
}
Also used : PhoneNumber(com.cmput301w18t05.taskzilla.PhoneNumber) Photo(com.cmput301w18t05.taskzilla.Photo) EmailAddress(com.cmput301w18t05.taskzilla.EmailAddress) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Aggregations

Photo (com.cmput301w18t05.taskzilla.Photo)12 ColorDrawable (android.graphics.drawable.ColorDrawable)5 ActionBar (android.support.v7.app.ActionBar)5 Intent (android.content.Intent)4 AppColors (com.cmput301w18t05.taskzilla.AppColors)4 LatLng (com.google.android.gms.maps.model.LatLng)4 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 View (android.view.View)3 EditText (android.widget.EditText)3 CustomOnItemClick (com.cmput301w18t05.taskzilla.CustomOnItemClick)3 EmailAddress (com.cmput301w18t05.taskzilla.EmailAddress)3 PhoneNumber (com.cmput301w18t05.taskzilla.PhoneNumber)3 RecyclerViewAdapter (com.cmput301w18t05.taskzilla.RecyclerViewAdapter)3 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 DialogInterface (android.content.DialogInterface)2