Search in sources :

Example 6 with StatusBarIcon

use of com.android.internal.statusbar.StatusBarIcon in project platform_frameworks_base by android.

the class StatusBarIconController method setIconVisibility.

public void setIconVisibility(String slot, boolean visibility) {
    int index = getSlotIndex(slot);
    StatusBarIcon icon = getIcon(index);
    if (icon == null || icon.visible == visibility) {
        return;
    }
    icon.visible = visibility;
    handleSet(index, icon);
}
Also used : StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Example 7 with StatusBarIcon

use of com.android.internal.statusbar.StatusBarIcon in project platform_frameworks_base by android.

the class StatusBarManagerService method setIcon.

@Override
public void setIcon(String slot, String iconPackage, int iconId, int iconLevel, String contentDescription) {
    enforceStatusBar();
    synchronized (mIcons) {
        StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId, iconLevel, 0, contentDescription);
        //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
        mIcons.put(slot, icon);
        if (mBar != null) {
            try {
                mBar.setIcon(slot, icon);
            } catch (RemoteException ex) {
            }
        }
    }
}
Also used : StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) RemoteException(android.os.RemoteException)

Example 8 with StatusBarIcon

use of com.android.internal.statusbar.StatusBarIcon in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method updateNotification.

public void updateNotification(IBinder key, StatusBarNotification notification) {
    if (DEBUG)
        Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")");
    final NotificationData.Entry oldEntry = mNotificationData.findByKey(key);
    if (oldEntry == null) {
        Slog.w(TAG, "updateNotification for unknown key: " + key);
        return;
    }
    final StatusBarNotification oldNotification = oldEntry.notification;
    // XXX: modify when we do something more intelligent with the two content views
    final RemoteViews oldContentView = oldNotification.getNotification().contentView;
    final RemoteViews contentView = notification.getNotification().contentView;
    final RemoteViews oldBigContentView = oldNotification.getNotification().bigContentView;
    final RemoteViews bigContentView = notification.getNotification().bigContentView;
    if (DEBUG) {
        Slog.d(TAG, "old notification: when=" + oldNotification.getNotification().when + " ongoing=" + oldNotification.isOngoing() + " expanded=" + oldEntry.expanded + " contentView=" + oldContentView + " bigContentView=" + oldBigContentView + " rowParent=" + oldEntry.row.getParent());
        Slog.d(TAG, "new notification: when=" + notification.getNotification().when + " ongoing=" + oldNotification.isOngoing() + " contentView=" + contentView + " bigContentView=" + bigContentView);
    }
    // Can we just reapply the RemoteViews in place?  If when didn't change, the order
    // didn't change.
    // 1U is never null
    boolean contentsUnchanged = oldEntry.expanded != null && contentView.getPackage() != null && oldContentView.getPackage() != null && oldContentView.getPackage().equals(contentView.getPackage()) && oldContentView.getLayoutId() == contentView.getLayoutId();
    // large view may be null
    boolean bigContentsUnchanged = (oldEntry.getLargeView() == null && bigContentView == null) || ((oldEntry.getLargeView() != null && bigContentView != null) && bigContentView.getPackage() != null && oldBigContentView.getPackage() != null && oldBigContentView.getPackage().equals(bigContentView.getPackage()) && oldBigContentView.getLayoutId() == bigContentView.getLayoutId());
    ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent();
    boolean orderUnchanged = notification.getNotification().when == oldNotification.getNotification().when && notification.getScore() == oldNotification.getScore();
    // score now encompasses/supersedes isOngoing()
    boolean updateTicker = notification.getNotification().tickerText != null && !TextUtils.equals(notification.getNotification().tickerText, oldEntry.notification.getNotification().tickerText) || mHaloActive;
    boolean isTopAnyway = isTopNotification(rowParent, oldEntry);
    if (contentsUnchanged && bigContentsUnchanged && (orderUnchanged || isTopAnyway)) {
        if (DEBUG)
            Slog.d(TAG, "reusing notification for key: " + key);
        oldEntry.notification = notification;
        try {
            // Reapply the RemoteViews
            contentView.reapply(mContext, oldEntry.expanded, mOnClickHandler);
            if (bigContentView != null && oldEntry.getLargeView() != null) {
                bigContentView.reapply(mContext, oldEntry.getLargeView(), mOnClickHandler);
            }
            // update the contentIntent
            final PendingIntent contentIntent = notification.getNotification().contentIntent;
            if (contentIntent != null) {
                final View.OnClickListener listener = makeClicker(contentIntent, notification.getPackageName(), notification.getTag(), notification.getId());
                oldEntry.content.setOnClickListener(listener);
                oldEntry.floatingIntent = makeClicker(contentIntent, notification.getPackageName(), notification.getTag(), notification.getId());
                oldEntry.floatingIntent.makeFloating(true);
            } else {
                oldEntry.content.setOnClickListener(null);
                oldEntry.floatingIntent = null;
            }
            // Update the roundIcon
            prepareHaloNotification(oldEntry, notification, true);
            // Update the icon.
            final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), notification.getUser(), notification.getNotification().icon, notification.getNotification().iconLevel, notification.getNotification().number, notification.getNotification().tickerText);
            if (!oldEntry.icon.set(ic)) {
                handleNotificationError(key, notification, "Couldn't update icon: " + ic);
                return;
            }
            updateExpansionStates();
        } catch (RuntimeException e) {
            // It failed to add cleanly.  Log, and remove the view from the panel.
            Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e);
            removeNotificationViews(key);
            addNotificationViews(key, notification);
        }
    } else {
        if (DEBUG)
            Slog.d(TAG, "not reusing notification for key: " + key);
        if (DEBUG)
            Slog.d(TAG, "contents was " + (contentsUnchanged ? "unchanged" : "changed"));
        if (DEBUG)
            Slog.d(TAG, "order was " + (orderUnchanged ? "unchanged" : "changed"));
        if (DEBUG)
            Slog.d(TAG, "notification is " + (isTopAnyway ? "top" : "not top"));
        final boolean wasExpanded = oldEntry.userExpanded();
        removeNotificationViews(key);
        addNotificationViews(key, notification);
        if (wasExpanded) {
            final NotificationData.Entry newEntry = mNotificationData.findByKey(key);
            expandView(newEntry, true);
            newEntry.setUserExpanded(true);
        }
    }
    // Update the veto button accordingly (and as a result, whether this row is
    // swipe-dismissable)
    updateNotificationVetoButton(oldEntry.row, notification);
    // Is this for you?
    boolean isForCurrentUser = notificationIsForCurrentUser(notification);
    if (DEBUG)
        Slog.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you");
    // Restart the ticker if it's still running
    if (updateTicker && isForCurrentUser) {
        haltTicker();
        tick(key, notification, false);
    }
    // Recalculate the position of the sliding windows and the titles.
    setAreThereNotifications();
    updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
    // See if we need to update the intruder.
    if (ENABLE_INTRUDERS && oldNotification == mCurrentlyIntrudingNotification) {
        if (DEBUG)
            Slog.d(TAG, "updating the current intruder:" + notification);
        // the intruder.
        if (notification.getNotification().fullScreenIntent == null) {
            // TODO(dsandler): consistent logic with add()
            if (DEBUG)
                Slog.d(TAG, "no longer intrudes!");
            mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
        }
    }
    // Update halo
    if (mHalo != null)
        mHalo.update();
}
Also used : RemoteViews(android.widget.RemoteViews) StatusBarNotification(android.service.notification.StatusBarNotification) ViewGroup(android.view.ViewGroup) PendingIntent(android.app.PendingIntent) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ImageView(android.widget.ImageView) QuickSettingsContainerView(com.android.systemui.statusbar.phone.QuickSettingsContainerView) View(android.view.View) TextView(android.widget.TextView) SearchPanelView(com.android.systemui.SearchPanelView)

Example 9 with StatusBarIcon

use of com.android.internal.statusbar.StatusBarIcon in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method start.

public void start() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDisplay = mWindowManager.getDefaultDisplay();
    // set up
    mProvisioningObserver.onChange(false);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver);
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    mStatusBarContainer = new FrameLayout(mContext);
    mLocale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
    // Connect in to the status bar manager service
    StatusBarIconList iconList = new StatusBarIconList();
    ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
    ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
    mCommandQueue = new CommandQueue(this, iconList);
    int[] switches = new int[7];
    ArrayList<IBinder> binders = new ArrayList<IBinder>();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, switches, binders);
    } catch (RemoteException ex) {
    // If the system process isn't there we're doomed anyway.
    }
    mHaloActive = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HALO_ACTIVE, 0) == 1;
    createAndAddWindows();
    disable(switches[0]);
    setSystemUiVisibility(switches[1], 0xffffffff);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4]);
    setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
    // Set up the initial icon state
    int N = iconList.size();
    int viewIndex = 0;
    for (int i = 0; i < N; i++) {
        StatusBarIcon icon = iconList.getIcon(i);
        if (icon != null) {
            addIcon(iconList.getSlot(i), i, viewIndex, icon);
            viewIndex++;
        }
    }
    // Set up the initial notification state
    N = notificationKeys.size();
    if (N == notifications.size()) {
        for (int i = 0; i < N; i++) {
            addNotification(notificationKeys.get(i), notifications.get(i));
        }
    } else {
        Log.wtf(TAG, "Notification list length mismatch: keys=" + N + " notifications=" + notifications.size());
    }
    if (DEBUG) {
        Slog.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", iconList.size(), switches[0], switches[1], switches[2], switches[3]));
    }
    mCurrentUserId = ActivityManager.getCurrentUser();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (true)
                    Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
                userSwitched(mCurrentUserId);
            }
        }
    }, filter);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        Bitmap currentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(currentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        BitmapDrawable currentBitmapDrawable = new BitmapDrawable(currentBitmap);
        Bitmap newBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(newBitmap);
        mNewCanvas.drawColor(0xFF000000);
        BitmapDrawable newBitmapDrawable = new BitmapDrawable(newBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { currentBitmapDrawable, newBitmapDrawable });
        mBarView.setBackground(mTransition);
        mLastIconColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR);
        updateIconColor();
        updateBackgroundColor();
        // Listen for status bar icon color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.STATUS_ICON_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateIconColor();
            }
        });
        // Listen for status bar background color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateBackgroundColor();
            }
        });
        // Listen for per-app-color state changes, this one will revert to stock colors all over
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PER_APP_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                if (!ColorUtils.getPerAppColorState(mContext)) {
                    for (int i = 0; i < ExtendedPropertiesUtils.PARANOID_COLORS_COUNT; i++) {
                        ColorUtils.ColorSettingInfo colorInfo = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
                        ColorUtils.setColor(mContext, ExtendedPropertiesUtils.PARANOID_COLORS_SETTINGS[i], colorInfo.systemColorString, "NULL", 1, 250);
                    }
                }
            }
        });
    }
    attachPie();
    // Listen for PIE gravity
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PIE_GRAVITY), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updatePieControls();
        }
    });
    // Listen for HALO state
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_ACTIVE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHalo();
        }
    });
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            restartHalo();
        }
    });
    updateHalo();
    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
}
Also used : ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ContentObserver(android.database.ContentObserver) Context(android.content.Context) IntentFilter(android.content.IntentFilter) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StatusBarIconList(com.android.internal.statusbar.StatusBarIconList) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RemoteException(android.os.RemoteException)

Example 10 with StatusBarIcon

use of com.android.internal.statusbar.StatusBarIcon in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method prepareHaloNotification.

public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
    Notification notif = notification.getNotification();
    // Get the remote view
    try {
        if (!update) {
            ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
            if (mainView instanceof FrameLayout) {
                entry.haloContent = mainView.getChildAt(1);
                mainView.removeViewAt(1);
            } else {
                entry.haloContent = mainView;
            }
        } else {
            notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
        }
    } catch (Exception e) {
        // Non uniform content?
        android.util.Log.d("PARANOID", "   Non uniform content?");
    }
    // Construct the round icon
    final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
    int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
    int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
    int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
    int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
    Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(roundIcon);
    canvas.drawARGB(0, 0, 0, 0);
    // halo-bubble, we'll use that one and cut it round
    if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
        Paint smoothingPaint = new Paint();
        smoothingPaint.setAntiAlias(true);
        smoothingPaint.setFilterBitmap(true);
        smoothingPaint.setDither(true);
        canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
        smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        final int newWidth = iconSize;
        final int newHeight = iconSize * largeIconWidth / largeIconHeight;
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
        canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
    } else {
        try {
            Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
            if (icon == null)
                icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
            int margin = (iconSize - smallIconSize) / 2;
            icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
            icon.draw(canvas);
        } catch (Exception e) {
        // NameNotFoundException
        }
    }
    entry.roundIcon = roundIcon;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Paint(android.graphics.Paint) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) FrameLayout(android.widget.FrameLayout) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Aggregations

StatusBarIcon (com.android.internal.statusbar.StatusBarIcon)56 StatusBarNotification (android.service.notification.StatusBarNotification)16 Notification (android.app.Notification)13 RemoteException (android.os.RemoteException)13 ComponentName (android.content.ComponentName)10 Drawable (android.graphics.drawable.Drawable)8 StatusBarIconView (com.android.systemui.statusbar.StatusBarIconView)8 IBinder (android.os.IBinder)7 ArrayList (java.util.ArrayList)7 IntentFilter (android.content.IntentFilter)6 Rect (android.graphics.Rect)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 Configuration (android.content.res.Configuration)5 Icon (android.graphics.drawable.Icon)5 UserHandle (android.os.UserHandle)5 IVrManager (android.service.vr.IVrManager)5 LinearLayout (android.widget.LinearLayout)5 LockPatternUtils (com.android.internal.widget.LockPatternUtils)5 Entry (com.android.systemui.statusbar.NotificationData.Entry)5