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

Commit e339737d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor some ViewHolder complications." into tm-dev

parents 249f6591 9ed7588c
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -16,32 +16,32 @@

package com.android.systemui.dreams.complication;

import static com.android.systemui.dreams.complication.dagger.DreamClockDateComplicationComponent.DreamClockDateComplicationModule.DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS;
import static com.android.systemui.dreams.complication.dagger.DreamClockDateComplicationComponent.DreamClockDateComplicationModule.DREAM_CLOCK_DATE_COMPLICATION_VIEW;
import static com.android.systemui.dreams.complication.dagger.DreamClockDateComplicationModule.DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS;
import static com.android.systemui.dreams.complication.dagger.DreamClockDateComplicationModule.DREAM_CLOCK_DATE_COMPLICATION_VIEW;

import android.content.Context;
import android.view.View;

import com.android.systemui.CoreStartable;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.dreams.complication.dagger.DreamClockDateComplicationComponent;

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

/**
 * Clock Date Complication that produce Clock Date view holder.
 */
public class DreamClockDateComplication implements Complication {
    DreamClockDateComplicationComponent.Factory mComponentFactory;
    private final Provider<DreamClockDateViewHolder> mDreamClockDateViewHolderProvider;

    /**
     * Default constructor for {@link DreamClockDateComplication}.
     */
    @Inject
    public DreamClockDateComplication(
            DreamClockDateComplicationComponent.Factory componentFactory) {
        mComponentFactory = componentFactory;
            Provider<DreamClockDateViewHolder> dreamClockDateViewHolderProvider) {
        mDreamClockDateViewHolderProvider = dreamClockDateViewHolderProvider;
    }

    @Override
@@ -54,11 +54,11 @@ public class DreamClockDateComplication implements Complication {
     */
    @Override
    public ViewHolder createView(ComplicationViewModel model) {
        return mComponentFactory.create().getViewHolder();
        return mDreamClockDateViewHolderProvider.get();
    }

    /**
     * {@link CoreStartable} responsbile for registering {@link DreamClockDateComplication} with
     * {@link CoreStartable} responsible for registering {@link DreamClockDateComplication} with
     * SystemUI.
     */
    public static class Registrant extends CoreStartable {
@@ -84,7 +84,7 @@ public class DreamClockDateComplication implements Complication {
    }

    /**
     * ViewHolder to contain value/logic associated with a Clock Date Complication View.
     * {@link ViewHolder} to contain value/logic associated with {@link DreamClockDateComplication}.
     */
    public static class DreamClockDateViewHolder implements ViewHolder {
        private final View mView;
+9 −9
Original line number Diff line number Diff line
@@ -16,32 +16,32 @@

package com.android.systemui.dreams.complication;

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

import android.content.Context;
import android.view.View;

import com.android.systemui.CoreStartable;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.dreams.complication.dagger.DreamClockTimeComplicationComponent;

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 {
    DreamClockTimeComplicationComponent.Factory mComponentFactory;
    private final Provider<DreamClockTimeViewHolder> mDreamClockTimeViewHolderProvider;

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

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

    /**
     * {@link CoreStartable} responsbile for registering {@link DreamClockTimeComplication} with
     * {@link CoreStartable} responsible for registering {@link DreamClockTimeComplication} with
     * SystemUI.
     */
    public static class Registrant extends CoreStartable {
@@ -84,7 +84,7 @@ public class DreamClockTimeComplication implements Complication {
    }

    /**
     * ViewHolder to contain value/logic associated with a Clock Time Complication View.
     * {@link ViewHolder} to contain value/logic associated with {@link DreamClockTimeComplication}.
     */
    public static class DreamClockTimeViewHolder implements ViewHolder {
        private final View mView;
+0 −110
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.dreams.complication.dagger;


import static java.lang.annotation.RetentionPolicy.RUNTIME;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.internal.util.Preconditions;
import com.android.systemui.R;
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
import com.android.systemui.dreams.complication.DreamClockDateComplication.DreamClockDateViewHolder;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Named;
import javax.inject.Scope;

import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;

/**
 * {@link DreamClockDateComplicationComponent} is responsible for generating dependencies
 * surrounding the
 * Clock Date {@link com.android.systemui.dreams.complication.Complication}, such as the layout
 * details.
 */
@Subcomponent(modules = {
        DreamClockDateComplicationComponent.DreamClockDateComplicationModule.class,
})
@DreamClockDateComplicationComponent.DreamClockDateComplicationScope
public interface DreamClockDateComplicationComponent {
    /**
     * Creates {@link DreamClockDateViewHolder}.
     */
    DreamClockDateViewHolder getViewHolder();

    @Documented
    @Retention(RUNTIME)
    @Scope
    @interface DreamClockDateComplicationScope {
    }

    /**
     * Generates {@link DreamClockDateComplicationComponent}.
     */
    @Subcomponent.Factory
    interface Factory {
        DreamClockDateComplicationComponent create();
    }

    /**
     * Scoped values for {@link DreamClockDateComplicationComponent}.
     */
    @Module
    interface DreamClockDateComplicationModule {
        String DREAM_CLOCK_DATE_COMPLICATION_VIEW = "clock_date_complication_view";
        String DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS =
                "clock_date_complication_layout_params";
        // Order weight of insert into parent container
        int INSERT_ORDER_WEIGHT = 2;

        /**
         * Provides the complication view.
         */
        @Provides
        @DreamClockDateComplicationScope
        @Named(DREAM_CLOCK_DATE_COMPLICATION_VIEW)
        static View provideComplicationView(LayoutInflater layoutInflater) {
            return Preconditions.checkNotNull(
                    layoutInflater.inflate(R.layout.dream_overlay_complication_clock_date,
                            null, false),
                    "R.layout.dream_overlay_complication_clock_date did not properly inflated");
        }

        /**
         * Provides the layout parameters for the complication view.
         */
        @Provides
        @DreamClockDateComplicationScope
        @Named(DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS)
        static ComplicationLayoutParams provideLayoutParams() {
            return new ComplicationLayoutParams(0,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ComplicationLayoutParams.POSITION_BOTTOM
                            | ComplicationLayoutParams.POSITION_START,
                    ComplicationLayoutParams.DIRECTION_END,
                    INSERT_ORDER_WEIGHT);
        }
    }
}
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.dreams.complication.dagger;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.internal.util.Preconditions;
import com.android.systemui.R;
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
import com.android.systemui.dreams.complication.DreamClockDateComplication;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

/**
 * Module for providing {@link DreamClockDateComplication}.
 */
@Module
public interface DreamClockDateComplicationModule {
    String DREAM_CLOCK_DATE_COMPLICATION_VIEW = "clock_date_complication_view";
    String DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS =
            "clock_date_complication_layout_params";
    // Order weight of insert into parent container
    //TODO(b/217199227): move to a single location.
    int INSERT_ORDER_WEIGHT = 2;

    /**
     * Provides the complication view.
     */
    @Provides
    @Named(DREAM_CLOCK_DATE_COMPLICATION_VIEW)
    static View provideComplicationView(LayoutInflater layoutInflater) {
        return Preconditions.checkNotNull(
                layoutInflater.inflate(R.layout.dream_overlay_complication_clock_date,
                        null, false),
                "R.layout.dream_overlay_complication_clock_date did not properly inflated");
    }

    /**
     * Provides the layout parameters for the complication view.
     */
    @Provides
    @Named(DREAM_CLOCK_DATE_COMPLICATION_LAYOUT_PARAMS)
    static ComplicationLayoutParams provideLayoutParams() {
        return new ComplicationLayoutParams(0,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ComplicationLayoutParams.POSITION_BOTTOM
                        | ComplicationLayoutParams.POSITION_START,
                ComplicationLayoutParams.DIRECTION_END,
                INSERT_ORDER_WEIGHT);
    }
}
+0 −115
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.dreams.complication.dagger;


import static java.lang.annotation.RetentionPolicy.RUNTIME;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextClock;

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

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Named;
import javax.inject.Scope;

import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;

/**
 * {@link DreamClockTimeComplicationComponent} is responsible for generating dependencies
 * surrounding the
 * Clock Time {@link com.android.systemui.dreams.complication.Complication}, such as the layout
 * details.
 */
@Subcomponent(modules = {
        DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule.class,
})
@DreamClockTimeComplicationComponent.DreamClockTimeComplicationScope
public interface DreamClockTimeComplicationComponent {
    /**
     * Creates {@link DreamClockTimeViewHolder}.
     */
    DreamClockTimeViewHolder getViewHolder();

    @Documented
    @Retention(RUNTIME)
    @Scope
    @interface DreamClockTimeComplicationScope {
    }

    /**
     * Generates {@link DreamClockTimeComplicationComponent}.
     */
    @Subcomponent.Factory
    interface Factory {
        DreamClockTimeComplicationComponent create();
    }

    /**
     * Scoped values for {@link DreamClockTimeComplicationComponent}.
     */
    @Module
    interface DreamClockTimeComplicationModule {
        String DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view";
        String DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS =
                "clock_time_complication_layout_params";
        // Order weight of insert into parent container
        int INSERT_ORDER_WEIGHT = 0;
        String TAG_WEIGHT = "'wght' ";
        int WEIGHT = 200;

        /**
         * Provides the complication view.
         */
        @Provides
        @DreamClockTimeComplicationScope
        @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
        static View provideComplicationView(LayoutInflater layoutInflater) {
            final TextClock view = Preconditions.checkNotNull((TextClock)
                            layoutInflater.inflate(R.layout.dream_overlay_complication_clock_time,
                                    null, false),
                    "R.layout.dream_overlay_complication_clock_time did not properly inflated");
            view.setFontVariationSettings(TAG_WEIGHT + WEIGHT);
            return view;
        }

        /**
         * Provides the layout parameters for the complication view.
         */
        @Provides
        @DreamClockTimeComplicationScope
        @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
        static ComplicationLayoutParams provideLayoutParams() {
            return new ComplicationLayoutParams(0,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ComplicationLayoutParams.POSITION_BOTTOM
                            | ComplicationLayoutParams.POSITION_START,
                    ComplicationLayoutParams.DIRECTION_UP,
                    INSERT_ORDER_WEIGHT);
        }
    }
}
Loading