blob: 8ed4c75e86737727b70c8d5b060b9b5ffc3424e5 [file] [log] [blame]
Alan Viverettef6a67982014-04-08 15:27:24 -07001/*
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
17package com.android.systemui.settings;
18
19import android.content.Context;
yuemingweb2bf7d182018-01-23 16:05:08 +000020import android.content.Intent;
Alan Viverettef6a67982014-04-08 15:27:24 -070021import android.util.AttributeSet;
22import android.view.MotionEvent;
Selim Cinek4949c752015-06-26 14:49:18 -040023import android.view.accessibility.AccessibilityNodeInfo;
Alan Viverettef6a67982014-04-08 15:27:24 -070024import android.widget.SeekBar;
25
yuemingweb2bf7d182018-01-23 16:05:08 +000026import com.android.settingslib.RestrictedLockUtils;
27import com.android.systemui.Dependency;
28import com.android.systemui.plugins.ActivityStarter;
29
Alan Viverettef6a67982014-04-08 15:27:24 -070030public class ToggleSeekBar extends SeekBar {
Selim Cinek4949c752015-06-26 14:49:18 -040031 private String mAccessibilityLabel;
32
yuemingweb2bf7d182018-01-23 16:05:08 +000033 private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin = null;
34
Alan Viverettef6a67982014-04-08 15:27:24 -070035 public ToggleSeekBar(Context context) {
36 super(context);
37 }
38
39 public ToggleSeekBar(Context context, AttributeSet attrs) {
40 super(context, attrs);
41 }
42
43 public ToggleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
44 super(context, attrs, defStyleAttr);
45 }
46
47 @Override
48 public boolean onTouchEvent(MotionEvent event) {
yuemingweb2bf7d182018-01-23 16:05:08 +000049 if (mEnforcedAdmin != null) {
50 Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
51 mContext, mEnforcedAdmin);
52 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(intent, 0);
53 return true;
54 }
Alan Viverettef6a67982014-04-08 15:27:24 -070055 if (!isEnabled()) {
56 setEnabled(true);
57 }
58
59 return super.onTouchEvent(event);
60 }
Selim Cinek4949c752015-06-26 14:49:18 -040061
62 public void setAccessibilityLabel(String label) {
63 mAccessibilityLabel = label;
64 }
65
66 @Override
67 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
68 super.onInitializeAccessibilityNodeInfo(info);
69 if (mAccessibilityLabel != null) {
70 info.setText(mAccessibilityLabel);
71 }
72 }
yuemingweb2bf7d182018-01-23 16:05:08 +000073
74 public void setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
75 mEnforcedAdmin = admin;
76 }
Alan Viverettef6a67982014-04-08 15:27:24 -070077}