Android TV アプリ用に android.support.v17.leanback.widget.DetailsOverviewRow を少し変更したバージョンを作成しようとしています。私が実現しようとしているレイアウトは、Google のデフォルト バージョンとほぼ同じですが、アクション パネルの上にプログレス バーが追加されています。私が今持っているものは次のようになります:
私が作成したいのは、おおよそ次のようなものです。
可能であれば、まったく新しいレイアウトをゼロから作成することなく、これを動的に追加したいと考えています。現在使用しているコードは次のとおりです。Android Studio のデフォルトの Android TV アプリからわずかに変更されています。
public class VideoDetailsFragment extends DetailsFragment {
private static final String TAG = "VideoDetailsFragment";
private static final int ACTION_UPDATE = 1;
private static final int ACTION_CHANGELOG = 2;
private static final int ACTION_INSTALLED = 3;
private static final int DETAIL_THUMB_WIDTH = 274;
private static final int DETAIL_THUMB_HEIGHT = 274;
private static final int NUM_COLS = 10;
private static final String UPDATE = "Update";
private Update mSelectedUpdate;
private Drawable mDefaultBackground;
private Target mBackgroundTarget;
private DisplayMetrics mMetrics;
private DetailsOverviewRowPresenter mDorPresenter;
private DetailRowBuilderTask mDetailRowBuilderTask;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate DetailsFragment");
super.onCreate(savedInstanceState);
mDorPresenter =
new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
BackgroundManager backgroundManager = BackgroundManager.getInstance(getActivity());
backgroundManager.attach(getActivity().getWindow());
mBackgroundTarget = new PicassoBackgroundManagerTarget(backgroundManager);
mDefaultBackground = getResources().getDrawable(R.drawable.default_background);
mMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
List<Update> list = UpdateList.setupMovies();
mSelectedUpdate = list.get(0);//(Update) getActivity().getIntent().getSerializableExtra(MOVIE);
mDetailRowBuilderTask = (DetailRowBuilderTask) new DetailRowBuilderTask().execute(list);
mDorPresenter.setSharedElementEnterTransition(getActivity(),
DetailsActivity.SHARED_ELEMENT_NAME);
setOnItemViewClickedListener(new ItemViewClickedListener());
}
@Override
public void onStop() {
mDetailRowBuilderTask.cancel(true);
super.onStop();
}
private class DetailRowBuilderTask extends AsyncTask<List<Update>, Integer, List<DetailsOverviewRow>> {
@Override
protected List<DetailsOverviewRow> doInBackground(List<Update>... movies) {
List<DetailsOverviewRow> rows = new ArrayList<DetailsOverviewRow>();
int exampleUpdate = 0;
for (Update m: movies[0]) {
DetailsOverviewRow row = new DetailsOverviewRow(m);
try {
//String test = mSelectedUpdate.getCardImageUrl();
Bitmap poster = Picasso.with(getActivity())
.load(m.getCardImageUrl())
.resize(Utils.convertDpToPixel(getActivity().getApplicationContext(), DETAIL_THUMB_WIDTH),
Utils.convertDpToPixel(getActivity().getApplicationContext(), DETAIL_THUMB_HEIGHT))
.centerCrop()
.get();
row.setImageBitmap(getActivity(), poster);
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, e.toString(), e);
}
SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
if (exampleUpdate++ == 0) {
Action a1 = new Action(ACTION_UPDATE, getResources().getString(R.string.download));
Action a2 = new Action(ACTION_CHANGELOG, getResources().getString(R.string.release_notes));
adapter.set(ACTION_UPDATE, a1);
adapter.set(ACTION_CHANGELOG, a2);
row.setActionsAdapter(adapter);
}else{
Action a1 = new Action(ACTION_INSTALLED, getResources().getString(
R.string.installed));
Action a2 = new Action(ACTION_CHANGELOG, getResources().getString(R.string.release_notes));
//ProgressBar p1 = new ProgressBar(getActivity(),null, android.R.attr.progressBarStyleHorizontal);
adapter.set(1, a1);
adapter.set(2, a2);
//adapter.set(3, p1);
row.setActionsAdapter(adapter);
}
rows.add(row);
}
return rows;
}
@Override
protected void onPostExecute(List<DetailsOverviewRow> detailRows) {
ClassPresenterSelector ps = new ClassPresenterSelector();
// set detail background and style
mDorPresenter.setBackgroundColor(getResources().getColor(R.color.black_opaque));
Log.i("TEST", "Setting BG Color of Detail View");
mDorPresenter.setStyleLarge(true);
mDorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
if (action.getId() == ACTION_UPDATE) {
/*Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class);
intent.putExtra(getResources().getString(R.string.movie), mSelectedUpdate);
intent.putExtra(getResources().getString(R.string.should_start), true);
startActivity(intent);*/
Toast.makeText(getActivity(), "Download Update", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
}
}
});
ps.addClassPresenter(DetailsOverviewRow.class, mDorPresenter);
ps.addClassPresenter(ListRow.class,
new ListRowPresenter());
ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
for(DetailsOverviewRow detailRow : detailRows){
adapter.add(detailRow);
}
String subcategories[] = {
getString(R.string.related_movies)
};
//HeaderItem header = new HeaderItem(0, subcategories[0]);
//adapter.add(new ListRow(header, listRowAdapter));
setAdapter(adapter);
}
}
private final class ItemViewClickedListener implements OnItemViewClickedListener {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof Update) {
Update update = (Update) item;
Log.d(TAG, "Item: " + item.toString());
Intent intent = new Intent(getActivity(), DetailsActivity.class);
intent.putExtra(DetailsActivity.MOVIE, update);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView) itemViewHolder.view).getMainImageView(),
DetailsActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
}
}
}
ProgressBar を追加する簡単な方法はありますか、それともまったく新しい xml レイアウトを作成する必要がありますか?