aboutsummaryrefslogtreecommitdiffstats
path: root/samples/externalviews/keyguardviewprovider/src/org/cyanogenmod/samples/keyguardextview/SampleKeyguardProviderService.java
blob: 194173ae39bd64b26196f74a0a573c47c654beb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (C) 2015 The CyanogenMod 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 org.cyanogenmod.samples.keyguardextview;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import cyanogenmod.externalviews.KeyguardExternalViewProviderService;

public class SampleKeyguardProviderService extends KeyguardExternalViewProviderService {

    @Override
    protected KeyguardExternalViewProviderService.Provider createExternalView(Bundle options) {
        return new ProviderImpl(options);
    }

    private class ProviderImpl extends Provider {
        ImageView mImageView;
        Animation mPulseAnimation;

        protected ProviderImpl(Bundle options) {
            super(options);
        }

        /**
         * Create a view that will be displayed within the system's lock screen (aka keyguard)
         * @return The view to be displayed
         */
        @Override
        protected View onCreateView() {
            View view = LayoutInflater.from(SampleKeyguardProviderService.this)
                    .inflate(R.layout.main, null);
            mImageView = (ImageView) view.findViewById(R.id.cid);
            return view;
        }

        /**
         * Called when the keyguard is being shown
         * @param screenOn True if the screen is currently on
         */
        @Override
        protected void onKeyguardShowing(boolean screenOn) {

        }

        /**
         * Called when the user has unlocked their device and the keyguard is dismissed
         */
        @Override
        protected void onKeyguardDismissed() {

        }

        /**
         * Called when the state of the bouncer being shown changes
         * @param showing True if the bouncer is showing
         */
        @Override
        protected void onBouncerShowing(boolean showing) {

        }

        /**
         * Called when the screen has been turned on
         */
        @Override
        protected void onScreenTurnedOn() {
            mImageView.startAnimation(mPulseAnimation);
        }

        /**
         * Called when the screen has been turned off
         */
        @Override
        protected void onScreenTurnedOff() {
            mImageView.clearAnimation();
        }

        @Override
        protected void onLockscreenSlideOffsetChanged(float slideProgress) {

        }

        /**
         * Called when the view has been attached to a window
         */
        @Override
        protected void onAttach() {
            super.onAttach();
            // If this is an interactive component, now is a good time to
            // call setInteractivity(true);
            setInteractivity(false);
            mPulseAnimation = AnimationUtils.loadAnimation(SampleKeyguardProviderService.this,
                    R.anim.pulsing_anim);
            mImageView.startAnimation(mPulseAnimation);
        }

        /**
         * Called when the view has been detached from the window
         */
        @Override
        protected void onDetach() {
            super.onDetach();
        }
    }
}