use of android.view.InflateException in project platform_frameworks_base by android.
the class AnimatorInflater method getPVH.
private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId, int valueToId, String propertyName) {
TypedValue tvFrom = styledAttributes.peekValue(valueFromId);
boolean hasFrom = (tvFrom != null);
int fromType = hasFrom ? tvFrom.type : 0;
TypedValue tvTo = styledAttributes.peekValue(valueToId);
boolean hasTo = (tvTo != null);
int toType = hasTo ? tvTo.type : 0;
if (valueType == VALUE_TYPE_UNDEFINED) {
// Check whether it's color type. If not, fall back to default type (i.e. float type)
if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) {
valueType = VALUE_TYPE_COLOR;
} else {
valueType = VALUE_TYPE_FLOAT;
}
}
boolean getFloats = (valueType == VALUE_TYPE_FLOAT);
PropertyValuesHolder returnValue = null;
if (valueType == VALUE_TYPE_PATH) {
String fromString = styledAttributes.getString(valueFromId);
String toString = styledAttributes.getString(valueToId);
PathParser.PathData nodesFrom = fromString == null ? null : new PathParser.PathData(fromString);
PathParser.PathData nodesTo = toString == null ? null : new PathParser.PathData(toString);
if (nodesFrom != null || nodesTo != null) {
if (nodesFrom != null) {
TypeEvaluator evaluator = new PathDataEvaluator();
if (nodesTo != null) {
if (!PathParser.canMorph(nodesFrom, nodesTo)) {
throw new InflateException(" Can't morph from " + fromString + " to " + toString);
}
returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo);
} else {
returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom);
}
} else if (nodesTo != null) {
TypeEvaluator evaluator = new PathDataEvaluator();
returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo);
}
}
} else {
TypeEvaluator evaluator = null;
// Integer and float value types are handled here.
if (valueType == VALUE_TYPE_COLOR) {
// special case for colors: ignore valueType and get ints
evaluator = ArgbEvaluator.getInstance();
}
if (getFloats) {
float valueFrom;
float valueTo;
if (hasFrom) {
if (fromType == TypedValue.TYPE_DIMENSION) {
valueFrom = styledAttributes.getDimension(valueFromId, 0f);
} else {
valueFrom = styledAttributes.getFloat(valueFromId, 0f);
}
if (hasTo) {
if (toType == TypedValue.TYPE_DIMENSION) {
valueTo = styledAttributes.getDimension(valueToId, 0f);
} else {
valueTo = styledAttributes.getFloat(valueToId, 0f);
}
returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo);
} else {
returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom);
}
} else {
if (toType == TypedValue.TYPE_DIMENSION) {
valueTo = styledAttributes.getDimension(valueToId, 0f);
} else {
valueTo = styledAttributes.getFloat(valueToId, 0f);
}
returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo);
}
} else {
int valueFrom;
int valueTo;
if (hasFrom) {
if (fromType == TypedValue.TYPE_DIMENSION) {
valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f);
} else if (isColorType(fromType)) {
valueFrom = styledAttributes.getColor(valueFromId, 0);
} else {
valueFrom = styledAttributes.getInt(valueFromId, 0);
}
if (hasTo) {
if (toType == TypedValue.TYPE_DIMENSION) {
valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
} else if (isColorType(toType)) {
valueTo = styledAttributes.getColor(valueToId, 0);
} else {
valueTo = styledAttributes.getInt(valueToId, 0);
}
returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo);
} else {
returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom);
}
} else {
if (hasTo) {
if (toType == TypedValue.TYPE_DIMENSION) {
valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
} else if (isColorType(toType)) {
valueTo = styledAttributes.getColor(valueToId, 0);
} else {
valueTo = styledAttributes.getInt(valueToId, 0);
}
returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo);
}
}
}
if (returnValue != null && evaluator != null) {
returnValue.setEvaluator(evaluator);
}
}
return returnValue;
}
use of android.view.InflateException in project material-dialogs by afollestad.
the class ChangelogDialog method onCreateDialog.
@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final View customView;
try {
customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null);
} catch (InflateException e) {
throw new IllegalStateException("This device does not support Web Views.");
}
MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).theme(getArguments().getBoolean("dark_theme") ? Theme.DARK : Theme.LIGHT).title(R.string.changelog).customView(customView, false).positiveText(android.R.string.ok).build();
final WebView webView = (WebView) customView.findViewById(R.id.webview);
try {
// Load from changelog.html in the assets folder
StringBuilder buf = new StringBuilder();
InputStream json = getActivity().getAssets().open("changelog.html");
BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
String str;
while ((str = in.readLine()) != null) {
buf.append(str);
}
in.close();
// Inject color values for WebView body background and links
final int accentColor = getArguments().getInt("accent_color");
webView.loadData(buf.toString().replace("{style-placeholder}", getArguments().getBoolean("dark_theme") ? "body { background-color: #444444; color: #fff; }" : "body { background-color: #fff; color: #000; }").replace("{link-color}", colorToHex(shiftColor(accentColor, true))).replace("{link-color-active}", colorToHex(accentColor)), "text/html", "UTF-8");
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
return dialog;
}
use of android.view.InflateException in project platform_frameworks_base by android.
the class TransitionInflater method createTransitionFromXml.
//
// Transition loading
//
private Transition createTransitionFromXml(XmlPullParser parser, AttributeSet attrs, Transition parent) throws XmlPullParserException, IOException {
Transition transition = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
TransitionSet transitionSet = (parent instanceof TransitionSet) ? (TransitionSet) parent : null;
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if ("fade".equals(name)) {
transition = new Fade(mContext, attrs);
} else if ("changeBounds".equals(name)) {
transition = new ChangeBounds(mContext, attrs);
} else if ("slide".equals(name)) {
transition = new Slide(mContext, attrs);
} else if ("explode".equals(name)) {
transition = new Explode(mContext, attrs);
} else if ("changeImageTransform".equals(name)) {
transition = new ChangeImageTransform(mContext, attrs);
} else if ("changeTransform".equals(name)) {
transition = new ChangeTransform(mContext, attrs);
} else if ("changeClipBounds".equals(name)) {
transition = new ChangeClipBounds(mContext, attrs);
} else if ("autoTransition".equals(name)) {
transition = new AutoTransition(mContext, attrs);
} else if ("recolor".equals(name)) {
transition = new Recolor(mContext, attrs);
} else if ("changeScroll".equals(name)) {
transition = new ChangeScroll(mContext, attrs);
} else if ("transitionSet".equals(name)) {
transition = new TransitionSet(mContext, attrs);
} else if ("transition".equals(name)) {
transition = (Transition) createCustom(attrs, Transition.class, "transition");
} else if ("targets".equals(name)) {
getTargetIds(parser, attrs, parent);
} else if ("arcMotion".equals(name)) {
parent.setPathMotion(new ArcMotion(mContext, attrs));
} else if ("pathMotion".equals(name)) {
parent.setPathMotion((PathMotion) createCustom(attrs, PathMotion.class, "pathMotion"));
} else if ("patternPathMotion".equals(name)) {
parent.setPathMotion(new PatternPathMotion(mContext, attrs));
} else {
throw new RuntimeException("Unknown scene name: " + parser.getName());
}
if (transition != null) {
if (!parser.isEmptyElementTag()) {
createTransitionFromXml(parser, attrs, transition);
}
if (transitionSet != null) {
transitionSet.addTransition(transition);
transition = null;
} else if (parent != null) {
throw new InflateException("Could not add transition to another transition.");
}
}
}
return transition;
}
use of android.view.InflateException in project AndroidChromium by JackyAndroid.
the class WarmupManager method initializeViewHierarchy.
/**
* Inflates and constructs the view hierarchy that the app will use.
* @param baseContext The base context to use for creating the ContextWrapper.
* @param toolbarContainerId Id of the toolbar container.
*/
public void initializeViewHierarchy(Context baseContext, int toolbarContainerId) {
TraceEvent.begin("WarmupManager.initializeViewHierarchy");
// Inflating the view hierarchy causes StrictMode violations on some
// devices. Since layout inflation should happen on the UI thread, allow
// the disk reads. crbug.com/644243.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
ThreadUtils.assertOnUiThread();
if (mMainView != null && mToolbarContainerId == toolbarContainerId)
return;
ContextThemeWrapper context = new ContextThemeWrapper(baseContext, ChromeActivity.getThemeId());
FrameLayout contentHolder = new FrameLayout(context);
mMainView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.main, contentHolder);
mToolbarContainerId = toolbarContainerId;
if (toolbarContainerId != ChromeActivity.NO_CONTROL_CONTAINER) {
ViewStub stub = (ViewStub) mMainView.findViewById(R.id.control_container_stub);
stub.setLayoutResource(toolbarContainerId);
stub.inflate();
}
} catch (InflateException e) {
// See crbug.com/606715.
Log.e(TAG, "Inflation exception.", e);
mMainView = null;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
TraceEvent.end("WarmupManager.initializeViewHierarchy");
}
}
use of android.view.InflateException in project AndroidChromium by JackyAndroid.
the class TitleBitmapFactory method getFaviconBitmap.
/**
* Generates the favicon bitmap.
*
* @param context Android's UI context.
* @param favicon The favicon of the tab.
* @return The Bitmap with the favicon.
*/
public Bitmap getFaviconBitmap(Context context, Bitmap favicon) {
try {
Bitmap b = Bitmap.createBitmap(mFaviconDimension, mFaviconDimension, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
if (favicon == null) {
Drawable drawable = ApiCompatibilityUtils.getDrawable(context.getResources(), mNullFaviconResourceId);
if (drawable instanceof BitmapDrawable) {
favicon = ((BitmapDrawable) drawable).getBitmap();
}
}
if (favicon != null) {
c.drawBitmap(favicon, Math.round((mFaviconDimension - favicon.getWidth()) / 2.0f), Math.round((mFaviconDimension - favicon.getHeight()) / 2.0f), null);
}
return b;
} catch (OutOfMemoryError ex) {
Log.w(TAG, "OutOfMemoryError while building favicon texture.");
} catch (InflateException ex) {
Log.w(TAG, "InflateException while building favicon texture.");
}
return null;
}
Aggregations