Commit eb815b6c authored by newt's avatar newt Committed by Commit bot

Add infobar layout for app install banners.

This makes InfoBarLayout more flexible and uses that flexibility to
implement the app banner view.

BUG=442690

Review URL: https://codereview.chromium.org/868663009

Cr-Commit-Position: refs/heads/master@{#315195}
parent dfadfaf7
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 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. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/star_gray" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/star_gray" />
<item android:id="@android:id/progress" android:drawable="@drawable/star_green" />
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 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. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="start" >
<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="18sp"
android:textColor="@color/default_text_color" />
<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:progressDrawable="@drawable/rating_bar"
android:indeterminateDrawable="@drawable/rating_bar"
android:minHeight="16dp"
android:maxHeight="16dp"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.5" />
<TextView
android:id="@+id/web_app_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="14sp"
android:textColor="#646464" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2013 The Chromium Authors. All rights reserved. <!-- Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. found in the LICENSE file. -->
-->
<org.chromium.ui.widget.TextViewWithClickableSpans <org.chromium.ui.widget.TextViewWithClickableSpans
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/infobar_message" android:id="@+id/infobar_message"
android:layout_marginTop="@dimen/infobar_margin"
android:layout_marginBottom="@dimen/infobar_margin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.25" android:lineSpacingMultiplier="1.25"
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
<color name="accessibility_close_undo_text">#3adaff</color> <color name="accessibility_close_undo_text">#3adaff</color>
<!-- App banner colors --> <!-- App banner colors -->
<color name="app_banner_install_button_bg">#689f38</color>
<color name="app_banner_install_button_fg">#ffffff</color> <color name="app_banner_install_button_fg">#ffffff</color>
<color name="app_banner_open_button_fg">#777777</color> <color name="app_banner_open_button_fg">#777777</color>
<color name="app_banner_card_highlight">#33999999</color> <color name="app_banner_card_highlight">#33999999</color>
......
...@@ -56,6 +56,9 @@ ...@@ -56,6 +56,9 @@
<dimen name="infobar_icon_size">36dp</dimen> <dimen name="infobar_icon_size">36dp</dimen>
<!-- App banner dimensions --> <!-- App banner dimensions -->
<dimen name="app_banner_infobar_icon_size">48dp</dimen>
<dimen name="app_banner_infobar_icon_spacing">16dp</dimen>
<dimen name="app_banner_max_width">424dp</dimen> <dimen name="app_banner_max_width">424dp</dimen>
<dimen name="app_banner_margin_sides">8dp</dimen> <dimen name="app_banner_margin_sides">8dp</dimen>
<dimen name="app_banner_margin_bottom">8dp</dimen> <dimen name="app_banner_margin_bottom">8dp</dimen>
......
...@@ -5,9 +5,14 @@ ...@@ -5,9 +5,14 @@
package org.chromium.chrome.browser.infobar; package org.chromium.chrome.browser.infobar;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
...@@ -26,7 +31,7 @@ public class AppBannerInfoBar extends ConfirmInfoBar implements View.OnClickList ...@@ -26,7 +31,7 @@ public class AppBannerInfoBar extends ConfirmInfoBar implements View.OnClickList
// Views composing the infobar. // Views composing the infobar.
private Button mButton; private Button mButton;
private View mTitleView; private ViewGroup mTitleView;
private View mIconView; private View mIconView;
private final String mAppTitle; private final String mAppTitle;
...@@ -58,32 +63,45 @@ public class AppBannerInfoBar extends ConfirmInfoBar implements View.OnClickList ...@@ -58,32 +63,45 @@ public class AppBannerInfoBar extends ConfirmInfoBar implements View.OnClickList
@Override @Override
public void createContent(InfoBarLayout layout) { public void createContent(InfoBarLayout layout) {
if (mAppUrl != null) {
TextView url = new TextView(layout.getContext());
url.setText(mAppUrl);
layout.setCustomContent(url);
}
super.createContent(layout); super.createContent(layout);
mButton = (Button) layout.findViewById(R.id.button_primary); mButton = layout.getPrimaryButton();
mTitleView = layout.findViewById(R.id.infobar_message); mIconView = layout.getIcon();
// TODO(dfalcantara): Grab the icon from the layout. Resources res = getContext().getResources();
// mIconView = layout.findViewById(R.id.infobar_icon); int iconSize = res.getDimensionPixelSize(R.dimen.app_banner_infobar_icon_size);
int iconSpacing = res.getDimensionPixelSize(R.dimen.app_banner_infobar_icon_spacing);
layout.setIconSizeAndSpacing(iconSize, iconSize, iconSpacing);
assert mButton != null && mTitleView != null; mTitleView = (ViewGroup) LayoutInflater.from(getContext()).inflate(
R.layout.app_banner_title, null);
TextView appName = (TextView) mTitleView.findViewById(R.id.app_name);
RatingBar ratingView = (RatingBar) mTitleView.findViewById(R.id.rating_bar);
TextView webAppUrl = (TextView) mTitleView.findViewById(R.id.web_app_url);
appName.setText(mAppTitle);
layout.setMessageView(mTitleView);
// Set up accessibility text.
Context context = getContext(); Context context = getContext();
if (mAppData != null) { if (mAppData != null) {
// Native app.
ImageView playLogo = new ImageView(layout.getContext());
playLogo.setImageResource(R.drawable.google_play);
layout.setCustomViewInButtonRow(playLogo);
ratingView.setRating(mAppData.rating());
layout.getPrimaryButton().setButtonColor(getContext().getResources().getColor(
R.color.app_banner_install_button_bg));
layout.setContentDescription(context.getString( layout.setContentDescription(context.getString(
R.string.app_banner_view_native_app_accessibility, mAppTitle, R.string.app_banner_view_native_app_accessibility, mAppTitle,
mAppData.rating())); mAppData.rating()));
mTitleView.removeView(webAppUrl);
} else { } else {
// Web app.
webAppUrl.setText(mAppUrl);
layout.setContentDescription(context.getString( layout.setContentDescription(context.getString(
R.string.app_banner_view_web_app_accessibility, mAppTitle, R.string.app_banner_view_web_app_accessibility, mAppTitle,
mAppUrl)); mAppUrl));
mTitleView.removeView(ratingView);
} }
// Set up clicking on the controls to bring up the app details. // Set up clicking on the controls to bring up the app details.
......
...@@ -152,6 +152,7 @@ public abstract class InfoBar implements InfoBarView { ...@@ -152,6 +152,7 @@ public abstract class InfoBar implements InfoBarView {
InfoBarLayout layout = InfoBarLayout layout =
new InfoBarLayout(mContext, this, mIconDrawableId, mIconBitmap, mMessage); new InfoBarLayout(mContext, this, mIconDrawableId, mIconBitmap, mMessage);
createContent(layout); createContent(layout);
layout.onContentCreated();
return layout; return layout;
} }
......
...@@ -42,6 +42,14 @@ public class ButtonCompat extends Button { ...@@ -42,6 +42,14 @@ public class ButtonCompat extends Button {
private int mColor; private int mColor;
/**
* Returns a new borderless material-style button.
*/
public static Button createBorderlessButton(Context context) {
Context wrapper = new ContextThemeWrapper(context, R.style.ButtonBorderlessCompat);
return new Button(wrapper, null, 0);
}
/** /**
* Constructs a button with the given buttonColor as its background. * Constructs a button with the given buttonColor as its background.
*/ */
...@@ -81,6 +89,7 @@ public class ButtonCompat extends Button { ...@@ -81,6 +89,7 @@ public class ButtonCompat extends Button {
* Sets the background color of the button. * Sets the background color of the button.
*/ */
public void setButtonColor(int color) { public void setButtonColor(int color) {
if (color == mColor) return;
mColor = color; mColor = color;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
......
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