John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2010 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.policy; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.os.UserHandle; |
| 21 | |
| 22 | import com.android.internal.view.RotationPolicy; |
| 23 | |
| 24 | import java.util.concurrent.CopyOnWriteArrayList; |
| 25 | |
| 26 | /** Platform implementation of the rotation lock controller. **/ |
| 27 | public final class RotationLockControllerImpl implements RotationLockController { |
| 28 | private final Context mContext; |
| 29 | private final CopyOnWriteArrayList<RotationLockControllerCallback> mCallbacks = |
| 30 | new CopyOnWriteArrayList<RotationLockControllerCallback>(); |
| 31 | |
| 32 | private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = |
| 33 | new RotationPolicy.RotationPolicyListener() { |
| 34 | @Override |
| 35 | public void onChange() { |
| 36 | notifyChanged(); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | public RotationLockControllerImpl(Context context) { |
| 41 | mContext = context; |
| 42 | RotationPolicy.registerRotationPolicyListener(mContext, |
| 43 | mRotationPolicyListener, UserHandle.USER_ALL); |
| 44 | } |
| 45 | |
| 46 | public void addRotationLockControllerCallback(RotationLockControllerCallback callback) { |
| 47 | mCallbacks.add(callback); |
| 48 | } |
| 49 | |
| 50 | public void removeRotationLockControllerCallback(RotationLockControllerCallback callback) { |
| 51 | mCallbacks.remove(callback); |
| 52 | } |
| 53 | |
| 54 | public int getRotationLockOrientation() { |
| 55 | return RotationPolicy.getRotationLockOrientation(mContext); |
| 56 | } |
| 57 | |
| 58 | public boolean isRotationLocked() { |
| 59 | return RotationPolicy.isRotationLocked(mContext); |
| 60 | } |
| 61 | |
| 62 | public void setRotationLocked(boolean locked) { |
| 63 | RotationPolicy.setRotationLock(mContext, locked); |
| 64 | } |
| 65 | |
| 66 | public boolean isRotationLockAffordanceVisible() { |
| 67 | return RotationPolicy.isRotationLockToggleVisible(mContext); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void dispose() { |
| 72 | RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener); |
| 73 | } |
| 74 | |
| 75 | private void notifyChanged() { |
| 76 | for (RotationLockControllerCallback callback : mCallbacks) { |
| 77 | callback.onRotationLockStateChanged(RotationPolicy.isRotationLocked(mContext), |
| 78 | RotationPolicy.isRotationLockToggleVisible(mContext)); |
| 79 | } |
| 80 | } |
| 81 | } |