Generate support version of leanback fragment tests
Include all leanback support version of fragment except PlaybackOverlayFragment missing a support version of PlaybackControlHelper. Change-Id: Icb5c99e8677630e8541b22b009051dd3908d4f35
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/* This file is auto-generated from BrowseErrorActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
public class BrowseErrorSupportActivity extends FragmentActivity
|
||||
{
|
||||
private ErrorSupportFragment mErrorSupportFragment;
|
||||
private SpinnerSupportFragment mSpinnerSupportFragment;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.browse_support);
|
||||
|
||||
testError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
BackgroundHelper.attach(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
BackgroundHelper.release(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private void testError() {
|
||||
mErrorSupportFragment = new ErrorSupportFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mErrorSupportFragment).commit();
|
||||
|
||||
mSpinnerSupportFragment = new SpinnerSupportFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerSupportFragment).commit();
|
||||
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getSupportFragmentManager().isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction().remove(mSpinnerSupportFragment).commit();
|
||||
mErrorSupportFragment.setErrorContent(getResources());
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
static public class SpinnerSupportFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
ProgressBar progressBar = new ProgressBar(container.getContext());
|
||||
if (container instanceof FrameLayout) {
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100, Gravity.CENTER);
|
||||
progressBar.setLayoutParams(layoutParams);
|
||||
}
|
||||
return progressBar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/* This file is auto-generated from BrowseActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class BrowseSupportActivity extends FragmentActivity {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.browse_support);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
BackgroundHelper.attach(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
BackgroundHelper.release(this);
|
||||
super.onStop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/* This file is auto-generated from BrowseFragment.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v17.leanback.app.GuidedStepSupportFragment;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class BrowseSupportFragment extends android.support.v17.leanback.app.BrowseSupportFragment {
|
||||
private static final String TAG = "leanback.BrowseSupportFragment";
|
||||
|
||||
private static final boolean TEST_ENTRANCE_TRANSITION = true;
|
||||
private static final int NUM_ROWS = 10;
|
||||
// Row heights default to wrap content
|
||||
private static final boolean USE_FIXED_ROW_HEIGHT = false;
|
||||
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
|
||||
|
||||
// For good performance, it's important to use a single instance of
|
||||
// a card presenter for all rows using that presenter.
|
||||
final static CardPresenter sCardPresenter = new CardPresenter();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
|
||||
setTitle("Leanback Sample App");
|
||||
setHeadersState(HEADERS_ENABLED);
|
||||
|
||||
setOnSearchClickedListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
setupRows();
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener());
|
||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemSelected: " + item + " row " + row);
|
||||
|
||||
if (isShowingHeaders()) {
|
||||
mBackgroundHelper.setBackground(getActivity(), null);
|
||||
}
|
||||
else if (item instanceof PhotoItem) {
|
||||
mBackgroundHelper.setBackground(
|
||||
getActivity(), ((PhotoItem) item).getImageResourceId());
|
||||
}
|
||||
}
|
||||
});
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
// don't run entrance transition if fragment is restored.
|
||||
if (savedInstanceState == null) {
|
||||
prepareEntranceTransition();
|
||||
}
|
||||
}
|
||||
// simulates in a real world use case data being loaded two seconds later
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
loadData();
|
||||
startEntranceTransition();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
private void setupRows() {
|
||||
ListRowPresenter lrp = new ListRowPresenter();
|
||||
|
||||
if (USE_FIXED_ROW_HEIGHT) {
|
||||
lrp.setRowHeight(CardPresenter.getRowHeight(getActivity()));
|
||||
lrp.setExpandedRowHeight(CardPresenter.getExpandedRowHeight(getActivity()));
|
||||
}
|
||||
|
||||
mRowsAdapter = new ArrayObjectAdapter(lrp);
|
||||
|
||||
setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(sCardPresenter);
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", "Only a test", R.drawable.gallery_photo_2));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", "by Google", R.drawable.gallery_photo_3));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_5));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", "Open GuidedStepSupportFragment", R.drawable.gallery_photo_6));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", "open RowsSupportActivity", R.drawable.gallery_photo_7));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", "open BrowseSupportActivity", R.drawable.gallery_photo_8));
|
||||
HeaderItem header = new HeaderItem(i, "Row " + i);
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
|
||||
Intent intent;
|
||||
Bundle bundle;
|
||||
if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_6) {
|
||||
GuidedStepSupportFragment.add(getFragmentManager(),
|
||||
new GuidedStepSupportActivity.FirstStepFragment(),
|
||||
android.R.id.content);
|
||||
return;
|
||||
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
|
||||
intent = new Intent(getActivity(), BrowseSupportActivity.class);
|
||||
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
|
||||
.toBundle();
|
||||
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_7) {
|
||||
intent = new Intent(getActivity(), RowsSupportActivity.class);
|
||||
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
|
||||
.toBundle();
|
||||
} else {
|
||||
intent = new Intent(getActivity(), DetailsSupportActivity.class);
|
||||
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
|
||||
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView)itemViewHolder.view).getMainImageView(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
}
|
||||
getActivity().startActivity(intent, bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,9 @@ public class DetailsActivity extends Activity
|
||||
public static final String EXTRA_ITEM = "item";
|
||||
public static final String SHARED_ELEMENT_NAME = "hero";
|
||||
|
||||
public static boolean USE_LEGACY_PRESENTER = false;
|
||||
|
||||
private boolean useLegacyFragment() {
|
||||
return (USE_LEGACY_PRESENTER && !(this instanceof SearchDetailsActivity));
|
||||
return (DetailsPresenterSelectionActivity.USE_LEGACY_PRESENTER
|
||||
&& !(this instanceof SearchDetailsActivity));
|
||||
}
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
|
||||
@@ -40,6 +40,7 @@ public class DetailsPresenterSelectionActivity extends Activity {
|
||||
private static final long ACTION_ID_SWITCH_LEGACY_ON = 10000;
|
||||
private static final long ACTION_ID_SWITCH_LEGACY_OFF = 10001;
|
||||
|
||||
public static boolean USE_LEGACY_PRESENTER = false;
|
||||
|
||||
private static final String[] OPTION_NAMES = { "Use new details presenter", "Use legacy details presenter" };
|
||||
private static final String[] OPTION_DESCRIPTIONS = { "Use new details presenter",
|
||||
@@ -97,11 +98,11 @@ public class DetailsPresenterSelectionActivity extends Activity {
|
||||
for (int i = 0; i < OPTION_NAMES.length; i++) {
|
||||
boolean checked = false;
|
||||
if (OPTION_IDS[i] == ACTION_ID_SWITCH_LEGACY_ON) {
|
||||
if (DetailsActivity.USE_LEGACY_PRESENTER) {
|
||||
if (USE_LEGACY_PRESENTER) {
|
||||
checked = true;
|
||||
}
|
||||
} else if (OPTION_IDS[i] == ACTION_ID_SWITCH_LEGACY_OFF) {
|
||||
if (!DetailsActivity.USE_LEGACY_PRESENTER) {
|
||||
if (!USE_LEGACY_PRESENTER) {
|
||||
checked = true;
|
||||
}
|
||||
}
|
||||
@@ -113,9 +114,9 @@ public class DetailsPresenterSelectionActivity extends Activity {
|
||||
@Override
|
||||
public void onGuidedActionClicked(GuidedAction action) {
|
||||
if (action.getId() == ACTION_ID_SWITCH_LEGACY_ON) {
|
||||
DetailsActivity.USE_LEGACY_PRESENTER = action.isChecked();
|
||||
USE_LEGACY_PRESENTER = action.isChecked();
|
||||
} else if (action.getId() == ACTION_ID_SWITCH_LEGACY_OFF) {
|
||||
DetailsActivity.USE_LEGACY_PRESENTER = !action.isChecked();
|
||||
USE_LEGACY_PRESENTER = !action.isChecked();
|
||||
}
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* This file is auto-generated from DetailsActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class DetailsSupportActivity extends FragmentActivity
|
||||
{
|
||||
public static final String EXTRA_ITEM = "item";
|
||||
public static final String SHARED_ELEMENT_NAME = "hero";
|
||||
|
||||
private boolean useLegacyFragment() {
|
||||
return (DetailsPresenterSelectionActivity.USE_LEGACY_PRESENTER
|
||||
&& !(this instanceof SearchDetailsSupportActivity));
|
||||
}
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(useLegacyFragment() ? R.layout.legacy_details_support : R.layout.details_support);
|
||||
if (savedInstanceState == null) {
|
||||
// Only pass object to fragment when activity is first time created,
|
||||
// later object is modified and persisted with fragment state.
|
||||
if (useLegacyFragment()) {
|
||||
((DetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
|
||||
.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
|
||||
} else {
|
||||
((NewDetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
|
||||
.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
BackgroundHelper.attach(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
BackgroundHelper.release(this);
|
||||
super.onStop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/* This file is auto-generated from DetailsFragment.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
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.ImageCardView;
|
||||
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.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class DetailsSupportFragment extends android.support.v17.leanback.app.DetailsSupportFragment {
|
||||
private static final String TAG = "leanback.DetailsSupportFragment";
|
||||
private static final String ITEM = "item";
|
||||
|
||||
private static final int NUM_ROWS = 3;
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private PhotoItem mPhotoItem;
|
||||
final CardPresenter cardPresenter = new CardPresenter();
|
||||
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
|
||||
|
||||
private static final int ACTION_PLAY = 1;
|
||||
private static final int ACTION_RENT = 2;
|
||||
private static final int ACTION_BUY = 3;
|
||||
|
||||
private static final boolean TEST_SHARED_ELEMENT_TRANSITION = true;
|
||||
private static final boolean TEST_ENTRANCE_TRANSITION = true;
|
||||
|
||||
private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
|
||||
private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
|
||||
|
||||
private Action mActionPlay;
|
||||
private Action mActionRent;
|
||||
private Action mActionBuy;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
|
||||
setTitle("Leanback Sample App");
|
||||
setOnSearchClickedListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
mActionPlay = new Action(ACTION_PLAY, "Play");
|
||||
mActionRent = new Action(ACTION_RENT, "Rent", "$3.99",
|
||||
getResources().getDrawable(R.drawable.ic_action_a));
|
||||
mActionBuy = new Action(ACTION_BUY, "Buy $9.99");
|
||||
|
||||
ClassPresenterSelector ps = new ClassPresenterSelector();
|
||||
DetailsOverviewRowPresenter dorPresenter =
|
||||
new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
|
||||
dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
|
||||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
|
||||
DetailsOverviewRow dor = (DetailsOverviewRow) mRowsAdapter.get(0);
|
||||
if (action.getId() == ACTION_BUY) {
|
||||
// on the UI thread, we can modify actions adapter directly
|
||||
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
|
||||
dor.getActionsAdapter();
|
||||
actions.set(ACTION_PLAY, mActionPlay);
|
||||
actions.clear(ACTION_RENT);
|
||||
actions.clear(ACTION_BUY);
|
||||
dor.setItem(mPhotoItem.getTitle() + "(Owned)");
|
||||
dor.setImageDrawable(getResources().getDrawable(R.drawable.details_img_16x9));
|
||||
} else if (action.getId() == ACTION_RENT) {
|
||||
// on the UI thread, we can modify actions adapter directly
|
||||
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
|
||||
dor.getActionsAdapter();
|
||||
actions.set(ACTION_PLAY, mActionPlay);
|
||||
actions.clear(ACTION_RENT);
|
||||
dor.setItem(mPhotoItem.getTitle() + "(Rented)");
|
||||
} else if (action.getId() == ACTION_PLAY) {
|
||||
Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class);
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
|
||||
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
|
||||
mRowsAdapter = new ArrayObjectAdapter(ps);
|
||||
|
||||
PhotoItem item = (PhotoItem) (savedInstanceState != null ?
|
||||
savedInstanceState.getParcelable(ITEM) : null);
|
||||
if (item != null) {
|
||||
setItem(item);
|
||||
}
|
||||
|
||||
setOnItemViewClickedListener(new OnItemViewClickedListener() {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemClicked: " + item + " row " + row);
|
||||
if (item instanceof PhotoItem){
|
||||
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
|
||||
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
|
||||
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView)itemViewHolder.view).getMainImageView(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
getActivity().startActivity(intent, bundle);
|
||||
}
|
||||
}
|
||||
});
|
||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemSelected: " + item + " row " + row);
|
||||
}
|
||||
});
|
||||
|
||||
if (TEST_SHARED_ELEMENT_TRANSITION) {
|
||||
dorPresenter.setSharedElementEnterTransition(getActivity(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME);
|
||||
}
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
// don't run entrance transition if Activity is restored.
|
||||
if (savedInstanceState == null) {
|
||||
prepareEntranceTransition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(ITEM, mPhotoItem);
|
||||
}
|
||||
|
||||
public void setItem(PhotoItem photoItem) {
|
||||
mPhotoItem = photoItem;
|
||||
|
||||
mRowsAdapter.clear();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
Resources res = getActivity().getResources();
|
||||
DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle());
|
||||
dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId()));
|
||||
SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
|
||||
adapter.set(ACTION_RENT, mActionRent);
|
||||
adapter.set(ACTION_BUY, mActionBuy);
|
||||
dor.setActionsAdapter(adapter);
|
||||
mRowsAdapter.add(0, dor);
|
||||
setSelectedPosition(0, false);
|
||||
}
|
||||
}, TIME_TO_LOAD_OVERVIEW_ROW_MS);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
||||
HeaderItem header = new HeaderItem(i, "Row " + i);
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
startEntranceTransition();
|
||||
}
|
||||
}
|
||||
}, TIME_TO_LOAD_RELATED_ROWS_MS);
|
||||
setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (mPhotoItem != null) {
|
||||
mBackgroundHelper.setBackground(
|
||||
getActivity(), mPhotoItem.getImageResourceId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* This file is auto-generated from ErrorFragment.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
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.Row;
|
||||
import android.support.v17.leanback.widget.SearchOrbView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
public class ErrorSupportFragment extends android.support.v17.leanback.app.ErrorSupportFragment {
|
||||
private static final String TAG = "leanback.ErrorSupportFragment";
|
||||
private static final boolean TRANSLUCENT = true;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTitle("Leanback Sample App");
|
||||
}
|
||||
|
||||
void setErrorContent(Resources resources) {
|
||||
setImageDrawable(resources.getDrawable(R.drawable.lb_ic_sad_cloud));
|
||||
setMessage("An error occurred.");
|
||||
setDefaultBackground(TRANSLUCENT);
|
||||
|
||||
setButtonText("Dismiss");
|
||||
setButtonClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
Log.i(TAG, "button clicked");
|
||||
getFragmentManager().beginTransaction().remove(ErrorSupportFragment.this).commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* This file is auto-generated from GuidedStepActivity. DO NOT MODIFY. */
|
||||
/* This file is auto-generated from GuidedStepActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
|
||||
@@ -57,26 +57,40 @@ public class MainActivity extends Activity {
|
||||
@Override
|
||||
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
|
||||
addAction(actions, BrowseActivity.class, R.string.browse, R.string.browse_description);
|
||||
addAction(actions, BrowseSupportActivity.class, R.string.browse_support,
|
||||
R.string.browse_support_description);
|
||||
addAction(actions, SearchActivity.class, R.string.search, R.string.search_description);
|
||||
addAction(actions, SearchSupportActivity.class, R.string.search_support, R.string.search_support_description);
|
||||
addAction(actions, DetailsActivity.class, R.string.details, R.string.details_description);
|
||||
actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
|
||||
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
addAction(actions, DetailsSupportActivity.class, R.string.details_support, R.string.details_support_description);
|
||||
actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
|
||||
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
addAction(actions, SearchDetailsActivity.class, R.string.search_details,
|
||||
R.string.search_details_description);
|
||||
actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
|
||||
actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM,
|
||||
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
addAction(actions, SearchDetailsSupportActivity.class, R.string.search_details_support,
|
||||
R.string.search_details_support_description);
|
||||
actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsSupportActivity.EXTRA_ITEM,
|
||||
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
addAction(actions, PlaybackOverlayActivity.class, R.string.playback,
|
||||
R.string.playback_description);
|
||||
addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid,
|
||||
R.string.hgrid_description);
|
||||
addAction(actions, VerticalGridActivity.class, R.string.vgrid,
|
||||
R.string.vgrid_description);
|
||||
addAction(actions, VerticalGridSupportActivity.class, R.string.vgrid_support,
|
||||
R.string.vgrid_support_description);
|
||||
addAction(actions, GuidedStepActivity.class, R.string.guidedstep,
|
||||
R.string.guidedstep_description);
|
||||
addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport,
|
||||
R.string.guidedstepsupport_description);
|
||||
addAction(actions, BrowseErrorActivity.class, R.string.browseerror,
|
||||
R.string.browseerror_description);
|
||||
addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support,
|
||||
R.string.browseerror_support_description);
|
||||
addAction(actions, PlaybackOverlayActivity.class, R.string.playback,
|
||||
R.string.playback_description);
|
||||
addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid,
|
||||
R.string.hgrid_description);
|
||||
addAction(actions, DetailsPresenterSelectionActivity.class,
|
||||
R.string.detail_presenter_options,
|
||||
R.string.detail_presenter_options_description);
|
||||
|
||||
@@ -68,8 +68,7 @@ public class NewDetailsFragment extends android.support.v17.leanback.app.Details
|
||||
private FullWidthDetailsOverviewSharedElementHelper mHelper;
|
||||
|
||||
private void initializeTest() {
|
||||
Activity activity = getActivity();
|
||||
TEST_SHARED_ELEMENT_TRANSITION = null != activity.getWindow().getSharedElementEnterTransition();
|
||||
TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow().getSharedElementEnterTransition();
|
||||
TEST_OVERVIEW_ROW_ON_SECOND = !TEST_SHARED_ELEMENT_TRANSITION;
|
||||
TEST_ENTRANCE_TRANSITION = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
/* This file is auto-generated from NewDetailsFragment.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
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.FullWidthDetailsOverviewRowPresenter;
|
||||
import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElementHelper;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
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.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class NewDetailsSupportFragment extends android.support.v17.leanback.app.DetailsSupportFragment {
|
||||
private static final String TAG = "leanback.DetailsSupportFragment";
|
||||
private static final String ITEM = "item";
|
||||
|
||||
private static final int NUM_ROWS = 3;
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private PhotoItem mPhotoItem;
|
||||
final CardPresenter cardPresenter = new CardPresenter();
|
||||
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
|
||||
|
||||
private static final int ACTION_PLAY = 1;
|
||||
private static final int ACTION_RENT = 2;
|
||||
private static final int ACTION_BUY = 3;
|
||||
|
||||
private boolean TEST_OVERVIEW_ROW_ON_SECOND;
|
||||
private boolean TEST_SHARED_ELEMENT_TRANSITION;
|
||||
private boolean TEST_ENTRANCE_TRANSITION;
|
||||
|
||||
private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
|
||||
private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
|
||||
|
||||
private Action mActionPlay;
|
||||
private Action mActionRent;
|
||||
private Action mActionBuy;
|
||||
|
||||
private FullWidthDetailsOverviewSharedElementHelper mHelper;
|
||||
|
||||
private void initializeTest() {
|
||||
TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow().getSharedElementEnterTransition();
|
||||
TEST_OVERVIEW_ROW_ON_SECOND = !TEST_SHARED_ELEMENT_TRANSITION;
|
||||
TEST_ENTRANCE_TRANSITION = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
initializeTest();
|
||||
|
||||
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
|
||||
setTitle("Leanback Sample App");
|
||||
setOnSearchClickedListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
mActionPlay = new Action(ACTION_PLAY, "Play");
|
||||
mActionRent = new Action(ACTION_RENT, "Rent", "$3.99",
|
||||
getResources().getDrawable(R.drawable.ic_action_a));
|
||||
mActionBuy = new Action(ACTION_BUY, "Buy $9.99");
|
||||
|
||||
ClassPresenterSelector ps = new ClassPresenterSelector();
|
||||
FullWidthDetailsOverviewRowPresenter dorPresenter =
|
||||
new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
|
||||
dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
|
||||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
|
||||
int indexOfOverviewRow = TEST_OVERVIEW_ROW_ON_SECOND ? 1 : 0;
|
||||
DetailsOverviewRow dor = (DetailsOverviewRow) mRowsAdapter.get(indexOfOverviewRow);
|
||||
if (action.getId() == ACTION_BUY) {
|
||||
// on the UI thread, we can modify actions adapter directly
|
||||
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
|
||||
dor.getActionsAdapter();
|
||||
actions.set(ACTION_PLAY, mActionPlay);
|
||||
actions.clear(ACTION_RENT);
|
||||
actions.clear(ACTION_BUY);
|
||||
dor.setItem(mPhotoItem.getTitle() + "(Owned)");
|
||||
dor.setImageDrawable(getResources().getDrawable(R.drawable.details_img_16x9));
|
||||
} else if (action.getId() == ACTION_RENT) {
|
||||
// on the UI thread, we can modify actions adapter directly
|
||||
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
|
||||
dor.getActionsAdapter();
|
||||
actions.set(ACTION_PLAY, mActionPlay);
|
||||
actions.clear(ACTION_RENT);
|
||||
dor.setItem(mPhotoItem.getTitle() + "(Rented)");
|
||||
} else if (action.getId() == ACTION_PLAY) {
|
||||
Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class);
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (TEST_OVERVIEW_ROW_ON_SECOND) {
|
||||
dorPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_SMALL);
|
||||
}
|
||||
|
||||
ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
|
||||
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
|
||||
mRowsAdapter = new ArrayObjectAdapter(ps);
|
||||
|
||||
PhotoItem item = (PhotoItem) (savedInstanceState != null ?
|
||||
savedInstanceState.getParcelable(ITEM) : null);
|
||||
if (item != null) {
|
||||
setItem(item);
|
||||
}
|
||||
|
||||
setOnItemViewClickedListener(new OnItemViewClickedListener() {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemClicked: " + item + " row " + row);
|
||||
if (item instanceof PhotoItem){
|
||||
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
|
||||
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
|
||||
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView)itemViewHolder.view).getMainImageView(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
getActivity().startActivity(intent, bundle);
|
||||
}
|
||||
}
|
||||
});
|
||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemSelected: " + item + " row " + row);
|
||||
}
|
||||
});
|
||||
|
||||
if (TEST_SHARED_ELEMENT_TRANSITION) {
|
||||
mHelper = new FullWidthDetailsOverviewSharedElementHelper();
|
||||
mHelper.setSharedElementEnterTransition(getActivity(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME);
|
||||
dorPresenter.setListener(mHelper);
|
||||
dorPresenter.setParticipatingEntranceTransition(false);
|
||||
} else {
|
||||
dorPresenter.setParticipatingEntranceTransition(true);
|
||||
}
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
// don't run entrance transition if Activity is restored.
|
||||
if (savedInstanceState == null) {
|
||||
prepareEntranceTransition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(ITEM, mPhotoItem);
|
||||
}
|
||||
|
||||
public void setItem(PhotoItem photoItem) {
|
||||
mPhotoItem = photoItem;
|
||||
|
||||
mRowsAdapter.clear();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
if (TEST_OVERVIEW_ROW_ON_SECOND) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
||||
HeaderItem header = new HeaderItem(0, "Search Result");
|
||||
mRowsAdapter.add(0, new ListRow(header, listRowAdapter));
|
||||
}
|
||||
|
||||
Resources res = getActivity().getResources();
|
||||
DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle());
|
||||
dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId()));
|
||||
SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
|
||||
adapter.set(ACTION_RENT, mActionRent);
|
||||
adapter.set(ACTION_BUY, mActionBuy);
|
||||
dor.setActionsAdapter(adapter);
|
||||
int indexOfOverviewRow = TEST_OVERVIEW_ROW_ON_SECOND ? 1 : 0;
|
||||
mRowsAdapter.add(indexOfOverviewRow, dor);
|
||||
setSelectedPosition(0, true);
|
||||
if (TEST_SHARED_ELEMENT_TRANSITION) {
|
||||
if (mHelper != null && !mHelper.getAutoStartSharedElementTransition()) {
|
||||
mHelper.startPostponedEnterTransition();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TIME_TO_LOAD_OVERVIEW_ROW_MS);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
||||
HeaderItem header = new HeaderItem(i, "Row " + i);
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
startEntranceTransition();
|
||||
}
|
||||
}
|
||||
}, TIME_TO_LOAD_RELATED_ROWS_MS);
|
||||
setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (mPhotoItem != null) {
|
||||
mBackgroundHelper.setBackground(
|
||||
getActivity(), mPhotoItem.getImageResourceId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/* This file is auto-generated from RowsActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.R;
|
||||
import android.support.v17.leanback.widget.BrowseFrameLayout;
|
||||
import android.support.v17.leanback.widget.TitleHelper;
|
||||
import android.support.v17.leanback.widget.TitleView;
|
||||
import android.view.View;
|
||||
|
||||
public class RowsSupportActivity extends FragmentActivity
|
||||
{
|
||||
private RowsSupportFragment mRowsSupportFragment;
|
||||
private TitleHelper mTitleHelper;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.rows_support);
|
||||
|
||||
mRowsSupportFragment = (RowsSupportFragment) getSupportFragmentManager().findFragmentById(
|
||||
R.id.main_rows_fragment);
|
||||
|
||||
setupTitleFragment();
|
||||
}
|
||||
|
||||
private void setupTitleFragment() {
|
||||
TitleView titleView = (TitleView) findViewById(R.id.title);
|
||||
titleView.setTitle("RowsSupportFragment");
|
||||
titleView.setOnSearchClickedListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(RowsSupportActivity.this, SearchSupportActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
BrowseFrameLayout frameLayout = (BrowseFrameLayout) findViewById(R.id.rows_frame);
|
||||
mTitleHelper = new TitleHelper(frameLayout, titleView);
|
||||
frameLayout.setOnFocusSearchListener(mTitleHelper.getOnFocusSearchListener());
|
||||
mRowsSupportFragment.setTitleHelper(mTitleHelper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/* This file is auto-generated from RowsFragment.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.widget.TitleHelper;
|
||||
import android.support.v17.leanback.widget.TitleView;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v17.leanback.R;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class RowsSupportFragment extends android.support.v17.leanback.app.RowsSupportFragment {
|
||||
|
||||
private static final String TAG = "leanback.RowsSupportFragment";
|
||||
|
||||
private static final int NUM_ROWS = 10;
|
||||
// Row heights default to wrap content
|
||||
private static final boolean USE_FIXED_ROW_HEIGHT = false;
|
||||
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private TitleHelper mTitleHelper;
|
||||
|
||||
public void setTitleHelper(TitleHelper titleHelper) {
|
||||
mTitleHelper = titleHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setupRows();
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener());
|
||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemSelected: " + item + " row " + row);
|
||||
if (mTitleHelper != null) {
|
||||
mTitleHelper.showTitle(getAdapter() == null || getAdapter().size() == 0 ||
|
||||
getAdapter().get(0) == row);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupRows() {
|
||||
ListRowPresenter lrp = new ListRowPresenter();
|
||||
|
||||
if (USE_FIXED_ROW_HEIGHT) {
|
||||
lrp.setRowHeight(CardPresenter.getRowHeight(getActivity()));
|
||||
lrp.setExpandedRowHeight(CardPresenter.getExpandedRowHeight(getActivity()));
|
||||
}
|
||||
|
||||
mRowsAdapter = new ArrayObjectAdapter(lrp);
|
||||
|
||||
// For good performance, it's important to use a single instance of
|
||||
// a card presenter for all rows using that presenter.
|
||||
final CardPresenter cardPresenter = new CardPresenter();
|
||||
|
||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_5));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_6));
|
||||
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_7));
|
||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_8));
|
||||
HeaderItem header = new HeaderItem(i, "Row " + i);
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
|
||||
setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
|
||||
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
|
||||
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView)itemViewHolder.view).getMainImageView(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
getActivity().startActivity(intent, bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* This file is auto-generated from SearchDetailsActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Same implementation as DetailsSupportActivity for different entries in AndroidManifest.
|
||||
*/
|
||||
public class SearchDetailsSupportActivity extends DetailsSupportActivity
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/* This file is auto-generated from SearchActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.app.SearchSupportFragment;
|
||||
import android.support.v17.leanback.widget.SpeechRecognitionCallback;
|
||||
import android.util.Log;
|
||||
|
||||
public class SearchSupportActivity extends FragmentActivity
|
||||
{
|
||||
private static final String TAG = "SearchSupportActivity";
|
||||
private static boolean DEBUG = true;
|
||||
|
||||
/** If using internal speech recognizer, you must have RECORD_AUDIO permission */
|
||||
private static boolean USE_INTERNAL_SPEECH_RECOGNIZER = false;
|
||||
private static final int REQUEST_SPEECH = 1;
|
||||
|
||||
private SearchSupportFragment mFragment;
|
||||
private SpeechRecognitionCallback mSpeechRecognitionCallback;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.search_support);
|
||||
|
||||
mFragment = (SearchSupportFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment);
|
||||
|
||||
if (!USE_INTERNAL_SPEECH_RECOGNIZER) {
|
||||
mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
|
||||
@Override
|
||||
public void recognizeSpeech() {
|
||||
if (DEBUG) Log.v(TAG, "recognizeSpeech");
|
||||
startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
|
||||
}
|
||||
};
|
||||
mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (DEBUG) Log.v(TAG, "onActivityResult requestCode=" + requestCode +
|
||||
" resultCode=" + resultCode +
|
||||
" data=" + data);
|
||||
if (requestCode == REQUEST_SPEECH && resultCode == RESULT_OK) {
|
||||
mFragment.setSearchQuery(data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/* This file is auto-generated from SearchFragment.java. DO NOT MODIFY. */
|
||||
|
||||
package com.example.android.leanback;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
import android.support.v17.leanback.widget.ObjectAdapter;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class SearchSupportFragment extends android.support.v17.leanback.app.SearchSupportFragment
|
||||
implements android.support.v17.leanback.app.SearchSupportFragment.SearchResultProvider {
|
||||
private static final String TAG = "leanback.SearchSupportFragment";
|
||||
private static final int NUM_ROWS = 3;
|
||||
private static final int SEARCH_DELAY_MS = 1000;
|
||||
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private Handler mHandler = new Handler();
|
||||
private String mQuery;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
|
||||
|
||||
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
|
||||
setTitle("Leanback Sample App");
|
||||
setSearchResultProvider(this);
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectAdapter getResultsAdapter() {
|
||||
return mRowsAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newQuery) {
|
||||
Log.i(TAG, String.format("Search Query Text Change %s", newQuery));
|
||||
mRowsAdapter.clear();
|
||||
loadQuery(newQuery);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
Log.i(TAG, String.format("Search Query Text Submit %s", query));
|
||||
mRowsAdapter.clear();
|
||||
loadQuery(query);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadQuery(String query) {
|
||||
mQuery = query;
|
||||
mHandler.removeCallbacks(mDelayedLoad);
|
||||
if (!TextUtils.isEmpty(query) && !query.equals("nil")) {
|
||||
mHandler.postDelayed(mDelayedLoad, SEARCH_DELAY_MS);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRows() {
|
||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
|
||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
||||
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
|
||||
HeaderItem header = new HeaderItem(i, mQuery + " results row " + i);
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mDelayedLoad = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadRows();
|
||||
}
|
||||
};
|
||||
|
||||
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
|
||||
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
|
||||
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView)itemViewHolder.view).getMainImageView(),
|
||||
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
getActivity().startActivity(intent, bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* This file is auto-generated from VerticalGridActivity.java. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.v4.app.FragmentActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class VerticalGridSupportActivity extends FragmentActivity
|
||||
{
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.vertical_grid_support);
|
||||
// TODO: use BackgroundManager here
|
||||
getWindow().setBackgroundDrawableResource(R.drawable.bg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/* This file is auto-generated from VerticalGridFragment. DO NOT MODIFY. */
|
||||
|
||||
/*
|
||||
* 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.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v17.leanback.widget.VerticalGridPresenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class VerticalGridSupportFragment extends android.support.v17.leanback.app.VerticalGridSupportFragment {
|
||||
private static final String TAG = "leanback.VerticalGridSupportFragment";
|
||||
|
||||
private static final int NUM_COLUMNS = 3;
|
||||
private static final int NUM_ITEMS = 50;
|
||||
private static final int HEIGHT = 200;
|
||||
private static final boolean TEST_ENTRANCE_TRANSITION = true;
|
||||
|
||||
private static class Adapter extends ArrayObjectAdapter {
|
||||
public Adapter(StringPresenter presenter) {
|
||||
super(presenter);
|
||||
}
|
||||
public void callNotifyChanged() {
|
||||
super.notifyChanged();
|
||||
}
|
||||
}
|
||||
private Adapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
|
||||
setTitle("Leanback Vertical Grid Demo");
|
||||
|
||||
setupFragment();
|
||||
if (TEST_ENTRANCE_TRANSITION) {
|
||||
// don't run entrance transition if fragment is restored.
|
||||
if (savedInstanceState == null) {
|
||||
prepareEntranceTransition();
|
||||
}
|
||||
}
|
||||
// simulates in a real world use case data being loaded two seconds later
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
loadData();
|
||||
startEntranceTransition();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
for (int i = 0; i < NUM_ITEMS; i++) {
|
||||
mAdapter.add(Integer.toString(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void setupFragment() {
|
||||
VerticalGridPresenter gridPresenter = new VerticalGridPresenter();
|
||||
gridPresenter.setNumberOfColumns(NUM_COLUMNS);
|
||||
setGridPresenter(gridPresenter);
|
||||
|
||||
mAdapter = new Adapter(new StringPresenter());
|
||||
setAdapter(mAdapter);
|
||||
|
||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemSelected: " + item + " row " + row);
|
||||
}
|
||||
});
|
||||
|
||||
setOnItemViewClickedListener(new OnItemViewClickedListener() {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Log.i(TAG, "onItemClicked: " + item + " row " + row);
|
||||
mAdapter.callNotifyChanged();
|
||||
}
|
||||
});
|
||||
setOnSearchClickedListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user