Commit 4ca7aa46 authored by twellington's avatar twellington Committed by Commit bot

Replace search_sogou.png with a vector drawable

Extends PromoDialog to support vector drawables, and replaces
the large search_sogou.png asset with a vector drawable.

Replaces 131,070 bytes with 4,834.

BUG=666062

Review-Url: https://codereview.chromium.org/2857893003
Cr-Commit-Position: refs/heads/master@{#469381}
parent 954d0aca
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="21"
android:width="140dp"
android:height="140dp"
android:viewportWidth="140"
android:viewportHeight="140">
<path
android:fillColor="#FD6853"
android:strokeWidth="1"
android:pathData="M69.9999999,140 C108.659932,140 140,108.659932 140,70 C140,31.3400675
108.659932,0 69.9999999,0 C45.8117571,0 24.4889425,12.2683563
11.9146576,30.9219676 L2.9577194,90.1969502 C11.6260098,119.010586
38.3618346,140 69.9999999,140 Z" />
<path
android:fillColor="#ECECEC"
android:strokeWidth="1"
android:pathData="M2.94406777,90.1515152 C1.02899053,83.7699463 0,77.00514 0,70 C0,55.4571827
4.43480818,41.9501704 12.0258118,30.7575758 L88.1511811,30.7575758
C89.2559355,30.7575758 90.1515158,31.6432685 90.1515158,32.7507019
L90.1515158,88.1583891 C90.1515158,89.2591623 89.2564895,90.1515152
88.1511811,90.1515152 L2.94406777,90.1515152 Z" />
<path
android:fillColor="#D4D4D4"
android:strokeWidth="1"
android:pathData="M0.0078717273,71.060606 C0.00263006448,70.7076973 0,70.3541558 0,70 C0,62.99486
1.02899053,56.2300537 2.94406777,49.8484848 L71.0606061,49.8484848
L71.0606061,71.060606 L0.0078717273,71.060606 Z" />
<path
android:fillColor="#000000"
android:fillAlpha="0.0724637681"
android:strokeWidth="1"
android:pathData="M135.638271,94.3778225 C128.394909,113.873208 112.71449,129.266853
93.0338029,136.121966 L50.6375799,93.2637512 C55.8236903,97.3749255
62.3735899,99.8342058 69.4986932,99.8342058 C75.6589387,99.8342058
81.3924203,97.9967058 86.1795991,94.8414027 L103.083165,111.777956
C104.530451,113.225683 106.886931,113.225683 108.334218,111.777956
L111.089629,109.021706 C112.527638,107.583259 112.527638,105.216782
111.089629,103.778335 L94.3159477,86.9717058 C97.8413895,81.997463
99.9195442,75.9188645 99.9195442,69.3576903 C99.9195442,64.2442433
98.657807,59.4370463 96.4404902,55.168107 L135.638271,94.3778225 Z" />
<path
android:fillColor="#282828"
android:fillAlpha="0.200000003"
android:strokeAlpha="0.200000003"
android:strokeWidth="1"
android:pathData="M111.544225,104.25163 L111.117461,103.824736 C112.51836,105.272463
112.509082,107.601819 111.080351,109.021706 L108.32494,111.777956
C106.877653,113.225683 104.521173,113.225683 103.073887,111.777956
L86.1703217,94.8414027 C81.3831429,97.9967058 75.6496613,99.8342058
69.4894158,99.8342058 C52.8456197,99.8342058 39.3283339,86.4427282
39.0778419,69.8217054 C39.0778419,69.9794706 39.0685645,70.1279554
39.0685645,70.2857206 C39.0685645,87.1201906 52.6879026,100.762236
69.4894158,100.762236 C75.6496613,100.762236 81.3738654,98.9247361
86.1703217,95.769433 L103.073887,112.705986 C104.521173,114.153713
106.877653,114.153713 108.32494,112.705986 L111.544225,109.485721
C112.991511,108.056554 112.991511,105.699357 111.544225,104.25163 Z" />
<path
android:fillColor="#FFFFFF"
android:strokeWidth="1"
android:pathData="M111.089628,103.778335 L94.3159477,86.9717058 C97.8413895,81.997463
99.9195442,75.9281448 99.9195442,69.3576903 C99.9195442,52.5232206
86.3002064,38.8811751 69.4986932,38.8811751 C52.69718,38.8811751
39.0778419,52.5232206 39.0778419,69.3576903 C39.0778419,86.19216
52.69718,99.8342058 69.4986932,99.8342058 C75.6589387,99.8342058
81.3831429,97.9967058 86.1795991,94.8414027 L103.083165,111.777956
C104.530451,113.225683 106.886931,113.225683 108.334218,111.777956
L111.089628,109.021706 C112.527638,107.573978 112.527638,105.216782
111.089628,103.778335 L111.089628,103.778335 Z M69.4986932,88.5771982
C58.9038131,88.5771982 50.3221457,79.974357 50.3221457,69.3669706
C50.3221457,58.7595842 58.9130905,50.1567433 69.4986932,50.1567433
C80.0935734,50.1567433 88.6752406,58.7595842 88.6752406,69.3669706
C88.6752406,79.974357 80.0935734,88.5771982 69.4986932,88.5771982 Z" />
<path
android:fillColor="#282828"
android:fillAlpha="0.200000003"
android:strokeAlpha="0.200000003"
android:strokeWidth="1"
android:pathData="M69.4986932,51.0754933 C79.9358562,51.0754933 88.4061935,59.427766
88.6566853,69.8217054 C88.6566853,69.6639403 88.6845188,69.5154554
88.6845188,69.3576903 C88.6845188,58.7503039 80.0935734,50.147463
69.5079706,50.147463 C58.9130905,50.147463 50.3314231,58.7503039
50.3314231,69.3576903 C50.3314231,69.5154554 50.3499781,69.6639403
50.3592555,69.8217054 C50.5911925,59.427766 59.0615302,51.0754933
69.4986932,51.0754933 Z" />
</vector>
...@@ -80,7 +80,7 @@ public class SogouPromoDialog extends PromoDialog { ...@@ -80,7 +80,7 @@ public class SogouPromoDialog extends PromoDialog {
@Override @Override
protected DialogParams getDialogParams() { protected DialogParams getDialogParams() {
PromoDialog.DialogParams params = new PromoDialog.DialogParams(); PromoDialog.DialogParams params = new PromoDialog.DialogParams();
params.drawableResource = R.drawable.search_sogou; params.vectorDrawableResource = R.drawable.search_sogou;
params.headerStringResource = R.string.search_with_sogou; params.headerStringResource = R.string.search_with_sogou;
params.subheaderStringResource = R.string.sogou_explanation; params.subheaderStringResource = R.string.sogou_explanation;
params.primaryButtonStringResource = R.string.ok; params.primaryButtonStringResource = R.string.ok;
......
...@@ -23,9 +23,18 @@ public abstract class PromoDialog ...@@ -23,9 +23,18 @@ public abstract class PromoDialog
extends Dialog implements View.OnClickListener, DialogInterface.OnDismissListener { extends Dialog implements View.OnClickListener, DialogInterface.OnDismissListener {
/** Parameters that can be used to create a new PromoDialog. */ /** Parameters that can be used to create a new PromoDialog. */
public static class DialogParams { public static class DialogParams {
/** Optional: Resource ID of the Drawable to use for the promo illustration. */ /**
* Optional: Resource ID of the Drawable to use for the promo illustration.
* This parameter and {@link #vectorDrawableResource} are mutually exclusive.
*/
public int drawableResource; public int drawableResource;
/**
* Optional: Resource ID of the VectorDrawable to use for the promo illustration.
* This parameter and {@link #drawableResource} are mutually exclusive.
*/
public int vectorDrawableResource;
/** Resource ID of the String to show as the promo title. */ /** Resource ID of the String to show as the promo title. */
public int headerStringResource; public int headerStringResource;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.widget; package org.chromium.chrome.browser.widget;
import android.content.Context; import android.content.Context;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -79,7 +80,7 @@ public final class PromoDialogLayout extends BoundedLinearLayout { ...@@ -79,7 +80,7 @@ public final class PromoDialogLayout extends BoundedLinearLayout {
assert params.primaryButtonStringResource != 0; assert params.primaryButtonStringResource != 0;
mParams = params; mParams = params;
if (mParams.drawableResource == 0) { if (mParams.drawableResource == 0 && mParams.vectorDrawableResource == 0) {
// Dialogs with no illustration make the header stay visible at all times instead of // Dialogs with no illustration make the header stay visible at all times instead of
// scrolling off on small screens. // scrolling off on small screens.
((ViewGroup) mIllustrationView.getParent()).removeView(mIllustrationView); ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustrationView);
...@@ -94,6 +95,9 @@ public final class PromoDialogLayout extends BoundedLinearLayout { ...@@ -94,6 +95,9 @@ public final class PromoDialogLayout extends BoundedLinearLayout {
(MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize); (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize);
ApiCompatibilityUtils.setMarginEnd( ApiCompatibilityUtils.setMarginEnd(
(MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize); (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize);
} else if (mParams.vectorDrawableResource != 0) {
mIllustrationView.setImageDrawable(VectorDrawableCompat.create(
getResources(), mParams.vectorDrawableResource, getContext().getTheme()));
} else { } else {
mIllustrationView.setImageResource(mParams.drawableResource); mIllustrationView.setImageResource(mParams.drawableResource);
} }
......
...@@ -102,9 +102,9 @@ public class PromoDialogTest { ...@@ -102,9 +102,9 @@ public class PromoDialogTest {
public void testBasic_Visibility() throws Exception { public void testBasic_Visibility() throws Exception {
// Create a full dialog. // Create a full dialog.
DialogParams dialogParams = new DialogParams(); DialogParams dialogParams = new DialogParams();
dialogParams.drawableResource = R.drawable.search_sogou; dialogParams.drawableResource = R.drawable.data_reduction_illustration;
dialogParams.headerStringResource = R.string.search_with_sogou; dialogParams.headerStringResource = R.string.data_reduction_promo_title;
dialogParams.subheaderStringResource = R.string.sogou_explanation; dialogParams.subheaderStringResource = R.string.data_reduction_promo_summary;
dialogParams.primaryButtonStringResource = R.string.ok; dialogParams.primaryButtonStringResource = R.string.ok;
dialogParams.secondaryButtonStringResource = R.string.cancel; dialogParams.secondaryButtonStringResource = R.string.cancel;
dialogParams.footerStringResource = R.string.learn_more; dialogParams.footerStringResource = R.string.learn_more;
...@@ -112,7 +112,7 @@ public class PromoDialogTest { ...@@ -112,7 +112,7 @@ public class PromoDialogTest {
// Create a minimal dialog. // Create a minimal dialog.
dialogParams = new DialogParams(); dialogParams = new DialogParams();
dialogParams.headerStringResource = R.string.search_with_sogou; dialogParams.headerStringResource = R.string.data_reduction_promo_title;
dialogParams.primaryButtonStringResource = R.string.ok; dialogParams.primaryButtonStringResource = R.string.ok;
checkDialogControlVisibility(dialogParams); checkDialogControlVisibility(dialogParams);
} }
...@@ -154,9 +154,9 @@ public class PromoDialogTest { ...@@ -154,9 +154,9 @@ public class PromoDialogTest {
@SmallTest @SmallTest
public void testBasic_Orientation() throws Exception { public void testBasic_Orientation() throws Exception {
DialogParams dialogParams = new DialogParams(); DialogParams dialogParams = new DialogParams();
dialogParams.drawableResource = R.drawable.search_sogou; dialogParams.drawableResource = R.drawable.data_reduction_illustration;
dialogParams.headerStringResource = R.string.search_with_sogou; dialogParams.headerStringResource = R.string.data_reduction_promo_title;
dialogParams.subheaderStringResource = R.string.sogou_explanation; dialogParams.subheaderStringResource = R.string.data_reduction_promo_summary;
dialogParams.primaryButtonStringResource = R.string.ok; dialogParams.primaryButtonStringResource = R.string.ok;
dialogParams.secondaryButtonStringResource = R.string.cancel; dialogParams.secondaryButtonStringResource = R.string.cancel;
dialogParams.footerStringResource = R.string.learn_more; dialogParams.footerStringResource = R.string.learn_more;
...@@ -253,7 +253,28 @@ public class PromoDialogTest { ...@@ -253,7 +253,28 @@ public class PromoDialogTest {
// With an illustration, the header View is part of the scrollable content. // With an illustration, the header View is part of the scrollable content.
{ {
DialogParams dialogParams = new DialogParams(); DialogParams dialogParams = new DialogParams();
dialogParams.drawableResource = R.drawable.search_sogou; dialogParams.drawableResource = R.drawable.data_reduction_illustration;
dialogParams.headerStringResource = R.string.data_reduction_promo_title;
dialogParams.primaryButtonStringResource = R.string.data_reduction_enable_button;
PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams);
PromoDialogLayout promoDialogLayout =
(PromoDialogLayout) wrapper.dialog.getWindow().getDecorView().findViewById(
R.id.promo_dialog_layout);
ViewGroup scrollableLayout =
(ViewGroup) promoDialogLayout.findViewById(R.id.scrollable_promo_content);
View header = promoDialogLayout.findViewById(R.id.header);
MarginLayoutParams headerParams = (MarginLayoutParams) header.getLayoutParams();
Assert.assertEquals(scrollableLayout.getChildAt(0), header);
Assert.assertEquals(0, ApiCompatibilityUtils.getMarginStart(headerParams));
Assert.assertEquals(0, ApiCompatibilityUtils.getMarginEnd(headerParams));
}
// With a vector illustration, the header View is part of the scrollable content.
{
DialogParams dialogParams = new DialogParams();
dialogParams.vectorDrawableResource = R.drawable.search_sogou;
dialogParams.headerStringResource = R.string.search_with_sogou; dialogParams.headerStringResource = R.string.search_with_sogou;
dialogParams.primaryButtonStringResource = R.string.ok; dialogParams.primaryButtonStringResource = R.string.ok;
......
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