Revert "Revert "Add example of vertical grid transition and GuidedStepFragment""
This reverts commit c1e0465a05.
This commit is contained in:
@@ -45,12 +45,14 @@
|
|||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
<activity android:name="VerticalGridActivity"
|
<activity android:name="VerticalGridActivity"
|
||||||
|
android:theme="@style/Theme.Example.Leanback.VerticalGrid"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
<activity android:name="SearchActivity"
|
<activity android:name="SearchActivity"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
<activity android:name="BrowseErrorActivity"
|
<activity android:name="BrowseErrorActivity"
|
||||||
|
android:theme="@style/Theme.Example.Leanback.Browse"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
<activity android:name="HorizontalGridTestActivity"
|
<activity android:name="HorizontalGridTestActivity"
|
||||||
|
|||||||
@@ -27,4 +27,9 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- container for hosting GuidedStepFragment background -->
|
||||||
|
<FrameLayout android:id="@+id/lb_guidedstep_background"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
</style>
|
</style>
|
||||||
<style name="Theme.Example.Leanback.Details" parent="Theme.Leanback.Details">
|
<style name="Theme.Example.Leanback.Details" parent="Theme.Leanback.Details">
|
||||||
</style>
|
</style>
|
||||||
|
<style name="Theme.Example.Leanback.VerticalGrid" parent="Theme.Leanback.VerticalGrid">
|
||||||
|
</style>
|
||||||
<style name="Theme.Example.Leanback.Rows" parent="Theme.Leanback">
|
<style name="Theme.Example.Leanback.Rows" parent="Theme.Leanback">
|
||||||
<item name="browseTitleTextStyle">@style/Widget.Example.Leanback.Title.Text</item>
|
<item name="browseTitleTextStyle">@style/Widget.Example.Leanback.Title.Text</item>
|
||||||
<item name="rowsVerticalGridStyle">@style/Widget.Example.Leanback.Rows.VerticalGridView</item>
|
<item name="rowsVerticalGridStyle">@style/Widget.Example.Leanback.Rows.VerticalGridView</item>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v4.app.ActivityOptionsCompat;
|
import android.support.v4.app.ActivityOptionsCompat;
|
||||||
|
import android.support.v17.leanback.app.GuidedStepFragment;
|
||||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||||
import android.support.v17.leanback.widget.HeaderItem;
|
import android.support.v17.leanback.widget.HeaderItem;
|
||||||
import android.support.v17.leanback.widget.ImageCardView;
|
import android.support.v17.leanback.widget.ImageCardView;
|
||||||
@@ -42,6 +43,10 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
|
|||||||
private ArrayObjectAdapter mRowsAdapter;
|
private ArrayObjectAdapter mRowsAdapter;
|
||||||
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
Log.i(TAG, "onCreate");
|
Log.i(TAG, "onCreate");
|
||||||
@@ -77,17 +82,18 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (TEST_ENTRANCE_TRANSITION) {
|
if (TEST_ENTRANCE_TRANSITION) {
|
||||||
// don't run entrance transition if Activity is restored.
|
// don't run entrance transition if fragment is restored.
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
prepareEntranceTransition();
|
prepareEntranceTransition();
|
||||||
}
|
}
|
||||||
// simulate delay loading data
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
startEntranceTransition();
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
|
// 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() {
|
private void setupRows() {
|
||||||
@@ -100,25 +106,24 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
|
|||||||
|
|
||||||
mRowsAdapter = new ArrayObjectAdapter(lrp);
|
mRowsAdapter = new ArrayObjectAdapter(lrp);
|
||||||
|
|
||||||
// For good performance, it's important to use a single instance of
|
setAdapter(mRowsAdapter);
|
||||||
// a card presenter for all rows using that presenter.
|
}
|
||||||
final CardPresenter cardPresenter = new CardPresenter();
|
|
||||||
|
|
||||||
|
private void loadData() {
|
||||||
for (int i = 0; i < NUM_ROWS; ++i) {
|
for (int i = 0; i < NUM_ROWS; ++i) {
|
||||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(sCardPresenter);
|
||||||
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
|
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("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("Android TV", "by Google", R.drawable.gallery_photo_3));
|
||||||
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
|
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("Hello world", R.drawable.gallery_photo_5));
|
||||||
listRowAdapter.add(new PhotoItem("This is a test", "Only a test", R.drawable.gallery_photo_6));
|
listRowAdapter.add(new PhotoItem("This is a test", "Open GuidedStepFragment", R.drawable.gallery_photo_6));
|
||||||
listRowAdapter.add(new PhotoItem("Android TV", "open RowsActivity", R.drawable.gallery_photo_7));
|
listRowAdapter.add(new PhotoItem("Android TV", "open RowsActivity", R.drawable.gallery_photo_7));
|
||||||
listRowAdapter.add(new PhotoItem("Leanback", "open BrowseActivity", R.drawable.gallery_photo_8));
|
listRowAdapter.add(new PhotoItem("Leanback", "open BrowseActivity", R.drawable.gallery_photo_8));
|
||||||
HeaderItem header = new HeaderItem(i, "Row " + i);
|
HeaderItem header = new HeaderItem(i, "Row " + i);
|
||||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||||
}
|
}
|
||||||
|
|
||||||
setAdapter(mRowsAdapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||||
@@ -128,7 +133,12 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
Bundle bundle;
|
Bundle bundle;
|
||||||
if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
|
if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_6) {
|
||||||
|
GuidedStepFragment.add(getFragmentManager(),
|
||||||
|
new GuidedStepActivity.FirstStepFragment(),
|
||||||
|
android.R.id.content);
|
||||||
|
return;
|
||||||
|
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
|
||||||
intent = new Intent(getActivity(), BrowseActivity.class);
|
intent = new Intent(getActivity(), BrowseActivity.class);
|
||||||
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
|
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
|
||||||
.toBundle();
|
.toBundle();
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class DetailsPresenterSelectionActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
GuidedStepFragment.add(getFragmentManager(), new SetupFragment());
|
GuidedStepFragment.addAsRoot(this, new SetupFragment(), android.R.id.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addAction(List<GuidedAction> actions, long id, String title, String desc) {
|
private static void addAction(List<GuidedAction> actions, long id, String title, String desc) {
|
||||||
|
|||||||
@@ -58,12 +58,7 @@ public class GuidedStepActivity extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
Log.v(TAG, "onCreate");
|
Log.v(TAG, "onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
GuidedStepFragment.add(getFragmentManager(), new FirstStepFragment());
|
GuidedStepFragment.addAsRoot(this, new FirstStepFragment(), android.R.id.content);
|
||||||
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
|
||||||
@Override public void onGlobalLayout() {
|
|
||||||
//Log.v(TAG, "onGlobalLayout", new Exception());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,14 +134,14 @@ public class GuidedStepActivity extends Activity {
|
|||||||
public void onGuidedActionClicked(GuidedAction action) {
|
public void onGuidedActionClicked(GuidedAction action) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (action.getId() == CONTINUE) {
|
if (action.getId() == CONTINUE) {
|
||||||
GuidedStepFragment.add(fm, new SecondStepFragment());
|
GuidedStepFragment.add(fm, new SecondStepFragment(), android.R.id.content);
|
||||||
} else {
|
} else {
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SecondStepFragment extends GuidedStepFragment {
|
public static class SecondStepFragment extends GuidedStepFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Guidance onCreateGuidance(Bundle savedInstanceState) {
|
public Guidance onCreateGuidance(Bundle savedInstanceState) {
|
||||||
@@ -173,7 +168,7 @@ public class GuidedStepActivity extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ThirdStepFragment extends GuidedStepFragment {
|
public static class ThirdStepFragment extends GuidedStepFragment {
|
||||||
|
|
||||||
private int mSelectedOption = DEFAULT_OPTION;
|
private int mSelectedOption = DEFAULT_OPTION;
|
||||||
|
|
||||||
@@ -221,7 +216,11 @@ public class GuidedStepActivity extends Activity {
|
|||||||
public void onGuidedActionClicked(GuidedAction action) {
|
public void onGuidedActionClicked(GuidedAction action) {
|
||||||
if (action.getId() == CONTINUE) {
|
if (action.getId() == CONTINUE) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
GuidedStepFragment.add(fm, new FourthStepFragment(mSelectedOption));
|
FourthStepFragment f = new FourthStepFragment();
|
||||||
|
Bundle arguments = new Bundle();
|
||||||
|
arguments.putInt(FourthStepFragment.EXTRA_OPTION, mSelectedOption);
|
||||||
|
f.setArguments(arguments);
|
||||||
|
GuidedStepFragment.add(fm, f, android.R.id.content);
|
||||||
} else {
|
} else {
|
||||||
mSelectedOption = getSelectedActionPosition()-1;
|
mSelectedOption = getSelectedActionPosition()-1;
|
||||||
}
|
}
|
||||||
@@ -229,18 +228,23 @@ public class GuidedStepActivity extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FourthStepFragment extends GuidedStepFragment {
|
public static class FourthStepFragment extends GuidedStepFragment {
|
||||||
private final int mOption;
|
public static final String EXTRA_OPTION = "extra_option";
|
||||||
|
|
||||||
public FourthStepFragment(int option) {
|
public FourthStepFragment() {
|
||||||
mOption = option;
|
}
|
||||||
|
|
||||||
|
public int getOption() {
|
||||||
|
Bundle b = getArguments();
|
||||||
|
if (b == null) return 0;
|
||||||
|
return b.getInt(EXTRA_OPTION, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Guidance onCreateGuidance(Bundle savedInstanceState) {
|
public Guidance onCreateGuidance(Bundle savedInstanceState) {
|
||||||
String title = getString(R.string.guidedstep_fourth_title);
|
String title = getString(R.string.guidedstep_fourth_title);
|
||||||
String breadcrumb = getString(R.string.guidedstep_fourth_breadcrumb);
|
String breadcrumb = getString(R.string.guidedstep_fourth_breadcrumb);
|
||||||
String description = "You chose: " + OPTION_NAMES[mOption];
|
String description = "You chose: " + OPTION_NAMES[getOption()];
|
||||||
Drawable icon = getActivity().getDrawable(R.drawable.ic_main_icon);
|
Drawable icon = getActivity().getDrawable(R.drawable.ic_main_icon);
|
||||||
return new Guidance(title, description, breadcrumb, icon);
|
return new Guidance(title, description, breadcrumb, icon);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.ActivityOptionsCompat;
|
||||||
import android.support.v17.leanback.app.GuidedStepFragment;
|
import android.support.v17.leanback.app.GuidedStepFragment;
|
||||||
import android.support.v17.leanback.widget.GuidedAction;
|
import android.support.v17.leanback.widget.GuidedAction;
|
||||||
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
|
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
|
||||||
@@ -39,7 +40,8 @@ public class MainActivity extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
mGuidedStepFragment = new StepFragment();
|
mGuidedStepFragment = new StepFragment();
|
||||||
GuidedStepFragment.add(getFragmentManager(), mGuidedStepFragment);
|
GuidedStepFragment.addAsRoot(this, mGuidedStepFragment, android.R.id.content);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StepFragment extends GuidedStepFragment {
|
public static class StepFragment extends GuidedStepFragment {
|
||||||
@@ -90,7 +92,9 @@ public class MainActivity extends Activity {
|
|||||||
public void onGuidedActionClicked(GuidedAction action) {
|
public void onGuidedActionClicked(GuidedAction action) {
|
||||||
Intent intent = action.getIntent();
|
Intent intent = action.getIntent();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
startActivity(intent);
|
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
|
||||||
|
.toBundle();
|
||||||
|
startActivity(intent, bundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ package com.example.android.leanback;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||||
import android.support.v17.leanback.widget.Presenter;
|
import android.support.v17.leanback.widget.Presenter;
|
||||||
import android.support.v17.leanback.widget.RowPresenter;
|
import android.support.v17.leanback.widget.RowPresenter;
|
||||||
@@ -34,6 +35,7 @@ public class VerticalGridFragment extends android.support.v17.leanback.app.Verti
|
|||||||
private static final int NUM_COLUMNS = 3;
|
private static final int NUM_COLUMNS = 3;
|
||||||
private static final int NUM_ITEMS = 50;
|
private static final int NUM_ITEMS = 50;
|
||||||
private static final int HEIGHT = 200;
|
private static final int HEIGHT = 200;
|
||||||
|
private static final boolean TEST_ENTRANCE_TRANSITION = true;
|
||||||
|
|
||||||
private static class Adapter extends ArrayObjectAdapter {
|
private static class Adapter extends ArrayObjectAdapter {
|
||||||
public Adapter(StringPresenter presenter) {
|
public Adapter(StringPresenter presenter) {
|
||||||
@@ -54,6 +56,25 @@ public class VerticalGridFragment extends android.support.v17.leanback.app.Verti
|
|||||||
setTitle("Leanback Vertical Grid Demo");
|
setTitle("Leanback Vertical Grid Demo");
|
||||||
|
|
||||||
setupFragment();
|
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() {
|
private void setupFragment() {
|
||||||
@@ -62,9 +83,6 @@ public class VerticalGridFragment extends android.support.v17.leanback.app.Verti
|
|||||||
setGridPresenter(gridPresenter);
|
setGridPresenter(gridPresenter);
|
||||||
|
|
||||||
mAdapter = new Adapter(new StringPresenter());
|
mAdapter = new Adapter(new StringPresenter());
|
||||||
for (int i = 0; i < NUM_ITEMS; i++) {
|
|
||||||
mAdapter.add(Integer.toString(i));
|
|
||||||
}
|
|
||||||
setAdapter(mAdapter);
|
setAdapter(mAdapter);
|
||||||
|
|
||||||
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||||
|
|||||||
Reference in New Issue
Block a user