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
This commit is contained in:
Bryce Lee
2021-07-13 12:48:06 -07:00
parent 898f2c796d
commit 936af5b5fc
5 changed files with 186 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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<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);
}
}

View File

@@ -21,6 +21,8 @@ import dagger.Module;
/**
* Dagger Module providing Communal-related functionality.
*/
@Module
@Module(subcomponents = {
CommunalViewComponent.class,
})
public class CommunalModule {
}

View File

@@ -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();
}

View File

@@ -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);
}
}