1 /* 2 * Copyright (C) 2018 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.systemui.statusbar.notification; 18 19 import android.util.Pools; 20 import android.view.View; 21 22 import com.android.internal.widget.MessagingImageMessage; 23 import com.android.systemui.R; 24 import com.android.systemui.statusbar.ViewTransformationHelper; 25 26 /** 27 * A transform state of a image view. 28 */ 29 public class MessagingImageTransformState extends ImageTransformState { 30 private static Pools.SimplePool<MessagingImageTransformState> sInstancePool 31 = new Pools.SimplePool<>(40); 32 private static final int START_ACTUAL_WIDTH = R.id.transformation_start_actual_width; 33 private static final int START_ACTUAL_HEIGHT = R.id.transformation_start_actual_height; 34 private MessagingImageMessage mImageMessage; 35 36 @Override initFrom(View view, TransformInfo transformInfo)37 public void initFrom(View view, TransformInfo transformInfo) { 38 super.initFrom(view, transformInfo); 39 mImageMessage = (MessagingImageMessage) view; 40 } 41 42 @Override sameAs(TransformState otherState)43 protected boolean sameAs(TransformState otherState) { 44 if (super.sameAs(otherState)) { 45 return true; 46 } 47 if (otherState instanceof MessagingImageTransformState) { 48 MessagingImageTransformState otherMessage = (MessagingImageTransformState) otherState; 49 return mImageMessage.sameAs(otherMessage.mImageMessage); 50 } 51 return false; 52 } 53 obtain()54 public static MessagingImageTransformState obtain() { 55 MessagingImageTransformState instance = sInstancePool.acquire(); 56 if (instance != null) { 57 return instance; 58 } 59 return new MessagingImageTransformState(); 60 } 61 62 @Override transformScale(TransformState otherState)63 protected boolean transformScale(TransformState otherState) { 64 return false; 65 } 66 67 @Override transformViewFrom(TransformState otherState, int transformationFlags, ViewTransformationHelper.CustomTransformation customTransformation, float transformationAmount)68 protected void transformViewFrom(TransformState otherState, int transformationFlags, 69 ViewTransformationHelper.CustomTransformation customTransformation, 70 float transformationAmount) { 71 super.transformViewFrom(otherState, transformationFlags, customTransformation, 72 transformationAmount); 73 float interpolatedValue = mDefaultInterpolator.getInterpolation( 74 transformationAmount); 75 if (otherState instanceof MessagingImageTransformState && sameAs(otherState)) { 76 MessagingImageMessage otherMessage 77 = ((MessagingImageTransformState) otherState).mImageMessage; 78 if (transformationAmount == 0.0f) { 79 setStartActualWidth(otherMessage.getActualWidth()); 80 setStartActualHeight(otherMessage.getActualHeight()); 81 } 82 float startActualWidth = getStartActualWidth(); 83 mImageMessage.setActualWidth( 84 (int) NotificationUtils.interpolate(startActualWidth, 85 mImageMessage.getStaticWidth(), 86 interpolatedValue)); 87 float startActualHeight = getStartActualHeight(); 88 mImageMessage.setActualHeight( 89 (int) NotificationUtils.interpolate(startActualHeight, 90 mImageMessage.getHeight(), 91 interpolatedValue)); 92 } 93 } 94 getStartActualWidth()95 public int getStartActualWidth() { 96 Object tag = mTransformedView.getTag(START_ACTUAL_WIDTH); 97 return tag == null ? -1 : (int) tag; 98 } 99 setStartActualWidth(int actualWidth)100 public void setStartActualWidth(int actualWidth) { 101 mTransformedView.setTag(START_ACTUAL_WIDTH, actualWidth); 102 } 103 getStartActualHeight()104 public int getStartActualHeight() { 105 Object tag = mTransformedView.getTag(START_ACTUAL_HEIGHT); 106 return tag == null ? -1 : (int) tag; 107 } 108 setStartActualHeight(int actualWidth)109 public void setStartActualHeight(int actualWidth) { 110 mTransformedView.setTag(START_ACTUAL_HEIGHT, actualWidth); 111 } 112 113 @Override recycle()114 public void recycle() { 115 super.recycle(); 116 if (getClass() == MessagingImageTransformState.class) { 117 sInstancePool.release(this); 118 } 119 } 120 121 @Override resetTransformedView()122 protected void resetTransformedView() { 123 super.resetTransformedView(); 124 mImageMessage.setActualWidth(mImageMessage.getStaticWidth()); 125 mImageMessage.setActualHeight(mImageMessage.getHeight()); 126 } 127 128 @Override reset()129 protected void reset() { 130 super.reset(); 131 mImageMessage = null; 132 } 133 } 134