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

Commit 33b4225f authored by Nicolò Mazzucato's avatar Nicolò Mazzucato Committed by Android (Google) Code Review
Browse files

Merge "Create connected display presentation" into udc-qpr-dev

parents b20dbb50 212dc4a1
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ class DefaultClockController(
    private val burmeseLineSpacing =
        resources.getFloat(R.dimen.keyguard_clock_line_spacing_scale_burmese)
    private val defaultLineSpacing = resources.getFloat(R.dimen.keyguard_clock_line_spacing_scale)
    protected var onSecondaryDisplay: Boolean = false

    override val events: DefaultClockEvents
    override val config = ClockConfig()
@@ -142,6 +143,11 @@ class DefaultClockController(
                    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSizePx)
                    recomputePadding(targetRegion)
                }

                override fun onSecondaryDisplayChanged(onSecondaryDisplay: Boolean) {
                    this@DefaultClockController.onSecondaryDisplay = onSecondaryDisplay
                    recomputePadding(null)
                }
            }

        open fun recomputePadding(targetRegion: Rect?) {}
@@ -182,13 +188,19 @@ class DefaultClockController(
        override fun recomputePadding(targetRegion: Rect?) {
            // We center the view within the targetRegion instead of within the parent
            // view by computing the difference and adding that to the padding.
            val lp = view.getLayoutParams() as FrameLayout.LayoutParams
            lp.topMargin =
                if (onSecondaryDisplay) {
                    // On the secondary display we don't want any additional top/bottom margin.
                    0
                } else {
                    val parent = view.parent
                    val yDiff =
                        if (targetRegion != null && parent is View && parent.isLaidOut())
                            targetRegion.centerY() - parent.height / 2f
                        else 0f
            val lp = view.getLayoutParams() as FrameLayout.LayoutParams
            lp.topMargin = (-0.5f * view.bottom + yDiff).toInt()
                    (-0.5f * view.bottom + yDiff).toInt()
                }
            view.setLayoutParams(lp)
        }

+3 −0
Original line number Diff line number Diff line
@@ -177,6 +177,9 @@ interface ClockFaceEvents {
     * targetRegion is relative to the parent view.
     */
    fun onTargetRegionChanged(targetRegion: Rect?)

    /** Called to notify the clock about its display. */
    fun onSecondaryDisplayChanged(onSecondaryDisplay: Boolean)
}

/** Tick rates for clocks */
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
**
** Copyright 2023, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License")
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/presentation"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.android.keyguard.KeyguardStatusView
        android:id="@+id/clock"
        android:layout_width="410dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">

        <include
            android:id="@+id/keyguard_clock_container"
            layout="@layout/keyguard_clock_switch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </com.android.keyguard.KeyguardStatusView>

</FrameLayout>
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.keyguard

import android.app.Presentation
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.Display
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.android.keyguard.dagger.KeyguardStatusViewComponent
import com.android.systemui.R
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

/** [Presentation] shown in connected displays while on keyguard. */
class ConnectedDisplayKeyguardPresentation
@AssistedInject
constructor(
    @Assisted display: Display,
    context: Context,
    private val keyguardStatusViewComponentFactory: KeyguardStatusViewComponent.Factory,
) :
    Presentation(
        context,
        display,
        R.style.Theme_SystemUI_KeyguardPresentation,
        WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
    ) {

    private lateinit var keyguardStatusViewController: KeyguardStatusViewController
    private lateinit var clock: KeyguardStatusView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(
            LayoutInflater.from(context)
                .inflate(R.layout.keyguard_clock_presentation, /* root= */ null)
        )
        val window = window ?: error("no window available.")

        // Logic to make the lock screen fullscreen
        window.decorView.systemUiVisibility =
            (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
        window.attributes.fitInsetsTypes = 0
        window.isNavigationBarContrastEnforced = false
        window.navigationBarColor = Color.TRANSPARENT

        clock = findViewById(R.id.clock)
        keyguardStatusViewController =
            keyguardStatusViewComponentFactory.build(clock).keyguardStatusViewController.apply {
                setDisplayedOnSecondaryDisplay()
                init()
            }
    }

    /** [ConnectedDisplayKeyguardPresentation] factory. */
    @AssistedFactory
    interface Factory {
        /** Creates a new [Presentation] for the given [display]. */
        fun create(
            display: Display,
        ): ConnectedDisplayKeyguardPresentation
    }
}
+7 −5
Original line number Diff line number Diff line
package com.android.keyguard;

import static android.view.View.ALPHA;
import static android.view.View.SCALE_X;
import static android.view.View.SCALE_Y;
import static android.view.View.TRANSLATION_Y;

import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_X_CLOCK_DESIGN;
import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_Y_CLOCK_DESIGN;
import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_Y_CLOCK_SIZE;
@@ -145,6 +140,13 @@ public class KeyguardClockSwitch extends RelativeLayout {
        updateStatusArea(/* animate= */false);
    }

    /** Sets whether the large clock is being shown on a connected display. */
    public void setLargeClockOnSecondaryDisplay(boolean onSecondaryDisplay) {
        if (mClock != null) {
            mClock.getLargeClock().getEvents().onSecondaryDisplayChanged(onSecondaryDisplay);
        }
    }

    /**
     * Enable or disable split shade specific positioning
     */
Loading