Commit b6d04acd authored by newt@chromium.org's avatar newt@chromium.org

Visual makeover for infobars.

NOTRY=true
BUG=375379

Review URL: https://codereview.chromium.org/378043002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282206 0039d316-1c4b-4281-b951-d872f2087c98
parent 749cbc62
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
......@@ -9,7 +8,16 @@
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@drawable/infobar_button_normal_floating_enabled" />
<item
android:drawable="@drawable/infobar_button_normal_floating_pressed" />
android:state_selected="false">
<shape>
<solid android:color="@color/infobar_accent_blue" />
<corners android:radius="1dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/infobar_accent_blue_pressed" />
<corners android:radius="1dp" />
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@drawable/infobar_button_normal_full_left_enabled" />
<item
android:drawable="@drawable/infobar_button_normal_full_left_pressed" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@drawable/infobar_button_normal_full_right_enabled" />
<item
android:drawable="@drawable/infobar_button_normal_full_right_pressed" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@android:color/transparent" />
<item
android:state_pressed="false"
android:state_focused="true"
android:drawable="@drawable/infobar_close_button_focused" />
<item
android:drawable="@drawable/infobar_close_button_pressed" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp" />
<solid android:color="@color/button_focused" />
<stroke
android:width="1px"
android:color="#80000000" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp" />
<solid android:color="@color/button_pressed" />
</shape>
......@@ -7,16 +7,13 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="60dp"
android:minHeight="@dimen/infobar_touch_target_height"
android:background="?android:attr/selectableItemBackground"
android:fontFamily="sans-serif-medium"
android:minWidth="88dp"
android:minHeight="36dp"
android:textSize="@dimen/infobar_button_text_size"
android:textColor="@drawable/infobar_button_text"
android:shadowColor="#FFF"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:background="@drawable/infobar_button_normal_floating"
android:paddingStart="@dimen/infobar_button_horizontal_padding"
android:paddingEnd="@dimen/infobar_button_horizontal_padding"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
android:paddingBottom="5dp"
android:textAllCaps="true" />
......@@ -11,6 +11,7 @@
android:layout_marginBottom="@dimen/infobar_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.25"
android:textDirection="locale"
android:textSize="@dimen/infobar_text_size"
android:textColor="@color/infobar_text" />
......@@ -5,9 +5,13 @@
-->
<resources>
<!-- Infobar colors -->
<color name="infobar_text">#333</color>
<color name="infobar_background">#fff</color>
<color name="infobar_background_separator">#afafaf</color>
<color name="infobar_accent_blue">#4285f4</color>
<color name="infobar_accent_blue_pressed">#679df6</color>
<color name="infobar_tertiary_button_text">#969696</color>
<!-- Tab Switcher Colors -->
<color name="tab_switcher_background">#111111</color>
......@@ -20,10 +24,6 @@
<color name="accessibility_tab_switcher_list_item">#252525</color>
<color name="accessibility_close_undo_text">#33b5e5</color>
<!-- Button Colors -->
<color name="button_pressed">#ff77c5e1</color>
<color name="button_focused">#ffa9d0df</color>
<!-- App banner colors -->
<color name="app_banner_install_button_fg">#ffffff</color>
<color name="app_banner_open_button_fg">#777777</color>
......
......@@ -31,16 +31,16 @@
<!-- Text size of the infobar message. -->
<dimen name="infobar_text_size">16sp</dimen>
<!-- Text size of text inside infobar buttons. -->
<dimen name="infobar_button_text_size">16sp</dimen>
<!-- Minimum dimension (height or width) of the upper row of an infobar. -->
<dimen name="infobar_min_size">60dp</dimen>
<dimen name="infobar_button_text_size">12sp</dimen>
<!-- Minimum width of an infobar. -->
<dimen name="infobar_min_width">220dp</dimen>
<!-- Margin between items in an infobar. -->
<dimen name="infobar_margin">10dp</dimen>
<dimen name="infobar_margin">16dp</dimen>
<!-- Left/right padding for infobar button text. -->
<dimen name="infobar_button_horizontal_padding">30dp</dimen>
<dimen name="infobar_button_horizontal_padding">20dp</dimen>
<!-- Minimum height for a touch target. -->
<dimen name="infobar_touch_target_height">40dp</dimen>
<!-- Height and width of the infobar icon. -->
<!-- Width and height of the infobar icon. -->
<dimen name="infobar_icon_size">36dp</dimen>
<!-- App banner dimensions -->
......
......@@ -9,5 +9,6 @@
<item type="id" name="infobar_close_button" />
<item type="id" name="button_primary" />
<item type="id" name="button_secondary" />
<item type="id" name="button_tertiary" />
<item type="id" name="infobar_extra_check" />
</resources>
......@@ -236,8 +236,7 @@ public class AnimationHelper implements ViewTreeObserver.OnGlobalLayoutListener
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && mToShow != null &&
(mAnimationType == ANIMATION_TYPE_SHOW ||
mAnimationType == ANIMATION_TYPE_SWAP)) {
mToShow.announceForAccessibility(
mInfoBar.getMessageText(mContainer.getContext()));
mToShow.announceForAccessibility(mInfoBar.getMessage());
}
}
});
......
......@@ -4,92 +4,38 @@
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;
/**
* An infobar that presents the user with 2 buttons (typically OK, Cancel).
* An infobar that presents the user with several buttons.
*
* TODO(newt): merge this into InfoBar.java.
*/
public class ConfirmInfoBar extends TwoButtonInfoBar {
// Message to prompt the user.
private final String mMessage;
// Link text shown to the user, in addition to the message.
private final String mLinkText;
// Typically set to "OK", or some other positive action.
public class ConfirmInfoBar extends InfoBar {
/** Text shown on the primary button, e.g. "OK". */
private final String mPrimaryButtonText;
// Typically set to "Cancel", or some other negative action.
/** Text shown on the secondary button, e.g. "Cancel".*/
private final String mSecondaryButtonText;
// Listens for when either of the buttons is clicked.
private final InfoBarListeners.Confirm mConfirmListener;
public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int backgroundType,
int iconDrawableId, String message, String primaryButtonText,
String secondaryButtonText) {
this(confirmListener, iconDrawableId, message, primaryButtonText, secondaryButtonText);
}
/** Text shown on the extra button, e.g. "More info". */
private final String mTertiaryButtonText;
public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int iconDrawableId,
String message, String primaryButtonText, String secondaryButtonText) {
this(confirmListener, iconDrawableId, message, null, primaryButtonText,
secondaryButtonText);
}
public ConfirmInfoBar(InfoBarListeners.Confirm confirmListener, int iconDrawableId,
String message, String linkText, String primaryButtonText, String secondaryButtonText) {
this(0, confirmListener, iconDrawableId, message, linkText, primaryButtonText,
secondaryButtonText);
}
/** Notified when one of the buttons is clicked. */
private final InfoBarListeners.Confirm mConfirmListener;
public ConfirmInfoBar(long nativeInfoBar, InfoBarListeners.Confirm confirmListener,
int iconDrawableId, String message, String linkText, String primaryButtonText,
String secondaryButtonText) {
super(confirmListener, iconDrawableId);
mMessage = message;
mLinkText = linkText;
super(confirmListener, iconDrawableId, message);
mPrimaryButtonText = primaryButtonText;
mSecondaryButtonText = secondaryButtonText;
mTertiaryButtonText = linkText;
mConfirmListener = confirmListener;
setNativeInfoBar(nativeInfoBar);
}
@Override
public CharSequence getMessageText(Context context) {
// Construct text to be displayed on the infobar.
SpannableStringBuilder infobarMessage = new SpannableStringBuilder(mMessage);
// If we have a link text to display, append it.
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;
public void createContent(InfoBarLayout layout) {
layout.setButtons(mPrimaryButtonText, mSecondaryButtonText, mTertiaryButtonText);
}
@Override
......
......@@ -36,11 +36,8 @@ public abstract class InfoBar implements InfoBarView {
public static final int ACTION_TYPE_TRANSLATE = 3;
public static final int ACTION_TYPE_TRANSLATE_SHOW_ORIGINAL = 4;
// Background types
public static final int BACKGROUND_TYPE_INFO = 0;
public static final int BACKGROUND_TYPE_WARNING = 1;
private final int mIconDrawableId;
private final CharSequence mMessage;
private InfoBarListeners.Dismiss mListener;
private ContentWrapperView mContentView;
......@@ -66,14 +63,23 @@ public abstract class InfoBar implements InfoBarView {
/**
* @param listener Listens to when buttons have been clicked on the InfoBar.
* @param iconDrawableId ID of the resource to use for the Icon. If 0, no icon will be shown.
* @param message The message to show in the infobar.
*/
public InfoBar(InfoBarListeners.Dismiss listener, int iconDrawableId) {
public InfoBar(InfoBarListeners.Dismiss listener, int iconDrawableId, CharSequence message) {
mListener = listener;
mId = generateId();
mIconDrawableId = iconDrawableId;
mMessage = message;
mExpireOnNavigation = true;
}
/**
* @return The message shown in the infobar, useful for accessibility.
*/
public CharSequence getMessage() {
return mMessage;
}
/**
* Stores a pointer to the native-side counterpart of this InfoBar.
* @param nativeInfoBarPtr Pointer to the NativeInfoBar.
......@@ -96,13 +102,13 @@ public abstract class InfoBar implements InfoBarView {
}
/**
* Determine if the infobar should be dismissed when |url| is loaded. Calling
* Determine if the infobar should be dismissed when a new page starts loading. Calling
* setExpireOnNavigation(true/false) causes this method always to return true/false.
* This only applies to java-only infobars. C++ infobars will use the same logic
* as other platforms so they are not attempted to be dismissed twice.
* It should really be removed once all infobars have a C++ counterpart.
*/
public final boolean shouldExpire(String url) {
public final boolean shouldExpire() {
return mExpireOnNavigation && mNativeInfoBarPtr == 0;
}
......@@ -146,7 +152,10 @@ public abstract class InfoBar implements InfoBarView {
*/
protected final View createView() {
assert mContext != null;
return new InfoBarLayout(mContext, this, mIconDrawableId);
InfoBarLayout layout = new InfoBarLayout(mContext, this, mIconDrawableId, mMessage);
createContent(layout);
return layout;
}
/**
......@@ -207,10 +216,16 @@ public abstract class InfoBar implements InfoBarView {
public void setControlsEnabled(boolean state) {
mControlsEnabled = state;
// Handle the close button.
// Disable all buttons on the infobar.
if (mContentView != null) {
View closeButton = mContentView.findViewById(R.id.infobar_close_button);
View primaryButton = mContentView.findViewById(R.id.button_primary);
View secondaryButton = mContentView.findViewById(R.id.button_secondary);
View tertiaryButton = mContentView.findViewById(R.id.button_tertiary);
if (closeButton != null) closeButton.setEnabled(state);
if (primaryButton != null) primaryButton.setEnabled(state);
if (secondaryButton != null) secondaryButton.setEnabled(state);
if (tertiaryButton != null) tertiaryButton.setEnabled(state);
}
}
......@@ -227,16 +242,6 @@ public abstract class InfoBar implements InfoBarView {
public void createContent(InfoBarLayout layout) {
}
@Override
public String getPrimaryButtonText(Context context) {
return null;
}
@Override
public String getSecondaryButtonText(Context context) {
return null;
}
/**
* Returns the id of the tab this infobar is showing into.
*/
......
......@@ -369,11 +369,11 @@ public class InfoBarContainer extends LinearLayout {
}
// Called by the tab when it has started loading a new page.
public void onPageStarted(String url) {
public void onPageStarted() {
LinkedList<InfoBar> barsToRemove = new LinkedList<InfoBar>();
for (InfoBar infoBar : mInfoBars) {
if (infoBar.shouldExpire(url)) {
if (infoBar.shouldExpire()) {
barsToRemove.add(infoBar);
}
}
......
......@@ -4,52 +4,24 @@
package org.chromium.chrome.browser.infobar;
import android.content.Context;
/**
* Functions needed to display an InfoBar UI.
*/
public interface InfoBarView {
/**
* Prepare the InfoBar for display and adding InfoBar-specific controls to the layout.
* Prepares the InfoBar for display and adds InfoBar-specific controls to the layout.
* @param layout Layout containing all of the controls.
*/
public void createContent(InfoBarLayout layout);
/**
* Returns the message indicating what the InfoBar is informing or asking the user about.
* @param context Context to pull the string from.
* @return The string to display.
*/
public CharSequence getMessageText(Context context);
/**
* Returns text to display on the primary button indicating that some action will be taken.
* Setting this to null prevents the button from being created.
* @param context Context to pull the string from.
* @return The string to display.
*/
public String getPrimaryButtonText(Context context);
/**
* Returns text to display on the secondary button, typically indicating that some action will
* not be taken.
*
* Example text includes "Cancel" or "Nope". Setting this to null prevents the button from
* being created. It is illegal to have a secondary button without a primary button.
*
* @param context Context to pull the string from.
* @return The string to display.
*/
public String getSecondaryButtonText(Context context);
/**
* Take some action related to the link being clicked.
* Takes some action related to the link being clicked.
*/
public void onLinkClicked();
/**
* Take some action related to the close button being clicked.
* Takes some action related to the close button being clicked.
*/
public void onCloseButtonClicked();
......
......@@ -4,71 +4,33 @@
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import org.chromium.chrome.R;
/**
* A simple infobar that contains a message and a close icon on the right side.
* This is used only in the context of Java code and is not associated with any native
* InfoBarDelegate.
*
* TODO(newt): merge this into InfoBar.java
*/
public class MessageInfoBar extends InfoBar {
private final CharSequence mTitle;
/**
* Creates and returns an infobar with a white background and a close button on the right.
* @param title the text displayed in the infobar
* @return the infobar.
*/
public static MessageInfoBar createInfoBar(CharSequence title) {
return new MessageInfoBar(null, 0, title);
}
/**
* Creates and returns an infobar with a white background and a close button on the right.
* @param iconResourceId the icon shown on the right
* @param title the text displayed in the infobar
* @return the infobar.
*/
public static MessageInfoBar createInfoBar(int iconResourceId, CharSequence title) {
return new MessageInfoBar(null, iconResourceId, title);
}
/**
* Creates a warning infobar, with a yellow background and a warning icon on the right.
* Creates an infobar with a message and a close button.
* @param title the text displayed in the infobar
* @return the infobar.
*/
public static MessageInfoBar createWarningInfoBar(CharSequence title) {
return createWarningInfoBar(null, title);
public MessageInfoBar(CharSequence title) {
this(null, 0, title);
}
/**
* Creates a warning infobar, with a yellow background and a warning icon on the right.
* @param listener an infobar dismissed listener
* @param title the text displayed in the infobar
* @return the infobar.
* Creates an infobar with an icon, a message and a close button.
* @param listener A listener to be notified when the infobar is dismissed, or null.
* @param iconResourceId The icon to display in the infobar, or 0 if no icon should be shown.
* @param title The text to display in the infobar.
*/
public static MessageInfoBar createWarningInfoBar(InfoBarListeners.Dismiss listener,
CharSequence title) {
return new MessageInfoBar(listener, R.drawable.infobar_warning, title);
}
protected MessageInfoBar(InfoBarListeners.Dismiss listener, int iconResourceId,
CharSequence title, int backgroundType) {
this(listener, iconResourceId, title);
}
protected MessageInfoBar(InfoBarListeners.Dismiss listener, int iconResourceId,
public MessageInfoBar(InfoBarListeners.Dismiss listener, int iconResourceId,
CharSequence title) {
super(listener, iconResourceId);
mTitle = title;
}
@Override
public CharSequence getMessageText(Context context) {
return mTitle;
super(listener, iconResourceId, title);
}
@Override
......
......@@ -32,7 +32,7 @@ public class SavePasswordInfoBar extends ConfirmInfoBar {
mUseAdditionalAuthenticationCheckbox = new CheckBox(getContext());
mUseAdditionalAuthenticationCheckbox.setText(
PasswordAuthenticationManager.getPasswordProtectionString());
layout.addGroup(mUseAdditionalAuthenticationCheckbox);
layout.setCustomContent(mUseAdditionalAuthenticationCheckbox);
}
super.createContent(layout);
......
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.widget.TextView;
import org.chromium.chrome.R;
......@@ -23,16 +22,15 @@ public class TranslateAlwaysPanel implements TranslateSubPanel {
@Override
public void createContent(Context context, InfoBarLayout layout) {
TextView panelMessage = (TextView) layout.findViewById(R.id.infobar_message);
panelMessage.setText(context.getString(
layout.setMessage(context.getString(
R.string.translate_infobar_translation_done, mOptions.targetLanguage()));
if (!mOptions.triggeredFromMenu()) {
TranslateCheckBox checkBox = new TranslateCheckBox(mOptions, mListener);
checkBox.createContent(context, layout);
TranslateCheckBox checkBox = new TranslateCheckBox(context, mOptions, mListener);
layout.setCustomContent(checkBox);
}
layout.addButtons(context.getString(R.string.translate_button_done),
layout.setButtons(context.getString(R.string.translate_button_done),
context.getString(R.string.translate_show_original));
}
......
......@@ -6,38 +6,35 @@ package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import org.chromium.chrome.R;
/**
* A check box used to determine if a page should always be translated.
*/
public class TranslateCheckBox {
public class TranslateCheckBox extends CheckBox implements OnCheckedChangeListener {
private final SubPanelListener mListener;
private final TranslateOptions mOptions;
public TranslateCheckBox(TranslateOptions options, SubPanelListener listener) {
public TranslateCheckBox(Context context, TranslateOptions options, SubPanelListener listener) {
super(context);
mOptions = options;
mListener = listener;
setId(R.id.infobar_extra_check);
setText(context.getString(R.string.translate_always_text, mOptions.sourceLanguage()));
setChecked(mOptions.alwaysTranslateLanguageState());
setOnCheckedChangeListener(this);
}
public void createContent(Context context, InfoBarLayout layout) {
CheckBox checkBox = new CheckBox(context);
checkBox.setId(R.id.infobar_extra_check);
checkBox.setText(context.getString(R.string.translate_always_text,
mOptions.sourceLanguage()));
checkBox.setChecked(mOptions.alwaysTranslateLanguageState());
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
mOptions.toggleAlwaysTranslateLanguageState(isChecked);
if (isChecked) {
mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE);
} else {
mListener.onOptionsChanged();
}
}
});
layout.addGroup(checkBox);
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
mOptions.toggleAlwaysTranslateLanguageState(isChecked);
if (isChecked) {
mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE);
} else {
mListener.onOptionsChanged();
}
}
}
......@@ -19,7 +19,7 @@ import org.chromium.ui.base.DeviceFormFactor;
/**
* Java version of the translate infobar
*/
public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListener {
public class TranslateInfoBar extends InfoBar implements SubPanelListener {
// Needs to be kept in sync with the Type enum in translate_infobar_delegate.h.
public static final int BEFORE_TRANSLATE_INFOBAR = 0;
public static final int TRANSLATING_INFOBAR = 1;
......@@ -45,8 +45,7 @@ public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListen
int infoBarType, int sourceLanguageIndex, int targetLanguageIndex,
boolean autoTranslatePair, boolean shouldShowNeverBar,
boolean triggeredFromMenu, String[] languages) {
super(null, R.drawable.infobar_translate);
super(null, R.drawable.infobar_translate, null);
mTranslateDelegate = delegate;
mOptions = new TranslateOptions(sourceLanguageIndex, targetLanguageIndex, languages,
autoTranslatePair, triggeredFromMenu);
......@@ -111,8 +110,7 @@ public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListen
return action;
}
@Override
public CharSequence getMessageText(Context context) {
private CharSequence getMessageText(Context context) {
switch (getInfoBarType()) {
case BEFORE_TRANSLATE_INFOBAR:
String template = context.getString(R.string.translate_infobar_text);
......@@ -137,8 +135,7 @@ public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListen
}
}
@Override
public String getPrimaryButtonText(Context context) {
private String getPrimaryButtonText(Context context) {
switch (getInfoBarType()) {
case BEFORE_TRANSLATE_INFOBAR:
return context.getString(R.string.translate_button);
......@@ -154,8 +151,7 @@ public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListen
}
}
@Override
public String getSecondaryButtonText(Context context) {
private String getSecondaryButtonText(Context context) {
switch (getInfoBarType()) {
case BEFORE_TRANSLATE_INFOBAR:
return context.getString(R.string.translate_nope);
......@@ -181,15 +177,17 @@ public class TranslateInfoBar extends TwoButtonInfoBar implements SubPanelListen
return;
}
Context context = layout.getContext();
layout.setMessage(getMessageText(context));
layout.setButtons(getPrimaryButtonText(context), getSecondaryButtonText(context));
if (getInfoBarType() == AFTER_TRANSLATE_INFOBAR &&
!needsAlwaysPanel() &&
!mOptions.triggeredFromMenu()) {
// Long always translate version
TranslateCheckBox checkBox = new TranslateCheckBox(mOptions, this);
checkBox.createContent(getContext(), layout);
TranslateCheckBox checkBox = new TranslateCheckBox(context, mOptions, this);
layout.setCustomContent(checkBox);
}
super.createContent(layout);
}
// SubPanelListener implementation
......
......@@ -70,15 +70,14 @@ public class TranslateLanguagePanel
mTargetSpinner = null;
String changeLanguage = context.getString(R.string.translate_infobar_change_languages);
TextView panelMessage = (TextView) layout.findViewById(R.id.infobar_message);
panelMessage.setText(changeLanguage);
layout.setMessage(changeLanguage);
// Set up the spinners.
createSpinners(context);
layout.addGroup(mSourceSpinner, mTargetSpinner);
layout.setCustomContent(mSourceSpinner, mTargetSpinner);
// Set up the buttons.
layout.addButtons(context.getString(R.string.translate_button_done),
layout.setButtons(context.getString(R.string.translate_button_done),
context.getString(R.string.cancel));
}
......
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.widget.TextView;
import org.chromium.chrome.R;
......@@ -25,11 +24,9 @@ public class TranslateNeverPanel implements TranslateSubPanel {
public void createContent(Context context, InfoBarLayout layout) {
String changeLanguage = context.getString(
R.string.translate_never_translate_message_text, mOptions.sourceLanguage());
layout.setMessage(changeLanguage);
TextView panelMessage = (TextView) layout.findViewById(R.id.infobar_message);
panelMessage.setText(changeLanguage);
layout.addButtons(
layout.setButtons(
context.getString(R.string.translate_never_translate_site),
context.getString(R.string.translate_never_translate_language,
mOptions.sourceLanguage()));
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.widget.Button;
import org.chromium.chrome.R;
/**
* An infobar that presents the user with up to 2 buttons.
*/
public abstract class TwoButtonInfoBar extends InfoBar {
public TwoButtonInfoBar(InfoBarListeners.Dismiss dismissListener, int backgroundType,
int iconDrawableId) {
super(dismissListener, iconDrawableId);
}
public TwoButtonInfoBar(InfoBarListeners.Dismiss dismissListener, int iconDrawableId) {
super(dismissListener, iconDrawableId);
}
/**
* Creates controls for the current InfoBar.
* @param layout InfoBarLayout to find controls in.
*/
@Override
public void createContent(InfoBarLayout layout) {
Context context = layout.getContext();
layout.addButtons(getPrimaryButtonText(context), getSecondaryButtonText(context));
}
@Override
public void setControlsEnabled(boolean state) {
super.setControlsEnabled(state);
// Handle the buttons.
ContentWrapperView wrapper = getContentWrapper(false);
if (wrapper != null) {
Button primary = (Button) wrapper.findViewById(R.id.button_primary);
Button secondary = (Button) wrapper.findViewById(R.id.button_secondary);
if (primary != null) primary.setEnabled(state);
if (secondary != null) secondary.setEnabled(state);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment