Search in sources :

Example 1 with ChooserTarget

use of android.service.chooser.ChooserTarget in project cw-omnibus by commonsguy.

the class CTService method buildTarget.

private ChooserTarget buildTarget(int targetId) {
    String title = String.format(titleTemplate, targetId);
    int iconId = getResources().getIdentifier("ic_share" + targetId, "drawable", getPackageName());
    Icon icon = Icon.createWithResource(this, iconId);
    float score = 1.0f - ((float) targetId / 40);
    ComponentName cn = new ComponentName(this, FauxSender.class);
    Bundle extras = new Bundle();
    extras.putInt(FauxSender.EXTRA_TARGET_ID, targetId);
    return (new ChooserTarget(title, icon, score, cn, extras));
}
Also used : Bundle(android.os.Bundle) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 2 with ChooserTarget

use of android.service.chooser.ChooserTarget in project Conversations by siacs.

the class ContactChooserTargetService method onGetChooserTargets.

@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;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Conversation(eu.siacs.conversations.entities.Conversation) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 3 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by DirtyUnicorns.

the class ChooserActivity method filterServiceTargets.

void filterServiceTargets(String packageName, List<ChooserTarget> targets) {
    if (targets == null) {
        return;
    }
    final PackageManager pm = getPackageManager();
    for (int i = targets.size() - 1; i >= 0; i--) {
        final ChooserTarget target = targets.get(i);
        final ComponentName targetName = target.getComponentName();
        if (packageName != null && packageName.equals(targetName.getPackageName())) {
            // Anything from the original target's package is fine.
            continue;
        }
        boolean remove;
        try {
            final ActivityInfo ai = pm.getActivityInfo(targetName, 0);
            remove = !ai.exported || ai.permission != null;
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Target " + target + " returned by " + packageName + " component not found");
            remove = true;
        }
        if (remove) {
            targets.remove(i);
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Example 4 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by AOSPA.

the class ChooserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (!(targetParcelable instanceof Intent)) {
        Log.w("ChooserActivity", "Target is not an intent: " + targetParcelable);
        finish();
        super.onCreate(null);
        return;
    }
    Intent target = (Intent) targetParcelable;
    if (target != null) {
        modifyTargetIntent(target);
    }
    Parcelable[] targetsParcelable = intent.getParcelableArrayExtra(Intent.EXTRA_ALTERNATE_INTENTS);
    if (targetsParcelable != null) {
        final boolean offset = target == null;
        Intent[] additionalTargets = new Intent[offset ? targetsParcelable.length - 1 : targetsParcelable.length];
        for (int i = 0; i < targetsParcelable.length; i++) {
            if (!(targetsParcelable[i] instanceof Intent)) {
                Log.w(TAG, "EXTRA_ALTERNATE_INTENTS array entry #" + i + " is not an Intent: " + targetsParcelable[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent additionalTarget = (Intent) targetsParcelable[i];
            if (i == 0 && target == null) {
                target = additionalTarget;
                modifyTargetIntent(target);
            } else {
                additionalTargets[offset ? i - 1 : i] = additionalTarget;
                modifyTargetIntent(additionalTarget);
            }
        }
        setAdditionalTargets(additionalTargets);
    }
    mReplacementExtras = intent.getBundleExtra(Intent.EXTRA_REPLACEMENT_EXTRAS);
    CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
    int defaultTitleRes = 0;
    if (title == null) {
        defaultTitleRes = com.android.internal.R.string.chooseActivity;
    }
    Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
    Intent[] initialIntents = null;
    if (pa != null) {
        initialIntents = new Intent[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof Intent)) {
                Log.w(TAG, "Initial intent #" + i + " not an Intent: " + pa[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent in = (Intent) pa[i];
            modifyTargetIntent(in);
            initialIntents[i] = in;
        }
    }
    mReferrerFillInIntent = new Intent().putExtra(Intent.EXTRA_REFERRER, getReferrer());
    mChosenComponentSender = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
    mRefinementIntentSender = intent.getParcelableExtra(Intent.EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER);
    setSafeForwardingMode(true);
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_EXCLUDE_COMPONENTS);
    if (pa != null) {
        ComponentName[] names = new ComponentName[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ComponentName)) {
                Log.w(TAG, "Filtered component #" + i + " not a ComponentName: " + pa[i]);
                names = null;
                break;
            }
            names[i] = (ComponentName) pa[i];
        }
        setFilteredComponents(names);
    }
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS);
    if (pa != null) {
        ChooserTarget[] targets = new ChooserTarget[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ChooserTarget)) {
                Log.w(TAG, "Chooser target #" + i + " not a ChooserTarget: " + pa[i]);
                targets = null;
                break;
            }
            targets[i] = (ChooserTarget) pa[i];
        }
        mCallerChooserTargets = targets;
    }
    mPinnedSharedPrefs = getPinnedSharedPrefs(this);
    super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents, null, false);
    MetricsLogger.action(this, MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN);
}
Also used : ChooserTarget(android.service.chooser.ChooserTarget) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) ComponentName(android.content.ComponentName)

Example 5 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by ResurrectionRemix.

the class ChooserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (!(targetParcelable instanceof Intent)) {
        Log.w("ChooserActivity", "Target is not an intent: " + targetParcelable);
        finish();
        super.onCreate(null);
        return;
    }
    Intent target = (Intent) targetParcelable;
    if (target != null) {
        modifyTargetIntent(target);
    }
    Parcelable[] targetsParcelable = intent.getParcelableArrayExtra(Intent.EXTRA_ALTERNATE_INTENTS);
    if (targetsParcelable != null) {
        final boolean offset = target == null;
        Intent[] additionalTargets = new Intent[offset ? targetsParcelable.length - 1 : targetsParcelable.length];
        for (int i = 0; i < targetsParcelable.length; i++) {
            if (!(targetsParcelable[i] instanceof Intent)) {
                Log.w(TAG, "EXTRA_ALTERNATE_INTENTS array entry #" + i + " is not an Intent: " + targetsParcelable[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent additionalTarget = (Intent) targetsParcelable[i];
            if (i == 0 && target == null) {
                target = additionalTarget;
                modifyTargetIntent(target);
            } else {
                additionalTargets[offset ? i - 1 : i] = additionalTarget;
                modifyTargetIntent(additionalTarget);
            }
        }
        setAdditionalTargets(additionalTargets);
    }
    mReplacementExtras = intent.getBundleExtra(Intent.EXTRA_REPLACEMENT_EXTRAS);
    CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
    int defaultTitleRes = 0;
    if (title == null) {
        defaultTitleRes = com.android.internal.R.string.chooseActivity;
    }
    Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
    Intent[] initialIntents = null;
    if (pa != null) {
        initialIntents = new Intent[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof Intent)) {
                Log.w(TAG, "Initial intent #" + i + " not an Intent: " + pa[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent in = (Intent) pa[i];
            modifyTargetIntent(in);
            initialIntents[i] = in;
        }
    }
    mReferrerFillInIntent = new Intent().putExtra(Intent.EXTRA_REFERRER, getReferrer());
    mChosenComponentSender = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
    mRefinementIntentSender = intent.getParcelableExtra(Intent.EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER);
    setSafeForwardingMode(true);
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_EXCLUDE_COMPONENTS);
    if (pa != null) {
        ComponentName[] names = new ComponentName[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ComponentName)) {
                Log.w(TAG, "Filtered component #" + i + " not a ComponentName: " + pa[i]);
                names = null;
                break;
            }
            names[i] = (ComponentName) pa[i];
        }
        setFilteredComponents(names);
    }
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS);
    if (pa != null) {
        ChooserTarget[] targets = new ChooserTarget[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ChooserTarget)) {
                Log.w(TAG, "Chooser target #" + i + " not a ChooserTarget: " + pa[i]);
                targets = null;
                break;
            }
            targets[i] = (ChooserTarget) pa[i];
        }
        mCallerChooserTargets = targets;
    }
    mPinnedSharedPrefs = getPinnedSharedPrefs(this);
    super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents, null, false);
    MetricsLogger.action(this, MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN);
}
Also used : ChooserTarget(android.service.chooser.ChooserTarget) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) ComponentName(android.content.ComponentName)

Aggregations

ComponentName (android.content.ComponentName)13 ChooserTarget (android.service.chooser.ChooserTarget)13 Intent (android.content.Intent)6 ActivityInfo (android.content.pm.ActivityInfo)5 LabeledIntent (android.content.pm.LabeledIntent)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Parcelable (android.os.Parcelable)5 Bundle (android.os.Bundle)3 Icon (android.graphics.drawable.Icon)2 PendingIntent (android.app.PendingIntent)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Conversation (eu.siacs.conversations.entities.Conversation)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1