Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 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 |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 7 | * |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 9 | * |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 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. |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 15 | */ |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 16 | |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 17 | package com.example.android.leanback; |
| 18 | |
| 19 | import android.app.Activity; |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.graphics.drawable.Drawable; |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 24 | import android.support.v17.leanback.app.GuidedStepFragment; |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 25 | import android.support.v17.leanback.widget.GuidanceStylist.Guidance; |
susnata | 20767a1 | 2016-01-28 14:02:48 -0800 | [diff] [blame] | 26 | import android.support.v17.leanback.widget.GuidedAction; |
| 27 | import android.support.v4.app.ActivityOptionsCompat; |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 28 | import android.support.v4.content.res.ResourcesCompat; |
Dake Gu | ef05d54 | 2016-12-07 11:04:42 -0800 | [diff] [blame] | 29 | |
susnata | 20767a1 | 2016-01-28 14:02:48 -0800 | [diff] [blame] | 30 | import java.util.List; |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Activity that allows navigation among the demo activities. |
| 34 | */ |
| 35 | public class MainActivity extends Activity { |
| 36 | |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 37 | @Override |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 38 | protected void onCreate(Bundle savedInstanceState) { |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 39 | super.onCreate(savedInstanceState); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 40 | |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 41 | GuidedStepFragment.addAsRoot(this, new StepFragment(), android.R.id.content); |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 42 | } |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 43 | |
Dake Gu | 28526e9 | 2015-06-24 15:05:20 -0700 | [diff] [blame] | 44 | public static class StepFragment extends GuidedStepFragment { |
susnata | 20767a1 | 2016-01-28 14:02:48 -0800 | [diff] [blame] | 45 | |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 46 | @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 Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 51 | final Context context = getActivity(); |
| 52 | Drawable icon = ResourcesCompat.getDrawable(context.getResources(), |
| 53 | R.drawable.ic_main_icon, context.getTheme()); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 54 | 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 Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 60 | addAction(actions, BrowseSupportActivity.class, R.string.browse_support, |
| 61 | R.string.browse_support_description); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 62 | addAction(actions, SearchActivity.class, R.string.search, R.string.search_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 63 | addAction(actions, SearchSupportActivity.class, R.string.search_support, |
| 64 | R.string.search_support_description); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 65 | |
| 66 | addAction(actions, DetailsActivity.class, R.string.details, |
| 67 | R.string.details_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 68 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM, |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 69 | new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 70 | addAction(actions, DetailsSupportActivity.class, R.string.details_support, |
| 71 | R.string.details_support_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 72 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM, |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 73 | new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 74 | |
| 75 | addAction(actions, DetailsVideoActivity.class, R.string.details_video, |
| 76 | R.string.details_video_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 77 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM, |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 78 | 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); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 81 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM, |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 82 | 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); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 86 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM, |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 87 | 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); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 91 | actions.get(actions.size() - 1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM, |
Dake Gu | 5bcc058 | 2016-12-28 16:18:49 -0800 | [diff] [blame] | 92 | new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
| 93 | |
Dake Gu | 58d1958 | 2015-04-29 11:46:46 -0700 | [diff] [blame] | 94 | addAction(actions, SearchDetailsActivity.class, R.string.search_details, |
| 95 | R.string.search_details_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 96 | actions.get(actions.size() - 1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM, |
Dake Gu | 58d1958 | 2015-04-29 11:46:46 -0700 | [diff] [blame] | 97 | new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 98 | addAction(actions, SearchDetailsSupportActivity.class, R.string.search_details_support, |
| 99 | R.string.search_details_support_description); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 100 | actions.get(actions.size() - 1).getIntent().putExtra( |
| 101 | SearchDetailsSupportActivity.EXTRA_ITEM, |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 102 | new PhotoItem("Hello world", R.drawable.gallery_photo_1)); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 103 | addAction(actions, VerticalGridActivity.class, R.string.vgrid, |
| 104 | R.string.vgrid_description); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 105 | addAction(actions, VerticalGridSupportActivity.class, R.string.vgrid_support, |
| 106 | R.string.vgrid_support_description); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 107 | addAction(actions, GuidedStepActivity.class, R.string.guidedstep, |
| 108 | R.string.guidedstep_description); |
Dake Gu | ab1d3dc | 2015-09-04 15:25:49 -0700 | [diff] [blame] | 109 | addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport, |
| 110 | R.string.guidedstepsupport_description); |
susnata | 20767a1 | 2016-01-28 14:02:48 -0800 | [diff] [blame] | 111 | addAction(actions, GuidedStepHalfScreenActivity.class, R.string.guidedstephalfscreen, |
| 112 | R.string.guidedstep_description); |
| 113 | addAction(actions, GuidedStepSupportHalfScreenActivity.class, |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 114 | R.string.guidedstepsupporthalfscreen, |
| 115 | R.string.guidedstep_description); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 116 | addAction(actions, BrowseErrorActivity.class, R.string.browseerror, |
| 117 | R.string.browseerror_description); |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 118 | addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support, |
| 119 | R.string.browseerror_support_description); |
Dake Gu | 3bcad88 | 2017-03-20 16:40:45 -0700 | [diff] [blame] | 120 | addAction(actions, PlaybackTransportControlActivity.class, R.string.playback, |
Dake Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 121 | R.string.playback_description); |
Dake Gu | 3bcad88 | 2017-03-20 16:40:45 -0700 | [diff] [blame] | 122 | addAction(actions, PlaybackTransportControlSupportActivity.class, |
| 123 | R.string.playback_support, R.string.playback_support_description); |
susnata | aa49439 | 2016-10-31 16:28:19 -0700 | [diff] [blame] | 124 | 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 Gu | 71e7e67 | 2015-09-29 15:32:42 -0700 | [diff] [blame] | 128 | addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid, |
| 129 | R.string.hgrid_description); |
Dake Gu | 58d1958 | 2015-04-29 11:46:46 -0700 | [diff] [blame] | 130 | addAction(actions, DetailsPresenterSelectionActivity.class, |
| 131 | R.string.detail_presenter_options, |
| 132 | R.string.detail_presenter_options_description); |
Keyvan Amiri | ad3b469 | 2016-10-04 15:44:03 -0700 | [diff] [blame] | 133 | addAction(actions, SettingsActivity.class, |
| 134 | R.string.settings, |
| 135 | R.string.settings_description); |
Chulwoo Lee | e3ef610 | 2016-03-22 18:18:14 -0700 | [diff] [blame] | 136 | 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); |
jingjiangli | 6121801 | 2017-07-10 06:53:25 -0700 | [diff] [blame] | 142 | addAction(actions, VideoActivityWithDetailedCard.class, |
| 143 | R.string.video_play_with_detail_card, |
| 144 | R.string.video_play_with_detail_card_description); |
jingjiangli | dbe6c87 | 2017-07-23 16:23:46 -0700 | [diff] [blame] | 145 | |
| 146 | addAction(actions, MusicExampleActivity.class, |
| 147 | R.string.music, |
| 148 | R.string.music_description); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | private void addAction(List<GuidedAction> actions, Class cls, int titleRes, int descRes) { |
Dake Gu | b7087e0 | 2016-09-22 14:34:56 -0700 | [diff] [blame] | 152 | actions.add(new GuidedAction.Builder(getActivity()) |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 153 | .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 Gu | 067d9b9 | 2015-08-18 13:55:07 -0700 | [diff] [blame] | 163 | Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity()) |
| 164 | .toBundle(); |
| 165 | startActivity(intent, bundle); |
Kris Giesing | 6f0d24a | 2015-02-16 15:10:05 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | } |
Dake Gu | 290cc49 | 2017-04-28 15:38:26 -0700 | [diff] [blame] | 170 | |
| 171 | @Override |
| 172 | protected void onDestroy() { |
| 173 | MovieData.clear(); |
| 174 | super.onDestroy(); |
| 175 | } |
Tim Kilbourn | 2223b08 | 2014-03-21 07:12:33 -0700 | [diff] [blame] | 176 | } |