ConfirmInfoBar.java revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.chrome.browser.infobar; 6 7import android.content.Context; 8 9/** 10 * An infobar that presents the user with 2 buttons (typically OK, Cancel). 11 */ 12public class ConfirmInfoBar extends TwoButtonInfoBar { 13 // Message to prompt the user. 14 private final String mMessage; 15 16 // Typically set to "OK", or some other positive action. 17 private final String mPrimaryButtonText; 18 19 // Typically set to "Cancel", or some other negative action. 20 private final String mSecondaryButtonText; 21 22 // Listens for when either of the buttons is clicked. 23 private final InfoBarListeners.Confirm mConfirmListener; 24 25 public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int backgroundType, 26 int iconDrawableId, String message, String primaryButtonText, 27 String secondaryButtonText) { 28 this(0, confirmListener, backgroundType, iconDrawableId, message, primaryButtonText, 29 secondaryButtonText); 30 } 31 32 public ConfirmInfoBar(int nativeInfoBar, InfoBarListeners.Confirm confirmListener, 33 int backgroundType, int iconDrawableId, String message, String primaryButtonText, 34 String secondaryButtonText) { 35 super(confirmListener, backgroundType, iconDrawableId); 36 mMessage = message; 37 mPrimaryButtonText = primaryButtonText; 38 mSecondaryButtonText = secondaryButtonText; 39 mConfirmListener = confirmListener; 40 setNativeInfoBar(nativeInfoBar); 41 } 42 43 @Override 44 public CharSequence getMessageText(Context context) { 45 return mMessage; 46 } 47 48 @Override 49 public String getPrimaryButtonText(Context context) { 50 return mPrimaryButtonText; 51 } 52 53 @Override 54 public String getSecondaryButtonText(Context context) { 55 return mSecondaryButtonText; 56 } 57 58 @Override 59 public void onButtonClicked(boolean isPrimaryButton) { 60 if (mConfirmListener != null) { 61 mConfirmListener.onConfirmInfoBarButtonClicked(this, isPrimaryButton); 62 } 63 64 if (mNativeInfoBarPtr != 0) { 65 int action = isPrimaryButton ? InfoBar.ACTION_TYPE_OK : InfoBar.ACTION_TYPE_CANCEL; 66 nativeOnButtonClicked(mNativeInfoBarPtr, action, ""); 67 } 68 } 69 70 @Override 71 public void onCloseButtonClicked() { 72 if (mNativeInfoBarPtr != 0) { 73 nativeOnCloseButtonClicked(mNativeInfoBarPtr); 74 } 75 super.onCloseButtonClicked(); 76 } 77} 78