Skip to content

Commit

Permalink
Add Rounded Corners to snackbars on Tablet
Browse files Browse the repository at this point in the history
Per Material Design, floating snackbars should have rounded corners with
radius of 2dp. This CL implements this detail.

BUG=545258
R=dfalcantara@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#355424}
  • Loading branch information
jollycopper committed Oct 21, 2015
1 parent 9dac286 commit 92a89cb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
13 changes: 13 additions & 0 deletions chrome/android/java/res/drawable-sw600dp/snackbar_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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. -->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/snackbar_background_color" />

<corners android:radius="2dip" />

</shape>
1 change: 0 additions & 1 deletion chrome/android/java/res/layout/snackbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#282C32"
android:minHeight="@dimen/snackbar_min_height"
android:orientation="horizontal" >

Expand Down
3 changes: 3 additions & 0 deletions chrome/android/java/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<color name="infobar_accent_blue">#4285f4</color>
<color name="infobar_tertiary_button_text">#969696</color>

<!-- Snackbar colors -->
<color name="snackbar_background_color">#282C32</color>

<!-- Tab Switcher Colors -->
<color name="tab_switcher_background">#14181C</color>
<color name="accessibility_tab_switcher_list_item">#252525</color>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

package org.chromium.chrome.browser.snackbar;

import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.ui.base.DeviceFormFactor;

Expand Down Expand Up @@ -67,8 +69,23 @@ void update(Snackbar snackbar, boolean animate) {
mMessageView.setTemplate(snackbar.getTemplateText());
setViewText(mMessageView, snackbar.getText(), animate);
String actionText = snackbar.getActionText();

View view = getContentView();
int backgroundColor = snackbar.getBackgroundColor();
if (backgroundColor == 0) {
backgroundColor = ApiCompatibilityUtils.getColor(view.getResources(),
R.color.snackbar_background_color);
}

if (DeviceFormFactor.isTablet(view.getContext())) {
// On tablet, snackbar popups have rounded corners.
view.setBackgroundResource(R.drawable.snackbar_background);
((GradientDrawable) view.getBackground()).setColor(backgroundColor);
} else {
view.setBackgroundColor(backgroundColor);
}

if (snackbar.getBackgroundColor() != 0) {
View view = getContentView();
view.setBackgroundColor(snackbar.getBackgroundColor());
}
if (actionText != null) {
Expand Down

0 comments on commit 92a89cb

Please sign in to comment.