-1

Currently, I do the camera function where when I click the camera button, it will take the photo and display it at ImageView. Now, I want to make the ImageView is clickable, which means, when clicked, it will open the image with full screen. Can anyone know how to do it?

Below is my current code

Java

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_update);

        setTitle("Task Details");

        if (!SharedPrefManager.getInstance(this).isLoggedIn()) {
            finish();
            startActivity(new Intent(this, MainActivity.class));
        }

        TaskClass task = (TaskClass) getIntent().getExtras().getSerializable("task");

        tvTaskName = findViewById(R.id.tvTaskName);
        btnCamera = findViewById(R.id.btnCamera);
        imgAttach = findViewById(R.id.imgAttach);

        tvTaskName.setText(task.getTask_name());
        EnableRuntimePermission();

        btnCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                startActivityForResult(intent, 7);

            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 7 && resultCode == RESULT_OK) {

            Bitmap bitmap = (Bitmap) data.getExtras().get("data");

            imgAttach.setImageBitmap(bitmap);
        }
    }

    public void EnableRuntimePermission(){

        if (ActivityCompat.shouldShowRequestPermissionRationale(TaskUpdate.this,
                Manifest.permission.CAMERA))
        {

            Toast.makeText(TaskUpdate.this,"CAMERA permission allows us to Access CAMERA app", Toast.LENGTH_LONG).show();

        } else {

            ActivityCompat.requestPermissions(TaskUpdate.this,new String[]{
                    Manifest.permission.CAMERA}, RequestPermissionCode);
        }
    }

    @Override
    public void onRequestPermissionsResult(int RC, String per[], int[] PResult) {

        switch (RC) {

            case RequestPermissionCode:

                if (PResult.length > 0 && PResult[0] == PackageManager.PERMISSION_GRANTED) {

                    Toast.makeText(TaskUpdate.this,"Permission Granted, Now your application can access CAMERA.", Toast.LENGTH_LONG).show();

                } else {

                    Toast.makeText(TaskUpdate.this,"Permission Canceled, Now your application cannot access CAMERA.", Toast.LENGTH_LONG).show();

                }
                break;
        }
    }

XML

<ImageView
    android:id="@+id/imgAttach"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:paddingTop="05dp"
    android:paddingBottom="05dp"
    android:background="@drawable/imgborder"/>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hawau
  • 99
  • 9

1 Answers1

0

Create another activity like ViewImage.java with only one ImageView in it's layout file, then open that activity when user clicks on the image, and pass the bitmap. Set a custom style to that ViewImage activity, in your case that should be NoActionBar. Receive the bitmap in ViewImage activity and set it to that imageView which you created in the layout file.

Sk Suraj
  • 500
  • 2
  • 15