Search in sources :

Example 1 with CircleTransform

use of org.fossasia.openevent.common.ui.image.CircleTransform in project open-event-android by fossasia.

the class SpeakerViewHolder method bindSpeaker.

public void bindSpeaker(Speaker speaker) {
    this.speaker = speaker;
    String thumbnail = Utils.parseImageUri(this.speaker.getThumbnailImageUrl());
    String name = Utils.checkStringEmpty(speaker.getName());
    if (thumbnail == null)
        thumbnail = Utils.parseImageUri(this.speaker.getPhotoUrl());
    final Palette.PaletteAsyncListener paletteAsyncListener = palette -> {
        Palette.Swatch swatch = palette.getVibrantSwatch();
        if (speakerTextualInfo != null) {
            if (swatch != null) {
                // bitmap has vibrant swatch profile
                speakerTextualInfo.setBackgroundColor(swatch.getRgb());
            } else {
                Palette.Swatch swatch2 = palette.getDarkMutedSwatch();
                if (swatch2 != null) {
                    // bitmap has dark muted swatch profile
                    speakerTextualInfo.setBackgroundColor(swatch2.getRgb());
                } else {
                    speakerTextualInfo.setBackgroundColor(ContextCompat.getColor(context, R.color.color_primary_dark));
                }
            }
        }
    };
    RequestCreator requestCreator = StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(thumbnail);
    TextDrawable drawable;
    if (isImageCircle) {
        requestCreator.transform(new CircleTransform());
        drawable = Views.getTextDrawableBuilder().round().build(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
    } else {
        drawable = Views.getTextDrawableBuilder().buildRect(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
    }
    final Target target = new Target() {

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            speakerImage.setImageBitmap(bitmap);
            if (speakerTextualInfo != null) {
                Palette.from(bitmap).generate(paletteAsyncListener);
            }
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            speakerImage.setImageDrawable(drawable);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            speakerImage.setImageDrawable(drawable);
        }
    };
    requestCreator.into(target);
    setStringField(speakerName, name);
    setStringField(speakerDesignation, String.format("%s %s", speaker.getPosition(), speaker.getOrganisation()));
    setStringField(speakerCountry, speaker.getCountry());
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) Utils(org.fossasia.openevent.common.utils.Utils) ImageView(android.widget.ImageView) Intent(android.content.Intent) Drawable(android.graphics.drawable.Drawable) BindView(butterknife.BindView) Picasso(com.squareup.picasso.Picasso) ActivityOptions(android.app.ActivityOptions) Views(org.fossasia.openevent.common.ui.Views) Target(com.squareup.picasso.Target) View(android.view.View) CircleTransform(org.fossasia.openevent.common.ui.image.CircleTransform) Speaker(org.fossasia.openevent.data.Speaker) R(org.fossasia.openevent.R) StrategyRegistry(org.fossasia.openevent.config.StrategyRegistry) RequestCreator(com.squareup.picasso.RequestCreator) ContextCompat(android.support.v4.content.ContextCompat) TextUtils(android.text.TextUtils) ColorGenerator(com.amulyakhare.textdrawable.util.ColorGenerator) Timber(timber.log.Timber) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Bitmap(android.graphics.Bitmap) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Palette(android.support.v7.graphics.Palette) Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Drawable(android.graphics.drawable.Drawable) CircleTransform(org.fossasia.openevent.common.ui.image.CircleTransform) RequestCreator(com.squareup.picasso.RequestCreator)

Example 2 with CircleTransform

use of org.fossasia.openevent.common.ui.image.CircleTransform in project open-event-android by fossasia.

the class EditProfileActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri imageUri = data.getData();
        Timber.d(imageUri.toString());
        UCrop.of(imageUri, Uri.fromFile(new File(getCacheDir(), imageUri.getUserInfo() + ".png"))).start(this);
    }
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        final Uri resultUri = UCrop.getOutput(data);
        InputStream imageStream = null;
        try {
            imageStream = getContentResolver().openInputStream(resultUri);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
        encodedImage = encodeImage(selectedImage);
        StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(resultUri).transform(new CircleTransform()).into(avatar);
    } else if (resultCode == UCrop.RESULT_ERROR) {
        final Throwable cropError = UCrop.getError(data);
        Timber.d("EditProfileActivity", "UCrop Error" + cropError);
    }
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) CircleTransform(org.fossasia.openevent.common.ui.image.CircleTransform) Uri(android.net.Uri) File(java.io.File)

Aggregations

Bitmap (android.graphics.Bitmap)2 CircleTransform (org.fossasia.openevent.common.ui.image.CircleTransform)2 Activity (android.app.Activity)1 ActivityOptions (android.app.ActivityOptions)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 ContextCompat (android.support.v4.content.ContextCompat)1 Palette (android.support.v7.graphics.Palette)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TextUtils (android.text.TextUtils)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1