List of usage examples for android.content IntentFilter schemesIterator
public final Iterator<String> schemesIterator()
From source file:com.java2s.intents4.IntentsDemo4Activity.java
String filterToString(IntentFilter filter) { StringBuffer buffer = new StringBuffer("IntentFilter { "); Iterator<String> actionsIter = filter.actionsIterator(); if (actionsIter != null) { buffer.append("act=["); while (actionsIter.hasNext()) { String temp = actionsIter.next().trim(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter action: >" + temp + "<"); }/*w ww.j a v a 2 s.co m*/ if (buffer.lastIndexOf(",") >= 0) { buffer.setCharAt(buffer.lastIndexOf(","), ']'); } else { buffer.append(']'); } buffer.append(" "); } Iterator<String> schemesIter = filter.schemesIterator(); if (schemesIter != null) { buffer.append("sche=["); while (schemesIter.hasNext()) { String temp = schemesIter.next().trim(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter scheme: >" + temp + "<"); } buffer.setCharAt(buffer.lastIndexOf(","), ']'); buffer.append(" "); } Iterator<IntentFilter.AuthorityEntry> authsIter = filter.authoritiesIterator(); if (authsIter != null) { buffer.append("auth=["); while (authsIter.hasNext()) { IntentFilter.AuthorityEntry entry = authsIter.next(); String temp = entry.getHost() + ":" + entry.getPort(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter authority: >" + temp + "<"); } buffer.setCharAt(buffer.lastIndexOf(","), ']'); buffer.append(" "); } Iterator<PatternMatcher> pathsIter = filter.pathsIterator(); if (pathsIter != null) { buffer.append("path=["); while (pathsIter.hasNext()) { PatternMatcher entry = pathsIter.next(); String temp = entry.toString(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter path: >" + temp + "<"); } buffer.setCharAt(buffer.lastIndexOf(","), ']'); buffer.append(" "); } Iterator<String> typesIter = filter.typesIterator(); if (typesIter != null) { buffer.append("typ=["); while (typesIter.hasNext()) { String temp = typesIter.next().trim(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter type: >" + temp + "<"); } buffer.setCharAt(buffer.lastIndexOf(","), ']'); buffer.append(" "); } Iterator<String> catsIter = filter.categoriesIterator(); if (catsIter != null) { buffer.append("cat=["); while (catsIter.hasNext()) { String temp = catsIter.next().trim(); buffer.append(temp + ","); Log.i(CLASSNAME, "Filter category: >" + temp + "<"); } buffer.setCharAt(buffer.lastIndexOf(","), ']'); buffer.append(" "); } buffer.append('}'); return buffer.toString(); }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
/** * Update IntentFilter of categories and data * @param isInit/* www. java 2 s. 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()])); }