android.service.chooser.ChooserTarget Java Examples

The following examples show how to use android.service.chooser.ChooserTarget. 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 File: IRCChooserTargetService.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetComponentName,
                                               IntentFilter intentFilter) {
    if (sServer != null && sChannel != null) {
        if (System.currentTimeMillis() - sSetTime >= SET_TIMEOUT) {
            sServer = null;
            sChannel = null;
            return null;
        }
        ComponentName componentName = new ComponentName(getPackageName(),
                MainActivity.class.getCanonicalName());

        List<ChooserTarget> targets = new ArrayList<>();
        Bundle extras = new Bundle();
        extras.putString(MainActivity.ARG_SERVER_UUID, sServer.toString());
        extras.putString(MainActivity.ARG_CHANNEL_NAME, sChannel);
        targets.add(new ChooserTarget(sChannel,
                Icon.createWithResource(this, R.drawable.ic_direct_share),
                1.f, componentName, extras));
        return targets;
    }
    return null;
}
 
Example #2
Source File: DirectShareService.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    ComponentName componentName = new ComponentName(getPackageName(),
            ShareActivity.class.getCanonicalName());
    ArrayList<ChooserTarget> targets = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Bundle extras = new Bundle();
        extras.putInt("directsharekey", i);
        targets.add(new ChooserTarget(
                "name_" + i,
                Icon.createWithResource(this, R.mipmap.ic_logo),
                0.5f,
                componentName,
                extras));
    }
    return targets;
}
 
Example #3
Source File: HostChooserTargetService.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    final List<ChooserTarget> targets = new ArrayList<>();
    HostManager hostManager = HostManager.getInstance(this);

    final Icon icon = Icon.createWithResource(this, R.mipmap.ic_launcher);
    final float score = 0;
    final ComponentName componentName = new ComponentName(getPackageName(), "org.xbmc.kore.ui.sections.remote.RemoteActivity");

    for (HostInfo host : hostManager.getHosts()) {
        Bundle intentExtras = new Bundle();
        intentExtras.putInt("hostId", host.getId());
        targets.add(new ChooserTarget(host.getName(), icon, score, componentName, intentExtras));
    }

    return targets;
}
 
Example #4
Source File: ProfileChooserService.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    DrawingHelper helper = new DrawingHelper(this);
    List<MultiProfile> profiles = ProfilesManager.get(this).getProfiles();
    List<ChooserTarget> targets = new ArrayList<>();
    ChooserTargetsCache cache = ChooserTargetsCache.get();
    for (MultiProfile profile : profiles)
        targets.add(cache.getOrGenerate(profile, helper, targetActivityName));
    return targets;
}
 
Example #5
Source File: ContactChooserTargetService.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
    if (!EventReceiver.hasEnabledAccounts(this)) {
        return chooserTargets;
    }
    final Intent intent = new Intent(this, XmppConnectionService.class);
    intent.setAction("contact_chooser");
    Compatibility.startService(this, intent);
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    try {
        waitForService();
        final ArrayList<Conversation> conversations = new ArrayList<>();
        if (!mXmppConnectionService.areMessagesInitialized()) {
            return chooserTargets;
        }

        mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter));
        final ComponentName componentName = new ComponentName(this, ConversationsActivity.class);
        final int pixel = AvatarService.getSystemUiAvatarSize(this);
        for (Conversation conversation : conversations) {
            if (conversation.sentMessagesCount() == 0) {
                continue;
            }
            final String name = conversation.getName().toString();
            final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
            final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size();
            final Bundle extras = new Bundle();
            extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
            chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
            if (chooserTargets.size() >= MAX_TARGETS) {
                break;
            }
        }
    } catch (InterruptedException e) {
    }
    unbindService(this);
    return chooserTargets;
}
 
Example #6
Source File: DirectShareService.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
                                               IntentFilter matchedFilter)
{
  List<ChooserTarget> results        = new LinkedList<>();
  MasterSecret        masterSecret   = KeyCachingService.getMasterSecret(this);

  if (masterSecret == null) {
    return results;
  }

  ComponentName  componentName  = new ComponentName(this, ShareActivity.class);
  ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
  Cursor         cursor         = threadDatabase.getDirectShareList();

  try {
    ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, new MasterCipher(masterSecret));
    ThreadRecord record;

    while ((record = reader.getNext()) != null && results.size() < 10) {
      Recipients recipients = RecipientFactory.getRecipientsForIds(this, record.getRecipients().getIds(), false);
      String     name       = recipients.toShortString();
      Drawable   drawable   = recipients.getContactPhoto().asDrawable(this, recipients.getColor().toConversationColor(this));
      Bitmap     avatar     = BitmapUtil.createFromDrawable(drawable, 500, 500);

      Bundle bundle = new Bundle();
      bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
      bundle.putLongArray(ShareActivity.EXTRA_RECIPIENT_IDS, recipients.getIds());
      bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());

      results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
    }

    return results;
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
Example #7
Source File: SampleChooserTargetService.java    From android-DirectShare with Apache License 2.0 5 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
                                               IntentFilter matchedFilter) {
    ComponentName componentName = new ComponentName(getPackageName(),
            SendMessageActivity.class.getCanonicalName());
    // The list of Direct Share items. The system will show the items the way they are sorted
    // in this list.
    ArrayList<ChooserTarget> targets = new ArrayList<>();
    for (int i = 0; i < Contact.CONTACTS.length; ++i) {
        Contact contact = Contact.byId(i);
        Bundle extras = new Bundle();
        extras.putInt(Contact.ID, i);
        targets.add(new ChooserTarget(
                // The name of this target.
                contact.getName(),
                // The icon to represent this target.
                Icon.createWithResource(this, contact.getIcon()),
                // The ranking score for this target (0.0-1.0); the system will omit items with
                // low scores when there are too many Direct Share items.
                0.5f,
                // The name of the component to be launched if this target is chosen.
                componentName,
                // The extra values here will be merged into the Intent when this target is
                // chosen.
                extras));
    }
    return targets;
}
 
Example #8
Source File: ContactChooserTargetService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
    if (!EventReceiver.hasEnabledAccounts(this)) {
        return chooserTargets;
    }
    final Intent intent = new Intent(this, XmppConnectionService.class);
    intent.setAction("contact_chooser");
    Compatibility.startService(this, intent);
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    try {
        waitForService();
        final ArrayList<Conversation> conversations = new ArrayList<>();
        if (!mXmppConnectionService.areMessagesInitialized()) {
            return chooserTargets;
        }
        
        mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter));
        final ComponentName componentName = new ComponentName(this, ConversationsActivity.class);
        final int pixel = AvatarService.getSystemUiAvatarSize(this);
        for (Conversation conversation : conversations) {
            if (conversation.sentMessagesCount() == 0) {
                continue;
            }
            final String name = conversation.getName().toString();
            final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
            final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size();
            final Bundle extras = new Bundle();
            extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
            chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
            if (chooserTargets.size() >= MAX_TARGETS) {
                break;
            }
        }
    } catch (InterruptedException e) {
    }
    unbindService(this);
    return chooserTargets;
}
 
Example #9
Source File: DirectShareService.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
                                               IntentFilter matchedFilter)
{
  List<ChooserTarget> results        = new LinkedList<>();
  ComponentName       componentName  = new ComponentName(this, ShareActivity.class);
  ThreadDatabase      threadDatabase = DatabaseFactory.getThreadDatabase(this);
  Cursor              cursor         = threadDatabase.getRecentConversationList(10, false);

  try {
    ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor);
    ThreadRecord record;

    while ((record = reader.getNext()) != null) {
        Recipient recipient = Recipient.resolved(record.getRecipient().getId());
        String    name      = recipient.toShortString(this);

        Bitmap avatar;

        if (recipient.getContactPhoto() != null) {
          try {
            avatar = GlideApp.with(this)
                             .asBitmap()
                             .load(recipient.getContactPhoto())
                             .circleCrop()
                             .submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                                     getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
                             .get();
          } catch (InterruptedException | ExecutionException e) {
            Log.w(TAG, e);
            avatar = getFallbackDrawable(recipient);
          }
        } else {
          avatar = getFallbackDrawable(recipient);
        }

        Bundle bundle = new Bundle();
        bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
        bundle.putString(ShareActivity.EXTRA_RECIPIENT_ID, recipient.getId().serialize());
        bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
        bundle.setClassLoader(getClassLoader());

        results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
    }

    return results;
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
Example #10
Source File: ChooserTargetsCache.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
private ChooserTarget get(@NonNull String id) {
    return cache.get(id);
}
 
Example #11
Source File: DirectShareService.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
                                               IntentFilter matchedFilter)
{
  List<ChooserTarget> results        = new LinkedList<>();
  ComponentName       componentName  = new ComponentName(this, ShareActivity.class);
  ApplicationDcContext dcContext = DcHelper.getContext(this);

  DcChatlist chatlist = dcContext.getChatlist(
          DcContext.DC_GCL_ADD_ALLDONE_HINT | DcContext.DC_GCL_FOR_FORWARDING | DcContext.DC_GCL_NO_SPECIALS,
          null,
          0
  );
  int max = 4;
  if (chatlist.getCnt() < max) {
    max = chatlist.getCnt();
  }
  for (int i = 0; i <= max; i++) {
    DcChat chat = chatlist.getChat(i);
    if (!chat.canSend()) {
      continue;
    }

    Bundle bundle = new Bundle();
    bundle.putInt(ShareActivity.EXTRA_CHAT_ID, chat.getId());
    bundle.setClassLoader(getClassLoader());
    Recipient recipient = DcHelper.getContext(this).getRecipient(chat);
    Bitmap avatar;
    try {
      avatar = GlideApp.with(this)
              .asBitmap()
              .load(recipient.getContactPhoto(this))
              .circleCrop()
              .submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                      getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
              .get();
    } catch (InterruptedException | ExecutionException | NullPointerException e) {
      Log.w(TAG, e);
      avatar = getFallbackDrawable(recipient);
    }
    results.add(new ChooserTarget(chat.getName(), Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
  }

  return results;
}