Home | History | Annotate | Download | only in model
      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 
     17 package com.android.systemui.recents.model;
     18 
     19 import android.graphics.Rect;
     20 
     21 import java.util.ArrayList;
     22 
     23 
     24 /**
     25  * The full recents space is partitioned using a BSP into various nodes that define where task
     26  * stacks should be placed.
     27  */
     28 public class SpaceNode {
     29     /* BSP node callbacks */
     30     public interface SpaceNodeCallbacks {
     31         /** Notifies when a node is added */
     32         public void onSpaceNodeAdded(SpaceNode node);
     33         /** Notifies when a node is measured */
     34         public void onSpaceNodeMeasured(SpaceNode node, Rect rect);
     35     }
     36 
     37     SpaceNode mStartNode;
     38     SpaceNode mEndNode;
     39 
     40     TaskStack mStack;
     41 
     42     public SpaceNode() {
     43         // Do nothing
     44     }
     45 
     46     /** Sets the current stack for this space node */
     47     public void setStack(TaskStack stack) {
     48         mStack = stack;
     49     }
     50 
     51     /** Returns the task stack (not null if this is a leaf) */
     52     TaskStack getStack() {
     53         return mStack;
     54     }
     55 
     56     /** Returns whether there are any tasks in any stacks below this node. */
     57     public boolean hasTasks() {
     58         return (mStack.getTaskCount() > 0) ||
     59                 (mStartNode != null && mStartNode.hasTasks()) ||
     60                 (mEndNode != null && mEndNode.hasTasks());
     61     }
     62 
     63     /** Returns whether this is a leaf node */
     64     boolean isLeafNode() {
     65         return (mStartNode == null) && (mEndNode == null);
     66     }
     67 
     68     /** Returns all the descendent task stacks */
     69     private void getStacksRec(ArrayList<TaskStack> stacks) {
     70         if (isLeafNode()) {
     71             stacks.add(mStack);
     72         } else {
     73             mStartNode.getStacksRec(stacks);
     74             mEndNode.getStacksRec(stacks);
     75         }
     76     }
     77     public ArrayList<TaskStack> getStacks() {
     78         ArrayList<TaskStack> stacks = new ArrayList<TaskStack>();
     79         getStacksRec(stacks);
     80         return stacks;
     81     }
     82 }
     83