Java Code Examples for android.app.ActivityManager#getLauncherLargeIconSize()

The following examples show how to use android.app.ActivityManager#getLauncherLargeIconSize() . 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: PackageInstallerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void updateSessionAppIcon(int sessionId, Bitmap appIcon) {
    synchronized (mSessions) {
        final PackageInstallerSession session = mSessions.get(sessionId);
        if (session == null || !isCallingUidOwner(session)) {
            throw new SecurityException("Caller has no access to session " + sessionId);
        }

        // Defensively resize giant app icons
        if (appIcon != null) {
            final ActivityManager am = (ActivityManager) mContext.getSystemService(
                    Context.ACTIVITY_SERVICE);
            final int iconSize = am.getLauncherLargeIconSize();
            if ((appIcon.getWidth() > iconSize * 2)
                    || (appIcon.getHeight() > iconSize * 2)) {
                appIcon = Bitmap.createScaledBitmap(appIcon, iconSize, iconSize, true);
            }
        }

        session.params.appIcon = appIcon;
        session.params.appIconLastModified = -1;

        mInternalCallback.onSessionBadgingChanged(session);
    }
}
 
Example 2
Source File: DetailActivity.java    From cashuwallet with MIT License 5 votes vote down vote up
private Bitmap getBitmap(int drawableId) {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    Drawable drawable = ContextCompat.getDrawable(this, drawableId);
    drawable = (DrawableCompat.wrap(drawable)).mutate();
    int iconSize = am.getLauncherLargeIconSize();
    Bitmap bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example 3
Source File: ShortcutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given icon matches the size requirements to be used on the home screen.
 * @param width Icon width, in pixels.
 * @param height Icon height, in pixels.
 * @return whether the given icon matches the size requirements to be used on the home screen.
 */
@CalledByNative
public static boolean isIconLargeEnoughForLauncher(int width, int height) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int minimalSize = am.getLauncherLargeIconSize() / 2;
    return width >= minimalSize && height >= minimalSize;
}
 
Example 4
Source File: ShortcutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
 * a letter in the middle taken from the website's domain name.
 *
 * @param url URL of the shortcut.
 * @param red Red component of the dominant icon color.
 * @param green Green component of the dominant icon color.
 * @param blue Blue component of the dominant icon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int outerSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    // Draw the drop shadow.
    int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
    Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
    Bitmap iconShadow =
            getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(iconShadow, null, outerBounds, paint);

    // Draw the rounded rectangle and letter.
    int innerSize = outerSize - 2 * padding;
    int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
    int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
    int color = Color.rgb(red, green, blue);
    RoundedIconGenerator generator = new RoundedIconGenerator(
            innerSize, innerSize, cornerRadius, color, fontSize);
    Bitmap icon = generator.generateIconForUrl(url);
    if (icon == null) return null; // Bookmark URL does not have a domain.
    canvas.drawBitmap(icon, padding, padding, null);

    return bitmap;
}
 
Example 5
Source File: ShortcutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given icon matches the size requirements to be used on the home screen.
 * @param width Icon width, in pixels.
 * @param height Icon height, in pixels.
 * @return whether the given icon matches the size requirements to be used on the home screen.
 */
@CalledByNative
public static boolean isIconLargeEnoughForLauncher(int width, int height) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int minimalSize = am.getLauncherLargeIconSize() / 2;
    return width >= minimalSize && height >= minimalSize;
}
 
Example 6
Source File: ShortcutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
 * a letter in the middle taken from the website's domain name.
 *
 * @param url URL of the shortcut.
 * @param red Red component of the dominant icon color.
 * @param green Green component of the dominant icon color.
 * @param blue Blue component of the dominant icon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int outerSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    // Draw the drop shadow.
    int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
    Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
    Bitmap iconShadow =
            getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(iconShadow, null, outerBounds, paint);

    // Draw the rounded rectangle and letter.
    int innerSize = outerSize - 2 * padding;
    int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
    int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
    int color = Color.rgb(red, green, blue);
    RoundedIconGenerator generator = new RoundedIconGenerator(
            innerSize, innerSize, cornerRadius, color, fontSize);
    Bitmap icon = generator.generateIconForUrl(url);
    if (icon == null) return null; // Bookmark URL does not have a domain.
    canvas.drawBitmap(icon, padding, padding, null);

    return bitmap;
}
 
Example 7
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given icon matches the size requirements to be used on the home screen.
 * @param width  Icon width, in pixels.
 * @param height Icon height, in pixels.
 * @return whether the given icon matches the size requirements to be used on the home screen.
 */
@CalledByNative
public static boolean isIconLargeEnoughForLauncher(int width, int height) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int minimalSize = am.getLauncherLargeIconSize() / 2;
    return width >= minimalSize && height >= minimalSize;
}
 
Example 8
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
 * a letter in the middle taken from the website's domain name.
 *
 * @param url   URL of the shortcut.
 * @param red   Red component of the dominant icon color.
 * @param green Green component of the dominant icon color.
 * @param blue  Blue component of the dominant icon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int outerSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    // Draw the drop shadow.
    int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
    Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
    Bitmap iconShadow =
            getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(iconShadow, null, outerBounds, paint);

    // Draw the rounded rectangle and letter.
    int innerSize = outerSize - 2 * padding;
    int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
    int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
    int color = Color.rgb(red, green, blue);
    RoundedIconGenerator generator = new RoundedIconGenerator(
            innerSize, innerSize, cornerRadius, color, fontSize);
    Bitmap icon = generator.generateIconForUrl(url);
    if (icon == null) return null; // Bookmark URL does not have a domain.
    canvas.drawBitmap(icon, padding, padding, null);

    return bitmap;
}
 
Example 9
Source File: TelecineActivity.java    From Telecine with Apache License 2.0 5 votes vote down vote up
@NonNull private Bitmap rasterizeTaskIcon() {
  Drawable drawable = getResources().getDrawable(R.drawable.ic_videocam_white_24dp, getTheme());

  ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
  int size = am.getLauncherLargeIconSize();
  Bitmap icon = Bitmap.createBitmap(size, size, ARGB_8888);

  Canvas canvas = new Canvas(icon);
  drawable.setBounds(0, 0, size, size);
  drawable.draw(canvas);

  return icon;
}
 
Example 10
Source File: BookmarkUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates an icon to be associated with this bookmark. If available, the touch icon
 * will be used, else we draw our own.
 * @param context Context used to create the intent.
 * @param favicon Bookmark favicon bitmap.
 * @param rValue Red component of the dominant favicon color.
 * @param gValue Green component of the dominant favicon color.
 * @param bValue Blue component of the dominant favicon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
private static Bitmap createIcon(Context context, Bitmap favicon, int rValue,
        int gValue, int bValue) {
    Bitmap bitmap = null;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int iconSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();
    try {
        bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        if (favicon == null) {
            favicon = getBitmapFromResourceId(context, R.drawable.globe_favicon, iconDensity);
            rValue = gValue = bValue = DEFAULT_RGB_VALUE;
        }
        final int smallestSide = iconSize;
        if (favicon.getWidth() >= smallestSide / 2 && favicon.getHeight() >= smallestSide / 2) {
            drawTouchIconToCanvas(context, favicon, canvas);
        } else {
            drawWidgetBackgroundToCanvas(context, canvas, iconDensity,
                    Color.rgb(rValue, gValue, bValue));
            drawFaviconToCanvas(context, favicon, canvas);
        }
        canvas.setBitmap(null);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
    }
    return bitmap;
}
 
Example 11
Source File: BookmarkUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates an icon to be associated with this bookmark. If available, the touch icon
 * will be used, else we draw our own.
 * @param context Context used to create the intent.
 * @param favicon Bookmark favicon bitmap.
 * @param rValue Red component of the dominant favicon color.
 * @param gValue Green component of the dominant favicon color.
 * @param bValue Blue component of the dominant favicon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
private static Bitmap createIcon(Context context, Bitmap favicon, int rValue,
        int gValue, int bValue) {
    Bitmap bitmap = null;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int iconSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();
    try {
        bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        if (favicon == null) {
            favicon = getBitmapFromResourceId(context, R.drawable.globe_favicon, iconDensity);
            rValue = gValue = bValue = DEFAULT_RGB_VALUE;
        }
        final int smallestSide = iconSize;
        if (favicon.getWidth() >= smallestSide / 2 && favicon.getHeight() >= smallestSide / 2) {
            drawTouchIconToCanvas(context, favicon, canvas);
        } else {
            drawWidgetBackgroundToCanvas(context, canvas, iconDensity,
                    Color.rgb(rValue, gValue, bValue));
            drawFaviconToCanvas(context, favicon, canvas);
        }
        canvas.setBitmap(null);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
    }
    return bitmap;
}
 
Example 12
Source File: ResolverActivity.java    From container with GNU General Public License v3.0 4 votes vote down vote up
protected void onCreate(Bundle savedInstanceState, Intent intent,
                            CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList,
                            boolean alwaysUseOption,int userid) {
        super.onCreate(savedInstanceState);
        mLaunchedFromUid = userid;
        mPm = getPackageManager();
        mAlwaysUseOption = alwaysUseOption;
        mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns);

        mRegistered = true;

        final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        mIconDpi = am.getLauncherLargeIconDensity();
        mIconSize = am.getLauncherLargeIconSize();

        mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList,
                mLaunchedFromUid);
        int count = mAdapter.getCount();
        if (Build.VERSION.SDK_INT >= 17) {
            if (mLaunchedFromUid < 0) {
                // Gulp!
                finish();
                return;
            }
        }

        if (count == 1) {
            startSelected(0, false);
            mRegistered = false;
            finish();
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        if (count > 1) {
            mListView = new ListView(this);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(this);
            mListView.setOnItemLongClickListener(new ItemLongClickListener());
            builder.setView(mListView);
            if (alwaysUseOption) {
                mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            }
        } else {
            builder.setMessage(R.string.noApplications);
        }
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog = builder.show();
//
//        if (alwaysUseOption) {
//            final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
//            if (buttonLayout != null) {
//                buttonLayout.setVisibility(View.VISIBLE);
//                mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
//                mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
//            } else {
//                mAlwaysUseOption = false;
//            }
//            // Set the initial highlight if there was a preferred or last used choice
//            final int initialHighlight = mAdapter.getInitialHighlight();
//            if (initialHighlight >= 0) {
//                mListView.setItemChecked(initialHighlight, true);
//                onItemClick(null, null, initialHighlight, 0); // Other entries are not used
//            }
//        }
    }