Add menu option to lock screen when viewing card

When passing a phone to a clerk to scan the barcode, if the
phone is rotated and the screen reloads it can be bothersome
or confusion. To avoid this situation, a new option is
added to lock the screen.

A menu icon is now added which defaults as unlocked. When
touched the app sets its orientation to the "natural" orientation
of the device. When touched again the sensor dictates the
orientation of the device.
This commit is contained in:
Branden Archer
2017-07-16 21:19:43 -04:00
parent 641d29a6f8
commit fb7e3e12f2
20 changed files with 67 additions and 1 deletions

View File

@@ -2,8 +2,11 @@ package protect.card_locker;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
@@ -53,6 +56,8 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
boolean updateLoyaltyCard;
boolean viewLoyaltyCard;
boolean rotationEnabled;
DBHelper db;
@Override
@@ -305,6 +310,8 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
getMenuInflater().inflate(R.menu.card_add_menu, menu);
}
rotationEnabled = true;
return super.onCreateOptionsMenu(menu);
}
@@ -361,6 +368,22 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
finish();
return true;
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);
}
else
{
item.setIcon(R.drawable.ic_lock_open_white_24dp);
item.setTitle(R.string.lockScreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
rotationEnabled = !rotationEnabled;
return true;
case R.id.action_save:
doSave();
return true;