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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Color; | 9 import android.graphics.Color; |
10 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 */ | 189 */ |
190 WebappInfo getWebappInfo() { | 190 WebappInfo getWebappInfo() { |
191 return mWebappInfo; | 191 return mWebappInfo; |
192 } | 192 } |
193 | 193 |
194 private void initializeSplashScreen() { | 194 private void initializeSplashScreen() { |
195 final int backgroundColor = mWebappInfo.backgroundColor( | 195 final int backgroundColor = mWebappInfo.backgroundColor( |
196 ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_de
fault_bg)); | 196 ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_de
fault_bg)); |
197 | 197 |
198 ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content); | 198 ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content); |
199 mSplashScreen = createSplashScreen(contentView); | 199 mSplashScreen = (ViewGroup) LayoutInflater.from(this).inflate( |
| 200 R.layout.webapp_splash_screen, contentView, false); |
200 mSplashScreen.setBackgroundColor(backgroundColor); | 201 mSplashScreen.setBackgroundColor(backgroundColor); |
201 contentView.addView(mSplashScreen); | 202 contentView.addView(mSplashScreen); |
202 | 203 |
203 mWebappUma.splashscreenVisible(); | 204 mWebappUma.splashscreenVisible(); |
204 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro
undColor() | 205 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro
undColor() |
205 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM | 206 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
206 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); | 207 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
207 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor() | 208 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor() |
208 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM | 209 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
209 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); | 210 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
210 | 211 |
211 WebappDataStorage.open(this, mWebappInfo.id()) | 212 WebappDataStorage.open(this, mWebappInfo.id()) |
212 .getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap
>() { | 213 .getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap
>() { |
213 @Override | 214 @Override |
214 public void onDataRetrieved(Bitmap splashIcon) { | 215 public void onDataRetrieved(Bitmap splashIcon) { |
215 setSplashScreenIconAndText(mSplashScreen, splashIcon, ba
ckgroundColor); | 216 Bitmap displayIcon = splashIcon == null ? mWebappInfo.ic
on() : splashIcon; |
| 217 if (displayIcon == null || displayIcon.getWidth() < getR
esources() |
| 218 .getDimensionPixelSize(R.dimen.webapp_splash_ima
ge_min_size)) { |
| 219 mWebappUma.recordSplashscreenIconType( |
| 220 WebappUma.SPLASHSCREEN_ICON_TYPE_NONE); |
| 221 return; |
| 222 } |
| 223 |
| 224 mWebappUma.recordSplashscreenIconType(splashIcon != null |
| 225 ? WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM |
| 226 : WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK); |
| 227 mWebappUma.recordSplashscreenIconSize( |
| 228 Math.round((float) displayIcon.getWidth() |
| 229 / getResources().getDisplayMetrics().den
sity)); |
| 230 |
| 231 TextView appNameView = (TextView) mSplashScreen.findView
ById( |
| 232 R.id.webapp_splash_screen_name); |
| 233 ImageView splashIconView = (ImageView) mSplashScreen.fin
dViewById( |
| 234 R.id.webapp_splash_screen_icon); |
| 235 appNameView.setText(mWebappInfo.name()); |
| 236 splashIconView.setImageBitmap(displayIcon); |
| 237 |
| 238 if (ColorUtils.shoudUseLightForegroundOnBackground(backg
roundColor)) { |
| 239 appNameView.setTextColor(ApiCompatibilityUtils.getCo
lor(getResources(), |
| 240 R.color.webapp_splash_title_light)); |
| 241 } |
216 } | 242 } |
217 }); | 243 }); |
218 } | 244 } |
219 | 245 |
220 private void updateUrlBar() { | 246 private void updateUrlBar() { |
221 Tab tab = getActivityTab(); | 247 Tab tab = getActivityTab(); |
222 if (tab == null || mUrlBar == null) return; | 248 if (tab == null || mUrlBar == null) return; |
223 mUrlBar.update(tab.getUrl(), tab.getSecurityLevel()); | 249 mUrlBar.update(tab.getUrl(), tab.getSecurityLevel()); |
224 } | 250 } |
225 | 251 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 /** | 393 /** |
368 * Get the active directory by this web app. | 394 * Get the active directory by this web app. |
369 * | 395 * |
370 * @return The directory used for the current web app. | 396 * @return The directory used for the current web app. |
371 */ | 397 */ |
372 @Override | 398 @Override |
373 protected final File getActivityDirectory() { | 399 protected final File getActivityDirectory() { |
374 return mDirectoryManager.getWebappDirectory(this, getId()); | 400 return mDirectoryManager.getWebappDirectory(this, getId()); |
375 } | 401 } |
376 | 402 |
377 @VisibleForTesting | |
378 ViewGroup createSplashScreen(ViewGroup parentView) { | |
379 return (ViewGroup) LayoutInflater.from(this) | |
380 .inflate(R.layout.webapp_splash_screen, parentView, false); | |
381 } | |
382 | |
383 @VisibleForTesting | |
384 void setSplashScreenIconAndText(View splashScreen, Bitmap splashIcon, int ba
ckgroundColor) { | |
385 if (splashScreen == null) return; | |
386 | |
387 Bitmap displayIcon = splashIcon == null ? mWebappInfo.icon() : splashIco
n; | |
388 if (displayIcon == null || displayIcon.getWidth() < getResources() | |
389 .getDimensionPixelSize(R.dimen.webapp_splash_image_min_size)) { | |
390 mWebappUma.recordSplashscreenIconType(WebappUma.SPLASHSCREEN_ICON_TY
PE_NONE); | |
391 return; | |
392 } | |
393 | |
394 mWebappUma.recordSplashscreenIconType(splashIcon != null | |
395 ? WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM | |
396 : WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK); | |
397 mWebappUma.recordSplashscreenIconSize(Math.round( | |
398 (float) displayIcon.getWidth() / getResources().getDisplayMetric
s().density)); | |
399 | |
400 TextView appNameView = (TextView) splashScreen.findViewById( | |
401 R.id.webapp_splash_screen_name); | |
402 ImageView splashIconView = (ImageView) splashScreen.findViewById( | |
403 R.id.webapp_splash_screen_icon); | |
404 appNameView.setText(mWebappInfo.name()); | |
405 splashIconView.setImageBitmap(displayIcon); | |
406 | |
407 if (ColorUtils.shoudUseLightForegroundOnBackground(backgroundColor)) { | |
408 appNameView.setTextColor(ApiCompatibilityUtils.getColor(getResources
(), | |
409 R.color.webapp_splash_title_light)); | |
410 } | |
411 } | |
412 | |
413 private void hideSplashScreen(final int reason) { | 403 private void hideSplashScreen(final int reason) { |
414 if (mSplashScreen == null) return; | 404 if (mSplashScreen == null) return; |
415 | 405 |
416 mSplashScreen.animate() | 406 mSplashScreen.animate() |
417 .alpha(0f) | 407 .alpha(0f) |
418 .withEndAction(new Runnable() { | 408 .withEndAction(new Runnable() { |
419 @Override | 409 @Override |
420 public void run() { | 410 public void run() { |
421 ViewGroup contentView = | 411 ViewGroup contentView = |
422 (ViewGroup) findViewById(android.R.id.content); | 412 (ViewGroup) findViewById(android.R.id.content); |
423 if (mSplashScreen == null) return; | 413 if (mSplashScreen == null) return; |
424 contentView.removeView(mSplashScreen); | 414 contentView.removeView(mSplashScreen); |
425 mSplashScreen = null; | 415 mSplashScreen = null; |
426 mWebappUma.splashscreenHidden(reason); | 416 mWebappUma.splashscreenHidden(reason); |
427 } | 417 } |
428 }); | 418 }); |
429 } | 419 } |
430 | 420 |
431 @VisibleForTesting | 421 @VisibleForTesting |
432 boolean isSplashScreenVisibleForTest() { | 422 boolean isSplashScreenVisibleForTests() { |
433 return mSplashScreen != null; | 423 return mSplashScreen != null; |
434 } | 424 } |
435 | 425 |
436 @VisibleForTesting | 426 @VisibleForTesting |
| 427 ViewGroup getSplashScreenForTests() { |
| 428 return mSplashScreen; |
| 429 } |
| 430 |
| 431 @VisibleForTesting |
437 WebappUrlBar getUrlBarForTests() { | 432 WebappUrlBar getUrlBarForTests() { |
438 return mUrlBar; | 433 return mUrlBar; |
439 } | 434 } |
440 | 435 |
441 @VisibleForTesting | 436 @VisibleForTesting |
442 boolean isUrlBarVisible() { | 437 boolean isUrlBarVisible() { |
443 return findViewById(R.id.control_container).getVisibility() == View.VISI
BLE; | 438 return findViewById(R.id.control_container).getVisibility() == View.VISI
BLE; |
444 } | 439 } |
445 | 440 |
446 @Override | 441 @Override |
(...skipping 26 matching lines...) Expand all Loading... |
473 return visible; | 468 return visible; |
474 } | 469 } |
475 | 470 |
476 // We're temporarily disable CS on webapp since there are some issues. (http
://crbug.com/471950) | 471 // We're temporarily disable CS on webapp since there are some issues. (http
://crbug.com/471950) |
477 // TODO(changwan): re-enable it once the issues are resolved. | 472 // TODO(changwan): re-enable it once the issues are resolved. |
478 @Override | 473 @Override |
479 protected boolean isContextualSearchAllowed() { | 474 protected boolean isContextualSearchAllowed() { |
480 return false; | 475 return false; |
481 } | 476 } |
482 } | 477 } |
OLD | NEW |