Search in sources :

Example 26 with MenuItem

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());
}
Also used : MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 27 with MenuItem

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));
}
Also used : MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 28 with MenuItem

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));
}
Also used : MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 29 with MenuItem

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());
}
Also used : MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 30 with MenuItem

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));
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

MenuItem (android.view.MenuItem)713 View (android.view.View)125 Intent (android.content.Intent)75 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)55 PopupMenu (android.widget.PopupMenu)54 Menu (android.view.Menu)47 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 SearchView (android.support.v7.widget.SearchView)41 RecyclerView (android.support.v7.widget.RecyclerView)32 MenuInflater (android.view.MenuInflater)29 AdapterView (android.widget.AdapterView)27 ListView (android.widget.ListView)27 SubMenu (android.view.SubMenu)26 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)24 Parcelable (android.os.Parcelable)23 Toolbar (android.support.v7.widget.Toolbar)19 ResolveInfo (android.content.pm.ResolveInfo)18 Bundle (android.os.Bundle)18