android.app.ActivityManager#getLauncherLargeIconDensity ( )源码实例Demo

下面列出了android.app.ActivityManager#getLauncherLargeIconDensity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: delion   文件: ShortcutHelper.java
/**
 * 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;
}
 
源代码2 项目: AndroidChromium   文件: ShortcutHelper.java
/**
 * 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;
}
 
源代码3 项目: TurboLauncher   文件: IconCache.java
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();
}
 
源代码4 项目: FastAccess   文件: IconCache.java
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();

}
 
源代码5 项目: 365browser   文件: ShortcutHelper.java
/**
 * 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;
}
 
源代码6 项目: LB-Launcher   文件: IconCache.java
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));
}
 
源代码7 项目: KAM   文件: IconCache.java
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();
}
 
源代码8 项目: Hangar   文件: IconCacheHelper.java
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();
}
 
源代码9 项目: android-chromium   文件: BookmarkUtils.java
/**
 * 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;
}
 
源代码10 项目: android-chromium   文件: BookmarkUtils.java
/**
 * 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;
}
 
源代码11 项目: container   文件: ResolverActivity.java
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
//            }
//        }
    }
 
源代码12 项目: AndroidProcesses   文件: AppIconRequestHandler.java
public AppIconRequestHandler(Context context) {
  ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
  dpi = am.getLauncherLargeIconDensity();
  pm = context.getPackageManager();
}