i am currently developing an app in adroid studio named Clear Up where this app helps person/people with dyslexia by scanning a text and pronouncing it using text to speech feature but, i have a problem. when i try to run the app in my phone the app opens and the camera is working perfectly fine but the camera preview in portrait is weird and also is stretched and i need to run it in landscape mode just for it to avoid the weird thing but the stretch is still there. also i have a main menu in my drawable but my MainActivity.java is set to only show the main_activity.xml where the camera preview is located. so in my main menu i have 1 group contains 4 buttons and another one group that contains 2 buttons. i wanted the main menu to show after i open the app like do you get my point? below is the files and codes.

main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="20dp"
        android:scaleType="centerCrop"
        android:background="@drawable/image_outline" />

    <Button
        android:id="@+id/image_capture"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_margin="20dp"
        android:background="@drawable/button_background"
        android:gravity="center"
        android:paddingLeft="24dp"
        android:paddingRight="24dp"
        android:text="@string/capture_button"
        android:textAlignment="center"
        android:textColor="@color/purple_200"
        android:textSize="25sp" />
</LinearLayout>


main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item android:id="@+id/home"
            android:icon="@drawable/baseline_home_24"
            android:title="Home"
            tools:ignore="HardcodedText" />
        <item android:id="@+id/camera"
            android:icon="@drawable/baseline_photo_camera_24"
            android:title="Camera"
            tools:ignore="HardcodedText" />
        <item android:id="@+id/gallery"
            android:icon="@drawable/baseline_home_24"
            android:title="Gallery"
            tools:ignore="HardcodedText" />
    </group>
    <item android:title="Profile"
        tools:ignore="HardcodedText">
        <menu>
            <group android:checkableBehavior="single">
                <item android:id="@+id/about"
                    android:icon="@drawable/baseline_back_hand_24"
                    android:title="About"
                    tools:ignore="HardcodedText" />
                <item android:id="@+id/login"
                    android:icon="@drawable/baseline_assignment_ind_24"
                    android:title="Login"
                    tools:ignore="HardcodedText" />
            </group>
        </menu>
    </item>



</menu>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    tools:context="com.androidstudio.clearup.ActivityMain">

    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:headerLayout="@layout/header"
        app:menu="@menu/main_menu"
        android:layout_gravity="start"
        android:id="@+id/nav_view"/>
</androidx.drawerlayout.widget.DrawerLayout>

ActivityMain.java
package com.androidstudio.clearup;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.clearup.android.clearup.R;
import com.google.android.material.navigation.NavigationView;

public class ActivityMain extends AppCompatActivity {
    DrawerLayout drawerLayout;
    NavigationView navigationView;
    ActionBarDrawerToggle drawerToggle;

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if(drawerToggle.onOptionsItemSelected(item))
        {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


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

        drawerLayout = findViewById(R.id.drawer_layout);
        navigationView = findViewById(R.id.nav_view);
        drawerToggle =new ActionBarDrawerToggle(this,drawerLayout,R.string.open,R.string.close);
        drawerLayout.addDrawerListener(drawerToggle);
        drawerToggle.syncState();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                int itemId = menuItem.getItemId();
                if (itemId == R.id.home) {
                    Toast.makeText(ActivityMain.this, "Home Selected", Toast.LENGTH_SHORT).show();
                } else if (itemId == R.id.camera) {
                    Toast.makeText(ActivityMain.this, "Camera Selected", Toast.LENGTH_SHORT).show();
                } else if (itemId == R.id.gallery) {
                    Toast.makeText(ActivityMain.this, "Gallery Selected", Toast.LENGTH_SHORT).show();
                } else if (itemId == R.id.about) {
                    Toast.makeText(ActivityMain.this, "About Selected", Toast.LENGTH_SHORT).show();
                } else if (itemId == R.id.login) {
                    Toast.makeText(ActivityMain.this, "Login Selected", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });
    }

    @Override
    public void onBackPressed() {
        if(drawerLayout.isDrawerOpen(GravityCompat.START))
        {
            drawerLayout.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }
}

CameraActivity.java
package com.androidstudio.clearup;

import android.Manifest;
import static android.app.ProgressDialog.show;
import static android.content.ContentValues.TAG;
import static android.provider.MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.clearup.android.clearup.R;
import org.jetbrains.annotations.Contract;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CameraActivity extends Activity {

    private static final int REQUEST_CAMERA_PERMISSION = 201;
    private Camera mCamera;
    private Camera.PictureCallback mPicture;
    private MainActivity.CameraPreview mPreview;

    private Fragment requestingFragment;
    private Object permissions;


    public CameraActivity() {
        mPicture = (data, camera) -> {

            File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
            if (pictureFile == null){
                Log.d(TAG, "Error creating media file, check storage permissions");
                return;
            }

            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e) {
                Log.d(TAG, "File not found: " + e.getMessage());
            } catch (IOException e) {
                Log.d(TAG, "Error accessing file: " + e.getMessage());
            }
        };
    }

    @Nullable
    @Contract(pure = true)
    private File getOutputMediaFile(int mediaTypeImage) {
        return null;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        // Create an instance of Camera
        mCamera = MainActivity.getCameraInstance();

        // Create our Preview view and set it as the content of our activity.
        mPreview = new MainActivity.CameraPreview(this, mCamera);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.addView(mPreview);

        initializePictureCallback();

        Button captureButton = findViewById(R.id.image_capture);
        if (captureButton != null) {
            captureButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!hasCameraPermission()) {
                        requestCameraPermission();
                    } else {
                        // Camera permission has already been granted. Continue with capturing.
                        captureImage();
                    }
                }
            });
        }
        Fragment fragment = requestingFragment;
        int requestCode = 0;
        Object permissions1 = permissions;
                int[] grantResults = new int[0]; {
            switch (requestCode) {
                case REQUEST_CAMERA_PERMISSION:
                if (requestCode == REQUEST_CAMERA_PERMISSION) {
                    if (grantResults.length > 0 &&
                            grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        // Permission was granted. Proceed with the camera capture.
                        captureImage();
                    } else {
                        // Permission denied. Inform the user with a toast or dialog.
                        Toast.makeText(this, "Camera permission needed for capturing images", Toast.LENGTH_SHORT).show();
                    }
                    return;
                }
            }
        }
    }

    public boolean hasCameraPermission() {
        return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; }

    private void captureImage() {
        if (mCamera != null) {
            mCamera.takePicture(null, null, mPicture);
        } else {
            Log.e(TAG, "Camera is not initialized.");
        }
    }

    private void requestCameraPermission() {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
    }

    // Assume this method is correctly implemented elsewhere in your class
        private static Camera getCameraInstance() {
            // TODO: Implementation
            return null;
        }
    private void initializePictureCallback() {
        mPicture = new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                // Implementation to handle the picture data
            }
        };
    }

}

MainActivity.java
package com.androidstudio.clearup;

import static android.content.ContentValues.TAG;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import java.io.IOException;

public class MainActivity extends Activity {
    @SuppressLint("UnsupportedChromeOsCameraSystemFeature")
    private boolean checkCameraHardware(Context context) {
        // this device has a camera
        // no camera on this device
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
    }
    public static Camera getCameraInstance(){
        Camera c = null;
        try {
            c = Camera.open(); // attempt to get a Camera instance
        }
        catch (Exception e){
            // Camera is not available (in use or does not exist)
        }
        return c; // returns null if camera is unavailable
    }

    public static class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
        private SurfaceHolder mHolder;
        private Camera mCamera;

        public CameraPreview(Context context, Camera camera) {
            super(context);
            mCamera = camera;

            // Install a SurfaceHolder.Callback so we get notified when the
            // underlying surface is created and destroyed.
            mHolder = getHolder();
            mHolder.addCallback(this);
            // deprecated setting, but required on Android versions prior to 3.0
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }

        public void surfaceCreated(SurfaceHolder holder) {
            // The Surface has been created, now tell the camera where to draw the preview.
            try {
                mCamera.setPreviewDisplay(holder);
                mCamera.startPreview();
            } catch (IOException e) {
                Log.d(TAG, "Error setting camera preview: " + e.getMessage());
            }
        }

        public void surfaceDestroyed(SurfaceHolder holder) {
            // empty. Take care of releasing the Camera preview in your activity.
        }

        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
            // If your preview can change or rotate, take care of those events here.
            // Make sure to stop the preview before resizing or reformatting it.

            if (mHolder.getSurface() == null){
                // preview surface does not exist
                return;
            }

            // stop preview before making changes
            try {
                mCamera.stopPreview();
            } catch (Exception e){
                // ignore: tried to stop a non-existent preview
            }

            // set preview size and make any resize, rotate or
            // reformatting changes here

            // start preview with new settings
            try {
                mCamera.setPreviewDisplay(mHolder);
                mCamera.startPreview();

            } catch (Exception e){
                Log.d(TAG, "Error starting camera preview: " + e.getMessage());
            }
        }
    }
}