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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java

Issue 871103004: Allow installing apps via the AppBannerInfoBar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pointers
Patch Set: Fix compile Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
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 5600d68c7f70ce1d373c4f9c1585a389bed3d84c..123b6aa07628693e593e3a1607f002e4c4b7331b 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,14 @@ public class AppBannerInfoBar extends ConfirmInfoBar {
super.createContent(layout);
+ mButton = (Button) layout.findViewById(R.id.button_primary);
+ mTitleView = layout.findViewById(R.id.infobar_message);
+
+ // TODO(dfalcantara): Grab the icon from the layout.
+ // mIconView = layout.findViewById(R.id.infobar_icon);
+
+ assert mButton != null && mTitleView != null;
+
// Set up accessibility text.
Context context = getContext();
if (mAppData != null) {
@@ -62,6 +85,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();
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698