Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82f1652e authored by Jamie Garside's avatar Jamie Garside
Browse files

Move bouncer to bottom of screen when in one handed mode.

If one handed bouncer is enabled, both in the SysUI config (i.e.
sw600dp-land) and in the device config, then use a different gravity for
the keyguard host view. This is used to move the bouncer to the bottom
of the screen when the bouncer is one handed.

Of course, password entry isn't one-handed, but we don't bother checking
which security mode is in use. In that mode, the password line is just
on top of the keyboard anyway, so even using gravity = BOTTOM, it
doesn't render differently.

Bug: 170858298
Test: atest
SystemUITests: com.android.keyguard.KeyguardHostViewControllerTest
Change-Id: Ia24d74ca1993d667c46b8ebb8bde6ea4888a0f97
parent 3d41ec9b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,4 +20,11 @@

         0x50 = bottom, 0x01 = center_horizontal -->
    <integer name="keyguard_host_view_gravity">0x51</integer>

    <!-- Gravity for the keyguard when it is in one-handed mode. This is ignored unless
         can_use_one_handed_bouncer is true, _and_ the one handed bouncer is enabled in the device
         config (com.android.internal.R.bool.config_enableOneHandedKeyguard)

         0x50 = bottom, 0x01 = center_horizontal -->
    <integer name="keyguard_host_view_one_handed_gravity">0x51</integer>
</resources>
+12 −1
Original line number Diff line number Diff line
@@ -475,7 +475,18 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
     * configuration.
     */
    public void updateResources() {
        int gravity = mView.getResources().getInteger(R.integer.keyguard_host_view_gravity);
        int gravity;

        Resources resources = mView.getResources();

        if (resources.getBoolean(R.bool.can_use_one_handed_bouncer)
                && resources.getBoolean(
                com.android.internal.R.bool.config_enableOneHandedKeyguard)) {
            gravity = resources.getInteger(
                    R.integer.keyguard_host_view_one_handed_gravity);
        } else {
            gravity = resources.getInteger(R.integer.keyguard_host_view_gravity);
        }

        // Android SysUI uses a FrameLayout as the top-level, but Auto uses RelativeLayout.
        // We're just changing the gravity here though (which can't be applied to RelativeLayout),
+48 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableResources;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -49,7 +50,6 @@ import org.mockito.junit.MockitoRule;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class KeyguardHostViewControllerTest extends SysuiTestCase {

    @Mock
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;

@@ -68,14 +68,21 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase {
    @Rule
    public MockitoRule mMockitoRule = MockitoJUnit.rule();

    private TestableResources mTestableResources;
    private KeyguardHostViewController mKeyguardHostViewController;

    @Before
    public void setup() {
        mContext.ensureTestableResources();
        mTestableResources = mContext.getOrCreateTestableResources();

        mKeyguardHostView = new KeyguardHostView(mContext);

        // Explicitly disable one handed keyguard.
        mTestableResources.addOverride(
                R.bool.can_use_one_handed_bouncer, false);
        mTestableResources.addOverride(
                com.android.internal.R.bool.config_enableOneHandedKeyguard, false);

        when(mKeyguardSecurityContainerControllerFactory.create(any(
                KeyguardSecurityContainer.SecurityCallback.class)))
                .thenReturn(mKeyguardSecurityContainerController);
@@ -106,7 +113,7 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase {
        mKeyguardHostView.setLayoutParams(lp);

        // Set initial gravity
        mContext.getOrCreateTestableResources().addOverride(R.integer.keyguard_host_view_gravity,
        mTestableResources.addOverride(R.integer.keyguard_host_view_gravity,
                Gravity.CENTER);

        // Kick off the initial pass...
@@ -116,9 +123,46 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase {
                Gravity.CENTER);

        // Now simulate a config change
        mContext.getOrCreateTestableResources().addOverride(R.integer.keyguard_host_view_gravity,
        mTestableResources.addOverride(R.integer.keyguard_host_view_gravity,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);

        mKeyguardHostViewController.updateResources();
        assertEquals(
                ((FrameLayout.LayoutParams) mKeyguardHostView.getLayoutParams()).gravity,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    }

    @Test
    public void testGravityUsesOneHandGravityWhenApplicable() {
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        mKeyguardHostView.setLayoutParams(lp);

        mTestableResources.addOverride(
                R.integer.keyguard_host_view_gravity,
                Gravity.CENTER);
        mTestableResources.addOverride(
                R.integer.keyguard_host_view_one_handed_gravity,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);

        // Start disabled.
        mTestableResources.addOverride(
                R.bool.can_use_one_handed_bouncer, false);
        mTestableResources.addOverride(
                com.android.internal.R.bool.config_enableOneHandedKeyguard, false);

        mKeyguardHostViewController.init();
        assertEquals(
                ((FrameLayout.LayoutParams) mKeyguardHostView.getLayoutParams()).gravity,
                Gravity.CENTER);

        // And enable
        mTestableResources.addOverride(
                R.bool.can_use_one_handed_bouncer, true);
        mTestableResources.addOverride(
                com.android.internal.R.bool.config_enableOneHandedKeyguard, true);

        mKeyguardHostViewController.updateResources();
        assertEquals(
                ((FrameLayout.LayoutParams) mKeyguardHostView.getLayoutParams()).gravity,