Skip to content

Commit

Permalink
add ability to switch camera rotation 0,90,180,270 #138
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerInk committed Dec 13, 2020
1 parent 7929d58 commit 05f95e9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import freed.settings.SettingKeys;
import freed.settings.SettingsManager;
import freed.utils.Log;
import freed.utils.OrientationUtil;
import freed.utils.PermissionManager;

/**
Expand Down Expand Up @@ -147,8 +148,8 @@ private void prepareRecorder()

recorder.setInfoListener(this);

if (SettingsManager.get(SettingKeys.orientationHack).get())
recorder.setOrientation(180);
if (!SettingsManager.get(SettingKeys.orientationHack).get().equals("0"))
recorder.setOrientation(Integer.parseInt(SettingsManager.get(SettingKeys.orientationHack).get()));
else
recorder.setOrientation(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ public void SetPictureOrientation(int orientation)
{
if (cameraParameters == null)
return;
if (SettingsManager.get(SettingKeys.orientationHack).get() || SettingsManager.getInstance().getIsFrontCamera())
if (!SettingsManager.get(SettingKeys.orientationHack).get().equals("0") || SettingsManager.getInstance().getIsFrontCamera())
{
int or = orientation +180;
int or = orientation +Integer.parseInt(SettingsManager.get(SettingKeys.orientationHack).get());
if (or >360)
or = or - 360;
orientation = or;
Expand Down Expand Up @@ -621,10 +621,8 @@ public float getFocal()
public void SetCameraRotation()
{

if (!SettingsManager.get(SettingKeys.orientationHack).get())
((CameraHolder) cameraUiWrapper.getCameraHolder()).SetCameraRotation(0);
else
((CameraHolder) cameraUiWrapper.getCameraHolder()).SetCameraRotation(180);
int or = Integer.parseInt(SettingsManager.get(SettingKeys.orientationHack).get());
((CameraHolder) cameraUiWrapper.getCameraHolder()).SetCameraRotation(or);
}

public void SetupMTK() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import freed.settings.SettingKeys;
import freed.settings.SettingsManager;
import freed.utils.Log;
import freed.utils.OrientationUtil;


/**
Expand Down Expand Up @@ -253,9 +254,7 @@ private void preparePreviewTextureView(int orientationToSet, Size previewSize) {
case 0: rotation = 270;
break;
}
if (SettingsManager.get(SettingKeys.orientationHack).get())
rotation = (360 + rotation+180)%360;
final int or = rotation;
final int or = OrientationUtil.getOrientation(rotation);

Log.d(TAG, "rotation to set : " + or);
mainHandler.post(() -> cameraUiWrapper.captureSessionHandler.SetTextureViewSize(w, h,or,true));
Expand All @@ -276,16 +275,15 @@ private void preparePreviewTextureView(int orientationToSet, Size previewSize) {
rotation = 270;
break;
case 180:
rotation =180;
rotation =0;
break;
case 270: rotation = 270;
break;
case 0: rotation = 180;
break;
}
if (SettingsManager.get(SettingKeys.orientationHack).get())
rotation = (360 + rotation+180)%360;
final int or = rotation;

final int or = OrientationUtil.getOrientation(rotation);;
Log.d(TAG, "rotation to set : " + or);

mainHandler.post(() -> cameraUiWrapper.captureSessionHandler.SetTextureViewSize(w, h, or,false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import freed.settings.SettingKeys;
import freed.settings.SettingsManager;
import freed.utils.Log;
import freed.utils.OrientationUtil;
import freed.utils.PermissionManager;
import freed.utils.VideoMediaProfile;

Expand Down Expand Up @@ -233,9 +234,7 @@ public void startPreview() {
case 0: rotation = 270;
break;
}
if (SettingsManager.get(SettingKeys.orientationHack).get())
rotation = (360 + rotation+180)%360;
final int or = rotation;
final int or = OrientationUtil.getOrientation(rotation);

Log.d(TAG, "rotation to set : " + or);
mainHandler.post(() -> cameraUiWrapper.captureSessionHandler.SetTextureViewSize(previewSize.getWidth(), previewSize.getHeight(),or,true));
Expand Down Expand Up @@ -267,9 +266,7 @@ public void startPreview() {
final int w, h, or;
w = previewSize.getWidth();
h = previewSize.getHeight();
if (SettingsManager.get(SettingKeys.orientationHack).get())
orientation = (360 + orientation + 180) % 360;
or = orientation;
or = OrientationUtil.getOrientation(orientation);
mainHandler.post(() -> cameraUiWrapper.captureSessionHandler.SetTextureViewSize(w, h, or, false));

SurfaceTexture texture = cameraUiWrapper.getTexturView().getSurfaceTexture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import freed.settings.SettingKeys;
import freed.settings.SettingsManager;
import freed.utils.Log;
import freed.utils.OrientationUtil;
import freed.views.VideoToneCurveProfile;

/**
Expand Down Expand Up @@ -250,13 +251,7 @@ public void SetFocusAREA(Rect focusAreas) {
@Override
public void SetPictureOrientation(int orientation)
{
if (SettingsManager.get(SettingKeys.orientationHack).get())
{
int or = orientation +180;
if (or >360)
or = or - 360;
orientation = or;
}
orientation = OrientationUtil.getOrientation(orientation);
if (cameraHolder == null || cameraHolder.isWorking)
return;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void detect()
SettingsManager.getInstance().SetCurrentCamera(i);

//publishProgress("isFrontCamera:"+SettingsManager.getInstance().getIsFrontCamera() + " CameraID:"+ i);
SettingsManager.get(SettingKeys.orientationHack).setValues(new String[]{"0","90","180","270"});
SettingsManager.get(SettingKeys.orientationHack).set("0");
SettingsManager.get(SettingKeys.orientationHack).setIsSupported(true);

Camera.Parameters parameters = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public void detect()
//publishProgress("#####CameraID:"+cameraids.get(c)+"####");
//publishProgress("###################");
//publishProgress("Check camera features:" + cameraids.get(c));
SettingsManager.get(SettingKeys.orientationHack).setValues(new String[]{"0","90","180","270"});
SettingsManager.get(SettingKeys.orientationHack).set("0");
SettingsManager.get(SettingKeys.orientationHack).setIsSupported(true);

CameraCharacteristics characteristics = null;
try {
characteristics = manager.getCameraCharacteristics(cameraids.get(c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,18 @@ public SettingsChildMenuOrientationHack(Context context, int headerid, int descr
public void SetCameraUIWrapper(CameraWrapperInterface cameraUiWrapper)
{
this.cameraUiWrapper = cameraUiWrapper;
if (SettingsManager.get(SettingKeys.orientationHack).get())
onStringValueChanged(getResources().getString(R.string.on_));
else
onStringValueChanged(getResources().getString(R.string.off_));
onStringValueChanged(SettingsManager.get(SettingKeys.orientationHack).get());
}

@Override
public String[] GetValues() {
return new String[] {getResources().getString(R.string.on_), getResources().getString(R.string.off_)};
return SettingsManager.get(SettingKeys.orientationHack).getValues();
}

@Override
public void SetValue(String value)
{
if (value.equals(getContext().getResources().getString(R.string.on_)))
SettingsManager.get(SettingKeys.orientationHack).set(true);
else
SettingsManager.get(SettingKeys.orientationHack).set(false);
SettingsManager.get(SettingKeys.orientationHack).set(value);
if (cameraUiWrapper instanceof Camera1Fragment) {
((ParametersHandler) cameraUiWrapper.getParameterHandler()).SetCameraRotation();
cameraUiWrapper.getParameterHandler().SetPictureOrientation(0);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/freed/settings/SettingKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class SettingKeys{

public final static Key<ApiBooleanSettingMode> useQcomFocus = new Key(ApiBooleanSettingMode.class, R.string.aps_qcomfocus);
public final static Key<ApiBooleanSettingMode> support12bitRaw = new Key(ApiBooleanSettingMode.class, R.string.aps_support12bitraw);
public final static Key<ApiBooleanSettingMode> orientationHack = new Key(ApiBooleanSettingMode.class, R.string.aps_orientationHack);
public final static Key<SettingMode> orientationHack = new Key(SettingMode.class, R.string.aps_orientationHack);
public final static Key<ApiBooleanSettingMode> openCamera1Legacy = new Key(ApiBooleanSettingMode.class, R.string.aps_opencamera1legacy);
public final static Key<ApiBooleanSettingMode> useHuaweiWhiteBalance = new Key(ApiBooleanSettingMode.class, R.string.aps_usehuawei_wb);

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/freed/utils/OrientationUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package freed.utils;

import freed.settings.SettingKeys;
import freed.settings.SettingsManager;

public class OrientationUtil {
public static int getOrientation(int rotation)
{
if (!SettingsManager.get(SettingKeys.orientationHack).get().equals("0"))
return (360 + rotation+Integer.parseInt(SettingsManager.get(SettingKeys.orientationHack).get()))%360;
else return rotation;
}
}

0 comments on commit 05f95e9

Please sign in to comment.