Search in sources :

Example 1 with AnimatedView

use of carbon.animation.AnimatedView in project Carbon by ZieIony.

the class Carbon method initAnimations.

public static void initAnimations(AnimatedView view, TypedArray a, int[] ids) {
    if (((View) view).isInEditMode())
        return;
    int carbon_inAnimation = ids[0];
    if (a.hasValue(carbon_inAnimation)) {
        TypedValue typedValue = new TypedValue();
        a.getValue(carbon_inAnimation, typedValue);
        if (typedValue.resourceId != 0) {
            view.setInAnimator(AnimatorInflater.loadAnimator(((View) view).getContext(), typedValue.resourceId));
        } else {
            view.setInAnimator(AnimUtils.Style.values()[typedValue.data].getInAnimator());
        }
    }
    int carbon_outAnimation = ids[1];
    if (a.hasValue(carbon_outAnimation)) {
        TypedValue typedValue = new TypedValue();
        a.getValue(carbon_outAnimation, typedValue);
        if (typedValue.resourceId != 0) {
            view.setOutAnimator(AnimatorInflater.loadAnimator(((View) view).getContext(), typedValue.resourceId));
        } else {
            view.setOutAnimator(AnimUtils.Style.values()[typedValue.data].getOutAnimator());
        }
    }
}
Also used : TintedView(carbon.view.TintedView) ShadowView(carbon.view.ShadowView) StrokeView(carbon.view.StrokeView) View(android.view.View) RippleView(carbon.drawable.ripple.RippleView) RevealView(carbon.view.RevealView) AutoSizeTextView(carbon.view.AutoSizeTextView) InsetView(carbon.view.InsetView) AnimatedView(carbon.animation.AnimatedView) ShapeModelView(carbon.view.ShapeModelView) MaxSizeView(carbon.view.MaxSizeView) TouchMarginView(carbon.view.TouchMarginView) TextAppearanceView(carbon.view.TextAppearanceView) StateAnimatorView(carbon.view.StateAnimatorView) TypedValue(android.util.TypedValue)

Example 2 with AnimatedView

use of carbon.animation.AnimatedView in project Carbon by ZieIony.

the class PowerMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    button = findViewById(R.id.button);
    powerMenu = findViewById(R.id.powerMenu);
    transition = findViewById(R.id.transition);
    screenPowerMenu = findViewById(R.id.screen_powerMenu);
    screenPowerOff = findViewById(R.id.screen_powerOff);
    screenReboot = findViewById(R.id.screen_reboot);
    screenAirplaneMode = findViewById(R.id.screen_airplaneMode);
    button.setOnClickListener(view -> {
        if (powerMenu.getVisibility() == View.VISIBLE)
            return;
        for (int i = 0; i < transition.getChildCount(); i++) transition.getChildAt(i).setVisibility(i == 0 ? View.VISIBLE : View.GONE);
        final List<View> viewsWithTag = screenPowerMenu.findViewsWithTag("animate");
        Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
        Animator animator = powerMenu.animateVisibility(View.VISIBLE);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                Stream.of(viewsWithTag).forEach(v -> {
                    v.getHandler().postDelayed(() -> {
                        if (v instanceof AnimatedView) {
                            ((AnimatedView) v).animateVisibility(View.VISIBLE);
                        } else {
                            v.setVisibility(View.VISIBLE);
                        }
                    }, viewsWithTag.indexOf(v) * 40);
                });
            }
        });
    });
    findViewById(R.id.powerOff).setOnClickListener(view -> {
        final List<View> viewsWithTag = screenPowerOff.findViewsWithTag("animate");
        Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
        screenPowerOff.setVisibility(View.VISIBLE);
        Animator circularReveal = screenPowerOff.createCircularReveal(view.findViewById(R.id.powerOffIcon), 0, RevealView.MAX_RADIUS);
        circularReveal.setDuration(400);
        circularReveal.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                Stream.of(viewsWithTag).forEach(v -> {
                    view.getHandler().postDelayed(() -> {
                        if (v instanceof AnimatedView) {
                            ((AnimatedView) v).animateVisibility(View.VISIBLE);
                        } else {
                            v.setVisibility(View.VISIBLE);
                        }
                    }, viewsWithTag.indexOf(v) * 20);
                });
            }
        });
        circularReveal.start();
        view.getHandler().postDelayed(() -> powerMenu.animateVisibility(View.INVISIBLE), 3000);
    });
    findViewById(R.id.reboot).setOnClickListener(view -> {
        final List<View> viewsWithTag = screenReboot.findViewsWithTag("animate");
        Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
        screenReboot.setVisibility(View.VISIBLE);
        Animator circularReveal = screenReboot.createCircularReveal(view.findViewById(R.id.rebootIcon), 0, RevealView.MAX_RADIUS);
        circularReveal.setDuration(400);
        circularReveal.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                Stream.of(viewsWithTag).forEach(v -> {
                    view.getHandler().postDelayed(() -> {
                        if (v instanceof AnimatedView) {
                            ((AnimatedView) v).animateVisibility(View.VISIBLE);
                        } else {
                            v.setVisibility(View.VISIBLE);
                        }
                    }, viewsWithTag.indexOf(v) * 20);
                });
            }
        });
        circularReveal.start();
        view.getHandler().postDelayed(() -> powerMenu.animateVisibility(View.INVISIBLE), 3000);
    });
    findViewById(R.id.airplaneMode).setOnClickListener(view -> {
        final List<View> viewsWithTag = screenAirplaneMode.findViewsWithTag("animate");
        Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
        screenAirplaneMode.setVisibility(View.VISIBLE);
        Animator circularReveal = screenAirplaneMode.createCircularReveal(view.findViewById(R.id.airplaneModeIcon), 0, RevealView.MAX_RADIUS);
        circularReveal.setDuration(400);
        circularReveal.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                Stream.of(viewsWithTag).forEach(v -> {
                    view.getHandler().postDelayed(() -> {
                        if (v instanceof AnimatedView) {
                            ((AnimatedView) v).animateVisibility(View.VISIBLE);
                        } else {
                            v.setVisibility(View.VISIBLE);
                        }
                    }, viewsWithTag.indexOf(v) * 20);
                });
            }
        });
        circularReveal.start();
        view.getHandler().postDelayed(() -> {
            Animator circularReveal2 = screenAirplaneMode.createCircularReveal(view.findViewById(R.id.airplaneModeIcon), RevealView.MAX_RADIUS, 0);
            circularReveal2.setDuration(400);
            circularReveal2.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    screenAirplaneMode.setVisibility(View.INVISIBLE);
                }
            });
            circularReveal2.start();
            airplaneMode = !airplaneMode;
            TextView amStatus = findViewById(R.id.airplaneModeStatus);
            amStatus.setText("Airplane PopupMode is " + (airplaneMode ? "on" : "off"));
            ImageView airplaneModeIcon = view.findViewById(R.id.airplaneModeIcon);
            airplaneModeIcon.setImageResource(airplaneMode ? R.raw.ic_airplanemode_on_24px : R.raw.ic_airplanemode_off_24px);
        }, 3000);
    });
    findViewById(R.id.vibration).setOnClickListener(view -> {
        if (vibration) {
            vibration = false;
            view.setBackgroundColor(Carbon.getThemeColor(PowerMenuActivity.this, android.R.attr.colorBackground));
            ((ImageView) view).setTint(Carbon.getThemeColor(PowerMenuActivity.this, R.attr.carbon_iconColor));
        } else {
            vibration = true;
            view.setBackgroundColor(getResources().getColor(R.color.carbon_black_54o));
            ((ImageView) view).setTint(Carbon.getThemeColor(PowerMenuActivity.this, R.attr.carbon_iconColorInverse));
            Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(500);
        }
        powerMenu.postInvalidate();
    });
    findViewById(R.id.volume).setOnClickListener(view -> {
        if (volume) {
            volume = false;
            view.setBackgroundColor(Carbon.getThemeColor(PowerMenuActivity.this, android.R.attr.colorBackground));
            ((ImageView) view).setTint(Carbon.getThemeColor(PowerMenuActivity.this, R.attr.carbon_iconColor));
        } else {
            volume = true;
            view.setBackgroundColor(getResources().getColor(R.color.carbon_black_54o));
            ((ImageView) view).setTint(Carbon.getThemeColor(PowerMenuActivity.this, R.attr.carbon_iconColorInverse));
            view.playSoundEffect(SoundEffectConstants.CLICK);
        }
        powerMenu.postInvalidate();
    });
}
Also used : Context(android.content.Context) ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Bundle(android.os.Bundle) Button(carbon.widget.Button) Stream(com.annimon.stream.Stream) AnimatedView(carbon.animation.AnimatedView) LinearLayout(carbon.widget.LinearLayout) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) RevealView(carbon.view.RevealView) SoundEffectConstants(android.view.SoundEffectConstants) List(java.util.List) Carbon(carbon.Carbon) R(tk.zielony.carbonsamples.R) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) Vibrator(android.os.Vibrator) FrameLayout(carbon.widget.FrameLayout) AnimatedView(carbon.animation.AnimatedView) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(carbon.widget.TextView) ImageView(carbon.widget.ImageView) Vibrator(android.os.Vibrator) AnimatedView(carbon.animation.AnimatedView) RevealView(carbon.view.RevealView) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView)

Aggregations

View (android.view.View)2 AnimatedView (carbon.animation.AnimatedView)2 RevealView (carbon.view.RevealView)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 Vibrator (android.os.Vibrator)1 TypedValue (android.util.TypedValue)1 SoundEffectConstants (android.view.SoundEffectConstants)1 Carbon (carbon.Carbon)1 RippleView (carbon.drawable.ripple.RippleView)1 AutoSizeTextView (carbon.view.AutoSizeTextView)1 InsetView (carbon.view.InsetView)1 MaxSizeView (carbon.view.MaxSizeView)1 ShadowView (carbon.view.ShadowView)1 ShapeModelView (carbon.view.ShapeModelView)1 StateAnimatorView (carbon.view.StateAnimatorView)1 StrokeView (carbon.view.StrokeView)1 TextAppearanceView (carbon.view.TextAppearanceView)1