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

Commit 936af5b5 authored by Bryce Lee's avatar Bryce Lee
Browse files

Add CommunalHostView.

This changelist introduces CommunalHostView, a parent
container for hosting communal content on the lockscreen
UI. This ViewGroup eases managing the positioning and
visibility of communal-related content. An associated
controller for managing the view and dependency
associations have also been added.

Bug: 193550437
Test: atest CommunalHostViewControllerTest
Change-Id: Ifbf3784a065cdceb6708bde0bd17b578874f904f
parent 898f2c79
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.communal;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Container for communal presentation. Containing communal-related view to this parent view allows
 * for aggregate measurement/layout adjustments and capturing said values before the communal views
 * might be available.
 */
public class CommunalHostView extends FrameLayout {
    public CommunalHostView(@NonNull Context context) {
        this(context, null, 0);
    }

    public CommunalHostView(@NonNull Context context,
            @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CommunalHostView(@NonNull Context context, @Nullable AttributeSet attrs,
            int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.communal;

import android.view.View;

import com.android.systemui.util.ViewController;

/**
 * Injectable controller for {@link CommunalHostView}.
 */
public class CommunalHostViewController extends ViewController<CommunalHostView> {
    protected CommunalHostViewController(CommunalHostView view) {
        super(view);
    }

    @Override
    protected void onViewAttached() {
    }

    @Override
    protected void onViewDetached() {
    }

    /**
     * Sets whether the {@link CommunalHostView} is visible.
     *
     * @param visible {@code true} if the view should be shown, {@code false} otherwise.
     */
    public void show(boolean visible) {
        mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import dagger.Module;
/**
 * Dagger Module providing Communal-related functionality.
 */
@Module
@Module(subcomponents = {
        CommunalViewComponent.class,
})
public class CommunalModule {
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.communal.dagger;

import com.android.systemui.communal.CommunalHostView;
import com.android.systemui.communal.CommunalHostViewController;

import dagger.BindsInstance;
import dagger.Subcomponent;

/**
 * Subcomponent for working with {@link CommunalHostView}.
 */
@Subcomponent
public interface CommunalViewComponent {
    /** Simple factory for {@link CommunalViewComponent}. */
    @Subcomponent.Factory
    interface Factory {
        CommunalViewComponent build(@BindsInstance CommunalHostView view);
    }

    /** Builds a {@link CommunalHostViewController}. */
    CommunalHostViewController getCommunalHostViewController();
}
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.communal;

import static org.mockito.Mockito.verify;

import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.view.View;

import com.android.systemui.SysuiTestCase;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidTestingRunner.class)
public class CommunalHostViewControllerTest extends SysuiTestCase {
    @Mock
    private CommunalHostView mCommunalView;

    private CommunalHostViewController mController;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);

        mController = new CommunalHostViewController(mCommunalView);
    }

    @Test
    public void testShow() {
        mController.show(true /* visible */);
        verify(mCommunalView).setVisibility(View.VISIBLE);
    }
}