Search in sources :

Example 41 with Rational

use of android.util.Rational in project vlc-android by videolan.

the class VideoPlayerActivity method switchToPopup.

@TargetApi(Build.VERSION_CODES.N)
public void switchToPopup() {
    final MediaWrapper mw = mService != null ? mService.getCurrentMediaWrapper() : null;
    if (mw == null)
        return;
    if (AndroidDevices.hasPiP) {
        if (AndroidUtil.isOOrLater)
            try {
                final int height = mVideoHeight != 0 ? mVideoHeight : mw.getHeight();
                final int width = Math.min(mVideoWidth != 0 ? mVideoWidth : mw.getWidth(), (int) (height * 2.39f));
                enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(new Rational(width, height)).build());
            } catch (IllegalArgumentException e) {
                // Fallback with default parameters
                // noinspection deprecation
                enterPictureInPictureMode();
            }
        else {
            // noinspection deprecation
            enterPictureInPictureMode();
        }
    } else {
        if (Permissions.canDrawOverlays(this)) {
            mSwitchingView = true;
            mSwitchToPopup = true;
            if (mService != null && !mService.isPlaying())
                mw.addFlags(MediaWrapper.MEDIA_PAUSED);
            cleanUI();
            exitOK();
        } else
            Permissions.checkDrawOverlaysPermission(this);
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Rational(android.util.Rational) TargetApi(android.annotation.TargetApi)

Example 42 with Rational

use of android.util.Rational in project ring-client-android by savoirfairelinux.

the class CallFragment method enterPipMode.

@Override
public void enterPipMode(SipCall sipCall) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        PictureInPictureParams.Builder paramBuilder = new PictureInPictureParams.Builder();
        if (mVideoSurface.getVisibility() == View.VISIBLE) {
            int[] l = new int[2];
            mVideoSurface.getLocationInWindow(l);
            int x = l[0];
            int y = l[1];
            int w = mVideoSurface.getWidth();
            int h = mVideoSurface.getHeight();
            Rect videoBounds = new Rect(x, y, x + w, y + h);
            paramBuilder.setAspectRatio(new Rational(w, h));
            paramBuilder.setSourceRectHint(videoBounds);
        }
        ArrayList<RemoteAction> actions = new ArrayList<>(1);
        actions.add(new RemoteAction(Icon.createWithResource(getContext(), R.drawable.ic_call_end_white), getString(R.string.action_call_hangup), getString(R.string.action_call_hangup), PendingIntent.getService(getContext(), new Random().nextInt(), new Intent(DRingService.ACTION_CALL_END).setClass(getContext(), DRingService.class).putExtra(NotificationService.KEY_CALL_ID, sipCall.getCallId()), PendingIntent.FLAG_ONE_SHOT)));
        paramBuilder.setActions(actions);
        getActivity().enterPictureInPictureMode(paramBuilder.build());
    } else if (DeviceUtils.isTv(getContext())) {
        getActivity().enterPictureInPictureMode();
    }
}
Also used : Rect(android.graphics.Rect) Rational(android.util.Rational) Random(java.util.Random) PictureInPictureParams(android.app.PictureInPictureParams) RemoteAction(android.app.RemoteAction) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 43 with Rational

use of android.util.Rational in project android_packages_apps_Snap by LineageOS.

the class SettingsManager method buildExposureCompensation.

private void buildExposureCompensation(int cameraId) {
    Range<Integer> range = mCharacteristics.get(cameraId).get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
    int max = range.getUpper();
    int min = range.getLower();
    if (min == 0 && max == 0) {
        removePreference(mPreferenceGroup, KEY_EXPOSURE);
        return;
    }
    ListPreference pref = mPreferenceGroup.findPreference(KEY_EXPOSURE);
    Rational rational = mCharacteristics.get(cameraId).get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
    double step = rational.doubleValue();
    int increment = 1;
    while ((max - min) / increment > 10) {
        increment++;
    }
    int start = min;
    if (start < 0) {
        while (Math.abs(start) % increment != 0) {
            start++;
        }
    }
    int size = 0;
    for (int i = start; i <= max; i += increment) size++;
    CharSequence[] entries = new CharSequence[size];
    CharSequence[] entryValues = new CharSequence[size];
    int count = 0;
    for (int i = start; i <= max; i += increment, count++) {
        entryValues[count] = Integer.toString(i);
        StringBuilder builder = new StringBuilder();
        if (i > 0)
            builder.append('+');
        DecimalFormat format = new DecimalFormat("#.##");
        entries[count] = builder.append(format.format(i * step)).toString();
    }
    pref.setEntries(entries);
    pref.setEntryValues(entryValues);
}
Also used : Rational(android.util.Rational) StringBuilder(java.lang.StringBuilder) DecimalFormat(java.text.DecimalFormat)

Example 44 with Rational

use of android.util.Rational in project Conversations by siacs.

the class SurfaceViewRenderer method onFrameResolutionChanged.

public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation) {
    super.onFrameResolutionChanged(videoWidth, videoHeight, rotation);
    final int rotatedWidth = rotation != 0 && rotation != 180 ? videoHeight : videoWidth;
    final int rotatedHeight = rotation != 0 && rotation != 180 ? videoWidth : videoHeight;
    final Rational currentRational = this.aspectRatio;
    this.aspectRatio = new Rational(rotatedWidth, rotatedHeight);
    Log.d(Config.LOGTAG, "onFrameResolutionChanged(" + rotatedWidth + "," + rotatedHeight + "," + aspectRatio + ")");
    if (currentRational.equals(this.aspectRatio) || onAspectRatioChanged == null) {
        return;
    }
    onAspectRatioChanged.onAspectRatioChanged(this.aspectRatio);
}
Also used : Rational(android.util.Rational)

Example 45 with Rational

use of android.util.Rational in project Signal-Android by WhisperSystems.

the class SignalCameraXModule method bindToLifecycleAfterViewMeasured.

@RequiresPermission(permission.CAMERA)
void bindToLifecycleAfterViewMeasured() {
    if (mNewLifecycle == null) {
        return;
    }
    clearCurrentLifecycle();
    if (mNewLifecycle.getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
        // Lifecycle is already in a destroyed state. Since it may have been a valid
        // lifecycle when bound, but became destroyed while waiting for layout, treat this as
        // a no-op now that we have cleared the previous lifecycle.
        mNewLifecycle = null;
        return;
    }
    mCurrentLifecycle = mNewLifecycle;
    mNewLifecycle = null;
    if (mCameraProvider == null) {
        // try again once the camera provider is no longer null
        return;
    }
    Set<Integer> available = getAvailableCameraLensFacing();
    if (available.isEmpty()) {
        Logger.w(TAG, "Unable to bindToLifeCycle since no cameras available");
        mCameraLensFacing = null;
    }
    // Ensure the current camera exists, or default to another camera
    if (mCameraLensFacing != null && !available.contains(mCameraLensFacing)) {
        Logger.w(TAG, "Camera does not exist with direction " + mCameraLensFacing);
        // Default to the first available camera direction
        mCameraLensFacing = available.iterator().next();
        Logger.w(TAG, "Defaulting to primary camera with direction " + mCameraLensFacing);
    }
    // were no available cameras, which should be logged in the logic above.
    if (mCameraLensFacing == null) {
        return;
    }
    // Set the preferred aspect ratio as 4:3 if it is IMAGE only mode. Set the preferred aspect
    // ratio as 16:9 if it is VIDEO or MIXED mode. Then, it will be WYSIWYG when the view finder
    // is in CENTER_INSIDE mode.
    boolean isDisplayPortrait = getDisplayRotationDegrees() == 0 || getDisplayRotationDegrees() == 180;
    // Begin Signal Custom Code Block
    int resolution = CameraXUtil.getIdealResolution(Resources.getSystem().getDisplayMetrics().widthPixels, Resources.getSystem().getDisplayMetrics().heightPixels);
    // End Signal Custom Code Block
    Rational targetAspectRatio;
    // Begin Signal Custom Code Block
    mImageCaptureBuilder.setTargetResolution(CameraXUtil.buildResolutionForRatio(resolution, ASPECT_RATIO_16_9, isDisplayPortrait));
    targetAspectRatio = isDisplayPortrait ? ASPECT_RATIO_9_16 : ASPECT_RATIO_16_9;
    // End Signal Custom Code Block
    // Begin Signal Custom Code Block
    mImageCaptureBuilder.setCaptureMode(CameraXUtil.getOptimalCaptureMode());
    // End Signal Custom Code Block
    mImageCaptureBuilder.setTargetRotation(getDisplaySurfaceRotation());
    mImageCapture = mImageCaptureBuilder.build();
    // Begin Signal Custom Code Block
    Size size = VideoUtil.getVideoRecordingSize();
    mVideoCaptureBuilder.setTargetResolution(size);
    mVideoCaptureBuilder.setMaxResolution(size);
    // End Signal Custom Code Block
    mVideoCaptureBuilder.setTargetRotation(getDisplaySurfaceRotation());
    // Begin Signal Custom Code Block
    if (MediaConstraints.isVideoTranscodeAvailable()) {
        mVideoCapture = mVideoCaptureBuilder.build();
    }
    // End Signal Custom Code Block
    // Adjusts the preview resolution according to the view size and the target aspect ratio.
    int height = (int) (getMeasuredWidth() / targetAspectRatio.floatValue());
    mPreviewBuilder.setTargetResolution(new Size(getMeasuredWidth(), height));
    mPreview = mPreviewBuilder.build();
    mPreview.setSurfaceProvider(mCameraView.getPreviewView().getSurfaceProvider());
    CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(mCameraLensFacing).build();
    if (getCaptureMode() == SignalCameraView.CaptureMode.IMAGE) {
        mCamera = mCameraProvider.bindToLifecycle(mCurrentLifecycle, cameraSelector, mImageCapture, mPreview);
    } else if (getCaptureMode() == SignalCameraView.CaptureMode.VIDEO) {
        mCamera = mCameraProvider.bindToLifecycle(mCurrentLifecycle, cameraSelector, mVideoCapture, mPreview);
    } else {
        mCamera = mCameraProvider.bindToLifecycle(mCurrentLifecycle, cameraSelector, mImageCapture, mVideoCapture, mPreview);
    }
    setZoomRatio(UNITY_ZOOM_SCALE);
    mCurrentLifecycle.getLifecycle().addObserver(mCurrentLifecycleObserver);
    // Enable flash setting in ImageCapture after use cases are created and binded.
    setFlash(getFlash());
}
Also used : Rational(android.util.Rational) CameraSelector(androidx.camera.core.CameraSelector) Size(android.util.Size) SuppressLint(android.annotation.SuppressLint) RequiresPermission(androidx.annotation.RequiresPermission)

Aggregations

Rational (android.util.Rational)96 SmallTest (android.test.suitebuilder.annotation.SmallTest)50 Range (android.util.Range)15 Size (android.util.Size)6 Point (android.graphics.Point)5 Pair (android.util.Pair)5 InvalidObjectException (java.io.InvalidObjectException)5 PictureInPictureParams (android.app.PictureInPictureParams)4 TargetApi (android.annotation.TargetApi)3 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 RemoteAction (android.app.RemoteAction)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 RequiresApi (androidx.annotation.RequiresApi)1 RequiresPermission (androidx.annotation.RequiresPermission)1 CameraSelector (androidx.camera.core.CameraSelector)1 StringBuilder (java.lang.StringBuilder)1 DecimalFormat (java.text.DecimalFormat)1