1f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn/* 2f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * Copyright (C) 2014 The Android Open Source Project 3f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * 4f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * in compliance with the License. You may obtain a copy of the License at 6f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * 7f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * http://www.apache.org/licenses/LICENSE-2.0 8f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * 9f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * Unless required by applicable law or agreed to in writing, software distributed under the License 10f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * or implied. See the License for the specific language governing permissions and limitations under 12f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn * the License. 13f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn */ 14f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbournpackage com.example.android.leanback; 15f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn 16f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbournimport android.app.Activity; 17f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbournimport android.os.Bundle; 18f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn 19f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbournpublic class DetailsActivity extends Activity 20f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn{ 217f3028385b0349cfc6c0d6784840be148943b296Dake Gu public static final String EXTRA_ITEM = "item"; 227f3028385b0349cfc6c0d6784840be148943b296Dake Gu public static final String SHARED_ELEMENT_NAME = "hero"; 237f3028385b0349cfc6c0d6784840be148943b296Dake Gu 2458d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu private boolean useLegacyFragment() { 2571e7e67f320b23feac784b629db17b3bcce08722Dake Gu return (DetailsPresenterSelectionActivity.USE_LEGACY_PRESENTER 2671e7e67f320b23feac784b629db17b3bcce08722Dake Gu && !(this instanceof SearchDetailsActivity)); 2758d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu } 2858d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu 29f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn /** Called when the activity is first created. */ 30f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn @Override 31f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn public void onCreate(Bundle savedInstanceState) 32f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn { 33f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn super.onCreate(savedInstanceState); 3458d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu setContentView(useLegacyFragment() ? R.layout.legacy_details : R.layout.details); 35c3f4128ac652dc38ed84577efc660b8b1e59fe08Dake Gu if (savedInstanceState == null) { 36c3f4128ac652dc38ed84577efc660b8b1e59fe08Dake Gu // Only pass object to fragment when activity is first time created, 37c3f4128ac652dc38ed84577efc660b8b1e59fe08Dake Gu // later object is modified and persisted with fragment state. 3858d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu if (useLegacyFragment()) { 3958d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu ((DetailsFragment)getFragmentManager().findFragmentById(R.id.details_fragment)) 4058d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM)); 4158d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu } else { 4258d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu ((NewDetailsFragment)getFragmentManager().findFragmentById(R.id.details_fragment)) 43c3f4128ac652dc38ed84577efc660b8b1e59fe08Dake Gu .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM)); 4458d19582d57cc3c1dae4efc76c5a91f87e5fef63Dake Gu } 45c3f4128ac652dc38ed84577efc660b8b1e59fe08Dake Gu } 46f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn } 477f3028385b0349cfc6c0d6784840be148943b296Dake Gu 48a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout @Override 49a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout public void onAttachedToWindow() { 50a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout super.onAttachedToWindow(); 51a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout BackgroundHelper.attach(this); 52a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout } 53a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout 54a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout @Override 55a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout public void onStop() { 56a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout BackgroundHelper.release(this); 57a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout super.onStop(); 58a5e729eb7c417a872876ac6f2b904bc8d232aa06Craig Stout } 59f519df88d6a69e517e08b844ffadd722b9ceb9abTim Kilbourn} 60