From 9203e45a01afd98e69599d08adb6946715b2027b Mon Sep 17 00:00:00 2001 From: Heemin Seog Date: Thu, 5 Dec 2019 15:59:01 -0800 Subject: [PATCH] DO NOT MERGE Make nav bar button click listeners overrideable Bug: 145547127 Test: build, manual Change-Id: Ib7a96012f663ff740054588b135a2eec6d5164d0 --- .../statusbar/car/CarFacetButton.java | 26 +++++++--- .../statusbar/car/CarNavigationButton.java | 50 +++++++++++-------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarFacetButton.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarFacetButton.java index a371a1d8db019..fd9ce43a3a584 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarFacetButton.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarFacetButton.java @@ -110,24 +110,34 @@ public class CarFacetButton extends LinearLayout { mComponentNames = componentNameString.split(FACET_FILTER_DELIMITER); } - setOnClickListener(v -> { - intent.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected); - mContext.startActivityAsUser(intent, UserHandle.CURRENT); - }); + setOnClickListener(getButtonClickListener(intent)); if (longPressIntentString != null) { final Intent longPressIntent = Intent.parseUri(longPressIntentString, Intent.URI_INTENT_SCHEME); - setOnLongClickListener(v -> { - mContext.startActivityAsUser(longPressIntent, UserHandle.CURRENT); - return true; - }); + setOnLongClickListener(getButtonLongClickListener(longPressIntent)); } } catch (Exception e) { throw new RuntimeException("Failed to attach intent", e); } } + /** Defines the behavior of a button click. */ + protected OnClickListener getButtonClickListener(Intent toSend) { + return v -> { + toSend.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected); + mContext.startActivityAsUser(toSend, UserHandle.CURRENT); + }; + } + + /** Defines the behavior of a long click. */ + protected OnLongClickListener getButtonLongClickListener(Intent toSend) { + return v -> { + mContext.startActivityAsUser(toSend, UserHandle.CURRENT); + return true; + }; + } + private void setupIcons(TypedArray styledAttributes) { mSelectedAlpha = styledAttributes.getFloat( R.styleable.CarFacetButton_selectedAlpha, mSelectedAlpha); diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java index 8879742db00ac..bdf23c56797bf 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java @@ -90,17 +90,7 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag try { if (mIntent != null) { final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME); - setOnClickListener(v -> { - try { - if (mBroadcastIntent) { - mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); - return; - } - mContext.startActivityAsUser(intent, UserHandle.CURRENT); - } catch (Exception e) { - Log.e(TAG, "Failed to launch intent", e); - } - }); + setOnClickListener(getButtonClickListener(intent)); } } catch (URISyntaxException e) { throw new RuntimeException("Failed to attach intent", e); @@ -109,21 +99,41 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag try { if (mLongIntent != null) { final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME); - setOnLongClickListener(v -> { - try { - mContext.startActivityAsUser(intent, UserHandle.CURRENT); - } catch (Exception e) { - Log.e(TAG, "Failed to launch intent", e); - } - // consume event either way - return true; - }); + setOnLongClickListener(getButtonLongClickListener(intent)); } } catch (URISyntaxException e) { throw new RuntimeException("Failed to attach long press intent", e); } } + /** Defines the behavior of a button click. */ + protected OnClickListener getButtonClickListener(Intent toSend) { + return v -> { + try { + if (mBroadcastIntent) { + mContext.sendBroadcastAsUser(toSend, UserHandle.CURRENT); + return; + } + mContext.startActivityAsUser(toSend, UserHandle.CURRENT); + } catch (Exception e) { + Log.e(TAG, "Failed to launch intent", e); + } + }; + } + + /** Defines the behavior of a long click. */ + protected OnLongClickListener getButtonLongClickListener(Intent toSend) { + return v -> { + try { + mContext.startActivityAsUser(toSend, UserHandle.CURRENT); + } catch (Exception e) { + Log.e(TAG, "Failed to launch intent", e); + } + // consume event either way + return true; + }; + } + /** * @param selected true if should indicate if this is a selected state, false otherwise */