diff --git a/packages/SystemUI/res/drawable/car_ic_arrow.xml b/packages/SystemUI/res/drawable/car_ic_arrow.xml
new file mode 100644
index 0000000000000..9d292cc0259a6
--- /dev/null
+++ b/packages/SystemUI/res/drawable/car_ic_arrow.xml
@@ -0,0 +1,27 @@
+
+
- * The navigation bar in the automotive use case is more like a list of shortcuts, which we - * expect to be customizable by the car OEMs. This implementation populates the nav_buttons layout - * from resources rather than the layout file so customization would then mean updating - * arrays_car.xml appropriately in an overlay. + * The navigation bar in the automotive use case is more like a list of shortcuts, rendered + * in a linear layout. */ class CarNavigationBarView extends NavigationBarView { - private ActivityStarter mActivityStarter; + private LinearLayout mNavButtons; + private LinearLayout mLightsOutButtons; public CarNavigationBarView(Context context, AttributeSet attrs) { super(context, attrs); @@ -54,83 +47,13 @@ class CarNavigationBarView extends NavigationBarView { @Override public void onFinishInflate() { - // Read up arrays_car.xml and populate the navigation bar here. - Context context = getContext(); - Resources r = getContext().getResources(); - TypedArray icons = r.obtainTypedArray(R.array.car_shortcut_icons); - TypedArray intents = r.obtainTypedArray(R.array.car_shortcut_intent_uris); - TypedArray longpressIntents = - r.obtainTypedArray(R.array.car_shortcut_longpress_intent_uris); - - if (icons.length() != intents.length()) { - throw new RuntimeException("car_shortcut_icons and car_shortcut_intents do not match"); - } - - LinearLayout navButtons = (LinearLayout) findViewById(R.id.nav_buttons); - LinearLayout lightsOut = (LinearLayout) findViewById(R.id.lights_out); - - for (int i = 0; i < icons.length(); i++) { - Drawable icon = icons.getDrawable(i); - - try { - Intent intent = Intent.parseUri(intents.getString(i), Intent.URI_INTENT_SCHEME); - Intent longpress = null; - String longpressUri = longpressIntents.getString(i); - if (!longpressUri.isEmpty()) { - longpress = Intent.parseUri(longpressUri, Intent.URI_INTENT_SCHEME); - } - - // nav_buttons and lights_out should match exactly. - navButtons.addView(makeButton(context, icon, intent, longpress)); - lightsOut.addView(makeButton(context, icon, intent, longpress)); - } catch (URISyntaxException e) { - throw new RuntimeException("Malformed intent uri", e); - } - } + mNavButtons = (LinearLayout) findViewById(R.id.nav_buttons); + mLightsOutButtons = (LinearLayout) findViewById(R.id.lights_out); } - private ImageButton makeButton(Context context, Drawable icon, - final Intent intent, final Intent longpress) { - ImageButton button = new ImageButton(context); - - button.setImageDrawable(icon); - button.setScaleType(ScaleType.CENTER); - button.setBackgroundColor(color.transparent); - LinearLayout.LayoutParams lp = - new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1); - button.setLayoutParams(lp); - - button.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (mActivityStarter != null) { - mActivityStarter.startActivity(intent, true); - } - } - }); - - // Long click handlers are optional. - if (longpress != null) { - button.setLongClickable(true); - button.setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - if (mActivityStarter != null) { - mActivityStarter.startActivity(longpress, true); - return true; - } - return false; - } - }); - } else { - button.setLongClickable(false); - } - - return button; - } - - public void setActivityStarter(ActivityStarter activityStarter) { - mActivityStarter = activityStarter; + public void addButton(CarNavigationButton button, CarNavigationButton lightsOutButton){ + mNavButtons.addView(button); + mLightsOutButtons.addView(lightsOutButton); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java new file mode 100644 index 0000000000000..36b3a8ae816e4 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.statusbar.car; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import com.android.keyguard.AlphaOptimizedImageButton; +import com.android.systemui.R; + +/** + * A wrapper view for a car navigation facet, which includes a button icon and a drop down icon. + */ +public class CarNavigationButton extends RelativeLayout { + private static final float SELECTED_ALPHA = 1; + private static final float UNSELECTED_ALPHA = 0.7f; + + private AlphaOptimizedImageButton mIcon; + private AlphaOptimizedImageButton mMoreIcon; + + public CarNavigationButton(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void onFinishInflate() { + super.onFinishInflate(); + mIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_icon); + mIcon.setClickable(false); + mIcon.setScaleType(ImageView.ScaleType.CENTER); + mIcon.setBackgroundColor(android.R.color.transparent); + mIcon.setAlpha(UNSELECTED_ALPHA); + + mMoreIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_more_icon); + mMoreIcon.setClickable(false); + mMoreIcon.setScaleType(ImageView.ScaleType.CENTER); + mMoreIcon.setBackgroundColor(android.R.color.transparent); + mMoreIcon.setVisibility(INVISIBLE); + mMoreIcon.setImageDrawable(getContext().getDrawable(R.drawable.car_ic_arrow)); + mMoreIcon.setAlpha(UNSELECTED_ALPHA); + } + + public void setResources(Drawable icon) { + mIcon.setImageDrawable(icon); + } + + public void setSelected(boolean selected, boolean showMoreIcon) { + if (selected) { + mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : INVISIBLE); + mMoreIcon.setAlpha(SELECTED_ALPHA); + mIcon.setAlpha(SELECTED_ALPHA); + } else { + mMoreIcon.setVisibility(INVISIBLE); + mIcon.setAlpha(UNSELECTED_ALPHA); + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index 31631f8efa663..f6f1f94017aab 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -16,30 +16,52 @@ package com.android.systemui.statusbar.car; +import android.app.ActivityManager; +import android.app.ITaskStackListener; import android.content.Context; import android.graphics.PixelFormat; +import android.os.Handler; +import android.os.Looper; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import com.android.systemui.R; +import com.android.systemui.recents.Recents; +import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.statusbar.phone.PhoneStatusBar; /** * A status bar (and navigation bar) tailored for the automotive use case. */ public class CarStatusBar extends PhoneStatusBar { + private SystemServicesProxy mSystemServicesProxy; + private TaskStackListenerImpl mTaskStackListener; + private Handler mHandler; + + private CarNavigationBarView mCarNavigationBar; + private CarNavigationBarController mController; + + @Override + public void start() { + super.start(); + mHandler = new Handler(); + mTaskStackListener = new TaskStackListenerImpl(mHandler); + mSystemServicesProxy = new SystemServicesProxy(mContext); + mSystemServicesProxy.registerTaskStackListener(mTaskStackListener); + } + @Override protected void addNavigationBar() { WindowManager.LayoutParams lp = new WindowManager.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, - WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING - | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL - | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH - | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH - | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, + WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING + | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL + | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH + | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH + | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, PixelFormat.TRANSLUCENT); lp.setTitle("CarNavigationBar"); lp.windowAnimations = 0; @@ -51,11 +73,11 @@ public class CarStatusBar extends PhoneStatusBar { if (mNavigationBarView != null) { return; } - - CarNavigationBarView carNavBar = + mCarNavigationBar = (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null); - carNavBar.setActivityStarter(this); - mNavigationBarView = carNavBar; + mController = new CarNavigationBarController(context, mCarNavigationBar, + this /* ActivityStarter*/); + mNavigationBarView = mCarNavigationBar; } @Override @@ -63,4 +85,40 @@ public class CarStatusBar extends PhoneStatusBar { // The navigation bar for a vehicle will not need to be repositioned, as it is always // set at the bottom. } + + /** + * An implementation of ITaskStackListener, that listens for changes in the system task + * stack and notifies the navigation bar. + */ + private class TaskStackListenerImpl extends ITaskStackListener.Stub implements Runnable { + private Handler mHandler; + + public TaskStackListenerImpl(Handler handler) { + this.mHandler = handler; + } + + @Override + public void onActivityPinned() { + } + + @Override + public void onTaskStackChanged() { + mHandler.removeCallbacks(this); + mHandler.post(this); + } + + @Override + public void run() { + ensureMainThread(); + SystemServicesProxy ssp = Recents.getSystemServices(); + ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask(); + mController.taskChanged(runningTaskInfo.baseActivity.getPackageName()); + } + + private void ensureMainThread() { + if (!Looper.getMainLooper().isCurrentThread()) { + throw new RuntimeException("Must be called on the UI thread"); + } + } + } }