Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.stackdivider; |
| 18 | |
| 19 | import android.content.res.Configuration; |
| 20 | import android.view.LayoutInflater; |
| 21 | |
| 22 | import com.android.systemui.R; |
| 23 | import com.android.systemui.SystemUI; |
| 24 | |
| 25 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 26 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 27 | |
| 28 | /** |
| 29 | * Controls the docked stack divider. |
| 30 | */ |
| 31 | public class Divider extends SystemUI { |
| 32 | private static final String TAG = "Divider"; |
| 33 | private int mDividerWindowWidth; |
| 34 | private DividerWindowManager mWindowManager; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 35 | private DividerView mView; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 36 | |
| 37 | @Override |
| 38 | public void start() { |
| 39 | mWindowManager = new DividerWindowManager(mContext); |
| 40 | mDividerWindowWidth = mContext.getResources().getDimensionPixelSize( |
| 41 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
| 42 | update(mContext.getResources().getConfiguration()); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 43 | putComponent(Divider.class, this); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | protected void onConfigurationChanged(Configuration newConfig) { |
| 48 | super.onConfigurationChanged(newConfig); |
| 49 | update(newConfig); |
| 50 | } |
| 51 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 52 | public DividerView getView() { |
| 53 | return mView; |
| 54 | } |
| 55 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 56 | private void addDivider(Configuration configuration) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 57 | mView = (DividerView) |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 58 | LayoutInflater.from(mContext).inflate(R.layout.docked_stack_divider, null); |
| 59 | final boolean landscape = configuration.orientation == ORIENTATION_LANDSCAPE; |
| 60 | final int width = landscape ? mDividerWindowWidth : MATCH_PARENT; |
| 61 | final int height = landscape ? MATCH_PARENT : mDividerWindowWidth; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 62 | mWindowManager.add(mView, width, height); |
| 63 | mView.setWindowManager(mWindowManager); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | private void removeDivider() { |
| 67 | mWindowManager.remove(); |
| 68 | } |
| 69 | |
| 70 | private void update(Configuration configuration) { |
| 71 | removeDivider(); |
| 72 | addDivider(configuration); |
| 73 | } |
| 74 | } |