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 3// found in the LICENSE file. 4 5package org.chromium.chrome.browser.banners; 6 7import android.app.PendingIntent; 8import android.graphics.drawable.Drawable; 9 10/** 11 * Stores information about a particular app. 12 */ 13public class AppData { 14 // Immutable data about this app. 15 private final String mSiteUrl; 16 private final String mPackageName; 17 18 // Data returned by the system when queried about the app. 19 private String mTitle; 20 private String mImageUrl; 21 private float mRating; 22 private String mInstallButtonText; 23 private PendingIntent mDetailsIntent; 24 private PendingIntent mInstallIntent; 25 26 // Data that can be updated asynchronously. 27 private Drawable mIcon; 28 29 /** 30 * Creates a new AppData for the given page and package. 31 * @param siteUrl URL for the site requesting the banner. 32 * @param packageName Name of the package associated with the app. 33 */ 34 public AppData(String siteUrl, String packageName) { 35 mSiteUrl = siteUrl; 36 mPackageName = packageName; 37 } 38 39 /** 40 * Returns the URL of the website requesting the banner. 41 * @return The URL of the website. 42 */ 43 String siteUrl() { 44 return mSiteUrl; 45 } 46 47 /** 48 * Returns the package name of the app. 49 * @return The String containing the package name. 50 */ 51 public String packageName() { 52 return mPackageName; 53 } 54 55 /** 56 * Returns the title to display for the app in the banner. 57 * @return The String to display. 58 */ 59 String title() { 60 return mTitle; 61 } 62 63 /** 64 * Returns the URL where the app icon can be retrieved from. 65 * @return The URL to grab the icon from. 66 */ 67 String imageUrl() { 68 return mImageUrl; 69 } 70 71 /** 72 * Returns the Drawable depicting the app's icon. 73 * @return The Drawable to use as the app icon. 74 */ 75 Drawable icon() { 76 return mIcon; 77 } 78 79 /** 80 * Returns how well the app was rated, on a scale from 0 to 5. 81 * @return The rating of the app. 82 */ 83 float rating() { 84 return mRating; 85 } 86 87 /** 88 * Returns text to display on the install button when the app is not installed on the system. 89 * @return The String to display. 90 */ 91 String installButtonText() { 92 return mInstallButtonText; 93 } 94 95 /** 96 * Returns the Intent used to send a user to a details page about the app. 97 * The IntentSender stored inside dictates what package needs to be launched. 98 * @return Intent that triggers the details page. 99 */ 100 PendingIntent detailsIntent() { 101 return mDetailsIntent; 102 } 103 104 /** 105 * Returns the PendingIntent that triggers the install. 106 * The IntentSender stored inside dictates what package needs to be launched. 107 * @return PendingIntent used to trigger the install. 108 */ 109 PendingIntent installIntent() { 110 return mInstallIntent; 111 } 112 113 /** 114 * Stores all of the data about the given app after it's been retrieved. 115 * @param title App title. 116 * @param imageUrl URL where the icon is located. 117 * @param rating Rating of the app. 118 * @param installButtonText Text to display on the install button if it's not installed yet. 119 * @param detailsIntent Intent to fire to launch the details page for the app 120 * @param installIntent Intent to fire to trigger the purchase/install process. 121 */ 122 public void setPackageInfo(String title, String imageUrl, float rating, 123 String installButtonText, PendingIntent detailsIntent, PendingIntent installIntent) { 124 mTitle = title; 125 mImageUrl = imageUrl; 126 mRating = rating; 127 mInstallButtonText = installButtonText; 128 mDetailsIntent = detailsIntent; 129 mInstallIntent = installIntent; 130 } 131 132 /** 133 * Sets the icon used to depict the app. 134 * @param Drawable App icon in Drawable form. 135 */ 136 void setIcon(Drawable icon) { 137 mIcon = icon; 138 } 139} 140