20c3aeaf0f6c0e7652e229ae0ded6ec53e95e259
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / infobar / MessageInfoBar.java
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
5 package org.chromium.chrome.browser.infobar;
6
7 import android.content.Context;
8
9 import org.chromium.chrome.R;
10
11 /**
12  * A simple infobar that contains a message and a close icon on the right side.
13  * This is used only in the context of Java code and is not associated with any native
14  * InfoBarDelegate.
15  */
16 public class MessageInfoBar extends InfoBar {
17     private final CharSequence mTitle;
18
19     /**
20      * Creates and returns an infobar with a white background and a close button on the right.
21      * @param title the text displayed in the infobar
22      * @return the infobar.
23      */
24     public static MessageInfoBar createInfoBar(CharSequence title) {
25         return new MessageInfoBar(null, 0, title, BACKGROUND_TYPE_INFO);
26     }
27
28     /**
29      * Creates and returns an infobar with a white background and a close button on the right.
30      * @param iconResourceId the icon shown on the right
31      * @param title the text displayed in the infobar
32      * @return the infobar.
33      */
34     public static MessageInfoBar createInfoBar(int iconResourceId, CharSequence title) {
35         return new MessageInfoBar(null, iconResourceId, title, BACKGROUND_TYPE_INFO);
36     }
37
38     /**
39      * Creates a warning infobar, with a yellow background and a warning icon on the right.
40      * @param title the text displayed in the infobar
41      * @return the infobar.
42      */
43     public static MessageInfoBar createWarningInfoBar(CharSequence title) {
44         return createWarningInfoBar(null, title);
45     }
46
47     /**
48      * Creates a warning infobar, with a yellow background and a warning icon on the right.
49      * @param listener an infobar dismissed listener
50      * @param title the text displayed in the infobar
51      * @return the infobar.
52      */
53     public static MessageInfoBar createWarningInfoBar(InfoBarListeners.Dismiss listener,
54             CharSequence title) {
55         return new MessageInfoBar(listener, R.drawable.warning, title, BACKGROUND_TYPE_WARNING);
56     }
57
58     protected MessageInfoBar(InfoBarListeners.Dismiss listener, int iconResourceId,
59             CharSequence title, int backgroundType) {
60         super(listener, backgroundType, iconResourceId);
61         mTitle = title;
62     }
63
64     @Override
65     public CharSequence getMessageText(Context context) {
66         return mTitle;
67     }
68
69     @Override
70     public void onCloseButtonClicked() {
71         super.dismissJavaOnlyInfoBar();
72     }
73 }