1package com.android.systemui.statusbar;
2
3import android.content.Context;
4import android.util.AttributeSet;
5import android.widget.CompoundButton;
6
7import com.android.systemui.statusbar.policy.AutoRotateController;
8
9public class RotationToggle extends CompoundButton
10        implements AutoRotateController.RotationLockCallbacks {
11    private AutoRotateController mRotater;
12
13    public RotationToggle(Context context) {
14        super(context);
15    }
16
17    public RotationToggle(Context context, AttributeSet attrs) {
18        super(context, attrs);
19    }
20
21    public RotationToggle(Context context, AttributeSet attrs, int defStyle) {
22        super(context, attrs, defStyle);
23    }
24
25    @Override
26    protected void onAttachedToWindow() {
27        super.onAttachedToWindow();
28        mRotater = new AutoRotateController(getContext(), this, this);
29    }
30
31    @Override
32    protected void onDetachedFromWindow() {
33        super.onDetachedFromWindow();
34        if (mRotater != null) {
35            mRotater.release();
36            mRotater = null;
37        }
38    }
39
40    @Override
41    public void setRotationLockControlVisibility(boolean show) {
42        setVisibility(show ? VISIBLE : GONE);
43    }
44}
45