blob: 15a07697c7cc0936a95fde3d74a9fa4bf8fd1f1c [file] [log] [blame]
Tim Kilbourn2223b082014-03-21 07:12:33 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
Kris Giesing6f0d24a2015-02-16 15:10:05 -08004 * 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
Tim Kilbourn2223b082014-03-21 07:12:33 -07007 *
Kris Giesing6f0d24a2015-02-16 15:10:05 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Tim Kilbourn2223b082014-03-21 07:12:33 -07009 *
Kris Giesing6f0d24a2015-02-16 15:10:05 -080010 * 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.
Tim Kilbourn2223b082014-03-21 07:12:33 -070015 */
Kris Giesing6f0d24a2015-02-16 15:10:05 -080016
Tim Kilbourn2223b082014-03-21 07:12:33 -070017package com.example.android.leanback;
18
19import android.app.Activity;
Dake Gub7087e02016-09-22 14:34:56 -070020import android.content.Context;
Kris Giesing6f0d24a2015-02-16 15:10:05 -080021import android.content.Intent;
22import android.graphics.drawable.Drawable;
Tim Kilbourn2223b082014-03-21 07:12:33 -070023import android.os.Bundle;
Kris Giesing6f0d24a2015-02-16 15:10:05 -080024import android.support.v17.leanback.app.GuidedStepFragment;
Kris Giesing6f0d24a2015-02-16 15:10:05 -080025import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
susnata20767a12016-01-28 14:02:48 -080026import android.support.v17.leanback.widget.GuidedAction;
27import android.support.v4.app.ActivityOptionsCompat;
Dake Gub7087e02016-09-22 14:34:56 -070028import android.support.v4.content.res.ResourcesCompat;
Dake Guef05d542016-12-07 11:04:42 -080029
susnata20767a12016-01-28 14:02:48 -080030import java.util.List;
Kris Giesing6f0d24a2015-02-16 15:10:05 -080031
32/**
33 * Activity that allows navigation among the demo activities.
34 */
35public class MainActivity extends Activity {
36
Tim Kilbourn2223b082014-03-21 07:12:33 -070037 @Override
Kris Giesing6f0d24a2015-02-16 15:10:05 -080038 protected void onCreate(Bundle savedInstanceState) {
Tim Kilbourn2223b082014-03-21 07:12:33 -070039 super.onCreate(savedInstanceState);
Kris Giesing6f0d24a2015-02-16 15:10:05 -080040
Dake Gub7087e02016-09-22 14:34:56 -070041 GuidedStepFragment.addAsRoot(this, new StepFragment(), android.R.id.content);
Tim Kilbourn2223b082014-03-21 07:12:33 -070042 }
Kris Giesing6f0d24a2015-02-16 15:10:05 -080043
Dake Gu28526e92015-06-24 15:05:20 -070044 public static class StepFragment extends GuidedStepFragment {
susnata20767a12016-01-28 14:02:48 -080045
Kris Giesing6f0d24a2015-02-16 15:10:05 -080046 @Override
47 public Guidance onCreateGuidance(Bundle savedInstanceState) {
48 String title = getString(R.string.main_title);
49 String breadcrumb = getString(R.string.main_breadcrumb);
50 String description = "";
Dake Gub7087e02016-09-22 14:34:56 -070051 final Context context = getActivity();
52 Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
53 R.drawable.ic_main_icon, context.getTheme());
Kris Giesing6f0d24a2015-02-16 15:10:05 -080054 return new Guidance(title, description, breadcrumb, icon);
55 }
56
57 @Override
58 public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
59 addAction(actions, BrowseActivity.class, R.string.browse, R.string.browse_description);
Dake Gu71e7e672015-09-29 15:32:42 -070060 addAction(actions, BrowseSupportActivity.class, R.string.browse_support,
61 R.string.browse_support_description);
Kris Giesing6f0d24a2015-02-16 15:10:05 -080062 addAction(actions, SearchActivity.class, R.string.search, R.string.search_description);
jingjiangli61218012017-07-10 06:53:25 -070063 addAction(actions, SearchSupportActivity.class, R.string.search_support,
64 R.string.search_support_description);
Dake Gu5bcc0582016-12-28 16:18:49 -080065
66 addAction(actions, DetailsActivity.class, R.string.details,
67 R.string.details_description);
jingjiangli61218012017-07-10 06:53:25 -070068 actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
Kris Giesing6f0d24a2015-02-16 15:10:05 -080069 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
Dake Gu5bcc0582016-12-28 16:18:49 -080070 addAction(actions, DetailsSupportActivity.class, R.string.details_support,
71 R.string.details_support_description);
jingjiangli61218012017-07-10 06:53:25 -070072 actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
Dake Gu71e7e672015-09-29 15:32:42 -070073 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
Dake Gu5bcc0582016-12-28 16:18:49 -080074
75 addAction(actions, DetailsVideoActivity.class, R.string.details_video,
76 R.string.details_video_description);
jingjiangli61218012017-07-10 06:53:25 -070077 actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
Dake Gu5bcc0582016-12-28 16:18:49 -080078 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
79 addAction(actions, DetailsVideoSupportActivity.class, R.string.details_video_support,
80 R.string.details_video_support_description);
jingjiangli61218012017-07-10 06:53:25 -070081 actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
Dake Gu5bcc0582016-12-28 16:18:49 -080082 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
83
84 addAction(actions, DetailsCustomTitleActivity.class, R.string.details_custom_title,
85 R.string.details_custom_title_description);
jingjiangli61218012017-07-10 06:53:25 -070086 actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
Dake Gu5bcc0582016-12-28 16:18:49 -080087 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
88 addAction(actions, DetailsCustomTitleSupportActivity.class,
89 R.string.details_custom_title_support,
90 R.string.details_custom_title_support_description);
jingjiangli61218012017-07-10 06:53:25 -070091 actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
Dake Gu5bcc0582016-12-28 16:18:49 -080092 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
93
Dake Gu58d19582015-04-29 11:46:46 -070094 addAction(actions, SearchDetailsActivity.class, R.string.search_details,
95 R.string.search_details_description);
jingjiangli61218012017-07-10 06:53:25 -070096 actions.get(actions.size() - 1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM,
Dake Gu58d19582015-04-29 11:46:46 -070097 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
Dake Gu71e7e672015-09-29 15:32:42 -070098 addAction(actions, SearchDetailsSupportActivity.class, R.string.search_details_support,
99 R.string.search_details_support_description);
jingjiangli61218012017-07-10 06:53:25 -0700100 actions.get(actions.size() - 1).getIntent().putExtra(
101 SearchDetailsSupportActivity.EXTRA_ITEM,
Dake Gu71e7e672015-09-29 15:32:42 -0700102 new PhotoItem("Hello world", R.drawable.gallery_photo_1));
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800103 addAction(actions, VerticalGridActivity.class, R.string.vgrid,
104 R.string.vgrid_description);
Dake Gu71e7e672015-09-29 15:32:42 -0700105 addAction(actions, VerticalGridSupportActivity.class, R.string.vgrid_support,
106 R.string.vgrid_support_description);
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800107 addAction(actions, GuidedStepActivity.class, R.string.guidedstep,
108 R.string.guidedstep_description);
Dake Guab1d3dc2015-09-04 15:25:49 -0700109 addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport,
110 R.string.guidedstepsupport_description);
susnata20767a12016-01-28 14:02:48 -0800111 addAction(actions, GuidedStepHalfScreenActivity.class, R.string.guidedstephalfscreen,
112 R.string.guidedstep_description);
113 addAction(actions, GuidedStepSupportHalfScreenActivity.class,
jingjiangli61218012017-07-10 06:53:25 -0700114 R.string.guidedstepsupporthalfscreen,
115 R.string.guidedstep_description);
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800116 addAction(actions, BrowseErrorActivity.class, R.string.browseerror,
117 R.string.browseerror_description);
Dake Gu71e7e672015-09-29 15:32:42 -0700118 addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support,
119 R.string.browseerror_support_description);
Dake Gu3bcad882017-03-20 16:40:45 -0700120 addAction(actions, PlaybackTransportControlActivity.class, R.string.playback,
Dake Gu71e7e672015-09-29 15:32:42 -0700121 R.string.playback_description);
Dake Gu3bcad882017-03-20 16:40:45 -0700122 addAction(actions, PlaybackTransportControlSupportActivity.class,
123 R.string.playback_support, R.string.playback_support_description);
susnataaa494392016-10-31 16:28:19 -0700124 addAction(actions, VideoActivity.class, R.string.video_playback,
125 R.string.playback_description);
126 addAction(actions, VideoSupportActivity.class, R.string.video_playback_support,
127 R.string.playback_description);
Dake Gu71e7e672015-09-29 15:32:42 -0700128 addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid,
129 R.string.hgrid_description);
Dake Gu58d19582015-04-29 11:46:46 -0700130 addAction(actions, DetailsPresenterSelectionActivity.class,
131 R.string.detail_presenter_options,
132 R.string.detail_presenter_options_description);
Keyvan Amiriad3b4692016-10-04 15:44:03 -0700133 addAction(actions, SettingsActivity.class,
134 R.string.settings,
135 R.string.settings_description);
Chulwoo Leee3ef6102016-03-22 18:18:14 -0700136 addAction(actions, OnboardingActivity.class,
137 R.string.onboarding,
138 R.string.onboarding_description);
139 addAction(actions, OnboardingSupportActivity.class,
140 R.string.onboarding_support,
141 R.string.onboarding_description);
jingjiangli61218012017-07-10 06:53:25 -0700142 addAction(actions, VideoActivityWithDetailedCard.class,
143 R.string.video_play_with_detail_card,
144 R.string.video_play_with_detail_card_description);
jingjianglidbe6c872017-07-23 16:23:46 -0700145
146 addAction(actions, MusicExampleActivity.class,
147 R.string.music,
148 R.string.music_description);
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800149 }
150
151 private void addAction(List<GuidedAction> actions, Class cls, int titleRes, int descRes) {
Dake Gub7087e02016-09-22 14:34:56 -0700152 actions.add(new GuidedAction.Builder(getActivity())
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800153 .intent(new Intent(getActivity(), cls))
154 .title(getString(titleRes))
155 .description(getString(descRes))
156 .build());
157 }
158
159 @Override
160 public void onGuidedActionClicked(GuidedAction action) {
161 Intent intent = action.getIntent();
162 if (intent != null) {
Dake Gu067d9b92015-08-18 13:55:07 -0700163 Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
164 .toBundle();
165 startActivity(intent, bundle);
Kris Giesing6f0d24a2015-02-16 15:10:05 -0800166 }
167 }
168
169 }
Dake Gu290cc492017-04-28 15:38:26 -0700170
171 @Override
172 protected void onDestroy() {
173 MovieData.clear();
174 super.onDestroy();
175 }
Tim Kilbourn2223b082014-03-21 07:12:33 -0700176}