Search in sources :

Example 46 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterWithTooSmallSquareBitmap.

@Test
public void testFitCenterWithTooSmallSquareBitmap() {
    final int maxSide = 500;
    Bitmap smallSquare = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, smallSquare, maxSide, maxSide);
    assertHasOriginalAspectRatio(smallSquare, transformed);
    assertBitmapFitsExactlyWithinBounds(maxSide, transformed);
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 47 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testCenterCropReturnsGivenBitmapIfGivenBitmapExactlyMatchesGivenDimensions.

@Test
public void testCenterCropReturnsGivenBitmapIfGivenBitmapExactlyMatchesGivenDimensions() {
    Bitmap toCrop = Bitmap.createBitmap(200, 300, Bitmap.Config.ARGB_8888);
    Bitmap transformed = TransformationUtils.centerCrop(bitmapPool, toCrop, toCrop.getWidth(), toCrop.getHeight());
    // Robolectric incorrectly implements equals() for Bitmaps, we want the original object not
    // just an equivalent.
    assertTrue(toCrop == transformed);
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 48 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterWithSmallTallBitmap.

@Test
public void testFitCenterWithSmallTallBitmap() {
    final int maxSide = 500;
    Bitmap smallTall = Bitmap.createBitmap(10, 400, Bitmap.Config.ARGB_8888);
    Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, smallTall, maxSide, maxSide);
    assertHasOriginalAspectRatio(smallTall, transformed);
    assertBitmapFitsExactlyWithinBounds(maxSide, transformed);
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 49 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterReturnsGivenBitmapIfGivenBitmapWidthMatchesExactly.

@Test
public void testFitCenterReturnsGivenBitmapIfGivenBitmapWidthMatchesExactly() {
    Bitmap toFit = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444);
    Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, toFit, toFit.getWidth(), toFit.getHeight() * 2);
    assertTrue(toFit == transformed);
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 50 with Bitmap

use of android.graphics.Bitmap in project ADWLauncher2 by boombuler.

the class CustomShirtcutActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch(requestCode) {
            case PICK_CUSTOM_PICTURE:
                mBitmap = (Bitmap) data.getParcelableExtra("data");
                if (mBitmap != null) {
                    if (mBitmap.getWidth() > mIconSize)
                        mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                    btPickIcon.setImageBitmap(mBitmap);
                }
                break;
            case PICK_CUSTOM_ICON:
                Uri photoUri = data.getData();
                try {
                    InputStream is = getContentResolver().openInputStream(photoUri);
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    BitmapFactory.decodeStream(is, null, opts);
                    BitmapFactory.Options ops2 = new BitmapFactory.Options();
                    int width = mIconSize;
                    float w = opts.outWidth;
                    //int scale = Math.round(w / width);
                    int scale = (int) (w / width);
                    ops2.inSampleSize = scale;
                    is = getContentResolver().openInputStream(photoUri);
                    mBitmap = BitmapFactory.decodeStream(is, null, ops2);
                    if (mBitmap != null) {
                        if (mBitmap.getWidth() > mIconSize)
                            mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                        btPickIcon.setImageBitmap(mBitmap);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case PICK_FROM_ICON_PACK:
                mBitmap = (Bitmap) data.getParcelableExtra("icon");
                if (mBitmap != null) {
                    if (mBitmap.getWidth() > mIconSize)
                        mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                    btPickIcon.setImageBitmap(mBitmap);
                }
                break;
            case PICK_STANDARD_MENU:
                String applicationName = getResources().getString(R.string.group_applications);
                String activitiesName = getResources().getString(R.string.shirtcuts_activity);
                String launcheractionsName = getResources().getString(R.string.launcher_actions);
                String shortcutName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
                if (applicationName != null && applicationName.equals(shortcutName)) {
                    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
                    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
                    pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
                    startActivityForResult(pickIntent, PICK_STANDARD_APPLICATION);
                } else if (activitiesName != null && activitiesName.equals(shortcutName)) {
                    Intent picker = new Intent();
                    picker.setClass(this, ActivityPickerActivity.class);
                    startActivityForResult(picker, PICK_STANDARD_SHORTCUT);
                } else if (launcheractionsName != null && launcheractionsName.equals(shortcutName)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle(getString(R.string.launcher_actions));
                    final ListAdapter adapter = LauncherActions.getInstance().getSelectActionAdapter();
                    builder.setAdapter(adapter, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            LauncherActions.Action action = (LauncherActions.Action) adapter.getItem(which);
                            Intent result = new Intent();
                            result.putExtra(Intent.EXTRA_SHORTCUT_NAME, action.getName());
                            result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, LauncherActions.getInstance().getIntentForAction(action));
                            ShortcutIconResource iconResource = new ShortcutIconResource();
                            iconResource.packageName = CustomShirtcutActivity.this.getPackageName();
                            iconResource.resourceName = getResources().getResourceName(action.getIconResourceId());
                            result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
                            onActivityResult(PICK_STANDARD_SHORTCUT, RESULT_OK, result);
                        }
                    });
                    builder.create().show();
                } else {
                    startActivityForResult(data, PICK_STANDARD_SHORTCUT);
                }
                break;
            case PICK_STANDARD_APPLICATION:
                if (mBitmap != null) {
                    mBitmap.recycle();
                    mBitmap = null;
                }
                ComponentName component = data.getComponent();
                ActivityInfo activityInfo = null;
                try {
                    activityInfo = mPackageManager.getActivityInfo(component, 0);
                } catch (NameNotFoundException e) {
                }
                String title = null;
                if (activityInfo != null) {
                    title = activityInfo.loadLabel(mPackageManager).toString();
                    if (title == null) {
                        title = activityInfo.name;
                    }
                    mIntent = data;
                    btPickActivity.setText(title);
                    mBitmap = null;
                    btPickIcon.setImageDrawable(activityInfo.loadIcon(mPackageManager));
                    btPickIcon.setEnabled(true);
                    btOk.setEnabled(true);
                    edLabel.setText(title);
                }
                break;
            case PICK_STANDARD_SHORTCUT:
                if (mBitmap != null) {
                    mBitmap.recycle();
                    mBitmap = null;
                }
                Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
                String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
                Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
                Drawable icon = null;
                if (bitmap != null) {
                    icon = new FastBitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
                    mBitmap = bitmap;
                } else {
                    Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                    if (extra != null && extra instanceof ShortcutIconResource) {
                        try {
                            ShortcutIconResource iconResource = (ShortcutIconResource) extra;
                            Resources resources = mPackageManager.getResourcesForApplication(iconResource.packageName);
                            final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                            icon = resources.getDrawable(id);
                            mBitmap = Utilities.createIconBitmap(icon, this);
                        } catch (Exception e) {
                        }
                    }
                }
                if (icon == null) {
                    icon = getPackageManager().getDefaultActivityIcon();
                }
                mIntent = intent;
                btPickActivity.setText(name);
                btPickIcon.setImageDrawable(icon);
                btPickIcon.setEnabled(true);
                btOk.setEnabled(true);
                edLabel.setText(name);
                break;
            default:
                break;
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ComponentName(android.content.ComponentName) BitmapFactory(android.graphics.BitmapFactory) ListAdapter(android.widget.ListAdapter) ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) InputStream(java.io.InputStream) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Parcelable(android.os.Parcelable) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LauncherActions(org.adw.launcher2.actions.LauncherActions) Resources(android.content.res.Resources)

Aggregations

Bitmap (android.graphics.Bitmap)3746 Canvas (android.graphics.Canvas)889 Paint (android.graphics.Paint)709 BitmapDrawable (android.graphics.drawable.BitmapDrawable)461 IOException (java.io.IOException)394 Rect (android.graphics.Rect)341 File (java.io.File)262 Test (org.junit.Test)255 Matrix (android.graphics.Matrix)254 Drawable (android.graphics.drawable.Drawable)243 BitmapFactory (android.graphics.BitmapFactory)240 View (android.view.View)225 ImageView (android.widget.ImageView)210 Intent (android.content.Intent)187 FileOutputStream (java.io.FileOutputStream)186 InputStream (java.io.InputStream)171 RectF (android.graphics.RectF)150 FileNotFoundException (java.io.FileNotFoundException)150 Point (android.graphics.Point)148 Uri (android.net.Uri)128