use of android.databinding.BindingAdapter in project xDrip by NightscoutFoundation.
the class BindingAdapterUtils method setVisibility.
@BindingAdapter(value = { "animatedVisibility" })
public static synchronized void setVisibility(@NonNull final View view, final int visibility) {
// Were we animating before? If so, what was the visibility?
Integer endAnimVisibility = (Integer) view.getTag(FINAL_VISIBILITY_ID);
int oldVisibility = endAnimVisibility == null ? view.getVisibility() : endAnimVisibility;
if (oldVisibility == visibility) {
// just let it finish any current animation.
return;
}
boolean isVisibile = oldVisibility == View.VISIBLE;
boolean willBeVisible = visibility == View.VISIBLE;
float startAlpha = isVisibile ? 1f : 0f;
if (endAnimVisibility != null) {
startAlpha = view.getAlpha();
}
float endAlpha = willBeVisible ? 1f : 0f;
view.setAlpha(startAlpha);
view.setVisibility(View.VISIBLE);
// Create the animator
final ObjectAnimator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, startAlpha, endAlpha);
final long duration = 600;
final long stagger = 150;
alpha.setDuration(duration);
// Stagger animations keyed at the same moment
long now = JoH.tsl();
if (now <= endTime) {
alpha.setStartDelay(JoH.msTill(endTime));
endTime += stagger;
} else {
endTime = now + stagger;
}
alpha.setAutoCancel(true);
alpha.addListener(new AnimatorListenerAdapter() {
private boolean isCanceled;
@Override
public void onAnimationStart(Animator anim) {
view.setTag(FINAL_VISIBILITY_ID, visibility);
}
@Override
public void onAnimationCancel(Animator anim) {
isCanceled = true;
}
@Override
public void onAnimationEnd(Animator anim) {
view.setTag(FINAL_VISIBILITY_ID, null);
if (!isCanceled) {
view.setAlpha(1f);
view.setVisibility(visibility);
}
}
});
alpha.start();
}
use of android.databinding.BindingAdapter in project xDrip-plus by jamorham.
the class BindingAdapterUtils method setVisibility.
@BindingAdapter(value = { "animatedVisibility" })
public static synchronized void setVisibility(@NonNull final View view, final int visibility) {
// Were we animating before? If so, what was the visibility?
Integer endAnimVisibility = (Integer) view.getTag(FINAL_VISIBILITY_ID);
int oldVisibility = endAnimVisibility == null ? view.getVisibility() : endAnimVisibility;
if (oldVisibility == visibility) {
// just let it finish any current animation.
return;
}
boolean isVisibile = oldVisibility == View.VISIBLE;
boolean willBeVisible = visibility == View.VISIBLE;
float startAlpha = isVisibile ? 1f : 0f;
if (endAnimVisibility != null) {
startAlpha = view.getAlpha();
}
float endAlpha = willBeVisible ? 1f : 0f;
view.setAlpha(startAlpha);
view.setVisibility(View.VISIBLE);
// Create the animator
final ObjectAnimator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, startAlpha, endAlpha);
final long duration = 600;
final long stagger = 150;
alpha.setDuration(duration);
// Stagger animations keyed at the same moment
long now = JoH.tsl();
if (now <= endTime) {
alpha.setStartDelay(JoH.msTill(endTime));
endTime += stagger;
} else {
endTime = now + stagger;
}
alpha.setAutoCancel(true);
alpha.addListener(new AnimatorListenerAdapter() {
private boolean isCanceled;
@Override
public void onAnimationStart(Animator anim) {
view.setTag(FINAL_VISIBILITY_ID, visibility);
}
@Override
public void onAnimationCancel(Animator anim) {
isCanceled = true;
}
@Override
public void onAnimationEnd(Animator anim) {
view.setTag(FINAL_VISIBILITY_ID, null);
if (!isCanceled) {
view.setAlpha(1f);
view.setVisibility(visibility);
}
}
});
alpha.start();
}
use of android.databinding.BindingAdapter in project open-event-orga-app by fossasia.
the class BindingAdapters method bindCircularProgressColor.
@BindingAdapter("circular_progress_color")
public static void bindCircularProgressColor(CircularProgressBar circularProgressBar, String colorName) {
Context context = circularProgressBar.getContext();
Resources resources = circularProgressBar.getResources();
int color = ContextCompat.getColor(context, resources.getIdentifier(colorName + "_500", "color", context.getPackageName()));
int bgColor = ContextCompat.getColor(context, resources.getIdentifier(colorName + "_100", "color", context.getPackageName()));
circularProgressBar.setColor(color);
circularProgressBar.setBackgroundColor(bgColor);
}
use of android.databinding.BindingAdapter in project open-event-orga-app by fossasia.
the class DateBindings method bindDate.
@BindingAdapter("date")
public static void bindDate(Button button, ObservableField<String> date) {
String format = DateUtils.FORMAT_DATE_COMPLETE;
bindTemporal(button, date, format, zonedDateTime -> new DatePickerDialog(button.getContext(), (picker, year, month, dayOfMonth) -> setPickedDate(LocalDateTime.of(LocalDate.of(year, month + 1, dayOfMonth), zonedDateTime.toLocalTime()), button, format, date), zonedDateTime.getYear(), zonedDateTime.getMonthValue() - 1, zonedDateTime.getDayOfMonth()));
}
use of android.databinding.BindingAdapter in project vlc-android by GeoffreyMetais.
the class AsyncImageLoader method loadPicture.
@BindingAdapter({ "media" })
public static void loadPicture(View v, MediaLibraryItem item) {
if (item == null || item.getItemType() == MediaLibraryItem.TYPE_GENRE || item.getItemType() == MediaLibraryItem.TYPE_PLAYLIST)
return;
final boolean isMedia = item.getItemType() == MediaLibraryItem.TYPE_MEDIA;
final boolean isGroup = isMedia && ((MediaWrapper) item).getType() == MediaWrapper.TYPE_GROUP;
final String cacheKey = isGroup ? "group:" + item.getTitle() : ThumbnailsProvider.getMediaCacheKey(isMedia, item);
final Bitmap bitmap = cacheKey != null ? sBitmapCache.getBitmapFromMemCache(cacheKey) : null;
if (bitmap != null) {
updateTargetImage(bitmap, v, DataBindingUtil.findBinding(v));
return;
}
if (isMedia && !isGroup && item.getId() == 0L) {
MediaWrapper mw = (MediaWrapper) item;
final int type = mw.getType();
final boolean isMediaFile = type == MediaWrapper.TYPE_AUDIO || type == MediaWrapper.TYPE_VIDEO;
final Uri uri = mw.getUri();
if (!isMediaFile && !(type == MediaWrapper.TYPE_DIR && "upnp".equals(uri.getScheme())))
return;
if (isMediaFile && "file".equals(uri.getScheme())) {
mw = sMedialibrary.getMedia(uri);
if (mw != null)
item = mw;
}
}
loadImage(MLItemCoverFetcher.obtain().init(v, item), v);
}
Aggregations