Commit e10e6939 authored by Hazem Ashmawy's avatar Hazem Ashmawy Committed by Commit Bot

[AW] DevUI: Improve different webview provider error message

Refactor the PersistentErrorView class into a Text message with an
always yellow background and black text with an optional button for
a quick action.

Use round alert error icon currently in drawable resources instead of
the framework triangle white icon, to match the black text color.

Refactor WebViewPackageError to show a more informative message with a
quick action to:
- Change WebView Provider if it's possible.
- If WebView provider cannot be changed, then offer to open DevTools
  from the current provider if it has a valid DevTools implementation.
Clicking the message body will still open a dialog to offer a more
detailed message and both options to open current WebView provider
DevTools if possible or change WebView if possible.

Stop showing the different package error dialog at the start of the UI.

This will also fix the presubmit warning because of using setTextColor.

Fixed: 1059475,1061164,1052192,1062406
Change-Id: I67176896580143e5e962991a36faf0576e156090
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098689
Commit-Queue: Hazem Ashmawy <hazems@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756115}
parent 03fb2593
......@@ -5,16 +5,36 @@
LICENSE file.
-->
<TextView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:id="@+id/crashes_list_activity_layout"
android:background="@color/warning_yellow"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
android:drawableStart="@android:drawable/stat_notify_error"
android:drawablePadding="8dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"/>
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingBottom="5dp"
android:visibility="gone">
<TextView
android:id="@+id/error_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
style="?android:attr/textAppearanceMedium"
android:drawableStart="@drawable/ic_alert_error"
android:drawablePadding="15dp"
android:paddingTop="15dp"
android:paddingBottom="10dp"
android:textColor="@android:color/black"/>
<Button
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonBarButtonStyle"
android:textColor="@android:color/black"
android:layout_gravity="end"
android:visibility="gone"/>
</LinearLayout>
\ No newline at end of file
......@@ -463,8 +463,7 @@ public class CrashesListFragment extends Fragment {
}
Activity activity = (Activity) mContext;
return new PersistentErrorView(
activity, R.id.crash_consent_error, PersistentErrorView.Type.ERROR)
return new PersistentErrorView(activity, R.id.crash_consent_error)
.setText("Crash collection is disabled. Tap for more info.")
.setDialog(dialogBuilder.create());
}
......
......@@ -51,8 +51,6 @@ public class MainActivity extends FragmentActivity {
mSwitchFragmentOnResume = true;
mDifferentPackageError = new WebViewPackageError(this);
// show the dialog once when the activity is created.
mDifferentPackageError.showDialogIfDifferent();
// Set up bottom navigation bar:
mFragmentIdMap.put(R.id.navigation_home, FRAGMENT_ID_HOME);
......
......@@ -6,44 +6,26 @@ package org.chromium.android_webview.devui;
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.IdRes;
/**
* Shows a text message at the top of a LinearLayout to show error and warning messages.
* Shows a text message at the top of a Layout to show error messages.
*/
public class PersistentErrorView {
/**
* Error message type.
*/
public enum Type {
ERROR,
WARNING,
}
private TextView mTextView;
private ViewGroup mViewGroup;
/**
* @param context The Activity where this View is shon.
* @param type View type.
*/
public PersistentErrorView(Activity context, @IdRes int errorViewId, Type type) {
mTextView = (TextView) context.findViewById(errorViewId);
switch (type) {
case ERROR:
mTextView.setBackgroundResource(R.color.error_red);
mTextView.setTextColor(Color.WHITE);
break;
case WARNING:
mTextView.setBackgroundResource(R.color.warning_yellow);
mTextView.setTextColor(Color.BLACK);
break;
}
public PersistentErrorView(Activity context, @IdRes int errorViewId) {
mViewGroup = (ViewGroup) context.findViewById(errorViewId);
}
/**
......@@ -52,7 +34,7 @@ public class PersistentErrorView {
* @return object reference for chaining.
*/
public PersistentErrorView setOnClickListener(OnClickListener listener) {
mTextView.setOnClickListener(listener);
mViewGroup.setOnClickListener(listener);
return this;
}
......@@ -62,7 +44,30 @@ public class PersistentErrorView {
* @return object reference for chaining.
*/
public PersistentErrorView setDialog(Dialog dialog) {
setOnClickListener(v -> dialog.show());
if (dialog == null) {
setOnClickListener(null);
} else {
setOnClickListener(v -> dialog.show());
}
return this;
}
/**
* Set and show the main action button. If {@code text} is {@null} the button will be hidden.
* @param text Button text.
* @param listener the listener to execute when the button is clicked.
* @return object reference for chaining.
*/
public PersistentErrorView setActionButton(String text, OnClickListener listener) {
Button button = (Button) mViewGroup.findViewById(R.id.action_button);
if (text == null) {
button.setVisibility(View.GONE);
button.setOnClickListener(null);
} else {
button.setVisibility(View.VISIBLE);
button.setText(text);
button.setOnClickListener(listener);
}
return this;
}
......@@ -72,7 +77,8 @@ public class PersistentErrorView {
* @return object reference for chaining.
*/
public PersistentErrorView setText(String text) {
mTextView.setText(text);
TextView textView = (TextView) mViewGroup.findViewById(R.id.error_text);
textView.setText(text);
return this;
}
......@@ -80,13 +86,13 @@ public class PersistentErrorView {
* Show the view by setting its visibility.
*/
public void show() {
mTextView.setVisibility(View.VISIBLE);
mViewGroup.setVisibility(View.VISIBLE);
}
/**
* Hide the view by setting its visibility.
*/
public void hide() {
mTextView.setVisibility(View.GONE);
mViewGroup.setVisibility(View.GONE);
}
}
......@@ -134,6 +134,13 @@ public final class WebViewPackageHelper {
return context.getPackageName().equals(systemWebViewPackage.packageName);
}
/**
* Check if the system currently has a valid WebView implementation.
*/
public static boolean hasValidWebViewImplementation(Context context) {
return getCurrentWebViewPackage(context) != null;
}
/**
* Loads a label for the app specified by {@code mContext}. This is designed to be consistent
* with how the system's WebView chooser labels WebView packages (see {@code
......
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