/*
- * <p>MuPdf Fragment<br/>
- * Copyright (C) 2016 Adullact-Projet.</p>
+ * <p>AMIES Android<br/>
+ * Copyright (C) 2016 Adullact.</p>
*
* <p>This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
*/
package org.adullact.amies.utils;
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.app.ActivityManager;
-import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.PointF;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.util.TypedValue;
-import android.view.View;
import org.adullact.amies.R;
public static final String COLLECTIVITY_IMAGE_URL = "https://amies.adullact.org/nodejs/image/%s";
/**
- * Hardcoded android.R.integer.config_shortAnimTime
- * We had some NPE on weird tablets that doesn't have this value set.
- **/
- public static long CONFIG_SHORT_ANIM_TIME = 200L;
-
- /**
- * Swap smoothly between content and spinner, the Google way.
- * <br/>
- * Code source : http://developer.android.com/training/animation/crossfade.html
- *
- * @param contentView should be invisible on start
- * @param spinnerView will be set to Visibility.GONE at the end
- */
- public static void crossfade(@NonNull View contentView, @NonNull final View spinnerView) {
-
- // Cancelling previous animation (overlapping animations produce chaos, fire, and biblical cataclysms)
- contentView.animate().cancel();
- spinnerView.animate().cancel();
-
- // Set the content view to 0% opacity but visible, so that it is visible
- // (but fully transparent) during the animation.
- contentView.setAlpha(0f);
- contentView.setVisibility(View.VISIBLE);
-
- // Animate the content view to 100% opacity, and clear any animation
- // listener set on the view.
- contentView.animate().alpha(1f).setDuration(CONFIG_SHORT_ANIM_TIME).setListener(null);
-
- // Animate the loading view to 0% opacity. After the animation ends,
- // set its visibility to GONE as an optimization step (it won't
- // participate in layout passes, etc.)
- spinnerView.animate().alpha(0f).setDuration(CONFIG_SHORT_ANIM_TIME).setListener(new AnimatorListenerAdapter() {
- @Override public void onAnimationEnd(Animator animation) {
- spinnerView.setVisibility(View.GONE);
- spinnerView.setAlpha(1f);
- }
- });
- }
-
- /**
- * Hide and show a view, executing Runnable on hide.
- *
- * @param contentView should be invisible on start
- * @param inBetweenBlinkRunnable to execute on hide
- */
- public static void blink(@NonNull final View contentView, @NonNull final Runnable inBetweenBlinkRunnable) {
-
- // Cancelling previous animation (overlapping animations produce chaos, fire, and biblical cataclysms)
- contentView.animate().cancel();
-
- // Animate the content view to 0% opacity
- contentView.animate().alpha(0f).setDuration(CONFIG_SHORT_ANIM_TIME).setListener(new AnimatorListenerAdapter() {
-
- @Override public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
-
- inBetweenBlinkRunnable.run();
-
- // Animate the loading view to 100% opacity. After the animation ends.
- contentView.animate().alpha(1f).setDuration(CONFIG_SHORT_ANIM_TIME).setListener(null);
- }
- });
- }
-
- /**
- * Yep, Pythagore.
- *
- * @param point1 in pixels
- * @param point2 in pixels
- * @return a float, in pixels
- */
- public static float getDistanceBetween(PointF point1, PointF point2) {
- return (float) Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2));
- }
-
- public static float dipsToPixels(@NonNull Context context, int dips) {
- return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, context.getResources().getDisplayMetrics());
- }
-
- /**
- *
* @param activity the main one, should be in the onCreate
- * @param iconRes the icon
+ * @param iconRes the icon
*/
public static void overrideOverviewIcon(@NonNull Activity activity, @DrawableRes int iconRes) {
}
}
-// /**
-// * Animate a flip between two views, the Google way.
-// * <br/>
-// * Animators source : http://developer.android.com/training/animation/cardflip.html
-// * Animation code source : http://developer.android.com/guide/topics/graphics/prop-animation.html
-// *
-// * @param context needed to load some resources
-// * @param outView the card-front view
-// * @param inView the card-back view
-// * @param animationListener set on the inView animation
-// */
-// public static void flip(@NonNull Context context, @NonNull View outView, @NonNull View inView, @Nullable Animator.AnimatorListener animationListener) {
-//
-// outView.setAlpha(1f);
-// AnimatorSet outAnim = (AnimatorSet) AnimatorInflater.loadAnimator(context, R.animator.card_flip_left_out);
-// outAnim.setTarget(outView);
-// outAnim.start();
-//
-// inView.setAlpha(0f);
-// AnimatorSet inAnim = (AnimatorSet) AnimatorInflater.loadAnimator(context, R.animator.card_flip_right_in);
-// inAnim.setTarget(inView);
-// inAnim.start();
-//
-// if (animationListener != null)
-// inAnim.addListener(animationListener);
-// }
-
-// /**
-// * Popup menu doesn't show any icons (in Lollipop),
-// * but an hidden method can be called reflectively to force it.
-// * Maybe some day, in a future Android version, it woudn't be necessary.
-// *
-// * That's not very pretty, but it is in a try/catch, so... Why not.
-// */
-// public static void setForceShowIcon(@NonNull PopupMenu popupMenu) {
-// try {
-// Field[] fields = popupMenu.getClass().getDeclaredFields();
-// for (Field field : fields) {
-// if ("mPopup".equals(field.getName())) {
-// field.setAccessible(true);
-// Object menuPopupHelper = field.get(popupMenu);
-// Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
-// Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
-// setForceIcons.invoke(menuPopupHelper, true);
-// break;
-// }
-// }
-// }
-// catch (Throwable e) {
-// e.printStackTrace();
-// }
-// }
-
- /**
- * Hide and show a view, executing Runnable on hide.
- *
- * @param contentView should be invisible on start
- */
- public static void showAfterDelay(@NonNull final View contentView, long delay) {
-
- // Cancelling previous animation (overlapping animations produce chaos, fire, and biblical cataclysms)
- contentView.animate().cancel();
-
- contentView.setAlpha(0f);
- contentView.setVisibility(View.VISIBLE);
-
- // Animate the content view to 100% opacity
- contentView.animate().alpha(1f).setDuration(CONFIG_SHORT_ANIM_TIME).setStartDelay(delay).setListener(null);
- }
-
- /**
- * Hide and show a view, executing Runnable on hide.
- *
- * @param contentView should be invisible on start
- */
- public static void hideAfterDelay(@NonNull final View contentView, long delay) {
-
- // Cancelling previous animation (overlapping animations produce chaos, fire, and biblical cataclysms)
- contentView.animate().cancel();
-
- contentView.setAlpha(1f);
-
- // Animate the content view to 0% opacity
- contentView.animate().alpha(0f).setDuration(CONFIG_SHORT_ANIM_TIME).setStartDelay(delay).setListener(new AnimatorListenerAdapter() {
-
- @Override public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
- contentView.setVisibility(View.GONE);
- }
- });
- }
}
\ No newline at end of file