in AutofillFramework/Application/src/main/java/com/example/android/autofill/app/view/widget/NavigationItem.java [54:97]
public NavigationItem(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationItem,
defStyleAttr, defStyleRes);
int activityMinSdk = typedArray.getInteger(R.styleable.NavigationItem_minSdk, 26);
// TODO: Remove BuildCompat.isAtLeastP() check when API 28 is finalized.
int deviceMinSdk = BuildCompat.isAtLeastP() ? 28 : Build.VERSION.SDK_INT;
if (deviceMinSdk < activityMinSdk) {
// If device's SDK is lower than the minSdk specified by the NavigationItem, hide it.
setVisibility(View.GONE);
return;
}
String labelText = typedArray.getString(R.styleable.NavigationItem_labelText);
String infoText = typedArray.getString(R.styleable.NavigationItem_infoText);
Drawable logoDrawable = typedArray.getDrawable(R.styleable.NavigationItem_itemLogo);
@ColorRes int colorRes = typedArray.getResourceId(R.styleable.NavigationItem_imageColor, 0);
String launchingActivityName = typedArray.getString(R.styleable.NavigationItem_destinationActivityName);
int imageColor = ContextCompat.getColor(getContext(), colorRes);
typedArray.recycle();
View rootView = LayoutInflater.from(context).inflate(R.layout.navigation_item, this);
TextView buttonLabel = rootView.findViewById(R.id.buttonLabel);
buttonLabel.setText(labelText);
if (logoDrawable != null) {
Drawable mutatedLogoDrawable = logoDrawable.mutate();
mutatedLogoDrawable.setColorFilter(imageColor, PorterDuff.Mode.SRC_IN);
buttonLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(mutatedLogoDrawable, null,
null, null);
}
InfoButton infoButton = rootView.findViewById(R.id.infoButton);
infoButton.setInfoText(infoText);
infoButton.setColorFilter(imageColor);
CardView outerView = rootView.findViewById(R.id.cardView);
outerView.setOnClickListener((view) -> {
if (launchingActivityName != null) {
Intent intent = new Intent();
intent.setClassName(getContext().getPackageName(), launchingActivityName);
context.startActivity(intent);
} else {
Log.w(TAG, "Launching Activity name not set.");
}
});
}