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

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

Allow animation movie for "find the sensor" flow

This adds an optional overlay to specify a per-device
movie to illustrate enrolling a fingerprint. To enable,
create a new layout overlay for
fingerprint_enroll_find_sensor_graphic.xml using
FingerprintLocationAnimationVideoView

Fixes bug 22954305

Change-Id: I59294f71617ecf7a9bf09603fc0b068cc5aa8ff9
parent 9cbf3255
Loading
Loading
Loading
Loading
+33 −31
Original line number Diff line number Diff line
@@ -22,6 +22,19 @@
    android:layout_height="match_parent"
    style="?attr/fingerprint_layout_theme">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:clipToPadding="false"
        android:clipChildren="false">

        <include
            layout="@layout/fingerprint_enroll_find_sensor_graphic"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal|bottom"/>

        <LinearLayout
            style="@style/SuwContentFrame"
            android:layout_width="match_parent"
@@ -42,17 +55,6 @@
                android:layout_width="match_parent"
                android:layout_weight="1"/>

        <include
            layout="@layout/fingerprint_enroll_find_sensor_graphic"
            android:layout_width="@dimen/fingerprint_find_sensor_graphic_size"
            android:layout_height="@dimen/fingerprint_find_sensor_graphic_size"
            android:layout_gravity="center_horizontal"/>

        <View
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:layout_weight="1"/>

            <Button
                style="@style/Button.FingerprintButton"
                android:id="@+id/next_button"
@@ -65,5 +67,5 @@
                android:text="@string/fingerprint_enroll_button_next" />

        </LinearLayout>

    </FrameLayout>
</com.android.setupwizardlib.SetupWizardLayout>
+0 −0

Empty file added.

+2 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
    private static final int ENROLLING = 2;
    public static final String EXTRA_KEY_LAUNCHED_CONFIRM = "launched_confirm_lock";

    private FingerprintLocationAnimationView mAnimation;
    private FingerprintFindSensorAnimation mAnimation;
    private boolean mLaunchedConfirmLock;

    @Override
@@ -46,7 +46,7 @@ public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
        if (mToken == null && !mLaunchedConfirmLock) {
            launchConfirmLock();
        }
        mAnimation = (FingerprintLocationAnimationView) findViewById(
        mAnimation = (FingerprintFindSensorAnimation) findViewById(
                R.id.fingerprint_sensor_location_animation);
    }

+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.settings.fingerprint;

/**
 * An abstraction for a view that contains an animation that shows the user
 * where the fingerprint sensor is on the device.
 */
public interface FingerprintFindSensorAnimation {

    /**
     * Start the animation
     */
    void startAnimation();

    /**
     * Stop the animation
     */
    void stopAnimation();

}
+125 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.settings.fingerprint;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;

import com.android.settings.R;

/**
 * A view containing a VideoView for showing the user how to enroll a fingerprint
 */
public class FingerprintLocationAnimationVideoView extends TextureView
        implements FingerprintFindSensorAnimation {
    protected float mAspect = 1.0f; // initial guess until we know
    protected MediaPlayer mMediaPlayer;

    public FingerprintLocationAnimationVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Width is driven by measurespec, height is derrived from aspect ratio
        int originalWidth = MeasureSpec.getSize(widthMeasureSpec);
        int height = Math.round(mAspect * originalWidth);
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setSurfaceTextureListener(new SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
                    int height) {
                setVisibility(View.INVISIBLE);
                Uri videoUri = resourceEntryToUri(mContext, R.raw.fingerprint_location_animation);
                mMediaPlayer = MediaPlayer.create(mContext, videoUri);
                mMediaPlayer.setSurface(new Surface(surfaceTexture));
                mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mediaPlayer) {
                        mediaPlayer.setLooping(true);
                    }
                });
                mMediaPlayer.setOnInfoListener(new OnInfoListener() {
                    @Override
                    public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
                        if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                            // Keep the view hidden until video starts
                            setVisibility(View.VISIBLE);
                        }
                        return false;
                    }
                });
                mAspect = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth();
                requestLayout();
                startAnimation();
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture,
                    int width, int height) {
            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
                return false;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
            }
        });
    }

    private static Uri resourceEntryToUri (Context context, int id) {
        Resources res = context.getResources();
        return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
                res.getResourcePackageName(id) + '/' +
                res.getResourceTypeName(id) + '/' +
                res.getResourceEntryName(id));
    }

    @Override
    public void startAnimation() {
        if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
            mMediaPlayer.start();
        }
    }

    @Override
    public void stopAnimation() {
        if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
            mMediaPlayer.stop();
        }
    }

}
Loading