DO NOT MERGE Make nav bar button click listeners overrideable

Bug: 145547127
Test: build, manual
Change-Id: Ib7a96012f663ff740054588b135a2eec6d5164d0
This commit is contained in:
Heemin Seog
2019-12-05 15:59:01 -08:00
parent 2f79f57d66
commit 9203e45a01
2 changed files with 48 additions and 28 deletions

View File

@@ -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);

View File

@@ -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
*/