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);
}
}
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();
}
}
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);
}
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);
}
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());
}
Aggregations