This source file includes following definitions.
- getMessageText
- getPrimaryButtonText
- getSecondaryButtonText
- onButtonClicked
- onCloseButtonClicked
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.view.View;
public class ConfirmInfoBar extends TwoButtonInfoBar {
private final String mMessage;
private final String mLinkText;
private final String mPrimaryButtonText;
private final String mSecondaryButtonText;
private final InfoBarListeners.Confirm mConfirmListener;
public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int backgroundType,
int iconDrawableId, String message, String primaryButtonText,
String secondaryButtonText) {
this(confirmListener, backgroundType, iconDrawableId, message, null, primaryButtonText,
secondaryButtonText);
}
public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int backgroundType,
int iconDrawableId, String message, String linkText, String primaryButtonText,
String secondaryButtonText) {
this(0, confirmListener, backgroundType, iconDrawableId, message, linkText,
primaryButtonText, secondaryButtonText);
}
public ConfirmInfoBar(long nativeInfoBar, InfoBarListeners.Confirm confirmListener,
int backgroundType, int iconDrawableId, String message, String linkText,
String primaryButtonText, String secondaryButtonText) {
super(confirmListener, backgroundType, iconDrawableId);
mMessage = message;
mLinkText = linkText;
mPrimaryButtonText = primaryButtonText;
mSecondaryButtonText = secondaryButtonText;
mConfirmListener = confirmListener;
setNativeInfoBar(nativeInfoBar);
}
@Override
public CharSequence getMessageText(Context context) {
SpannableStringBuilder infobarMessage = new SpannableStringBuilder(mMessage);
if (!TextUtils.isEmpty(mLinkText)) {
SpannableStringBuilder spannableLinkText = new SpannableStringBuilder(mLinkText);
ClickableSpan onLinkClicked = new ClickableSpan() {
@Override
public void onClick(View view) {
onLinkClicked();
}
};
spannableLinkText.setSpan(onLinkClicked, 0, spannableLinkText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
infobarMessage.append(" ");
infobarMessage.append(spannableLinkText);
}
return infobarMessage;
}
@Override
public String getPrimaryButtonText(Context context) {
return mPrimaryButtonText;
}
@Override
public String getSecondaryButtonText(Context context) {
return mSecondaryButtonText;
}
@Override
public void onButtonClicked(boolean isPrimaryButton) {
if (mConfirmListener != null) {
mConfirmListener.onConfirmInfoBarButtonClicked(this, isPrimaryButton);
}
if (mNativeInfoBarPtr != 0) {
int action = isPrimaryButton ? InfoBar.ACTION_TYPE_OK : InfoBar.ACTION_TYPE_CANCEL;
nativeOnButtonClicked(mNativeInfoBarPtr, action, "");
}
}
@Override
public void onCloseButtonClicked() {
if (mNativeInfoBarPtr != 0) {
nativeOnCloseButtonClicked(mNativeInfoBarPtr);
} else {
super.dismissJavaOnlyInfoBar();
}
}
}