Skip to content

Commit 7e736a4

Browse files
committed
Add PlaybackOverlayFragment
Change-Id: If4c5b2f747885948e0bae422d9d30eec11c027b9
1 parent 850c44e commit 7e736a4

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

samples/SupportLeanbackDemos/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<activity android:name="DetailsActivity"
3030
android:exported="true" />
3131

32+
<activity android:name="PlaybackOverlayActivity"
33+
android:exported="true" />
34+
3235
<activity android:name="VerticalGridActivity"
3336
android:exported="true" />
3437

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2014 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:name="com.example.android.leanback.PlaybackOverlayFragment"
20+
android:id="@+id/playback_controls_fragment"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
/>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.example.android.leanback;
15+
16+
import android.app.Activity;
17+
import android.os.Bundle;
18+
19+
public class PlaybackOverlayActivity extends Activity
20+
{
21+
/** Called when the activity is first created. */
22+
@Override
23+
public void onCreate(Bundle savedInstanceState)
24+
{
25+
super.onCreate(savedInstanceState);
26+
setContentView(R.layout.playback_controls);
27+
}
28+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.example.android.leanback;
15+
16+
import android.content.Context;
17+
import android.content.res.Resources;
18+
import android.os.Bundle;
19+
import android.support.v17.leanback.widget.Action;
20+
import android.support.v17.leanback.widget.ArrayObjectAdapter;
21+
import android.support.v17.leanback.widget.ClassPresenterSelector;
22+
import android.support.v17.leanback.widget.PlaybackControlsRow;
23+
import android.support.v17.leanback.widget.PlaybackControlsRowPresenter;
24+
import android.support.v17.leanback.widget.HeaderItem;
25+
import android.support.v17.leanback.widget.ListRow;
26+
import android.support.v17.leanback.widget.ListRowPresenter;
27+
import android.support.v17.leanback.widget.OnActionClickedListener;
28+
import android.support.v17.leanback.widget.ControlButtonPresenterSelector;
29+
import android.util.Log;
30+
import android.widget.Toast;
31+
32+
public class PlaybackOverlayFragment extends android.support.v17.leanback.app.PlaybackOverlayFragment {
33+
private static final String TAG = "leanback.PlaybackControlsFragment";
34+
35+
private static final int NUM_ROWS = 3;
36+
private static final boolean SHOW_ITEM_DETAIL = true;
37+
private static final boolean HIDE_MORE_ACTIONS = false;
38+
39+
private ArrayObjectAdapter mRowsAdapter;
40+
private ArrayObjectAdapter mPrimaryActionsAdapter;
41+
private ArrayObjectAdapter mSecondaryActionsAdapter;
42+
private PlaybackControlsRow.PlayPauseAction mPlayPauseAction;
43+
private PlaybackControlsRow.RepeatAction mRepeatAction;
44+
private PlaybackControlsRow mPlaybackControlsRow;
45+
46+
@Override
47+
public void onCreate(Bundle savedInstanceState) {
48+
Log.i(TAG, "onCreate");
49+
super.onCreate(savedInstanceState);
50+
51+
setupRows();
52+
}
53+
54+
private static void notifyChanged(ArrayObjectAdapter adapter, Action action) {
55+
adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1);
56+
}
57+
58+
private void setupRows() {
59+
ClassPresenterSelector ps = new ClassPresenterSelector();
60+
61+
PlaybackControlsRowPresenter playbackControlsRowPresenter;
62+
if (SHOW_ITEM_DETAIL) {
63+
playbackControlsRowPresenter = new PlaybackControlsRowPresenter(
64+
new DetailsDescriptionPresenter());
65+
} else {
66+
playbackControlsRowPresenter = new PlaybackControlsRowPresenter();
67+
}
68+
playbackControlsRowPresenter.setOnActionClickedListener(new OnActionClickedListener() {
69+
public void onActionClicked(Action action) {
70+
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
71+
if (action.getId() == mPlayPauseAction.getId()) {
72+
mPlayPauseAction.toggle();
73+
notifyChanged(mPrimaryActionsAdapter, mPlayPauseAction);
74+
} else if (action.getId() == mRepeatAction.getId()) {
75+
mRepeatAction.next();
76+
notifyChanged(mSecondaryActionsAdapter, mRepeatAction);
77+
}
78+
}
79+
});
80+
playbackControlsRowPresenter.setSecondaryActionsHidden(HIDE_MORE_ACTIONS);
81+
82+
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
83+
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
84+
mRowsAdapter = new ArrayObjectAdapter(ps);
85+
86+
addPlaybackControlsRow();
87+
88+
setAdapter(mRowsAdapter);
89+
}
90+
91+
private void addPlaybackControlsRow() {
92+
Context context = getActivity();
93+
94+
ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector();
95+
mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
96+
mSecondaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
97+
98+
if (SHOW_ITEM_DETAIL) {
99+
mPlaybackControlsRow = new PlaybackControlsRow("Playback Controls Title");
100+
mPlaybackControlsRow.setImageDrawable(context.getResources().getDrawable(
101+
R.drawable.details_img));
102+
} else {
103+
mPlaybackControlsRow = new PlaybackControlsRow();
104+
}
105+
mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter);
106+
mPlaybackControlsRow.setSecondaryActionsAdapter(mSecondaryActionsAdapter);
107+
mRowsAdapter.add(mPlaybackControlsRow);
108+
109+
mPlayPauseAction = new PlaybackControlsRow.PlayPauseAction(context);
110+
mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
111+
112+
mPrimaryActionsAdapter.add(new PlaybackControlsRow.SkipPreviousAction(context));
113+
mPrimaryActionsAdapter.add(new PlaybackControlsRow.RewindAction(context));
114+
mPrimaryActionsAdapter.add(mPlayPauseAction);
115+
mPrimaryActionsAdapter.add(new PlaybackControlsRow.FastForwardAction(context));
116+
mPrimaryActionsAdapter.add(new PlaybackControlsRow.SkipNextAction(context));
117+
118+
mSecondaryActionsAdapter.add(new PlaybackControlsRow.ThumbsUpAction(context));
119+
mSecondaryActionsAdapter.add(mRepeatAction);
120+
mSecondaryActionsAdapter.add(new PlaybackControlsRow.ShuffleAction(context));
121+
mSecondaryActionsAdapter.add(new PlaybackControlsRow.ThumbsDownAction(context));
122+
123+
for (int i = 0; i < NUM_ROWS; ++i) {
124+
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new StringPresenter());
125+
listRowAdapter.add("Some related content");
126+
listRowAdapter.add("Other related content");
127+
HeaderItem header = new HeaderItem(i, "Row " + i, null);
128+
mRowsAdapter.add(new ListRow(header, listRowAdapter));
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)