Merge "Remove complication id from entry mapping on removal." into tm-dev
This commit is contained in:
@@ -540,13 +540,15 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
/**
|
/**
|
||||||
* Removes a complication by {@link ComplicationId}.
|
* Removes a complication by {@link ComplicationId}.
|
||||||
*/
|
*/
|
||||||
public void removeComplication(ComplicationId id) {
|
public boolean removeComplication(ComplicationId id) {
|
||||||
if (!mEntries.containsKey(id)) {
|
final ViewEntry entry = mEntries.remove(id);
|
||||||
|
|
||||||
|
if (entry == null) {
|
||||||
Log.e(TAG, "could not find id:" + id);
|
Log.e(TAG, "could not find id:" + id);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ViewEntry entry = mEntries.get(id);
|
|
||||||
entry.remove();
|
entry.remove();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.systemui.dreams.complication;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -414,4 +415,37 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
|
|||||||
assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue();
|
assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures a second removal of a complication is a no-op.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testDoubleRemoval() {
|
||||||
|
final ComplicationLayoutEngine engine =
|
||||||
|
new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0);
|
||||||
|
|
||||||
|
final ViewInfo firstViewInfo = new ViewInfo(
|
||||||
|
new ComplicationLayoutParams(
|
||||||
|
100,
|
||||||
|
100,
|
||||||
|
ComplicationLayoutParams.POSITION_TOP
|
||||||
|
| ComplicationLayoutParams.POSITION_END,
|
||||||
|
ComplicationLayoutParams.DIRECTION_DOWN,
|
||||||
|
0),
|
||||||
|
Complication.CATEGORY_STANDARD,
|
||||||
|
mLayout);
|
||||||
|
|
||||||
|
engine.addComplication(firstViewInfo.id, firstViewInfo.view, firstViewInfo.lp,
|
||||||
|
firstViewInfo.category);
|
||||||
|
verify(mLayout).addView(firstViewInfo.view);
|
||||||
|
|
||||||
|
assertThat(engine.removeComplication(firstViewInfo.id)).isTrue();
|
||||||
|
verify(firstViewInfo.view).getParent();
|
||||||
|
verify(mLayout).removeView(firstViewInfo.view);
|
||||||
|
|
||||||
|
Mockito.clearInvocations(mLayout, firstViewInfo.view);
|
||||||
|
assertThat(engine.removeComplication(firstViewInfo.id)).isFalse();
|
||||||
|
verify(firstViewInfo.view, never()).getParent();
|
||||||
|
verify(mLayout, never()).removeView(firstViewInfo.view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user