Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b505074e authored by Jim Miller's avatar Jim Miller
Browse files

Add new MultiWaveView widget and integrate it into LockScreen

This adds a new multi-target widget to the framework and integrates
it into LockScreen.

Now with updated assets.

Change-Id: Ib41595b9e80a7be6d647f44c803a77f9e5bfeca9
parent d408f4a8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -425,6 +425,7 @@ package android {
    field public static final int fastScrollTextColor = 16843609; // 0x1010359
    field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336
    field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339
    field public static final int feedbackCount = 16843665; // 0x1010391
    field public static final int fillAfter = 16843197; // 0x10101bd
    field public static final int fillBefore = 16843196; // 0x10101bc
    field public static final int fillEnabled = 16843343; // 0x101024f
@@ -478,6 +479,7 @@ package android {
    field public static final int hand_hour = 16843011; // 0x1010103
    field public static final int hand_minute = 16843012; // 0x1010104
    field public static final int handle = 16843354; // 0x101025a
    field public static final int handleDrawable = 16843657; // 0x1010389
    field public static final int handleProfiling = 16842786; // 0x1010022
    field public static final int hapticFeedbackEnabled = 16843358; // 0x101025e
    field public static final int hardwareAccelerated = 16843475; // 0x10102d3
@@ -486,10 +488,12 @@ package android {
    field public static final int headerDividersEnabled = 16843310; // 0x101022e
    field public static final int height = 16843093; // 0x1010155
    field public static final int hint = 16843088; // 0x1010150
    field public static final int hitRadius = 16843662; // 0x101038e
    field public static final int homeAsUpIndicator = 16843531; // 0x101030b
    field public static final int homeLayout = 16843549; // 0x101031d
    field public static final int horizontalDivider = 16843053; // 0x101012d
    field public static final int horizontalGap = 16843327; // 0x101023f
    field public static final int horizontalOffset = 16843667; // 0x1010393
    field public static final int horizontalScrollViewStyle = 16843603; // 0x1010353
    field public static final int horizontalSpacing = 16843028; // 0x1010114
    field public static final int host = 16842792; // 0x1010028
@@ -610,6 +614,7 @@ package android {
    field public static final int layout_x = 16843135; // 0x101017f
    field public static final int layout_y = 16843136; // 0x1010180
    field public static final int left = 16843181; // 0x10101ad
    field public static final int leftChevronDrawable = 16843658; // 0x101038a
    field public static final int lineSpacingExtra = 16843287; // 0x1010217
    field public static final int lineSpacingMultiplier = 16843288; // 0x1010218
    field public static final int lines = 16843092; // 0x1010154
@@ -681,6 +686,7 @@ package android {
    field public static final int orderingFromXml = 16843239; // 0x10101e7
    field public static final int orientation = 16842948; // 0x10100c4
    field public static final int outAnimation = 16843128; // 0x1010178
    field public static final int outerRadius = 16843661; // 0x101038d
    field public static final int overScrollFooter = 16843459; // 0x10102c3
    field public static final int overScrollHeader = 16843458; // 0x10102c2
    field public static final int overScrollMode = 16843457; // 0x10102c1
@@ -769,6 +775,7 @@ package android {
    field public static final int restoreAnyVersion = 16843450; // 0x10102ba
    field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
    field public static final int right = 16843183; // 0x10101af
    field public static final int rightChevronDrawable = 16843659; // 0x101038b
    field public static final int ringtonePreferenceStyle = 16842899; // 0x1010093
    field public static final int ringtoneType = 16843257; // 0x10101f9
    field public static final int rotation = 16843558; // 0x1010326
@@ -844,6 +851,7 @@ package android {
    field public static final int smallIcon = 16843422; // 0x101029e
    field public static final int smallScreens = 16843396; // 0x1010284
    field public static final int smoothScrollbar = 16843313; // 0x1010231
    field public static final int snapMargin = 16843664; // 0x1010390
    field public static final int soundEffectsEnabled = 16843285; // 0x1010215
    field public static final int spacing = 16843027; // 0x1010113
    field public static final int spinnerDropDownItemStyle = 16842887; // 0x1010087
@@ -908,6 +916,7 @@ package android {
    field public static final int tag = 16842961; // 0x10100d1
    field public static final int targetActivity = 16843266; // 0x1010202
    field public static final int targetClass = 16842799; // 0x101002f
    field public static final int targetDrawables = 16843656; // 0x1010388
    field public static final int targetPackage = 16842785; // 0x1010021
    field public static final int targetSdkVersion = 16843376; // 0x1010270
    field public static final int taskAffinity = 16842770; // 0x1010012
@@ -1026,8 +1035,10 @@ package android {
    field public static final int verticalCorrection = 16843322; // 0x101023a
    field public static final int verticalDivider = 16843054; // 0x101012e
    field public static final int verticalGap = 16843328; // 0x1010240
    field public static final int verticalOffset = 16843666; // 0x1010392
    field public static final int verticalScrollbarPosition = 16843572; // 0x1010334
    field public static final int verticalSpacing = 16843029; // 0x1010115
    field public static final int vibrationDuration = 16843663; // 0x101038f
    field public static final int visibility = 16842972; // 0x10100dc
    field public static final int visible = 16843156; // 0x1010194
    field public static final int vmSafeMode = 16843448; // 0x10102b8
@@ -1044,6 +1055,7 @@ package android {
    field public static final int wallpaperIntraOpenExitAnimation = 16843416; // 0x1010298
    field public static final int wallpaperOpenEnterAnimation = 16843411; // 0x1010293
    field public static final int wallpaperOpenExitAnimation = 16843412; // 0x1010294
    field public static final int waveDrawable = 16843660; // 0x101038c
    field public static final int webTextViewStyle = 16843449; // 0x10102b9
    field public static final int webViewStyle = 16842885; // 0x1010085
    field public static final int weekDayTextAppearance = 16843592; // 0x1010348
+132 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.widget.multiwaveview;

import android.animation.TimeInterpolator;

class Ease {
    private static final float DOMAIN = 1.0f;
    private static final float DURATION = 1.0f;
    private static final float START = 0.0f;

    static class Linear {
        public static final TimeInterpolator easeNone = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return input;
            }
        };
    }

    static class Cubic {
        public static final TimeInterpolator easeIn = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN*(input/=DURATION)*input*input + START;
            }
        };
        public static final TimeInterpolator easeOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN*((input=input/DURATION-1)*input*input + 1) + START;
            }
        };
        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return ((input/=DURATION/2) < 1.0f) ?
                        (DOMAIN/2*input*input*input + START)
                            : (DOMAIN/2*((input-=2)*input*input + 2) + START);
            }
        };
    }

    static class Quad {
        public static final TimeInterpolator easeIn = new TimeInterpolator() {
            public float getInterpolation (float input) {
                return DOMAIN*(input/=DURATION)*input + START;
            }
        };
        public static final TimeInterpolator easeOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return -DOMAIN *(input/=DURATION)*(input-2) + START;
            }
        };
        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return ((input/=DURATION/2) < 1) ?
                        (DOMAIN/2*input*input + START)
                            : (-DOMAIN/2 * ((--input)*(input-2) - 1) + START);
            }
        };
    }

    static class Quart {
        public static final TimeInterpolator easeIn = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN*(input/=DURATION)*input*input*input + START;
            }
        };
        public static final TimeInterpolator easeOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return -DOMAIN * ((input=input/DURATION-1)*input*input*input - 1) + START;
            }
        };
        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return ((input/=DURATION/2) < 1) ?
                        (DOMAIN/2*input*input*input*input + START)
                            : (-DOMAIN/2 * ((input-=2)*input*input*input - 2) + START);
            }
        };
    }

    static class Quint {
        public static final TimeInterpolator easeIn = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN*(input/=DURATION)*input*input*input*input + START;
            }
        };
        public static final TimeInterpolator easeOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN*((input=input/DURATION-1)*input*input*input*input + 1) + START;
            }
        };
        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return ((input/=DURATION/2) < 1) ?
                        (DOMAIN/2*input*input*input*input*input + START)
                            : (DOMAIN/2*((input-=2)*input*input*input*input + 2) + START);
            }
        };
    }

    static class Sine {
        public static final TimeInterpolator easeIn = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return -DOMAIN * (float) Math.cos(input/DURATION * (Math.PI/2)) + DOMAIN + START;
            }
        };
        public static final TimeInterpolator easeOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return DOMAIN * (float) Math.sin(input/DURATION * (Math.PI/2)) + START;
            }
        };
        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
            public float getInterpolation(float input) {
                return -DOMAIN/2 * ((float)Math.cos(Math.PI*input/DURATION) - 1.0f) + START;
            }
        };
    }

}
+645 −0

File added.

Preview size limit exceeded, changes collapsed.

+215 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.widget.multiwaveview;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.Log;

public class TargetDrawable {
    private static final String TAG = "TargetDrawable";
    public static final int[] STATE_ACTIVE =
            { android.R.attr.state_enabled, android.R.attr.state_active };
    public static final int[] STATE_INACTIVE =
            { android.R.attr.state_enabled, -android.R.attr.state_active };
    public static final int[] STATE_FOCUSED =
            { android.R.attr.state_enabled, android.R.attr.state_focused };

    private float mTranslationX = 0.0f;
    private float mTranslationY = 0.0f;
    private float mScaleX = 1.0f;
    private float mScaleY = 1.0f;
    private float mAlpha = 1.0f;
    private Drawable mDrawable;

    /* package */ static class DrawableWithAlpha extends Drawable {
        private float mAlpha = 1.0f;
        private Drawable mRealDrawable;
        public DrawableWithAlpha(Drawable realDrawable) {
            mRealDrawable = realDrawable;
        }
        public void setAlpha(float alpha) {
            mAlpha = alpha;
        }
        public float getAlpha() {
            return mAlpha;
        }
        public void draw(Canvas canvas) {
            mRealDrawable.setAlpha((int) Math.round(mAlpha * 255f));
            mRealDrawable.draw(canvas);
        }
        @Override
        public void setAlpha(int alpha) {
            mRealDrawable.setAlpha(alpha);
        }
        @Override
        public void setColorFilter(ColorFilter cf) {
            mRealDrawable.setColorFilter(cf);
        }
        @Override
        public int getOpacity() {
            return mRealDrawable.getOpacity();
        }
    }

    public TargetDrawable(Resources res, int resId) {
        this(res, resId == 0 ? null : res.getDrawable(resId));
    }

    public TargetDrawable(Resources res, Drawable drawable) {
        // Mutate the drawable so we can animate shared drawable properties.
        mDrawable = drawable != null ? drawable.mutate() : null;
        resizeDrawables();
        setState(STATE_INACTIVE);
    }

    public void setState(int [] state) {
        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            d.setState(state);
        }
    }

    public boolean hasState(int [] state) {
        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            // TODO: this doesn't seem to work
            return d.getStateDrawableIndex(state) != -1;
        }
        return false;
    }

    /**
     * Returns true if the drawable is a StateListDrawable and is in the focused state.
     *
     * @return
     */
    public boolean isActive() {
        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            int[] states = d.getState();
            for (int i = 0; i < states.length; i++) {
                if (states[i] == android.R.attr.state_focused) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Returns true if this target is enabled. Typically an enabled target contains a valid
     * drawable in a valid state. Currently all targets with valid drawables are valid.
     *
     * @return
     */
    public boolean isValid() {
        return mDrawable != null;
    }

    /**
     * Makes drawables in a StateListDrawable all the same dimensions.
     * If not a StateListDrawable, then justs sets the bounds to the intrinsic size of the
     * drawable.
     */
    private void resizeDrawables() {
        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            int maxWidth = 0;
            int maxHeight = 0;
            for (int i = 0; i < d.getStateCount(); i++) {
                Drawable childDrawable = d.getStateDrawable(i);
                maxWidth = Math.max(maxWidth, childDrawable.getIntrinsicWidth());
                maxHeight = Math.max(maxHeight, childDrawable.getIntrinsicHeight());
            }
            Log.v(TAG, "union of childDrawable rects " + d + " to: " + maxWidth + "x" + maxHeight);
            d.setBounds(0, 0, maxWidth, maxHeight);
            for (int i = 0; i < d.getStateCount(); i++) {
                Drawable childDrawable = d.getStateDrawable(i);
                Log.v(TAG, "sizing drawable " + childDrawable + " to: " + maxWidth + "x" + maxHeight);
                childDrawable.setBounds(0, 0, maxWidth, maxHeight);
            }
        } else if (mDrawable != null) {
            mDrawable.setBounds(0, 0,
                    mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
        }
    }

    public void setX(float x) {
        mTranslationX = x;
    }

    public void setY(float y) {
        mTranslationY = y;
    }

    public void setScaleX(float x) {
        mScaleX = x;
    }

    public void setScaleY(float y) {
        mScaleY = y;
    }

    public void setAlpha(float alpha) {
        mAlpha = alpha;
    }

    public float getX() {
        return mTranslationX;
    }

    public float getY() {
        return mTranslationY;
    }

    public float getScaleX() {
        return mScaleX;
    }

    public float getScaleY() {
        return mScaleY;
    }

    public float getAlpha() {
        return mAlpha;
    }

    public int getWidth() {
        return mDrawable != null ? mDrawable.getIntrinsicWidth() : 0;
    }

    public int getHeight() {
        return mDrawable != null ? mDrawable.getIntrinsicHeight() : 0;
    }

    public void draw(Canvas canvas) {
        if (mDrawable == null) {
            return;
        }
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mTranslationX, mTranslationY);
        canvas.scale(mScaleX, mScaleY);
        canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    }
}
+132 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.widget.multiwaveview;

import java.util.ArrayList;
import java.util.HashMap;

import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator.AnimatorUpdateListener;

class Tweener {
    private static final String TAG = "Tweener";

    private Object object;
    ObjectAnimator animator;
    private static HashMap<Object, Tweener> sTweens = new HashMap<Object, Tweener>();

    public Tweener(Object obj, ObjectAnimator anim) {
        object = obj;
        animator = anim;
    }

    public static Tweener to(Object object, long duration, Object... vars) {
        long delay = 0;
        AnimatorUpdateListener updateListener = null;
        AnimatorListener listener = null;
        TimeInterpolator interpolator = null;

        // Iterate through arguments and discover properties to animate
        ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length/2);
        for (int i = 0; i < vars.length; i+=2) {
            if (!(vars[i] instanceof String)) {
                throw new IllegalArgumentException("Key must be a string: " + vars[i]);
            }
            String key = (String) vars[i];
            Object value = vars[i+1];
            if ("simultaneousTween".equals(key)) {
                // TODO
            } else if ("ease".equals(key)) {
                interpolator = (TimeInterpolator) value; // TODO: multiple interpolators?
            } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
                updateListener = (AnimatorUpdateListener) value;
            } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
                listener = (AnimatorListener) value;
            } else if ("delay".equals(key)) {
                delay = ((Number) value).longValue();
            } else if ("syncWith".equals(key)) {
                // TODO
            } else if (value instanceof Number[]) {
                // TODO: support Tween.from()
            } else if (value instanceof Number) {
                float floatValue = ((Number)value).floatValue();
                props.add(PropertyValuesHolder.ofFloat(key, floatValue));
            } else {
                throw new IllegalArgumentException(
                        "Bad argument for key \"" + key + "with value" + value);
            }
        }

        // Re-use existing tween, if present
        Tweener tween = sTweens.get(object);
        if (tween == null) {
            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(object,
                    props.toArray(new PropertyValuesHolder[props.size()]));
            tween = new Tweener(object, anim);
            sTweens.put(object, tween);
        } else {
            tween.animator.cancel();
            replace(props, object);
        }

        if (interpolator != null) {
            tween.animator.setInterpolator(interpolator);
        }

        // Update animation with properties discovered in loop above
        tween.animator.setStartDelay(delay);
        tween.animator.setDuration(duration);
        if (updateListener != null) {
            tween.animator.removeAllUpdateListeners(); // There should be only one
            tween.animator.addUpdateListener(updateListener);
        }
        if (listener != null) {
            tween.animator.removeAllListeners(); // There should be only one.
            tween.animator.addListener(listener);
        }
        tween.animator.start();

        return tween;
    }

    Tweener from(Object object, long duration, Object... vars) {
        // TODO:  for v of vars
        //            toVars[v] = object[v]
        //            object[v] = vars[v]
        return Tweener.to(object, duration, vars);
    }

    static void replace(ArrayList<PropertyValuesHolder> props, Object... args) {
        for (final Object killobject : args) {
            Tweener tween = sTweens.get(killobject);
            if (tween != null) {
                if (killobject == tween.object) {
                    tween.animator.cancel();
                    if (props != null) {
                        tween.animator.setValues(
                                props.toArray(new PropertyValuesHolder[props.size()]));
                    } else {
                        sTweens.remove(tween);
                    }
                }
            }
        }
    }
}
Loading