diff --git a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostView.java b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostView.java new file mode 100644 index 0000000000000..6e2fcd11f6437 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostView.java @@ -0,0 +1,45 @@ +/* + * 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); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java new file mode 100644 index 0000000000000..65920150cab36 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java @@ -0,0 +1,47 @@ +/* + * 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 { + 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); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java index cb4eddd49c8ab..bcc36847d1fe2 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.java @@ -21,6 +21,8 @@ import dagger.Module; /** * Dagger Module providing Communal-related functionality. */ -@Module +@Module(subcomponents = { + CommunalViewComponent.class, +}) public class CommunalModule { } diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalViewComponent.java b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalViewComponent.java new file mode 100644 index 0000000000000..3a80a03aecb25 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalViewComponent.java @@ -0,0 +1,38 @@ +/* + * 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(); +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java new file mode 100644 index 0000000000000..8c327af2389fd --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java @@ -0,0 +1,53 @@ +/* + * 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); + } +}