下面列出了android.content.Intent#filterEquals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private BroadcastRecord replaceBroadcastLocked(ArrayList<BroadcastRecord> queue,
BroadcastRecord r, String typeForLogging) {
final Intent intent = r.intent;
for (int i = queue.size() - 1; i > 0; i--) {
final BroadcastRecord old = queue.get(i);
if (old.userId == r.userId && intent.filterEquals(old.intent)) {
if (DEBUG_BROADCAST) {
Slog.v(TAG_BROADCAST, "***** DROPPING "
+ typeForLogging + " [" + mQueueName + "]: " + intent);
}
queue.set(i, r);
return old;
}
}
return null;
}
private BroadcastRecord replaceBroadcastLocked(ArrayList<BroadcastRecord> queue,
BroadcastRecord r, String typeForLogging) {
final Intent intent = r.intent;
for (int i = queue.size() - 1; i > 0; i--) {
final BroadcastRecord old = queue.get(i);
if (old.userId == r.userId && intent.filterEquals(old.intent)) {
if (DEBUG_BROADCAST) {
Slog.v(TAG_BROADCAST, "***** DROPPING "
+ typeForLogging + " [" + mQueueName + "]: " + intent);
}
queue.set(i, r);
return old;
}
}
return null;
}
private void prePerformCreate(Activity activity) {
if (mWaitingActivities != null) {
synchronized (mSync) {
final int N = mWaitingActivities.size();
for (int i=0; i<N; i++) {
final ActivityWaiter aw = mWaitingActivities.get(i);
final Intent intent = aw.intent;
if (intent.filterEquals(activity.getIntent())) {
aw.activity = activity;
mMessageQueue.addIdleHandler(new ActivityGoing(aw));
}
}
}
}
}
private void prePerformCreate(Activity activity) {
if (mWaitingActivities != null) {
synchronized (mSync) {
final int N = mWaitingActivities.size();
for (int i=0; i<N; i++) {
final ActivityWaiter aw = mWaitingActivities.get(i);
final Intent intent = aw.intent;
if (intent.filterEquals(activity.getIntent())) {
aw.activity = activity;
mMessageQueue.addIdleHandler(new ActivityGoing(aw));
}
}
}
}
}
private void prePerformCreate(Activity activity) {
if (mWaitingActivities != null) {
synchronized (mSync) {
final int N = mWaitingActivities.size();
for (int i=0; i<N; i++) {
final ActivityWaiter aw = mWaitingActivities.get(i);
final Intent intent = aw.intent;
if (intent.filterEquals(activity.getIntent())) {
aw.activity = activity;
mMessageQueue.addIdleHandler(new ActivityGoing(aw));
}
}
}
}
}
/**
* Return true if the input activity has the same intent filter as the intent this task
* record is based on (normally the root activity intent).
*/
boolean isSameIntentFilter(ActivityRecord r) {
final Intent intent = new Intent(r.intent);
// Correct the activity intent for aliasing. The task record intent will always be based on
// the real activity that will be launched not the alias, so we need to use an intent with
// the component name pointing to the real activity not the alias in the activity record.
intent.setComponent(r.realActivity);
return intent.filterEquals(this.intent);
}
private void prePerformCreate(Activity activity) {
if (mWaitingActivities != null) {
synchronized (mSync) {
final int N = mWaitingActivities.size();
for (int i=0; i<N; i++) {
final ActivityWaiter aw = mWaitingActivities.get(i);
final Intent intent = aw.intent;
if (intent.filterEquals(activity.getIntent())) {
aw.activity = activity;
mMessageQueue.addIdleHandler(new ActivityGoing(aw));
}
}
}
}
}
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
return true;
}
}
return false;
}
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
return true;
}
}
return false;
}
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
return true;
}
}
return false;
}
/** Matches an intent if it {@link Intent#filterEquals(Intent)} the expected intent. */
public static Matcher<Intent> filterEquals(Intent expectedIntent) {
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("filterEquals: ").appendValue(expectedIntent);
}
@Override
public boolean matchesSafely(Intent intent) {
return expectedIntent.filterEquals(intent);
}
};
}
private static Matcher<Intent> isSameIntent(final Intent expectedIntent) {
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("is Intent: " + expectedIntent);
}
@Override
public boolean matchesSafely(Intent intent) {
return expectedIntent.filterEquals(intent);
}
};
}
@Override
public void onReceive(Context context, Intent intent) {
if (mTvShowLoader != null) {
if (intent.filterEquals(new Intent("mizuu-shows-actor-search"))) {
mTvShowLoader.search("actor: " + intent.getStringExtra("intent_extra_data_key"));
} else {
mTvShowLoader.load();
}
showProgressBar();
}
}
@Override
public void onReceive(Context context, Intent intent) {
if (mMovieLoader != null) {
if (intent.filterEquals(new Intent("mizuu-movie-actor-search"))) {
mMovieLoader.search("actor: " + intent.getStringExtra("intent_extra_data_key"));
} else {
mMovieLoader.load();
}
showProgressBar();
}
}
/**
* Find the task that would be removed if the given {@param task} is added to the recent tasks
* list (if any).
*/
private int findRemoveIndexForAddTask(TaskRecord task) {
final int recentsCount = mTasks.size();
final Intent intent = task.intent;
final boolean document = intent != null && intent.isDocument();
int maxRecents = task.maxRecents - 1;
for (int i = 0; i < recentsCount; i++) {
final TaskRecord tr = mTasks.get(i);
if (task != tr) {
if (!hasCompatibleActivityTypeAndWindowingMode(task, tr)
|| task.userId != tr.userId) {
continue;
}
final Intent trIntent = tr.intent;
final boolean sameAffinity =
task.affinity != null && task.affinity.equals(tr.affinity);
final boolean sameIntent = intent != null && intent.filterEquals(trIntent);
boolean multiTasksAllowed = false;
final int flags = intent.getFlags();
if ((flags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NEW_DOCUMENT)) != 0
&& (flags & FLAG_ACTIVITY_MULTIPLE_TASK) != 0) {
multiTasksAllowed = true;
}
final boolean trIsDocument = trIntent != null && trIntent.isDocument();
final boolean bothDocuments = document && trIsDocument;
if (!sameAffinity && !sameIntent && !bothDocuments) {
continue;
}
if (bothDocuments) {
// Do these documents belong to the same activity?
final boolean sameActivity = task.realActivity != null
&& tr.realActivity != null
&& task.realActivity.equals(tr.realActivity);
if (!sameActivity) {
// If the document is open in another app or is not the same document, we
// don't need to trim it.
continue;
} else if (maxRecents > 0) {
--maxRecents;
if (!sameIntent || multiTasksAllowed) {
// We don't want to trim if we are not over the max allowed entries and
// the tasks are not of the same intent filter, or multiple entries for
// the task is allowed.
continue;
}
}
// Hit the maximum number of documents for this task. Fall through
// and remove this document from recents.
} else if (document || trIsDocument) {
// Only one of these is a document. Not the droid we're looking for.
continue;
}
}
return i;
}
return -1;
}
private static void removeShortcut(Context context, Intent data) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
if (intent != null && name != null) {
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT },
LauncherSettings.Favorites.TITLE + "=?", new String[] { name }, null);
final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
boolean changed = false;
try {
while (c.moveToNext()) {
try {
if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) {
final long id = c.getLong(idIndex);
final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
cr.delete(uri, null, null);
changed = true;
if (!duplicate) {
break;
}
}
} catch (URISyntaxException e) {
}
}
} finally {
c.close();
}
if (changed) {
cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name),
Toast.LENGTH_SHORT).show();
}
}
}
private static void removeShortcut(Context context, Intent data) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
if (intent != null && name != null) {
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT },
LauncherSettings.Favorites.TITLE + "=?", new String[] { name }, null);
final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
boolean changed = false;
try {
while (c.moveToNext()) {
try {
if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) {
final long id = c.getLong(idIndex);
final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
cr.delete(uri, null, null);
changed = true;
if (!duplicate) {
break;
}
}
} catch (URISyntaxException e) {
// Ignore
}
}
} finally {
c.close();
}
if (changed) {
cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name),
Toast.LENGTH_SHORT).show();
}
}
}