Merge "DO NOT MERGE Make nav bar button click listeners overrideable" into qt-qpr1-dev

This commit is contained in:
Heemin Seog
2019-12-10 20:45:40 +00:00
committed by Android (Google) Code Review
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); mComponentNames = componentNameString.split(FACET_FILTER_DELIMITER);
} }
setOnClickListener(v -> { setOnClickListener(getButtonClickListener(intent));
intent.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
});
if (longPressIntentString != null) { if (longPressIntentString != null) {
final Intent longPressIntent = Intent.parseUri(longPressIntentString, final Intent longPressIntent = Intent.parseUri(longPressIntentString,
Intent.URI_INTENT_SCHEME); Intent.URI_INTENT_SCHEME);
setOnLongClickListener(v -> { setOnLongClickListener(getButtonLongClickListener(longPressIntent));
mContext.startActivityAsUser(longPressIntent, UserHandle.CURRENT);
return true;
});
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to attach intent", 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) { private void setupIcons(TypedArray styledAttributes) {
mSelectedAlpha = styledAttributes.getFloat( mSelectedAlpha = styledAttributes.getFloat(
R.styleable.CarFacetButton_selectedAlpha, mSelectedAlpha); R.styleable.CarFacetButton_selectedAlpha, mSelectedAlpha);

View File

@@ -90,17 +90,7 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
try { try {
if (mIntent != null) { if (mIntent != null) {
final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME); final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME);
setOnClickListener(v -> { setOnClickListener(getButtonClickListener(intent));
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);
}
});
} }
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new RuntimeException("Failed to attach intent", e); throw new RuntimeException("Failed to attach intent", e);
@@ -109,19 +99,39 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
try { try {
if (mLongIntent != null) { if (mLongIntent != null) {
final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME); final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
setOnLongClickListener(v -> { 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 { try {
mContext.startActivityAsUser(intent, UserHandle.CURRENT); 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) { } catch (Exception e) {
Log.e(TAG, "Failed to launch intent", e); Log.e(TAG, "Failed to launch intent", e);
} }
// consume event either way // consume event either way
return true; return true;
}); };
}
} catch (URISyntaxException e) {
throw new RuntimeException("Failed to attach long press intent", e);
}
} }
/** /**