Dake Gu | cc671dd | 2016-10-18 12:46:07 -0700 | [diff] [blame] | 1 | // CHECKSTYLE:OFF Generated code |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 2 | /* This file is auto-generated from NewDetailsFragment.java. DO NOT MODIFY. */ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2014 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 8 | * in compliance with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 13 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 14 | * or implied. See the License for the specific language governing permissions and limitations under |
| 15 | * the License. |
| 16 | */ |
| 17 | package com.example.android.leanback; |
| 18 | |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
susnata | 935b033 | 2016-07-27 16:15:10 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
| 24 | import android.os.Handler; |
Dake Gu | e1cde4d | 2016-12-21 09:57:21 -0800 | [diff] [blame] | 25 | import android.support.v17.leanback.app.DetailsSupportFragmentBackgroundController; |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 26 | import android.support.v17.leanback.media.MediaPlayerAdapter; |
Dake Gu | 95ac470 | 2016-11-29 11:22:23 -0800 | [diff] [blame] | 27 | import android.support.v17.leanback.media.MediaPlayerGlue; |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 28 | import android.support.v17.leanback.media.PlaybackGlue; |
| 29 | import android.support.v17.leanback.media.PlaybackTransportControlGlue; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 30 | import android.support.v17.leanback.widget.Action; |
| 31 | import android.support.v17.leanback.widget.ArrayObjectAdapter; |
| 32 | import android.support.v17.leanback.widget.ClassPresenterSelector; |
| 33 | import android.support.v17.leanback.widget.DetailsOverviewRow; |
| 34 | import android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter; |
| 35 | import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElementHelper; |
| 36 | import android.support.v17.leanback.widget.HeaderItem; |
| 37 | import android.support.v17.leanback.widget.ImageCardView; |
| 38 | import android.support.v17.leanback.widget.ListRow; |
| 39 | import android.support.v17.leanback.widget.ListRowPresenter; |
| 40 | import android.support.v17.leanback.widget.OnActionClickedListener; |
| 41 | import android.support.v17.leanback.widget.OnItemViewClickedListener; |
| 42 | import android.support.v17.leanback.widget.OnItemViewSelectedListener; |
| 43 | import android.support.v17.leanback.widget.Presenter; |
| 44 | import android.support.v17.leanback.widget.Row; |
| 45 | import android.support.v17.leanback.widget.RowPresenter; |
| 46 | import android.support.v17.leanback.widget.SparseArrayObjectAdapter; |
Dake Gu | 3778c4e | 2016-07-28 19:13:27 -0700 | [diff] [blame] | 47 | import android.support.v4.app.ActivityOptionsCompat; |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 48 | import android.support.v4.content.res.ResourcesCompat; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 49 | import android.util.Log; |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 50 | import android.view.LayoutInflater; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 51 | import android.view.View; |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 52 | import android.view.ViewGroup; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 53 | |
| 54 | public class NewDetailsSupportFragment extends android.support.v17.leanback.app.DetailsSupportFragment { |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 55 | |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 56 | private static final String TAG = "leanback.DetailsSupportFragment"; |
| 57 | private static final String ITEM = "item"; |
| 58 | |
| 59 | private static final int NUM_ROWS = 3; |
| 60 | private ArrayObjectAdapter mRowsAdapter; |
| 61 | private PhotoItem mPhotoItem; |
| 62 | final CardPresenter cardPresenter = new CardPresenter(); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 63 | |
| 64 | private static final int ACTION_PLAY = 1; |
| 65 | private static final int ACTION_RENT = 2; |
| 66 | private static final int ACTION_BUY = 3; |
| 67 | |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 68 | private boolean TEST_SHARED_ELEMENT_TRANSITION = true; |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 69 | private boolean TEST_BACKGROUND_PLAYER; |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 70 | |
| 71 | private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000; |
| 72 | private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000; |
| 73 | |
| 74 | private Action mActionPlay; |
| 75 | private Action mActionRent; |
| 76 | private Action mActionBuy; |
| 77 | |
| 78 | private FullWidthDetailsOverviewSharedElementHelper mHelper; |
Dake Gu | e1cde4d | 2016-12-21 09:57:21 -0800 | [diff] [blame] | 79 | private BackgroundHelper mBackgroundHelper; // used to download bitmap async. |
| 80 | private final DetailsSupportFragmentBackgroundController mDetailsBackground = |
| 81 | new DetailsSupportFragmentBackgroundController(this); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 82 | |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 83 | void setupTrailerVideo() { |
| 84 | MediaPlayerGlue mediaPlayerGlue = new MediaPlayerGlue(getActivity()); |
| 85 | mDetailsBackground.setupVideoPlayback(mediaPlayerGlue); |
| 86 | mediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ONE); |
| 87 | mediaPlayerGlue.setArtist("A Googler"); |
| 88 | mediaPlayerGlue.setTitle("Diving with Sharks Trailer"); |
| 89 | mediaPlayerGlue.setMediaSource(Uri.parse("android.resource://com.example.android.leanback/" |
| 90 | + "raw/browse")); |
| 91 | } |
| 92 | |
| 93 | void setupMainVideo() { |
| 94 | Context context = getActivity(); |
| 95 | MediaPlayerAdapter adapter = new MediaPlayerAdapter(context); |
| 96 | PlaybackTransportControlGlue<MediaPlayerAdapter> mediaPlayerGlue = |
| 97 | new PlaybackTransportControlGlue(context, adapter); |
| 98 | mDetailsBackground.setupVideoPlayback(mediaPlayerGlue); |
| 99 | mediaPlayerGlue.setSubtitle("A Googler"); |
| 100 | mediaPlayerGlue.setTitle("Diving with Sharks"); |
| 101 | mediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse( |
| 102 | "https://storage.googleapis.com/android-tv/Sample videos/April Fool's " |
| 103 | + "2013/Explore Treasure Mode with Google Maps.mp4")); |
| 104 | mediaPlayerGlue.addPlayerCallback(new PlaybackGlue.PlayerCallback() { |
| 105 | @Override |
| 106 | public void onPreparedStateChanged(PlaybackGlue glue) { |
| 107 | super.onPreparedStateChanged(glue); |
| 108 | PlaybackTransportControlGlue controlGlue = (PlaybackTransportControlGlue) glue; |
| 109 | controlGlue.setSeekProvider(new PlaybackSeekDiskDataProvider( |
| 110 | controlGlue.getDuration(), 1000, |
| 111 | "/sdcard/seek/frame_%04d.jpg")); |
| 112 | } |
| 113 | }); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void onCreate(Bundle savedInstanceState) { |
| 118 | Log.i(TAG, "onCreate"); |
| 119 | super.onCreate(savedInstanceState); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 120 | |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 121 | mBackgroundHelper = new BackgroundHelper(getActivity()); |
Dake Gu | e1cde4d | 2016-12-21 09:57:21 -0800 | [diff] [blame] | 122 | mDetailsBackground.enableParallax(); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 123 | if (TEST_BACKGROUND_PLAYER) { |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 124 | if (MovieData.sStatus == MovieData.STATUS_INIT) { |
| 125 | // not own/rented, play trailer |
| 126 | setupTrailerVideo(); |
| 127 | } else { |
| 128 | // bought or rented, play the main content |
| 129 | setupMainVideo(); |
| 130 | // hide details main ui |
| 131 | mDetailsBackground.switchToVideo(); |
| 132 | } |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 133 | } |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 134 | |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 135 | final Context context = getActivity(); |
| 136 | setBadgeDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_title, |
| 137 | context.getTheme())); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 138 | setTitle("Leanback Sample App"); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 139 | if (!TEST_BACKGROUND_PLAYER) { |
| 140 | setOnSearchClickedListener(new View.OnClickListener() { |
| 141 | @Override |
| 142 | public void onClick(View view) { |
| 143 | Intent intent = new Intent(getActivity(), SearchSupportActivity.class); |
| 144 | startActivity(intent); |
| 145 | } |
| 146 | }); |
| 147 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 148 | |
| 149 | mActionPlay = new Action(ACTION_PLAY, "Play"); |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 150 | mActionRent = new Action(ACTION_RENT, "Rent", "$3.99", ResourcesCompat.getDrawable( |
| 151 | context.getResources(), R.drawable.ic_action_a, context.getTheme())); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 152 | mActionBuy = new Action(ACTION_BUY, "Buy $9.99"); |
| 153 | |
| 154 | ClassPresenterSelector ps = new ClassPresenterSelector(); |
| 155 | FullWidthDetailsOverviewRowPresenter dorPresenter = |
| 156 | new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter()); |
| 157 | dorPresenter.setOnActionClickedListener(new OnActionClickedListener() { |
| 158 | @Override |
| 159 | public void onActionClicked(Action action) { |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 160 | final Context context = getActivity(); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 161 | DetailsOverviewRow dor = (DetailsOverviewRow) mRowsAdapter.get(0); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 162 | if (action.getId() == ACTION_BUY) { |
| 163 | // on the UI thread, we can modify actions adapter directly |
| 164 | SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter) |
| 165 | dor.getActionsAdapter(); |
| 166 | actions.set(ACTION_PLAY, mActionPlay); |
| 167 | actions.clear(ACTION_RENT); |
| 168 | actions.clear(ACTION_BUY); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 169 | boolean previousRented = MovieData.sStatus == MovieData.STATUS_RENTED; |
| 170 | MovieData.sStatus = MovieData.STATUS_OWN; |
| 171 | dor.setItem(getDisplayTitle(mPhotoItem.getTitle())); |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 172 | dor.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), |
| 173 | R.drawable.details_img_16x9, context.getTheme())); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 174 | if (TEST_BACKGROUND_PLAYER) { |
| 175 | if (!previousRented) { |
| 176 | setupMainVideo(); |
| 177 | mDetailsBackground.switchToVideo(); |
| 178 | } |
| 179 | } else { |
Dake Gu | 8b04395 | 2017-09-25 11:29:13 -0700 | [diff] [blame^] | 180 | Intent intent = new Intent(context, PlaybackSupportActivity.class); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 181 | getActivity().startActivity(intent); |
| 182 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 183 | } else if (action.getId() == ACTION_RENT) { |
| 184 | // on the UI thread, we can modify actions adapter directly |
| 185 | SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter) |
| 186 | dor.getActionsAdapter(); |
| 187 | actions.set(ACTION_PLAY, mActionPlay); |
| 188 | actions.clear(ACTION_RENT); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 189 | MovieData.sStatus = MovieData.STATUS_RENTED; |
| 190 | dor.setItem(getDisplayTitle(mPhotoItem.getTitle())); |
| 191 | if (TEST_BACKGROUND_PLAYER) { |
| 192 | setupMainVideo(); |
| 193 | mDetailsBackground.switchToVideo(); |
| 194 | } else { |
Dake Gu | 8b04395 | 2017-09-25 11:29:13 -0700 | [diff] [blame^] | 195 | Intent intent = new Intent(context, PlaybackSupportActivity.class); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 196 | getActivity().startActivity(intent); |
| 197 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 198 | } else if (action.getId() == ACTION_PLAY) { |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 199 | if (TEST_BACKGROUND_PLAYER) { |
| 200 | mDetailsBackground.switchToVideo(); |
| 201 | } else { |
Dake Gu | 8b04395 | 2017-09-25 11:29:13 -0700 | [diff] [blame^] | 202 | Intent intent = new Intent(context, PlaybackSupportActivity.class); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 203 | getActivity().startActivity(intent); |
| 204 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | }); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 208 | |
| 209 | ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter); |
| 210 | ps.addClassPresenter(ListRow.class, new ListRowPresenter()); |
| 211 | |
| 212 | mRowsAdapter = new ArrayObjectAdapter(ps); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 213 | updateAdapter(); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 214 | |
| 215 | setOnItemViewClickedListener(new OnItemViewClickedListener() { |
| 216 | @Override |
| 217 | public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 218 | RowPresenter.ViewHolder rowViewHolder, Row row) { |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 219 | Log.i(TAG, "onItemClicked: " + item + " row " + row); |
susnata | 4702556 | 2016-10-11 11:18:45 -0700 | [diff] [blame] | 220 | if (item instanceof PhotoItem) { |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 221 | Intent intent = new Intent(getActivity(), DetailsSupportActivity.class); |
| 222 | intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item); |
| 223 | |
| 224 | Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( |
| 225 | getActivity(), |
susnata | 4702556 | 2016-10-11 11:18:45 -0700 | [diff] [blame] | 226 | ((ImageCardView) itemViewHolder.view).getMainImageView(), |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 227 | DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle(); |
| 228 | getActivity().startActivity(intent, bundle); |
| 229 | } |
| 230 | } |
| 231 | }); |
| 232 | setOnItemViewSelectedListener(new OnItemViewSelectedListener() { |
| 233 | @Override |
| 234 | public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 235 | RowPresenter.ViewHolder rowViewHolder, Row row) { |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 236 | Log.i(TAG, "onItemSelected: " + item + " row " + row); |
| 237 | } |
| 238 | }); |
| 239 | |
| 240 | if (TEST_SHARED_ELEMENT_TRANSITION) { |
| 241 | mHelper = new FullWidthDetailsOverviewSharedElementHelper(); |
| 242 | mHelper.setSharedElementEnterTransition(getActivity(), |
| 243 | DetailsSupportActivity.SHARED_ELEMENT_NAME); |
| 244 | dorPresenter.setListener(mHelper); |
| 245 | dorPresenter.setParticipatingEntranceTransition(false); |
| 246 | } else { |
| 247 | dorPresenter.setParticipatingEntranceTransition(true); |
| 248 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 251 | @Override |
| 252 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 253 | Bundle savedInstanceState) { |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 254 | View view = super.onCreateView(inflater, container, savedInstanceState); |
Dake Gu | 181c884 | 2016-10-27 17:58:09 -0700 | [diff] [blame] | 255 | return view; |
| 256 | } |
| 257 | |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 258 | public void setBackgroundVideo(boolean backgroundVideo) { |
| 259 | TEST_BACKGROUND_PLAYER = backgroundVideo; |
| 260 | } |
| 261 | |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 262 | public void setItem(PhotoItem photoItem) { |
| 263 | mPhotoItem = photoItem; |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 264 | updateAdapter(); |
| 265 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 266 | |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 267 | static String getDisplayTitle(String title) { |
| 268 | switch (MovieData.sStatus) { |
| 269 | case MovieData.STATUS_OWN: |
| 270 | title = title + "(Owned)"; |
| 271 | break; |
| 272 | case MovieData.STATUS_RENTED: |
| 273 | title = title + "(Rented)"; |
| 274 | break; |
| 275 | case MovieData.STATUS_INIT: |
| 276 | default: |
| 277 | } |
| 278 | return title; |
| 279 | } |
| 280 | |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 281 | void updateAdapter() { |
| 282 | if (mRowsAdapter == null) { |
| 283 | return; |
| 284 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 285 | mRowsAdapter.clear(); |
| 286 | new Handler().postDelayed(new Runnable() { |
Aurimas Liutikas | e2104f4 | 2017-03-05 09:55:41 -0800 | [diff] [blame] | 287 | @Override |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 288 | public void run() { |
Chulwoo Lee | 3649f8f | 2017-03-09 08:58:06 -0800 | [diff] [blame] | 289 | final Context context = getActivity(); |
| 290 | if (context == null) { |
| 291 | return; |
| 292 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 293 | |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 294 | DetailsOverviewRow dor = new DetailsOverviewRow( |
| 295 | getDisplayTitle(mPhotoItem.getTitle())); |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 296 | dor.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), |
| 297 | mPhotoItem.getImageResourceId(), context.getTheme())); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 298 | SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter(); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 299 | switch (MovieData.sStatus) { |
| 300 | case MovieData.STATUS_INIT: |
| 301 | adapter.set(ACTION_RENT, mActionRent); |
| 302 | adapter.set(ACTION_BUY, mActionBuy); |
| 303 | break; |
| 304 | case MovieData.STATUS_OWN: |
| 305 | adapter.set(ACTION_PLAY, mActionPlay); |
| 306 | break; |
| 307 | case MovieData.STATUS_RENTED: |
| 308 | adapter.set(ACTION_PLAY, mActionPlay); |
| 309 | adapter.set(ACTION_BUY, mActionBuy); |
| 310 | break; |
| 311 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 312 | dor.setActionsAdapter(adapter); |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 313 | mRowsAdapter.add(0, dor); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 314 | setSelectedPosition(0, true); |
| 315 | if (TEST_SHARED_ELEMENT_TRANSITION) { |
| 316 | if (mHelper != null && !mHelper.getAutoStartSharedElementTransition()) { |
| 317 | mHelper.startPostponedEnterTransition(); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | }, TIME_TO_LOAD_OVERVIEW_ROW_MS); |
| 322 | |
| 323 | new Handler().postDelayed(new Runnable() { |
Aurimas Liutikas | e2104f4 | 2017-03-05 09:55:41 -0800 | [diff] [blame] | 324 | @Override |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 325 | public void run() { |
Chulwoo Lee | 3649f8f | 2017-03-09 08:58:06 -0800 | [diff] [blame] | 326 | if (getActivity() == null) { |
| 327 | return; |
| 328 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 329 | for (int i = 0; i < NUM_ROWS; ++i) { |
| 330 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); |
| 331 | listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
| 332 | listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2)); |
| 333 | listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3)); |
| 334 | listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4)); |
| 335 | HeaderItem header = new HeaderItem(i, "Row " + i); |
| 336 | mRowsAdapter.add(new ListRow(header, listRowAdapter)); |
| 337 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 338 | } |
| 339 | }, TIME_TO_LOAD_RELATED_ROWS_MS); |
| 340 | setAdapter(mRowsAdapter); |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public void onStart() { |
| 345 | super.onStart(); |
susnata | 4702556 | 2016-10-11 11:18:45 -0700 | [diff] [blame] | 346 | |
Dake Gu | 0908efd | 2016-11-04 12:51:53 -0700 | [diff] [blame] | 347 | // Restore background drawable in onStart(): |
Dake Gu | 0908efd | 2016-11-04 12:51:53 -0700 | [diff] [blame] | 348 | mBackgroundHelper.loadBitmap(R.drawable.spiderman, |
| 349 | new BackgroundHelper.BitmapLoadCallback() { |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 350 | @Override |
| 351 | public void onBitmapLoaded(Bitmap bitmap) { |
| 352 | mDetailsBackground.setCoverBitmap(bitmap); |
| 353 | } |
| 354 | }); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 355 | } |
| 356 | |
susnata | 935b033 | 2016-07-27 16:15:10 -0700 | [diff] [blame] | 357 | @Override |
susnata | 4702556 | 2016-10-11 11:18:45 -0700 | [diff] [blame] | 358 | public void onStop() { |
Dake Gu | e1cde4d | 2016-12-21 09:57:21 -0800 | [diff] [blame] | 359 | mDetailsBackground.setCoverBitmap(null); |
susnata | 4702556 | 2016-10-11 11:18:45 -0700 | [diff] [blame] | 360 | super.onStop(); |
susnata | 180dc40 | 2016-09-26 09:52:44 -0700 | [diff] [blame] | 361 | } |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 362 | } |