Example usage for android.view Surface ROTATION_90

List of usage examples for android.view Surface ROTATION_90

Introduction

In this page you can find the example usage for android.view Surface ROTATION_90.

Prototype

int ROTATION_90

To view the source code for android.view Surface ROTATION_90.

Click Source Link

Document

Rotation constant: 90 degree rotation.

Usage

From source file:uk.ac.horizon.artcodes.camera.CameraView.java

private int getDeviceRotation() {
    WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        return 0;
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    }/*from   ww w .  j  a  va 2s  . c  om*/
    return 0;
}

From source file:co.taqat.call.LinphoneActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //This must be done before calling super.onCreate().
    super.onCreate(savedInstanceState);

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }/*from w  w  w  .  j  a v a  2  s.  c o  m*/

    boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_assistant_at_first_start);
    if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
        Intent wizard = new Intent();
        wizard.setClass(this, RemoteProvisioningLoginActivity.class);
        wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
        startActivity(wizard);
        finish();
        return;
    } else if (savedInstanceState == null
            && (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch())) {
        if (LinphonePreferences.instance().getAccountCount() > 0) {
            LinphonePreferences.instance().firstLaunchSuccessful();
        } else {
            startActivity(new Intent().setClass(this, AssistantActivity.class));
            finish();
            return;
        }
    }

    if (getIntent() != null && getIntent().getExtras() != null) {
        newProxyConfig = getIntent().getExtras().getBoolean("isNewProxyConfig");
    }

    if (getResources().getBoolean(R.bool.use_linphone_tag)) {
        if (getPackageManager().checkPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                getPackageName()) != PackageManager.PERMISSION_GRANTED) {
            checkSyncPermission();
        } else {
            ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
        }
    } else {
        ContactsManager.getInstance().initializeContactManager(getApplicationContext(), getContentResolver());
    }

    setContentView(R.layout.main);
    instance = this;
    fragmentsHistory = new ArrayList<FragmentsAvailable>();
    pendingFragmentTransaction = FragmentsAvailable.UNKNOW;

    initButtons();
    initSideMenu();

    currentFragment = FragmentsAvailable.EMPTY;
    if (savedInstanceState == null) {
        changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras());
    } else {
        currentFragment = (FragmentsAvailable) savedInstanceState.getSerializable("currentFragment");
    }

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            displayMissedChats(getUnreadMessageCount());
        }

        @Override
        public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy,
                LinphoneCore.RegistrationState state, String smessage) {
            if (state.equals(RegistrationState.RegistrationCleared)) {
                if (lc != null) {
                    LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(),
                            proxy.getDomain());
                    if (authInfo != null)
                        lc.removeAuthInfo(authInfo);
                }
            }

            refreshAccounts();

            if (getResources().getBoolean(R.bool.use_phone_number_validation)) {
                if (state.equals(RegistrationState.RegistrationOk)) {
                    LinphoneManager.getInstance().isAccountWithAlias();
                }
            }

            if (state.equals(RegistrationState.RegistrationFailed) && newProxyConfig) {
                newProxyConfig = false;
                if (proxy.getError() == Reason.BadCredentials) {
                    //displayCustomToast(getString(R.string.error_bad_credentials), Toast.LENGTH_LONG);
                }
                if (proxy.getError() == Reason.Unauthorized) {
                    displayCustomToast(getString(R.string.error_unauthorized), Toast.LENGTH_LONG);
                }
                if (proxy.getError() == Reason.IOError) {
                    displayCustomToast(getString(R.string.error_io_error), Toast.LENGTH_LONG);
                }
            }
        }

        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
            if (state == State.IncomingReceived) {
                startActivity(new Intent(LinphoneActivity.instance(), CallIncomingActivity.class));
            } else if (state == State.OutgoingInit || state == State.OutgoingProgress) {
                startActivity(new Intent(LinphoneActivity.instance(), CallOutgoingActivity.class));
            } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) {
                resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }

            int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
            displayMissedCalls(missedCalls);
        }
    };

    int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
    displayMissedCalls(missedCalls);

    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        rotation = 0;
        break;
    case Surface.ROTATION_90:
        rotation = 90;
        break;
    case Surface.ROTATION_180:
        rotation = 180;
        break;
    case Surface.ROTATION_270:
        rotation = 270;
        break;
    }

    LinphoneManager.getLc().setDeviceRotation(rotation);
    mAlwaysChangingPhoneAngle = rotation;
}

From source file:kr.wdream.storyshop.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;/* www .  ja v  a  2s .  c o  m*/
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.nextgis.maplibui.fragment.CompassFragment.java

public int getDeviceRotation() {
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    final int rotation = display.getRotation();

    if (rotation == Surface.ROTATION_90) {
        return 90;
    } else if (rotation == Surface.ROTATION_180) {
        return 180;
    } else if (rotation == Surface.ROTATION_270) {
        return 270;
    }/*w w  w. j a  va  2  s  .c  om*/

    return 0;
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;/* w w w . j  a  v a 2 s .c om*/
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}

From source file:com.example.android.mediarecorder.MainActivity.java

public void setCameraDisplayOrientation(int cameraId) {
    Log.i("TESTING", "Set Camera Display Orientation Called");
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = getWindowManager().getDefaultDisplay().getRotation();

    Log.i("TESTING", "Screen Rotation: " + rotation);
    Log.i("TESTING", "Sensor Orientation: " + sensorOrientation);
    if (sensorOrientation == SENSOR_ORIENTATION_DEFAULT_DEGREES) {
        Log.i("TESTING", "Camera: DEFAULT ROTATION: " + DEFAULT_ORIENTATIONS.get(rotation));

        int degrees = 0;
        switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;//from  ww w. j  av  a  2  s .  c o m
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        }

        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            orientation = (info.orientation + degrees) % 360;
            orientation = (360 - orientation) % 360; // compensate the mirror
            Log.i("TESTING", "Front Facing Camera Orientation: " + orientation);
        } else { // back-facing
            orientation = (info.orientation - degrees + 360) % 360;
            Log.i("TESTING", "Back Facing Camera Orientation: " + orientation);
        }
        Log.i("TESTING", "Set Camera Display Orientation Finished");
    } else {
        Log.i("TESTING", "Camera: INVERSING ROTATION: " + INVERSE_ORIENTATIONS.get(rotation));
        orientation = INVERSE_ORIENTATIONS.get(rotation);
    }
    mCamera.setDisplayOrientation(orientation);
}

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

/**
 * Sets up member variables related to camera.
 *
 * @param width The width of available size for camera preview
 * @param height The height of available size for camera preview
 */// w w w.  jav a  2s.  com
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());
            imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                    /*maxImages*/ 2);

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            // noinspection ConstantConditions
            /* Orientation of the camera sensor */
            int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (sensorOrientation == 90 || sensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (sensorOrientation == 0 || sensorOrientation == 180) {
                    swappedDimensions = true;
                }
                break;
            default:
                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
            }

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int rotatedPreviewWidth = width;
            int rotatedPreviewHeight = height;
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                rotatedPreviewWidth = height;
                rotatedPreviewHeight = width;
                maxPreviewWidth = displaySize.y;
                maxPreviewHeight = displaySize.x;
            }

            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                maxPreviewWidth = MAX_PREVIEW_WIDTH;
            }

            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
            }

            previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                    rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
            } else {
                textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
            }

            this.cameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to access Camera", e);
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(),
                FRAGMENT_DIALOG);
    }
}

From source file:fr.xebia.magritte.classifier.lite.Camera2BasicFragment.java

/**
 * Sets up member variables related to camera.
 *
 * @param width The width of available size for camera preview
 * @param height The height of available size for camera preview
 */// w ww. j  av a2  s .c o  m
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());
            imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                    /*maxImages*/ 2);

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            // noinspection ConstantConditions
            /* Orientation of the camera sensor */
            int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (sensorOrientation == 90 || sensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (sensorOrientation == 0 || sensorOrientation == 180) {
                    swappedDimensions = true;
                }
                break;
            default:
                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
            }

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int rotatedPreviewWidth = width;
            int rotatedPreviewHeight = height;
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                rotatedPreviewWidth = height;
                rotatedPreviewHeight = width;
                maxPreviewWidth = displaySize.y;
                maxPreviewHeight = displaySize.x;
            }

            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                maxPreviewWidth = MAX_PREVIEW_WIDTH;
            }

            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
            }

            previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                    rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
            } else {
                textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
            }

            this.cameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(),
                FRAGMENT_DIALOG);
    }
}

From source file:com.manufacton.cordova.MyCameraManager.java

/**
 * Sets up member variables related to camera.
 *
 * @param width  The width of available size for camera preview
 * @param height The height of available size for camera preview
 *//* w w w .j  av a 2s  .com*/
private void setUpCameraOutputs(int width, int height) {
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            //noinspection ConstantConditions
            mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (mSensorOrientation == 90 || mSensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (mSensorOrientation == 0 || mSensorOrientation == 180) {
                    swappedDimensions = true;
                }
                break;
            default:
                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
            }

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int rotatedPreviewWidth = width;
            int rotatedPreviewHeight = height;
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                rotatedPreviewWidth = height;
                rotatedPreviewHeight = width;
                maxPreviewWidth = displaySize.y;
                maxPreviewHeight = displaySize.x;
            }

            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                maxPreviewWidth = MAX_PREVIEW_WIDTH;
            }

            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
            }

            // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
            // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
            // garbage capture data.
            int cameraLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
            if (cameraLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY
                    && android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.LOLLIPOP) {
                Log.d(TAG, "LEGACY CAMERA DETECTED & OLD OS DETECTED");
                Size[] sizes = map.getOutputSizes(SurfaceTexture.class);
                for (Size option : sizes) {
                    Log.d(TAG, "available : WIDTH: " + option.getWidth() + " HEIGHT: " + option.getHeight());
                }
                mImageReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 2);
            } else {
                Log.d(TAG, "LEGACY CAMERA NOT DETECTED");
                mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                        rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);
                mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(),
                        ImageFormat.JPEG, 2);
                Log.d(TAG, "For mPreviewSize: WIDTH: " + mPreviewSize.getWidth() + " HEIGHT: "
                        + mPreviewSize.getHeight());
            }

            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            // int orientation = getResources().getConfiguration().orientation;
            // if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            //     mTextureView.setAspectRatio(
            //             mPreviewSize.getWidth(), mPreviewSize.getHeight());
            // } else {
            //     mTextureView.setAspectRatio(
            //             mPreviewSize.getHeight(), mPreviewSize.getWidth());
            // }

            // Check if the flash is supported.
            Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            mFlashSupported = available == null ? false : available;

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:org.linphone.LinphoneActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    instance = this;
    //        if (isTablet() && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
    //            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    //        } else if (!isTablet() && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
    //            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    //        }/* w w w . j  av a  2s .c o  m*/

    mInterstitialAd = new InterstitialAd(LinphoneActivity.this);
    mInterstitialAd.setAdUnitId("ca-app-pub-4414887992172337/6695240808");

    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
        }
    });
    requestNewInterstitial();

    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }

    if (!LinphoneManager.isInstanciated()) {
        Log.e("No service running: avoid crash by starting the launcher", this.getClass().getName());
        // super.onCreate called earlier
        finish();
        startActivity(getIntent().setClass(this, LinphoneLauncherActivity.class));
        return;
    }

    mPreferences = PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.this);

    //        boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
    //        if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
    //            Intent wizard = new Intent();
    //            wizard.setClass(this, RemoteProvisioningLoginActivity.class);
    //            wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
    //            startActivityForResult(wizard, REMOTE_PROVISIONING_LOGIN_ACTIVITY);
    //        }
    //        if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {

    //        if (mPreferences.getBoolean(Config.PREF_IS_LOGIN_SUCCESS, false)) { //  && LinphonePreferences.instance().getAccountCount() < 1
    //            LinphonePreferences.instance().firstLaunchSuccessful();
    //        } else {
    //            if (LinphonePreferences.instance().getAccountCount() > 0) {
    //                LinphonePreferences.instance().deleteAccount(LinphonePreferences.instance().getDefaultAccountIndex());
    //            }
    //            startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
    //        }
    //        }

    boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
    if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
        Intent wizard = new Intent();
        //wizard.setClass(this, RemoteProvisioningLoginActivity.class);
        wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
        startActivityForResult(wizard, REMOTE_PROVISIONING_LOGIN_ACTIVITY);
    } else if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
        if (LinphonePreferences.instance().getAccountCount() > 0) {
            LinphonePreferences.instance().firstLaunchSuccessful();
        } else {
            startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
        }
    }

    //TODO rework
    if (getResources().getBoolean(R.bool.use_linphone_tag)) {
        ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
    } else {
        ContactsManager.getInstance().initializeContactManager(getApplicationContext(), getContentResolver());
    }

    //        if (!LinphonePreferences.instance().isContactsMigrationDone()) {
    //            ContactsManager.getInstance().migrateContacts();
    //            LinphonePreferences.instance().contactsMigrationDone();
    //        }

    setContentView(R.layout.main);
    fragmentsHistory = new ArrayList<FragmentsAvailable>();
    initButtons();

    // following line added by aniruddh
    //mCall = (CallButton) findViewById(R.id.Call);

    currentFragment = nextFragment = FragmentsAvailable.DIALER;
    fragmentsHistory.add(currentFragment);
    if (savedInstanceState == null) {
        if (findViewById(R.id.fragmentContainer) != null) {
            dialerFragment = new DialerFragment();
            dialerFragment.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragmentContainer, dialerFragment, currentFragment.toString()).commit();
            selectMenu(FragmentsAvailable.DIALER);
        }
    }

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            if (!displayChatMessageNotification(message.getFrom().asStringUriOnly())) {
                cr.markAsRead();
            }
            displayMissedChats(getChatStorage().getUnreadMessageCount());
            if (messageListFragment != null && messageListFragment.isVisible()) {
                ((ChatListFragment) messageListFragment).refresh();
            }
        }

        @Override
        public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy,
                LinphoneCore.RegistrationState state, String smessage) {
            if (state.equals(RegistrationState.RegistrationCleared)) {
                if (lc != null) {
                    LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(),
                            proxy.getDomain());
                    if (authInfo != null)
                        lc.removeAuthInfo(authInfo);
                }
            }
        }

        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
            if (state == State.IncomingReceived) {
                startActivity(new Intent(LinphoneActivity.instance(), IncomingCallActivity.class));
            } else if (state == State.OutgoingInit) {
                if (call.getCurrentParamsCopy().getVideoEnabled()) {
                    startVideoActivity(call);
                } else {
                    startIncallActivity(call);
                }
            } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) {
                // Convert LinphoneCore message for internalization
                if (message != null && message.equals("Call declined.")) {
                    displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_LONG);
                } else if (message != null && message.equals("Not Found")) {
                    displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_LONG);
                } else if (message != null && message.equals("Unsupported media type")) {
                    displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_LONG);
                } else if (message != null && state == State.Error) {
                    //displayCustomToast(getString(R.string.error_unknown), Toast.LENGTH_LONG);
                    Log.e("", "eroor message: " + message);
                    if (message.contains("Temporarily Unavailable")) {
                        displayCustomToast(getString(R.string.user_not_available), Toast.LENGTH_LONG);
                    } else {
                        displayCustomToast(getString(R.string.dial_valid_number), Toast.LENGTH_LONG);
                    }
                }
                resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }

            int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
            displayMissedCalls(missedCalls);
        }
    };

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
        lc.addListener(mListener);
    }

    int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
    displayMissedCalls(missedCalls);

    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        rotation = 0;
        break;
    case Surface.ROTATION_90:
        rotation = 90;
        break;
    case Surface.ROTATION_180:
        rotation = 180;
        break;
    case Surface.ROTATION_270:
        rotation = 270;
        break;
    }

    LinphoneManager.getLc().setDeviceRotation(rotation);
    mAlwaysChangingPhoneAngle = rotation;

    updateAnimationsState();

    mLinphonePreferences = LinphonePreferences.instance();
    defaultAccountIndex = LinphonePreferences.instance().getDefaultAccountIndex();

}