android.view.ContextMenu#size ( )源码实例Demo

下面列出了android.view.ContextMenu#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenLibre   文件: LogRecyclerViewAdapter.java
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    MenuInflater inflater = new MenuInflater(itemView.getContext());
    inflater.inflate(R.menu.menu_log_item_context, menu);
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setOnMenuItemClickListener(this);
    }
}
 
源代码2 项目: delion   文件: ChromeContextMenuPopulator.java
private void removeUnsupportedItems(ContextMenu menu, int[] whitelist) {
    Arrays.sort(BASE_WHITELIST);
    Arrays.sort(whitelist);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (Arrays.binarySearch(whitelist, item.getItemId()) < 0
                && Arrays.binarySearch(BASE_WHITELIST, item.getItemId()) < 0) {
            menu.removeItem(item.getItemId());
            i--;
        }
    }
}
 
private void removeUnsupportedItems(ContextMenu menu, int[] whitelist) {
    Arrays.sort(BASE_WHITELIST);
    Arrays.sort(whitelist);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (Arrays.binarySearch(whitelist, item.getItemId()) < 0
                && Arrays.binarySearch(BASE_WHITELIST, item.getItemId()) < 0) {
            menu.removeItem(item.getItemId());
            i--;
        }
    }
}
 
源代码4 项目: go-bees   文件: RecordingsAdapter.java
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view,
                                ContextMenu.ContextMenuInfo contextMenuInfo) {
    // Inflate menu
    menuInflater.inflate(R.menu.recording_item_menu, contextMenu);
    // Set click listener
    for (int i = 0; i < contextMenu.size(); i++) {
        contextMenu.getItem(i).setOnMenuItemClickListener(this);
    }
}
 
源代码5 项目: go-bees   文件: ApiariesAdapter.java
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view,
                                ContextMenu.ContextMenuInfo contextMenuInfo) {
    // Inflate menu
    menuInflater.inflate(R.menu.apiary_item_menu, contextMenu);
    // Set click listener
    for (int i = 0; i < contextMenu.size(); i++) {
        contextMenu.getItem(i).setOnMenuItemClickListener(this);
    }
}
 
源代码6 项目: go-bees   文件: HivesAdapter.java
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view,
                                ContextMenu.ContextMenuInfo contextMenuInfo) {
    // Inflate menu
    menuInflater.inflate(R.menu.hive_item_menu, contextMenu);
    // Set click listener
    for (int i = 0; i < contextMenu.size(); i++) {
        contextMenu.getItem(i).setOnMenuItemClickListener(this);
    }
}
 
源代码7 项目: ticdesign   文件: MenuFragment.java
@Override
public void onCreateContextMenu(ContextMenu menu, View v) {
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.default_hint, menu);

    int count = (Integer) v.getTag();
    for (int i = menu.size(); i > count; i--) {
        MenuItem item = menu.getItem(i - 1);
        menu.removeItem(item.getItemId());
    }
}
 
源代码8 项目: Shelter   文件: AppListFragment.java
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (mSelectedApp == null) return;

    if (mIsRemote) {
        if (!mSelectedApp.isSystem())
            menu.add(Menu.NONE, MENU_ITEM_CLONE, Menu.NONE, R.string.clone_to_main_profile);
        // Freezing / Unfreezing is only available in profiles that we can control
        if (mSelectedApp.isHidden()) {
            menu.add(Menu.NONE, MENU_ITEM_UNFREEZE, Menu.NONE, R.string.unfreeze_app);
            menu.add(Menu.NONE, MENU_ITEM_LAUNCH, Menu.NONE, R.string.unfreeze_and_launch);
        } else {
            menu.add(Menu.NONE, MENU_ITEM_FREEZE, Menu.NONE, R.string.freeze_app);
            menu.add(Menu.NONE, MENU_ITEM_LAUNCH, Menu.NONE, R.string.launch);
        }
        // Cross-profile widget settings is also limited to work profile
        MenuItem crossProfileWdiegt =
                menu.add(Menu.NONE, MENU_ITEM_ALLOW_CROSS_PROFILE_WIDGET, Menu.NONE,
                        R.string.allow_cross_profile_widgets);
        crossProfileWdiegt.setCheckable(true);
        crossProfileWdiegt.setChecked(
                mCrossProfileWidgetProviders.contains(mSelectedApp.getPackageName()));

        // TODO: If we implement God Mode (i.e. Shelter as device owner), we should
        // TODO: use two different lists to store auto freeze apps because we'll be
        // TODO: able to freeze apps in main profile.
        MenuItem autoFreeze = menu.add(Menu.NONE, MENU_ITEM_AUTO_FREEZE, Menu.NONE, R.string.auto_freeze);
        autoFreeze.setCheckable(true);
        autoFreeze.setChecked(
                LocalStorageManager.getInstance().stringListContains(
                        LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE, mSelectedApp.getPackageName()));
        menu.add(Menu.NONE, MENU_ITEM_CREATE_UNFREEZE_SHORTCUT, Menu.NONE, R.string.create_unfreeze_shortcut);
    } else {
        menu.add(Menu.NONE, MENU_ITEM_CLONE, Menu.NONE, R.string.clone_to_work_profile);
    }

    if (!mSelectedApp.isSystem()) {
        // We can't uninstall system apps in both cases
        // but we'll be able to "freeze" them
        menu.add(Menu.NONE, MENU_ITEM_UNINSTALL, Menu.NONE, R.string.uninstall_app);
    }

    if (menu.size() > 0) {
        // Only set title when the menu is not empty
        // this ensures that no menu will be shown
        // if no operation available
        menu.setHeaderTitle(
                getString(R.string.app_context_menu_title, mSelectedApp.getLabel()));
    }
}
 
源代码9 项目: WiFiKeyView   文件: LongPressNetworkHook.java
@Override
public void afterHookedMethod(MethodHookParam param) {
	WiFiKeyView.verboseLog(this, "afterHookedMethod(MethodHookParam)", "Injecting context menu item...");
	
	// Get the context menu from the arguments
	ContextMenu menu = null;
	try {
		menu = ((ContextMenu) param.args[0]);
	} catch (ClassCastException cce) {
		// Another method was hooked, otherwise the footprint would have been the same,
		// something went horribly wrong here
		cce.printStackTrace();
	}
	
	// Without the menu, there is nothing to do
	if (menu == null) {
		WiFiKeyView.verboseLog(this, "afterHookedMethod(MethodHookParam)", "Could not find ContextMenu in parameter -> null!");
		return;
	}
	
	/*
	 * If an network is not known there is only 1 option
	 * 1. Connect
	 * 
	 * If an network is already known there are 2 options for the menu items:
	 * 1. Connect, Modify, Forget	-> When not connected to the network
	 * 2. Modify, Forget			-> When connected to the network
	 * 
	 * As we can only see the password previously entered, this only supports known networks
	 */
	int size = menu.size(); 
	if ( (size == 2) || (size == 3) ) {
		menu.add(
				Menu.NONE, 												// Group 	(not used/needed)
				MENU_ID_SHOWPASSWORD, 									// Id 		(of the item)
				Menu.NONE, 												// Order    (not used/needed)
				mContext.getString(R.string.menu_option_show_password)	// Text		(for display in the item)
		);
		
		if (debug) {
			WiFiKeyView.verboseLog(this, "afterHookedMethod(MethodHookParam)", "Show password added to Context menu.");
		}
	}
}