Example usage for android.content IntentFilter countDataSchemes

List of usage examples for android.content IntentFilter countDataSchemes

Introduction

In this page you can find the example usage for android.content IntentFilter countDataSchemes.

Prototype

public final int countDataSchemes() 

Source Link

Document

Return the number of data schemes in the filter.

Usage

From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java

static CharSequence dumpIntentFilter(IntentFilter filter, Resources res, boolean isBroadcast) {
    FormattedTextBuilder ftb = new FormattedTextBuilder();
    int tagColor = res.getColor(R.color.xml_tag);
    int attributeNameColor = res.getColor(R.color.xml_attr_name);
    int attributeValueColor = res.getColor(R.color.xml_attr_value);
    int commentColor = res.getColor(R.color.xml_comment);
    final String protectedComment = " <!-- " + res.getString(R.string.broadcast_action_protected_comment)
            + " -->";

    ftb.appendColoured("\n<intent-filter>", tagColor);

    for (int i = 0, j = filter.countActions(); i < j; i++) {
        final String action = filter.getAction(i);
        ftb.appendColoured("\n  <action", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + action + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);

        if (isBroadcast && Utils.isProtectedBroadcast(action)) {
            ftb.appendColoured(protectedComment, commentColor);
        }/*  ww  w  . ja  v  a  2  s .c om*/
    }

    for (int i = 0, j = filter.countCategories(); i < j; i++) {
        ftb.appendColoured("\n  <category", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getCategory(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataSchemes(); i < j; i++) {
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:scheme=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getDataScheme(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataAuthorities(); i < j; i++) {
        IntentFilter.AuthorityEntry authority = filter.getDataAuthority(i);
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:host=", attributeNameColor);
        ftb.appendColoured("\"" + authority.getHost() + "\"", attributeValueColor);
        if (authority.getPort() != -1) {
            ftb.appendColoured(" a:port=", attributeNameColor);
            ftb.appendColoured("\"" + authority.getPort() + "\"", attributeValueColor);
        }
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataPaths(); i < j; i++) {
        PatternMatcher pathMatcher = filter.getDataPath(i);
        int type = pathMatcher.getType();
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(
                " a:path"
                        + (type == PatternMatcher.PATTERN_LITERAL ? ""
                                : type == PatternMatcher.PATTERN_PREFIX ? "Prefix"
                                        : type == PatternMatcher.PATTERN_SIMPLE_GLOB ? "Pattern" : "[unknown]")
                        + "=",
                attributeNameColor);
        ftb.appendColoured("\"" + pathMatcher.getPath() + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataTypes(); i < j; i++) {
        String dataType = filter.getDataType(i);
        if (!dataType.contains("/")) {
            // IntentFilter for partial types don't store "/*" at end
            // e.g. "image" instead of "image/*".
            // We display it in full form here
            dataType += "/*";
        }
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:mimeType=", attributeNameColor);
        ftb.appendColoured("\"" + dataType + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    ftb.appendColoured("\n</intent-filter>", tagColor);
    return ftb.getText();
}

From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java

/**
 * Update IntentFilter of categories and data
 * @param isInit//from w  w w .  j  a v  a 2s  .c  o  m
 */
private void updateNonActionIntentFilter(boolean isInit) {
    // If we don't have any IntentFilter use non-filtering editors
    if (mAvailbleActions == null) {
        setFreeFormCategoryEditor();
        mDataTextWrapper.setVisibility(View.VISIBLE);
        mDataTextHeader.setVisibility(View.VISIBLE);
        mUriAutocompleteAdapter.setIntentFilters(null);
        setupUnfilteredDataTypeFields();
        return;
    }

    // Update edited intent
    if (!isInit) {
        updateEditedIntent(mEditedIntent);
    }

    // Get all IntentFilters
    final IntentFilter[] allIntentFilters = getIntentEditor().getAttachedIntentFilters();

    // Get selected action
    String action = (String) mActionsSpinner.getSelectedItem();

    HashSet<String> availableCategories = new HashSet<String>();

    HashSet<String> availableMimeTypes = new HashSet<String>();
    boolean acceptsAnyDataType = false;
    boolean acceptsUntypedData = false;
    boolean mayAutoDetectType = false;

    boolean acceptsUris = false;

    ArrayList<IntentFilter> selectedIntentFilters = new ArrayList<IntentFilter>();

    // Iterate over intent filters that has selected action
    for (IntentFilter filter : allIntentFilters) {
        if (filter.hasAction(action)) {
            // List categories
            if (filter.countCategories() != 0) {
                for (Iterator<String> iterator = filter.categoriesIterator(); iterator.hasNext();) {
                    availableCategories.add(iterator.next());
                }
            }

            // List available types or set flag that we don't need them
            if (filter.countDataTypes() == 0) {
                acceptsUntypedData = true;
            } else {
                for (Iterator<String> iterator = filter.typesIterator(); iterator.hasNext();) {
                    final String type = iterator.next();
                    if ("*".equals(type)) {
                        acceptsAnyDataType = true;
                    } else {
                        availableMimeTypes.add(type);
                    }
                }
            }

            // Scan schemes to see if system can auto detect type
            if (!mayAutoDetectType) {
                if (filter.countDataSchemes() != 0) {
                    for (Iterator<String> iterator = filter.schemesIterator(); iterator.hasNext();) {
                        String scheme = iterator.next();
                        if ("content".equals(scheme) || "file".equals(scheme)) {
                            mayAutoDetectType = true;
                            break;
                        }
                    }
                } else if ( // No schemes declared
                filter.countDataTypes() != 0 && ( // There's at least one
                !NO_IMPLICIT_URI_ACTIONS.contains(action) || // Action is not on list
                        filter.countDataAuthorities() != 0 // There is host specified
                )) {

                    // Intent will match empty, content: or file: scheme
                    acceptsUris = true;
                    mayAutoDetectType = true;
                }
            }

            // Check if we have data
            if (filter.countDataSchemes() != 0) {
                acceptsUris = true;
            }

            // Save used IntentFilter to list because UriAutocompleteAdapter scans them on his own
            selectedIntentFilters.add(filter);
        }
    }

    // Setup categories
    setupCategoryCheckBoxes(availableCategories);

    // Setup data type
    if (acceptsAnyDataType) {
        setupUnfilteredDataTypeFields();
    } else {
        setupFilteredDataTypeFields(acceptsUntypedData, mayAutoDetectType, availableMimeTypes);
    }

    // Setup data uri
    mDataTextWrapper.setVisibility(acceptsUris ? View.VISIBLE : View.GONE);
    mDataTextHeader.setVisibility(acceptsUris ? View.VISIBLE : View.GONE);
    if (!acceptsUris) {
        mDataText.setText("");
    }
    mUriAutocompleteAdapter
            .setIntentFilters(selectedIntentFilters.toArray(new IntentFilter[selectedIntentFilters.size()]));
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Get info on the preferred (launch by default) applications.
 * @return/*  ww w  .  j  av a  2 s .com*/
 */
public String getPreferredAppInfo() {
    List<PackageInfo> packages = getActivity().getPackageManager().getInstalledPackages(0);
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    String info = "";
    int nPref = 0, nFilters = 0, nActivities = 0;
    PackageInfo packInfo = null;
    // int orderCnt = 0;
    for (int i = 0; i < packages.size(); i++) {
        packInfo = packages.get(i);
        nPref = getActivity().getPackageManager().getPreferredActivities(filters, activities,
                packInfo.packageName);
        nFilters = filters.size();
        nActivities = activities.size();
        if (nPref > 0 || nFilters > 0 || nActivities > 0) {
            // This is a launch by default package
            // info += "\n" + packInfo.packageName + "\n";
            ArrayListPairString pkgList = new ArrayListPairString();

            for (IntentFilter filter : filters) {
                info += "IntentFilter:\n";
                for (int j = 0; j < filter.countActions(); j++) {
                    addList(pkgList, "Action", filter.getAction(j));
                }
                for (int j = 0; j < filter.countCategories(); j++) {
                    addList(pkgList, "Category", filter.getCategory(j));
                }
                for (int j = 0; j < filter.countDataTypes(); j++) {
                    addList(pkgList, "Type", filter.getDataType(j));
                }
                for (int j = 0; j < filter.countDataAuthorities(); j++) {
                    addList(pkgList, "Authority", filter.getDataAuthority(j).toString());
                }
                for (int j = 0; j < filter.countDataPaths(); j++) {
                    addList(pkgList, "Path", filter.getDataPath(j).toString());
                }
                for (int j = 0; j < filter.countDataSchemes(); j++) {
                    addList(pkgList, "Scheme", filter.getDataScheme(j));
                }
                // for (ComponentName activity : activities) {
                // info += "activity="
                // + activity.flattenToString() + "\n";
                // }
            }
            if (pkgList.size() != 0) {
                m_workList.add(new PackingItem(packInfo.packageName, pkgList, packInfo, i,
                        packInfo.applicationInfo.processName));
            }
        }
    }

    return info;
}