Java Code Examples for android.content.Intent#filterEquals()

The following examples show how to use android.content.Intent#filterEquals() . 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
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;
}
 
Example 2
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;
}
 
Example 3
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));
                }
            }
        }
    }
}
 
Example 4
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));
                }
            }
        }
    }
}
 
Example 5
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));
                }
            }
        }
    }
}
 
Example 6
Source Project: android_9.0.0_r45   File: TaskRecord.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
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));
                }
            }
        }
    }
}
 
Example 8
/** 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;
}
 
Example 9
/** 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;
}
 
Example 10
/** 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;
}
 
Example 11
Source Project: android-test   File: IntentMatchers.java    License: Apache License 2.0 5 votes vote down vote up
/** 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);
    }
  };
}
 
Example 12
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);
      }
    };
  }
 
Example 13
Source Project: Mizuu   File: TvShowLibraryFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 14
Source Project: Mizuu   File: MovieLibraryFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 15
Source Project: android_9.0.0_r45   File: RecentTasks.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 16
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();
        }
    }
}
 
Example 17
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();
        }
    }
}