Support suggestion UI card with a button.
Bug: 65065268 Test: robotests Change-Id: I24c8947e9b23a80de38b8cbd57404736a5d1660a
This commit is contained in:
@@ -18,15 +18,17 @@ package android.service.settings.suggestions;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Parcel;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
public class Suggestion {
|
||||
|
||||
public static final int FLAG_HAS_BUTTON = 1 << 0;
|
||||
|
||||
private final String mId;
|
||||
private final CharSequence mTitle;
|
||||
private final CharSequence mSummary;
|
||||
private final Icon mIcon;
|
||||
private final int mFlags;
|
||||
private final PendingIntent mPendingIntent;
|
||||
|
||||
/**
|
||||
@@ -57,6 +59,10 @@ public class Suggestion {
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return mFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Intent to launch when the suggestion is activated.
|
||||
*/
|
||||
@@ -70,13 +76,16 @@ public class Suggestion {
|
||||
mIcon = builder.mIcon;
|
||||
mPendingIntent = builder.mPendingIntent;
|
||||
mId = builder.mId;
|
||||
mFlags = builder.mFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder class for {@link Suggestion}.
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
private final String mId;
|
||||
private int mFlags;
|
||||
private CharSequence mTitle;
|
||||
private CharSequence mSummary;
|
||||
private Icon mIcon;
|
||||
@@ -114,6 +123,11 @@ public class Suggestion {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFlags(int flags) {
|
||||
mFlags = flags;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets suggestion intent
|
||||
*/
|
||||
|
@@ -143,6 +143,21 @@ public class SuggestionAdapterTest {
|
||||
.isEqualTo(R.layout.suggestion_tile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemType_hasButton_shouldReturnSuggestionWithButton() {
|
||||
final List<Suggestion> suggestions = new ArrayList<>();
|
||||
suggestions.add(new Suggestion.Builder("id")
|
||||
.setFlags(Suggestion.FLAG_HAS_BUTTON)
|
||||
.setTitle("123")
|
||||
.setSummary("456")
|
||||
.build());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||
suggestions, new ArrayList<>());
|
||||
|
||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||
.isEqualTo(R.layout.suggestion_tile_with_button);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_shouldSetListener() {
|
||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
||||
|
@@ -92,7 +92,7 @@ public class SuggestionDismissControllerTest {
|
||||
@Test
|
||||
public void getSwipeDirs_isSuggestionTileCard_shouldReturnDirection() {
|
||||
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
|
||||
when(vh.getItemViewType()).thenReturn(R.layout.suggestion_tile_remote_container);
|
||||
when(vh.getItemViewType()).thenReturn(R.layout.suggestion_tile_with_button);
|
||||
|
||||
assertThat(mController.getSwipeDirs(mRecyclerView, vh))
|
||||
.isEqualTo(ItemTouchHelper.START | ItemTouchHelper.END);
|
||||
|
Reference in New Issue
Block a user