android.support.v17.leanback.widget.DetailsOverviewRow Java Examples

The following examples show how to use android.support.v17.leanback.widget.DetailsOverviewRow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Video... videos) {
    DetailsOverviewRow row = new DetailsOverviewRow(videos[0]);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(videos[0].getThumbUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
        Log.e("VideoDetailsFragment", "Cannot load thumbnail for " + videos[0].getId(), e);
    }

    SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
    adapter.set(ACTION_PLAY, new Action(ACTION_PLAY, getResources().getString(
            R.string.action_play)));
    adapter.set(ACTION_WATCH_LATER, new Action(ACTION_WATCH_LATER, getResources().getString(R.string.action_watch_later)));
    row.setActionsAdapter(adapter);

    return row;
}
 
Example #2
Source File: MovieDetailsFragment.java    From BuildingForAndroidTV with MIT License 6 votes vote down vote up
private void setupDetailsOverviewRowPresenter() {
    // Set detail background and style.
    DetailsOverviewRowPresenter detailsPresenter =
            new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
    detailsPresenter.setBackgroundColor(getResources().getColor(R.color.selected_background));
    detailsPresenter.setStyleLarge(true);

    // Hook up transition element.
    detailsPresenter.setSharedElementEnterTransition(getActivity(),
            MovieDetailsActivity.SHARED_ELEMENT_NAME);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_WATCH_TRAILER) {
                Intent intent = new Intent(getActivity(), PlaybackActivity.class);
                intent.putExtra(MovieDetailsActivity.MOVIE, mSelectedMovie);
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });
    mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
}
 
Example #3
Source File: TVVideoDetailsFragment.java    From BuildingForAndroidTV with MIT License 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Movie... movies) {
    selectedMovie = movies[0];

    DetailsOverviewRow row = new DetailsOverviewRow(selectedMovie);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(selectedMovie.getCardImageUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
    }

    row.addAction(new Action(ACTION_WATCH_TRAILER, getResources().getString(
            R.string.watch_trailer_1), getResources().getString(R.string.watch_trailer_2)));
    row.addAction(new Action(ACTION_RENT, getResources().getString(R.string.rent_1),
            getResources().getString(R.string.rent_2)));
    row.addAction(new Action(ACTION_BUY, getResources().getString(R.string.buy_1),
            getResources().getString(R.string.buy_2)));
    return row;
}
 
Example #4
Source File: TVVideoDetailsFragment.java    From BuildingForAndroidTV with MIT License 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Movie... movies) {
    selectedMovie = movies[0];

    DetailsOverviewRow row = new DetailsOverviewRow(selectedMovie);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(selectedMovie.getCardImageUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
    }

    row.addAction(new Action(ACTION_WATCH_TRAILER, getResources().getString(
            R.string.watch_trailer_1), getResources().getString(R.string.watch_trailer_2)));
    row.addAction(new Action(ACTION_RENT, getResources().getString(R.string.rent_1),
            getResources().getString(R.string.rent_2)));
    row.addAction(new Action(ACTION_BUY, getResources().getString(R.string.buy_1),
            getResources().getString(R.string.buy_2)));
    return row;
}
 
Example #5
Source File: TVVideoDetailsFragment.java    From BuildingForAndroidTV with MIT License 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Movie... movies) {
    selectedMovie = movies[0];

    DetailsOverviewRow row = new DetailsOverviewRow(selectedMovie);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(selectedMovie.getCardImageUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
    }

    row.addAction(new Action(ACTION_WATCH_TRAILER, getResources().getString(
            R.string.watch_trailer_1), getResources().getString(R.string.watch_trailer_2)));
    row.addAction(new Action(ACTION_RENT, getResources().getString(R.string.rent_1),
            getResources().getString(R.string.rent_2)));
    row.addAction(new Action(ACTION_BUY, getResources().getString(R.string.buy_1),
            getResources().getString(R.string.buy_2)));
    return row;
}
 
Example #6
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Video... videos) {
    DetailsOverviewRow row = new DetailsOverviewRow(videos[0]);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(videos[0].getThumbUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
        Log.e("VideoDetailsFragment", "Cannot load thumbnail for " + videos[0].getId(), e);
    }

    SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
    adapter.set(ACTION_PLAY, new Action(ACTION_PLAY, getResources().getString(
            R.string.action_play)));
    adapter.set(ACTION_WATCH_LATER, new Action(ACTION_WATCH_LATER, getResources().getString(R.string.action_watch_later)));
    row.setActionsAdapter(adapter);

    return row;
}
 
Example #7
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Video... videos) {
    DetailsOverviewRow row = new DetailsOverviewRow(videos[0]);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(videos[0].getThumbUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
        Log.e("VideoDetailsFragment", "Cannot load thumbnail for " + videos[0].getId(), e);
    }

    SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
    adapter.set(ACTION_PLAY, new Action(ACTION_PLAY, getResources().getString(
            R.string.action_play)));
    adapter.set(ACTION_WATCH_LATER, new Action(ACTION_WATCH_LATER, getResources().getString(R.string.action_watch_later)));
    row.setActionsAdapter(adapter);

    return row;
}
 
Example #8
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Video... videos) {
    DetailsOverviewRow row = new DetailsOverviewRow(videos[0]);
    try {
        Bitmap poster = Picasso.with(getActivity())
                .load(videos[0].getThumbUrl())
                .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                        dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(getActivity(), poster);
    } catch (IOException e) {
        Log.e("VideoDetailsFragment", "Cannot load thumbnail for " + videos[0].getId(), e);
    }

    SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
    adapter.set(ACTION_PLAY, new Action(ACTION_PLAY, getResources().getString(
            R.string.action_play)));
    adapter.set(ACTION_WATCH_LATER, new Action(ACTION_WATCH_LATER, getResources().getString(R.string.action_watch_later)));
    row.setActionsAdapter(adapter);

    return row;
}
 
Example #9
Source File: LiveDataDetailFragmentUiModule.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@Provides
@PerFragment
public FullWidthDetailsOverviewSharedElementHelper provideHelper(Activity activity,
        PresenterSelector mPs, DetailsOverviewRow row, OnActionClickedListener listener) {
    FullWidthDetailsOverviewSharedElementHelper mHelper =
            new FullWidthDetailsOverviewSharedElementHelper();
    mHelper.setSharedElementEnterTransition(activity,
            LiveDataDetailActivity.SHARED_ELEMENT_NAME);

    ((FullWidthDetailsOverviewRowPresenter) mPs.getPresenter(row))
            .setListener(mHelper);
    ((FullWidthDetailsOverviewRowPresenter) mPs.getPresenter(row))
            .setParticipatingEntranceTransition(false);
    ((FullWidthDetailsOverviewRowPresenter) mPs.getPresenter(row))
            .setOnActionClickedListener(listener);
    return mHelper;

}
 
Example #10
Source File: DetailFragment.java    From TuentiTV with Apache License 2.0 5 votes vote down vote up
@Override public void showCardInfo(final CardInfo cardInfo) {
  new AsyncTask<Void, Void, Bitmap>() {

    @Override protected Bitmap doInBackground(Void... params) {
      Bitmap detailImage = null;
      try {
        detailImage = Picasso.with(getActivity())
            .load(cardInfo.getCardImageUrl())
            .placeholder(R.drawable.icn_wink)
            .error(R.drawable.icn_wink)
            .resize(Util.convertDpToPixel(getActivity(), DETAIL_THUMB_WIDTH),
                Util.convertDpToPixel(getActivity(), DETAIL_THUMB_HEIGHT))
            .centerCrop()
            .get();
      } catch (IOException e) {
        //Empty
      }
      return detailImage;
    }

    @Override protected void onPostExecute(Bitmap bitmap) {
      DetailsOverviewRow detailRow = configureDetailsOverviewRow(cardInfo, bitmap);
      ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
      DetailsOverviewRowPresenter dorPresenter =
          new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
      dorPresenter.setBackgroundColor(getResources().getColor(R.color.primary_color));
      dorPresenter.setStyleLarge(false);
      presenterSelector.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
      presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
      adapter = new ArrayObjectAdapter(presenterSelector);
      adapter.add(detailRow);
      setAdapter(adapter);
    }
  }.execute();
}
 
Example #11
Source File: VideoDetailsFragment.java    From leanback-assistant with Apache License 2.0 5 votes vote down vote up
private void setupDetailsOverviewRow() {
    final DetailsOverviewRow row = new DetailsOverviewRow(mMovie);

    Glide.with(this)
            .load(mMovie.getCardImage())
            .asBitmap()
            .dontAnimate()
            .error(R.drawable.assistant_tv_banner)
            .into(
                    new SimpleTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(
                                final Bitmap resource, GlideAnimation glideAnimation) {
                            row.setImageBitmap(getActivity(), resource);
                        }
                    });

    SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();

    adapter.set(
            ACTION_WATCH, new Action(ACTION_WATCH, getResources().getString(R.string.watch)));
    adapter.set(
            ACTION_RENT,
            new Action(
                    ACTION_RENT,
                    getResources().getString(R.string.rent),
                    mMovie.getRentalPrice()));
    adapter.set(
            ACTION_BUY,
            new Action(
                    ACTION_BUY,
                    getResources().getString(R.string.buy),
                    mMovie.getPurchasePrice()));
    row.setActionsAdapter(adapter);

    mAdapter.add(row);
}
 
Example #12
Source File: MovieDetailsFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private void setupDetailsOverviewRow() {
    Log.d(TAG, "doInBackground: " + mSelectedMovie.toString());
    final DetailsOverviewRow row = new DetailsOverviewRow(mSelectedMovie);
    row.setImageDrawable(getResources().getDrawable(R.drawable.default_background));
    int width = Utils.convertDpToPixel(getActivity()
            .getApplicationContext(), DETAIL_THUMB_WIDTH);
    int height = Utils.convertDpToPixel(getActivity()
            .getApplicationContext(), DETAIL_THUMB_HEIGHT);
    Glide.with(getActivity())
            .load(mSelectedMovie.getCardImageUrl())
            .centerCrop()
            .error(R.drawable.default_background)
            .into(new SimpleTarget<GlideDrawable>(width, height) {
                @Override
                public void onResourceReady(GlideDrawable resource,
                                            GlideAnimation<? super GlideDrawable>
                                                    glideAnimation) {
                    Log.d(TAG, "details overview card image url ready: " + resource);
                    row.setImageDrawable(resource);
                    mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size());
                }
            });

    row.addAction(new Action(ACTION_WATCH_TRAILER, getResources().getString(
            R.string.watch_trailer_1), getResources().getString(R.string.watch_trailer_2)));
    row.addAction(new Action(ACTION_RENT, getResources().getString(R.string.rent_1),
            getResources().getString(R.string.rent_2)));
    row.addAction(new Action(ACTION_BUY, getResources().getString(R.string.buy_1),
            getResources().getString(R.string.buy_2)));

    mAdapter.add(row);
}
 
Example #13
Source File: VideoDetailsFragment.java    From leanback-assistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    DetailsOverviewRow row = (DetailsOverviewRow) item;
    ImageView imageView = ((ImageView) viewHolder.view);
    imageView.setImageDrawable(row.getImageDrawable());
    if (isBoundToImage((ViewHolder) viewHolder, row)) {
        MovieDetailsOverviewLogoPresenter.ViewHolder vh =
                (MovieDetailsOverviewLogoPresenter.ViewHolder) viewHolder;
        vh.getParentPresenter().notifyOnBindLogo(vh.getParentViewHolder());
    }
}
 
Example #14
Source File: AppDetailsFragment.java    From TvAppRepo with Apache License 2.0 5 votes vote down vote up
private void setupDetailsOverviewRowPresenter() {
    // Set detail background and style.
    DetailsOverviewRowPresenter detailsPresenter =
            new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getActivity()));
    detailsPresenter.setBackgroundColor(getResources().getColor(R.color.selected_background));
    detailsPresenter.setStyleLarge(true);

    // Hook up transition element.
    detailsPresenter.setSharedElementEnterTransition(getActivity(),
            DetailsActivity.SHARED_ELEMENT_NAME);
    mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
}
 
Example #15
Source File: VideoDetailsFragment.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute( DetailsOverviewRow detailRow ) {
    if( detailRow == null )
        return;

    ClassPresenterSelector ps = new ClassPresenterSelector();
    DetailsOverviewRowPresenter dorPresenter =
            new DetailsOverviewRowPresenter( new DetailsDescriptionPresenter() );
    // set detail background and style
    dorPresenter.setBackgroundColor( getResources().getColor( R.color.detail_background ) );
    dorPresenter.setStyleLarge( true );
    dorPresenter.setOnActionClickedListener( new OnActionClickedListener() {
        @Override
        public void onActionClicked( Action action ) {
            if (action.getId() == ACTION_WATCH ) {
                Intent intent = new Intent( getActivity(), PlayerActivity.class );
                intent.putExtra( EXTRA_MOVIE, mSelectedMovie );
                intent.putExtra( EXTRA_SHOULD_AUTO_START, true );
                startActivity( intent );
            }
        }
    });

    ps.addClassPresenter( DetailsOverviewRow.class, dorPresenter );
    ps.addClassPresenter( ListRow.class,
            new ListRowPresenter() );


    ArrayObjectAdapter adapter = new ArrayObjectAdapter( ps );
    adapter.add( detailRow );
    loadRelatedMedia( adapter );
    setAdapter( adapter );
}
 
Example #16
Source File: DetailRowBuilderTask.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(DetailsOverviewRow detailRow) {
    ClassPresenterSelector ps = new ClassPresenterSelector();
    DetailsOverviewRowPresenter dorPresenter =
            new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter(mActivity));

    dorPresenter.setBackgroundColor(mActivity.getResources().getColor(R.color.fastlane_background));
    dorPresenter.setStyleLarge(true);
    dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_PLAY) {
                VideoUtils.playVideo(new WeakReference<Activity>(mActivity), mVideo);
            }
            else if (action.getId() == ACTION_VIEW_TRAILER) {
                Uri trailerUri = Uri.parse(mVideo.getMovie().getTrailer());
                mActivity.startActivity(new Intent(Intent.ACTION_VIEW, trailerUri));
            }
            else {
                Toast.makeText(mActivity, action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
    ps.addClassPresenter(ListRow.class, new ListRowPresenter());

    ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
    adapter.add(detailRow);

    addGroups(adapter);

    if (mRowBuilderTaskListener != null) {
        mRowBuilderTaskListener.taskCompleted(adapter);
    }
}
 
Example #17
Source File: DetailRowBuilderTask.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
@Override
protected DetailsOverviewRow doInBackground(Video... videos) {
    mVideo = videos[0];

    DetailsOverviewRow row = new DetailsOverviewRow(mVideo);
    try {
        Bitmap poster = Picasso.with(mActivity)
                .load(mVideo.getCardImageUrl())
                .resize(Utils.dpToPx(DETAIL_THUMB_WIDTH, mActivity.getApplicationContext()),
                        Utils.dpToPx(DETAIL_THUMB_HEIGHT, mActivity.getApplicationContext()))
                .centerCrop()
                .get();
        row.setImageBitmap(mActivity, poster);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (mShowPlayButton) {
        row.addAction(new Action(ACTION_PLAY, mActivity.getString(R.string.play)));
    }

    if (mVideo.getMovie() != null && !TextUtils.isEmpty(mVideo.getMovie().getTrailer())) {
        row.addAction(
                new Action(ACTION_VIEW_TRAILER, mActivity.getString(R.string.watch_trailer)));
    }

    return row;
}
 
Example #18
Source File: DetailFragment.java    From TuentiTV with Apache License 2.0 5 votes vote down vote up
private DetailsOverviewRow configureDetailsOverviewRow(CardInfo cardInfo, Bitmap bitmap) {
  final DetailsOverviewRow row = new DetailsOverviewRow(cardInfo);
  row.setImageBitmap(getActivity(), bitmap);
  row.addAction(new Action(VD_CALL_ACTION_ID, getString(R.string.vd_call_action_title)));
  row.addAction(new Action(CALL_ACTION_ID, getString(R.string.call_action_title)));
  row.addAction(new Action(CHAT_ACTION_ID, getString(R.string.chat_action_title)));
  row.addAction(new Action(EDIT_ACTION_ID, getString(R.string.edit_action_title)));
  return row;
}
 
Example #19
Source File: AdapterModule.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@DetailFragmentArrayObjectAdapterForRowsQualifier
@PerFragment
@Provides
ArrayObjectAdapter provideRowsArrayObjectAdapter(DetailsOverviewRow detailsOverviewRow, ListRow relatedRow, PresenterSelector mps) {
    ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(mps);
    rowsAdapter.add(detailsOverviewRow);
    rowsAdapter.add(relatedRow);
    return rowsAdapter;
}
 
Example #20
Source File: VideoDetailsFragment.java    From leanback-assistant with Apache License 2.0 5 votes vote down vote up
private void setupAdapter() {
    FullWidthDetailsOverviewRowPresenter detailsPresenter =
            new FullWidthDetailsOverviewRowPresenter(
                    new DetailsDescriptionPresenter(), new MovieDetailsOverviewLogoPresenter());

    detailsPresenter.setBackgroundColor(
            ContextCompat.getColor(getContext(), R.color.background_dark));
    detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_HALF);

    detailsPresenter.setOnActionClickedListener(
            new OnActionClickedListener() {
                @Override
                public void onActionClicked(Action action) {
                    if (action.getId() == ACTION_WATCH) {
                        Intent intent =
                                PlaybackActivity.createIntent(getContext(), mMovie.getId());
                        startActivity(intent);
                    } else {
                        Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            });

    ClassPresenterSelector mPresenterSelector = new ClassPresenterSelector();
    mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
    mAdapter = new ArrayObjectAdapter(mPresenterSelector);
    setAdapter(mAdapter);
}
 
Example #21
Source File: RowModule.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Provides
@PerFragment
DetailsOverviewRow provideDetailsOverviewRow(
        @DetailFragmentArrayObjectAdapterForActionsQualifier ArrayObjectAdapter adapter) {
    DetailsOverviewRow row = new DetailsOverviewRow(new Object());
    row.setActionsAdapter(adapter);
    return row;
}
 
Example #22
Source File: DetailViewExampleWithVideoBackgroundFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
    if (requestCode == DetailViewExampleWithVideoBackgroundActivity.BUY_MOVIE_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            ArrayObjectAdapter actionAdapter = (ArrayObjectAdapter)
                    ((DetailsOverviewRow) getAdapter().get(0)).getActionsAdapter();

            actionAdapter.add(0, mActionPlay);
            actionAdapter.remove(mActionRent);
            setTitle(getTitle() + " (Owned)");

            boolean watchNow = returnIntent
                    .getBooleanExtra(WizardExampleActivity.WATCH_NOW,
                            false);

            if (watchNow) {
                // Leave a delay for playing the video in order to focus on the video fragment
                // after coming back from Wizard activity
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        playMainVideoOnBackground();
                    }
                }, 500);
            }
        }
    }
}
 
Example #23
Source File: PresenterModule.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@PerFragment
@Provides
@IntoMap
@PresenterSelectorKey(DetailsOverviewRow.class)
public Presenter provideDetailsOverviewRowPresenter() {

    DetailsDescriptionPresenter pre = new DetailsDescriptionPresenter();
    return new FullWidthDetailsOverviewRowPresenter(pre);
}
 
Example #24
Source File: VideoDetailsFragment.java    From CumulusTV with MIT License 4 votes vote down vote up
private void setupDetailsOverviewRow() {
    final DetailsOverviewRow row = new DetailsOverviewRow(jsonChannel);
    row.setImageDrawable(getResources().getDrawable(R.drawable.c_background5));
    int width = Utils.convertDpToPixel(getActivity()
            .getApplicationContext(), DETAIL_THUMB_WIDTH);
    int height = Utils.convertDpToPixel(getActivity()
            .getApplicationContext(), DETAIL_THUMB_HEIGHT);
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                final Bitmap bitmap = Glide.with(getActivity())
                        .load(ChannelDatabase.getNonNullChannelLogo(jsonChannel))
                        .asBitmap()
                        .fitCenter()
                        .error(R.drawable.c_background5)
                        .into(DETAIL_THUMB_WIDTH, DETAIL_THUMB_HEIGHT)
                        .get();
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        row.setImageBitmap(getActivity(), bitmap);
                        mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size());
                    }
                });
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }).start();

    ArrayObjectAdapter actions = new ArrayObjectAdapter();
    // Add another action IF it isn't a channel you already have:
    ChannelDatabase cdn = ChannelDatabase.getInstance(getActivity());
    if(cdn.findChannelByMediaUrl(jsonChannel.getMediaUrl()) == null) {
        actions.add(new Action(ACTION_ADD, getString(R.string.add_channel_txt)));
    } else {
        actions.add(new Action(ACTION_EDIT, getString(R.string.edit_channel)));
    }
    actions.add(new Action(ACTION_WATCH, getString(R.string.play)));
    row.setActionsAdapter(actions);
    mAdapter.add(row);
}
 
Example #25
Source File: VideoDetailsFragment.java    From CumulusTV with MIT License 4 votes vote down vote up
private void setupDetailsOverviewRowPresenter() {
    // Set detail background and style.
    DetailsOverviewRowPresenter detailsPresenter =
            new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
    detailsPresenter.setBackgroundColor(getResources().getColor(R.color.selected_background));
    detailsPresenter.setStyleLarge(true);

    // Hook up transition element.
    detailsPresenter.setSharedElementEnterTransition(getActivity(),
            DetailsActivity.SHARED_ELEMENT_NAME);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if(action.getId() == ACTION_EDIT) {
                ActivityUtils.editChannel(getActivity(), jsonChannel.getMediaUrl());
            } else if(action.getId() == ACTION_WATCH) {
                Log.d(TAG, ChannelDatabase.getInstance(getActivity()).getHashMap().toString());
                if (ChannelDatabase.getInstance(getActivity()).getHashMap()
                        .containsKey(jsonChannel.getMediaUrl())) {
                    // Open in Live Channels
                    Uri liveChannelsUri =
                            TvContract.buildChannelUri(
                                    ChannelDatabase.getInstance(
                                            getActivity()).getHashMap()
                                            .get(jsonChannel.getMediaUrl()));
                    getActivity().startActivity(
                            new Intent(Intent.ACTION_VIEW, liveChannelsUri));
                } else {
                    ActivityUtils.openStream(getActivity(), jsonChannel.getMediaUrl());
                }
            } else if(action.getId() == ACTION_ADD) {
                Log.d(TAG, "Adding " + jsonChannel.toString());
                ActivityUtils
                        .addChannel(getActivity(), gapi, jsonChannel);
                getActivity().setResult(LeanbackActivity.RESULT_CODE_REFRESH_UI);
                getActivity().finish();
            }
        }
    });
    mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
}
 
Example #26
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(DetailsOverviewRow detailRow) {
    ClassPresenterSelector ps = new ClassPresenterSelector();

    FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getContext()));
    detailsPresenter.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary));
    detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_FULL);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_PLAY) {
                Intent intent = new Intent(getActivity(), PlayerActivity.class);
                intent.putExtra(Video.INTENT_EXTRA_VIDEO, selectedVideo);
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    ps.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
    ps.addClassPresenter(ListRow.class,
            new ListRowPresenter());

    /** bonus code for adding related items to details fragment **/
    // <START>
    ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
    adapter.add(detailRow);

    String subcategories[] = {
            "You may also like"
    };

    CursorObjectAdapter rowAdapter = new CursorObjectAdapter(new SinglePresenterSelector(new CardPresenter()));
    VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowAdapter);
    manager.startDataLoading();
    HeaderItem header = new HeaderItem(0, subcategories[0]);
    adapter.add(new ListRow(header, rowAdapter));
    setAdapter(adapter);
    // <END>
}
 
Example #27
Source File: RichAppLinkDetailsFragment.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final String displayNumber = getActivity().getIntent().getStringExtra(
            RichFeedUtil.EXTRA_DISPLAY_NUMBER);

    DetailsOverviewRowPresenter dorPresenter = new DetailsOverviewRowPresenter(
            new DetailsDescriptionPresenter());
    dorPresenter.setSharedElementEnterTransition(getActivity(), "RichAppLinkDetailsFragment");

    DetailsOverviewRow row = new DetailsOverviewRow(displayNumber);
    Resources res = getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.your_company);
    int length = Math.min(bitmap.getWidth(), bitmap.getHeight());
    Bitmap croppedBitmap = Bitmap.createBitmap(bitmap,
            (bitmap.getWidth() - length) / 2,
            (bitmap.getHeight() - length) / 2,
            length, length);
    row.setImageBitmap(getActivity(), croppedBitmap);

    Action action1 = new Action(0, res.getString(R.string.details_fragment_action_1));
    Action action2 = new Action(1, res.getString(R.string.details_fragment_action_2));
    row.addAction(action1);
    row.addAction(action2);

    ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
    dorPresenter.setBackgroundColor(ContextCompat.getColor(getActivity(),
            R.color.detail_background));
    dorPresenter.setStyleLarge(true);

    dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            getActivity().finish();
        }
    });

    presenterSelector.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
    presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
    ArrayObjectAdapter adapter = new ArrayObjectAdapter(presenterSelector);
    adapter.add(row);

    setAdapter(adapter);
}
 
Example #28
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(DetailsOverviewRow detailRow) {
    ClassPresenterSelector ps = new ClassPresenterSelector();

    FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getContext()));
    detailsPresenter.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary));
    detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_FULL);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_PLAY) {
                Intent intent = new Intent(getActivity(), PlayerActivity.class);
                intent.putExtra(Video.INTENT_EXTRA_VIDEO, selectedVideo);
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    ps.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
    ps.addClassPresenter(ListRow.class,
            new ListRowPresenter());

    /** bonus code for adding related items to details fragment **/
    // <START>
    ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
    adapter.add(detailRow);

    String subcategories[] = {
            "You may also like"
    };

    CursorObjectAdapter rowAdapter = new CursorObjectAdapter(new SinglePresenterSelector(new CardPresenter()));
    VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowAdapter);
    manager.startDataLoading();
    HeaderItem header = new HeaderItem(0, subcategories[0]);
    adapter.add(new ListRow(header, rowAdapter));
    setAdapter(adapter);
    // <END>

}
 
Example #29
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(DetailsOverviewRow detailRow) {
    ClassPresenterSelector ps = new ClassPresenterSelector();

    FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getContext()));
    detailsPresenter.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary));
    detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_FULL);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_PLAY) {
                Intent intent = new Intent(getActivity(), PlayerActivity.class);
                intent.putExtra(Video.INTENT_EXTRA_VIDEO, selectedVideo);
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    ps.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
    ps.addClassPresenter(ListRow.class, new ListRowPresenter());

    /** bonus code for adding related items to details fragment **/
    // <START>
    ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
    adapter.add(detailRow);

    String subcategories[] = {
            "You may also like"
    };

    CursorObjectAdapter rowAdapter = new CursorObjectAdapter(new SinglePresenterSelector(new CardPresenter()));
    VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowAdapter);
    manager.startDataLoading();
    HeaderItem header = new HeaderItem(0, subcategories[0]);
    adapter.add(new ListRow(header, rowAdapter));
    setAdapter(adapter);
    // <END>
}
 
Example #30
Source File: VideoDetailsFragment.java    From android-tv-leanback with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(DetailsOverviewRow detailRow) {
    ClassPresenterSelector ps = new ClassPresenterSelector();

    FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getContext()));
    detailsPresenter.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary));
    detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_FULL);

    detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
        @Override
        public void onActionClicked(Action action) {
            if (action.getId() == ACTION_PLAY) {
                Intent intent = new Intent(getActivity(), PlayerActivity.class);
                intent.putExtra(Video.INTENT_EXTRA_VIDEO, selectedVideo);
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    ps.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
    ps.addClassPresenter(ListRow.class, new ListRowPresenter());

    /** bonus code for adding related items to details fragment **/
    // <START>
    ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
    adapter.add(detailRow);

    String subcategories[] = {
            "You may also like"
    };

    CursorObjectAdapter rowAdapter = new CursorObjectAdapter(new SinglePresenterSelector(new CardPresenter()));
    VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowAdapter);
    manager.startDataLoading();
    HeaderItem header = new HeaderItem(0, subcategories[0]);
    adapter.add(new ListRow(header, rowAdapter));
    setAdapter(adapter);
    // <END>

}