Add a details fragment to leanback samples.
Change-Id: Ib958e02b464618107ab7233cb0e05bddc6ef56df
This commit is contained in:
@@ -19,5 +19,8 @@
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="DetailsActivity"
|
||||
android:exported="true" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
BIN
samples/SupportLeanbackDemos/res/drawable/details_img.png
Normal file
BIN
samples/SupportLeanbackDemos/res/drawable/details_img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
samples/SupportLeanbackDemos/res/drawable/ic_action_a.png
Normal file
BIN
samples/SupportLeanbackDemos/res/drawable/ic_action_a.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 720 B |
BIN
samples/SupportLeanbackDemos/res/drawable/ic_title.png
Normal file
BIN
samples/SupportLeanbackDemos/res/drawable/ic_title.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 243 B |
23
samples/SupportLeanbackDemos/res/layout/details.xml
Normal file
23
samples/SupportLeanbackDemos/res/layout/details.xml
Normal file
@@ -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"
|
||||
/>
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user