Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java |
| index c47a8f0dfe5fd75439f21d8ff0c0f13468964457..7b2047310b6cd75080fdf5c6616d8508baca7222 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java |
| @@ -6,6 +6,8 @@ package org.chromium.chrome.browser.infobar; |
| import android.content.Context; |
| import android.graphics.Bitmap; |
| +import android.view.View; |
| +import android.widget.Button; |
| import android.widget.TextView; |
| import org.chromium.base.ApplicationStatus; |
| @@ -16,11 +18,22 @@ import org.chromium.chrome.browser.banners.AppData; |
| /** |
| * Infobar informing the user about an app related to this page. |
| */ |
| -public class AppBannerInfoBar extends ConfirmInfoBar { |
| +public class AppBannerInfoBar extends ConfirmInfoBar implements View.OnClickListener { |
| + // Installation states. |
| + public static final int INSTALL_STATE_NOT_INSTALLED = 0; |
| + public static final int INSTALL_STATE_INSTALLING = 1; |
| + public static final int INSTALL_STATE_INSTALLED = 2; |
| + |
| + // Views composing the infobar. |
| + private Button mButton; |
| + private View mTitleView; |
| + private View mIconView; |
| + |
| private final String mAppTitle; |
| // Data for native app installs. |
| private final AppData mAppData; |
| + private int mInstallState; |
| // Data for web app installs. |
| private final String mAppUrl; |
| @@ -31,6 +44,7 @@ public class AppBannerInfoBar extends ConfirmInfoBar { |
| mAppTitle = appTitle; |
| mAppData = data; |
| mAppUrl = null; |
| + mInstallState = INSTALL_STATE_NOT_INSTALLED; |
| } |
| // Banner for web apps. |
| @@ -39,6 +53,7 @@ public class AppBannerInfoBar extends ConfirmInfoBar { |
| mAppTitle = appTitle; |
| mAppData = null; |
| mAppUrl = url; |
| + mInstallState = INSTALL_STATE_NOT_INSTALLED; |
| } |
| @Override |
| @@ -51,6 +66,11 @@ public class AppBannerInfoBar extends ConfirmInfoBar { |
| super.createContent(layout); |
| + mButton = (Button) layout.findViewById(R.id.button_primary); |
| + mTitleView = layout.findViewById(R.id.infobar_message); |
| + mIconView = layout.findViewById(R.id.infobar_icon); |
| + assert mButton != null && mTitleView != null; |
| + |
| // Set up accessibility text. |
| Context context = getContext(); |
| if (mAppData != null) { |
| @@ -62,6 +82,52 @@ public class AppBannerInfoBar extends ConfirmInfoBar { |
| R.string.app_banner_view_web_app_accessibility, mAppTitle, |
| mAppUrl)); |
| } |
| + |
| + // Set up clicking on the controls to bring up the app details. |
| + mTitleView.setOnClickListener(this); |
| + if (mIconView != null) mIconView.setOnClickListener(this); |
| + } |
| + |
| + @Override |
| + public void onButtonClicked(boolean isPrimaryButton) { |
| + if (mInstallState == INSTALL_STATE_INSTALLING) { |
| + setControlsEnabled(true); |
| + updateButton(); |
|
newt (away)
2015/02/06 22:46:27
why call updateButton() here?
gone
2015/02/06 22:55:01
Needed to re-disable the "installing" button after
|
| + return; |
| + } |
| + super.onButtonClicked(isPrimaryButton); |
| + } |
| + |
| + @CalledByNative |
| + public void onInstallStateChanged(int newState) { |
| + setControlsEnabled(true); |
| + mInstallState = newState; |
| + updateButton(); |
| + } |
| + |
| + private void updateButton() { |
| + String text; |
| + String accessibilityText = null; |
| + boolean enabled = true; |
| + if (mInstallState == INSTALL_STATE_NOT_INSTALLED) { |
| + text = mAppData.installButtonText(); |
| + accessibilityText = |
| + getContext().getString(R.string.app_banner_install_accessibility, text); |
| + } else if (mInstallState == INSTALL_STATE_INSTALLING) { |
| + text = getContext().getString(R.string.app_banner_installing); |
| + enabled = false; |
| + } else { |
| + text = getContext().getString(R.string.app_banner_open); |
| + } |
| + |
| + mButton.setText(text); |
| + mButton.setContentDescription(accessibilityText); |
| + mButton.setEnabled(enabled); |
| + } |
| + |
| + @Override |
| + public void onClick(View v) { |
| + if (v == mTitleView || v == mIconView) onLinkClicked(); |
| } |
| private static String getAddToHomescreenText() { |