| 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.banners; | 5 package org.chromium.chrome.browser.banners; |
| 6 | 6 |
| 7 import android.animation.ObjectAnimator; | 7 import android.animation.ObjectAnimator; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
| 10 import android.content.ActivityNotFoundException; | 10 import android.content.ActivityNotFoundException; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 * MARGIN CALCULATIONS | 54 * MARGIN CALCULATIONS |
| 55 * Margin calculations for the banner are complicated by the background Drawable
's drop shadows, | 55 * Margin calculations for the banner are complicated by the background Drawable
's drop shadows, |
| 56 * since the drop shadows are meant to be counted as being part of the margin.
To deal with this, | 56 * since the drop shadows are meant to be counted as being part of the margin.
To deal with this, |
| 57 * the margins are calculated by deducting the background Drawable's padding fro
m the margins | 57 * the margins are calculated by deducting the background Drawable's padding fro
m the margins |
| 58 * defined by the XML files. | 58 * defined by the XML files. |
| 59 * | 59 * |
| 60 * EVEN MORE LAYOUT QUIRKS | 60 * EVEN MORE LAYOUT QUIRKS |
| 61 * The layout of the banner, which includes its widget sizes, may change when th
e screen is rotated | 61 * The layout of the banner, which includes its widget sizes, may change when th
e screen is rotated |
| 62 * to account for less screen real estate. This means that all of the View's wi
dgets and cached | 62 * to account for less screen real estate. This means that all of the View's wi
dgets and cached |
| 63 * dimensions must be rebuilt from scratch. | 63 * dimensions must be rebuilt from scratch. |
| 64 * |
| 65 * TODO(dfalcantara): Nuke this file. |
| 64 */ | 66 */ |
| 65 public class AppBannerView extends SwipableOverlayView | 67 public class AppBannerView extends SwipableOverlayView |
| 66 implements View.OnClickListener, InstallerDelegate.Observer, IntentCallb
ack { | 68 implements View.OnClickListener, InstallerDelegate.Observer, IntentCallb
ack { |
| 67 private static final String TAG = "AppBannerView"; | 69 private static final String TAG = "AppBannerView"; |
| 68 | 70 |
| 69 /** | 71 /** |
| 70 * Class that is alerted about things happening to the BannerView. | 72 * Class that is alerted about things happening to the BannerView. |
| 71 */ | 73 */ |
| 72 public static interface Observer { | 74 public static interface Observer { |
| 73 /** | 75 /** |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 assert mRatingView != null; | 239 assert mRatingView != null; |
| 238 assert mBannerHighlightView != null; | 240 assert mBannerHighlightView != null; |
| 239 assert mCloseButtonView != null; | 241 assert mCloseButtonView != null; |
| 240 | 242 |
| 241 // Set up the buttons to fire an event. | 243 // Set up the buttons to fire an event. |
| 242 mInstallButtonView.setOnClickListener(this); | 244 mInstallButtonView.setOnClickListener(this); |
| 243 mCloseButtonView.setOnClickListener(this); | 245 mCloseButtonView.setOnClickListener(this); |
| 244 | 246 |
| 245 // Configure the controls with the package information. | 247 // Configure the controls with the package information. |
| 246 mTitleView.setText(mAppData.title()); | 248 mTitleView.setText(mAppData.title()); |
| 247 mIconView.setImageDrawable(mAppData.icon()); | |
| 248 mRatingView.initialize(mAppData.rating()); | 249 mRatingView.initialize(mAppData.rating()); |
| 249 setAccessibilityInformation(); | |
| 250 | 250 |
| 251 // Determine how much the user can drag sideways before their touch is c
onsidered a scroll. | 251 // Determine how much the user can drag sideways before their touch is c
onsidered a scroll. |
| 252 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); | 252 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); |
| 253 | 253 |
| 254 // Set up the install button. | 254 // Set up the install button. |
| 255 updateButtonStatus(); | 255 updateButtonStatus(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 /** | |
| 259 * Creates a succinct description about the app being advertised. | |
| 260 */ | |
| 261 private void setAccessibilityInformation() { | |
| 262 String bannerText = getContext().getString( | |
| 263 R.string.app_banner_view_accessibility, mAppData.title(), mAppDa
ta.rating()); | |
| 264 setContentDescription(bannerText); | |
| 265 } | |
| 266 | |
| 267 @Override | 258 @Override |
| 268 public void onClick(View view) { | 259 public void onClick(View view) { |
| 269 if (mObserver == null) return; | 260 if (mObserver == null) return; |
| 270 | 261 |
| 271 // Only allow the button to be clicked when the banner's in a neutral po
sition. | 262 // Only allow the button to be clicked when the banner's in a neutral po
sition. |
| 272 if (Math.abs(getTranslationX()) > ZERO_THRESHOLD | 263 if (Math.abs(getTranslationX()) > ZERO_THRESHOLD |
| 273 || Math.abs(getTranslationY()) > ZERO_THRESHOLD) { | 264 || Math.abs(getTranslationY()) > ZERO_THRESHOLD) { |
| 274 return; | 265 return; |
| 275 } | 266 } |
| 276 | 267 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 846 |
| 856 /** | 847 /** |
| 857 * Calculates how tall the given View has been measured to be, including its
margins. | 848 * Calculates how tall the given View has been measured to be, including its
margins. |
| 858 * @param view View to measure. | 849 * @param view View to measure. |
| 859 * @return Measured height of the view plus its margins. | 850 * @return Measured height of the view plus its margins. |
| 860 */ | 851 */ |
| 861 private static int getHeightWithMargins(View view) { | 852 private static int getHeightWithMargins(View view) { |
| 862 return view.getMeasuredHeight() + getMarginHeight(view); | 853 return view.getMeasuredHeight() + getMarginHeight(view); |
| 863 } | 854 } |
| 864 } | 855 } |
| OLD | NEW |