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 package com.example.android.apis.animation;
17 
18 import com.example.android.apis.R;
19 
20 import android.app.Activity;
21 import android.app.ActivityOptions;
22 import android.content.Intent;
23 import android.graphics.drawable.ColorDrawable;
24 import android.graphics.drawable.Drawable;
25 import android.os.Bundle;
26 import android.view.View;
27 import android.widget.ImageView;
28 
29 /**
30  *
31  */
32 public class ActivityTransitionDetails extends Activity {
33 
34     private static final String TAG = "ActivityTransitionDetails";
35 
36     private static final String KEY_ID = "ViewTransitionValues:id";
37 
38     private int mImageResourceId = R.drawable.ducky;
39 
40     private String mName = "ducky";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         getWindow().setBackgroundDrawable(new ColorDrawable(randomColor()));
46         setContentView(R.layout.image_details);
47         ImageView titleImage = (ImageView) findViewById(R.id.titleImage);
48         titleImage.setImageDrawable(getHeroDrawable());
49     }
50 
getHeroDrawable()51     private Drawable getHeroDrawable() {
52         String name = getIntent().getStringExtra(KEY_ID);
53         if (name != null) {
54             mName = name;
55             mImageResourceId = ActivityTransition.getDrawableIdForKey(name);
56         }
57 
58         return getResources().getDrawable(mImageResourceId);
59     }
60 
clicked(View v)61     public void clicked(View v) {
62         Intent intent = new Intent(this, ActivityTransition.class);
63         intent.putExtra(KEY_ID, mName);
64         ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(this,
65                 v, "hero");
66         startActivity(intent, activityOptions.toBundle());
67     }
68 
randomColor()69     private static int randomColor() {
70         int red = (int)(Math.random() * 128);
71         int green = (int)(Math.random() * 128);
72         int blue = (int)(Math.random() * 128);
73         return 0xFF000000 | (red << 16) | (green << 8) | blue;
74     }
75 }
76