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.internal.widget; 18 19 import android.app.Notification; 20 import android.view.View; 21 import android.view.ViewGroup; 22 import android.view.ViewParent; 23 24 /** 25 * Shared state and implementation for MessagingMessages. Used to share common implementations. 26 */ 27 public class MessagingMessageState { 28 private final View mHostView; 29 private Notification.MessagingStyle.Message mMessage; 30 private MessagingGroup mGroup; 31 private boolean mIsHistoric; 32 private boolean mIsHidingAnimated; 33 MessagingMessageState(View hostView)34 MessagingMessageState(View hostView) { 35 mHostView = hostView; 36 } 37 setMessage(Notification.MessagingStyle.Message message)38 public void setMessage(Notification.MessagingStyle.Message message) { 39 mMessage = message; 40 } 41 getMessage()42 public Notification.MessagingStyle.Message getMessage() { 43 return mMessage; 44 } 45 setGroup(MessagingGroup group)46 public void setGroup(MessagingGroup group) { 47 mGroup = group; 48 } 49 getGroup()50 public MessagingGroup getGroup() { 51 return mGroup; 52 } 53 setIsHistoric(boolean isHistoric)54 public void setIsHistoric(boolean isHistoric) { 55 mIsHistoric = isHistoric; 56 } 57 setIsHidingAnimated(boolean isHiding)58 public void setIsHidingAnimated(boolean isHiding) { 59 ViewParent parent = mHostView.getParent(); 60 mIsHidingAnimated = isHiding; 61 mHostView.invalidate(); 62 if (parent instanceof ViewGroup) { 63 ((ViewGroup) parent).invalidate(); 64 } 65 } 66 isHidingAnimated()67 public boolean isHidingAnimated() { 68 return mIsHidingAnimated; 69 } 70 getHostView()71 public View getHostView() { 72 return mHostView; 73 } 74 recycle()75 public void recycle() { 76 mHostView.setAlpha(1.0f); 77 mHostView.setTranslationY(0); 78 MessagingPropertyAnimator.recycle(mHostView); 79 mIsHidingAnimated = false; 80 mIsHistoric = false; 81 mGroup = null; 82 mMessage = null; 83 } 84 } 85