当前位置: 首页>>代码示例>>Java>>正文


Java ChooserTarget类代码示例

本文整理汇总了Java中android.service.chooser.ChooserTarget的典型用法代码示例。如果您正苦于以下问题:Java ChooserTarget类的具体用法?Java ChooserTarget怎么用?Java ChooserTarget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChooserTarget类属于android.service.chooser包,在下文中一共展示了ChooserTarget类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@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;
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:24,代码来源:IRCChooserTargetService.java

示例2: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@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;
}
 
开发者ID:DIY-green,项目名称:AndroidStudyDemo,代码行数:18,代码来源:DirectShareService.java

示例3: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:39,代码来源:DirectShareService.java

示例4: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@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;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:29,代码来源:SampleChooserTargetService.java

示例5: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
	Intent intent = new Intent(this, XmppConnectionService.class);
	intent.setAction("contact_chooser");
	startService(intent);
	bindService(intent, this, Context.BIND_AUTO_CREATE);
	ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
	try {
		waitForService();
		final ArrayList<Conversation> conversations = new ArrayList<>();
		if (!mXmppConnectionService.areMessagesInitialized()) {
			return chooserTargets;
		}
		mXmppConnectionService.populateWithOrderedConversations(conversations, false);
		final ComponentName componentName = new ComponentName(this, ShareWithActivity.class);
		final int pixel = (int) (48 * getResources().getDisplayMetrics().density);
		for(int i = 0; i < Math.min(conversations.size(),MAX_TARGETS); ++i) {
			final Conversation conversation = conversations.get(i);
			final String name = conversation.getName();
			final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
			final float score = 1 - (1.0f / MAX_TARGETS) * i;
			final Bundle extras = new Bundle();
			extras.putString("uuid", conversation.getUuid());
			chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
		}
	} catch (InterruptedException e) {
	}
	unbindService(this);
	return chooserTargets;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:31,代码来源:ContactChooserTargetService.java

示例6: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
	Intent intent = new Intent(this, XmppConnectionService.class);
	intent.setAction("contact_chooser");
	startService(intent);
	bindService(intent, this, Context.BIND_AUTO_CREATE);
	ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
	try {
		waitForService();
		final ArrayList<Conversation> conversations = new ArrayList<>();
		if (!mXmppConnectionService.areMessagesInitialized()) {
			return chooserTargets;
		}
		mXmppConnectionService.populateWithOrderedConversations(conversations, false);
		final ComponentName componentName = new ComponentName(this, ShareWithActivity.class);
		final int pixel = (int) (48 * getResources().getDisplayMetrics().density);
		for(int i = 0; i < Math.min(conversations.size(),MAX_TARGETS); ++i) {
			final Conversation conversation = conversations.get(i);
			final String name = conversation.getName();
			final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
			final float score = (1.0f / MAX_TARGETS) * i;
			final Bundle extras = new Bundle();
			extras.putString("uuid", conversation.getUuid());
			chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
		}
	} catch (InterruptedException e) {
	}
	unbindService(this);
	return chooserTargets;
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:31,代码来源:ContactChooserTargetService.java

示例7: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter)
{
	AccessDatabase database = new AccessDatabase(getApplicationContext());
	ArrayList<ChooserTarget> list = new ArrayList<>();

	for (NetworkDevice device : database.castQuery(new SQLQuery.Select(AccessDatabase.TABLE_DEVICES), NetworkDevice.class)) {
		if (device.isLocalAddress)
			continue;

		Bundle bundle = new Bundle();

		bundle.putString(ShareActivity.EXTRA_DEVICE_ID, device.deviceId);

		String firstLetters = TextUtils.getFirstLetters(device.nickname, 1);
		TextDrawable textImage = TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(this, R.color.networkDeviceRipple), 100);
		Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);

		textImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
		textImage.draw(canvas);

		float result = (float) device.lastUsageTime / (float) System.currentTimeMillis();

		list.add(new ChooserTarget(
				device.nickname,
				Icon.createWithBitmap(bitmap),
				result,
				targetActivityName,
				bundle
		));
	}

	return list;
}
 
开发者ID:genonbeta,项目名称:TrebleShot,代码行数:36,代码来源:DeviceChooserService.java

示例8: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName componentName, IntentFilter intentFilter) {
    Log.d(TAG, "onGetChooserTargets()");

    final List<ChooserTarget> targets = new LinkedList<>();
    targets.add(createTarget("David K.", R.drawable.icon_david, 0.4f));
    targets.add(createTarget("Erin D.", R.drawable.icon_erin, 0.6f));
    targets.add(createTarget("Austin M.", R.drawable.icon_austin, 0.2f));

    return targets;
}
 
开发者ID:ToxicBakery,项目名称:MarshmallowDemo,代码行数:12,代码来源:DirectShareService.java

示例9: createTarget

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
private ChooserTarget createTarget(@NonNull String name,
                                   @DrawableRes int iconRes,
                                   @FloatRange(from = 0, to = 1) float score) {

    Bitmap bitmapSource = BitmapFactory.decodeResource(getResources(), iconRes);
    Bitmap bitmapCircleCrop = ImageUtil.circleCrop(bitmapSource);

    Icon icon = Icon.createWithBitmap(bitmapCircleCrop);
    ComponentName componentName = new ComponentName(this, ActivityShareReceiver.class);

    Bundle bundle = new Bundle();
    bundle.putString(ActivityShareReceiver.EXTRA_SENDER_NAME, name);

    return new ChooserTarget(name, icon, score, componentName, bundle);
}
 
开发者ID:ToxicBakery,项目名称:MarshmallowDemo,代码行数:16,代码来源:DirectShareService.java

示例10: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    Intent intent = new Intent(this, XmppConnectionService.class);
    intent.setAction("contact_chooser");
    startService(intent);
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
    try {
        waitForService();
        final ArrayList<Conversation> conversations = new ArrayList<>();
        if (!mXmppConnectionService.areMessagesInitialized()) {
            return chooserTargets;
        }
        mXmppConnectionService.populateWithOrderedConversations(conversations, false);
        final ComponentName componentName = new ComponentName(this, ShareWithActivity.class);
        final int pixel = (int) (48 * getResources().getDisplayMetrics().density);
        for (int i = 0; i < Math.min(conversations.size(), MAX_TARGETS); ++i) {
            final Conversation conversation = conversations.get(i);
            final String name = conversation.getName();
            final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
            final float score = 1 - (1.0f / MAX_TARGETS) * i;
            final Bundle extras = new Bundle();
            extras.putString("uuid", conversation.getUuid());
            chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
        }
    } catch (InterruptedException e) {
    }
    unbindService(this);
    return chooserTargets;
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:31,代码来源:ContactChooserTargetService.java

示例11: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
                                               IntentFilter matchedFilter) {
    sendAnalyticsEvent();

    ComponentName componentName = new ComponentName( this, ShareToOpenWith.class);

    return Collections.singletonList(new ChooserTarget(
            getString(R.string.open_with),
            Icon.createWithResource(this, R.mipmap.ic_launcher_main),
            0.2f,
            componentName,
            createBundleExtra()
    ));
}
 
开发者ID:tasomaniac,项目名称:OpenLinkWith,代码行数:16,代码来源:ResolverChooserTargetService.java

示例12: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
/**
 * Returns a list of targets available for sharing, in this case, the last {@link #MAX_TARGETS}
 * open conversations.
 */
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    ComponentName componentName = new ComponentName(getPackageName(),
        ComposeMessage.class.getCanonicalName());

    Cursor cursor = MessagesProviderClient.getLatestThreads(this, false, MAX_TARGETS);
    if (cursor.moveToFirst()) {
        List<ChooserTarget> targets = new ArrayList<>(MAX_TARGETS);
        do {
            String userId = cursor.getString(MessagesProviderClient.LATEST_THREADS_COLUMN_PEER);

            Contact contact = Contact.findByUserId(this, userId);

            // ComposeMessage will get an ACTION_SEND intent with a user id extra.
            // This will skip the chooseContact() step and go directly to the conversation
            Bundle extras = new Bundle();
            extras.putString(ComposeMessage.EXTRA_USERID, userId);
            targets.add(new ChooserTarget(contact.getDisplayName(),
                Icon.createWithBitmap(createRoundBitmap(contact.getAvatarBitmap(this))), 0.5f,
                componentName, extras));
        } while (cursor.moveToNext());
        return targets;
    }

    return Collections.emptyList();
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:31,代码来源:DirectShareTargetService.java

示例13: onGetChooserTargets

import android.service.chooser.ChooserTarget; //导入依赖的package包/类
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    Log.d(TAG, "onGetChooserTargets");
    final List<ChooserTarget> targets = new ArrayList<>();

    if (!mManager.isDefaultSmsPackage()) {
        Log.w(TAG, "We're not the default SMS app, so ignoring this event");
        // If we can't send texts, then don't have targets.
        return targets;
    }

    final ComponentName componentName = new ComponentName(this, MessageActivity.class);

    List<Thread> recentThreads = getRecentThreads();
    for (Thread thread : recentThreads) {
        final String title = getTitle(thread);
        final Icon icon = getIcon(thread);
        final float score = 1.0f - ((float) recentThreads.indexOf(thread) / recentThreads.size());
        final Bundle extras = new Bundle();
        extras.putString(MessageActivity.EXTRA_THREAD_ID, thread.getId());
        extras.putString(Intent.EXTRA_PHONE_NUMBER, getRecipients(thread));

        targets.add(new ChooserTarget(title, icon, score, componentName, extras));
    }
    Log.i(TAG, "Found " + recentThreads.size() + " recent threads.");

    return targets;
}
 
开发者ID:Xlythe,项目名称:AndroidTextManager,代码行数:29,代码来源:FetchChooserTargetService.java


注:本文中的android.service.chooser.ChooserTarget类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。