diff options
author | Craig Stout <cstout@google.com> | 2014-07-21 11:41:38 -0700 |
---|---|---|
committer | Craig Stout <cstout@google.com> | 2014-07-24 06:49:35 -0700 |
commit | 7e736a4df27c3612fc402a9332a5c074e0f76e6c (patch) | |
tree | 2b0a221b7cb486f7256764f15150d0922566b4d0 | |
parent | 850c44e0ec6af4aeb88488729b53405be2fe6c73 (diff) | |
download | android_development-7e736a4df27c3612fc402a9332a5c074e0f76e6c.tar.gz android_development-7e736a4df27c3612fc402a9332a5c074e0f76e6c.tar.bz2 android_development-7e736a4df27c3612fc402a9332a5c074e0f76e6c.zip |
Add PlaybackOverlayFragment
Change-Id: If4c5b2f747885948e0bae422d9d30eec11c027b9
4 files changed, 185 insertions, 0 deletions
diff --git a/samples/SupportLeanbackDemos/AndroidManifest.xml b/samples/SupportLeanbackDemos/AndroidManifest.xml index 3bf462b36..9dfeecbd4 100644 --- a/samples/SupportLeanbackDemos/AndroidManifest.xml +++ b/samples/SupportLeanbackDemos/AndroidManifest.xml @@ -29,6 +29,9 @@ <activity android:name="DetailsActivity" android:exported="true" /> + <activity android:name="PlaybackOverlayActivity" + android:exported="true" /> + <activity android:name="VerticalGridActivity" android:exported="true" /> diff --git a/samples/SupportLeanbackDemos/res/layout/playback_controls.xml b/samples/SupportLeanbackDemos/res/layout/playback_controls.xml new file mode 100644 index 000000000..357184cb4 --- /dev/null +++ b/samples/SupportLeanbackDemos/res/layout/playback_controls.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.PlaybackOverlayFragment" + android:id="@+id/playback_controls_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" +/> diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayActivity.java new file mode 100644 index 000000000..72ef1c482 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayActivity.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 PlaybackOverlayActivity extends Activity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.playback_controls); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java new file mode 100644 index 000000000..ddb4f48cb --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java @@ -0,0 +1,131 @@ +/* + * 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.Context; +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.PlaybackControlsRow; +import android.support.v17.leanback.widget.PlaybackControlsRowPresenter; +import android.support.v17.leanback.widget.HeaderItem; +import android.support.v17.leanback.widget.ListRow; +import android.support.v17.leanback.widget.ListRowPresenter; +import android.support.v17.leanback.widget.OnActionClickedListener; +import android.support.v17.leanback.widget.ControlButtonPresenterSelector; +import android.util.Log; +import android.widget.Toast; + +public class PlaybackOverlayFragment extends android.support.v17.leanback.app.PlaybackOverlayFragment { + private static final String TAG = "leanback.PlaybackControlsFragment"; + + private static final int NUM_ROWS = 3; + private static final boolean SHOW_ITEM_DETAIL = true; + private static final boolean HIDE_MORE_ACTIONS = false; + + private ArrayObjectAdapter mRowsAdapter; + private ArrayObjectAdapter mPrimaryActionsAdapter; + private ArrayObjectAdapter mSecondaryActionsAdapter; + private PlaybackControlsRow.PlayPauseAction mPlayPauseAction; + private PlaybackControlsRow.RepeatAction mRepeatAction; + private PlaybackControlsRow mPlaybackControlsRow; + + @Override + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "onCreate"); + super.onCreate(savedInstanceState); + + setupRows(); + } + + private static void notifyChanged(ArrayObjectAdapter adapter, Action action) { + adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1); + } + + private void setupRows() { + ClassPresenterSelector ps = new ClassPresenterSelector(); + + PlaybackControlsRowPresenter playbackControlsRowPresenter; + if (SHOW_ITEM_DETAIL) { + playbackControlsRowPresenter = new PlaybackControlsRowPresenter( + new DetailsDescriptionPresenter()); + } else { + playbackControlsRowPresenter = new PlaybackControlsRowPresenter(); + } + playbackControlsRowPresenter.setOnActionClickedListener(new OnActionClickedListener() { + public void onActionClicked(Action action) { + Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show(); + if (action.getId() == mPlayPauseAction.getId()) { + mPlayPauseAction.toggle(); + notifyChanged(mPrimaryActionsAdapter, mPlayPauseAction); + } else if (action.getId() == mRepeatAction.getId()) { + mRepeatAction.next(); + notifyChanged(mSecondaryActionsAdapter, mRepeatAction); + } + } + }); + playbackControlsRowPresenter.setSecondaryActionsHidden(HIDE_MORE_ACTIONS); + + ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter); + ps.addClassPresenter(ListRow.class, new ListRowPresenter()); + mRowsAdapter = new ArrayObjectAdapter(ps); + + addPlaybackControlsRow(); + + setAdapter(mRowsAdapter); + } + + private void addPlaybackControlsRow() { + Context context = getActivity(); + + ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); + mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); + mSecondaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); + + if (SHOW_ITEM_DETAIL) { + mPlaybackControlsRow = new PlaybackControlsRow("Playback Controls Title"); + mPlaybackControlsRow.setImageDrawable(context.getResources().getDrawable( + R.drawable.details_img)); + } else { + mPlaybackControlsRow = new PlaybackControlsRow(); + } + mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); + mPlaybackControlsRow.setSecondaryActionsAdapter(mSecondaryActionsAdapter); + mRowsAdapter.add(mPlaybackControlsRow); + + mPlayPauseAction = new PlaybackControlsRow.PlayPauseAction(context); + mRepeatAction = new PlaybackControlsRow.RepeatAction(context); + + mPrimaryActionsAdapter.add(new PlaybackControlsRow.SkipPreviousAction(context)); + mPrimaryActionsAdapter.add(new PlaybackControlsRow.RewindAction(context)); + mPrimaryActionsAdapter.add(mPlayPauseAction); + mPrimaryActionsAdapter.add(new PlaybackControlsRow.FastForwardAction(context)); + mPrimaryActionsAdapter.add(new PlaybackControlsRow.SkipNextAction(context)); + + mSecondaryActionsAdapter.add(new PlaybackControlsRow.ThumbsUpAction(context)); + mSecondaryActionsAdapter.add(mRepeatAction); + mSecondaryActionsAdapter.add(new PlaybackControlsRow.ShuffleAction(context)); + mSecondaryActionsAdapter.add(new PlaybackControlsRow.ThumbsDownAction(context)); + + for (int i = 0; i < NUM_ROWS; ++i) { + ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new StringPresenter()); + listRowAdapter.add("Some related content"); + listRowAdapter.add("Other related content"); + HeaderItem header = new HeaderItem(i, "Row " + i, null); + mRowsAdapter.add(new ListRow(header, listRowAdapter)); + } + } +} |