Search in sources :

Example 61 with InflateException

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;
}
Also used : PathParser(android.util.PathParser) InflateException(android.view.InflateException) TypedValue(android.util.TypedValue)

Example 62 with InflateException

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;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) BufferedReader(java.io.BufferedReader) InflateException(android.view.InflateException) WebView(android.webkit.WebView) NonNull(android.support.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Example 63 with InflateException

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;
}
Also used : InflateException(android.view.InflateException)

Example 64 with InflateException

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");
    }
}
Also used : StrictMode(android.os.StrictMode) ViewStub(android.view.ViewStub) ContextThemeWrapper(android.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) InflateException(android.view.InflateException)

Example 65 with InflateException

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;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) InflateException(android.view.InflateException) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

InflateException (android.view.InflateException)91 IOException (java.io.IOException)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 AttributeSet (android.util.AttributeSet)28 XmlResourceParser (android.content.res.XmlResourceParser)18 Constructor (java.lang.reflect.Constructor)13 Path (android.graphics.Path)10 View (android.view.View)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 StringTokenizer (java.util.StringTokenizer)6 NonNull (android.annotation.NonNull)5 SuppressLint (android.annotation.SuppressLint)5 PathParser (android.util.PathParser)5 TypedValue (android.util.TypedValue)5 ExpandedMenuView (android.support.v7.internal.view.menu.ExpandedMenuView)4 ActionBarView (android.support.v7.internal.widget.ActionBarView)4 ViewGroup (android.view.ViewGroup)4 AlertDialog (android.app.AlertDialog)2 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2