1/* 2 * Copyright (C) 2015 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.phone; 18 19import com.android.internal.statusbar.StatusBarIcon; 20 21import java.io.PrintWriter; 22import java.util.ArrayList; 23 24public class StatusBarIconList { 25 private ArrayList<String> mSlots = new ArrayList<>(); 26 private ArrayList<StatusBarIcon> mIcons = new ArrayList<>(); 27 28 public void defineSlots(String[] slots) { 29 mSlots.clear(); 30 final int N = slots.length; 31 for (int i=0; i < N; i++) { 32 mSlots.add(slots[i]); 33 if (mIcons.size() < mSlots.size()) { 34 mIcons.add(null); 35 } 36 } 37 } 38 39 public int getSlotIndex(String slot) { 40 final int N = mSlots.size(); 41 for (int i=0; i<N; i++) { 42 if (slot.equals(mSlots.get(i))) { 43 return i; 44 } 45 } 46 // Auto insert new items at the beginning. 47 mSlots.add(0, slot); 48 mIcons.add(0, null); 49 return 0; 50 } 51 52 public int size() { 53 return mSlots.size(); 54 } 55 56 public void setIcon(int index, StatusBarIcon icon) { 57 mIcons.set(index, icon); 58 } 59 60 public void removeIcon(int index) { 61 mIcons.set(index, null); 62 } 63 64 public String getSlot(int index) { 65 return mSlots.get(index); 66 } 67 68 public StatusBarIcon getIcon(int index) { 69 return mIcons.get(index); 70 } 71 72 public int getViewIndex(int index) { 73 int count = 0; 74 for (int i = 0; i < index; i++) { 75 if (mIcons.get(i) != null) { 76 count++; 77 } 78 } 79 return count; 80 } 81 82 public void dump(PrintWriter pw) { 83 final int N = mSlots.size(); 84 pw.println("Icon list:"); 85 for (int i=0; i<N; i++) { 86 pw.printf(" %2d: (%s) %s\n", i, mSlots.get(i), mIcons.get(i)); 87 } 88 } 89} 90