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