Java Code Examples for android.app.activitymanager#getLauncherLargeIconDensity()

The following examples show how to use android.app.activitymanager#getLauncherLargeIconDensity() . 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: 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 2
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 3
Source File: IconCache.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public IconCache(Context context) {
	ActivityManager activityManager = (ActivityManager) context
			.getSystemService(Context.ACTIVITY_SERVICE);

	mContext = context;
	mPackageManager = context.getPackageManager();
	mIconDpi = activityManager.getLauncherLargeIconDensity();

	// need to set mIconDpi before getting default icon
	mDefaultIcon = makeDefaultIcon();
}
 
Example 4
Source File: IconCache.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
public IconCache(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    mContext = context;
    mPackageManager = context.getPackageManager();
    mIconDpi = activityManager.getLauncherLargeIconDensity();
    mDefaultIcon = makeDefaultIcon();
    mIconPackHelper = new IconPackHelper(context);
    loadIconPack();

}
 
Example 5
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 6
Source File: IconCache.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public IconCache(Context context) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    mContext = context;
    mPackageManager = context.getPackageManager();
    mUserManager = UserManagerCompat.getInstance(mContext);
    mLauncherApps = LauncherAppsCompat.getInstance(mContext);
    mIconDpi = activityManager.getLauncherLargeIconDensity();

    // need to set mIconDpi before getting default icon
    UserHandleCompat myUser = UserHandleCompat.myUserHandle();
    mDefaultIcons.put(myUser, makeDefaultIcon(myUser));
}
 
Example 7
Source File: IconCache.java    From KAM with GNU General Public License v3.0 5 votes vote down vote up
public IconCache(Context context) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    mContext = context;
    mPackageManager = context.getPackageManager();
    mIconDpi = activityManager.getLauncherLargeIconDensity();

    // need to set mIconDpi before getting default icon
    mDefaultIcon = makeDefaultIcon();
}
 
Example 8
Source File: IconCacheHelper.java    From Hangar with GNU General Public License v3.0 5 votes vote down vote up
public IconCacheHelper(Context context) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    mContext = context;
    mPackageManager = context.getPackageManager();
    mIconDpi = activityManager.getLauncherLargeIconDensity();
    // need to set mIconDpi before getting default icon

    mIconPackHelper = new IconPackHelper(context);
    loadIconPack();
}
 
Example 9
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 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: 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
//            }
//        }
    }
 
Example 12
Source File: AppIconRequestHandler.java    From AndroidProcesses with Apache License 2.0 4 votes vote down vote up
public AppIconRequestHandler(Context context) {
  ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
  dpi = am.getLauncherLargeIconDensity();
  pm = context.getPackageManager();
}