android.graphics.drawable.Icon类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(292)

本文整理了Java中android.graphics.drawable.Icon类的一些代码示例,展示了Icon类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Icon类的具体详情如下:
包路径:android.graphics.drawable.Icon
类名称:Icon

Icon介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

private Icon buildIcon(Bookmark item) {
  return(Icon.createWithResource(getActivity(),
   R.drawable.ic_bookmark_border_black_24dp));
 }
}

代码示例来源:origin: k9mail/k-9

@Nullable
  private Icon loadRecipientIcon(Recipient recipient) {
    Bitmap bitmap = contactPictureLoader.getContactPicture(recipient);
    if (bitmap == null) {
      return null;
    }

    return Icon.createWithBitmap(bitmap);
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    //noinspection deprecation
    builder.setSmallIcon(notification.icon);
    //noinspection deprecation
    builder.setLargeIcon(notification.largeIcon);
  } else {
    Icon icon = notification.getSmallIcon();
    if (icon != null) {
      Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setSmallIcon(newIcon);
      }
    }
    Icon largeIcon = notification.getLargeIcon();
    if (largeIcon != null) {
      Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setLargeIcon(newIcon);
      }
    }
  }
}

代码示例来源:origin: WangDaYeeeeee/Mysplash

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,
              size, size));
    } catch (ExecutionException | InterruptedException e) {
      icon = Icon.createWithResource(context, R.drawable.default_avatar_round);
    icon = Icon.createWithBitmap(bitmap);
  } else {
    icon = Icon.createWithResource(context, R.drawable.default_avatar_round);

代码示例来源:origin: WireGuard/wireguard-android

@Override
public void onCreate() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    iconOff = iconOn = Icon.createWithResource(this, R.drawable.ic_tile);
    return;
  }
  final SlashDrawable icon = new SlashDrawable(getResources().getDrawable(R.drawable.ic_tile, Application.get().getTheme()));
  icon.setAnimationEnabled(false); /* Unfortunately we can't have animations, since Icons are marshaled. */
  icon.setSlashed(false);
  Bitmap b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
  Canvas c = new Canvas(b);
  icon.setBounds(0, 0, c.getWidth(), c.getHeight());
  icon.draw(c);
  iconOn = Icon.createWithBitmap(b);
  icon.setSlashed(true);
  b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
  c = new Canvas(b);
  icon.setBounds(0, 0, c.getWidth(), c.getHeight());
  icon.draw(c);
  iconOff = Icon.createWithBitmap(b);
}

代码示例来源:origin: WangDaYeeeeee/Mysplash

@RequiresApi(api = Build.VERSION_CODES.N_MR1)
  private static Icon getShortcutsIcon(Context context,
                     @DrawableRes int id, @DrawableRes int foregroundId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      try {
        DisplayUtils utils = new DisplayUtils(context);
        int size = (int) Math.min(utils.dpToPx(108), 288);
        Bitmap bitmap = ImageHelper.loadBitmap(context, foregroundId, size, size);
        return Icon.createWithAdaptiveBitmap(bitmap);
      } catch (ExecutionException | InterruptedException ignored) {

      }
    }
    return Icon.createWithResource(context, id);
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

@TargetApi(Build.VERSION_CODES.M)
void fixIcon(Icon icon, Context appContext, boolean installed) {
  if (icon == null) {
    return;
  }
  int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
    if (installed) {
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
      mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
    } else {
      Drawable drawable = icon.loadDrawable(appContext);
      Bitmap bitmap = drawableToBitMap(drawable);
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
      mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
      mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
    }
  }
}

代码示例来源:origin: robolectric/robolectric

@HiddenApi
@Implementation
public int getResId() {
 return directlyOn(realIcon, Icon.class).getResId();
}

代码示例来源:origin: LineageOS/android_packages_apps_Jelly

private void addShortcut() {
  Intent intent = new Intent(this, MainActivity.class);
  intent.setData(Uri.parse(mWebView.getUrl()));
  intent.setAction(Intent.ACTION_MAIN);
  Icon launcherIcon;
  if (mUrlIcon != null) {
    launcherIcon = Icon.createWithBitmap(
        UiUtils.getShortcutIcon(mUrlIcon, getThemeColorWithFallback()));
  } else {
    launcherIcon = Icon.createWithResource(this, R.mipmap.ic_launcher);
  }
  String title = mWebView.getTitle();
  ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, title)
      .setShortLabel(title)
      .setIcon(launcherIcon)
      .setIntent(intent)
      .build();
  getSystemService(ShortcutManager.class).requestPinShortcut(shortcutInfo, null);
}

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

.into(size, size)
        .get();
    icon = Icon.createWithAdaptiveBitmap(foreground);
  } catch (InterruptedException | ExecutionException e) {
    icon = Icon.createWithResource(
        c,
        WeatherHelper.getShortcutIcon(
  icon = Icon.createWithResource(
      c,
      WeatherHelper.getShortcutIcon(
icon = Icon.createWithResource(c, R.drawable.ic_shortcut_sun_day);

代码示例来源:origin: fennifith/Status

@Nullable
public Drawable getLargeIcon(Context context) {
  Drawable drawable = null;
  if (largeIcon != null) drawable = new BitmapDrawable(context.getResources(), largeIcon);
  if (drawable == null && unloadedLargeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    drawable = unloadedLargeIcon.loadDrawable(context);
  return drawable;
}

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = M)
public void build_setsIconOnNotification() throws Exception {
 Notification notification = builder.setSmallIcon(R.drawable.an_image).build();
 assertThat(notification.getSmallIcon().getResId()).isEqualTo(R.drawable.an_image);
}

代码示例来源:origin: commonsguy/cw-omnibus

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));
 }
}

代码示例来源:origin: android-hacker/VirtualXposed

try {
  Drawable applicationIcon = pm.getApplicationIcon(hostPackage);
  Icon icon = Icon.createWithBitmap(((BitmapDrawable) applicationIcon).getBitmap());
  mirror.android.content.pm.ShortcutInfo.mIcon.set(shortcutInfo, icon);
} catch (Throwable ignored) {

代码示例来源:origin: bzsome/VirtualApp-x326

private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    //noinspection deprecation
    builder.setSmallIcon(notification.icon);
    //noinspection deprecation
    builder.setLargeIcon(notification.largeIcon);
  } else {
    Icon icon = notification.getSmallIcon();
    if (icon != null) {
      Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setSmallIcon(newIcon);
      }
    }
    Icon largeIcon = notification.getLargeIcon();
    if (largeIcon != null) {
      Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setLargeIcon(newIcon);
      }
    }
  }
}

代码示例来源:origin: geniusgithub/AndroidDialer

@Nullable
private static Drawable createIconDrawableMarshmallow(PhoneAccount phoneAccount,
    Context context) {
  Icon accountIcon = getIcon(phoneAccount);
  if (accountIcon == null) {
    return null;
  }
  return accountIcon.loadDrawable(context);
}

代码示例来源:origin: org.robolectric/shadows-framework

@HiddenApi
@Implementation
public int getResId() {
 return directlyOn(realIcon, Icon.class).getResId();
}

代码示例来源:origin: commonsguy/cw-omnibus

private RemoteAction buildRemoteAction(int requestCode, int iconId,
                     int titleId, int descId) {
  Intent i=new Intent(this, RemoteActionReceiver.class)
   .putExtra(EXTRA_REQUEST, requestCode);
  PendingIntent pi=PendingIntent.getBroadcast(this, requestCode, i, 0);
  Icon icon=Icon.createWithResource(this, iconId);
  String title=getString(titleId);
  String desc=getString(descId);

  return(new RemoteAction(icon, title, desc, pi));
 }
}

代码示例来源:origin: android-hacker/VirtualXposed

Icon withBitmap = Icon.createWithBitmap(icon);
ShortcutInfo likeShortcut = new ShortcutInfo.Builder(context, id)
    .setShortLabel(name)

代码示例来源:origin: darkskygit/VirtualApp

private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    //noinspection deprecation
    builder.setSmallIcon(notification.icon);
    //noinspection deprecation
    builder.setLargeIcon(notification.largeIcon);
  } else {
    Icon icon = notification.getSmallIcon();
    if (icon != null) {
      Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setSmallIcon(newIcon);
      }
    }
    Icon largeIcon = notification.getLargeIcon();
    if (largeIcon != null) {
      Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
      if (bitmap != null) {
        Icon newIcon = Icon.createWithBitmap(bitmap);
        builder.setLargeIcon(newIcon);
      }
    }
  }
}

相关文章