I am making an app with the following layout:Main App Layout In the app I use a Take Photo button to call the camera intent from my phone to take a picture. The picture gets displayed into the image view(outlined in red in the layout).
I also use the Save Button to save the picture to the gallery via intent. I also use a Signature button to capture the user's signature.Signature has its own layout. The layout consists of the following: Signature LayoutHowever, Lets say I open the app and hit the Save Button when there is no image currently displayed. My Save button currently still works and pulls up the gallery despite there being no picture. The same thing happens with the save button in my signature layout. If there is no signature present currently, the save button still saves.
How would I code it to where I can check if there is currently a picture already shown or a signature already shown, and if not, save buttons in my Signature and Main App Layout are disabled. I know for disabling a button, the syntax is: myButton.setEnabled(false);
I have the following code for the save button in the main app layout:
//this save button is for the gallery app after you take a photo
saveButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//launch the gallery app intent
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Toast.makeText(DriverActivity.this, "Image Saved to Gallery", Toast.LENGTH_SHORT).show();
/*if there is currently no image, disable save button and display a toast message
Toast.makeText(DriverActivity.this, "There's no image currently shown.", Toast.LENGTH_SHORT).show();*/
}
});
// restoring storage image path from saved instance state
// otherwise the path will be null on device rotation
restoreFromBundle(savedInstanceState);
Then I have this code for the signature:
//this is for signature
signatureButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
/*// Use an intent to launch an email app.
// Send the order summary in the email body.
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT,
getString(R.string.order_summary_email_subject));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}*/
Intent intent = new Intent(DriverActivity.this, SignatureActivity.class);
startActivity(intent);
Toast.makeText(DriverActivity.this, "Now Loading Signature Sign", Toast.LENGTH_LONG).show();
}
});
This piece of code is from my SignatureActivity.java file(Note, the two code samples above are from a different Activity.java file(i.e.: DriverActivity.java):
//capture signature
btnSave.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
view.setDrawingCacheEnabled(true);
mSignature.save(view,StoredPath);
Intent intent2 = new Intent(getBaseContext(), DriverActivity.class);
startActivity(intent2);
finish();
Toast.makeText(getApplicationContext(), "Successfully Saved", Toast.LENGTH_SHORT).show();
}
});