Daniel Sandler | 50a5313 | 2012-10-24 15:02:27 -0400 | [diff] [blame] | 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 | |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 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 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 25 | public class RotationToggle extends CompoundButton |
| 26 | implements AutoRotateController.RotationLockCallbacks { |
| 27 | private AutoRotateController mRotater; |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 28 | |
| 29 | public RotationToggle(Context context) { |
| 30 | super(context); |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | public RotationToggle(Context context, AttributeSet attrs) { |
| 34 | super(context, attrs); |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public RotationToggle(Context context, AttributeSet attrs, int defStyle) { |
| 38 | super(context, attrs, defStyle); |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 41 | @Override |
| 42 | protected void onAttachedToWindow() { |
| 43 | super.onAttachedToWindow(); |
| 44 | mRotater = new AutoRotateController(getContext(), this, this); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected void onDetachedFromWindow() { |
| 49 | super.onDetachedFromWindow(); |
| 50 | if (mRotater != null) { |
| 51 | mRotater.release(); |
| 52 | mRotater = null; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void setRotationLockControlVisibility(boolean show) { |
| 58 | setVisibility(show ? VISIBLE : GONE); |
| 59 | } |
Daniel Sandler | 9ff6378 | 2012-05-03 23:16:42 -0400 | [diff] [blame] | 60 | } |