OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.support.v4.view.ViewCompat; | 9 import android.support.v4.view.ViewCompat; |
10 import android.view.View; | 10 import android.view.View; |
11 import android.widget.Button; | 11 import android.widget.Button; |
12 import android.widget.ImageView; | 12 import android.widget.ImageView; |
13 | 13 |
14 import org.chromium.base.ApiCompatibilityUtils; | 14 import org.chromium.base.ApiCompatibilityUtils; |
15 import org.chromium.base.ContextUtils; | 15 import org.chromium.base.ContextUtils; |
16 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
17 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
18 import org.chromium.chrome.browser.banners.AppData; | 18 import org.chromium.chrome.browser.banners.AppData; |
19 import org.chromium.chrome.browser.widget.DualControlLayout; | 19 import org.chromium.chrome.browser.widget.DualControlLayout; |
20 | 20 |
21 /** | 21 /** |
22 * Infobar informing the user about an app related to this page. | 22 * Infobar informing the user about an app related to this page. |
23 */ | 23 */ |
24 public class AppBannerInfoBarAndroid extends ConfirmInfoBar implements View.OnCl ickListener { | 24 public class AppBannerInfoBarAndroid extends ConfirmInfoBar implements View.OnCl ickListener { |
25 // Installation states. | 25 // Installation states. |
26 public static final int INSTALL_STATE_NOT_INSTALLED = 0; | 26 public static final int INSTALL_STATE_NOT_INSTALLED = 0; |
27 public static final int INSTALL_STATE_INSTALLING = 1; | 27 public static final int INSTALL_STATE_INSTALLING = 1; |
28 public static final int INSTALL_STATE_INSTALLED = 2; | 28 public static final int INSTALL_STATE_INSTALLED = 2; |
29 public static final int INSTALL_STATE_INSTALLING_WEBAPK = 3; | |
30 public static final int INSTALL_STATE_INSTALLED_WEBAPK = 4; | |
pkotwicz
2016/08/19 22:17:37
Can we pass in whether the infobar is for a WebAPK
| |
29 | 31 |
30 // Views composing the infobar. | 32 // Views composing the infobar. |
31 private Button mButton; | 33 private Button mButton; |
32 private InfoBarControlLayout mMessageLayout; | 34 private InfoBarControlLayout mMessageLayout; |
33 private View mTitleView; | 35 private View mTitleView; |
34 private View mIconView; | 36 private View mIconView; |
35 | 37 |
36 private final String mAppTitle; | 38 private final String mAppTitle; |
37 | 39 |
38 // Data for native app installs. | 40 // Data for native app installs. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 } | 131 } |
130 | 132 |
131 @CalledByNative | 133 @CalledByNative |
132 public void onInstallStateChanged(int newState) { | 134 public void onInstallStateChanged(int newState) { |
133 setControlsEnabled(true); | 135 setControlsEnabled(true); |
134 mInstallState = newState; | 136 mInstallState = newState; |
135 updateButton(); | 137 updateButton(); |
136 } | 138 } |
137 | 139 |
138 private void updateButton() { | 140 private void updateButton() { |
139 if (mButton == null || mAppData == null) return; | 141 if (mButton == null || mAppData == null |
142 && (mInstallState != INSTALL_STATE_INSTALLING_WEBAPK | |
143 && mInstallState != INSTALL_STATE_INSTALLED_WEBAPK)) { | |
144 return; | |
145 } | |
140 | 146 |
141 String text; | 147 String text; |
142 String accessibilityText = null; | 148 String accessibilityText = null; |
143 boolean enabled = true; | 149 boolean enabled = true; |
144 if (mInstallState == INSTALL_STATE_NOT_INSTALLED) { | 150 if (mInstallState == INSTALL_STATE_NOT_INSTALLED) { |
145 text = mAppData.installButtonText(); | 151 text = mAppData.installButtonText(); |
146 accessibilityText = getContext().getString( | 152 accessibilityText = getContext().getString( |
147 R.string.app_banner_view_native_app_install_accessibility, t ext); | 153 R.string.app_banner_view_native_app_install_accessibility, t ext); |
148 } else if (mInstallState == INSTALL_STATE_INSTALLING) { | 154 } else if (mInstallState == INSTALL_STATE_INSTALLING) { |
149 text = getContext().getString(R.string.app_banner_installing); | 155 text = getContext().getString(R.string.app_banner_installing); |
150 enabled = false; | 156 enabled = false; |
157 } else if (mInstallState == INSTALL_STATE_INSTALLING_WEBAPK) { | |
158 text = getContext().getString(R.string.app_banner_installing_webapk) ; | |
159 enabled = false; | |
151 } else { | 160 } else { |
152 text = getContext().getString(R.string.app_banner_open); | 161 text = getContext().getString(R.string.app_banner_open); |
153 } | 162 } |
154 | 163 |
155 mButton.setText(text); | 164 mButton.setText(text); |
156 mButton.setContentDescription(accessibilityText); | 165 mButton.setContentDescription(accessibilityText); |
157 mButton.setEnabled(enabled); | 166 mButton.setEnabled(enabled); |
158 } | 167 } |
159 | 168 |
160 @Override | 169 @Override |
161 public void onClick(View v) { | 170 public void onClick(View v) { |
162 if (v == mMessageLayout || v == mTitleView || v == mIconView) onLinkClic ked(); | 171 if (v == mMessageLayout || v == mTitleView || v == mIconView) onLinkClic ked(); |
163 } | 172 } |
164 | 173 |
165 private static String getAddToHomescreenText() { | 174 private static String getAddToHomescreenText() { |
166 return ContextUtils.getApplicationContext().getString(R.string.menu_add_ to_homescreen); | 175 return ContextUtils.getApplicationContext().getString(R.string.menu_add_ to_homescreen); |
167 } | 176 } |
168 | 177 |
169 @CalledByNative | 178 @CalledByNative |
170 private static InfoBar createNativeAppInfoBar( | 179 private static InfoBar createNativeAppInfoBar( |
171 String appTitle, Bitmap iconBitmap, AppData appData) { | 180 String appTitle, Bitmap iconBitmap, AppData appData) { |
172 return new AppBannerInfoBarAndroid(appTitle, iconBitmap, appData); | 181 return new AppBannerInfoBarAndroid(appTitle, iconBitmap, appData); |
173 } | 182 } |
174 | 183 |
175 @CalledByNative | 184 @CalledByNative |
176 private static InfoBar createWebAppInfoBar(String appTitle, Bitmap iconBitma p, String url) { | 185 private static InfoBar createWebAppInfoBar(String appTitle, Bitmap iconBitma p, String url) { |
177 return new AppBannerInfoBarAndroid(appTitle, iconBitmap, url); | 186 return new AppBannerInfoBarAndroid(appTitle, iconBitmap, url); |
178 } | 187 } |
179 } | 188 } |
OLD | NEW |