Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(966)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java

Issue 378043002: Visual makeover for infobars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't show buttons with empty text Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.content.Context;
8 import android.text.SpannableStringBuilder;
9 import android.text.Spanned;
10 import android.text.TextUtils;
11 import android.text.style.ClickableSpan;
12 import android.view.View;
13
14 /** 7 /**
15 * An infobar that presents the user with 2 buttons (typically OK, Cancel). 8 * An infobar that presents the user with several buttons.
9 *
10 * TODO(newt): merge this into InfoBar.java.
16 */ 11 */
17 public class ConfirmInfoBar extends TwoButtonInfoBar { 12 public class ConfirmInfoBar extends InfoBar {
18 // Message to prompt the user. 13 /** Text shown on the primary button, e.g. "OK". */
19 private final String mMessage;
20
21 // Link text shown to the user, in addition to the message.
22 private final String mLinkText;
23
24 // Typically set to "OK", or some other positive action.
25 private final String mPrimaryButtonText; 14 private final String mPrimaryButtonText;
26 15
27 // Typically set to "Cancel", or some other negative action. 16 /** Text shown on the secondary button, e.g. "Cancel".*/
28 private final String mSecondaryButtonText; 17 private final String mSecondaryButtonText;
29 18
30 // Listens for when either of the buttons is clicked. 19 /** Text shown on the extra button, e.g. "More info". */
20 private final String mTertiaryButtonText;
21
22 /** Notified when one of the buttons is clicked. */
31 private final InfoBarListeners.Confirm mConfirmListener; 23 private final InfoBarListeners.Confirm mConfirmListener;
32 24
33 public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int backgrou ndType,
34 int iconDrawableId, String message, String primaryButtonText,
35 String secondaryButtonText) {
36 this(confirmListener, iconDrawableId, message, primaryButtonText, second aryButtonText);
37 }
38
39 public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int iconDraw ableId,
40 String message, String primaryButtonText, String secondaryButtonText ) {
41 this(confirmListener, iconDrawableId, message, null, primaryButtonText,
42 secondaryButtonText);
43 }
44
45 public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int iconDraw ableId,
46 String message, String linkText, String primaryButtonText, String se condaryButtonText) {
47 this(0, confirmListener, iconDrawableId, message, linkText, primaryButto nText,
48 secondaryButtonText);
49 }
50
51 public ConfirmInfoBar(long nativeInfoBar, InfoBarListeners.Confirm confirmLi stener, 25 public ConfirmInfoBar(long nativeInfoBar, InfoBarListeners.Confirm confirmLi stener,
52 int iconDrawableId, String message, String linkText, String primaryB uttonText, 26 int iconDrawableId, String message, String linkText, String primaryB uttonText,
53 String secondaryButtonText) { 27 String secondaryButtonText) {
54 super(confirmListener, iconDrawableId); 28 super(confirmListener, iconDrawableId, message);
55 mMessage = message;
56 mLinkText = linkText;
57 mPrimaryButtonText = primaryButtonText; 29 mPrimaryButtonText = primaryButtonText;
58 mSecondaryButtonText = secondaryButtonText; 30 mSecondaryButtonText = secondaryButtonText;
31 mTertiaryButtonText = linkText;
59 mConfirmListener = confirmListener; 32 mConfirmListener = confirmListener;
60 setNativeInfoBar(nativeInfoBar); 33 setNativeInfoBar(nativeInfoBar);
61 } 34 }
62 35
63 @Override 36 @Override
64 public CharSequence getMessageText(Context context) { 37 public void createContent(InfoBarLayout layout) {
65 // Construct text to be displayed on the infobar. 38 layout.setButtons(mPrimaryButtonText, mSecondaryButtonText, mTertiaryBut tonText);
66 SpannableStringBuilder infobarMessage = new SpannableStringBuilder(mMess age);
67
68 // If we have a link text to display, append it.
69 if (!TextUtils.isEmpty(mLinkText)) {
70 SpannableStringBuilder spannableLinkText = new SpannableStringBuilde r(mLinkText);
71 ClickableSpan onLinkClicked = new ClickableSpan() {
72 @Override
73 public void onClick(View view) {
74 onLinkClicked();
75 }
76 };
77 spannableLinkText.setSpan(onLinkClicked, 0, spannableLinkText.length (),
78 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
79 infobarMessage.append(" ");
80 infobarMessage.append(spannableLinkText);
81 }
82 return infobarMessage;
83 } 39 }
84 40
85 @Override 41 @Override
86 public String getPrimaryButtonText(Context context) {
87 return mPrimaryButtonText;
88 }
89
90 @Override
91 public String getSecondaryButtonText(Context context) {
92 return mSecondaryButtonText;
93 }
94
95 @Override
96 public void onButtonClicked(boolean isPrimaryButton) { 42 public void onButtonClicked(boolean isPrimaryButton) {
97 if (mConfirmListener != null) { 43 if (mConfirmListener != null) {
98 mConfirmListener.onConfirmInfoBarButtonClicked(this, isPrimaryButton ); 44 mConfirmListener.onConfirmInfoBarButtonClicked(this, isPrimaryButton );
99 } 45 }
100 46
101 if (mNativeInfoBarPtr != 0) { 47 if (mNativeInfoBarPtr != 0) {
102 int action = isPrimaryButton ? InfoBar.ACTION_TYPE_OK : InfoBar.ACTI ON_TYPE_CANCEL; 48 int action = isPrimaryButton ? InfoBar.ACTION_TYPE_OK : InfoBar.ACTI ON_TYPE_CANCEL;
103 nativeOnButtonClicked(mNativeInfoBarPtr, action, ""); 49 nativeOnButtonClicked(mNativeInfoBarPtr, action, "");
104 } 50 }
105 } 51 }
106 52
107 @Override 53 @Override
108 public void onCloseButtonClicked() { 54 public void onCloseButtonClicked() {
109 if (mNativeInfoBarPtr != 0) { 55 if (mNativeInfoBarPtr != 0) {
110 nativeOnCloseButtonClicked(mNativeInfoBarPtr); 56 nativeOnCloseButtonClicked(mNativeInfoBarPtr);
111 } else { 57 } else {
112 super.dismissJavaOnlyInfoBar(); 58 super.dismissJavaOnlyInfoBar();
113 } 59 }
114 } 60 }
115 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698