Updating SupportLeanbackDemo to showcase GuidedStepFragment.

Included sample activities/fragments to showcase how to
use GuidedStepFragment in half screen mode.

Change-Id: I9eefe417ddf79b0dfe896a5cec25b7c7cd3a41e7
This commit is contained in:
susnata
2016-01-28 14:02:48 -08:00
parent 49342a6760
commit 15871fb0d4
11 changed files with 350 additions and 20 deletions

View File

@@ -16,7 +16,6 @@ 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.GuidedStepFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
@@ -28,6 +27,7 @@ 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.v4.app.ActivityOptionsCompat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -111,8 +111,8 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
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 GuidedStepFragment", R.drawable.gallery_photo_6));
listRowAdapter.add(new PhotoItem("GuidedStep (Slide left/right)", R.drawable.gallery_photo_5));
listRowAdapter.add(new PhotoItem("GuidedStep (Slide bottom up)", "Open GuidedStepFragment", R.drawable.gallery_photo_6));
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));
HeaderItem header = new HeaderItem(i, "Row " + i);
@@ -130,9 +130,13 @@ public class BrowseFragment extends android.support.v17.leanback.app.BrowseFragm
Bundle bundle;
if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_6) {
GuidedStepFragment.add(getFragmentManager(),
new GuidedStepActivity.FirstStepFragment(),
new GuidedStepHalfScreenActivity.FirstStepFragment(),
R.id.lb_guidedstep_host);
return;
} else if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_5) {
GuidedStepFragment.add(getFragmentManager(),
new GuidedStepActivity.FirstStepFragment(), R.id.lb_guidedstep_host);
return;
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
intent = new Intent(getActivity(), BrowseActivity.class);
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())

View File

@@ -18,7 +18,6 @@ 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;
@@ -30,6 +29,7 @@ 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.v4.app.ActivityOptionsCompat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -113,8 +113,8 @@ public class BrowseSupportFragment extends android.support.v17.leanback.app.Brow
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("GuidedStep (Slide left/right)", R.drawable.gallery_photo_5));
listRowAdapter.add(new PhotoItem("GuidedStep (Slide bottom up)", "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);
@@ -132,9 +132,13 @@ public class BrowseSupportFragment extends android.support.v17.leanback.app.Brow
Bundle bundle;
if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_6) {
GuidedStepSupportFragment.add(getFragmentManager(),
new GuidedStepSupportActivity.FirstStepFragment(),
new GuidedStepSupportHalfScreenActivity.FirstStepFragment(),
R.id.lb_guidedstep_host);
return;
} else if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_5) {
GuidedStepSupportFragment.add(getFragmentManager(),
new GuidedStepSupportActivity.FirstStepFragment(), R.id.lb_guidedstep_host);
return;
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
intent = new Intent(getActivity(), BrowseSupportActivity.class);
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())

View File

@@ -24,12 +24,12 @@ import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidedDatePickerAction;
import android.support.v17.leanback.widget.GuidedActionsStylist;
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidedActionsStylist;
import android.support.v17.leanback.widget.GuidedActionsStylist.ViewHolder;
import android.support.v17.leanback.widget.GuidedDatePickerAction;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
@@ -172,6 +172,7 @@ public class GuidedStepActivity extends Activity {
}
public static class FirstStepFragment extends GuidedStepFragment {
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_First;
@@ -208,7 +209,6 @@ public class GuidedStepActivity extends Activity {
finishGuidedStepFragments();
}
}
}
static ArrayList<String> sCards = new ArrayList<String>();

View File

@@ -0,0 +1,141 @@
/*
* 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.app.FragmentManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import android.util.Log;
import java.util.List;
/**
* Activity that showcases different aspects of GuidedStepFragments in half
* screen mode. This is achieved by setting the theme for this activity
* to {@code Theme.Example.Leanback.GuidedStep.Half}.
*/
public class GuidedStepHalfScreenActivity extends Activity {
private static final String TAG = "leanback.GuidedStepSupportHalfScreenActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.guided_step_activity);
GuidedStepFragment.addAsRoot(this, new FirstStepFragment(), R.id.lb_guidedstep_host);
}
public static class FirstStepFragment extends GuidedStepFragment {
@Override
public Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = getString(R.string.guidedstep_first_title);
String breadcrumb = getString(R.string.guidedstep_first_breadcrumb);
String description = getString(R.string.guidedstep_first_description);
Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
return new Guidance(title, description, breadcrumb, icon);
}
@Override
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
Context context = getActivity();
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CONTINUE)
.description("Just do it")
.build());
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Never mind")
.build());
}
public FirstStepFragment() {
setEntranceTransitionType(GuidedStepFragment.SLIDE_FROM_BOTTOM);
}
/**
* This fragment could be used by an activity using theme
* {@code Theme.Leanback.GuidedStep.Half} or something else (BrowseActivity).
* In order to provide a consistent half screen experience under
* both scenarios, we override onProvideTheme method.
*/
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_Half;
}
@Override
public void onGuidedActionClicked(GuidedAction action) {
FragmentManager fm = getFragmentManager();
if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
GuidedStepFragment.add(fm, new SecondStepFragment(), R.id.lb_guidedstep_host);
} else if (action.getId() == GuidedAction.ACTION_ID_CANCEL){
finishGuidedStepFragments();
}
}
}
public static class SecondStepFragment extends GuidedStepFragment {
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_Half;
}
@Override
public Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = getString(R.string.guidedstep_second_title);
String breadcrumb = getString(R.string.guidedstep_second_breadcrumb);
String description = getString(R.string.guidedstep_second_description);
Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
return new Guidance(title, description, breadcrumb, icon);
}
@Override
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
Context context = getActivity();
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_FINISH)
.description("Done")
.build());
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Never mind")
.build());
}
@Override
public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
actions.add(new GuidedAction.Builder(getActivity())
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Cancel")
.build());
}
@Override
public void onGuidedActionClicked(GuidedAction action) {
FragmentManager fm = getFragmentManager();
fm.popBackStack();
}
}
}

View File

@@ -26,12 +26,12 @@ import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepSupportFragment;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidedDatePickerAction;
import android.support.v17.leanback.widget.GuidedActionsStylist;
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidedActionsStylist;
import android.support.v17.leanback.widget.GuidedActionsStylist.ViewHolder;
import android.support.v17.leanback.widget.GuidedDatePickerAction;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
@@ -174,6 +174,7 @@ public class GuidedStepSupportActivity extends FragmentActivity {
}
public static class FirstStepFragment extends GuidedStepSupportFragment {
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_First;
@@ -210,7 +211,6 @@ public class GuidedStepSupportActivity extends FragmentActivity {
finishGuidedStepSupportFragments();
}
}
}
static ArrayList<String> sCards = new ArrayList<String>();

View File

@@ -0,0 +1,143 @@
/* This file is auto-generated from GuidedStepHalfScreenActivity.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.FragmentManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepSupportFragment;
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import android.util.Log;
import java.util.List;
/**
* Activity that showcases different aspects of GuidedStepSupportFragments in half
* screen mode. This is achieved by setting the theme for this activity
* to {@code Theme.Example.Leanback.GuidedStep.Half}.
*/
public class GuidedStepSupportHalfScreenActivity extends FragmentActivity {
private static final String TAG = "leanback.GuidedStepSupportHalfScreenActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.guided_step_activity);
GuidedStepSupportFragment.addAsRoot(this, new FirstStepFragment(), R.id.lb_guidedstep_host);
}
public static class FirstStepFragment extends GuidedStepSupportFragment {
@Override
public Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = getString(R.string.guidedstep_first_title);
String breadcrumb = getString(R.string.guidedstep_first_breadcrumb);
String description = getString(R.string.guidedstep_first_description);
Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
return new Guidance(title, description, breadcrumb, icon);
}
@Override
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
Context context = getActivity();
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CONTINUE)
.description("Just do it")
.build());
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Never mind")
.build());
}
public FirstStepFragment() {
setEntranceTransitionType(GuidedStepSupportFragment.SLIDE_FROM_BOTTOM);
}
/**
* This fragment could be used by an activity using theme
* {@code Theme.Leanback.GuidedStep.Half} or something else (BrowseActivity).
* In order to provide a consistent half screen experience under
* both scenarios, we override onProvideTheme method.
*/
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_Half;
}
@Override
public void onGuidedActionClicked(GuidedAction action) {
FragmentManager fm = getFragmentManager();
if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
GuidedStepSupportFragment.add(fm, new SecondStepFragment(), R.id.lb_guidedstep_host);
} else if (action.getId() == GuidedAction.ACTION_ID_CANCEL){
finishGuidedStepSupportFragments();
}
}
}
public static class SecondStepFragment extends GuidedStepSupportFragment {
@Override
public int onProvideTheme() {
return R.style.Theme_Example_Leanback_GuidedStep_Half;
}
@Override
public Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = getString(R.string.guidedstep_second_title);
String breadcrumb = getString(R.string.guidedstep_second_breadcrumb);
String description = getString(R.string.guidedstep_second_description);
Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
return new Guidance(title, description, breadcrumb, icon);
}
@Override
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
Context context = getActivity();
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_FINISH)
.description("Done")
.build());
actions.add(new GuidedAction.Builder(context)
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Never mind")
.build());
}
@Override
public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
actions.add(new GuidedAction.Builder(getActivity())
.clickAction(GuidedAction.ACTION_ID_CANCEL)
.description("Cancel")
.build());
}
@Override
public void onGuidedActionClicked(GuidedAction action) {
FragmentManager fm = getFragmentManager();
fm.popBackStack();
}
}
}

View File

@@ -20,13 +20,16 @@ import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v4.app.ActivityOptionsCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
/**
* Activity that allows navigation among the demo activities.
@@ -41,10 +44,10 @@ public class MainActivity extends Activity {
mGuidedStepFragment = new StepFragment();
GuidedStepFragment.addAsRoot(this, mGuidedStepFragment, android.R.id.content);
}
public static class StepFragment extends GuidedStepFragment {
@Override
public Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = getString(R.string.main_title);
@@ -83,6 +86,11 @@ public class MainActivity extends Activity {
R.string.guidedstep_description);
addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport,
R.string.guidedstepsupport_description);
addAction(actions, GuidedStepHalfScreenActivity.class, R.string.guidedstephalfscreen,
R.string.guidedstep_description);
addAction(actions, GuidedStepSupportHalfScreenActivity.class,
R.string.guidedstepsupporthalfscreen,
R.string.guidedstep_description);
addAction(actions, BrowseErrorActivity.class, R.string.browseerror,
R.string.browseerror_description);
addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support,