NotificationOverflowIconsView.java revision 7441931462c5dd00edc6f4598e1e60b4f5e67fc4
1/*
2 * Copyright (C) 2014 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
17package com.android.systemui.statusbar;
18
19import android.app.Notification;
20import android.content.Context;
21import android.content.res.Configuration;
22import android.graphics.PorterDuff;
23import android.util.AttributeSet;
24import android.widget.ImageView;
25import android.widget.TextView;
26
27import com.android.internal.util.NotificationColorUtil;
28import com.android.systemui.R;
29import com.android.systemui.statusbar.phone.IconMerger;
30
31/**
32 * A view to display all the overflowing icons on Keyguard.
33 */
34public class NotificationOverflowIconsView extends IconMerger {
35
36    private TextView mMoreText;
37    private int mTintColor;
38    private int mIconSize;
39    private NotificationColorUtil mNotificationColorUtil = new NotificationColorUtil();
40
41    public NotificationOverflowIconsView(Context context, AttributeSet attrs) {
42        super(context, attrs);
43    }
44
45    @Override
46    protected void onFinishInflate() {
47        super.onFinishInflate();
48        mTintColor = getResources().getColor(R.color.keyguard_overflow_content_color);
49        mIconSize = getResources().getDimensionPixelSize(
50                com.android.internal.R.dimen.status_bar_icon_size);
51    }
52
53    public void setMoreText(TextView moreText) {
54        mMoreText = moreText;
55    }
56
57    public void addNotification(NotificationData.Entry notification) {
58        StatusBarIconView v = new StatusBarIconView(getContext(), "",
59                notification.notification.getNotification());
60        v.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
61        addView(v, mIconSize, mIconSize);
62        v.set(notification.icon.getStatusBarIcon());
63        applyColor(notification.notification.getNotification(), v);
64        updateMoreText();
65    }
66
67    private void applyColor(Notification notification, StatusBarIconView view) {
68        if (notification.color == Notification.COLOR_DEFAULT) {
69            if (mNotificationColorUtil.isGrayscale(view.getDrawable())) {
70                view.setColorFilter(mTintColor, PorterDuff.Mode.MULTIPLY);
71            }
72        } else {
73            view.setColorFilter(notification.color, PorterDuff.Mode.SRC_ATOP);
74        }
75    }
76
77    private void updateMoreText() {
78        mMoreText.setText(
79                getResources().getString(R.string.keyguard_more_overflow_text, getChildCount()));
80    }
81}
82