diff options
author | Tim Kilbourn <tkilbourn@google.com> | 2014-03-27 11:01:34 -0700 |
---|---|---|
committer | Tim Kilbourn <tkilbourn@google.com> | 2014-04-04 12:46:19 -0700 |
commit | 7f94b8d6e6bd1dc4e2e8d95d1aeb1c3c00a13dd0 (patch) | |
tree | 34daaa1674360c1fada49631e75abedc8f185cef | |
parent | f3ff0296c96a81a6ebb053bf39f7484d03dc4678 (diff) | |
download | android_development-7f94b8d6e6bd1dc4e2e8d95d1aeb1c3c00a13dd0.tar.gz android_development-7f94b8d6e6bd1dc4e2e8d95d1aeb1c3c00a13dd0.tar.bz2 android_development-7f94b8d6e6bd1dc4e2e8d95d1aeb1c3c00a13dd0.zip |
Add a details fragment to leanback samples.
Change-Id: Ib958e02b464618107ab7233cb0e05bddc6ef56df
-rw-r--r-- | samples/SupportLeanbackDemos/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | samples/SupportLeanbackDemos/res/drawable/details_img.png | bin | 0 -> 2143 bytes | |||
-rw-r--r-- | samples/SupportLeanbackDemos/res/drawable/ic_action_a.png | bin | 0 -> 720 bytes | |||
-rw-r--r-- | samples/SupportLeanbackDemos/res/drawable/ic_title.png | bin | 0 -> 243 bytes | |||
-rw-r--r-- | samples/SupportLeanbackDemos/res/layout/details.xml | 23 | ||||
-rw-r--r-- | samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java | 1 | ||||
-rw-r--r-- | samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java | 28 | ||||
-rw-r--r-- | samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsDescriptionPresenter.java | 32 | ||||
-rw-r--r-- | samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java | 68 |
9 files changed, 155 insertions, 0 deletions
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 @@ <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> </activity> + + <activity android:name="DetailsActivity" + android:exported="true" /> </application> </manifest> diff --git a/samples/SupportLeanbackDemos/res/drawable/details_img.png b/samples/SupportLeanbackDemos/res/drawable/details_img.png Binary files differnew file mode 100644 index 000000000..7ea688b64 --- /dev/null +++ b/samples/SupportLeanbackDemos/res/drawable/details_img.png diff --git a/samples/SupportLeanbackDemos/res/drawable/ic_action_a.png b/samples/SupportLeanbackDemos/res/drawable/ic_action_a.png Binary files differnew file mode 100644 index 000000000..3d555efa5 --- /dev/null +++ b/samples/SupportLeanbackDemos/res/drawable/ic_action_a.png diff --git a/samples/SupportLeanbackDemos/res/drawable/ic_title.png b/samples/SupportLeanbackDemos/res/drawable/ic_title.png Binary files differnew file mode 100644 index 000000000..1c62b2e18 --- /dev/null +++ b/samples/SupportLeanbackDemos/res/drawable/ic_title.png diff --git a/samples/SupportLeanbackDemos/res/layout/details.xml b/samples/SupportLeanbackDemos/res/layout/details.xml new file mode 100644 index 000000000..4af4e6a1e --- /dev/null +++ b/samples/SupportLeanbackDemos/res/layout/details.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> + +<fragment xmlns:android="http://schemas.android.com/apk/res/android" + android:name="com.example.android.leanback.DetailsFragment" + android:id="@+id/details_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" +/> 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); + } + +} |