Search in sources :

Example 1 with RoundedCorners

use of com.bumptech.glide.load.resource.bitmap.RoundedCorners in project glide by bumptech.

the class NonBitmapDrawableResourcesTest method load_withShapeDrawableResourceId_asDrawable_withTransformation_validSize_succeeds.

@Test
public void load_withShapeDrawableResourceId_asDrawable_withTransformation_validSize_succeeds() throws ExecutionException, InterruptedException {
    Drawable drawable = Glide.with(context).load(ResourceIds.drawable.shape_drawable).apply(bitmapTransform(new RoundedCorners(10))).submit(100, 200).get();
    assertThat(drawable).isNotNull();
    assertThat(drawable.getIntrinsicWidth()).isEqualTo(100);
    assertThat(drawable.getIntrinsicHeight()).isEqualTo(200);
}
Also used : Drawable(android.graphics.drawable.Drawable) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) Test(org.junit.Test)

Example 2 with RoundedCorners

use of com.bumptech.glide.load.resource.bitmap.RoundedCorners in project glide by bumptech.

the class WideGamutTest method roundedCorners_withWideGamutBitmap_producesWideGamutBitmap.

@Test
public void roundedCorners_withWideGamutBitmap_producesWideGamutBitmap() {
    Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.RGBA_F16);
    byte[] data = asPng(bitmap);
    Bitmap result = concurrency.get(GlideApp.with(context).asBitmap().load(data).transform(new RoundedCorners(/*roundingRadius=*/
    10)).submit());
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isEqualTo(Config.RGBA_F16);
}
Also used : Bitmap(android.graphics.Bitmap) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) Test(org.junit.Test)

Example 3 with RoundedCorners

use of com.bumptech.glide.load.resource.bitmap.RoundedCorners in project glide by bumptech.

the class RoundedCornersRegressionTest method testRoundedCorners_usePool.

@Test
public void testRoundedCorners_usePool() throws ExecutionException, InterruptedException {
    canonicalBitmap = canonicalBitmap.scale(0.1f);
    Bitmap redRect = createRect(Color.RED, canonicalBitmap.getWidth(), canonicalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Glide.get(context).getBitmapPool().put(redRect);
    Bitmap roundedRect = bitmapRegressionTester.test(GlideApp.with(context).asBitmap().load(canonicalBitmap.getBitmap()).override(canonicalBitmap.getWidth(), canonicalBitmap.getHeight()).transform(new RoundedCorners(5)));
    assertThat(roundedRect).isEqualTo(redRect);
}
Also used : CanonicalBitmap(com.bumptech.glide.test.CanonicalBitmap) Bitmap(android.graphics.Bitmap) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) RegressionTest(com.bumptech.glide.test.RegressionTest) Test(org.junit.Test)

Example 4 with RoundedCorners

use of com.bumptech.glide.load.resource.bitmap.RoundedCorners in project Tusky by Vavassor.

the class NotificationHelper method make.

/**
 * Takes a given Mastodon notification and either creates a new Android notification or updates
 * the state of the existing notification to reflect the new interaction.
 *
 * @param context to access application preferences and services
 * @param body    a new Mastodon notification
 * @param account the account for which the notification should be shown
 */
public static void make(final Context context, Notification body, AccountEntity account, boolean isFirstOfBatch) {
    body = body.rewriteToStatusTypeIfNeeded(account.getAccountId());
    if (!filterNotification(account, body, context)) {
        return;
    }
    String rawCurrentNotifications = account.getActiveNotifications();
    JSONArray currentNotifications;
    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }
    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.getAccount().getName())) {
                currentNotifications.remove(i);
                break;
            }
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }
    currentNotifications.put(body.getAccount().getName());
    account.setActiveNotifications(currentNotifications.toString());
    // Notification group member
    // =========================
    final NotificationCompat.Builder builder = newNotification(context, body, account, false);
    notificationId++;
    builder.setContentTitle(titleForType(context, body, account)).setContentText(bodyForType(body, context));
    if (body.getType() == Notification.Type.MENTION || body.getType() == Notification.Type.POLL) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(bodyForType(body, context)));
    }
    // load the avatar synchronously
    Bitmap accountAvatar;
    try {
        FutureTarget<Bitmap> target = Glide.with(context).asBitmap().load(body.getAccount().getAvatar()).transform(new RoundedCorners(20)).submit();
        accountAvatar = target.get();
    } catch (ExecutionException | InterruptedException e) {
        Log.d(TAG, "error loading account avatar", e);
        accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
    }
    builder.setLargeIcon(accountAvatar);
    // Reply to mention action; RemoteInput is available from KitKat Watch, but buttons are available from Nougat
    if (body.getType() == Notification.Type.MENTION && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        RemoteInput replyRemoteInput = new RemoteInput.Builder(KEY_REPLY).setLabel(context.getString(R.string.label_quick_reply)).build();
        PendingIntent quickReplyPendingIntent = getStatusReplyIntent(REPLY_ACTION, context, body, account);
        NotificationCompat.Action quickReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_24dp, context.getString(R.string.action_quick_reply), quickReplyPendingIntent).addRemoteInput(replyRemoteInput).build();
        builder.addAction(quickReplyAction);
        PendingIntent composePendingIntent = getStatusReplyIntent(COMPOSE_ACTION, context, body, account);
        NotificationCompat.Action composeAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_24dp, context.getString(R.string.action_compose_shortcut), composePendingIntent).build();
        builder.addAction(composeAction);
    }
    builder.setSubText(account.getFullName());
    builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    builder.setOnlyAlertOnce(true);
    // only alert for the first notification of a batch to avoid multiple alerts at once
    if (!isFirstOfBatch) {
        builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
    }
    // Summary
    // =======
    final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);
    if (currentNotifications.length() != 1) {
        try {
            String title = context.getResources().getQuantityString(R.plurals.notification_title_summary, currentNotifications.length(), currentNotifications.length());
            String text = joinNames(context, currentNotifications);
            summaryBuilder.setContentTitle(title).setContentText(text);
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }
    summaryBuilder.setSubText(account.getFullName());
    summaryBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    summaryBuilder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    summaryBuilder.setOnlyAlertOnce(true);
    summaryBuilder.setGroupSummary(true);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(notificationId, builder.build());
    if (currentNotifications.length() == 1) {
        notificationManager.notify((int) account.getId(), builder.setGroupSummary(true).build());
    } else {
        notificationManager.notify((int) account.getId(), summaryBuilder.build());
    }
}
Also used : RemoteInput(androidx.core.app.RemoteInput) TaskStackBuilder(androidx.core.app.TaskStackBuilder) JSONArray(org.json.JSONArray) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) JSONException(org.json.JSONException) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) Bitmap(android.graphics.Bitmap) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with RoundedCorners

use of com.bumptech.glide.load.resource.bitmap.RoundedCorners in project banner by youth5201314.

the class MainActivity method click.

@OnClick({ R.id.style_image, R.id.style_image_title, R.id.style_image_title_num, R.id.style_multiple, R.id.style_net_image, R.id.change_indicator, R.id.rv_banner, R.id.cl_banner, R.id.vp_banner, R.id.banner_video, R.id.banner_tv, R.id.gallery, R.id.topLine })
public void click(View view) {
    indicator.setVisibility(View.GONE);
    switch(view.getId()) {
        case R.id.style_image:
            refresh.setEnabled(true);
            banner.setAdapter(new ImageAdapter(DataBean.getTestData()));
            banner.setIndicator(new CircleIndicator(this));
            banner.setIndicatorGravity(IndicatorConfig.Direction.CENTER);
            break;
        case R.id.style_image_title:
            refresh.setEnabled(true);
            banner.setAdapter(new ImageTitleAdapter(DataBean.getTestData()));
            banner.setIndicator(new CircleIndicator(this));
            banner.setIndicatorGravity(IndicatorConfig.Direction.RIGHT);
            banner.setIndicatorMargins(new IndicatorConfig.Margins(0, 0, BannerConfig.INDICATOR_MARGIN, BannerUtils.dp2px(12)));
            break;
        case R.id.style_image_title_num:
            refresh.setEnabled(true);
            // 这里是将数字指示器和title都放在adapter中的,如果不想这样你也可以直接设置自定义的数字指示器
            banner.setAdapter(new ImageTitleNumAdapter(DataBean.getTestData()));
            banner.removeIndicator();
            break;
        case R.id.style_multiple:
            refresh.setEnabled(true);
            banner.setIndicator(new CircleIndicator(this));
            banner.setAdapter(new MultipleTypesAdapter(this, DataBean.getTestData()));
            break;
        case R.id.style_net_image:
            refresh.setEnabled(false);
            // 方法一:使用自定义图片适配器
            // banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
            // 方法二:使用自带的图片适配器
            banner.setAdapter(new BannerImageAdapter<DataBean>(DataBean.getTestData3()) {

                @Override
                public void onBindView(BannerImageHolder holder, DataBean data, int position, int size) {
                    // 图片加载自己实现
                    Glide.with(holder.itemView).load(data.imageUrl).thumbnail(Glide.with(holder.itemView).load(R.drawable.loading)).apply(RequestOptions.bitmapTransform(new RoundedCorners(30))).into(holder.imageView);
                }
            });
            banner.setIndicator(new RoundLinesIndicator(this));
            banner.setIndicatorSelectedWidth(BannerUtils.dp2px(15));
            break;
        case R.id.change_indicator:
            indicator.setVisibility(View.VISIBLE);
            // 在布局文件中使用指示器,这样更灵活
            banner.setIndicator(indicator, false);
            banner.setIndicatorSelectedWidth(BannerUtils.dp2px(15));
            break;
        case R.id.gallery:
            startActivity(new Intent(this, GalleryActivity.class));
            break;
        case R.id.rv_banner:
            startActivity(new Intent(this, RecyclerViewBannerActivity.class));
            break;
        case R.id.cl_banner:
            startActivity(new Intent(this, ConstraintLayoutBannerActivity.class));
            break;
        case R.id.vp_banner:
            startActivity(new Intent(this, Vp2FragmentRecyclerviewActivity.class));
            break;
        case R.id.banner_video:
            startActivity(new Intent(this, VideoActivity.class));
            break;
        case R.id.banner_tv:
            startActivity(new Intent(this, TVActivity.class));
            break;
        case R.id.topLine:
            startActivity(new Intent(this, TouTiaoActivity.class));
            break;
    }
}
Also used : RoundLinesIndicator(com.youth.banner.indicator.RoundLinesIndicator) Vp2FragmentRecyclerviewActivity(com.test.banner.ui.Vp2FragmentRecyclerviewActivity) ImageTitleAdapter(com.test.banner.adapter.ImageTitleAdapter) TouTiaoActivity(com.test.banner.ui.TouTiaoActivity) VideoActivity(com.test.banner.ui.VideoActivity) Intent(android.content.Intent) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) GalleryActivity(com.test.banner.ui.GalleryActivity) IndicatorConfig(com.youth.banner.config.IndicatorConfig) ImageTitleNumAdapter(com.test.banner.adapter.ImageTitleNumAdapter) BannerImageHolder(com.youth.banner.holder.BannerImageHolder) TVActivity(com.test.banner.ui.TVActivity) DataBean(com.test.banner.bean.DataBean) RecyclerViewBannerActivity(com.test.banner.ui.RecyclerViewBannerActivity) MultipleTypesAdapter(com.test.banner.adapter.MultipleTypesAdapter) BannerImageAdapter(com.youth.banner.adapter.BannerImageAdapter) ImageAdapter(com.test.banner.adapter.ImageAdapter) ConstraintLayoutBannerActivity(com.test.banner.ui.ConstraintLayoutBannerActivity) CircleIndicator(com.youth.banner.indicator.CircleIndicator) OnClick(butterknife.OnClick)

Aggregations

RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)15 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RequestOptions (com.bumptech.glide.request.RequestOptions)5 Bitmap (android.graphics.Bitmap)3 Drawable (android.graphics.drawable.Drawable)3 Test (org.junit.Test)3 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)2 DecryptableUri (org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri)2 GlideRequest (org.thoughtcrime.securesms.mms.GlideRequest)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 NotificationCompat (androidx.core.app.NotificationCompat)1 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)1 RemoteInput (androidx.core.app.RemoteInput)1