blob: 50e010fc292814ed0b4a6d3ac506e4138d8109a1 [file] [log] [blame]
Jorim Jaggi1fcbab62015-11-04 16:39:50 +01001/*
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
17package com.android.systemui.stackdivider;
18
19import android.content.res.Configuration;
20import android.view.LayoutInflater;
21
22import com.android.systemui.R;
23import com.android.systemui.SystemUI;
24
25import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
26import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
27
28/**
29 * Controls the docked stack divider.
30 */
31public class Divider extends SystemUI {
32 private static final String TAG = "Divider";
33 private int mDividerWindowWidth;
34 private DividerWindowManager mWindowManager;
Jorim Jaggidd98d412015-11-18 15:57:38 -080035 private DividerView mView;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010036
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 Jaggidd98d412015-11-18 15:57:38 -080043 putComponent(Divider.class, this);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010044 }
45
46 @Override
47 protected void onConfigurationChanged(Configuration newConfig) {
48 super.onConfigurationChanged(newConfig);
49 update(newConfig);
50 }
51
Jorim Jaggidd98d412015-11-18 15:57:38 -080052 public DividerView getView() {
53 return mView;
54 }
55
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010056 private void addDivider(Configuration configuration) {
Jorim Jaggidd98d412015-11-18 15:57:38 -080057 mView = (DividerView)
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010058 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 Jaggidd98d412015-11-18 15:57:38 -080062 mWindowManager.add(mView, width, height);
63 mView.setWindowManager(mWindowManager);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010064 }
65
66 private void removeDivider() {
67 mWindowManager.remove();
68 }
69
70 private void update(Configuration configuration) {
71 removeDivider();
72 addDivider(configuration);
73 }
74}