當前位置: 首頁>>代碼示例>>Java>>正文


Java Icon.createWithBitmap方法代碼示例

本文整理匯總了Java中android.graphics.drawable.Icon.createWithBitmap方法的典型用法代碼示例。如果您正苦於以下問題:Java Icon.createWithBitmap方法的具體用法?Java Icon.createWithBitmap怎麽用?Java Icon.createWithBitmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.Icon的用法示例。


在下文中一共展示了Icon.createWithBitmap方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createShortcutForAndroidN

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void createShortcutForAndroidN() {
    Icon icon;
    if (mIsDefaultIcon) {
        icon = Icon.createWithResource(this, R.drawable.ic_node_js_black);
    } else {
        Bitmap bitmap = BitmapTool.drawableToBitmap(mIcon.getDrawable());
        icon = Icon.createWithBitmap(bitmap);
    }
    PersistableBundle extras = new PersistableBundle(1);
    extras.putString(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath());
    ShortcutManager.getInstance(this).addDynamicShortcut(mName.getText(), mScriptFile.getPath(), icon,
            new Intent(this, ShortcutActivity.class)
                    .putExtra(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath())
                    .setAction(Intent.ACTION_MAIN));
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:17,代碼來源:ShortcutCreateActivity.java

示例2: getIcon

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private Icon getIcon(String subreddit, @DrawableRes int overlay) {
    Bitmap color = Bitmap.createBitmap(toDp(this, 148), toDp(this, 148), Bitmap.Config.RGB_565);
    color.eraseColor(Palette.getColor(subreddit));
    color = clipToCircle(color);

    Bitmap over = drawableToBitmap(ResourcesCompat.getDrawable(getResources(), overlay, null));

    Canvas canvas = new Canvas(color);
    canvas.drawBitmap(over, color.getWidth() / 2 - (over.getWidth() / 2),
            color.getHeight() / 2 - (over.getHeight() / 2), null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return Icon.createWithBitmap(color);
    }
    return null;
}
 
開發者ID:ccrama,項目名稱:Slide,代碼行數:17,代碼來源:MainActivity.java

示例3: createRoundBitmap

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private Icon createRoundBitmap(File path) {
    try {
        Bitmap bitmap = BitmapFactory.decodeFile(path.toString());
        if (bitmap != null) {
            Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
            result.eraseColor(Color.TRANSPARENT);
            Canvas canvas = new Canvas(result);
            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            if (roundPaint == null) {
                roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                bitmapRect = new RectF();
            }
            roundPaint.setShader(shader);
            bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
            canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint);
            return Icon.createWithBitmap(result);
        }
    } catch (Throwable e) {
        FileLog.e(e);
    }
    return null;
}
 
開發者ID:DrKLO,項目名稱:Telegram,代碼行數:23,代碼來源:TgChooserTargetService.java

示例4: sendShortcutBroadcast

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private static void sendShortcutBroadcast(Context context, String shortcutId, Intent shortcutIntent, String title, Bitmap bitmap) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Icon icon = Icon.createWithBitmap(bitmap);

        ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
                        .setIcon(icon)
                        .setShortLabel(title)
                        .setIntent(shortcutIntent)
                        .build();

        ShortcutManager manager = context.getSystemService(ShortcutManager.class);
        if (manager != null) {
            manager.requestPinShortcut(shortcutInfo, null);
        }
    } else {
        final Context app = context.getApplicationContext();

        Intent intent = new Intent();
        intent.setAction(SHURTCUT_ACTION);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
        context.sendBroadcast(intent);

        Completable.complete()
                .observeOn(Injection.provideMainThreadScheduler())
                .subscribe(() -> Toast.makeText(app, R.string.success, Toast.LENGTH_SHORT).show());
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:30,代碼來源:ShortcutUtils.java

示例5: generateThemedIcon

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private static Icon generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) {
    // Get and tint foreground and background drawables
    Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor);
    Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);

    // Squash the two drawables together
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable});

    // Return as an Icon
    return Icon.createWithBitmap(drawableToBitmap(layerDrawable));
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:12,代碼來源:AppShortcutIconGenerator.java

示例6: Builder

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // For Notification.Action.Builder
@SuppressWarnings("deprecation") // For Builder(int, CharSequence, PendingIntent)
private static Notification.Action.Builder getActionBuilder(Action action) {
    Notification.Action.Builder actionBuilder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && action.iconBitmap != null) {
        // Icon was added in Android M.
        Icon icon = Icon.createWithBitmap(action.iconBitmap);
        actionBuilder = new Notification.Action.Builder(icon, action.title, action.intent);
    } else {
        actionBuilder =
                new Notification.Action.Builder(action.iconId, action.title, action.intent);
    }
    return actionBuilder;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:15,代碼來源:NotificationBuilderBase.java

示例7: onGetChooserTargets

import android.graphics.drawable.Icon; //導入方法依賴的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

示例8: onGetChooserTargets

import android.graphics.drawable.Icon; //導入方法依賴的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

示例9: createTarget

import android.graphics.drawable.Icon; //導入方法依賴的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.graphics.drawable.Icon; //導入方法依賴的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: getIcon

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private Icon getIcon(Thread thread) {
    ProfileDrawable drawable = new ProfileDrawable(this, mManager.getMembersExceptMe(thread.getLatestMessage()).get());

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);

    return Icon.createWithBitmap(bitmap);
}
 
開發者ID:Xlythe,項目名稱:AndroidTextManager,代碼行數:10,代碼來源:FetchChooserTargetService.java

示例12: setShortcuts

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static void setShortcuts(Context context, @Nullable Bitmap bitmap) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    List<ShortcutInfo> shortcutList = new ArrayList<>();
    shortcutList.add(
            new ShortcutInfo.Builder(context, context.getString(R.string.action_search))
                    .setIcon(
                            getShortcutsIcon(
                                    context,
                                    R.drawable.ic_shortcut_search,
                                    R.drawable.ic_shortcut_search_foreground))
                    .setShortLabel(context.getString(R.string.action_search))
                    .setLongLabel(context.getString(R.string.action_search))
                    .setIntent(new Intent(MainActivity.ACTION_SEARCH))
                    .setRank(2)
                    .build());
    shortcutList.add(
            new ShortcutInfo.Builder(context, context.getString(R.string.action_download_manage))
                    .setIcon(
                            getShortcutsIcon(
                                    context,
                                    R.drawable.ic_shortcut_download,
                                    R.drawable.ic_shortcut_download_foreground))
                    .setShortLabel(context.getString(R.string.action_download_manage))
                    .setLongLabel(context.getString(R.string.action_download_manage))
                    .setIntent(new Intent(DownloadManageActivity.ACTION_DOWNLOAD_MANAGER))
                    .setRank(3)
                    .build());
    if (AuthManager.getInstance().isAuthorized()) {
        Icon icon;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (bitmap != null) {
                icon = Icon.createWithAdaptiveBitmap(bitmap);
            } else {
                DisplayUtils utils = new DisplayUtils(context);
                int size = (int) Math.min(utils.dpToPx(108), 192);
                try {
                    icon = Icon.createWithAdaptiveBitmap(
                            ImageHelper.loadBitmap(
                                    context,
                                    R.drawable.default_avatar_foreground,
                                    size, size));
                } catch (ExecutionException | InterruptedException e) {
                    icon = Icon.createWithResource(context, R.drawable.default_avatar_round);
                }
            }
        } else {
            if (bitmap != null) {
                icon = Icon.createWithBitmap(bitmap);
            } else {
                icon = Icon.createWithResource(context, R.drawable.default_avatar_round);
            }
        }
        shortcutList.add(
                new ShortcutInfo.Builder(context, AuthManager.getInstance().getUsername())
                        .setIcon(icon)
                        .setShortLabel(AuthManager.getInstance().getUsername())
                        .setLongLabel(AuthManager.getInstance().getUsername())
                        .setIntent(
                                new Intent("com.wangdaye.mysplash.Me")
                                        .putExtra(MeActivity.EXTRA_BROWSABLE, true))
                        .setRank(1)
                        .build());
    }

    shortcutManager.setDynamicShortcuts(shortcutList);
}
 
開發者ID:WangDaYeeeeee,項目名稱:Mysplash,代碼行數:72,代碼來源:ShortcutsManager.java

示例13: getFromBitmap

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
static Icon getFromBitmap(Bitmap bitmap) {
    return Icon.createWithBitmap(bitmap);
}
 
開發者ID:henrichg,項目名稱:PhoneProfiles,代碼行數:4,代碼來源:ColorNotificationIcon.java

示例14: initializeNotification

import android.graphics.drawable.Icon; //導入方法依賴的package包/類
private void initializeNotification() {

        mHandler = new Handler(Looper.getMainLooper()) {

            @Override
            public void handleMessage(Message inputMessage) {

                if (mDestroyed) {
                    return;
                }

                Bitmap bitmap = createBitmapFromString(mDownloadSpeedOutput, mUnits);

                Icon icon = Icon.createWithBitmap(bitmap);

                mBuilder.setSmallIcon(icon);

                mNotifyMgr.notify(mNotificationId, mBuilder.build());

            }

        };

        mBuilder = new Notification.Builder(this);
        mBuilder.setSmallIcon(Icon.createWithBitmap(createBitmapFromString("0", " KB")));
        mBuilder.setContentTitle("");
        mBuilder.setVisibility(Notification.VISIBILITY_SECRET);
        mBuilder.setOngoing(true);

        /*Creates a special PendingIntent so that the app will open when the notification window
        is tapped*/
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent
                .FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(pendingIntent);


        mNotifyMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.notify(mNotificationId, mBuilder.build());

        startForeground(mNotificationId, mBuilder.build());

    }
 
開發者ID:karljamoralin,項目名稱:internet-speed-meter,代碼行數:45,代碼來源:ISMService.java


注:本文中的android.graphics.drawable.Icon.createWithBitmap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。