public class NewProductView extends AppCompatActivity implements NewProductContract.View { private int SELECT_PICTURE_RESULT = 1; private NewProductPresenter presenter; private Action action; private Product product; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_product); // Tenemos una enumeración definida para saber si tenemos que Registrar o Modificar un producto // Eso nos permite reutilizar el formulario que usamos para la recogida de datos action = Action.valueOf(getIntent().getStringExtra("ACTION")); if (action == PUT) { product = getIntent().getParcelableExtra("product"); fillProductDetails(); // TODO No está hecho para este ejemplo } presenter = new NewProductPresenter(this); } public void addProduct(View view) { EditText etName = findViewById(R.id.product_name); EditText etCategory = findViewById(R.id.product_category); EditText etQuantity = findViewById(R.id.product_quantity); EditText etPrice = findViewById(R.id.product_price); CheckBox checkImportant = findViewById(R.id.important_product); ImageView productImageView = findViewById(R.id.product_image); String name = etName.getText().toString(); String category = etCategory.getText().toString(); String quantity = etQuantity.getText().toString(); String price = etPrice.getText().toString(); boolean important = checkImportant.isChecked(); byte[] productImage = ImageUtils.fromImageViewToByteArray(productImageView); if (action == POST) presenter.addProduct(name, category, quantity, price, important, productImage); else presenter.modifyProduct(product.getId(), name, category, quantity, price, important, productImage); etName.setText(""); etCategory.setText(""); etQuantity.setText(""); etPrice.setText(""); checkImportant.setChecked(false); etName.requestFocus(); } @Override public void showMessage(String message) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } public void selectPicture(View view) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, SELECT_PICTURE_RESULT); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if ((requestCode == SELECT_PICTURE_RESULT) && (resultCode == RESULT_OK) && (data != null)) { Picasso.get().load(data.getData()) .noPlaceholder() .centerCrop() .fit() .into((ImageView) findViewById(R.id.product_image)); } } . . . . . . }