use of android.view.MenuItem in project android_frameworks_base by ParanoidAndroid.
the class MenuTest method testCheckable.
@SmallTest
public void testCheckable() {
final int groupId = 1;
final MenuItem item1 = mMenu.add(groupId, 1, 0, "item1");
final MenuItem item2 = mMenu.add(groupId, 2, 0, "item2");
// Set to exclusive
mMenu.setGroupCheckable(groupId, true, true);
Assert.assertTrue("Item was not set to checkable", item1.isCheckable());
item1.setChecked(true);
Assert.assertTrue("Item did not get checked", item1.isChecked());
Assert.assertFalse("Item was not unchecked due to exclusive checkable", item2.isChecked());
mMenu.findItem(2).setChecked(true);
Assert.assertTrue("Item did not get checked", item2.isChecked());
Assert.assertFalse("Item was not unchecked due to exclusive checkable", item1.isChecked());
// Multiple non-exlusive checkable items
mMenu.setGroupCheckable(groupId, true, false);
Assert.assertTrue("Item was not set to checkable", item1.isCheckable());
item1.setChecked(false);
Assert.assertFalse("Item did not get unchecked", item1.isChecked());
item1.setChecked(true);
Assert.assertTrue("Item did not get checked", item1.isChecked());
mMenu.findItem(2).setChecked(true);
Assert.assertTrue("Item did not get checked", item2.isChecked());
Assert.assertTrue("Item was unchecked when it shouldnt have been", item1.isChecked());
}
use of android.view.MenuItem in project android_frameworks_base by ParanoidAndroid.
the class MenuTest method testGroupId.
@SmallTest
public void testGroupId() {
final int groupId = 541;
final int item1Index = 1;
final int item2Index = 3;
mMenu.add(0, 0, item1Index - 1, "ignore");
final MenuItem item = mMenu.add(groupId, 0, item1Index, "test");
mMenu.add(0, 0, item2Index - 1, "ignore");
final MenuItem item2 = mMenu.add(groupId, 0, item2Index, "test2");
Assert.assertEquals(groupId, item.getGroupId());
Assert.assertEquals(groupId, item2.getGroupId());
Assert.assertEquals(item1Index, mMenu.findGroupIndex(groupId));
Assert.assertEquals(item2Index, mMenu.findGroupIndex(groupId, item1Index + 1));
}
use of android.view.MenuItem in project android_frameworks_base by ParanoidAndroid.
the class MenuTest method testItemId.
@SmallTest
public void testItemId() {
final int id = 512;
final MenuItem item = mMenu.add(0, id, 0, "test");
Assert.assertEquals(id, item.getItemId());
Assert.assertEquals(item, mMenu.findItem(id));
Assert.assertEquals(0, mMenu.findItemIndex(id));
}
use of android.view.MenuItem in project android_frameworks_base by ParanoidAndroid.
the class MenuTest method testVisibility.
@SmallTest
public void testVisibility() {
final MenuItem item1 = mMenu.add(0, 1, 0, "item1");
final MenuItem item2 = mMenu.add(0, 2, 0, "item2");
// Should start as visible
Assert.assertTrue("Item did not start as visible", item1.isVisible());
Assert.assertTrue("Item did not start as visible", item2.isVisible());
// Hide
item1.setVisible(false);
Assert.assertFalse("Item did not become invisible", item1.isVisible());
mMenu.findItem(2).setVisible(false);
Assert.assertFalse("Item did not become invisible", item2.isVisible());
}
use of android.view.MenuItem in project android_frameworks_base by ParanoidAndroid.
the class MenuTest method testSubMenu.
@SmallTest
public void testSubMenu() {
final SubMenu subMenu = mMenu.addSubMenu(0, 0, 0, "submenu");
final MenuItem subMenuItem = subMenu.getItem();
final MenuItem item1 = subMenu.add(0, 1, 0, "item1");
final MenuItem item2 = subMenu.add(0, 2, 0, "item2");
// findItem should recurse into submenus
Assert.assertEquals(item1, mMenu.findItem(1));
Assert.assertEquals(item2, mMenu.findItem(2));
}
Aggregations