There is CheckBox with following code:
CheckBox cb = (CheckBox)findViewById(R.id.freezer);
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChan
So, here is my solution.
private int getCurentOrientation() {
Display d = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
boolean isWide = d.getWidth() >= d.getHeight();
switch (d.getRotation()) {
case Surface.ROTATION_0:
return isWide ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
case Surface.ROTATION_90:
return isWide ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
case Surface.ROTATION_180:
return isWide ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
case Surface.ROTATION_270:
return isWide ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
return -1;
}
private void lockOrientation(boolean lock) {
if (lock) {
setRequestedOrientation(getCurentOrientation());
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
}
On 4 devices (2 smartphones and 2 tablets) it works as nedded.