From 7f94b8d6e6bd1dc4e2e8d95d1aeb1c3c00a13dd0 Mon Sep 17 00:00:00 2001 From: Tim Kilbourn Date: Thu, 27 Mar 2014 11:01:34 -0700 Subject: [PATCH] Add a details fragment to leanback samples. Change-Id: Ib958e02b464618107ab7233cb0e05bddc6ef56df --- .../SupportLeanbackDemos/AndroidManifest.xml | 3 + .../res/drawable/details_img.png | Bin 0 -> 2143 bytes .../res/drawable/ic_action_a.png | Bin 0 -> 720 bytes .../res/drawable/ic_title.png | Bin 0 -> 243 bytes .../res/layout/details.xml | 23 ++++++ .../android/leanback/BrowseFragment.java | 1 + .../android/leanback/DetailsActivity.java | 28 ++++++++ .../leanback/DetailsDescriptionPresenter.java | 32 +++++++++ .../android/leanback/DetailsFragment.java | 68 ++++++++++++++++++ 9 files changed, 155 insertions(+) create mode 100644 samples/SupportLeanbackDemos/res/drawable/details_img.png create mode 100644 samples/SupportLeanbackDemos/res/drawable/ic_action_a.png create mode 100644 samples/SupportLeanbackDemos/res/drawable/ic_title.png create mode 100644 samples/SupportLeanbackDemos/res/layout/details.xml create mode 100644 samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java create mode 100644 samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsDescriptionPresenter.java create mode 100644 samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java diff --git a/samples/SupportLeanbackDemos/AndroidManifest.xml b/samples/SupportLeanbackDemos/AndroidManifest.xml index 00cc1af20..42093f612 100644 --- a/samples/SupportLeanbackDemos/AndroidManifest.xml +++ b/samples/SupportLeanbackDemos/AndroidManifest.xml @@ -19,5 +19,8 @@ + + diff --git a/samples/SupportLeanbackDemos/res/drawable/details_img.png b/samples/SupportLeanbackDemos/res/drawable/details_img.png new file mode 100644 index 0000000000000000000000000000000000000000..7ea688b643236d6c50562a5d6ea871515d4a15c0 GIT binary patch literal 2143 zcmb`Jc{Cf?9>>E>TWjT6OD!+7>QNMplvtifE%9iHq6nt8gb1~7VMcW*<9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4_Xz^ zViLKG)T8hk=SJMK;BAO3?FTt^f7ku@VFI6tOQnu4dD4;haR6A~w}UspypsM0a}SYV literal 0 HcmV?d00001 diff --git a/samples/SupportLeanbackDemos/res/drawable/ic_action_a.png b/samples/SupportLeanbackDemos/res/drawable/ic_action_a.png new file mode 100644 index 0000000000000000000000000000000000000000..3d555efa5369d03df6f037edb115d041259f6de6 GIT binary patch literal 720 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX3?zBp#Z3TGEa{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBDDf)5C&U#ff91-n|NsB1 zsZBOBo88rQbo%tuFJ63MWo_c%XnFtsdr;8IsHnBuw%y*n`|kez_y7L=CnM7*C)cm4 zI_cT7&vkYCj~{>B({t?p{r8NF4fpQ7&&kBO=np%iH$#>#vxYb+WR3|Ni|iD%zQnvWbVM?ZANtSFgT0di2q&S6`Pbxpe8$ zODn6n>gto{%{$-GapcRFU(C#nPoI8DOWW+_wbaOH=Iz^WPn~+YX3e#0*Iw7u?9iZaEdVpkYY^oc6ae@$WTZHaySb- zB8!2v2N=7Z%(eqE9(uYshG?8Wd+}w^Ap;TC2Ld-+xL8w#Z)&ey5ny(ZRUjbX$=~_y z#VboZ59jYN_IQtYzXmq;! zo-|q8v@U-`O3EC@lt{kpeGjf5(p_-k-HR`i=AV`bUv+Ky%AY&`)jwyucWdtoU)f~l zv(DUS7oYH#cy<2D){CVsW`=LRt@u^4voXB=PPBfU9H&j*uCHHx6aKw>#y`u4FSE;_ z__I1&v9)f-=Svs$d4JyiT^z=@KJ$0~bP0l+XkK?m#!9 literal 0 HcmV?d00001 diff --git a/samples/SupportLeanbackDemos/res/drawable/ic_title.png b/samples/SupportLeanbackDemos/res/drawable/ic_title.png new file mode 100644 index 0000000000000000000000000000000000000000..1c62b2e18de5dfad14fce7115c509d15d89034bd GIT binary patch literal 243 zcmeAS@N?(olHy`uVBq!ia0vp^CLqkg1SGwrdiDS*#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPqv!t-0)M~!4+d!dWPZ!6Kh{JDh z8gd;_;9Xc4TYWkz + + + diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java index 81c8819e0..b1b3638e2 100644 --- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java @@ -32,6 +32,7 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm super.onCreate(savedInstanceState); Params p = new Params(); + p.setBadgeImage(getActivity().getResources().getDrawable(R.drawable.ic_title)); p.setTitle("Leanback Sample App"); p.setHeadersState(HEADERS_ENABLED); setBrowseParams(p); diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java new file mode 100644 index 000000000..082b134f5 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.example.android.leanback; + +import android.app.Activity; +import android.os.Bundle; + +public class DetailsActivity extends Activity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.details); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsDescriptionPresenter.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsDescriptionPresenter.java new file mode 100644 index 000000000..6d376f0aa --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsDescriptionPresenter.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.example.android.leanback; + +import android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter; +import android.support.v17.leanback.widget.DetailsOverviewRow; + +public class DetailsDescriptionPresenter extends AbstractDetailsDescriptionPresenter { + + @Override + protected void onBindDescription(ViewHolder vh, Object item) { + vh.getTitle().setText(item.toString()); + vh.getSubtitle().setText("2013 - 2014 Drama TV-14"); + vh.getBody().setText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " + + "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " + + "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse " + + "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " + + "proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java new file mode 100644 index 000000000..70a692bf9 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.example.android.leanback; + +import android.content.res.Resources; +import android.os.Bundle; +import android.support.v17.leanback.widget.Action; +import android.support.v17.leanback.widget.ArrayObjectAdapter; +import android.support.v17.leanback.widget.ClassPresenterSelector; +import android.support.v17.leanback.widget.DetailsOverviewRow; +import android.support.v17.leanback.widget.DetailsOverviewRowPresenter; +import android.support.v17.leanback.widget.HeaderItem; +import android.support.v17.leanback.widget.ListRow; +import android.support.v17.leanback.widget.ListRowPresenter; +import android.util.Log; + +public class DetailsFragment extends android.support.v17.leanback.app.DetailsFragment { + private static final String TAG = "leanback.BrowseFragment"; + + private static final int NUM_ROWS = 3; + private ArrayObjectAdapter mRowsAdapter; + + @Override + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "onCreate"); + super.onCreate(savedInstanceState); + + setupRows(); + } + + private void setupRows() { + ClassPresenterSelector ps = new ClassPresenterSelector(); + ps.addClassPresenter(DetailsOverviewRow.class, + new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter())); + ps.addClassPresenter(ListRow.class, + new ListRowPresenter()); + mRowsAdapter = new ArrayObjectAdapter(ps); + + Resources res = getActivity().getResources(); + DetailsOverviewRow dor = new DetailsOverviewRow("Details Overview"); + dor.setImageDrawable(res.getDrawable(R.drawable.details_img)); + dor.addAction(new Action(1, "Buy $9.99")); + dor.addAction(new Action(2, "Rent", "$3.99", res.getDrawable(R.drawable.ic_action_a))); + mRowsAdapter.add(dor); + + for (int i = 0; i < NUM_ROWS; ++i) { + ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new StringPresenter()); + listRowAdapter.add("Hello world"); + listRowAdapter.add("This is a test"); + HeaderItem header = new HeaderItem(i, "Row " + i, null); + mRowsAdapter.add(new ListRow(header, listRowAdapter)); + } + + setAdapter(mRowsAdapter); + } + +}