DO NOT MERGE Make nav bar button click listeners overrideable am: 9203e45a01
Change-Id: I7e772521dc196880367a56c35a3f411e522a4440
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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,21 +99,41 @@ 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));
|
||||||
try {
|
|
||||||
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "Failed to launch intent", e);
|
|
||||||
}
|
|
||||||
// consume event either way
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new RuntimeException("Failed to attach long press intent", 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
|
* @param selected true if should indicate if this is a selected state, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user