blob: 6ff7a3e0815970de5e604d36c5149e5bf9bc91bb [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;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080020import android.view.IDockDividerVisibilityListener;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010021import android.view.LayoutInflater;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080022import android.view.View;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010023
24import com.android.systemui.R;
25import com.android.systemui.SystemUI;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080026import com.android.systemui.recents.Recents;
27import com.android.systemui.recents.misc.SystemServicesProxy;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010028
29import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
30import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
31
32/**
33 * Controls the docked stack divider.
34 */
35public class Divider extends SystemUI {
36 private static final String TAG = "Divider";
37 private int mDividerWindowWidth;
38 private DividerWindowManager mWindowManager;
Jorim Jaggidd98d412015-11-18 15:57:38 -080039 private DividerView mView;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080040 private DockDividerVisibilityListener mDockDividerVisibilityListener;
41 private boolean mVisible = false;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010042
43 @Override
44 public void start() {
45 mWindowManager = new DividerWindowManager(mContext);
46 mDividerWindowWidth = mContext.getResources().getDimensionPixelSize(
47 com.android.internal.R.dimen.docked_stack_divider_thickness);
48 update(mContext.getResources().getConfiguration());
Jorim Jaggidd98d412015-11-18 15:57:38 -080049 putComponent(Divider.class, this);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080050 mDockDividerVisibilityListener = new DockDividerVisibilityListener();
51 SystemServicesProxy ssp = Recents.getSystemServices();
52 ssp.registerDockDividerVisibilityListener(mDockDividerVisibilityListener);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010053 }
54
55 @Override
56 protected void onConfigurationChanged(Configuration newConfig) {
57 super.onConfigurationChanged(newConfig);
58 update(newConfig);
59 }
60
Jorim Jaggidd98d412015-11-18 15:57:38 -080061 public DividerView getView() {
62 return mView;
63 }
64
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010065 private void addDivider(Configuration configuration) {
Jorim Jaggidd98d412015-11-18 15:57:38 -080066 mView = (DividerView)
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010067 LayoutInflater.from(mContext).inflate(R.layout.docked_stack_divider, null);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080068 mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010069 final boolean landscape = configuration.orientation == ORIENTATION_LANDSCAPE;
70 final int width = landscape ? mDividerWindowWidth : MATCH_PARENT;
71 final int height = landscape ? MATCH_PARENT : mDividerWindowWidth;
Jorim Jaggidd98d412015-11-18 15:57:38 -080072 mWindowManager.add(mView, width, height);
73 mView.setWindowManager(mWindowManager);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010074 }
75
76 private void removeDivider() {
77 mWindowManager.remove();
78 }
79
80 private void update(Configuration configuration) {
81 removeDivider();
82 addDivider(configuration);
83 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080084
85 private void updateVisibility(final boolean visible) {
86 mView.post(new Runnable() {
87 @Override
88 public void run() {
89 if (mVisible != visible) {
90 mVisible = visible;
91 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
92 }
93 }
94 });
95 }
96
97 class DockDividerVisibilityListener extends IDockDividerVisibilityListener.Stub {
98 @Override
99 public void onDockDividerVisibilityChanged(boolean visible) {
100 updateVisibility(visible);
101 }
102 }
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100103}