From 6428fb07babad8deb91be0ce662d674b0eaa2520 Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Sat, 8 Jan 2022 12:45:28 +0530 Subject: [PATCH] Show different message for views that are not supported --- .../inflater/NotSupportedException.java | 43 +++++++++++++++++++ .../itsaky/inflater/XMLLayoutInflater.java | 7 ++- xml-inflater/src/main/res/values/strings.xml | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 xml-inflater/src/main/java/com/itsaky/inflater/NotSupportedException.java diff --git a/xml-inflater/src/main/java/com/itsaky/inflater/NotSupportedException.java b/xml-inflater/src/main/java/com/itsaky/inflater/NotSupportedException.java new file mode 100644 index 000000000..6be011ee1 --- /dev/null +++ b/xml-inflater/src/main/java/com/itsaky/inflater/NotSupportedException.java @@ -0,0 +1,43 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.inflater; + +/** + * Exception thrown by inflaters and drawable parsers to + * indicate that the a specific view or tag is not + * supported. + * + * @author Akash Yadav + */ +public class NotSupportedException extends UnsupportedOperationException { + + public NotSupportedException () { + } + + public NotSupportedException (String message) { + super (message); + } + + public NotSupportedException (String message, Throwable cause) { + super (message, cause); + } + + public NotSupportedException (Throwable cause) { + super (cause); + } +} diff --git a/xml-inflater/src/main/java/com/itsaky/inflater/XMLLayoutInflater.java b/xml-inflater/src/main/java/com/itsaky/inflater/XMLLayoutInflater.java index c8f476975..dede6bab8 100644 --- a/xml-inflater/src/main/java/com/itsaky/inflater/XMLLayoutInflater.java +++ b/xml-inflater/src/main/java/com/itsaky/inflater/XMLLayoutInflater.java @@ -284,7 +284,7 @@ class XMLLayoutInflater extends BaseLayoutInflater { final var androidView = this.widgetInfo.getWidget (name); if (androidView == null) { // If this is not an Android view, do not bother to create one - throw new InflateException (String.format ("%s is not supported yet.", name)); + throw new NotSupportedException (); } final View created = createAndroidViewForName (name); @@ -294,6 +294,11 @@ class XMLLayoutInflater extends BaseLayoutInflater { : new UiView (name, created); return applyLayoutParams (view, parent); } catch (Throwable th) { + + if (th instanceof NotSupportedException) { + return onCreateErrorView (name, getString (R.string.msg_view_not_supported, name), parent); + } + final var msg = getString (R.string.msg_cannot_create_view, name); LOG.error (msg, th); return onCreateErrorView (name, msg, parent); diff --git a/xml-inflater/src/main/res/values/strings.xml b/xml-inflater/src/main/res/values/strings.xml index eb7d24329..5ea6d35a5 100644 --- a/xml-inflater/src/main/res/values/strings.xml +++ b/xml-inflater/src/main/res/values/strings.xml @@ -2,4 +2,5 @@ Cannot create view for tag: %s Unable to read values No attribute adapter implementation found for %s + View %s is not supported currently.