Search in sources :

Example 6 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class EditProfileActivity method onCreate.

/**
 * this runs when activity created, setting the default fields for the user
 *
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Edit Profile");
    setContentView(R.layout.activity_edit_profile);
    AppColors appColors = AppColors.getInstance();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
    actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
    NameText = findViewById(R.id.NameField);
    EmailText = findViewById(R.id.EmailField);
    PhoneText = findViewById(R.id.Phone);
    profilePicture = findViewById(R.id.ProfilePictureView);
    String userName = getIntent().getStringExtra("Name");
    String userEmail = getIntent().getStringExtra("Email");
    String userPhone = getIntent().getStringExtra("Phone");
    String userPicture = getIntent().getStringExtra("Photo");
    user.setName(userName);
    user.setEmail(new EmailAddress(userEmail));
    user.setPhone(new PhoneNumber(userPhone));
    NameText.setText(user.getName());
    EmailText.setText(user.getEmail().toString());
    PhoneText.setText(user.getPhone().toString());
    try {
        user.setPhoto(new Photo(userPicture));
        profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
    } catch (Exception e) {
        Photo defaultPhoto = new Photo("");
        profilePicture.setImageBitmap(defaultPhoto.StringToBitmap());
    }
    profilePicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            profilePictureClicked();
        }
    });
}
Also used : AppColors(com.cmput301w18t05.taskzilla.AppColors) ColorDrawable(android.graphics.drawable.ColorDrawable) PhoneNumber(com.cmput301w18t05.taskzilla.PhoneNumber) Photo(com.cmput301w18t05.taskzilla.Photo) ImageView(android.widget.ImageView) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) EmailAddress(com.cmput301w18t05.taskzilla.EmailAddress)

Example 7 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class ProfileFragment method setValues.

/**
 * setValues
 * sets the text and values of each field and variable in this class
 *
 * @author Micheal_Nguyen
 */
public void setValues() {
    nameField.setText(user.getName());
    emailField.setText(user.getEmail().toString());
    phoneField.setText(user.getPhone().toString());
    if (user.getProviderRating() == 0.0f) {
        providerRatingField.setText("n/a");
        providerRatingField.setTextSize(18);
    } else {
        providerRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getProviderRating()));
    }
    if (user.getProviderRating() == 0.0f) {
        requesterRatingField.setText("n/a");
        requesterRatingField.setTextSize(18);
    } else {
        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 : Photo(com.cmput301w18t05.taskzilla.Photo) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class NewTaskActivity method onActivityResult.

/**
 * reqcode 2: Get lat lon and set a marker on the map
 * reqcode 5: Set the image
 *
 * @param reqCode
 * @param resultCode
 * @param data
 */
@Override
protected void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    // 2018-04-03
    if (resultCode == RESULT_OK) {
        if (reqCode == 2) {
            DecimalFormat df = new DecimalFormat("#.#####");
            taskLocation = new LatLng(Double.parseDouble(data.getStringExtra("Lat")), Double.parseDouble(data.getStringExtra("Lon")));
            autocompleteFragment.setHint(df.format(Double.parseDouble(data.getStringExtra("Lat"))) + ", " + df.format(Double.parseDouble(data.getStringExtra("Lon"))));
            autocompleteFragment.setText(df.format(Double.parseDouble(data.getStringExtra("Lat"))) + ", " + df.format(Double.parseDouble(data.getStringExtra("Lon"))));
            mMap.clear();
            mMap.addMarker(new MarkerOptions().position(taskLocation).title("Your Location"));
            moveToCurrentLocation(taskLocation);
        } else {
            try {
                final Uri imageUri = data.getData();
                final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                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);
                photos.add(new Photo(image));
                Log.i("hi", String.valueOf(photos.size()));
                recyclerPhotosViewAdapter.notifyDataSetChanged();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                Toast.makeText(NewTaskActivity.this, "Something went wrong", Toast.LENGTH_LONG).show();
            }
        }
    } else {
        Toast.makeText(NewTaskActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show();
    }
}
Also used : Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) InputStream(java.io.InputStream) DecimalFormat(java.text.DecimalFormat) FileNotFoundException(java.io.FileNotFoundException) Photo(com.cmput301w18t05.taskzilla.Photo) LatLng(com.google.android.gms.maps.model.LatLng) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri)

Example 9 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class NewTaskActivity method onCreate.

/**
 * Activity uses the activity_new_task.xml layout
 * New tasks are created through NewTaskController
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTitle("Add a Task");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_task);
    AppColors appColors = AppColors.getInstance();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
    actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    newTaskController = new NewTaskController(this, getApplicationContext());
    currentLocationButton = findViewById(R.id.currentLocationButton);
    Button cancel = findViewById(R.id.CancelButton);
    Button addTask = findViewById(R.id.addTaskButton);
    final EditText taskName = findViewById(R.id.TaskName);
    final EditText taskDescription = findViewById(R.id.Description);
    addPhotoButton = findViewById(R.id.AddPhotoButton);
    autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

        /**
         * When user select a location
         * Set hint and set place
         * @param place
         */
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            autocompleteFragment.setHint(place.getName());
            taskLocation = place.getLatLng();
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            taskLocation = null;
            Log.i("err", "An error occurred: " + status);
        }
    });
    photos = new ArrayList<>();
    recyclerPhotosView = findViewById(R.id.listOfPhotos);
    layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerPhotosView.setLayoutManager(layoutManager);
    recyclerPhotosViewAdapter = new RecyclerViewAdapter(this, photos, new CustomOnItemClick() {

        @Override
        public void onColumnClicked(final int position) {
            // taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
            // 2018-03-16
            AlertDialog.Builder alert = new AlertDialog.Builder(NewTaskActivity.this);
            alert.setTitle("Delete Photo");
            alert.setMessage("Are you sure you want to delete this photo?");
            // DELETE CODE
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    photos.remove(position);
                    dialogInterface.dismiss();
                    recyclerPhotosViewAdapter.notifyDataSetChanged();
                }
            });
            // DELETE CANCEL CODE
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
    autocompleteFragment.setHint("Task Location");
    getLocation();
    autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
    /* cancel button */
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            newTaskController.cancelTask();
        }
    });
    currentLocationButton.setOnClickListener(new View.OnClickListener() {

        /**
         * Set loaction to the users current location
         * @param view
         */
        @Override
        public void onClick(View view) {
            setCurrentLocation();
        }
    });
    /* add task button */
    addTask.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            newTaskController.addTask(taskName.getText().toString(), cUser, taskDescription.getText().toString(), taskLocation, photos);
        }
    });
    addPhotoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AddPhotoButtonClicked();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) NewTaskController(com.cmput301w18t05.taskzilla.controller.NewTaskController) AppColors(com.cmput301w18t05.taskzilla.AppColors) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar) EditText(android.widget.EditText) Status(com.google.android.gms.common.api.Status) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ColorDrawable(android.graphics.drawable.ColorDrawable) Place(com.google.android.gms.location.places.Place)

Example 10 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class EditProfileActivity method ProfileSaveButton.

public void ProfileSaveButton(View view) {
    if (validateInformation()) {
        user.setName(NameText.getText().toString());
        user.setEmail(new EmailAddress(EmailText.getText().toString()));
        user.setPhone(new PhoneNumber(PhoneText.getText().toString()));
        Intent returnIntent = new Intent();
        returnIntent.putExtra("Name", user.getName());
        returnIntent.putExtra("Email", user.getEmail().toString());
        returnIntent.putExtra("Phone", user.getPhone().toString());
        returnIntent.putExtra("Photo", user.getPhoto().toString());
        setResult(RESULT_OK, returnIntent);
        finish();
    }
}
Also used : PhoneNumber(com.cmput301w18t05.taskzilla.PhoneNumber) Intent(android.content.Intent) EmailAddress(com.cmput301w18t05.taskzilla.EmailAddress)

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