1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.keyguard;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.MotionEvent;
22import android.view.View;
23
24public class EmergencyCarrierArea extends AlphaOptimizedLinearLayout {
25
26    private CarrierText mCarrierText;
27    private EmergencyButton mEmergencyButton;
28
29    public EmergencyCarrierArea(Context context) {
30        super(context);
31    }
32
33    public EmergencyCarrierArea(Context context, AttributeSet attrs) {
34        super(context, attrs);
35    }
36
37    @Override
38    protected void onFinishInflate() {
39        super.onFinishInflate();
40        mCarrierText = findViewById(R.id.carrier_text);
41        mEmergencyButton = findViewById(R.id.emergency_call_button);
42
43        // The emergency button overlaps the carrier text, only noticeable when highlighted.
44        // So temporarily hide the carrier text while the emergency button is pressed.
45        mEmergencyButton.setOnTouchListener(new OnTouchListener(){
46            @Override
47            public boolean onTouch(View v, MotionEvent event) {
48                if (mCarrierText.getVisibility() != View.VISIBLE) return false;
49                switch(event.getAction()) {
50                    case MotionEvent.ACTION_DOWN:
51                        mCarrierText.animate().alpha(0);
52                        break;
53                    case MotionEvent.ACTION_UP:
54                        mCarrierText.animate().alpha(1);
55                        break;
56                }
57                return false;
58            }});
59    }
60
61    public void setCarrierTextVisible(boolean visible) {
62        mCarrierText.setVisibility(visible ? View.VISIBLE : View.GONE);
63    }
64}
65