15cf1d0589a0045ee5f01802975f394847e891215Selim Cinek/* 25cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Copyright (C) 2017 The Android Open Source Project 35cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 45cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 55cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * you may not use this file except in compliance with the License. 65cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * You may obtain a copy of the License at 75cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 85cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 95cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * 105cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * Unless required by applicable law or agreed to in writing, software 115cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 125cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * See the License for the specific language governing permissions and 145cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * limitations under the License 155cf1d0589a0045ee5f01802975f394847e891215Selim Cinek */ 165cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 175cf1d0589a0045ee5f01802975f394847e891215Selim Cinekpackage com.android.systemui.statusbar.notification; 185cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 195cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport android.view.View; 205cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport android.view.ViewGroup; 215cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 225cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport com.android.internal.annotations.VisibleForTesting; 235cf1d0589a0045ee5f01802975f394847e891215Selim Cinekimport com.android.systemui.statusbar.ExpandableNotificationRow; 245cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 255cf1d0589a0045ee5f01802975f394847e891215Selim Cinek/** 265cf1d0589a0045ee5f01802975f394847e891215Selim Cinek * An observer that listens to the above shelf state and can notify listeners 275cf1d0589a0045ee5f01802975f394847e891215Selim Cinek */ 285cf1d0589a0045ee5f01802975f394847e891215Selim Cinekpublic class AboveShelfObserver implements AboveShelfChangedListener { 295cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 305cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private final ViewGroup mHostLayout; 315cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private boolean mHasViewsAboveShelf = false; 325cf1d0589a0045ee5f01802975f394847e891215Selim Cinek private HasViewAboveShelfChangedListener mListener; 335cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 345cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public AboveShelfObserver(ViewGroup hostLayout) { 355cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mHostLayout = hostLayout; 365cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 375cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 385cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void setListener(HasViewAboveShelfChangedListener listener) { 395cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mListener = listener; 405cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 415cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 425cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @Override 435cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public void onAboveShelfStateChanged(boolean aboveShelf) { 445cf1d0589a0045ee5f01802975f394847e891215Selim Cinek boolean hasViewsAboveShelf = aboveShelf; 455cf1d0589a0045ee5f01802975f394847e891215Selim Cinek if (!hasViewsAboveShelf && mHostLayout != null) { 465cf1d0589a0045ee5f01802975f394847e891215Selim Cinek int n = mHostLayout.getChildCount(); 475cf1d0589a0045ee5f01802975f394847e891215Selim Cinek for (int i = 0; i < n; i++) { 485cf1d0589a0045ee5f01802975f394847e891215Selim Cinek View child = mHostLayout.getChildAt(i); 495cf1d0589a0045ee5f01802975f394847e891215Selim Cinek if (child instanceof ExpandableNotificationRow) { 505cf1d0589a0045ee5f01802975f394847e891215Selim Cinek if (((ExpandableNotificationRow) child).isAboveShelf()) { 515cf1d0589a0045ee5f01802975f394847e891215Selim Cinek hasViewsAboveShelf = true; 525cf1d0589a0045ee5f01802975f394847e891215Selim Cinek break; 535cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 545cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 555cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 565cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 575cf1d0589a0045ee5f01802975f394847e891215Selim Cinek if (mHasViewsAboveShelf != hasViewsAboveShelf) { 585cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mHasViewsAboveShelf = hasViewsAboveShelf; 595cf1d0589a0045ee5f01802975f394847e891215Selim Cinek if (mListener != null) { 605cf1d0589a0045ee5f01802975f394847e891215Selim Cinek mListener.onHasViewsAboveShelfChanged(hasViewsAboveShelf); 615cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 625cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 635cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 645cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 655cf1d0589a0045ee5f01802975f394847e891215Selim Cinek @VisibleForTesting 665cf1d0589a0045ee5f01802975f394847e891215Selim Cinek boolean hasViewsAboveShelf() { 675cf1d0589a0045ee5f01802975f394847e891215Selim Cinek return mHasViewsAboveShelf; 685cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 695cf1d0589a0045ee5f01802975f394847e891215Selim Cinek 705cf1d0589a0045ee5f01802975f394847e891215Selim Cinek public interface HasViewAboveShelfChangedListener { 715cf1d0589a0045ee5f01802975f394847e891215Selim Cinek void onHasViewsAboveShelfChanged(boolean hasViewsAboveShelf); 725cf1d0589a0045ee5f01802975f394847e891215Selim Cinek } 735cf1d0589a0045ee5f01802975f394847e891215Selim Cinek} 74