Merge "[Status Bar Refactor] Improvements to StatusBarIconList:"
This commit is contained in:
committed by
Android (Google) Code Review
commit
164bb68d04
@@ -68,6 +68,7 @@ import com.android.systemui.statusbar.phone.ManagedProfileController;
|
||||
import com.android.systemui.statusbar.phone.ManagedProfileControllerImpl;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconControllerImpl;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconList;
|
||||
import com.android.systemui.statusbar.phone.StatusBarRemoteInputCallback;
|
||||
import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController;
|
||||
import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallFlags;
|
||||
@@ -252,6 +253,16 @@ public interface CentralSurfacesDependenciesModule {
|
||||
StatusBarIconController provideStatusBarIconController(
|
||||
StatusBarIconControllerImpl controllerImpl);
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provides
|
||||
@SysUISingleton
|
||||
static StatusBarIconList provideStatusBarIconList(Context context) {
|
||||
return new StatusBarIconList(
|
||||
context.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_statusBarIcons));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provides
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import static com.android.systemui.statusbar.phone.StatusBarIconList.Slot;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Icon;
|
||||
@@ -56,11 +58,12 @@ import javax.inject.Inject;
|
||||
* registered with it.
|
||||
*/
|
||||
@SysUISingleton
|
||||
public class StatusBarIconControllerImpl extends StatusBarIconList implements Tunable,
|
||||
public class StatusBarIconControllerImpl implements Tunable,
|
||||
ConfigurationListener, Dumpable, CommandQueue.Callbacks, StatusBarIconController, DemoMode {
|
||||
|
||||
private static final String TAG = "StatusBarIconController";
|
||||
|
||||
private final StatusBarIconList mStatusBarIconList;
|
||||
private final ArrayList<IconManager> mIconGroups = new ArrayList<>();
|
||||
private final ArraySet<String> mIconHideList = new ArraySet<>();
|
||||
|
||||
@@ -74,15 +77,12 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
DemoModeController demoModeController,
|
||||
ConfigurationController configurationController,
|
||||
TunerService tunerService,
|
||||
DumpManager dumpManager) {
|
||||
super(context.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_statusBarIcons));
|
||||
configurationController.addCallback(this);
|
||||
|
||||
DumpManager dumpManager,
|
||||
StatusBarIconList statusBarIconList) {
|
||||
mStatusBarIconList = statusBarIconList;
|
||||
mContext = context;
|
||||
|
||||
loadDimens();
|
||||
|
||||
configurationController.addCallback(this);
|
||||
commandQueue.addCallback(this);
|
||||
tunerService.addTunable(this, ICON_HIDE_LIST);
|
||||
demoModeController.addCallback(this);
|
||||
@@ -101,15 +101,14 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
|
||||
group.setController(this);
|
||||
mIconGroups.add(group);
|
||||
List<Slot> allSlots = getSlots();
|
||||
List<Slot> allSlots = mStatusBarIconList.getSlots();
|
||||
for (int i = 0; i < allSlots.size(); i++) {
|
||||
Slot slot = allSlots.get(i);
|
||||
List<StatusBarIconHolder> holders = slot.getHolderListInViewOrder();
|
||||
boolean hidden = mIconHideList.contains(slot.getName());
|
||||
|
||||
for (StatusBarIconHolder holder : holders) {
|
||||
int tag = holder.getTag();
|
||||
int viewIndex = getViewIndex(getSlotIndex(slot.getName()), holder.getTag());
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slot.getName(), holder.getTag());
|
||||
group.onIconAdded(viewIndex, slot.getName(), hidden, holder);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +143,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
}
|
||||
mIconHideList.clear();
|
||||
mIconHideList.addAll(StatusBarIconController.getIconHideList(mContext, newValue));
|
||||
ArrayList<Slot> currentSlots = getSlots();
|
||||
List<Slot> currentSlots = mStatusBarIconList.getSlots();
|
||||
ArrayMap<Slot, List<StatusBarIconHolder>> slotsToReAdd = new ArrayMap<>();
|
||||
|
||||
// This is a little hacky... Peel off all of the holders on all of the slots
|
||||
@@ -163,17 +162,13 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
List<StatusBarIconHolder> iconsForSlot = slotsToReAdd.get(item);
|
||||
if (iconsForSlot == null) continue;
|
||||
for (StatusBarIconHolder holder : iconsForSlot) {
|
||||
setIcon(getSlotIndex(item.getName()), holder);
|
||||
setIcon(item.getName(), holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDimens() {
|
||||
}
|
||||
|
||||
private void addSystemIcon(int index, StatusBarIconHolder holder) {
|
||||
String slot = getSlotName(index);
|
||||
int viewIndex = getViewIndex(index, holder.getTag());
|
||||
private void addSystemIcon(String slot, StatusBarIconHolder holder) {
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slot, holder.getTag());
|
||||
boolean hidden = mIconHideList.contains(slot);
|
||||
|
||||
mIconGroups.forEach(l -> l.onIconAdded(viewIndex, slot, hidden, holder));
|
||||
@@ -182,18 +177,17 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
/** */
|
||||
@Override
|
||||
public void setIcon(String slot, int resourceId, CharSequence contentDescription) {
|
||||
int index = getSlotIndex(slot);
|
||||
StatusBarIconHolder holder = getIcon(index, 0);
|
||||
StatusBarIconHolder holder = mStatusBarIconList.getIconHolder(slot, 0);
|
||||
if (holder == null) {
|
||||
StatusBarIcon icon = new StatusBarIcon(UserHandle.SYSTEM, mContext.getPackageName(),
|
||||
Icon.createWithResource(
|
||||
mContext, resourceId), 0, 0, contentDescription);
|
||||
holder = StatusBarIconHolder.fromIcon(icon);
|
||||
setIcon(index, holder);
|
||||
setIcon(slot, holder);
|
||||
} else {
|
||||
holder.getIcon().icon = Icon.createWithResource(mContext, resourceId);
|
||||
holder.getIcon().contentDescription = contentDescription;
|
||||
handleSet(index, holder);
|
||||
handleSet(slot, holder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,21 +197,18 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
*/
|
||||
@Override
|
||||
public void setSignalIcon(String slot, WifiIconState state) {
|
||||
|
||||
int index = getSlotIndex(slot);
|
||||
|
||||
if (state == null) {
|
||||
removeIcon(index, 0);
|
||||
removeIcon(slot, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
StatusBarIconHolder holder = getIcon(index, 0);
|
||||
StatusBarIconHolder holder = mStatusBarIconList.getIconHolder(slot, 0);
|
||||
if (holder == null) {
|
||||
holder = StatusBarIconHolder.fromWifiIconState(state);
|
||||
setIcon(index, holder);
|
||||
setIcon(slot, holder);
|
||||
} else {
|
||||
holder.setWifiState(state);
|
||||
handleSet(index, holder);
|
||||
handleSet(slot, holder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,8 +220,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
*/
|
||||
@Override
|
||||
public void setMobileIcons(String slot, List<MobileIconState> iconStates) {
|
||||
Slot mobileSlot = getSlot(slot);
|
||||
int slotIndex = getSlotIndex(slot);
|
||||
Slot mobileSlot = mStatusBarIconList.getSlot(slot);
|
||||
|
||||
// Reverse the sort order to show icons with left to right([Slot1][Slot2]..).
|
||||
// StatusBarIconList has UI design that first items go to the right of second items.
|
||||
@@ -241,10 +231,10 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
StatusBarIconHolder holder = mobileSlot.getHolderForTag(state.subId);
|
||||
if (holder == null) {
|
||||
holder = StatusBarIconHolder.fromMobileIconState(state);
|
||||
setIcon(slotIndex, holder);
|
||||
setIcon(slot, holder);
|
||||
} else {
|
||||
holder.setMobileState(state);
|
||||
handleSet(slotIndex, holder);
|
||||
handleSet(slot, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,21 +246,19 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
*/
|
||||
@Override
|
||||
public void setCallStrengthIcons(String slot, List<CallIndicatorIconState> states) {
|
||||
Slot callStrengthSlot = getSlot(slot);
|
||||
int callStrengthSlotIndex = getSlotIndex(slot);
|
||||
Slot callStrengthSlot = mStatusBarIconList.getSlot(slot);
|
||||
Collections.reverse(states);
|
||||
for (CallIndicatorIconState state : states) {
|
||||
if (!state.isNoCalling) {
|
||||
StatusBarIconHolder holder = callStrengthSlot.getHolderForTag(state.subId);
|
||||
if (holder == null) {
|
||||
holder = StatusBarIconHolder.fromCallIndicatorState(mContext, state);
|
||||
setIcon(callStrengthSlotIndex, holder);
|
||||
} else {
|
||||
holder.setIcon(new StatusBarIcon(UserHandle.SYSTEM, mContext.getPackageName(),
|
||||
Icon.createWithResource(mContext, state.callStrengthResId), 0, 0,
|
||||
state.callStrengthDescription));
|
||||
setIcon(callStrengthSlotIndex, holder);
|
||||
}
|
||||
setIcon(slot, holder);
|
||||
}
|
||||
setIconVisibility(slot, !state.isNoCalling, state.subId);
|
||||
}
|
||||
@@ -283,21 +271,19 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
*/
|
||||
@Override
|
||||
public void setNoCallingIcons(String slot, List<CallIndicatorIconState> states) {
|
||||
Slot noCallingSlot = getSlot(slot);
|
||||
int noCallingSlotIndex = getSlotIndex(slot);
|
||||
Slot noCallingSlot = mStatusBarIconList.getSlot(slot);
|
||||
Collections.reverse(states);
|
||||
for (CallIndicatorIconState state : states) {
|
||||
if (state.isNoCalling) {
|
||||
StatusBarIconHolder holder = noCallingSlot.getHolderForTag(state.subId);
|
||||
if (holder == null) {
|
||||
holder = StatusBarIconHolder.fromCallIndicatorState(mContext, state);
|
||||
setIcon(noCallingSlotIndex, holder);
|
||||
} else {
|
||||
holder.setIcon(new StatusBarIcon(UserHandle.SYSTEM, mContext.getPackageName(),
|
||||
Icon.createWithResource(mContext, state.noCallingResId), 0, 0,
|
||||
state.noCallingDescription));
|
||||
setIcon(noCallingSlotIndex, holder);
|
||||
}
|
||||
setIcon(slot, holder);
|
||||
}
|
||||
setIconVisibility(slot, state.isNoCalling, state.subId);
|
||||
}
|
||||
@@ -305,42 +291,31 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
|
||||
@Override
|
||||
public void setExternalIcon(String slot) {
|
||||
int viewIndex = getViewIndex(getSlotIndex(slot), 0);
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slot, 0);
|
||||
int height = mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.status_bar_icon_drawing_size);
|
||||
mIconGroups.forEach(l -> l.onIconExternal(viewIndex, height));
|
||||
}
|
||||
|
||||
//TODO: remove this (used in command queue and for 3rd party tiles?)
|
||||
@Override
|
||||
public void setIcon(String slot, StatusBarIcon icon) {
|
||||
setIcon(getSlotIndex(slot), icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* For backwards compatibility, in the event that someone gives us a slot and a status bar icon
|
||||
*/
|
||||
private void setIcon(int index, StatusBarIcon icon) {
|
||||
String slot = getSlotName(index);
|
||||
if (icon == null) {
|
||||
removeAllIconsForSlot(slot);
|
||||
return;
|
||||
}
|
||||
|
||||
StatusBarIconHolder holder = StatusBarIconHolder.fromIcon(icon);
|
||||
setIcon(index, holder);
|
||||
setIcon(slot, holder);
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
public void setIcon(int index, @NonNull StatusBarIconHolder holder) {
|
||||
boolean isNew = getIcon(index, holder.getTag()) == null;
|
||||
super.setIcon(index, holder);
|
||||
private void setIcon(String slot, @NonNull StatusBarIconHolder holder) {
|
||||
boolean isNew = mStatusBarIconList.getIconHolder(slot, holder.getTag()) == null;
|
||||
mStatusBarIconList.setIcon(slot, holder);
|
||||
|
||||
if (isNew) {
|
||||
addSystemIcon(index, holder);
|
||||
addSystemIcon(slot, holder);
|
||||
} else {
|
||||
handleSet(index, holder);
|
||||
handleSet(slot, holder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,34 +326,33 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
|
||||
/** */
|
||||
public void setIconVisibility(String slot, boolean visibility, int tag) {
|
||||
int index = getSlotIndex(slot);
|
||||
StatusBarIconHolder holder = getIcon(index, tag);
|
||||
StatusBarIconHolder holder = mStatusBarIconList.getIconHolder(slot, tag);
|
||||
if (holder == null || holder.isVisible() == visibility) {
|
||||
return;
|
||||
}
|
||||
|
||||
holder.setVisible(visibility);
|
||||
handleSet(index, holder);
|
||||
handleSet(slot, holder);
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
public void setIconAccessibilityLiveRegion(String slotName, int accessibilityLiveRegion) {
|
||||
Slot slot = getSlot(slotName);
|
||||
Slot slot = mStatusBarIconList.getSlot(slotName);
|
||||
if (!slot.hasIconsInSlot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int slotIndex = getSlotIndex(slotName);
|
||||
List<StatusBarIconHolder> iconsToUpdate = slot.getHolderListInViewOrder();
|
||||
for (StatusBarIconHolder holder : iconsToUpdate) {
|
||||
int viewIndex = getViewIndex(slotIndex, holder.getTag());
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slotName, holder.getTag());
|
||||
mIconGroups.forEach(l -> l.mGroup.getChildAt(viewIndex)
|
||||
.setAccessibilityLiveRegion(accessibilityLiveRegion));
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
public void removeIcon(String slot) {
|
||||
removeAllIconsForSlot(slot);
|
||||
}
|
||||
@@ -386,39 +360,34 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
/** */
|
||||
@Override
|
||||
public void removeIcon(String slot, int tag) {
|
||||
removeIcon(getSlotIndex(slot), tag);
|
||||
if (mStatusBarIconList.getIconHolder(slot, tag) == null) {
|
||||
return;
|
||||
}
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slot, tag);
|
||||
mStatusBarIconList.removeIcon(slot, tag);
|
||||
mIconGroups.forEach(l -> l.onRemoveIcon(viewIndex));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
public void removeAllIconsForSlot(String slotName) {
|
||||
Slot slot = getSlot(slotName);
|
||||
Slot slot = mStatusBarIconList.getSlot(slotName);
|
||||
if (!slot.hasIconsInSlot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int slotIndex = getSlotIndex(slotName);
|
||||
List<StatusBarIconHolder> iconsToRemove = slot.getHolderListInViewOrder();
|
||||
for (StatusBarIconHolder holder : iconsToRemove) {
|
||||
int viewIndex = getViewIndex(slotIndex, holder.getTag());
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slotName, holder.getTag());
|
||||
slot.removeForTag(holder.getTag());
|
||||
mIconGroups.forEach(l -> l.onRemoveIcon(viewIndex));
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
public void removeIcon(int index, int tag) {
|
||||
if (getIcon(index, tag) == null) {
|
||||
return;
|
||||
}
|
||||
super.removeIcon(index, tag);
|
||||
int viewIndex = getViewIndex(index, 0);
|
||||
mIconGroups.forEach(l -> l.onRemoveIcon(viewIndex));
|
||||
}
|
||||
|
||||
private void handleSet(int index, StatusBarIconHolder holder) {
|
||||
int viewIndex = getViewIndex(index, holder.getTag());
|
||||
|
||||
private void handleSet(String slotName, StatusBarIconHolder holder) {
|
||||
int viewIndex = mStatusBarIconList.getViewIndex(slotName, holder.getTag());
|
||||
mIconGroups.forEach(l -> l.onSetIconHolder(viewIndex, holder));
|
||||
}
|
||||
|
||||
@@ -438,7 +407,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
}
|
||||
}
|
||||
|
||||
super.dump(pw);
|
||||
mStatusBarIconList.dump(pw);
|
||||
}
|
||||
|
||||
/** */
|
||||
@@ -482,7 +451,6 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
/** */
|
||||
@Override
|
||||
public void onDensityOrFontScaleChanged() {
|
||||
loadDimens();
|
||||
refreshIconGroups();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,60 +25,72 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** A class holding the list of all the system icons that could be shown in the status bar. */
|
||||
public class StatusBarIconList {
|
||||
private ArrayList<Slot> mSlots = new ArrayList<>();
|
||||
private final ArrayList<Slot> mSlots = new ArrayList<>();
|
||||
private final List<Slot> mViewOnlySlots = Collections.unmodifiableList(mSlots);
|
||||
|
||||
public StatusBarIconList(String[] slots) {
|
||||
final int N = slots.length;
|
||||
for (int i=0; i < N; i++) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
mSlots.add(new Slot(slots[i], null));
|
||||
}
|
||||
}
|
||||
|
||||
public int getSlotIndex(String slot) {
|
||||
final int N = mSlots.size();
|
||||
for (int i=0; i<N; i++) {
|
||||
Slot item = mSlots.get(i);
|
||||
if (item.getName().equals(slot)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// Auto insert new items at the beginning.
|
||||
mSlots.add(0, new Slot(slot, null));
|
||||
return 0;
|
||||
/** Returns the list of current slots. */
|
||||
public List<Slot> getSlots() {
|
||||
return mViewOnlySlots;
|
||||
}
|
||||
|
||||
protected ArrayList<Slot> getSlots() {
|
||||
return new ArrayList<>(mSlots);
|
||||
/**
|
||||
* Gets the slot with the given {@code name}, or creates a new slot if we don't already have a
|
||||
* slot by that name.
|
||||
*
|
||||
* If a new slot is created, that slot will be inserted at the front of the list.
|
||||
*
|
||||
* TODO(b/237533036): Rename this to getOrCreateSlot to make it more clear that it could create
|
||||
* a new slot. Other methods in this class will also create a new slot if we don't have one,
|
||||
* should those be re-named too?
|
||||
*/
|
||||
public Slot getSlot(String name) {
|
||||
return mSlots.get(findOrInsertSlot(name));
|
||||
}
|
||||
|
||||
protected Slot getSlot(String name) {
|
||||
return mSlots.get(getSlotIndex(name));
|
||||
/**
|
||||
* Sets the icon in {@code holder} to be associated with the slot with the given
|
||||
* {@code slotName}.
|
||||
*/
|
||||
public void setIcon(String slotName, @NonNull StatusBarIconHolder holder) {
|
||||
mSlots.get(findOrInsertSlot(slotName)).addHolder(holder);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mSlots.size();
|
||||
/**
|
||||
* Removes the icon holder that we had associated with {@code slotName}'s slot at the given
|
||||
* {@code tag}.
|
||||
*/
|
||||
public void removeIcon(String slotName, int tag) {
|
||||
mSlots.get(findOrInsertSlot(slotName)).removeForTag(tag);
|
||||
}
|
||||
|
||||
public void setIcon(int index, @NonNull StatusBarIconHolder holder) {
|
||||
mSlots.get(index).addHolder(holder);
|
||||
/**
|
||||
* Returns the icon holder currently associated with {@code slotName}'s slot at the given
|
||||
* {@code tag}, or null if we don't have one.
|
||||
*/
|
||||
@Nullable
|
||||
public StatusBarIconHolder getIconHolder(String slotName, int tag) {
|
||||
return mSlots.get(findOrInsertSlot(slotName)).getHolderForTag(tag);
|
||||
}
|
||||
|
||||
public void removeIcon(int index, int tag) {
|
||||
mSlots.get(index).removeForTag(tag);
|
||||
}
|
||||
|
||||
public String getSlotName(int index) {
|
||||
return mSlots.get(index).getName();
|
||||
}
|
||||
|
||||
public StatusBarIconHolder getIcon(int index, int tag) {
|
||||
return mSlots.get(index).getHolderForTag(tag);
|
||||
}
|
||||
|
||||
public int getViewIndex(int slotIndex, int tag) {
|
||||
/**
|
||||
* Returns the index of the icon in {@code slotName}'s slot at the given {@code tag}.
|
||||
*
|
||||
* Note that a single slot can have multiple icons, and this function takes that into account.
|
||||
*/
|
||||
public int getViewIndex(String slotName, int tag) {
|
||||
int slotIndex = findOrInsertSlot(slotName);
|
||||
int count = 0;
|
||||
for (int i = 0; i < slotIndex; i++) {
|
||||
Slot item = mSlots.get(i);
|
||||
@@ -100,6 +112,25 @@ public class StatusBarIconList {
|
||||
}
|
||||
}
|
||||
|
||||
private int findOrInsertSlot(String slot) {
|
||||
final int N = mSlots.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
Slot item = mSlots.get(i);
|
||||
if (item.getName().equals(slot)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// Auto insert new items at the beginning.
|
||||
mSlots.add(0, new Slot(slot, null));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A class representing one slot in the status bar system icons view.
|
||||
*
|
||||
* Note that one slot can have multiple icons associated with it.
|
||||
*/
|
||||
public static class Slot {
|
||||
private final String mName;
|
||||
private StatusBarIconHolder mHolder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import static com.android.systemui.statusbar.phone.StatusBarIconController.TAG_PRIMARY;
|
||||
@@ -9,13 +25,10 @@ import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconHolder;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconList;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconList.Slot;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -33,28 +46,39 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testGetExistingSlot() {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
assertEquals(1, statusBarIconList.getSlotIndex("bbb"));
|
||||
assertEquals(2, statusBarIconList.getSlotIndex("ccc"));
|
||||
|
||||
List<Slot> slots = statusBarIconList.getSlots();
|
||||
assertEquals(3, slots.size());
|
||||
assertEquals("aaa", slots.get(0).getName());
|
||||
assertEquals("bbb", slots.get(1).getName());
|
||||
assertEquals("ccc", slots.get(2).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonexistingSlot() {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
assertEquals(0, statusBarIconList.getSlotIndex("aaa"));
|
||||
assertEquals(3, statusBarIconList.size());
|
||||
assertEquals(0, statusBarIconList.getSlotIndex("zzz")); // new content added in front
|
||||
assertEquals(1, statusBarIconList.getSlotIndex("aaa")); // slid back
|
||||
assertEquals(4, statusBarIconList.size());
|
||||
|
||||
statusBarIconList.getSlot("zzz");
|
||||
|
||||
List<Slot> slots = statusBarIconList.getSlots();
|
||||
assertEquals(4, slots.size());
|
||||
// new content added in front, so zzz should be first and aaa should slide back to second
|
||||
assertEquals("zzz", slots.get(0).getName());
|
||||
assertEquals("aaa", slots.get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSlotSlidesIcons() {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
StatusBarIconHolder sbHolder = mock(StatusBarIconHolder.class);
|
||||
statusBarIconList.setIcon(0, sbHolder);
|
||||
statusBarIconList.getSlotIndex("zzz"); // new content added in front
|
||||
assertNull(statusBarIconList.getIcon(0, TAG_PRIMARY));
|
||||
assertEquals(sbHolder, statusBarIconList.getIcon(1, TAG_PRIMARY));
|
||||
statusBarIconList.setIcon("aaa", sbHolder);
|
||||
|
||||
statusBarIconList.getSlot("zzz");
|
||||
|
||||
List<Slot> slots = statusBarIconList.getSlots();
|
||||
// new content added in front, so the holder we set on "aaa" should show up at index 1
|
||||
assertNull(slots.get(0).getHolderForTag(TAG_PRIMARY));
|
||||
assertEquals(sbHolder, slots.get(1).getHolderForTag(TAG_PRIMARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,11 +86,13 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
StatusBarIconHolder sbHolderA = mock(StatusBarIconHolder.class);
|
||||
StatusBarIconHolder sbHolderB = mock(StatusBarIconHolder.class);
|
||||
statusBarIconList.setIcon(0, sbHolderA);
|
||||
statusBarIconList.setIcon(1, sbHolderB);
|
||||
assertEquals(sbHolderA, statusBarIconList.getIcon(0, TAG_PRIMARY));
|
||||
assertEquals(sbHolderB, statusBarIconList.getIcon(1, TAG_PRIMARY));
|
||||
assertNull(statusBarIconList.getIcon(2, TAG_PRIMARY)); // icon not set
|
||||
|
||||
statusBarIconList.setIcon("aaa", sbHolderA);
|
||||
statusBarIconList.setIcon("bbb", sbHolderB);
|
||||
|
||||
assertEquals(sbHolderA, statusBarIconList.getIconHolder("aaa", TAG_PRIMARY));
|
||||
assertEquals(sbHolderB, statusBarIconList.getIconHolder("bbb", TAG_PRIMARY));
|
||||
assertNull(statusBarIconList.getIconHolder("ccc", TAG_PRIMARY)); // icon not set
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,24 +100,31 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
StatusBarIconHolder sbHolderA = mock(StatusBarIconHolder.class);
|
||||
StatusBarIconHolder sbHolderB = mock(StatusBarIconHolder.class);
|
||||
statusBarIconList.setIcon(0, sbHolderA);
|
||||
statusBarIconList.setIcon(1, sbHolderB);
|
||||
statusBarIconList.removeIcon(0, TAG_PRIMARY);
|
||||
assertNull(statusBarIconList.getIcon(0, TAG_PRIMARY)); // icon not set
|
||||
|
||||
statusBarIconList.setIcon("aaa", sbHolderA);
|
||||
statusBarIconList.setIcon("bbb", sbHolderB);
|
||||
|
||||
statusBarIconList.removeIcon("aaa", TAG_PRIMARY);
|
||||
|
||||
assertNull(statusBarIconList.getIconHolder("aaa", TAG_PRIMARY)); // icon not set
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetViewIndex_NoMultiples() {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
StatusBarIconHolder sbHolder = mock(StatusBarIconHolder.class);
|
||||
statusBarIconList.setIcon(2, sbHolder);
|
||||
// Icon for item 2 is 0th child view.
|
||||
assertEquals(0, statusBarIconList.getViewIndex(2, TAG_PRIMARY));
|
||||
statusBarIconList.setIcon(0, sbHolder);
|
||||
// Icon for item 0 is 0th child view,
|
||||
assertEquals(0, statusBarIconList.getViewIndex(0, TAG_PRIMARY));
|
||||
// and item 2 is now 1st child view.
|
||||
assertEquals(1, statusBarIconList.getViewIndex(2, TAG_PRIMARY));
|
||||
|
||||
statusBarIconList.setIcon("ccc", sbHolder);
|
||||
|
||||
// Since only "ccc" has a holder set, it should be first
|
||||
assertEquals(0, statusBarIconList.getViewIndex("ccc", TAG_PRIMARY));
|
||||
|
||||
// Now, also set a holder for "aaa"
|
||||
statusBarIconList.setIcon("aaa", sbHolder);
|
||||
|
||||
// Then "aaa" gets the first view index and "ccc" gets the second
|
||||
assertEquals(0, statusBarIconList.getViewIndex("aaa", TAG_PRIMARY));
|
||||
assertEquals(1, statusBarIconList.getViewIndex("ccc", TAG_PRIMARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +132,7 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
StatusBarIconList statusBarIconList = new StatusBarIconList(STATUS_BAR_SLOTS);
|
||||
StatusBarIconHolder sbHolder = mock(StatusBarIconHolder.class);
|
||||
|
||||
statusBarIconList.setIcon(2, sbHolder); // item 2, one icon 0th child
|
||||
statusBarIconList.setIcon("ccc", sbHolder);
|
||||
|
||||
// All of these can be added to the same slot
|
||||
// no tag bc it defaults to 0
|
||||
@@ -111,23 +144,23 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
int sb4Tag = 2;
|
||||
when(sbHolder4.getTag()).thenReturn(sb4Tag);
|
||||
|
||||
// Put a holder at slot 1, verify that it is first
|
||||
statusBarIconList.setIcon(1, sbHolder2);
|
||||
assertEquals(0, statusBarIconList.getViewIndex(1, TAG_PRIMARY));
|
||||
// Put a holder for "bbb", verify that it is first
|
||||
statusBarIconList.setIcon("bbb", sbHolder2);
|
||||
assertEquals(0, statusBarIconList.getViewIndex("bbb", TAG_PRIMARY));
|
||||
|
||||
// Put another holder at slot 1, verify it's index 0 and the rest come after
|
||||
statusBarIconList.setIcon(1, sbHolder3);
|
||||
assertEquals(0, statusBarIconList.getViewIndex(1, sb3Tag));
|
||||
assertEquals(1, statusBarIconList.getViewIndex(1, TAG_PRIMARY));
|
||||
// First icon should be at the end
|
||||
assertEquals(2, statusBarIconList.getViewIndex(2, TAG_PRIMARY));
|
||||
// Put another holder for "bbb" at slot 1, verify its index 0 and the rest come after
|
||||
statusBarIconList.setIcon("bbb", sbHolder3);
|
||||
assertEquals(0, statusBarIconList.getViewIndex("bbb", sb3Tag));
|
||||
assertEquals(1, statusBarIconList.getViewIndex("bbb", TAG_PRIMARY));
|
||||
// "ccc" should appear at the end
|
||||
assertEquals(2, statusBarIconList.getViewIndex("ccc", TAG_PRIMARY));
|
||||
|
||||
// Put another one in there just for good measure
|
||||
statusBarIconList.setIcon(1, sbHolder4);
|
||||
assertEquals(0, statusBarIconList.getViewIndex(1, sb4Tag));
|
||||
assertEquals(1, statusBarIconList.getViewIndex(1, sb3Tag));
|
||||
assertEquals(2, statusBarIconList.getViewIndex(1, TAG_PRIMARY));
|
||||
assertEquals(3, statusBarIconList.getViewIndex(2, TAG_PRIMARY));
|
||||
// Put another one in "bbb" just for good measure
|
||||
statusBarIconList.setIcon("bbb", sbHolder4);
|
||||
assertEquals(0, statusBarIconList.getViewIndex("bbb", sb4Tag));
|
||||
assertEquals(1, statusBarIconList.getViewIndex("bbb", sb3Tag));
|
||||
assertEquals(2, statusBarIconList.getViewIndex("bbb", TAG_PRIMARY));
|
||||
assertEquals(3, statusBarIconList.getViewIndex("ccc", TAG_PRIMARY));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,4 +205,4 @@ public class StatusBarIconListTest extends SysuiTestCase {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user