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

Commit 955a0169 authored by Jim Miller's avatar Jim Miller
Browse files

Fix 6613962: Update keyguard to use new GlowPadView UX design.

Change-Id: I4f1ef3107e5550f7df9dcb412943a84b66432b7d
parent 1c958102
Loading
Loading
Loading
Loading
+1226 −0

File added.

Preview size limit exceeded, changes collapsed.

+8 −28
Original line number Diff line number Diff line
@@ -117,8 +117,6 @@ public class MultiWaveView extends View {
    private float mWaveCenterY;
    private int mMaxTargetHeight;
    private int mMaxTargetWidth;
    private float mHorizontalOffset;
    private float mVerticalOffset;

    private float mOuterRadius = 0.0f;
    private float mHitRadius = 0.0f;
@@ -215,9 +213,6 @@ public class MultiWaveView extends View {

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiWaveView);
        mOuterRadius = a.getDimension(R.styleable.MultiWaveView_outerRadius, mOuterRadius);
//        mHorizontalOffset = a.getDimension(R.styleable.MultiWaveView_horizontalOffset,
//                mHorizontalOffset);
//        mVerticalOffset = a.getDimension(R.styleable.MultiWaveView_verticalOffset, mVerticalOffset);
        mHitRadius = a.getDimension(R.styleable.MultiWaveView_hitRadius, mHitRadius);
        mSnapMargin = a.getDimension(R.styleable.MultiWaveView_snapMargin, mSnapMargin);
        mVibrationDuration = a.getInt(R.styleable.MultiWaveView_vibrationDuration,
@@ -230,7 +225,6 @@ public class MultiWaveView extends View {
        mOuterRing = new TargetDrawable(res,
                a.peekValue(R.styleable.MultiWaveView_waveDrawable).resourceId);
        mAlwaysTrackFinger = a.getBoolean(R.styleable.MultiWaveView_alwaysTrackFinger, false);
        mGravity = a.getInt(R.styleable.MultiWaveView_gravity, Gravity.TOP);

        // Read array of chevron drawables
        TypedValue outValue = new TypedValue();
@@ -244,24 +238,6 @@ public class MultiWaveView extends View {
            }
        }

        // Support old-style chevron specification if new specification not found
        if (mChevronDrawables.size() == 0) {
            final int chevronResIds[] = {
                    R.styleable.MultiWaveView_rightChevronDrawable,
                    R.styleable.MultiWaveView_topChevronDrawable,
                    R.styleable.MultiWaveView_leftChevronDrawable,
                    R.styleable.MultiWaveView_bottomChevronDrawable
            };

            for (int i = 0; i < chevronResIds.length; i++) {
                TypedValue typedValue = a.peekValue(chevronResIds[i]);
                for (int k = 0; k < mFeedbackCount; k++) {
                    mChevronDrawables.add(
                        typedValue != null ? new TargetDrawable(res, typedValue.resourceId) : null);
                }
            }
        }

        // Read array of target drawables
        if (a.getValue(R.styleable.MultiWaveView_targetDrawables, outValue)) {
            internalSetTargetResources(outValue.resourceId);
@@ -289,6 +265,12 @@ public class MultiWaveView extends View {
        }

        a.recycle();

        // Use gravity attribute from LinearLayout
        a = context.obtainStyledAttributes(attrs, android.R.styleable.LinearLayout);
        mGravity = a.getInt(android.R.styleable.LinearLayout_gravity, Gravity.TOP);
        a.recycle();

        setVibrateEnabled(mVibrationDuration > 0);
        assignDefaultsIfNeeded();
    }
@@ -302,8 +284,6 @@ public class MultiWaveView extends View {
        Log.v(TAG, "TapRadius = " + mTapRadius);
        Log.v(TAG, "WaveCenterX = " + mWaveCenterX);
        Log.v(TAG, "WaveCenterY = " + mWaveCenterY);
        Log.v(TAG, "HorizontalOffset = " + mHorizontalOffset);
        Log.v(TAG, "VerticalOffset = " + mVerticalOffset);
    }

    public void suspendAnimations() {
@@ -1042,9 +1022,9 @@ public class MultiWaveView extends View {
        // width or the specified outer radius.
        final float placementWidth = Math.max(mOuterRing.getWidth(), 2 * mOuterRadius);
        final float placementHeight = Math.max(mOuterRing.getHeight(), 2 * mOuterRadius);
        float newWaveCenterX = mHorizontalOffset + mHorizontalInset
        float newWaveCenterX = mHorizontalInset
                + Math.max(width, mMaxTargetWidth + placementWidth) / 2;
        float newWaveCenterY = mVerticalOffset + mVerticalInset
        float newWaveCenterY = mVerticalInset
                + Math.max(height, + mMaxTargetHeight + placementHeight) / 2;

        if (mInitialLayout) {
+235 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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 android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.FloatMath;
import android.util.Log;

public class PointCloud {
    private static final float MIN_POINT_SIZE = 2.0f;
    private static final float MAX_POINT_SIZE = 4.0f;
    private static final int INNER_POINTS = 8;
    private static final String TAG = "PointCloud";
    private ArrayList<Point> mPointCloud = new ArrayList<Point>();
    private Drawable mDrawable;
    private float mCenterX;
    private float mCenterY;
    private Paint mPaint;
    private float mScale = 1.0f;
    private static final float PI = (float) Math.PI;

    // These allow us to have multiple concurrent animations.
    WaveManager waveManager = new WaveManager();
    GlowManager glowManager = new GlowManager();
    private float mOuterRadius;

    public class WaveManager {
        private float radius = 50;
        private float width = 200.0f; // TODO: Make configurable
        private float alpha = 0.0f;
        public void setRadius(float r) {
            radius = r;
        }

        public float getRadius() {
            return radius;
        }

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

        public float getAlpha() {
            return alpha;
        }
    };

    public class GlowManager {
        private float x;
        private float y;
        private float radius = 0.0f;
        private float alpha = 0.0f;

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

        public float getX() {
            return x;
        }

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

        public float getY() {
            return y;
        }

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

        public float getAlpha() {
            return alpha;
        }

        public void setRadius(float r) {
            radius = r;
        }

        public float getRadius() {
            return radius;
        }
    }

    class Point {
        float x;
        float y;
        float radius;

        public Point(float x2, float y2, float r) {
            x = (float) x2;
            y = (float) y2;
            radius = r;
        }
    }

    public PointCloud(Drawable drawable) {
        mPaint = new Paint();
        mPaint.setFilterBitmap(true);
        mPaint.setColor(Color.rgb(255, 255, 255)); // TODO: make configurable
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);

        mDrawable = drawable;
        if (mDrawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        }
    }

    public void setCenter(float x, float y) {
        mCenterX = x;
        mCenterY = y;
    }

    public void makePointCloud(float innerRadius, float outerRadius) {
        if (innerRadius == 0) {
            Log.w(TAG, "Must specify an inner radius");
            return;
        }
        mOuterRadius = outerRadius;
        mPointCloud.clear();
        final float pointAreaRadius =  (outerRadius - innerRadius);
        final float ds = (2.0f * PI * innerRadius / INNER_POINTS);
        final int bands = (int) Math.round(pointAreaRadius / ds);
        final float dr = pointAreaRadius / bands;
        float r = innerRadius;
        for (int b = 0; b <= bands; b++, r += dr) {
            float circumference = 2.0f * PI * r;
            final int pointsInBand = (int) (circumference / ds);
            float eta = PI/2.0f;
            float dEta = 2.0f * PI / pointsInBand;
            for (int i = 0; i < pointsInBand; i++) {
                float x = r * FloatMath.cos(eta);
                float y = r * FloatMath.sin(eta);
                eta += dEta;
                mPointCloud.add(new Point(x, y, r));
            }
        }
    }

    public void setScale(float scale) {
        mScale  = scale;
    }

    public float getScale() {
        return mScale;
    }

    private static float hypot(float x, float y) {
        return FloatMath.sqrt(x*x + y*y);
    }

    private static float max(float a, float b) {
        return a > b ? a : b;
    }

    public int getAlphaForPoint(Point point) {
        // Contribution from positional glow
        float glowDistance = hypot(glowManager.x - point.x, glowManager.y - point.y);
        float glowAlpha = 0.0f;
        if (glowDistance < glowManager.radius) {
            float cosf = FloatMath.cos(PI * 0.5f * glowDistance / glowManager.radius);
            glowAlpha = glowManager.alpha * max(0.0f, (float) Math.pow(cosf, 0.5f));
        }

        // Compute contribution from Wave
        float radius = hypot(point.x, point.y);
        float distanceToWaveRing = Math.abs(radius - waveManager.radius);
        float waveAlpha = 0.0f;
        if (distanceToWaveRing < waveManager.width * 0.5f) {
            float cosf = FloatMath.cos(PI * 0.5f * distanceToWaveRing / waveManager.width);
            waveAlpha = waveManager.alpha * max(0.0f, (float) Math.pow(cosf, 15.0f));
        }

        return (int) (max(glowAlpha, waveAlpha) * 255);
    }

    private float interp(float min, float max, float f) {
        return min + (max - min) * f;
    }

    public void draw(Canvas canvas) {
        ArrayList<Point> points = mPointCloud;
        final float cx = mDrawable != null ? (-mDrawable.getIntrinsicWidth() / 2) : 0;
        final float cy = mDrawable != null ? (-mDrawable.getIntrinsicHeight() / 2) : 0;
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale(mScale, mScale, mCenterX, mCenterY);
        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            final float pointSize = interp(MAX_POINT_SIZE, MIN_POINT_SIZE,
                    point.radius / mOuterRadius);
            final float px = point.x + cx + mCenterX;
            final float py = point.y + cy + mCenterY;
            int alpha = getAlphaForPoint(point);

            if (alpha == 0) continue;

            if (mDrawable != null) {
                canvas.save(Canvas.MATRIX_SAVE_FLAG);
                float s = pointSize / MAX_POINT_SIZE;
                canvas.scale(s, s, px, py);
                canvas.translate(px, py);
                mDrawable.setAlpha(alpha);
                mDrawable.draw(canvas);
                canvas.restore();
            } else {
                mPaint.setAlpha(alpha);
                canvas.drawCircle(px, py, pointSize, mPaint);
            }
        }
        canvas.restore();
    }

}
+738 B
Loading image diff...
+538 B
Loading image diff...
Loading