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

Commit 056cc05a authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge changes from topic "complication-ui-event" into udc-qpr-dev

* changes:
  Log UI event on tap clock complication
  Add dagger scope to clock complication
  Flatten clock complication layout
parents 8158e078 67e155d1
Loading
Loading
Loading
Loading
+21 −28
Original line number Diff line number Diff line
@@ -14,15 +14,10 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
-->
<FrameLayout
<com.android.systemui.shared.shadow.DoubleShadowTextClock
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.android.systemui.shared.shadow.DoubleShadowTextClock
        android:id="@+id/time_view"
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@*android:string/config_clockFontFamily"
    android:textColor="@android:color/white"
@@ -43,5 +38,3 @@
    app:ambientShadowAlpha="0.3"
    app:removeTextDescent="true"
    app:textDescentExtraPadding="@dimen/dream_overlay_clock_text_descent_extra_padding" />

</FrameLayout>
+38 −8
Original line number Diff line number Diff line
@@ -16,34 +16,36 @@

package com.android.systemui.complication;

import static com.android.systemui.complication.dagger.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW;
import static com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW;
import static com.android.systemui.complication.dagger.RegisteredComplicationsModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS;

import android.view.View;

import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent;
import com.android.systemui.dagger.qualifiers.SystemUser;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.shared.condition.Monitor;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.condition.ConditionalCoreStartable;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

/**
 * Clock Time Complication that produce Clock Time view holder.
 */
public class DreamClockTimeComplication implements Complication {
    private final Provider<DreamClockTimeViewHolder> mDreamClockTimeViewHolderProvider;
    private final DreamClockTimeComplicationComponent.Factory mComponentFactory;

    /**
     * Default constructor for {@link DreamClockTimeComplication}.
     */
    @Inject
    public DreamClockTimeComplication(
            Provider<DreamClockTimeViewHolder> dreamClockTimeViewHolderProvider) {
        mDreamClockTimeViewHolderProvider = dreamClockTimeViewHolderProvider;
            DreamClockTimeComplicationComponent.Factory componentFactory) {
        mComponentFactory = componentFactory;
    }

    @Override
@@ -56,7 +58,7 @@ public class DreamClockTimeComplication implements Complication {
     */
    @Override
    public ViewHolder createView(ComplicationViewModel model) {
        return mDreamClockTimeViewHolderProvider.get();
        return mComponentFactory.create().getViewHolder();
    }

    /**
@@ -94,11 +96,14 @@ public class DreamClockTimeComplication implements Complication {
        private final ComplicationLayoutParams mLayoutParams;

        @Inject
        DreamClockTimeViewHolder(@Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
        DreamClockTimeViewHolder(
                @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
                @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
                        ComplicationLayoutParams layoutParams) {
                        ComplicationLayoutParams layoutParams,
                DreamClockTimeViewController viewController) {
            mView = view;
            mLayoutParams = layoutParams;
            viewController.init();
        }

        @Override
@@ -111,4 +116,29 @@ public class DreamClockTimeComplication implements Complication {
            return mLayoutParams;
        }
    }

    static class DreamClockTimeViewController extends ViewController<View> {
        private final UiEventLogger mUiEventLogger;

        @Inject
        DreamClockTimeViewController(
                @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
                UiEventLogger uiEventLogger) {
            super(view);

            mUiEventLogger = uiEventLogger;
        }

        @Override
        protected void onViewAttached() {
            mView.setOnClickListener(this::onClick);
        }

        @Override
        protected void onViewDetached() {}

        private void onClick(View v) {
            mUiEventLogger.log(DreamOverlayUiEvent.DREAM_CLOCK_TAPPED);
        }
    }
}
+1 −20
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.animation.ActivityLaunchAnimator;
@@ -201,23 +199,6 @@ public class DreamHomeControlsComplication implements Complication {

        private final UiEventLogger mUiEventLogger;

        @VisibleForTesting
        public enum DreamOverlayEvent implements UiEventLogger.UiEventEnum {
            @UiEvent(doc = "The home controls on the screensaver has been tapped.")
            DREAM_HOME_CONTROLS_TAPPED(1212);

            private final int mId;

            DreamOverlayEvent(int id) {
                mId = id;
            }

            @Override
            public int getId() {
                return mId;
            }
        }

        @Inject
        DreamHomeControlsChipViewController(
                @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view,
@@ -246,7 +227,7 @@ public class DreamHomeControlsComplication implements Complication {
        private void onClickHomeControls(View v) {
            if (DEBUG) Log.d(TAG, "home controls complication tapped");

            mUiEventLogger.log(DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);
            mUiEventLogger.log(DreamOverlayUiEvent.DREAM_HOME_CONTROLS_TAPPED);

            final Intent intent = new Intent(mContext, ControlsActivity.class)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 * 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.
@@ -14,43 +14,19 @@
 * limitations under the License.
 */

package com.android.systemui.complication.dagger;
package com.android.systemui.complication

import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger.UiEventEnum

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextClock;
/** UI log events for the dream overlay. */
enum class DreamOverlayUiEvent(private val mId: Int) : UiEventEnum {
    @UiEvent(doc = "The home controls on the screensaver has been tapped.")
    DREAM_HOME_CONTROLS_TAPPED(1212),
    @UiEvent(doc = "The clock on the screensaver has been tapped") DREAM_CLOCK_TAPPED(1440),
    @UiEvent(doc = "The weather on the screensaver has been tapped") DREAM_WEATHER_TAPPED(1441);

import com.android.internal.util.Preconditions;
import com.android.systemui.R;
import com.android.systemui.complication.DreamClockTimeComplication;

import dagger.Module;
import dagger.Provides;

import javax.inject.Named;

/**
 * Module for providing {@link DreamClockTimeComplication}.
 */
@Module
public interface DreamClockTimeComplicationModule {
    String DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view";
    String TAG_WEIGHT = "'wght' ";
    int WEIGHT = 400;

    /**
     * Provides the complication view.
     */
    @Provides
    @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
    static View provideComplicationView(LayoutInflater layoutInflater) {
        final View view = Preconditions.checkNotNull(
                        layoutInflater.inflate(R.layout.dream_overlay_complication_clock_time,
                                null, false),
                "R.layout.dream_overlay_complication_clock_time did not properly inflated");
        ((TextClock) view.findViewById(R.id.time_view)).setFontVariationSettings(
                TAG_WEIGHT + WEIGHT);
        return view;
    override fun getId(): Int {
        return mId
    }
}
+81 −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.systemui.complication.dagger

import android.view.LayoutInflater
import android.view.View
import android.widget.TextClock
import com.android.internal.util.Preconditions
import com.android.systemui.R
import com.android.systemui.complication.DreamClockTimeComplication
import com.android.systemui.complication.DreamClockTimeComplication.DreamClockTimeViewHolder
import dagger.Module
import dagger.Provides
import dagger.Subcomponent
import javax.inject.Named
import javax.inject.Scope

/** Responsible for generating dependencies for the [DreamClockTimeComplication]. */
@Subcomponent(
    modules = [DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule::class]
)
@DreamClockTimeComplicationComponent.DreamClockTimeComplicationScope
interface DreamClockTimeComplicationComponent {
    /** Scope of the clock complication. */
    @MustBeDocumented
    @Retention(AnnotationRetention.RUNTIME)
    @Scope
    annotation class DreamClockTimeComplicationScope

    /** Factory that generates a component for the clock complication. */
    @Subcomponent.Factory
    interface Factory {
        fun create(): DreamClockTimeComplicationComponent
    }

    /** Creates a view holder for the clock complication. */
    fun getViewHolder(): DreamClockTimeViewHolder

    /** Module for providing injected values within the clock complication scope. */
    @Module
    interface DreamClockTimeComplicationModule {
        companion object {
            const val DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view"
            private const val TAG_WEIGHT = "'wght' "
            private const val WEIGHT = 400

            /** Provides the complication view. */
            @Provides
            @DreamClockTimeComplicationScope
            @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
            fun provideComplicationView(layoutInflater: LayoutInflater): View {
                val view =
                    Preconditions.checkNotNull(
                        layoutInflater.inflate(
                            R.layout.dream_overlay_complication_clock_time,
                            /* root = */ null,
                            /* attachToRoot = */ false,
                        ) as TextClock,
                        "R.layout.dream_overlay_complication_clock_time did not properly inflate"
                    )
                view.setFontVariationSettings(TAG_WEIGHT + WEIGHT)
                return view
            }
        }
    }
}
Loading