14e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi/* 24e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * Copyright (C) 2014 The Android Open Source Project 34e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * 44e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License"); 54e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * you may not use this file except in compliance with the License. 64e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * You may obtain a copy of the License at 74e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * 84e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * http://www.apache.org/licenses/LICENSE-2.0 94e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * 104e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * Unless required by applicable law or agreed to in writing, software 114e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS, 124e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * See the License for the specific language governing permissions and 144e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * limitations under the License 154e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi */ 164e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 170ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinekpackage com.android.systemui.statusbar.notification; 184e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 194e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggiimport android.content.Context; 207b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinekimport android.graphics.drawable.ColorDrawable; 217b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinekimport android.graphics.drawable.Drawable; 22ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinekimport android.view.NotificationHeaderView; 234e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggiimport android.view.View; 244e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 250ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinekimport com.android.systemui.statusbar.CrossFadeHelper; 267d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinekimport com.android.systemui.statusbar.ExpandableNotificationRow; 270ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinekimport com.android.systemui.statusbar.TransformableView; 284ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek 294e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi/** 304e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * Wraps the actual notification content view; used to implement behaviors which are different for 314e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * the individual templates and custom views. 324e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi */ 334ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinekpublic abstract class NotificationViewWrapper implements TransformableView { 344e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 354e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi protected final View mView; 367d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek protected final ExpandableNotificationRow mRow; 377bcf6d378f1bf1294ccd4c9beeb11bfd9b39816dAdrian Roos 387b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek private int mBackgroundColor = 0; 394e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 407d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) { 41be4116a3471184748bf6545506b59d48c720ea58Jorim Jaggi if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) { 420ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinek if ("bigPicture".equals(v.getTag())) { 437d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek return new NotificationBigPictureTemplateViewWrapper(ctx, v, row); 44d634d069dd484698c6d109525ee0b6e882ca49dfSelim Cinek } else if ("bigText".equals(v.getTag())) { 457d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek return new NotificationBigTextTemplateViewWrapper(ctx, v, row); 46df5bf6147ca8105f4617a815d4c7b92f818de3e8Selim Cinek } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) { 477d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek return new NotificationMediaTemplateViewWrapper(ctx, v, row); 48feafa052f33d97b9bf73cae8aa4074462c399f73Adrian Roos } else if ("messaging".equals(v.getTag())) { 49feafa052f33d97b9bf73cae8aa4074462c399f73Adrian Roos return new NotificationMessagingTemplateViewWrapper(ctx, v, row); 500ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinek } 517d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek return new NotificationTemplateViewWrapper(ctx, v, row); 529c7712d45ccec56a80873a83e56a83f810624b43Selim Cinek } else if (v instanceof NotificationHeaderView) { 537d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek return new NotificationHeaderViewWrapper(ctx, v, row); 544e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi } else { 557bcf6d378f1bf1294ccd4c9beeb11bfd9b39816dAdrian Roos return new NotificationCustomViewWrapper(ctx, v, row); 564e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi } 574e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi } 584e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 597bcf6d378f1bf1294ccd4c9beeb11bfd9b39816dAdrian Roos protected NotificationViewWrapper(Context ctx, View view, ExpandableNotificationRow row) { 604e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi mView = view; 617d1c63e66a2e19bf32249f52c56e563eae4c6819Selim Cinek mRow = row; 62131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek onReinflated(); 637bcf6d378f1bf1294ccd4c9beeb11bfd9b39816dAdrian Roos } 647bcf6d378f1bf1294ccd4c9beeb11bfd9b39816dAdrian Roos 65dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi /** 66dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi * Notifies this wrapper that the content of the view might have changed. 67414ad33470789e9f9fc6c7b82ba684418ff5caa4Selim Cinek * @param row the row this wrapper is attached to 68dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi */ 69131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek public void onContentUpdated(ExpandableNotificationRow row) { 70131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek } 71131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek 72131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek public void onReinflated() { 73245090f06004770cef3cf49446694f407000c2c1Selim Cinek if (shouldClearBackgroundOnReapply()) { 74245090f06004770cef3cf49446694f407000c2c1Selim Cinek mBackgroundColor = 0; 75245090f06004770cef3cf49446694f407000c2c1Selim Cinek } 76131f1a4bc491c07f0c3f643ac5b2551061799024Selim Cinek Drawable background = mView.getBackground(); 777b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek if (background instanceof ColorDrawable) { 787b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek mBackgroundColor = ((ColorDrawable) background).getColor(); 797b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek mView.setBackground(null); 807b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek } 817b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek } 827b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek 83245090f06004770cef3cf49446694f407000c2c1Selim Cinek protected boolean shouldClearBackgroundOnReapply() { 84245090f06004770cef3cf49446694f407000c2c1Selim Cinek return true; 85245090f06004770cef3cf49446694f407000c2c1Selim Cinek } 86245090f06004770cef3cf49446694f407000c2c1Selim Cinek 87be4116a3471184748bf6545506b59d48c720ea58Jorim Jaggi /** 8865b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek * Update the appearance of the expand button. 8965b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek * 9065b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek * @param expandable should this view be expandable 9165b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek * @param onClickListener the listener to invoke when the expand affordance is clicked on 9265b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek */ 9365b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {} 94ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek 95ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek /** 96ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek * @return the notification header if it exists 97ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek */ 98ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek public NotificationHeaderView getNotificationHeader() { 99ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek return null; 100ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek } 1014ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek 102aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek public int getHeaderTranslation() { 103aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek return 0; 104aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek } 105aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek 1064ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek @Override 1074ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek public TransformState getCurrentState(int fadingView) { 1084ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek return null; 1094ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek } 1104ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek 1114ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek @Override 1124ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek public void transformTo(TransformableView notification, Runnable endRunnable) { 1134ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek // By default we are fading out completely 1144ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek CrossFadeHelper.fadeOut(mView, endRunnable); 1154ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek } 1164ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek 1174ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek @Override 1188f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek public void transformTo(TransformableView notification, float transformationAmount) { 1198f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek CrossFadeHelper.fadeOut(mView, transformationAmount); 1208f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek } 1218f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek 1228f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek @Override 1234ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek public void transformFrom(TransformableView notification) { 1244ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek // By default we are fading in completely 1254ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek CrossFadeHelper.fadeIn(mView); 1264ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek } 1274ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek 1284ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek @Override 1298f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek public void transformFrom(TransformableView notification, float transformationAmount) { 1308f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek CrossFadeHelper.fadeIn(mView, transformationAmount); 1318f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek } 1328f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek 1338f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek @Override 1344ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek public void setVisible(boolean visible) { 135f64044c6a4e1d34595c9a9bc26ca949b54a93288Selim Cinek mView.animate().cancel(); 1364ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 1374ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek } 138c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek 139c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek public int getCustomBackgroundColor() { 1407b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek // Parent notifications should always use the normal background color 1417b9605b79c4f738ee5b306d8693018e931cda18eSelim Cinek return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor; 142c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek } 143c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek 144019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek protected int resolveBackgroundColor() { 145019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek int customBackgroundColor = getCustomBackgroundColor(); 146019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek if (customBackgroundColor != 0) { 147019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek return customBackgroundColor; 148019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek } 149019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek return mView.getContext().getColor( 150019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek com.android.internal.R.color.notification_material_background_color); 151019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek } 152019d71ecfcb5f2371260349112831f528a1efe29Selim Cinek 1531a48babb5ed30e8a3eb9645355d6455b21041406Selim Cinek public void setLegacy(boolean legacy) { 154c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek } 155181385ce33c83a249087a1cff65870dfe120aae8Adrian Roos 156181385ce33c83a249087a1cff65870dfe120aae8Adrian Roos public void setContentHeight(int contentHeight, int minHeightHint) { 157181385ce33c83a249087a1cff65870dfe120aae8Adrian Roos } 1587b9ed0d8fdb927cb1eece172af5fe28d319fe558Adrian Roos 1597b9ed0d8fdb927cb1eece172af5fe28d319fe558Adrian Roos public void setRemoteInputVisible(boolean visible) { 1607b9ed0d8fdb927cb1eece172af5fe28d319fe558Adrian Roos } 161414ad33470789e9f9fc6c7b82ba684418ff5caa4Selim Cinek 162414ad33470789e9f9fc6c7b82ba684418ff5caa4Selim Cinek public void setIsChildInGroup(boolean isChildInGroup) { 163414ad33470789e9f9fc6c7b82ba684418ff5caa4Selim Cinek } 1644705f29973a0640120e5803d14f5646c880d7cc5Selim Cinek 1654705f29973a0640120e5803d14f5646c880d7cc5Selim Cinek public boolean isDimmable() { 1664705f29973a0640120e5803d14f5646c880d7cc5Selim Cinek return true; 1674705f29973a0640120e5803d14f5646c880d7cc5Selim Cinek } 1685d6ef8de1e2da541d1cf7c6603739289be4d593eSelim Cinek 1695d6ef8de1e2da541d1cf7c6603739289be4d593eSelim Cinek public boolean disallowSingleClick(float x, float y) { 1705d6ef8de1e2da541d1cf7c6603739289be4d593eSelim Cinek return false; 1715d6ef8de1e2da541d1cf7c6603739289be4d593eSelim Cinek } 172e62255ccc59a9410ce543558815355420678ffcdSelim Cinek 173e62255ccc59a9410ce543558815355420678ffcdSelim Cinek public int getMinLayoutHeight() { 174e62255ccc59a9410ce543558815355420678ffcdSelim Cinek return 0; 175e62255ccc59a9410ce543558815355420678ffcdSelim Cinek } 176515b2035df09d491284bed4efb92db8de9cdf85cSelim Cinek 17786bfcee04bdad331ac9d41e690eaa1190ea7e334Selim Cinek public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) { 178515b2035df09d491284bed4efb92db8de9cdf85cSelim Cinek return false; 179515b2035df09d491284bed4efb92db8de9cdf85cSelim Cinek } 180aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek 181aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek public void setHeaderVisibleAmount(float headerVisibleAmount) { 182aa9db1f34fe8b4a2d143c1379ec6c0c304bbd40bSelim Cinek } 183396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek 184396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek /** 185396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek * Get the extra height that needs to be added to this view, such that it can be measured 186396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek * normally. 187396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek */ 188396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek public int getExtraMeasureHeight() { 189396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek return 0; 190396cacaaa8c41e19a835e1a64f76314cd2db49f5Selim Cinek } 1914e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi} 192