Search in sources :

Example 96 with InflateException

use of android.view.InflateException in project Transitions-Everywhere by andkulikov.

the class TransitionInflater method createTransitionFromXml.

// 
// Transition loading
// 
@Nullable
private Transition createTransitionFromXml(@NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable 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 ("scale".equals(name)) {
            transition = new Scale(mContext, attrs);
        } else if ("translation".equals(name)) {
            transition = new TranslationTransition(mContext, attrs);
        } else if ("transition".equals(name)) {
            transition = (Transition) createCustom(attrs, Transition.class, "transition");
        } else if ("targets".equals(name) && parent != null) {
            getTargetIds(parser, attrs, parent);
        } else if ("arcMotion".equals(name) && parent != null) {
            parent.setPathMotion(new ArcMotion(mContext, attrs));
        } else if ("pathMotion".equals(name) && parent != null) {
            parent.setPathMotion((PathMotion) createCustom(attrs, PathMotion.class, "pathMotion"));
        } else if ("patternPathMotion".equals(name) && parent != null) {
            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 : Scale(com.transitionseverywhere.extra.Scale) TranslationTransition(com.transitionseverywhere.extra.TranslationTransition) TranslationTransition(com.transitionseverywhere.extra.TranslationTransition) InflateException(android.view.InflateException) Nullable(android.support.annotation.Nullable)

Example 97 with InflateException

use of android.view.InflateException in project focus-android by mozilla-mobile.

the class GeckoViewPrompt method onDateTimePrompt.

@Override
public void onDateTimePrompt(final GeckoSession session, final String title, final int type, final String value, final String min, final String max, final TextCallback callback) {
    final Activity activity = mActivity;
    if (activity == null) {
        callback.dismiss();
        return;
    }
    final String format;
    if (type == DATETIME_TYPE_DATE) {
        format = "yyyy-MM-dd";
    } else if (type == DATETIME_TYPE_MONTH) {
        format = "yyyy-MM";
    } else if (type == DATETIME_TYPE_WEEK) {
        format = "yyyy-'W'ww";
    } else if (type == DATETIME_TYPE_TIME) {
        format = "HH:mm";
    } else if (type == DATETIME_TYPE_DATETIME_LOCAL) {
        format = "yyyy-MM-dd'T'HH:mm";
    } else {
        throw new UnsupportedOperationException();
    }
    final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ROOT);
    final Date minDate = parseDate(formatter, min, /* defaultToNow */
    false);
    final Date maxDate = parseDate(formatter, max, /* defaultToNow */
    false);
    final Date date = parseDate(formatter, value, /* defaultToNow */
    true);
    final Calendar cal = formatter.getCalendar();
    cal.setTime(date);
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final LayoutInflater inflater = LayoutInflater.from(builder.getContext());
    final DatePicker datePicker;
    if (type == DATETIME_TYPE_DATE || type == DATETIME_TYPE_MONTH || type == DATETIME_TYPE_WEEK || type == DATETIME_TYPE_DATETIME_LOCAL) {
        final int resId = builder.getContext().getResources().getIdentifier("date_picker_dialog", "layout", "android");
        DatePicker picker = null;
        if (resId != 0) {
            try {
                picker = (DatePicker) inflater.inflate(resId, /* root */
                null);
            } catch (final ClassCastException | InflateException e) {
            }
        }
        if (picker == null) {
            picker = new DatePicker(builder.getContext());
        }
        picker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), /* listener */
        null);
        if (minDate != null) {
            picker.setMinDate(minDate.getTime());
        }
        if (maxDate != null) {
            picker.setMaxDate(maxDate.getTime());
        }
        datePicker = picker;
    } else {
        datePicker = null;
    }
    final TimePicker timePicker;
    if (type == DATETIME_TYPE_TIME || type == DATETIME_TYPE_DATETIME_LOCAL) {
        final int resId = builder.getContext().getResources().getIdentifier("time_picker_dialog", "layout", "android");
        TimePicker picker = null;
        if (resId != 0) {
            try {
                picker = (TimePicker) inflater.inflate(resId, /* root */
                null);
            } catch (final ClassCastException | InflateException e) {
            }
        }
        if (picker == null) {
            picker = new TimePicker(builder.getContext());
        }
        setTimePickerTime(picker, cal);
        picker.setIs24HourView(DateFormat.is24HourFormat(builder.getContext()));
        timePicker = picker;
    } else {
        timePicker = null;
    }
    final LinearLayout container = addStandardLayout(builder, title, /* msg */
    null);
    container.setPadding(/* left */
    0, /* top */
    0, /* right */
    0, /* bottom */
    0);
    if (datePicker != null) {
        container.addView(datePicker);
    }
    if (timePicker != null) {
        container.addView(timePicker);
    }
    final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            if (which == DialogInterface.BUTTON_NEUTRAL) {
                // Clear
                callback.confirm("");
                return;
            }
            if (datePicker != null) {
                cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            }
            if (timePicker != null) {
                setCalendarTime(cal, timePicker);
            }
            callback.confirm(formatter.format(cal.getTime()));
        }
    };
    builder.setNegativeButton(android.R.string.cancel, /* listener */
    null).setNeutralButton(R.string.gv_prompt_clear, listener).setPositiveButton(android.R.string.ok, listener);
    createStandardDialog(builder, callback).show();
}
Also used : AlertDialog(android.app.AlertDialog) TimePicker(android.widget.TimePicker) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) Activity(android.app.Activity) Date(java.util.Date) LayoutInflater(android.view.LayoutInflater) InflateException(android.view.InflateException) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat) LinearLayout(android.widget.LinearLayout)

Example 98 with InflateException

use of android.view.InflateException in project MDM-Android-Agent by wso2-attic.

the class MenuInflater method inflate.

/**
 * Inflate a menu hierarchy from the specified XML resource. Throws
 * {@link InflateException} if there is an error.
 *
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,
 *            <code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will be
 *            added to this Menu.
 */
public void inflate(int menuRes, Menu menu) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs, menu);
    } catch (XmlPullParserException e) {
        throw new InflateException("Error inflating menu XML", e);
    } catch (IOException e) {
        throw new InflateException("Error inflating menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 99 with InflateException

use of android.view.InflateException in project Phonograph by kabouzeid.

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_web_view, null);
    } catch (InflateException e) {
        e.printStackTrace();
        return new MaterialDialog.Builder(getActivity()).title(android.R.string.dialog_alert_title).content("This device doesn't support web view, which is necessary to view the change log. It is missing a system component.").positiveText(android.R.string.ok).build();
    }
    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.changelog).customView(customView, false).positiveText(android.R.string.ok).showListener(dialog1 -> {
        if (getActivity() != null)
            setChangelogRead(getActivity());
    }).build();
    final WebView webView = customView.findViewById(R.id.web_view);
    try {
        // Load from phonograph-changelog.html in the assets folder
        StringBuilder buf = new StringBuilder();
        InputStream json = getActivity().getAssets().open("phonograph-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 String backgroundColor = colorToCSS(ATHUtil.resolveColor(getActivity(), R.attr.md_background_color, Color.parseColor(ThemeSingleton.get().darkTheme ? "#424242" : "#ffffff")));
        final String contentColor = colorToCSS(Color.parseColor(ThemeSingleton.get().darkTheme ? "#ffffff" : "#000000"));
        final String changeLog = buf.toString().replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor)).replace("{link-color}", colorToCSS(ThemeSingleton.get().positiveColor.getDefaultColor())).replace("{link-color-active}", colorToCSS(ColorUtil.lightenColor(ThemeSingleton.get().positiveColor.getDefaultColor())));
        webView.loadData(changeLog, "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 : Context(android.content.Context) ATHUtil(com.kabouzeid.appthemehelper.util.ATHUtil) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) LayoutInflater(android.view.LayoutInflater) PreferenceUtil(com.kabouzeid.gramophone.util.PreferenceUtil) Dialog(android.app.Dialog) PackageInfo(android.content.pm.PackageInfo) InputStreamReader(java.io.InputStreamReader) Color(android.graphics.Color) ThemeSingleton(com.afollestad.materialdialogs.internal.ThemeSingleton) SuppressLint(android.annotation.SuppressLint) InflateException(android.view.InflateException) ColorUtil(com.kabouzeid.appthemehelper.util.ColorUtil) View(android.view.View) BufferedReader(java.io.BufferedReader) WebView(android.webkit.WebView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Log(android.util.Log) R(com.kabouzeid.gramophone.R) DialogFragment(androidx.fragment.app.DialogFragment) InputStream(java.io.InputStream) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) InflateException(android.view.InflateException) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) NonNull(androidx.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Example 100 with InflateException

use of android.view.InflateException in project android_packages_apps_Snap by LineageOS.

the class PreferenceInflater method inflate.

private CameraPreference inflate(XmlPullParser parser) {
    AttributeSet attrs = Xml.asAttributeSet(parser);
    ArrayList<CameraPreference> list = new ArrayList<CameraPreference>();
    Object[] args = new Object[] { mContext, attrs };
    try {
        for (int type = parser.next(); type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
            if (type != XmlPullParser.START_TAG)
                continue;
            CameraPreference pref = newPreference(parser.getName(), args);
            int depth = parser.getDepth();
            if (depth > list.size()) {
                list.add(pref);
            } else {
                list.set(depth - 1, pref);
            }
            if (depth > 1) {
                ((PreferenceGroup) list.get(depth - 2)).addChild(pref);
            }
        }
        if (list.size() == 0) {
            throw new InflateException("No root element found");
        }
        return list.get(0);
    } catch (XmlPullParserException e) {
        throw new InflateException(e);
    } catch (IOException e) {
        throw new InflateException(parser.getPositionDescription(), e);
    }
}
Also used : AttributeSet(android.util.AttributeSet) ArrayList(java.util.ArrayList) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Aggregations

InflateException (android.view.InflateException)104 IOException (java.io.IOException)50 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)48 AttributeSet (android.util.AttributeSet)30 XmlResourceParser (android.content.res.XmlResourceParser)19 View (android.view.View)14 Constructor (java.lang.reflect.Constructor)13 Path (android.graphics.Path)10 SuppressLint (android.annotation.SuppressLint)7 WebView (android.webkit.WebView)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 StringTokenizer (java.util.StringTokenizer)6 NonNull (android.annotation.NonNull)5 PathParser (android.util.PathParser)5 TypedValue (android.util.TypedValue)5 Bitmap (android.graphics.Bitmap)4 ExpandedMenuView (android.support.v7.internal.view.menu.ExpandedMenuView)4 ActionBarView (android.support.v7.internal.widget.ActionBarView)4 ViewGroup (android.view.ViewGroup)4 TextView (android.widget.TextView)4