Add title and icon in panel header
- Add getIcon() and getSubTitle() in PanelContent - Check icon avalibility to decide header layout - Add test cases Bug: 147776885 Test: make -j42 RunSettingsRoboTests Change-Id: Idb51e81359b6037ca9b90965dd9b370fc5e22c84
This commit is contained in:
@@ -27,6 +27,51 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/panel_header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="49dp"
|
||||||
|
android:layout_height="49dp"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_marginStart="10dp">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/title_icon"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="25dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="9dp"
|
||||||
|
android:paddingTop="9dp">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/header_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/header_subtitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/panel_title"
|
android:id="@+id/panel_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -28,6 +28,20 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface PanelContent extends Instrumentable {
|
public interface PanelContent extends Instrumentable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a icon resource for the title of the Panel.
|
||||||
|
*/
|
||||||
|
default int getIcon() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a string for the subtitle of the Panel.
|
||||||
|
*/
|
||||||
|
default CharSequence getSubTitle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a string for the title of the Panel.
|
* @return a string for the title of the Panel.
|
||||||
*/
|
*/
|
||||||
|
@@ -32,6 +32,8 @@ import android.view.ViewGroup;
|
|||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -77,15 +79,19 @@ public class PanelFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private static final int DURATION_SLICE_BINDING_TIMEOUT_MS = 250;
|
private static final int DURATION_SLICE_BINDING_TIMEOUT_MS = 250;
|
||||||
|
|
||||||
private View mLayoutView;
|
@VisibleForTesting
|
||||||
|
View mLayoutView;
|
||||||
private TextView mTitleView;
|
private TextView mTitleView;
|
||||||
private Button mSeeMoreButton;
|
private Button mSeeMoreButton;
|
||||||
private Button mDoneButton;
|
private Button mDoneButton;
|
||||||
private RecyclerView mPanelSlices;
|
private RecyclerView mPanelSlices;
|
||||||
|
|
||||||
private PanelContent mPanel;
|
private PanelContent mPanel;
|
||||||
private MetricsFeatureProvider mMetricsProvider;
|
private MetricsFeatureProvider mMetricsProvider;
|
||||||
private String mPanelClosedKey;
|
private String mPanelClosedKey;
|
||||||
|
private LinearLayout mPanelHeader;
|
||||||
|
private ImageView mTitleIcon;
|
||||||
|
private TextView mHeaderTitle;
|
||||||
|
private TextView mHeaderSubtitle;
|
||||||
|
|
||||||
private final Map<Uri, LiveData<Slice>> mSliceLiveData = new LinkedHashMap<>();
|
private final Map<Uri, LiveData<Slice>> mSliceLiveData = new LinkedHashMap<>();
|
||||||
|
|
||||||
@@ -155,6 +161,10 @@ public class PanelFragment extends Fragment {
|
|||||||
mSeeMoreButton = mLayoutView.findViewById(R.id.see_more);
|
mSeeMoreButton = mLayoutView.findViewById(R.id.see_more);
|
||||||
mDoneButton = mLayoutView.findViewById(R.id.done);
|
mDoneButton = mLayoutView.findViewById(R.id.done);
|
||||||
mTitleView = mLayoutView.findViewById(R.id.panel_title);
|
mTitleView = mLayoutView.findViewById(R.id.panel_title);
|
||||||
|
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
|
||||||
|
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
|
||||||
|
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
||||||
|
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
||||||
|
|
||||||
// Make the panel layout gone here, to avoid janky animation when updating from old panel.
|
// Make the panel layout gone here, to avoid janky animation when updating from old panel.
|
||||||
// We will make it visible once the panel is ready to load.
|
// We will make it visible once the panel is ready to load.
|
||||||
@@ -182,7 +192,16 @@ public class PanelFragment extends Fragment {
|
|||||||
// Start loading Slices. When finished, the Panel will animate in.
|
// Start loading Slices. When finished, the Panel will animate in.
|
||||||
loadAllSlices();
|
loadAllSlices();
|
||||||
|
|
||||||
mTitleView.setText(mPanel.getTitle());
|
final int iconRes = mPanel.getIcon();
|
||||||
|
if (iconRes == -1) {
|
||||||
|
mTitleView.setText(mPanel.getTitle());
|
||||||
|
} else {
|
||||||
|
mTitleView.setVisibility(View.GONE);
|
||||||
|
mPanelHeader.setVisibility(View.VISIBLE);
|
||||||
|
mTitleIcon.setImageResource(iconRes);
|
||||||
|
mHeaderTitle.setText(mPanel.getTitle());
|
||||||
|
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
||||||
|
}
|
||||||
mSeeMoreButton.setOnClickListener(getSeeMoreListener());
|
mSeeMoreButton.setOnClickListener(getSeeMoreListener());
|
||||||
mDoneButton.setOnClickListener(getCloseListener());
|
mDoneButton.setOnClickListener(getCloseListener());
|
||||||
|
|
||||||
|
@@ -40,6 +40,27 @@ public class FakePanelContent implements PanelContent {
|
|||||||
|
|
||||||
public static final Intent INTENT = new Intent();
|
public static final Intent INTENT = new Intent();
|
||||||
|
|
||||||
|
private CharSequence mSubTitle;
|
||||||
|
private int mIconRes = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIcon() {
|
||||||
|
return mIconRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSubTitle() {
|
||||||
|
return mSubTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(int iconRes) {
|
||||||
|
mIconRes = iconRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubTitle(CharSequence subTitle) {
|
||||||
|
mSubTitle = subTitle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getTitle() {
|
public CharSequence getTitle() {
|
||||||
return TITLE;
|
return TITLE;
|
||||||
|
@@ -31,6 +31,7 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
@@ -41,10 +42,15 @@ import org.junit.runner.RunWith;
|
|||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.android.controller.ActivityController;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class PanelFragmentTest {
|
public class PanelFragmentTest {
|
||||||
|
|
||||||
|
private static final String SUBTITLE = "subtitle";
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PanelFragment mPanelFragment;
|
private PanelFragment mPanelFragment;
|
||||||
private FakeSettingsPanelActivity mActivity;
|
private FakeSettingsPanelActivity mActivity;
|
||||||
@@ -141,4 +147,38 @@ public class PanelFragmentTest {
|
|||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void supportIcon_displayIconHeaderLayout() {
|
||||||
|
mFakePanelContent.setIcon(R.drawable.ic_android);
|
||||||
|
mFakePanelContent.setSubTitle(SUBTITLE);
|
||||||
|
final ActivityController<FakeSettingsPanelActivity> activityController =
|
||||||
|
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||||
|
activityController.setup();
|
||||||
|
final PanelFragment panelFragment = (PanelFragment)
|
||||||
|
Objects.requireNonNull(activityController
|
||||||
|
.get()
|
||||||
|
.getSupportFragmentManager()
|
||||||
|
.findFragmentById(R.id.main_content));
|
||||||
|
final View titleView = panelFragment.mLayoutView.findViewById(R.id.panel_title);
|
||||||
|
final LinearLayout panelHeader = panelFragment.mLayoutView.findViewById(R.id.panel_header);
|
||||||
|
final TextView headerTitle = panelFragment.mLayoutView.findViewById(R.id.header_title);
|
||||||
|
final TextView headerSubtitle = panelFragment.mLayoutView.findViewById(
|
||||||
|
R.id.header_subtitle);
|
||||||
|
// Check visibility
|
||||||
|
assertThat(panelHeader.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
assertThat(titleView.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
// Check content
|
||||||
|
assertThat(headerTitle.getText()).isEqualTo(FakePanelContent.TITLE);
|
||||||
|
assertThat(headerSubtitle.getText()).isEqualTo(SUBTITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notSupportIcon_displayDefaultHeaderLayout() {
|
||||||
|
final View titleView = mPanelFragment.mLayoutView.findViewById(R.id.panel_title);
|
||||||
|
final View panelHeader = mPanelFragment.mLayoutView.findViewById(R.id.panel_header);
|
||||||
|
|
||||||
|
assertThat(panelHeader.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(titleView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user