Search in sources :

Example 1 with BindingAdapter

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();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BindingAdapter(android.databinding.BindingAdapter)

Example 2 with BindingAdapter

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();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BindingAdapter(android.databinding.BindingAdapter)

Example 3 with BindingAdapter

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);
}
Also used : Context(android.content.Context) Resources(android.content.res.Resources) BindingAdapter(android.databinding.BindingAdapter)

Example 4 with BindingAdapter

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()));
}
Also used : BindingAdapter(android.databinding.BindingAdapter) TimePickerDialog(android.app.TimePickerDialog) LocalTime(org.threeten.bp.LocalTime) LocalDate(org.threeten.bp.LocalDate) ZonedDateTime(org.threeten.bp.ZonedDateTime) Timber(timber.log.Timber) AlertDialog(android.app.AlertDialog) DatePickerDialog(android.app.DatePickerDialog) DateUtils(org.fossasia.openevent.app.utils.DateUtils) Function(org.fossasia.openevent.app.common.Function) LocalDateTime(org.threeten.bp.LocalDateTime) Button(android.widget.Button) DateTimeParseException(org.threeten.bp.format.DateTimeParseException) ObservableField(android.databinding.ObservableField) DatePickerDialog(android.app.DatePickerDialog) BindingAdapter(android.databinding.BindingAdapter)

Example 5 with BindingAdapter

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);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Bitmap(android.graphics.Bitmap) Uri(android.net.Uri) BindingAdapter(android.databinding.BindingAdapter)

Aggregations

BindingAdapter (android.databinding.BindingAdapter)15 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 AlertDialog (android.app.AlertDialog)2 DatePickerDialog (android.app.DatePickerDialog)2 TimePickerDialog (android.app.TimePickerDialog)2 Context (android.content.Context)2 ObservableField (android.databinding.ObservableField)2 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 Button (android.widget.Button)2 Function (org.fossasia.openevent.app.common.Function)2 DateUtils (org.fossasia.openevent.app.utils.DateUtils)2 LocalDate (org.threeten.bp.LocalDate)2 LocalDateTime (org.threeten.bp.LocalDateTime)2 LocalTime (org.threeten.bp.LocalTime)2 ZonedDateTime (org.threeten.bp.ZonedDateTime)2 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)2 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2