NotificationViewWrapper.java revision 19ba7050c3aaf47f431d33341de7399df776f559
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;
204ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinekimport android.service.notification.StatusBarNotification;
21ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinekimport android.view.NotificationHeaderView;
224e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggiimport android.view.View;
234e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
240ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinekimport com.android.systemui.statusbar.CrossFadeHelper;
250ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinekimport com.android.systemui.statusbar.TransformableView;
264ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek
274e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi/**
284e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * Wraps the actual notification content view; used to implement behaviors which are different for
294e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi * the individual templates and custom views.
304e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi */
314ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinekpublic abstract class NotificationViewWrapper implements TransformableView {
324e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
334e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    protected final View mView;
3419ba7050c3aaf47f431d33341de7399df776f559Selim Cinek    protected boolean mDark;
354e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
364e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    public static NotificationViewWrapper wrap(Context ctx, View v) {
37be4116a3471184748bf6545506b59d48c720ea58Jorim Jaggi        if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
380ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinek            if ("bigPicture".equals(v.getTag())) {
390ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinek                return new NotificationBigPictureTemplateViewWrapper(ctx, v);
400ffbda62e55ad390e05e6c3ff52e1378e420285cSelim Cinek            }
4175fe38c51790df834df914fda2bb0f12b8c9eebbSelim Cinek            return new NotificationTemplateViewWrapper(ctx, v);
429c7712d45ccec56a80873a83e56a83f810624b43Selim Cinek        } else if (v instanceof NotificationHeaderView) {
439c7712d45ccec56a80873a83e56a83f810624b43Selim Cinek            return new NotificationHeaderViewWrapper(ctx, v);
444e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi        } else {
454e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi            return new NotificationCustomViewWrapper(v);
464e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi        }
474e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    }
484e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
494e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    protected NotificationViewWrapper(View view) {
504e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi        mView = view;
514e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    }
524e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
534e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    /**
544e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     * In dark mode, we draw as little as possible, assuming a black background.
554e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     *
564e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     * @param dark whether we should display ourselves in dark mode
574e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     * @param fade whether to animate the transition if the mode changes
584e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     * @param delay if fading, the delay of the animation
594e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     */
6019ba7050c3aaf47f431d33341de7399df776f559Selim Cinek    public void setDark(boolean dark, boolean fade, long delay) {
6119ba7050c3aaf47f431d33341de7399df776f559Selim Cinek        mDark = dark;
6219ba7050c3aaf47f431d33341de7399df776f559Selim Cinek    }
63dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi
64dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi    /**
65dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi     * Notifies this wrapper that the content of the view might have changed.
664ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek     * @param notification
67dacc924a65d68e7888d8771baa14141329265ebfJorim Jaggi     */
6819ba7050c3aaf47f431d33341de7399df776f559Selim Cinek    public void notifyContentUpdated(StatusBarNotification notification) {
6919ba7050c3aaf47f431d33341de7399df776f559Selim Cinek        mDark = false;
7019ba7050c3aaf47f431d33341de7399df776f559Selim Cinek    };
71be4116a3471184748bf6545506b59d48c720ea58Jorim Jaggi
72be4116a3471184748bf6545506b59d48c720ea58Jorim Jaggi    /**
7365b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek     * Update the appearance of the expand button.
7465b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek     *
7565b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek     * @param expandable should this view be expandable
7665b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek     * @param onClickListener the listener to invoke when the expand affordance is clicked on
7765b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek     */
7865b2e7c6cbcd41985ab007eec3a21aad75dfc983Selim Cinek    public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {}
79ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek
80ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek    /**
81ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek     * @return the notification header if it exists
82ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek     */
83ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek    public NotificationHeaderView getNotificationHeader() {
84ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek        return null;
85ea4bef7386ca6c6260f292bf006d16a99b93f698Selim Cinek    }
864ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek
874ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    @Override
884ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    public TransformState getCurrentState(int fadingView) {
894ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        return null;
904ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    }
914ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek
924ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    @Override
934ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    public void transformTo(TransformableView notification, Runnable endRunnable) {
944ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        // By default we are fading out completely
954ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        CrossFadeHelper.fadeOut(mView, endRunnable);
964ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    }
974ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek
984ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    @Override
994ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    public void transformFrom(TransformableView notification) {
1004ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        // By default we are fading in completely
1014ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        CrossFadeHelper.fadeIn(mView);
1024ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    }
1034ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek
1044ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    @Override
1054ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    public void setVisible(boolean visible) {
1064ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek        mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
1074ffd63611a0d516c9988b37e9c06e6f8390c2a2fSelim Cinek    }
1084e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi}
109