1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.leanback; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.graphics.drawable.Drawable; 22 import android.os.Bundle; 23 import android.support.v17.leanback.app.GuidedStepFragment; 24 import android.support.v17.leanback.widget.GuidanceStylist.Guidance; 25 import android.support.v17.leanback.widget.GuidedAction; 26 import android.support.v4.app.ActivityOptionsCompat; 27 import android.view.LayoutInflater; 28 import android.view.View; 29 import android.view.ViewGroup; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 /** 35 * Activity that allows navigation among the demo activities. 36 */ 37 public class MainActivity extends Activity { 38 39 private GuidedStepFragment mGuidedStepFragment; 40 41 @Override 42 protected void onCreate(Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 45 mGuidedStepFragment = new StepFragment(); 46 GuidedStepFragment.addAsRoot(this, mGuidedStepFragment, android.R.id.content); 47 } 48 49 public static class StepFragment extends GuidedStepFragment { 50 51 @Override 52 public Guidance onCreateGuidance(Bundle savedInstanceState) { 53 String title = getString(R.string.main_title); 54 String breadcrumb = getString(R.string.main_breadcrumb); 55 String description = ""; 56 Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon); 57 return new Guidance(title, description, breadcrumb, icon); 58 } 59 60 @Override 61 public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) { 62 addAction(actions, BrowseActivity.class, R.string.browse, R.string.browse_description); 63 addAction(actions, BrowseSupportActivity.class, R.string.browse_support, 64 R.string.browse_support_description); 65 addAction(actions, SearchActivity.class, R.string.search, R.string.search_description); 66 addAction(actions, SearchSupportActivity.class, R.string.search_support, R.string.search_support_description); 67 addAction(actions, DetailsActivity.class, R.string.details, R.string.details_description); 68 actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM, 69 new PhotoItem("Hello world", R.drawable.gallery_photo_1)); 70 addAction(actions, DetailsSupportActivity.class, R.string.details_support, R.string.details_support_description); 71 actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM, 72 new PhotoItem("Hello world", R.drawable.gallery_photo_1)); 73 addAction(actions, SearchDetailsActivity.class, R.string.search_details, 74 R.string.search_details_description); 75 actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM, 76 new PhotoItem("Hello world", R.drawable.gallery_photo_1)); 77 addAction(actions, SearchDetailsSupportActivity.class, R.string.search_details_support, 78 R.string.search_details_support_description); 79 actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsSupportActivity.EXTRA_ITEM, 80 new PhotoItem("Hello world", R.drawable.gallery_photo_1)); 81 addAction(actions, VerticalGridActivity.class, R.string.vgrid, 82 R.string.vgrid_description); 83 addAction(actions, VerticalGridSupportActivity.class, R.string.vgrid_support, 84 R.string.vgrid_support_description); 85 addAction(actions, GuidedStepActivity.class, R.string.guidedstep, 86 R.string.guidedstep_description); 87 addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport, 88 R.string.guidedstepsupport_description); 89 addAction(actions, GuidedStepHalfScreenActivity.class, R.string.guidedstephalfscreen, 90 R.string.guidedstep_description); 91 addAction(actions, GuidedStepSupportHalfScreenActivity.class, 92 R.string.guidedstepsupporthalfscreen, 93 R.string.guidedstep_description); 94 addAction(actions, BrowseErrorActivity.class, R.string.browseerror, 95 R.string.browseerror_description); 96 addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support, 97 R.string.browseerror_support_description); 98 addAction(actions, PlaybackOverlayActivity.class, R.string.playback, 99 R.string.playback_description); 100 addAction(actions, PlaybackOverlaySupportActivity.class, R.string.playback_support, 101 R.string.playback_support_description); 102 addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid, 103 R.string.hgrid_description); 104 addAction(actions, DetailsPresenterSelectionActivity.class, 105 R.string.detail_presenter_options, 106 R.string.detail_presenter_options_description); 107 addAction(actions, OnboardingActivity.class, 108 R.string.onboarding, 109 R.string.onboarding_description); 110 addAction(actions, OnboardingSupportActivity.class, 111 R.string.onboarding_support, 112 R.string.onboarding_description); 113 } 114 115 private void addAction(List<GuidedAction> actions, Class cls, int titleRes, int descRes) { 116 actions.add(new GuidedAction.Builder() 117 .intent(new Intent(getActivity(), cls)) 118 .title(getString(titleRes)) 119 .description(getString(descRes)) 120 .build()); 121 } 122 123 @Override 124 public void onGuidedActionClicked(GuidedAction action) { 125 Intent intent = action.getIntent(); 126 if (intent != null) { 127 Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity()) 128 .toBundle(); 129 startActivity(intent, bundle); 130 } 131 } 132 133 } 134 } 135