use of android.graphics.drawable.InsetDrawable in project Signal-Android by WhisperSystems.
the class AddGroupDetailsFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
create = view.findViewById(R.id.create);
name = view.findViewById(R.id.name);
toolbar = view.findViewById(R.id.toolbar);
disappearingMessagesRow = view.findViewById(R.id.group_disappearing_messages_row);
setCreateEnabled(false, false);
GroupMemberListView members = view.findViewById(R.id.member_list);
ImageView avatar = view.findViewById(R.id.group_avatar);
View mmsWarning = view.findViewById(R.id.mms_warning);
LearnMoreTextView gv2Warning = view.findViewById(R.id.gv2_warning);
View addLater = view.findViewById(R.id.add_later);
TextView disappearingMessageValue = view.findViewById(R.id.group_disappearing_messages_value);
members.initializeAdapter(getViewLifecycleOwner());
avatarPlaceholder = VectorDrawableCompat.create(getResources(), R.drawable.ic_camera_outline_32_ultramarine, requireActivity().getTheme());
if (savedInstanceState == null) {
avatar.setImageDrawable(new InsetDrawable(avatarPlaceholder, ViewUtil.dpToPx(AVATAR_PLACEHOLDER_INSET_DP)));
}
initializeViewModel();
avatar.setOnClickListener(v -> showAvatarPicker());
members.setRecipientClickListener(this::handleRecipientClick);
EditTextUtil.addGraphemeClusterLimitFilter(name, FeatureFlags.getMaxGroupNameGraphemeLength());
name.addTextChangedListener(new AfterTextChanged(editable -> viewModel.setName(editable.toString())));
toolbar.setNavigationOnClickListener(unused -> callback.onNavigationButtonPressed());
create.setOnClickListener(v -> handleCreateClicked());
viewModel.getMembers().observe(getViewLifecycleOwner(), list -> {
addLater.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
members.setMembers(list);
});
viewModel.getCanSubmitForm().observe(getViewLifecycleOwner(), isFormValid -> setCreateEnabled(isFormValid, true));
viewModel.getIsMms().observe(getViewLifecycleOwner(), isMms -> {
disappearingMessagesRow.setVisibility(isMms ? View.GONE : View.VISIBLE);
mmsWarning.setVisibility(isMms ? View.VISIBLE : View.GONE);
name.setHint(isMms ? R.string.AddGroupDetailsFragment__group_name_optional : R.string.AddGroupDetailsFragment__group_name_required);
toolbar.setTitle(isMms ? R.string.AddGroupDetailsFragment__create_group : R.string.AddGroupDetailsFragment__name_this_group);
});
viewModel.getNonGv2CapableMembers().observe(getViewLifecycleOwner(), nonGv2CapableMembers -> {
gv2Warning.setVisibility(nonGv2CapableMembers.isEmpty() ? View.GONE : View.VISIBLE);
gv2Warning.setText(requireContext().getResources().getQuantityString(R.plurals.AddGroupDetailsFragment__d_members_do_not_support_new_groups_so_this_group_cannot_be_created, nonGv2CapableMembers.size(), nonGv2CapableMembers.size()));
gv2Warning.setLearnMoreVisible(true);
gv2Warning.setOnLinkClickListener(v -> NonGv2MemberDialog.showNonGv2Members(requireContext(), getViewLifecycleOwner(), nonGv2CapableMembers));
});
viewModel.getAvatar().observe(getViewLifecycleOwner(), avatarBytes -> {
if (avatarBytes == null) {
avatar.setImageDrawable(new InsetDrawable(avatarPlaceholder, ViewUtil.dpToPx(AVATAR_PLACEHOLDER_INSET_DP)));
} else {
GlideApp.with(this).load(avatarBytes).circleCrop().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(avatar);
}
});
viewModel.getDisappearingMessagesTimer().observe(getViewLifecycleOwner(), timer -> disappearingMessageValue.setText(ExpirationUtil.getExpirationDisplayValue(requireContext(), timer)));
disappearingMessagesRow.setOnClickListener(v -> {
startActivityForResult(RecipientDisappearingMessagesActivity.forCreateGroup(requireContext(), viewModel.getDisappearingMessagesTimer().getValue()), REQUEST_DISAPPEARING_TIMER);
});
name.requestFocus();
getParentFragmentManager().setFragmentResultListener(AvatarPickerFragment.REQUEST_KEY_SELECT_AVATAR, getViewLifecycleOwner(), (key, bundle) -> handleMediaResult(bundle));
}
use of android.graphics.drawable.InsetDrawable in project RespawnIRC-Android by FranckRJ.
the class ImageDownloader method buildInsetDrawableForAspectRatio.
public Drawable buildInsetDrawableForAspectRatio(Drawable drawableToChange, boolean isSetToDefaultSize) {
int drawableWidth = drawableToChange.getIntrinsicWidth();
int drawableHeight = drawableToChange.getIntrinsicHeight();
if ((drawableHeight / (double) drawableWidth) < ((imagesHeight / (double) imagesWidth) - 0.005)) {
int verticalMargin = Utils.roundToInt(drawableWidth * (imagesHeight / (double) imagesWidth)) - drawableHeight;
if (isSetToDefaultSize) {
verticalMargin *= (imagesHeight / (double) (verticalMargin + drawableHeight));
}
return (new InsetDrawable(drawableToChange, 0, verticalMargin / 2, 0, verticalMargin / 2));
} else if ((drawableHeight / (double) drawableWidth) > ((imagesHeight / (double) imagesWidth) + 0.005)) {
int horizontalMargin = Utils.roundToInt(drawableHeight / (imagesHeight / (double) imagesWidth)) - drawableWidth;
if (isSetToDefaultSize) {
horizontalMargin *= (imagesWidth / (double) (horizontalMargin + drawableWidth));
}
return (new InsetDrawable(drawableToChange, horizontalMargin / 2, 0, horizontalMargin / 2, 0));
} else {
return drawableToChange;
}
}
use of android.graphics.drawable.InsetDrawable in project PocketHub by pockethub.
the class AvatarLoader method bind.
/**
* Sets the logo on the {@link ActionBar} to the user's avatar.
*
* @param actionBar An ActionBar object on which you're placing the user's avatar.
* @param userReference An AtomicReference that points to the desired user.
* @return this helper
*/
public void bind(final ActionBar actionBar, final AtomicReference<User> userReference) {
if (userReference == null) {
return;
}
final User user = userReference.get();
if (user == null) {
return;
}
String avatarUrl = user.avatarUrl();
if (TextUtils.isEmpty(avatarUrl)) {
return;
}
// Remove the URL params as they are not needed and break cache
if (avatarUrl.contains("?") && !avatarUrl.contains("gravatar")) {
avatarUrl = avatarUrl.substring(0, avatarUrl.indexOf("?"));
}
final String url = avatarUrl;
new FetchAvatarTask(context) {
@Override
public BitmapDrawable call() throws Exception {
Bitmap image = Bitmap.createScaledBitmap(p.load(url).get(), avatarSize, avatarSize, false);
return new BitmapDrawable(context.getResources(), ImageUtils.roundCorners(image, cornerRadius));
}
@Override
protected void onSuccess(BitmapDrawable image) throws Exception {
// compute inset in pixels
int insetPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, context.getResources().getDisplayMetrics());
actionBar.setLogo(new InsetDrawable(image, 0, 0, insetPx, 0));
}
}.execute();
}
use of android.graphics.drawable.InsetDrawable in project wire-android by wireapp.
the class AddPhoneNumberPreferenceDialogFragment method clearColorFilter.
// from TextInputLayout
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearColorFilter(@NonNull Drawable drawable) {
drawable.clearColorFilter();
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
// children manually
if (drawable instanceof InsetDrawable) {
clearColorFilter(((InsetDrawable) drawable).getDrawable());
} else if (drawable instanceof DrawableWrapper) {
clearColorFilter(((DrawableWrapper) drawable).getWrappedDrawable());
} else if (drawable instanceof DrawableContainer) {
final DrawableContainer container = (DrawableContainer) drawable;
final DrawableContainer.DrawableContainerState state = (DrawableContainer.DrawableContainerState) container.getConstantState();
if (state != null) {
for (int i = 0, count = state.getChildCount(); i < count; i++) {
clearColorFilter(state.getChild(i));
}
}
}
}
}
use of android.graphics.drawable.InsetDrawable in project android_packages_apps_Settings by LineageOS.
the class MusicViewHolderController method setupView.
@Override
public void setupView(AppViewHolder holder) {
holder.appIcon.setImageDrawable(new InsetDrawable(mContext.getDrawable(R.drawable.ic_headset_24dp), INSET_SIZE));
holder.appName.setText(mContext.getText(R.string.audio_files_title));
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
Aggregations