• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc. All rights reserved.
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.xyztouristattractions.ui;
18 
19 import android.annotation.TargetApi;
20 import android.app.Activity;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.Build;
24 import android.os.Bundle;
25 import android.support.v4.app.ActivityCompat;
26 import android.support.v4.app.ActivityOptionsCompat;
27 import android.support.v7.app.AppCompatActivity;
28 import android.view.View;
29 
30 import com.example.android.xyztouristattractions.R;
31 
32 /**
33  * The tourist attraction detail activity screen which contains the details of
34  * a single attraction.
35  */
36 public class DetailActivity extends AppCompatActivity {
37 
38     private static final String EXTRA_ATTRACTION = "attraction";
39 
40     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
launch(Activity activity, String attraction, View heroView)41     public static void launch(Activity activity, String attraction, View heroView) {
42         Intent intent = getLaunchIntent(activity, attraction);
43         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
44             ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
45                     activity, heroView, heroView.getTransitionName());
46             ActivityCompat.startActivity(activity, intent, options.toBundle());
47         } else {
48             activity.startActivity(intent);
49         }
50     }
51 
getLaunchIntent(Context context, String attraction)52     public static Intent getLaunchIntent(Context context, String attraction) {
53         Intent intent = new Intent(context, DetailActivity.class);
54         intent.putExtra(EXTRA_ATTRACTION, attraction);
55         return intent;
56     }
57 
58     @Override
onCreate(Bundle savedInstanceState)59     protected void onCreate(Bundle savedInstanceState) {
60         super.onCreate(savedInstanceState);
61         setContentView(R.layout.activity_main);
62 
63         String attraction = getIntent().getStringExtra(EXTRA_ATTRACTION);
64         if (savedInstanceState == null) {
65             getSupportFragmentManager().beginTransaction()
66                     .add(R.id.container, DetailFragment.createInstance(attraction))
67                     .commit();
68         }
69     }
70 }
71