Commit 81c9fe43 authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[Sh-Clank] Custom toast for error messages

On Android 11, setGravity is deprecated. For text toasts is noop.
Therefore, create toast from a custom view, for which setGravity still
works. This is a short term solution.

Bug: 1135597
Change-Id: I8fc9c85df4b5f749b6e0d0781cee4b8963460c74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460971
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815817}
parent 638aa1cb
......@@ -7,6 +7,7 @@ import("//build/config/android/rules.gni")
android_resources("java_resources") {
sources = [
"java/res/drawable/camera_img.xml",
"java/res/drawable/custom_toast_background.xml",
"java/res/drawable/delete_icon.xml",
"java/res/drawable/edit_icon.xml",
"java/res/drawable/generic_favicon.xml",
......@@ -17,6 +18,7 @@ android_resources("java_resources") {
"java/res/drawable/save_icon.xml",
"java/res/drawable/share_icon.xml",
"java/res/drawable/text_icon.xml",
"java/res/layout/custom_toast_layout.xml",
"java/res/layout/qrcode_camera_error_layout.xml",
"java/res/layout/qrcode_dialog.xml",
"java/res/layout/qrcode_open_settings_layout.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 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">
<corners android:radius="20dp"/>
<padding
android:left="20dp"
android:right="20dp"/>
<solid android:color="@color/modern_grey_200"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 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. -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_text"
android:background="@drawable/custom_toast_background"
android:gravity="center"
android:minHeight="44dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.TextSmall.Primary"/>
\ No newline at end of file
......@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.share.link_to_text;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.widget.TextView;
import org.chromium.blink.mojom.TextFragmentSelectorProducer;
import org.chromium.chrome.R;
......@@ -60,9 +62,18 @@ public class LinkToTextCoordinator extends EmptyTabObserver {
params, new ChromeShareExtras.Builder().build(), System.currentTimeMillis());
if (selector.isEmpty()) {
// TODO(gayane): Android toast should be replace by another toast like UI which allows
// custom positioning as |setView| and |setGravity| are deprecated starting API 30.
String toastMessage =
mContext.getResources().getString(R.string.link_to_text_failure_toast_message);
Toast toast = Toast.makeText(mContext, toastMessage, Toast.LENGTH_SHORT);
LayoutInflater inflater = LayoutInflater.from(mContext);
TextView text = (TextView) inflater.inflate(R.layout.custom_toast_layout, null);
text.setText(toastMessage);
text.announceForAccessibility(toastMessage);
Toast toast = new Toast(mContext);
toast.setView(text);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(toast.getGravity(), toast.getXOffset(),
mContext.getResources().getDimensionPixelSize(R.dimen.y_offset));
toast.show();
......
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