Commit f39b225b authored by googleo's avatar googleo Committed by Commit bot

Show translate error message with toast when translation failed.

And reset selection to original language.

BUG=703887

Review-Url: https://codereview.chromium.org/2842113002
Cr-Commit-Position: refs/heads/master@{#467587}
parent 6c647b60
...@@ -15,6 +15,7 @@ import org.chromium.chrome.R; ...@@ -15,6 +15,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.translate.TranslateMenu; import org.chromium.chrome.browser.infobar.translate.TranslateMenu;
import org.chromium.chrome.browser.infobar.translate.TranslateMenuHelper; import org.chromium.chrome.browser.infobar.translate.TranslateMenuHelper;
import org.chromium.chrome.browser.infobar.translate.TranslateTabLayout; import org.chromium.chrome.browser.infobar.translate.TranslateTabLayout;
import org.chromium.ui.widget.Toast;
/** /**
* Java version of the compcat translate infobar * Java version of the compcat translate infobar
...@@ -92,11 +93,15 @@ class TranslateCompactInfoBar extends InfoBar ...@@ -92,11 +93,15 @@ class TranslateCompactInfoBar extends InfoBar
@CalledByNative @CalledByNative
private void onPageTranslated(int errorType) { private void onPageTranslated(int errorType) {
if (mTabLayout != null) { if (mTabLayout != null) {
// Success mTabLayout.hideProgressBar();
if (errorType == 0) { if (errorType != 0) {
mTabLayout.hideProgressBar(); Toast.makeText(getContext(), R.string.translate_infobar_error, Toast.LENGTH_SHORT)
} else { .show();
mTabLayout.stopProgressBarAndRevertBack(); // Disable OnTabSelectedListener then revert selection.
mTabLayout.removeOnTabSelectedListener(this);
mTabLayout.getTabAt(SOURCE_TAB_INDEX).select();
// Add OnTabSelectedListener back.
mTabLayout.addOnTabSelectedListener(this);
} }
} }
} }
......
...@@ -70,17 +70,6 @@ public class TranslateTabLayout extends TabLayout { ...@@ -70,17 +70,6 @@ public class TranslateTabLayout extends TabLayout {
tab.setContentDescription(tabTitle); tab.setContentDescription(tabTitle);
} }
/**
* Select a tab.
* @param tabPos The position of the tab to select.
*/
public void selectTab(int tabPos) {
if (tabPos < 0 || tabPos >= getTabCount() || mTabShowingProgressBar != null) {
return;
}
getTabAt(tabPos).select();
}
/** /**
* Show the spinning progress bar on a specified tab. * Show the spinning progress bar on a specified tab.
* @param tabPos The position of the tab to show the progress bar. * @param tabPos The position of the tab to show the progress bar.
...@@ -111,24 +100,6 @@ public class TranslateTabLayout extends TabLayout { ...@@ -111,24 +100,6 @@ public class TranslateTabLayout extends TabLayout {
mTabShowingProgressBar = null; mTabShowingProgressBar = null;
} }
/** Stop the spinning progress bar. */
public void stopProgressBarAndRevertBack() {
if (mTabShowingProgressBar == null) {
return;
}
// TODO(martiw) if we have setContentDescription at showProgressBarOnTab(), we need to
// revert it here.
if (tabIsSupported(mTabShowingProgressBar)) {
((TranslateTabContent) mTabShowingProgressBar.getCustomView()).hideProgressBar();
}
// TODO(martiw) See if we need to prevent the following from triggering onTabSelected event.
selectTab(0); // switch the selection back to the first tab.
mTabShowingProgressBar = null;
}
// Overrided to block children's touch event when showing progress bar. // Overrided to block children's touch event when showing progress bar.
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
......
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