• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.statusbar;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.widget.CompoundButton;
22 
23 import com.android.systemui.statusbar.policy.AutoRotateController;
24 
25 public class RotationToggle extends CompoundButton
26         implements AutoRotateController.RotationLockCallbacks {
27     private AutoRotateController mRotater;
28 
RotationToggle(Context context)29     public RotationToggle(Context context) {
30         super(context);
31     }
32 
RotationToggle(Context context, AttributeSet attrs)33     public RotationToggle(Context context, AttributeSet attrs) {
34         super(context, attrs);
35     }
36 
RotationToggle(Context context, AttributeSet attrs, int defStyle)37     public RotationToggle(Context context, AttributeSet attrs, int defStyle) {
38         super(context, attrs, defStyle);
39     }
40 
41     @Override
onAttachedToWindow()42     protected void onAttachedToWindow() {
43         super.onAttachedToWindow();
44         mRotater = new AutoRotateController(getContext(), this, this);
45     }
46 
47     @Override
onDetachedFromWindow()48     protected void onDetachedFromWindow() {
49         super.onDetachedFromWindow();
50         if (mRotater != null) {
51             mRotater.release();
52             mRotater = null;
53         }
54     }
55 
56     @Override
setRotationLockControlVisibility(boolean show)57     public void setRotationLockControlVisibility(boolean show) {
58         setVisibility(show ? VISIBLE : GONE);
59     }
60 }
61