Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [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.statusbar.car; |
| 18 | |
| 19 | import android.content.Context; |
Brad Stenning | e8a7568 | 2018-01-17 10:02:21 -0800 | [diff] [blame^] | 20 | import android.graphics.Canvas; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Brad Stenning | e8a7568 | 2018-01-17 10:02:21 -0800 | [diff] [blame^] | 22 | import android.view.MotionEvent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 23 | import android.view.View; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 24 | import android.widget.LinearLayout; |
| 25 | |
| 26 | import com.android.systemui.R; |
Brad Stenning | e8a7568 | 2018-01-17 10:02:21 -0800 | [diff] [blame^] | 27 | import com.android.systemui.plugins.statusbar.phone.NavGesture; |
| 28 | import com.android.systemui.statusbar.phone.NavigationBarGestureHelper; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 29 | import com.android.systemui.statusbar.phone.NavigationBarView; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 30 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 31 | /** |
| 32 | * A custom navigation bar for the automotive use case. |
| 33 | * <p> |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 34 | * The navigation bar in the automotive use case is more like a list of shortcuts, rendered |
| 35 | * in a linear layout. |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 36 | */ |
| 37 | class CarNavigationBarView extends NavigationBarView { |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 38 | private LinearLayout mNavButtons; |
| 39 | private LinearLayout mLightsOutButtons; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 40 | |
| 41 | public CarNavigationBarView(Context context, AttributeSet attrs) { |
| 42 | super(context, attrs); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void onFinishInflate() { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 47 | mNavButtons = findViewById(R.id.nav_buttons); |
| 48 | mLightsOutButtons = findViewById(R.id.lights_out); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 51 | public void addButton(CarNavigationButton button, CarNavigationButton lightsOutButton){ |
| 52 | mNavButtons.addView(button); |
| 53 | mLightsOutButtons.addView(lightsOutButton); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void setDisabledFlags(int disabledFlags, boolean force) { |
| 58 | // TODO: Populate. |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void reorient() { |
| 63 | // We expect the car head unit to always have a fixed rotation so we ignore this. The super |
| 64 | // class implentation expects mRotatedViews to be populated, so if you call into it, there |
| 65 | // is a possibility of a NullPointerException. |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public View getCurrentView() { |
| 70 | return this; |
| 71 | } |
Victor Chan | ecdb8b0 | 2016-01-07 18:32:43 -0800 | [diff] [blame] | 72 | |
| 73 | @Override |
| 74 | public void setNavigationIconHints(int hints, boolean force) { |
| 75 | // We do not need to set the navigation icon hints for a vehicle |
| 76 | // Calling setNavigationIconHints in the base class will result in a NPE as the car |
| 77 | // navigation bar does not have a back button. |
| 78 | } |
Brad Stenning | e8a7568 | 2018-01-17 10:02:21 -0800 | [diff] [blame^] | 79 | |
| 80 | @Override |
| 81 | public void onPluginConnected(NavGesture plugin, Context context) { |
| 82 | // set to null version of the plugin ignoring incoming arg. |
| 83 | super.onPluginConnected(new NullNavGesture(), context); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void onPluginDisconnected(NavGesture plugin) { |
| 88 | // reinstall the null nav gesture plugin |
| 89 | super.onPluginConnected(new NullNavGesture(), getContext()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Null object pattern to work around expectations of the base class. |
| 94 | * This is a temporary solution to have the car system ui working. |
| 95 | * Already underway is a refactor of they car sys ui as to not use this class |
| 96 | * hierarchy. |
| 97 | */ |
| 98 | private static class NullNavGesture implements NavGesture { |
| 99 | @Override |
| 100 | public GestureHelper getGestureHelper() { |
| 101 | return new GestureHelper() { |
| 102 | @Override |
| 103 | public boolean onTouchEvent(MotionEvent event) { |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void setBarState(boolean vertical, boolean isRtl) { |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void onDraw(Canvas canvas) { |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void onDarkIntensityChange(float intensity) { |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 126 | } |
| 127 | }; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public int getVersion() { |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onCreate(Context sysuiContext, Context pluginContext) { |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void onDestroy() { |
| 141 | } |
| 142 | } |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 143 | } |