package epson.common;

import android.app.Activity;
import android.content.res.Configuration;

import android.view.Display;

import androidx.annotation.NonNull;

public class OsAssistant {
    public static void lockScreenRotation(@NonNull Activity activity) {
        Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
        Configuration configuration = activity.getResources().getConfiguration();
        switch (defaultDisplay.getRotation()) {
            case 0:
                if (configuration.orientation == 2) {
                    activity.setRequestedOrientation(0);
                    return;
                } else {
                    activity.setRequestedOrientation(1);
                    return;
                }
            case 1:
                if (configuration.orientation == 1) {
                    activity.setRequestedOrientation(9);
                    return;
                } else {
                    activity.setRequestedOrientation(0);
                    return;
                }
            case 2:
                if (configuration.orientation == 2) {
                    activity.setRequestedOrientation(8);
                    return;
                } else {
                    activity.setRequestedOrientation(9);
                    return;
                }
            case 3:
                if (configuration.orientation == 1) {
                    activity.setRequestedOrientation(1);
                    return;
                } else {
                    activity.setRequestedOrientation(8);
                    return;
                }
            default:
                return;
        }
    }
}
