Java Code Examples for android.content.IntentFilter#countActions()

The following examples show how to use android.content.IntentFilter#countActions() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: guideshow   File: LocalBroadcastManager.java    License: MIT License 6 votes vote down vote up
/**
 * Register a receive for any local broadcasts that match the given IntentFilter.
 *
 * @param receiver The BroadcastReceiver to handle the broadcast.
 * @param filter Selects the Intent broadcasts to be received.
 *
 * @see #unregisterReceiver
 */
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
    synchronized (mReceivers) {
        ReceiverRecord entry = new ReceiverRecord(filter, receiver);
        ArrayList<IntentFilter> filters = mReceivers.get(receiver);
        if (filters == null) {
            filters = new ArrayList<IntentFilter>(1);
            mReceivers.put(receiver, filters);
        }
        filters.add(filter);
        for (int i=0; i<filter.countActions(); i++) {
            String action = filter.getAction(i);
            ArrayList<ReceiverRecord> entries = mActions.get(action);
            if (entries == null) {
                entries = new ArrayList<ReceiverRecord>(1);
                mActions.put(action, entries);
            }
            entries.add(entry);
        }
    }
}
 
Example 2
public ArrayList<F> findFilters(IntentFilter matching) {
    if (matching.countDataSchemes() == 1) {
        // Fast case.
        return collectFilters(mSchemeToFilter.get(matching.getDataScheme(0)), matching);
    } else if (matching.countDataTypes() != 0 && matching.countActions() == 1) {
        // Another fast case.
        return collectFilters(mTypedActionToFilter.get(matching.getAction(0)), matching);
    } else if (matching.countDataTypes() == 0 && matching.countDataSchemes() == 0
            && matching.countActions() == 1) {
        // Last fast case.
        return collectFilters(mActionToFilter.get(matching.getAction(0)), matching);
    } else {
        ArrayList<F> res = null;
        for (F cur : mFilters) {
            if (filterEquals(cur, matching)) {
                if (res == null) {
                    res = new ArrayList<>();
                }
                res.add(cur);
            }
        }
        return res;
    }
}
 
Example 3
public ArrayList<F> findFilters(IntentFilter matching) {
    if (matching.countDataSchemes() == 1) {
        // Fast case.
        return collectFilters(mSchemeToFilter.get(matching.getDataScheme(0)), matching);
    } else if (matching.countDataTypes() != 0 && matching.countActions() == 1) {
        // Another fast case.
        return collectFilters(mTypedActionToFilter.get(matching.getAction(0)), matching);
    } else if (matching.countDataTypes() == 0 && matching.countDataSchemes() == 0
            && matching.countActions() == 1) {
        // Last fast case.
        return collectFilters(mActionToFilter.get(matching.getAction(0)), matching);
    } else {
        ArrayList<F> res = null;
        for (F cur : mFilters) {
            if (filterEquals(cur, matching)) {
                if (res == null) {
                    res = new ArrayList<>();
                }
                res.add(cur);
            }
        }
        return res;
    }
}
 
Example 4
public ArrayList<F> findFilters(IntentFilter matching) {
	if (matching.countDataSchemes() == 1) {
		// Fast case.
		return collectFilters(mSchemeToFilter.get(matching.getDataScheme(0)), matching);
	} else if (matching.countDataTypes() != 0 && matching.countActions() == 1) {
		// Another fast case.
		return collectFilters(mTypedActionToFilter.get(matching.getAction(0)), matching);
	} else if (matching.countDataTypes() == 0 && matching.countDataSchemes() == 0 && matching.countActions() == 1) {
		// Last fast case.
		return collectFilters(mActionToFilter.get(matching.getAction(0)), matching);
	} else {
		ArrayList<F> res = null;
		for (F cur : mFilters) {
			if (filterEquals(cur, matching)) {
				if (res == null) {
					res = new ArrayList<>();
				}
				res.add(cur);
			}
		}
		return res;
	}
}
 
Example 5
Source Project: libcommon   File: BaseService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (DEBUG) Log.v(TAG, "onCreate:");
	final Context app_context = getApplicationContext();
	synchronized (mSync) {
		mLocalBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
		final IntentFilter filter = createIntentFilter();
		if ((filter != null) && filter.countActions() > 0) {
			mLocalBroadcastManager.registerReceiver(mLocalBroadcastReceiver, filter);
		}
		if (mAsyncHandler == null) {
			mAsyncHandler = HandlerThreadHandler.createHandler(getClass().getSimpleName());
		}
	}
}
 
Example 6
Source Project: android-sdk   File: LocalBroadcastManager.java    License: MIT License 6 votes vote down vote up
/**
 * Register a receive for any local broadcasts that match the given IntentFilter.
 *
 * @param receiver The BroadcastReceiver to handle the broadcast.
 * @param filter   Selects the Intent broadcasts to be received.
 * @see #unregisterReceiver
 */
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
    synchronized (mReceivers) {
        ReceiverRecord entry = new ReceiverRecord(filter, receiver);
        ArrayList<IntentFilter> filters = mReceivers.get(receiver);
        if (filters == null) {
            filters = new ArrayList<>(1);
            mReceivers.put(receiver, filters);
        }
        filters.add(filter);
        for (int i = 0; i < filter.countActions(); i++) {
            String action = filter.getAction(i);
            ArrayList<ReceiverRecord> entries = mActions.get(action);
            if (entries == null) {
                entries = new ArrayList<>(1);
                mActions.put(action, entries);
            }
            entries.add(entry);
        }
    }
}
 
Example 7
/**
 * Register a receive for any local broadcasts that match the given IntentFilter.
 *
 * @param receiver The BroadcastReceiver to handle the broadcast.
 * @param filter Selects the Intent broadcasts to be received.
 *
 * @see #unregisterReceiver
 */
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
    synchronized (mReceivers) {
        ReceiverRecord entry = new ReceiverRecord(filter, receiver);
        ArrayList<IntentFilter> filters = mReceivers.get(receiver);
        if (filters == null) {
            filters = new ArrayList<IntentFilter>(1);
            mReceivers.put(receiver, filters);
        }
        filters.add(filter);
        for (int i=0; i<filter.countActions(); i++) {
            String action = filter.getAction(i);
            ArrayList<ReceiverRecord> entries = mActions.get(action);
            if (entries == null) {
                entries = new ArrayList<ReceiverRecord>(1);
                mActions.put(action, entries);
            }
            entries.add(entry);
        }
    }
}
 
Example 8
Source Project: letv   File: LocalBroadcastManager.java    License: Apache License 2.0 5 votes vote down vote up
public void unregisterReceiver(BroadcastReceiver receiver) {
    synchronized (this.mReceivers) {
        ArrayList<IntentFilter> filters = (ArrayList) this.mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i = 0; i < filters.size(); i++) {
            IntentFilter filter = (IntentFilter) filters.get(i);
            for (int j = 0; j < filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = (ArrayList) this.mActions.get(action);
                if (receivers != null) {
                    int k = 0;
                    while (k < receivers.size()) {
                        if (((ReceiverRecord) receivers.get(k)).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                        k++;
                    }
                    if (receivers.size() <= 0) {
                        this.mActions.remove(action);
                    }
                }
            }
        }
    }
}
 
Example 9
/**
 * Unregister a previously registered BroadcastReceiver. <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 * 
 * @param receiver
 *            The BroadcastReceiver to unregister.
 * 
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
	synchronized (mReceivers) {
		ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
		if (filters == null) {
			return;
		}
		for (int i = 0; i < filters.size(); i++) {
			IntentFilter filter = filters.get(i);
			for (int j = 0; j < filter.countActions(); j++) {
				String action = filter.getAction(j);
				ArrayList<ReceiverRecord> receivers = mActions.get(action);
				if (receivers != null) {
					for (int k = 0; k < receivers.size(); k++) {
						if (receivers.get(k).receiver == receiver) {
							receivers.remove(k);
							k--;
						}
					}
					if (receivers.size() <= 0) {
						mActions.remove(action);
					}
				}
			}
		}
	}
}
 
Example 10
/**
 * Unregister a previously registered BroadcastReceiver.  <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 *
 * @param receiver The BroadcastReceiver to unregister.
 *
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
    synchronized (mReceivers) {
        ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i=0; i<filters.size(); i++) {
            IntentFilter filter = filters.get(i);
            for (int j=0; j<filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = mActions.get(action);
                if (receivers != null) {
                    for (int k=0; k<receivers.size(); k++) {
                        if (receivers.get(k).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                    }
                    if (receivers.size() <= 0) {
                        mActions.remove(action);
                    }
                }
            }
        }
    }
}
 
Example 11
Source Project: springreplugin   File: PmHostSvc.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void regReceiver(String plugin, Map rcvFilMap) throws RemoteException {
    PluginInfo pi = RePluginOS.getPlugin(plugin, false);
    if (pi == null || pi.getFrameworkVersion() < 4) {
        return;
    }

    HashMap<String, List<IntentFilter>> receiverFilterMap = (HashMap<String, List<IntentFilter>>) rcvFilMap;

    // 遍历此插件中所有静态声明的 Receiver
    for (HashMap.Entry<String, List<IntentFilter>> entry : receiverFilterMap.entrySet()) {
        if (mReceiverProxy == null) {
            mReceiverProxy = new PluginReceiverProxy();
            mReceiverProxy.setActionPluginMap(mActionPluginComponents);
        }

        /* 保存 action-plugin-receiver 的关系 */
        String receiver = entry.getKey();
        List<IntentFilter> filters = entry.getValue();

        if (filters != null) {
            for (IntentFilter filter : filters) {
                int actionCount = filter.countActions();
                while (actionCount >= 1) {
                    saveAction(filter.getAction(actionCount - 1), plugin, receiver);
                    actionCount--;
                }

                // 注册 Receiver
                mContext.registerReceiver(mReceiverProxy, filter);
            }
        }
    }
}
 
Example 12
Source Project: iMoney   File: LocalBroadcastManager.java    License: Apache License 2.0 5 votes vote down vote up
public void unregisterReceiver(BroadcastReceiver receiver) {
    HashMap var2 = this.mReceivers;
    synchronized (this.mReceivers) {
        ArrayList filters = (ArrayList) this.mReceivers.remove(receiver);
        if (filters != null) {
            for (int i = 0; i < filters.size(); ++i) {
                IntentFilter filter = (IntentFilter) filters.get(i);

                for (int j = 0; j < filter.countActions(); ++j) {
                    String action = filter.getAction(j);
                    ArrayList receivers = (ArrayList) this.mActions.get(action);
                    if (receivers != null) {
                        for (int k = 0; k < receivers.size(); ++k) {
                            if (((LocalBroadcastManager.ReceiverRecord) receivers.get(k)).receiver == receiver) {
                                receivers.remove(k);
                                --k;
                            }
                        }

                        if (receivers.size() <= 0) {
                            this.mActions.remove(action);
                        }
                    }
                }
            }

        }
    }
}
 
Example 13
Source Project: Noyze   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new IntentFilter, the product of both inputs.
 */
public static IntentFilter merge(IntentFilter a, IntentFilter b) {
    IntentFilter both = new IntentFilter(a);
    for (int i = 0, e = b.countActions(); i < e; ++i)
        both.addAction(b.getAction(i));
    return both;
}
 
Example 14
Source Project: Dashchan   File: LocalBroadcastManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Unregister a previously registered BroadcastReceiver. <em>All</em> filters that have been registered for this
 * BroadcastReceiver will be removed.
 *
 * @param receiver
 *            The BroadcastReceiver to unregister.
 *
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
	synchronized (mReceivers) {
		ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
		if (filters == null) {
			return;
		}
		for (int i = 0; i < filters.size(); i++) {
			IntentFilter filter = filters.get(i);
			for (int j = 0; j < filter.countActions(); j++) {
				String action = filter.getAction(j);
				ArrayList<ReceiverRecord> receivers = mActions.get(action);
				if (receivers != null) {
					for (int k = 0; k < receivers.size(); k++) {
						if (receivers.get(k).receiver == receiver) {
							receivers.remove(k);
							k--;
						}
					}
					if (receivers.size() <= 0) {
						mActions.remove(action);
					}
				}
			}
		}
	}
}
 
Example 15
/**
 * Unregister a previously registered BroadcastReceiver.  <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 *
 * @param receiver The BroadcastReceiver to unregister.
 *
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
    synchronized (mReceivers) {
        ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i=0; i<filters.size(); i++) {
            IntentFilter filter = filters.get(i);
            for (int j=0; j<filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = mActions.get(action);
                if (receivers != null) {
                    for (int k=0; k<receivers.size(); k++) {
                        if (receivers.get(k).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                    }
                    if (receivers.size() <= 0) {
                        mActions.remove(action);
                    }
                }
            }
        }
    }
}
 
Example 16
Source Project: android-sdk   File: LocalBroadcastManager.java    License: MIT License 5 votes vote down vote up
/**
 * Unregister a previously registered BroadcastReceiver.  <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 *
 * @param receiver The BroadcastReceiver to unregister.
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
    synchronized (mReceivers) {
        ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i = 0; i < filters.size(); i++) {
            IntentFilter filter = filters.get(i);
            for (int j = 0; j < filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = mActions.get(action);
                if (receivers != null) {
                    for (int k = 0; k < receivers.size(); k++) {
                        if (receivers.get(k).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                    }
                    if (receivers.size() <= 0) {
                        mActions.remove(action);
                    }
                }
            }
        }
    }
}
 
Example 17
Source Project: guideshow   File: LocalBroadcastManager.java    License: MIT License 5 votes vote down vote up
/**
 * Unregister a previously registered BroadcastReceiver.  <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 *
 * @param receiver The BroadcastReceiver to unregister.
 *
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
    synchronized (mReceivers) {
        ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i=0; i<filters.size(); i++) {
            IntentFilter filter = filters.get(i);
            for (int j=0; j<filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = mActions.get(action);
                if (receivers != null) {
                    for (int k=0; k<receivers.size(); k++) {
                        if (receivers.get(k).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                    }
                    if (receivers.size() <= 0) {
                        mActions.remove(action);
                    }
                }
            }
        }
    }
}
 
Example 18
Source Project: Noyze   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new IntentFilter, the product of both inputs.
 */
public static IntentFilter merge(IntentFilter a, IntentFilter b) {
    IntentFilter both = new IntentFilter(a);
    for (int i = 0, e = b.countActions(); i < e; ++i)
        both.addAction(b.getAction(i));
    return both;
}
 
Example 19
public static boolean filterEquals(IntentFilter f1, IntentFilter f2) {
    int s1 = f1.countActions();
    int s2 = f2.countActions();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasAction(f1.getAction(i))) {
            return false;
        }
    }
    s1 = f1.countCategories();
    s2 = f2.countCategories();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasCategory(f1.getCategory(i))) {
            return false;
        }
    }
    s1 = f1.countDataTypes();
    s2 = f2.countDataTypes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasExactDataType(f1.getDataType(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemes();
    s2 = f2.countDataSchemes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataScheme(f1.getDataScheme(i))) {
            return false;
        }
    }
    s1 = f1.countDataAuthorities();
    s2 = f2.countDataAuthorities();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataAuthority(f1.getDataAuthority(i))) {
            return false;
        }
    }
    s1 = f1.countDataPaths();
    s2 = f2.countDataPaths();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataPath(f1.getDataPath(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemeSpecificParts();
    s2 = f2.countDataSchemeSpecificParts();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataSchemeSpecificPart(f1.getDataSchemeSpecificPart(i))) {
            return false;
        }
    }
    return true;
}
 
Example 20
private boolean filterEquals(IntentFilter f1, IntentFilter f2) {
	int s1 = f1.countActions();
	int s2 = f2.countActions();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasAction(f1.getAction(i))) {
			return false;
		}
	}
	s1 = f1.countCategories();
	s2 = f2.countCategories();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasCategory(f1.getCategory(i))) {
			return false;
		}
	}
	s1 = f1.countDataTypes();
	s2 = f2.countDataTypes();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataSchemes();
	s2 = f2.countDataSchemes();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasDataScheme(f1.getDataScheme(i))) {
			return false;
		}
	}
	s1 = f1.countDataAuthorities();
	s2 = f2.countDataAuthorities();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataPaths();
	s2 = f2.countDataPaths();
	if (s1 != s2) {
		return false;
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		s1 = f1.countDataSchemeSpecificParts();
		s2 = f2.countDataSchemeSpecificParts();
		if (s1 != s2) {
			return false;
		}
	}
	return true;
}