1 /*
2  * Copyright (C) 2014 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 
17 package com.android.systemui.settings;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.util.AttributeSet;
22 import android.view.MotionEvent;
23 import android.view.accessibility.AccessibilityNodeInfo;
24 import android.widget.SeekBar;
25 
26 import com.android.settingslib.RestrictedLockUtils;
27 import com.android.systemui.Dependency;
28 import com.android.systemui.plugins.ActivityStarter;
29 
30 public class ToggleSeekBar extends SeekBar {
31     private String mAccessibilityLabel;
32 
33     private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin = null;
34 
ToggleSeekBar(Context context)35     public ToggleSeekBar(Context context) {
36         super(context);
37     }
38 
ToggleSeekBar(Context context, AttributeSet attrs)39     public ToggleSeekBar(Context context, AttributeSet attrs) {
40         super(context, attrs);
41     }
42 
ToggleSeekBar(Context context, AttributeSet attrs, int defStyleAttr)43     public ToggleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
44         super(context, attrs, defStyleAttr);
45     }
46 
47     @Override
onTouchEvent(MotionEvent event)48     public boolean onTouchEvent(MotionEvent event) {
49         if (mEnforcedAdmin != null) {
50             Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
51                     mContext, mEnforcedAdmin);
52             Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(intent, 0);
53             return true;
54         }
55         if (!isEnabled()) {
56             setEnabled(true);
57         }
58 
59         return super.onTouchEvent(event);
60     }
61 
setAccessibilityLabel(String label)62     public void setAccessibilityLabel(String label) {
63         mAccessibilityLabel = label;
64     }
65 
66     @Override
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)67     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
68         super.onInitializeAccessibilityNodeInfo(info);
69         if (mAccessibilityLabel != null) {
70             info.setText(mAccessibilityLabel);
71         }
72     }
73 
setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin)74     public void setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
75         mEnforcedAdmin = admin;
76     }
77 }
78