Home.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:buildAPKsSamples 作者:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ApplicationInfo info = mApplications.get(position);

    if (convertView == null) {
        final LayoutInflater inflater = getLayoutInflater();
        convertView = inflater.inflate(R.layout.application, parent, false);
    }

    Drawable icon = info.icon;

    if (!info.filtered) {
        //final Resources resources = getContext().getResources();
        int width = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
        int height = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);

        final int iconWidth = icon.getIntrinsicWidth();
        final int iconHeight = icon.getIntrinsicHeight();

        if (icon instanceof PaintDrawable) {
            PaintDrawable painter = (PaintDrawable) icon;
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        }

        if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
            final float ratio = (float) iconWidth / iconHeight;

            if (iconWidth > iconHeight) {
                height = (int) (width / ratio);
            } else if (iconHeight > iconWidth) {
                width = (int) (height * ratio);
            }

            final Bitmap.Config c =
                    icon.getOpacity() != PixelFormat.OPAQUE ?
                        Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
            final Bitmap thumb = Bitmap.createBitmap(width, height, c);
            final Canvas canvas = new Canvas(thumb);
            canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
            // Copy the old bounds to restore them later
            // If we were to do oldBounds = icon.getBounds(),
            // the call to setBounds() that follows would
            // change the same instance and we would lose the
            // old bounds
            mOldBounds.set(icon.getBounds());
            icon.setBounds(0, 0, width, height);
            icon.draw(canvas);
            icon.setBounds(mOldBounds);
            icon = info.icon = new BitmapDrawable(thumb);
            info.filtered = true;
        }
    }

    final TextView textView = (TextView) convertView.findViewById(R.id.label);
    textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    textView.setText(info.title);

    return convertView;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号