Move orientation locking code to separate method

This commit is contained in:
Branden Archer
2018-10-06 14:24:05 -07:00
parent cafa09a86a
commit c5de27abe3

View File

@@ -227,15 +227,11 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
case R.id.action_lock_unlock:
if(rotationEnabled)
{
item.setIcon(R.drawable.ic_lock_outline_white_24dp);
item.setTitle(R.string.unlockScreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
setOrientatonLock(item, true);
}
else
{
item.setIcon(R.drawable.ic_lock_open_white_24dp);
item.setTitle(R.string.lockScreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
setOrientatonLock(item, false);
}
rotationEnabled = !rotationEnabled;
return true;
@@ -243,4 +239,20 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
private void setOrientatonLock(MenuItem item, boolean lock)
{
if(lock)
{
item.setIcon(R.drawable.ic_lock_outline_white_24dp);
item.setTitle(R.string.unlockScreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
else
{
item.setIcon(R.drawable.ic_lock_open_white_24dp);
item.setTitle(R.string.lockScreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}
}