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());
}
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);
}
}
Aggregations