Commit 862a20cd authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Offline indicator v2] Add status icon

Bug: 1068346
Change-Id: Ied07d2d4b0e181a886ece94ad4a763c8ec9d7cf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137855Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#757535}
parent 5d5aafa9
......@@ -5,6 +5,7 @@
<org.chromium.components.browser_ui.widget.ViewResourceFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/status_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -12,11 +13,13 @@
<org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables
android:id="@+id/status_text"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minHeight="20dp"
android:textAlignment="center"
android:drawablePadding="8dp"
android:textAppearance="@style/TextAppearance.TextSmall.Primary"/>
android:gravity="center"
android:minHeight="@dimen/status_indicator_min_height"
android:drawablePadding="@dimen/status_indicator_icon_padding"
android:textAppearance="@style/TextAppearance.TextSmall.Primary"
app:drawableWidth="@dimen/status_indicator_icon_size"
app:drawableHeight="@dimen/status_indicator_icon_size"/>
</org.chromium.components.browser_ui.widget.ViewResourceFrameLayout>
......@@ -624,4 +624,9 @@
<dimen name="tab_indicator_height">3dp</dimen>
<dimen name="tab_indicator_radius">3dp</dimen>
<dimen name="tab_indicator_padding">2dp</dimen>
<!-- Status indicator dimensions -->
<dimen name="status_indicator_min_height">21dp</dimen>
<dimen name="status_indicator_icon_padding">8dp</dimen>
<dimen name="status_indicator_icon_size">12dp</dimen>
</resources>
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.status_indicator;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;
......@@ -40,9 +41,9 @@ class StatusIndicatorViewBinder {
((TextView) view.javaViewRoot.findViewById(R.id.status_text))
.setText(model.get(StatusIndicatorProperties.STATUS_TEXT));
} else if (StatusIndicatorProperties.STATUS_ICON == propertyKey) {
final Drawable drawable = model.get(StatusIndicatorProperties.STATUS_ICON);
((TextView) view.javaViewRoot.findViewById(R.id.status_text))
.setCompoundDrawablesRelativeWithIntrinsicBounds(
model.get(StatusIndicatorProperties.STATUS_ICON), null, null, null);
.setCompoundDrawablesRelative(drawable, null, null, null);
} else if (StatusIndicatorProperties.COMPOSITED_VIEW_VISIBLE == propertyKey) {
assert view.sceneLayer != null;
view.sceneLayer.setIsVisible(
......
......@@ -4,10 +4,12 @@
package org.chromium.chrome.browser.tabbed_mode;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
......@@ -252,16 +254,20 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator implements Native
mActivity.getResources(), R.color.offline_indicator_offline_color);
final int textColor = ApiCompatibilityUtils.getColor(
mActivity.getResources(), R.color.default_text_color_light);
final Drawable statusIcon = VectorDrawableCompat.create(mActivity.getResources(),
R.drawable.ic_cloud_offline_24dp, mActivity.getTheme());
final int iconTint = ApiCompatibilityUtils.getColor(
mActivity.getResources(), R.color.default_icon_color_light);
mStatusIndicatorCoordinator.show(
mActivity.getString(R.string.offline_indicator_v2_offline_text), null,
mActivity.getString(R.string.offline_indicator_v2_offline_text), statusIcon,
backgroundColor, textColor, iconTint);
} else {
final int backgroundColor = ApiCompatibilityUtils.getColor(
mActivity.getResources(), R.color.offline_indicator_back_online_color);
final int textColor = ApiCompatibilityUtils.getColor(
mActivity.getResources(), R.color.default_text_color_inverse);
final Drawable statusIcon = VectorDrawableCompat.create(
mActivity.getResources(), R.drawable.ic_globe_24dp, mActivity.getTheme());
final int iconTint = ApiCompatibilityUtils.getColor(
mActivity.getResources(), R.color.default_icon_color_inverse);
Runnable hide = () -> {
......@@ -270,8 +276,8 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator implements Native
STATUS_INDICATOR_WAIT_BEFORE_HIDE_DURATION_MS);
};
mStatusIndicatorCoordinator.updateContent(
mActivity.getString(R.string.offline_indicator_v2_back_online_text), null,
backgroundColor, textColor, iconTint, hide);
mActivity.getString(R.string.offline_indicator_v2_back_online_text),
statusIcon, backgroundColor, textColor, iconTint, hide);
}
});
}
......
......@@ -13,6 +13,7 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import org.chromium.components.browser_ui.widget.R;
......@@ -59,6 +60,19 @@ public class TextViewWithCompoundDrawables extends AppCompatTextView {
}
}
@Override
public void setCompoundDrawablesRelative(@Nullable Drawable start, @Nullable Drawable top,
@Nullable Drawable end, @Nullable Drawable bottom) {
Drawable[] drawables = {start, top, end, bottom};
setDrawableBounds(drawables);
if (mDrawableTint != null) {
setDrawableTint(drawables);
}
super.setCompoundDrawablesRelative(drawables[0], drawables[1], drawables[2], drawables[3]);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray array = context.obtainStyledAttributes(
attrs, R.styleable.TextViewWithCompoundDrawables, defStyleAttr, 0);
......@@ -75,20 +89,8 @@ public class TextViewWithCompoundDrawables extends AppCompatTextView {
if (mDrawableWidth <= 0 && mDrawableHeight <= 0 && mDrawableTint == null) return;
Drawable[] drawables = getCompoundDrawablesRelative();
for (Drawable drawable : drawables) {
if (drawable == null) continue;
if (mDrawableWidth > 0 || mDrawableHeight > 0) {
Rect bounds = drawable.getBounds();
if (mDrawableWidth > 0) {
bounds.right = bounds.left + mDrawableWidth;
}
if (mDrawableHeight > 0) {
bounds.bottom = bounds.top + mDrawableHeight;
}
drawable.setBounds(bounds);
}
}
setDrawableBounds(drawables);
if (mDrawableTint != null) setDrawableTint(drawables);
......@@ -104,4 +106,21 @@ public class TextViewWithCompoundDrawables extends AppCompatTextView {
mDrawableTint.getColorForState(getDrawableState(), 0), PorterDuff.Mode.SRC_IN);
}
}
private void setDrawableBounds(Drawable[] drawables) {
for (Drawable drawable : drawables) {
if (drawable == null) continue;
if (mDrawableWidth > 0 || mDrawableHeight > 0) {
Rect bounds = drawable.copyBounds();
if (mDrawableWidth > 0) {
bounds.right = bounds.left + mDrawableWidth;
}
if (mDrawableHeight > 0) {
bounds.bottom = bounds.top + mDrawableHeight;
}
drawable.setBounds(bounds);
}
}
}
}
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