LaVOZs

The World’s Largest Online Community for Developers

'; java - How to make a floating button disappear android? - LavOzs.Com

I have a simple floating button that open the camera and then display the image in the Main Activity.

I want to remove that floating button right after the user retrieve the image result so It should be onActivityResult right after scannedImageView.setImageBitmap(bitmap)

I tried using btnFloat.setVisibility(View.GONE); but since it's a floating button I do not know how to call it on my method.

MainActivity

ImageView scannedImageView;

public void init() {
FloatingActionButton fab = findViewById(R.id.fab_capture);
}

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == Activity.RESULT_OK && data != null) {
         if (requestCode == OPEN_THING) {
             Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
             Bitmap bitmap = null;
             try {
                 bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                 getContentResolver().delete(uri, null, null);
                 scannedImageView.setImageBitmap(bitmap);
               //btnFloat.setVisibility(View.GONE);
                 FileOutputStream outputStream = null;
                 File sdCard = new File(getExternalFilesDir(null).getAbsolutePath());
                 File directory = new File (sdCard.getAbsolutePath() +"/Scan Documents");
                 directory.mkdir();

                 String filename = String.format("d.jpg", System.currentTimeMillis());
                 File outFile = new File(directory, filename);

                 Toast.makeText(this, "Image Saved Successfully", Toast.LENGTH_SHORT).show();

                 Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                 intent.setData(Uri.fromFile(outFile));
                 sendBroadcast(intent);

                 try{
                     outputStream = new FileOutputStream(outFile);
                     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
                     outputStream.flush();
                     outputStream.close();

                 }catch (FileNotFoundException e)
                 {
                     e.printStackTrace();
                 }
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }
     }
 }

make FloatingActionButton a Global member variable then you can access it in onActivityResult

public class MyActivity extends Activity {
 ...
FloatingActionButton fab;

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fab = findViewById(R.id.fab_capture);
}



 protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
  ...
    fab.hide();
   ...
 }
}
Related
Is there a way to run Python on Android?
How do I read / convert an InputStream into a String in Java?
How to lazy load images in ListView in Android
Intent problem, return value (Android)
Close/hide android soft keyboard
How to stop EditText from gaining focus at Activity startup in Android
Is there a unique Android device ID?
What is 'Context' on Android?
How to fix 'android.os.NetworkOnMainThreadException'?
Proper use cases for Android UserManager.isUserAGoat()?