• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
17 package com.android.tv.dvr.ui;
18 
19 import android.content.Context;
20 import android.graphics.Bitmap;
21 import android.graphics.Matrix;
22 import android.graphics.drawable.BitmapDrawable;
23 import android.transition.ChangeImageTransform;
24 import android.transition.TransitionValues;
25 import android.util.AttributeSet;
26 import android.view.View;
27 import android.widget.ImageView;
28 import android.widget.ImageView.ScaleType;
29 import com.android.tv.R;
30 import java.util.Map;
31 
32 /**
33  * TODO: Remove this class once b/32405620 is fixed. This class is for the workaround of b/32405620
34  * and only for the shared element transition between {@link
35  * com.android.tv.dvr.ui.browse.RecordingCardView} and {@link
36  * com.android.tv.dvr.ui.browse.DvrDetailsActivity}.
37  */
38 public class ChangeImageTransformWithScaledParent extends ChangeImageTransform {
39     private static final String PROPNAME_MATRIX = "android:changeImageTransform:matrix";
40 
ChangeImageTransformWithScaledParent(Context context, AttributeSet attrs)41     public ChangeImageTransformWithScaledParent(Context context, AttributeSet attrs) {
42         super(context, attrs);
43     }
44 
45     @Override
captureStartValues(TransitionValues transitionValues)46     public void captureStartValues(TransitionValues transitionValues) {
47         super.captureStartValues(transitionValues);
48         applyParentScale(transitionValues);
49     }
50 
51     @Override
captureEndValues(TransitionValues transitionValues)52     public void captureEndValues(TransitionValues transitionValues) {
53         super.captureEndValues(transitionValues);
54         applyParentScale(transitionValues);
55     }
56 
applyParentScale(TransitionValues transitionValues)57     private void applyParentScale(TransitionValues transitionValues) {
58         View view = transitionValues.view;
59         Map<String, Object> values = transitionValues.values;
60         Matrix matrix = (Matrix) values.get(PROPNAME_MATRIX);
61         if (matrix != null
62                 && view.getId() == R.id.details_overview_image
63                 && view instanceof ImageView) {
64             ImageView imageView = (ImageView) view;
65             if (imageView.getScaleType() == ScaleType.CENTER_INSIDE
66                     && imageView.getDrawable() instanceof BitmapDrawable) {
67                 Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
68                 if (bitmap.getWidth() < imageView.getWidth()
69                         && bitmap.getHeight() < imageView.getHeight()) {
70                     float scale =
71                             imageView
72                                     .getContext()
73                                     .getResources()
74                                     .getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1);
75                     matrix.postScale(
76                             scale, scale, imageView.getWidth() / 2, imageView.getHeight() / 2);
77                 }
78             }
79         }
80     }
81 }
82