OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.text.TextUtils; | |
8 | 9 |
9 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.chrome.browser.profiles.Profile; | 11 import org.chromium.chrome.browser.profiles.Profile; |
11 | 12 |
12 /** | 13 /** |
13 * Provides access to the search provider's logo via the C++ LogoService. | 14 * Provides access to the search provider's logo via the C++ LogoService. |
14 */ | 15 */ |
15 class LogoBridge { | 16 class LogoBridge { |
16 | 17 |
17 /** | 18 /** |
18 * A logo for a search provider (e.g. the Yahoo! logo or Google doodle). | 19 * A logo for a search provider (e.g. the Yahoo! logo or Google doodle). |
19 */ | 20 */ |
20 static class Logo { | 21 static class Logo { |
21 /** | 22 /** |
22 * The logo image. Non-null. | 23 * The logo image. Non-null. |
23 */ | 24 */ |
24 public final Bitmap image; | 25 public final Bitmap image; |
25 | 26 |
26 /** | 27 /** |
27 * The URL to navigate to when the user clicks on the logo. May be null. | 28 * The URL to navigate to when the user clicks on the logo. May be null. |
28 */ | 29 */ |
29 public final String onClickUrl; | 30 public final String onClickUrl; |
30 | 31 |
31 /** | 32 /** |
32 * The accessibility text describing the logo. May be null. | 33 * The accessibility text describing the logo. May be null. |
33 */ | 34 */ |
34 public final String altText; | 35 public final String altText; |
35 | 36 |
36 Logo(Bitmap image, String onClickUrl, String altText) { | 37 /** |
38 * The URL to download the animated GIF. If null, there is no GIF to dow nload. | |
39 */ | |
40 public final String gifUrl; | |
newt (away)
2015/09/18 20:46:01
animatedLogoUrl
Ian Wen
2015/09/22 21:39:05
Done.
| |
41 | |
42 Logo(Bitmap image, String onClickUrl, String altText, String gifUrl) { | |
37 this.image = image; | 43 this.image = image; |
38 this.onClickUrl = onClickUrl; | 44 this.onClickUrl = onClickUrl; |
39 this.altText = altText; | 45 this.altText = altText; |
46 this.gifUrl = gifUrl; | |
47 } | |
48 | |
49 @Override | |
50 public int hashCode() { | |
51 final int prime = 31; | |
52 int result = 1; | |
53 result = prime * result + ((altText == null) ? 0 : altText.hashCode( )); | |
54 result = prime * result + ((gifUrl == null) ? 0 : gifUrl.hashCode()) ; | |
55 result = prime * result + ((image == null) ? 0 : image.hashCode()); | |
56 result = prime * result + ((onClickUrl == null) ? 0 : onClickUrl.has hCode()); | |
57 return result; | |
58 } | |
59 | |
60 @Override | |
61 public boolean equals(Object obj) { | |
62 if (this == obj) return true; | |
63 if (!(obj instanceof Logo)) return false; | |
64 Logo other = (Logo) obj; | |
65 if (!TextUtils.equals(altText, other.altText)) return false; | |
66 if (!TextUtils.equals(gifUrl, other.gifUrl)) return false; | |
67 if (!TextUtils.equals(onClickUrl, other.onClickUrl)) return false; | |
68 if (image == null) { | |
69 if (other.image != null) return false; | |
70 } else if (!image.sameAs(other.image)) { | |
newt (away)
2015/09/18 20:46:01
Why sameAs()? This compares pixel config, but not
Ian Wen
2015/09/22 21:39:05
Removed.
| |
71 return false; | |
72 } | |
73 return true; | |
40 } | 74 } |
41 } | 75 } |
42 | 76 |
43 /** | 77 /** |
44 * Observer for receiving the logo when it's available. | 78 * Observer for receiving the logo when it's available. |
45 */ | 79 */ |
46 interface LogoObserver { | 80 interface LogoObserver { |
47 /** | 81 /** |
48 * Called when the cached or fresh logo is available. This may be called up to two times, | 82 * Called when the cached or fresh logo is available. This may be called up to two times, |
49 * once with the cached logo and once with a freshly downloaded logo. | 83 * once with the cached logo and once with a freshly downloaded logo. |
50 * | 84 * |
51 * @param logo The search provider's logo. | 85 * @param logo The search provider's logo. |
52 * @param fromCache Whether the logo was loaded from the cache. | 86 * @param fromCache Whether the logo was loaded from the cache. |
53 */ | 87 */ |
54 @CalledByNative("LogoObserver") | 88 @CalledByNative("LogoObserver") |
55 void onLogoAvailable(Logo logo, boolean fromCache); | 89 void onLogoAvailable(Logo logo, boolean fromCache); |
56 } | 90 } |
57 | 91 |
92 /** | |
93 * A listener that is notified when the GIF file is successfully downloaded. | |
94 */ | |
95 interface GifListener { | |
newt (away)
2015/09/18 20:46:01
Call this AnimatedLogoCallback or AnimatedLogoObse
Ian Wen
2015/09/22 21:39:05
Done.
| |
96 | |
97 /** | |
98 * Called when the GIF is successfully downloaded. | |
99 * | |
100 * @param bytes The byte array representing the raw data for the GIF. | |
newt (away)
2015/09/18 20:46:01
"animated GIF"
Ian Wen
2015/09/22 21:39:05
Done.
| |
101 */ | |
102 @CalledByNative("GifListener") | |
103 void onGifDownloaded(byte[] bytes); | |
104 } | |
105 | |
58 private long mNativeLogoBridge; | 106 private long mNativeLogoBridge; |
59 | 107 |
60 /** | 108 /** |
61 * Creates a LogoBridge for getting the logo of the default search provider. | 109 * Creates a LogoBridge for getting the logo of the default search provider. |
62 * | 110 * |
63 * @param profile Profile of the tab that will show the logo. | 111 * @param profile Profile of the tab that will show the logo. |
64 */ | 112 */ |
65 LogoBridge(Profile profile) { | 113 LogoBridge(Profile profile) { |
66 mNativeLogoBridge = nativeInit(profile); | 114 mNativeLogoBridge = nativeInit(profile); |
67 } | 115 } |
(...skipping 12 matching lines...) Expand all Loading... | |
80 * Gets the current logo for the default search provider. | 128 * Gets the current logo for the default search provider. |
81 * | 129 * |
82 * @param logoObserver The observer to receive the cached and/or fresh logos when they're | 130 * @param logoObserver The observer to receive the cached and/or fresh logos when they're |
83 * available. logoObserver.onLogoAvailable() may be call ed synchronously if | 131 * available. logoObserver.onLogoAvailable() may be call ed synchronously if |
84 * the cached logo is already available. | 132 * the cached logo is already available. |
85 */ | 133 */ |
86 void getCurrentLogo(LogoObserver logoObserver) { | 134 void getCurrentLogo(LogoObserver logoObserver) { |
87 nativeGetCurrentLogo(mNativeLogoBridge, logoObserver); | 135 nativeGetCurrentLogo(mNativeLogoBridge, logoObserver); |
88 } | 136 } |
89 | 137 |
138 /** | |
139 * Asynchronously gets the GIF animation. | |
newt (away)
2015/09/18 20:46:01
"Downloads an animated GIF logo."
(It's pretty ob
Ian Wen
2015/09/22 21:39:05
Done.
| |
140 * @param listener The listener that will be notified when the GIF is ready. | |
141 * @param gifUrl The url from which to download the GIF. | |
142 */ | |
143 void getGif(GifListener listener, String gifUrl) { | |
newt (away)
2015/09/18 20:46:01
"getAnimatedLogo"
Ian Wen
2015/09/22 21:39:05
Done.
| |
144 nativeGetAnimatedLogo(mNativeLogoBridge, listener, gifUrl); | |
145 } | |
146 | |
90 @CalledByNative | 147 @CalledByNative |
91 private static Logo createLogo(Bitmap image, String onClickUrl, String altTe xt) { | 148 private static Logo createLogo(Bitmap image, String onClickUrl, String altTe xt, String gifUrl) { |
92 return new Logo(image, onClickUrl, altText); | 149 return new Logo(image, onClickUrl, altText, gifUrl); |
93 } | 150 } |
94 | 151 |
95 private native long nativeInit(Profile profile); | 152 private native long nativeInit(Profile profile); |
96 private native void nativeGetCurrentLogo(long nativeLogoBridge, LogoObserver logoObserver); | 153 private native void nativeGetCurrentLogo(long nativeLogoBridge, LogoObserver logoObserver); |
154 private native void nativeGetAnimatedLogo(long nativeLogoBridge, GifListener listenr, | |
newt (away)
2015/09/18 20:46:01
"listenr" typo, but it should be changed to "callb
Ian Wen
2015/09/22 21:39:05
Done.
| |
155 String gifUrl); | |
97 private native void nativeDestroy(long nativeLogoBridge); | 156 private native void nativeDestroy(long nativeLogoBridge); |
98 } | 157 } |
OLD | NEW |